Previous Next Contents Index Doc Set Home


Cross Platform Development

10



10.1 Introduction

This chapter describes the cross-platform capabilities of WorkShop Visual which are enabled in Microsoft Windows mode. It contains sections on:

This chapter makes certain assumptions about your knowledge of WorkShop Visual. It is assumed that you understand structured code generation, as described in the Structured Code Generation section on page 263 and that you are comfortable with the idea of generating C++ code. The C++ Classes section on page 268 provides information on C++ in WorkShop Visual. You may wish to follow the tutorial in Chapter 9, "C++ Code Tutorial" to gain experience with the generation of C++ code.


Note - This chapter is only relevant if you have purchased the WorkShop Visual XP add-on package. This package allows you to create interfaces which are common to both Motif and Windows environments.


10.2 Overview

The best way to develop an application which is to be ported to different platforms is to encapsulate the platform specific parts in some way so that the body of the application is isolated from the implementation details. WorkShop Visual uses its C++ code structuring capabilities to generate a set of classes for the user interface that have the same public interface, but two different implementations. In WorkShop Visual these implementations are known as flavors. There are three flavors of C++ code that can be generated:

1. Motif - The vanilla flavor is the same as generating C++ code when not using the cross platform capabilities. The base classes are a very simple set provided, with source, with the WorkShop Visual release.

2. Microsoft Windows MFC - The target base classes on the Microsoft Windows platform are the Microsoft Foundation Classes. These provide a fairly high level set of controls and functions which can be used to build user interfaces.

3. Motif XP - A set of base classes supplied with source as part of the WorkShop Visual release. They are very similar to the Motif flavor base classes except that they are named to match the Microsoft Foundation Classes and provide a little of the basic functionality. They are not intended to provide the whole of the MFC interface, only enough to allow the developer some measure of shared code in the user interface. The real goal is in sharing code in the rest of the application.

The full capabilities of WorkShop Visual's C++ model can still be used for cross platform applications. This means that you can use sub-classing and inheritance to add additional functionality. These techniques can be used, for example, to support cross platform versions of your user-defined widgets.

10.2.1 Microsoft Windows Mode and Compliance

Unfortunately for the user interface developer, the Motif and X toolkits bear little resemblance to the Microsoft Windows toolkit. Although the visual appearance is similar, the actual use of the toolkit is very different. This requires WorkShop Visual to impose some restrictions on the developer before Microsoft Windows code can be generated for a design. WorkShop Visual will impose these restrictions when it is in Microsoft Windows mode. When WorkShop Visual is in Microsoft Windows mode it needs to permit the developer to work on designs which do not comply with these restrictions (so that an existing design can be read in for example). As a result WorkShop Visual will check that a design is Microsoft Windows compliant. If a design is not Microsoft Windows compliant then C++ code can only be generated for the Motif flavor.

The issues of compliance and importing old designs are covered in later sections of this chapter.

10.2.2 Widgets and Resources

In addition to the compliance issues which prevent code from being generated for Microsoft Windows, there are many attributes of a design which simply have no effect in the Microsoft Windows implementation (for example the alignment of a label on a button), because the Microsoft Windows toolkit does not support the concept. WorkShop Visual indicates this by means of icon and color cues.

Icon Cues

In the resource panels, those resources which have no effect on Microsoft Windows are indicated with a cross icon, those that do have an effect are indicated with a tick icon.

Color Cue

By default, text input fields and option menus in the resource panels use a pink color to indicate that setting the resource will have no effect in the Microsoft Windows flavor.1

If the variable name field of the selected widget is pink, this indicates that the widget will not map to any equivalent Microsoft Windows object. For instance, in Microsoft Windows a menubar is simply an attribute of a Dialog, there is no menubar object. Consequently WorkShop Visual will show the variable name pink for menubar widgets.

WorkShop Visual will also use this technique to indicate that some links will not be reproduced in the Microsoft Windows code.

All these features are covered in more detail later in this chapter and in the tutorial following it.


10.3 Starting in Microsoft Windows Mode

There are three methods of invoking WorkShop Visual so that it is running in Microsoft Windows mode. Select the method which suits you best, bearing in mind that you may have to share your copy of WorkShop Visual with other users who do not want to run WorkShop Visual in Microsoft Windows mode.

