wpf container & controls in gupta td...

22
DOCUMENT TYPE | Title Here Abstract Windows Presentation Foundation (WPF) is a framework for building rich Windows applications. This white paper will show you how to create amazing Gupta Team Developer WPF applications using .NET WPF controls. WPF Container & Controls in Gupta TD 6 OpenText Gupta Team Developer

Upload: ngodat

Post on 22-Jul-2018

225 views

Category:

Documents


2 download

TRANSCRIPT

DOCUMENT TYPE | Title Here

Abstract Windows Presentation Foundation (WPF) is a framework for building rich Windows applications. This white paper will show you how to create amazing Gupta Team Developer WPF applications using .NET WPF controls.

WPF Container & Controls in Gupta TD 6 OpenText Gupta Team Developer

WHITEPAPER | WPF Container & Controls in TD 6

O P E N T E X T G U P T A T E A M D E V E L O P E R 2

Table of Contents .............................................................................................................. 1

Abstract ................................................................................................. 1

Overview ............................................................................................... 3

OpenText Gupta Team Developer 6 new feature: WPF Container ...... 3

WPF container versus ActiveX container in OpenText Gupta Team Developer .................................... 3

Creation of a WPF control in OpenText GuptaTeam Developer ............................................................ 3

Instantiating a WPF container ................................................................................................................ 5

XAML - what is it? ................................................................................................................................... 5

Invoking methods in a WPF control ........................................................................................................ 6

How to SET and GET properties in a WPF control ................................................................................ 8

Handling events in a WPF control ........................................................................................................ 11

Enrich your application using .NET WPF controls .............................. 11

Native .NET WPF controls .................................................................................................................... 11

MAPs in Team Developer! .................................................................................................................... 15

Acrobat Reader in OpenText Gupta Team Developer ......................................................................... 17

Report Builder CQT preview ................................................................................................................. 19

Current limitations ............................................................................ 20

Conclusion........................................................................................... 21

About OpenText.................................................................................................................................... 22

WHITEPAPER | WPF Container & Controls in TD 6

O P E N T E X T G U P T A T E A M D E V E L O P E R 3

Overview Gupta Team Developer now supports .NET! This unleashes tremendous power and flexibility, allowing you to create rich GUI application and more:

You can now create a WPF application directly in Team Developer using SAL. See:

Creating a .Net WPF application from scratch

You can also create and import .NET assemblies as well as creating and consuming Web Services. See:

Importing .Net classes into TD6.0

Finally, you can consume any of the .NET WPF controls currently available on the internet, dramatically enriching your application. That is what this document will cover.

OpenText Gupta Team Developer 6 new feature: WPF Container

WPF container versus ActiveX container in OpenText Gupta Team Developer WPF applications are not WIN32 applications. The same is true for WPF control versus ActiveX controls. However, they do share in common the feature to expose visual components in a “container” hosted by a top level window (i.e. a Team Developer form). The interaction between the application and the container is performed through Methods, Properties and Events. In that respect WPF controls are similar to visual ActiveX controls, the underlying technology being very different though. In that respect WPF controls are similar to visual ActiveX controls, the underlying technology being very different though.

Consequently, an ActiveX control can no longer be used “directly” in a .NET Gupta Team Developer application. During the migration of a Gupta Team Developer application to WPF you will have to replace your ActiveX by a similar WPF control if it exists. The same is true for custom controls; an equivalent of ActiveX controls yet another technology.

If you are familiar with ActiveX control in TD, you should be at home in consuming WPF controls, hence replacing ActiveX by WPF controls.

Creation of a WPF control in OpenText GuptaTeam Developer The process is relatively similar to the creation of an ActiveX control, where you generally drop the ActiveX control of your choice from the toolbox to the form. At this point, Team Developer generates the functional class, a binding to the ActiveX control. Using this interface bound to the control you can start calling methods, setting properties, handling events; in a word, consuming the ActiveX control.

It is roughly the same with WPF Controls. You now use the WPF container object from the Team Developer toolbox and drop it on your form. If you do this now and have a good knowledge of ActiveX in TD, this might confuse you since there will be no:

Specific controls or objects listed in the toolbox as there is with ActiveX

WHITEPAPER | WPF Container & Controls in TD 6