10.3.1 The Resource File

Microsoft Windows mode can be specified by a resource in the file containing your WorkShop Visual application resources:

	visu.windows:	true

10.3.2 The Command Line Switch

Microsoft Windows mode can also be specified by a command line switch when invoking WorkShop Visual:

	visu -windows

10.3.3 Separate Version of WorkShop Visual

The third method of invoking WorkShop Visual in Microsoft Windows mode gives the appearance of a separate application which is always in Microsoft Windows mode. This method uses the application resource, described above.

1. Create a hard link to your WorkShop Visual shell script in the $VISUROOT/bin directory.

2. Give this file a name such as visuwindows.

3. Create a hard link to your WorkShop Visual binary in the $VISUROOT/lib directory. Use the same file name as in Step 2.

4. Add the windows flag to the .Xdefaults file in your home directory, using the name of your symbolic link, as follows:

	visuwindows.windows:	true
In this way, you can simply type visuwindows. This will invoke WorkShop Visual in Microsoft Windows mode. Other people can then continue to use WorkShop Visual safe in the knowledge that the default will not be Microsoft Windows mode.


Note - This is the technique that WorkShop Visual uses to bring up the version for smaller screens - such as the VGA screen. The program small_visu is nothing more than a hard link to the WorkShop Visual binary which picks up an alternative set of resources from the WorkShop Visual resource file.


10.4 The WorkShop Visual Window

The WorkShop Visual Window looks slightly different when in Microsoft Windows mode. The main differences are the addition of two items in the toolbar at the top (and in corresponding menus) and the fact that some of the widgets are not included in the widget palette. This second point is dealt with in the Microsoft Windows Compliance section on page 336. The first set of differences is described here.

10.4.1 Microsoft Windows Compliant Toggles

There are two Microsoft Windows Compliant toggles - one on the toolbar and one in the Module menu. They both have the same function.

Figure  10-1 The Compliance Buttons in the Toolbar (left)
and the Module Menu (right)
These toggles indicate whether or not the current design is Microsoft Windows compliant. If you read in a design created with a version of WorkShop Visual not in Microsoft Windows mode or you cut and paste areas of a compliant hierarchy, it is possible to create structures which are not Microsoft Windows compliant.

In such a case a message is displayed informing you where the problem is and the two Microsoft Windows Compliant toggles are unset. The toolbar toggle displays a red cross when it is unset. Having made the appropriate changes to your design, pressing either of these toggles will check the compliance again. If your design is now Microsoft Windows compliant, the toolbar button will be set (the red cross will disappear). If not an error message will appear indicating the problem and the toggles will remain unset.

10.4.2 The Flavor Menu

The flavor menu in the toolbar specifies which flavor of code you wish to generate: plain Motif, Motif XP or Microsoft Windows. This only applies to C++ code generation.

Figure  10-2 The Flavor Menu in the Toolbar


10.5 Microsoft Windows Compliance

This section details the restrictions imposed by WorkShop Visual which ensure that Microsoft Windows compliant code can be generated. When in Microsoft Windows mode WorkShop Visual will not allow you to create a design which violates these restrictions.

10.5.1 Structure restrictions

Because of the differences between Motif and Microsoft Windows in the way events are handled, some widgets cannot be made classes. In Microsoft Windows, events concerning certain widgets are always sent to the enclosing class. Other widgets must be classes in order to handle Microsoft Windows messages. Here is a list of these restrictions:

The first error you are likely to encounter on reading a non-compliant design is the fact that the Shell must be structured as a C++ class. This error is easy to fix and can be done automatically from the Compliance Failure dialog. See the Compliance Failure section on page 342 for more details.

C Structures

WorkShop Visual does not support the Function or Data Structure options in a compliant design.

Classes and Callbacks

Structural errors can be considerably more complicated if you have a design which is well-structured, making good use of C++ classes and with callback methods scattered among the child widgets. The following example demonstrates how this problem may occur and how to overcome it.

Example

When a widget is given a callback method, the method is declared in the enclosing class. In the following example, while using a version of WorkShop Visual which was not in Microsoft Windows mode, the MenuBar, MBar_class, was declared a class and the button given a callback method:

Figure  10-3 Non-Compliant Hierarchy
The method is declared in MBar_class. If you then read the design into a version of WorkShop Visual in Microsoft Windows mode, you will be presented with the following error message because MenuBars cannot be classes:

Figure  10-4 Error Message Showing Non-Compliance
If you remove the class definition of the MenuBar (using the Core Resources dialog), you will then see the following error message:

Figure  10-5 Message Informing of Method Callback Declaration Invalidation
Make sure that the method declarations are removed from the MenuBar and, in this case, added to the Shell. You cannot add them to the Form because the Form, like the MenuBar, does not map to an object on Microsoft Windows.

Although WorkShop Visual assists you in the above way, changing whether a widget is a class or not could have a major impact on your application. You will need to reconsider the structure of your application very carefully.

10.5.2 Menubar restrictions

Menubars in Microsoft Windows are created by setting an attribute of the Dialog. This leads to two compliance restrictions:

10.5.3 FileSelectionBox

The File Selection Box must be a child of a DialogShell or TopLevelShell. In Microsoft Windows file selection is provided by a pre-defined FileSelection Dialog. This dialog can only contain a single work area child, it cannot support a Menubar, nor additional buttons (not managed by the work area).

10.5.4 Unsupported widgets

The following widgets have no comparable control in Microsoft Windows and so cannot be used in a design that is to be portable:

10.5.5 Scale

The Scale widget maps to a Microsoft Windows ScrollBar control which cannot support child controls. Therefore a Scale widget with children violates the Microsoft Windows compliance restrictions.

10.5.6 Frame and RadioBox

Because of the way messages are passed to an enclosing control, both Frame and RadioBox (if not the child of a Frame) have to be classes. However, as the child of a Shell cannot be a class, it follows that neither Frame nor RadioBox can be the immediate child of a Shell.

The second child of a Frame must be a Label widget - this is the title of the Frame. The Frame control in Microsoft Windows (actually a CButton in disguise) simply has a title attribute. There is no way to use another control as the title. The first child can be any widget.

10.5.7 MainWindow and ScrolledWindow

Microsoft Windows does not support automatic scrolling and hence WorkShop Visual in Microsoft Windows mode disables automatic scrolling options. The MainWindow widget may only include a work area and Menubar child. It does not support the command window or message window.

10.5.8 Paned Windows

A compliant design cannot contain a Paned Window which has Separator, MainWindow, OptionMenu, or MenuBar children. Neither may the children be definitions or instances.

10.5.9 Definitions

The XmNlabelType resource cannot be explicitly set for a widget which is a component of a definition when it is instantiated in another design. In other words, if a Button does not have XmNlabelType set in a definition then when that definition is used XmNlabelType cannot be set to PIXMAP. This is because Microsoft Windows uses a different class (CBitmapButton instead of CButton) to implement a button with a bitmap on it. It is obviously not possible to change the class of a variable after it has been created, hence the restriction.

For the same reason it is not possible to have a CascadeButton in a definition which has no Pulldown menu and to then add the Pulldown in an instance.

Slightly more subtly, it is not possible to have a widget with methods added to an instance which is not being sub-classed. For example, imagine you have an instance of a RowColumn definition, and the root widget (i.e. the RowColumn) does not have its structure set to class. When not in Microsoft Windows mode it is possible to add a button to the RowColumn instance and give it a method callback which is declared in an enclosing scope (say a Shell class). This is not possible in Microsoft Windows; the event has to be handled by the enclosing control (in this case the CWnd which represents the RowColumn).


10.6 Compliance Failure

When you read in a design which was created by WorkShop Visual while not in Microsoft Windows mode or you use cut and paste in such a way as to cause a design to become non-compliant, the Compliance Failure dialog appears showing you which widgets are causing the design to be non-compliant.

.

Figure  10-6 The Compliance Failure Dialog
You can select the widgets in the scrolled list of non-compliant widgets. You may then press one of the following buttons:

10.6.1 Example

This example shows how compliance failure is detected. In the hierarchy shown in Figure 10-7, the RowColumn widget rc_is_class has been made a class:

Figure  10-7 RowColumn Defined as Class
If you were to cut rc_is_class, clear the form and then paste (i.e. pasting rc_is_class as a child of shell), WorkShop Visual would mark the design as non-compliant and display the Compliance Failure Dialog shown in Figure 10-8 indicating that the child of a shell may not be a class:

Figure  10-8 Error When Pasting a Class as Child of Shell
WorkShop Visual allows you to continue with the operation but until you change the structure of rc_is_class, you will have a design which is not Microsoft Windows compliant. The Microsoft Windows compliant toggle in the toolbar displays a red cross to remind you.


10.7 User-Defined Widgets

WorkShop Visual can be extended to support widgets from any other Xt toolkit in addition to the default Motif set. Widgets added to WorkShop Visual are called user-defined widgets. Chapter 14, "User-Defined Widgets" provides a detailed description of this topic. The new widgets appear in the WorkShop Visual widget palette and can be used in the same way as the pre-defined Motif ones.

In Microsoft Windows mode WorkShop Visual does not provide any explicit support for user defined widgets. However, WorkShop Visual's C++ model does allow you sufficient flexibility to incorporate any user-defined widgets for which you have developed an appropriate MFC based class. WorkShop Visual will treat a user-defined widget as if it were an instance of the class from which it was derived. There are two possibilities:

1. You have a widget derived from another not supported by the Motif XP. In this case you will not be able to add it to your Microsoft Windows application.

2. You have a new widget derived from XmPushButton, which is supported by the Motif XP. WorkShop Visual will treat it as though it is an XmPushButton.

10.7.1 User Widget from Motif Class

In the second example above, WorkShop Visual will generate Motif XP code which is based on the CButton class (since this is the way XmPushButton is implemented in the Motif XP) to create an instance of your user-defined widget. The Microsoft Windows code will be exactly the same as if you had used a PushButton.

10.7.2 User Widget from MFC

If you have an MFC-based implementation of your widget, you can specify its class name in the "Instantiate as" field on the Code Generation page of the Core resources dialog. See the Creating a Derived Class section on page 276 for more details on how to do this. You will then need to provide a similarly named class in the Motif XP library. See the Enhancing the Motif XP section on page 736 for details on how to do this.

WorkShop Visual will, however, still generate the call to the Create method in the Microsoft Windows code as if the control were a CButton. Although you cannot change this, it should not cause a problem.


10.8 Using Links

In the Motif flavors links are pre-defined callbacks. In the Microsoft Windows flavor they are implemented as simple global functions which are called by a button's message handler. There are, however, some restrictions on how links can be used on Microsoft Windows. These restrictions only affect whether code is generated for a link, they do not affect the design's compliance.

10.8.1 Destination Widget Not an Object on Microsoft Windows

If the widget selected as the destination of a link is not mapped to an object on Microsoft Windows, the Add button in the Edit Links dialog is pink. The link can still be added and will be effective on Motif but it will not be generated into the Microsoft Windows code. To indicate this, the widget in the list of links is pink. See the Mapping Motif Widgets to Microsoft Windows section on page 695 for more information on which widgets are mapped to Microsoft Windows objects.

10.8.2 Buttons in Menus as Link Destinations

When adding a link where the destination widget is a PushButton in a Menu, the type of link is restricted to enable and disable. You cannot show, hide, manage or unmanage a Menu Button on Microsoft Windows.

10.8.3 File Selection Dialog as Link Destination

FileSelectionBox is implemented on Microsoft Windows as a CFileDialog, a modal dialog which is shown by calling the DoModal method. This method does not return until the FileSelection is complete or cancelled. On Microsoft Windows, therefore, only the show link is supported. For both MFC and Motif XP flavors the code is structured so that the DoModal method does not return until the selection is complete or cancelled.


10.9 Manager Widgets and Layout

The Motif manager widgets have no equivalents on Microsoft Windows. Widgets such as Forms and RowColumns do not exist on Microsoft Windows and therefore are not generated at all if they are not made a class.

WorkShop Visual generates absolute values for sizes and positions as they are at the moment of generation. So, for example, if you have a PushButton that is 100 pixels wide, 30 pixels high and is located at 10, 200 then those explicit values will be used in the Microsoft Windows code, even though you have not explicitly set the x, y, width and height resources but allowed them to be calculated by the Motif toolkit. In practice this gives very good results - generating Microsoft Windows dialogs which look very similar to their Motif counterparts.