O P E N T E X T G U P T A T E A M D E V E L O P E R 4

As we could not choose any specific controls from the toolbox, other than our WPF container, nothing will show inside the WPF control.

There is no APL interface to bind the object.

ActiveX instantiated and APL interface Un-instantiated WPF control.

What is going on?

If you used ActiveX in Gupta Team Developer, you might recall that you could also just drop an ActiveX container on the form (without choosing any specific control from the toolbox). At this point Team Developer would ask you to choose an object type. You could still ignore the selection of object and at this stage you are left with an empty un-instantiated ActiveX control. Since you are proficient in using ActiveX control in Team Developer you further know that you could still dynamically instantiate the ActiveX control through the SalActiveX API.

Image showing an ActiveX container un-instantiated with no APL interface generated

WHITEPAPER | WPF Container & Controls in TD 6

O P E N T E X T G U P T A T E A M D E V E L O P E R 5

At this point ActiveX versus WPF container are similar: you have a un-instantiated ActiveX container, same as our WPF container from the screenshot above.

Instantiating a WPF container Since you are in charge of instantiating the control, you obviously have to know what you would like to use and from what source! Currently in Gupta Team Developer there are no functionalities to explore the available list of controls on your machine as it is the case with the Team Developer Toolbox or the ActiveX explorer. You might use any of the .NET “native” WPF control (from the .NET framework) or look for any third party free or commercial controls. Needless to say that Team Developer already exposes some of the most used and needed WPF controls…but the list is endless!

Once you know what you like to consume, it is a simple matter to actually initialize the new Gupta Team Developer WPF container object. You do this in the properties of the WPF container entering a XAML snippet for the WPF Container in the attribute inspector.

Screen shot showing the wpf1 container XAML snippet set to use the .NET framework WebBrowser object. Note that at this point, the control is NOT instantiated at design time, it is onlydone at run-time.

XAML - what is it? It means, Extensible Application Markup Language. It is a declarative XML-based language created by Microsoft which is used to initialize structured values and objects.

The word “initialize” and “objects” is all that we want to know for the moment and for the remainder of this white paper. So we will not cover XAML here since it is far beyond the scope of this document and we will redirect you to further references, as WPF uses it extensively XAML. See:

http://en.wikipedia.org/wiki/Extensible_Application_Markup_Language

WHITEPAPER | WPF Container & Controls in TD 6

O P E N T E X T G U P T A T E A M D E V E L O P E R 6

So we have learned how to initialize our WPF container through the TD attribute inspector XAML property. If you just drop the WPF container on your form and set its XAML property to <WebBrowser/> and execute the application, you would see this:

Design time Runtime

Well, that’s rather simple and useless you would say and you are right as far as the snapshot is concerned. But you just learned how to initialize a Web Browser in a .NET Team Developer 6.0 WPF application using a XAML snippet! If you used the Microsoft ActiveX Web Browser object, dropping it on the form and running the application, you would see almost the same:

Design time Runtime

Invoking methods in a WPF control Now that we know how to initialize a Web Browser object, we would like to do a bit more and display a Web page from a URL. When using ActiveX we used the Navigate() method. In the same way, using WPF you will need to invoke a method to interact with it.

Because there isn’t any APL interface generated for a WPF container, the Active coding assistant will show nothing. You will not know directly what method to invoke. You can find methods of the object by searching the internet (MSDN) or directly in Visual Studio .NET.

Here we will be using the "Navigate" method from the WPF WebBrowser object which takes as an argument a string containing our URL, notice it is the same as with ActiveX: Set sParam[0]=”http://www.guptatechnologies.com" Call SalWPFInvokeMethod( wpf1, "Navigate", sParam, sReturn )

WHITEPAPER | WPF Container & Controls in TD 6

O P E N T E X T G U P T A T E A M D E V E L O P E R 7

Result of the above call…

The .NET WPF WebBrowser object exposes many more methods like Navigate() which takes an object type Uri, so you can navigate directly to the Web page.

From the above call, we just learned about a new function in Team Developer to invoke a WPF control methods; SalWPFInvokeMethod().

Here is the online help of the function:

SalWPFInvokeMethod

bOk = SalWPFInvokeMethod ( hWnd, strFunc, strArgs, strReturn )