10.9.1 Fonts

Because WorkShop Visual is generating an absolute size for a Microsoft Windows control, it is important that the size of a dialog is appropriate for any font that will be used for text displayed in it. The best way to ensure this is to make WorkShop Visual use a similarly sized font to display the dialog whilst it is being designed. There are two ways to do this.

The first way is to force the control to use a particular sized font, perhaps by setting the XmNfontList resource for the control or by setting the appropriate font resource on the shell. Consequently the dialogs will be similarly sized.

Alternatively use a resource so that WorkShop Visual displays the design windows with a font that approximates to the default font used on Microsoft Windows. This will cause WorkShop Visual to generate absolute sizes that are appropriate to the font. The Motif code will use a default font in the normal way. To make WorkShop Visual use a specific font for the design on Microsoft Windows, use settings similar to the following in your resource file:

visu*dialog.labelFontList:\
-adobe-helvetica-medium-r-normal-*-14-*-*-*-*-77-iso8859-1
visu*dialog.buttonFontList:\
-adobe-helvetica-medium-r-normal-*-14-*-*-*-*-77-iso8859-1
visu*dialog.textFontList:\
-adobe-helvetica-medium-r-normal-*-14-*-*-*-*-77-iso8859-1
These values may work well for you, but it will depend on the precise font used on your Microsoft Windows system. It is the size and average width values which are important.

10.9.2 Resize Behavior

In Microsoft Windows mode, WorkShop Visual generates OnSize message handlers to provide some resize behavior when the user resizes a dialog. WorkShop Visual does not attempt to reproduce exactly the Motif geometry management, rather it generates a handler which will simulate the resize behavior of certain manager widgets. In particular, these are:

These managers do not need to be classes in order to produce the resize behavior; WorkShop Visual generates a handler for the enclosing class that handles all descendant widgets. You can suppress the generation of the resize handler if you want to provide your own (through a sub class for example), by unsetting the MFC OnSize handler toggle on the Code generation page of the Core resources dialog. See Figure 10-9.

Figure  10-9 The Core Resources Dialog - Code Generation Page


10.10 Fonts

In order for a font to be generated into the Microsoft Windows code you must use font objects. This is because fonts must be persistent on Microsoft Windows. Only by using font objects can you guarantee this. WorkShop Visual provides a visual cue by making the Apply button pink if you select an item from the list of fonts in the font selection dialog. If, however, you select an item from the list of font objects, the Apply button is no longer pink.

10.10.1 Fontlists and Compound Strings

If you specify fontlists for your objects in WorkShop Visual, the first font in the list will be used for the object on Microsoft Windows. Compound strings containing a mixture of tags will be translated to Microsoft Windows using only the first font specified.

10.10.2 Font naming

Fonts in Microsoft Windows are named using a different mechanism from that used by X Windows. However, Microsoft Windows has quite a sophisticated matching algorithm. So, although WorkShop Visual uses a fairly crude mapping to translate the font specification, even if you specify a font which is not available in Microsoft Windows, it will probably be substituted with something that looks reasonable.


10.11 Pixmaps, Bitmaps and Icons

Pixmap objects created in WorkShop Visual are converted into a Microsoft Windows bitmap or icon (depending on whether the object is a button or label respectively). This is done for you automatically when you generate a Microsoft Windows resource file. X monochrome bitmaps are not supported in the translation to Microsoft Windows.

When you select "Microsoft Windows Resources" from the Generate dialog, WorkShop Visual informs you that it will create a resource file and a bitmap/icon file for each pixmap you have created. Bitmap files are generated with the suffix ".bmp" and icon files with the suffix ".ico". You never need to save the pixmap to a file for Microsoft Windows but you may wish to do so for the Motif version. Note that icons are always scaled to 32x32 pixels on Windows.

10.11.1 Buttons with Pixmaps

For a Motif Button with a pixmap type label, WorkShop Visual generates a CBitmapButton for Microsoft Windows. One difference between buttons with pixmaps on Motif and CBitmapButtons on Microsoft Windows is that CBitmapButtons have no border - in fact they do not look like buttons at all. You may, therefore, wish to incorporate a border in your pixmap design.