Invokes a method pertaining to a WPF control.

Parameters

hWnd Window Handle. The handle for the custom WPF control. strFunc String. The name of the function. strArgs String Array. The function arguments. Pass a string representation of any argument (e.g. '546.98' or '25 September 2010'). strReturn Receive String. The return value of the function. If the function's return type is not a string, a string representation will be used.

Return Value

bOk is true if the function succeeds, false if it fails.

WHITEPAPER | WPF Container & Controls in TD 6

O P E N T E X T G U P T A T E A M D E V E L O P E R 8

How to SET and GET properties in a WPF control Just as ActiveX uses PropSet/ProGet calls to deal with the properties of an ActiveX object, Gupta Team Developer provides a new set of functions for dealing with WPF properties. Like ActiveX and properties that you can set at design time (in the attribute inspector), you can also set properties of a WPF control directly in the XAML snippet. There are currently no functionalities to list the properties exposed by a .NET control as it is the case for ActiveX through the generated interface and the Active Coding Assistant.

We will see an example of interacting with properties later in some samples but here is a XAML snippet setting properties for the WPF Slider control

Here is the online help describing the Set/GetWPF calls:

SalWPFGetBoolProperty

bOk = SalWPFGetBoolProperty(hWnd, strProp, bValue)

Gets a boolean property of a WPF control.

Parameters

hWnd The handle for the custom WPF control. strProp String. The name of the property. The function will get the value of this property. bValue Receive Boolean. The value of the property.

Return Value

bOk is true if the function succeeds, false if it fails.

SalWPFGetDateProperty

bOk = SalWPFGetDateProperty(hWnd, strProp, dateValue)

Gets a date property of a WPF control.

WHITEPAPER | WPF Container & Controls in TD 6

O P E N T E X T G U P T A T E A M D E V E L O P E R 9

Parameters

hWnd The handle for the custom WPF control. strProp String. The name of the property. The function will get the value of this property. dateValue Receive Date. The value of the property.

Return Value

bOk is true if the function succeeds, false if it fails.

SalWPFGetNumericProperty

bOk = SalWPFGetNumericProperty(hWnd, strProp, numValue)

Gets a number property of a WPF control.

Parameters

hWnd The handle for the custom WPF control. strProp String. The name of the property. The function will get the value of this property. numValue Receive Number. The value of the property.

Return Value

bOk is true if the function succeeds, false if it fails.

SalWPFGetStrProperty

bOk = SalWPFGetStrProperty(hWnd, strProp, strValue)

Gets a string property of a WPF control.

Parameters

hWnd The handle for the custom WPF control. strProp String. The name of the property. The function will get the value of this property. strValue Receive String. The value of the property.

Return Value

bOk is true if the function succeeds, false if it fails.

SalWPFSetBoolProperty

bOk = SalWPFSetBoolProperty(hWnd, strProp, bValue)

Sets a boolean property for a WPF control.

Parameters

hWnd The handle for the custom WPF control. strProp String. The name of the property whose value should be set. bValue Boolean. The new value.

Return Value

WHITEPAPER | WPF Container & Controls in TD 6

O P E N T E X T G U P T A T E A M D E V E L O P E R 10

bOk is true if the property exists, if it is writeable, and if the new value can be converted to the type of the property.

SalWPFSetDateProperty

bOk = SalWPFSetDateProperty(hWnd, strProp, DateValue)

Sets a string property for a WPF control.

Parameters

hWnd The handle for the custom WPF control. strProp String. The name of the property whose value should be set. DateValue Date. The new value.

Return Value

bOk is true if the property exists, if it is writeable, and if the new value can be converted to the type of the property.

SalWPFSetNumProperty

bOk = SalWPFSetNumProperty(hWnd, strProp, numValue)

Sets a number property for a WPF control.

Parameters

hWnd The handle for the custom WPF control. strProp String. The name of the property whose value should be set. numValue Number. The new value.

Return Value

bOk is true if the property exists, if it is writeable, and if the new value can be converted to the type of the property.

SalWPFSetStrProperty

bOk = SalWPFSetStrProperty(hWnd, strProp, StrValue)

Sets a string property for a WPF control.

Note: This function can be used to set any property that is settable from xaml.

Parameters

hWnd The handle for the custom WPF control. strProp String. The name of the property whose value should be set. strValue String. The new value.

Return Value

bOk is true if the property exists, if it is writeable, and if the new value can be converted to the type of the property.

WHITEPAPER | WPF Container & Controls in TD 6

O P E N T E X T G U P T A T E A M D E V E L O P E R 11

Handling events in a WPF control Now we will talk about events, which are also very similar to ActiveX. You handle the events directly at the action level of the WPF container. There is only one SAM message to catch the event to deal with it: \

On SAM_WPFEvent

When this event is caught you can work on the particular event fired by the control using the system variable wpfEventName. You can only use On SAM_WPFEvent and its wpfEventName system variable on the level of the WPF container.

Here is an example dealing with a WPF Slider event

As for Methods and Properties, there is currently no list of events available for the initialized WPF control.

Enrich your application using .NET WPF controls Here we will show some of the samples provided in this white paper. You already learned about the Team Developer WPF container; how to instantiate the container through XAML, how to consume it by invoking methods, setting and getting properties and handling events using the new SalWPF API.

So, let’s see practical examples. All those samples are based on the work of the .NET community. With Team Developer 6 and .NET you do not only rely on the Team Developer community alone. You just step in the future of development!

Native .NET WPF controls The screenshot below shows you the toolbox of Team Developer and Visual Studio 2010 for WPF application. Team developer has many controls, some new one like the Navigation pane. There isn’t, for example, a Slider control. This sample will show you how to actually use the WPF Slider control in Team Developer and also transform a picture control so you can rotate the image, skew it etc.

WHITEPAPER | WPF Container & Controls in TD 6

O P E N T E X T G U P T A T E A M D E V E L O P E R 12

Using the .NET Slider is as simple as dropping a WPF container on a TD form, initializing the container in the XAML snippet and additionally setting some specific properties for the control as shown below. In the sample, a Navigation pane is used to apply some transformation to the picture.

The picture control is not a Gupta TD control, nor a WPF native control; it is a WPF user control written in C# Visual Studio 2010 which hosts a native WPF control containing a rectangle and at its turn an image. Note that it should be possible to apply directly transformation on Team Developer WPF control.

This snapshots show the initialization of a WPF container to hold a Slider control that sets additional properties. You also could set the properties using SalWPFGetNumericProperty() for the ranges of the Slider. Here we do it directly in the XAML snippet.

WHITEPAPER | WPF Container & Controls in TD 6

O P E N T E X T G U P T A T E A M D E V E L O P E R 13

Since currently Team Developer does not expose the list of available methods, properties and events, you have to find them out. You can use MSDN, but using Visual studio .NET will help you. See:

http://www.microsoft.com/express/Downloads/

This below shows a Visual Studio XAML snippet that defines a rectangle and a slider with additional sets of properties that are not set in the previous Gupta Team Developer screenshot.

It is up to you to use them if they are needed.

<Window x:Class="WpfApplication1.MainWindow"

xmlns=http://schemas.microsoft.com/winfx/2006/xaml/presentation xmlns:x=http://schemas.microsoft.com/winfx/2006/xaml Title="MainWindow" Height="350" Width="525">

<Grid>

<Rectangle Height="77" HorizontalAlignment="Left" Margin="38,12,0,0" Name="rectangle1" Stroke="Black" VerticalAlignment="Top" Width="109" /> <Slider Height="25" HorizontalAlignment="Left" Margin="120,172,0,0" Name="slider1" VerticalAlignment="Top" Width="317" ValueChanged="slider1_ValueChanged" Delay="700" IsDirectionReversed="True" IsMoveToPointEnabled="True" IsSelectionRangeEnabled="True" IsSnapToTickEnabled="True" />

</Grid>

</Window>

Here Visual Studio Intellisense would reveal to you the methods, properties and events available for the object.

WHITEPAPER | WPF Container & Controls in TD 6

O P E N T E X T G U P T A T E A M D E V E L O P E R 14

The sample uses a Dock Dialog dlgTransform that hosts a Team Developer Navigation Pane to interact with the control. Here you see the use of SalWPFGetNumericProperty() and SalWPFInvokeMethod()