10.12 Colors

You can set the Background and Foreground color of a widget which will be mapped to an object on Microsoft Windows. These colors will be generated into the Microsoft Windows code in terms of their RGB (Red, Green, Blue) values. Microsoft Windows does not normally have the richness of color that is commonly available on X/Motif. For this reason the colors may not look identical on the two platforms.

10.12.1 Color Objects

Specify the Background and Foreground colors in the usual way in WorkShop Visual. Background colors must be color objects - Foreground colors do not have to be.


10.13 Configuring WorkShop Visual

There are a number of application resources which apply to WorkShop Visual in Microsoft Windows mode. One of these is the windows flag, indicating that WorkShop Visual should start up in Microsoft Windows mode. This is described in the Starting in Microsoft Windows Mode section on page 334.

10.13.1 Adding Ctrl-M to Generated Lines

By default, WorkShop Visual generates code for Microsoft Windows which adds Ctrl-M as the carriage return before the linefeed character. This character is expected by MS-DOS and may, therefore, be expected by your file transfer program. If, however, you do not wish to have these characters at the end of each line, make the following change to the WorkShop Visual resource file:

visu.mfcCarriageReturn:	false

10.13.2 Setting the Color of non Microsoft Windows Resource Fields

By default, WorkShop Visual indicates that a field in a resource panel, or a button or any other text field, is not applicable to Microsoft Windows by coloring it pink. This color can be changed by altering the following line in the WorkShop Visual application resource file:

visu.mfcTextWarningBackground:	#ecc9c9eacdda
The example above shows the default file entry - i.e. the color pink. You can change this large number to a more readable color name.

10.13.3 Setting the Filename Filter

In the Generate dialog, WorkShop Visual provides a default filename filter in the Filter text field. You can change this in the application resource file. Search for the following:

visu.c++Filter:	*.c
visu.c++StubsFilter:	*.c
These are the default entries for Motif code generation - both vanilla Motif and Motif XP. For Microsoft Windows code generation there are two extra filename filters:

visu.visualC++Filter:	*.cpp
visu.visualC++StubsFilter:	*.cpp
If you wish to share code between the two platforms, you might consider changing the filename filters for the two different flavors so that they are the same. See the following section on file names for more details about points to bear in mind when naming files intended for both platforms.


10.14 File names

Filenames on the PC are restricted to 12 characters in total (including the dot) which must be distributed as no more than eight before the dot and no more than three after. If you wish to share files between the two platforms, this restriction will have to be kept in mind when generating Microsoft Windows code. Remember, also, that MS-DOS and Microsoft Windows are not case sensitive. Do not rely on upper and lower case letters to distinguish filenames.

10.14.1 Pixmaps

The above restrictions should also be remembered when naming pixmap objects. When you ask WorkShop Visual to generate a Microsoft Windows resource file after you have created pixmaps, WorkShop Visual automatically generates Microsoft Windows bitmaps and icons in separate files using the name you specified in the pixmap editor. If, therefore, you have specified a name with more than eight characters, you will encounter problems on Microsoft Windows.

10.14.2 C++ Code

Different compilers have varied conventions acceptable on filename extensions. The suffix `.cxx' seems to be universally supported; most compilers should support `.cpp'; some compilation systems may accept `.C' and `.c++'. Visual C++ will complain if you specify `.c' for a file which contains C++ code.

See the Setting the Filename Filter section on page 352 for details of how to change the default filters in the Generate dialog.

10.14.3 Makefile

No makefile can be generated for the Microsoft Windows code files. Since make is a UNIX utility, it is assumed that you will be using a Microsoft Windows development environment (such as Visual C++) to build your application.


Note - If you are using Make on your UNIX platform, it is best to generate different code flavors into separate directories in order to avoid confusion and name clashes.


10.15 Method Declarations

The Method Declarations dialog has an extra feature when in Microsoft Windows mode. There is a toggle button labelled Microsoft Windows MFC.

Figure  10-10 Method Declarations Dialog with Microsoft Windows MFC Toggle
This toggle is used to denote whether the method is declared in the class structure of the enclosing class when generating Microsoft Windows code. When generating Motif code, the method is still declared in the enclosing class. The enclosing class is the nearest ancestor which has its structure set to class (either explicitly or automatically).