Here is the result of the Gupta Team Developer sample that allows you to transform an image.

The example can be found in the \WPF container White Paper\tdTransform\tdtransform.apt. As mentioned, the picture displayed in the Team Developer Form is a WPF user control not a Team Developer control. The binary assembly is in tdTransformation.dll and the resulting source in \WPF container White Paper\tdTransform.

WHITEPAPER | WPF Container & Controls in TD 6

O P E N T E X T G U P T A T E A M D E V E L O P E R 15

MAPs in Team Developer! The example below might look complex as it integrates maps in a Gupta Team Developer application. Actually it is not, thanks to the amazing free WPF user control from http://greatmaps.codeplex.com/. You can just directly use it, no need of registration and no need of any web server to host the service. You could use also Google maps directly in WPF. See: http://code.google.com/apis/maps/articles/flashmapinwpf.html.

WHITEPAPER | WPF Container & Controls in TD 6

O P E N T E X T G U P T A T E A M D E V E L O P E R 16

Here are the highlights of this Gupta Team Developer application. You can find this in \WPF container White Paper\gMapTD\gmap.apt

Here is a snapshot showing a form Window with a WPF container initialized to use the GMapControl with a single property set to Render GoogleHybrid type map.

Here we setup the size of the WPF container (on 0x0005 WM_SIZE message) to tile to its parent window. Currently there is no Tile to parent properties for the WPF container object.

Here we have a dock dialog that actually allows rendering the map from an address, zoom, etc. This is where the application interacts with the object. Here you can see how simple this is to actually invoke the method of the control that will render the map from an address contained in a multi-line edit field ml1.

WHITEPAPER | WPF Container & Controls in TD 6

O P E N T E X T G U P T A T E A M D E V E L O P E R 17

The example is provided in the \WPF container White Paper\gMapTD\ folder and it also contains the source of the WPF control. The assemblies for these objects are in

GMap.NET.Core.dll

GMap.NET.Core.xml

GMap.NET.WindowsPresentation.dll

GMap.NET.WindowsPresentation.XML

If you want to further explore methods, properties and events that the object exposes, you will have to consult the source or the web site of the control provider.

Acrobat Reader in OpenText Gupta Team Developer It is perfectly possible to use ActiveX controls in an WPF application. Currently a Team Developer 6.0 WPF targeted application cannot use an ActiveX control directly. Since Gupta Team Developer allows you to consume a WPF control, you have a means to actually make a wrapper to the ActiveX control you want to use. A WinForm application (yet another type of .NET application) allows you through the System.Windows.Forms assembly to use an activeX control and, thanks to the WPF .NET WindowsFormsIntegration, you can host a Windows Form in your WPF control thus using ActiveX controls.

You can therefore use all the ActiveX visual controls, but this needs to be an in process (.DLL) type of control. For example, MSOFFICE ActiveX control i.e.: Microsoft Excel Worksheet/Chart, Microsoft office Word Document showing as ActiveX objects in the Gupta Team Developer toolbox would not work directly and this is true even in Visual Studio. One way to expose this special kind of ActiveX in a WPF application is to use the WPF WebBrowser control to render them. MSOffice application supports that. There can be other object types like Report Builder that will not support it; ie having Report Builder embedded in a Gupta Team Developer or using Report builder in Visual studio and embed it in a WPF window. Fortunately, there are ways around this as you will see in the next sample.

So the example below is simply demonstrating how to embed the Acrobat PDF reader. The sample is located in \WPF container White Paper\acrobat reader. The source of the controls (there are actually 2 controls), a WindowForm control and a WPF user control, are located in \WPF container White Paper\acrobat reader\AcroCTL.

WHITEPAPER | WPF Container & Controls in TD 6

O P E N T E X T G U P T A T E A M D E V E L O P E R 18

The initialization of the WPF control is rather simple:

The example only calls one method to open the selected PDF. This method is a wrapper implemented in WPF user control Visual Studio solution (see the source).

As in the previous example, the WPF container is tiled to its parent form so that when you resize the form the PDF document extends with it.

Here is a snapshot of the running sample.

WHITEPAPER | WPF Container & Controls in TD 6

O P E N T E X T G U P T A T E A M D E V E L O P E R 19

Report Builder CQT preview Gupta Report builder when targeting for a WIN32 type application supports both the Quick Object and ActiveX interface. Quick Object can no longer be used in a Team Developer WPF application, so you will have to use its ActiveX interface. As mentioned previously, you still can use certain ActiveX control in a WPF application but other types as out process ActiveX controls are challenging.

The goal of those 2 interfaces (Quick Object and ActiveX) to report builder is to do some automation (creation of report from scratch, displaying a preview, etc.). You can do this either with report builder hidden from the UI, or outside the application (out process) or report builder embedded in a Form (generally called in process since most of those ActiveX are DLLs that share the same address space). The approach and functionality when you use report builder in a form or outside a form is somewhat different. This is also the same for Word or Excel in place or out place. Some automation functionalities are not available when using the ActiveX embedded in the form. When you have such an object embedded in a form generally you use its Document(s) interface, while the Application interface is usually not used.

.Net WPF applications also cannot directly use Excel or Word embedded in a form. However, if the object supports it, you can expose it through the .NET WPF WebBrowser object. This is not the case for report builder.

In order to get this to work in a Team Developer WPF application as well as a full .NET application without resorting to the WebBrowser object, you actually have to do a “mix of automation” as well as exposing some server UI inside a WindowsForm hosted in a WPF control.

WHITEPAPER | WPF Container & Controls in TD 6

O P E N T E X T G U P T A T E A M D E V E L O P E R 20

There are couple examples of this on the internet. Here is one for your reference:

http://www.codeproject.com/KB/miscctrl/winwordcontrol.aspx?msg=2185867

The example provided here allows you to open a CQT file in a Team Developer WPF Desktop or Browser application, display its preview and navigate through the report pages. There is much more you can do using Report Builder Automation in the .NET control that acts as a wrapper.

The source of the application is located in

\WPF container White Paper\WPF Report Builder Preview\rbPreviewInWPFControl.apt

All that has been covered related to calling methods, setting and getting properties applies here in the TD application so we will not further describe it. All the work is done in the source of both controls:

the Winform control : \WPF container White Paper\WPF Report Builder Preview\WpfRBPreviewCTL (SLNs)\WinRBPreviewCTL

the WPF control : \WPF Report Builder Preview\WpfRBPreviewCTL (SLNs)\WpfRBPreviewCT

Current limitations

The invoke property methods will only work on the first child of the WPF container

No complex data type can be passed or returned currently in the invoke and property functions and events

There are no Team Developer generated interface .APL for the WPF container that holds an instance of a WPF control, hence no list of methods, properties and event are exposed in the Active Coding Assistant.

WHITEPAPER | WPF Container & Controls in TD 6

O P E N T E X T G U P T A T E A M D E V E L O P E R 21

Conclusion As mentioned in the overview of this document, Team Developer finally made it in the .NET world. You can now create WPF desktop and browser applications.

Today not only you can target your Team Developer application to .NET but you also can consume all the plethora of free and commercial third party controls available on .Net.

The WPF container is the first step to further open OpenText Gupta Team Developer to .Net allowing you to join the growing community of .NET users and enrich your win32 application by migrating your legacy application to Team Developer 6.0 WPF.

WHITEPAPER | WPF Container & Controls in TD 6

www.opentext.com

NORTH AMERICA +800 499 6544 UNITED STATES +1 847 267 9330 GERMANY +49 89 4629 0

UNITED KINGDOM +44 0 1189 848 000 AUSTRALIA +61 2 9026 3400

Copyright ©2015-2016 Open Text Corporation OpenText is a trademark or registered trademark of Open Text SA and/or Open Text ULC. The list of trademarks is not exhaustive of other trademarks, registered trademarks, product names, company names, brands and service

names mentioned herein are property of Open Text SA or other respective owners. All rights reserved. For more information, visit: http://www.opentext.com/2/global/site-copyright.html SKU#

About OpenText OpenText provides Enterprise Information Management software that enables companies of all sizes and industries to manage, secure and leverage their unstructured business information, either in their data center or in the cloud. Over 50,000 companies already use OpenText solutions to unleash the power of their information. To learn more about OpenText (NASDAQ: OTEX; TSX: OTC), please visit www.opentext.com.