This toggle does not indicate whether or not the method appears in the Microsoft Windows code stubs - the Callbacks dialog indicates this. If, in that dialog, the method callback has an `*' appended to it, it will not be generated into the Microsoft Windows stubs file. The Microsoft Windows MFC toggle gives you control over the method declarations, although you would usually use the default that WorkShop Visual provides. Use the Method declarations dialog to declare methods in a class of your choosing or declare them in one of your own classes. They must be declared somewhere.

When you add a method callback in the Callbacks dialog, if the method has not been declared already, WorkShop Visual will declare it for you in the enclosing class. If you do not wish the method to be declared there, use the Method Declarations dialog to unset the Microsoft Windows MFC toggle.


10.16 DrawingAreas

If a DrawingArea is not the child of a ScrolledWindow, MainWindow or Shell it is created as a basic CWnd class - otherwise it is ignored for Microsoft Windows code generation. See the Mapping Motif Widgets to Microsoft Windows section on page 695 for more information.

10.16.1 Adding Drawing Callbacks for Microsoft Windows

The Motif XP class library does not include any drawing support; any you require will be platform specific. However, WorkShop Visual does allow you to add callback methods which by default are only declared for Motif flavors and Microsoft Windows message handlers. When in Microsoft Windows mode WorkShop Visual adds a set of additional toggle buttons to the DrawingArea resource panel which can be used to add a Microsoft Windows message handler in the generated code.

Figure  10-11 The DrawingArea Resource Panel

10.16.2 The Microsoft Windows Message Handler for DrawingArea

If, for example, you were to select the OnRButtonDown toggle in the panel pictured above, the following stub is added to your callback stubs file:

afx_msg void scrolled_win_c::OnRButtonDown( UINT nFlags, CPoint 
point )
{
}
Note that afx_msg is a pseudo keyword on Microsoft Windows. The following lines are added to your C++ externs file:

//{{AFX_MSG(scrolled_win_c)
afx_msg void OnRButtonDown( UINT nFlags, CPoint point ):
//}}AFX_MSG
DECLARE_MESSAGE_MAP ()
This registers the message handler with Microsoft Windows.


10.17 Application Class

WorkShop Visual generates an instance of a CWinApp class to the MFC C++ flavors to represent the application. You can configure this class by means of the Application Class dialog which is displayed from the Module Menu. Figure 10-12 shows the dialog.

Figure  10-12 The Application Class Dialog

Note - The declaration of the application class (whether defined by yourself or using WorkShop Visual's default) is only generated when you are generating a main procedure - the "Main Program" in the Generate dialog.


10.18 Code Generation

There are three points which should be taken into consideration when generating code.

10.18.1 Synchronizing Save and Code Files

WorkShop Visual has to store the widget id numbers in the save file for definitions so that code can be correctly generated for instances which indirectly modify the layout of an unnamed component. This can cause a problem if the design is changed in a way which affects the widget ids (such as resetting) before the code is generated. WorkShop Visual will detect such loss of synchronization and will prompt you to save the file.

10.18.2 Dialog Flashing

In order for WorkShop Visual to correctly generate layout information the dialogs need to be realized. WorkShop Visual will automatically show and then hide any unrealized dialogs when Microsoft Windows code is generated. You may see the dialogs appear briefly on the display.

10.18.3 Use of Japanese Font

Any Microsoft Foundation Class (MFC) code generated by WorkShop Visual which contains Japanese text needs to be post-processed before it is compiled under Microsoft Windows.

A filter utility, visutosj, is provided as part of the WorkShop Visual release to perform this conversion. visutosj converts the MFC code from EUC to Shift-JIS encoding and changes the DEFAULT_CHARSET value in the MFC CFont creation method to SHIFTJIS_CHARSET.

visutosj is used in the following way:

visutosj [-xf*] [file]
The arguments are:

-x Displays a brief explanation of the utility

-f filter The shift-jis filter to use (default jconv)

-* Any other `-' flags are passed to the filter

[file] An optional file. If no file is specified, stdin is used


Previous Next Contents Index Doc Set Home


1 Pinking is only discernible on a color display.