PhAB widget library

Hello!

I would like to know if it’s possible to create a library with “complex”
widgets (for example a pane with predisposed labels and buttons inside,
made with phAB) that could be used with different programs.

For the moment I have the same complex widget in 2 different programs,
and for each modification on this widget, I need to modificate the
widget in both programs.
That’s why I thought a library with this widget that I could include in
any way in my programs would be very useful…

Do you think custom widgets will be relevant? I tried to understand but
I think it would be easier with examples. I can’t find examples
concerning widgets created with PhAB.

Please give me hints to create this library!!

Thank you very much for answering me,
Marilys

You can use PhAB’s “Template” feature to create complex widgets, but since
the template and all resources associated with it are copied when it gets
instantiated you cannot modify the complex widget in a central location and
have that change propagate out.

As you suspected the only real way to do this is by writing your own custom
widget class. In my experience custom widgets are not well suited for
implementing complex widgets made up of multiple widgets. What you might
want to do instead is create a special custom container class that performs
pre-defined positioning & naming of its children. You could then create a
PhAB template with your custom container class and a set of children already
present. In this way a user could add the complex widget in one step, and
since the internal positioning/naming is handled by your dynamically loaded
custom widget it would be updated everywhere after a code modification &
rebuild.

Cheers,
Max

<user@domain.invalid> wrote in message
news:42B3140C.7060008@domain.invalid

Hello!

I would like to know if it’s possible to create a library with “complex”
widgets (for example a pane with predisposed labels and buttons inside,
made with phAB) that could be used with different programs.

For the moment I have the same complex widget in 2 different programs,
and for each modification on this widget, I need to modificate the
widget in both programs.
That’s why I thought a library with this widget that I could include in
any way in my programs would be very useful…

Do you think custom widgets will be relevant? I tried to understand but
I think it would be easier with examples. I can’t find examples
concerning widgets created with PhAB.

Please give me hints to create this library!!

Thank you very much for answering me,
Marilys

If your complex widget is supposed to look and behave pretty much the
same way in all the applications that use it, you might not really need
it to be a real widget class that lets you create instances in PhAB and
modify their resources and access them from code using the common Photon
API. Instead, it might be simpler to make it a picture module in a
separate dummy PhAB project, and write your own library of functions
that create and initialize the widgets and let you access their
resources. Then you’d either import copies of the module into the
applications, or keep it in a separate file accessed with
ApOpenDBaseFile(), or bundle the module and the code together in a DLL.
This would allow you to edit the contents of your container using
PhAB, instead of being able to adjust the resources of each copy if it
sitting in your applications.

Each of these methods has its disadvantages, but so does writing your
own widget class…

Max Feil wrote:

You can use PhAB’s “Template” feature to create complex widgets, but since
the template and all resources associated with it are copied when it gets
instantiated you cannot modify the complex widget in a central location and
have that change propagate out.

As you suspected the only real way to do this is by writing your own custom
widget class. In my experience custom widgets are not well suited for
implementing complex widgets made up of multiple widgets. What you might
want to do instead is create a special custom container class that performs
pre-defined positioning & naming of its children. You could then create a
PhAB template with your custom container class and a set of children already
present. In this way a user could add the complex widget in one step, and
since the internal positioning/naming is handled by your dynamically loaded
custom widget it would be updated everywhere after a code modification &
rebuild.

Cheers,
Max

user@domain.invalid> > wrote in message
news:> 42B3140C.7060008@domain.invalid> …

Hello!

I would like to know if it’s possible to create a library with “complex”
widgets (for example a pane with predisposed labels and buttons inside,
made with phAB) that could be used with different programs.

For the moment I have the same complex widget in 2 different programs,
and for each modification on this widget, I need to modificate the
widget in both programs.
That’s why I thought a library with this widget that I could include in
any way in my programs would be very useful…

Do you think custom widgets will be relevant? I tried to understand but
I think it would be easier with examples. I can’t find examples
concerning widgets created with PhAB.

Please give me hints to create this library!!

Thank you very much for answering me,
Marilys
\

let’s say that you created your complex widget using picture module.
I know I can then create and realize each widget in that picture
module, but this seem very tedious. Is there a way I can treat this
complex widget as a single widget. Because right now my complex
widget has many buttons and I have to create and realize these
bottons one after the other from the picture module to make up my
complex widget.

jinma wrote:

let’s say that you created your complex widget using picture module.
I know I can then create and realize each widget in that picture
module, but this seem very tedious. Is there a way I can treat this
complex widget as a single widget. Because right now my complex
widget has many buttons and I have to create and realize these
bottons one after the other from the picture module to make up my
complex widget.

You could use ApCreateDBWidgetFamily() to create a container along with
all the widgets inside it, or ApCreateModule() to create all the widgets
in the picture module. Is that good enough?

It seems like using ApCrateDBWidgetFamily() or ApCreateModule() means
that I need to do the widget layout outside from PhAB using C code.
I prefer to use PhAB to create my complex widgets.

How about creating a picture module with a container and lying out the
widgets in that container? In such case, can I just create and
realize the container widget to get all the widgets inside that
container??? I think I tried this and it only gave me a container
widget and not any other widgets inside of it. I guess my question
is, is there a way to take out all the widgets inside a picture
module with one call instead of taking every individual widgets?
Also in such case, are the widgets retain their position relative to
each other?

Thanks

jinma wrote:

It seems like using ApCrateDBWidgetFamily() or ApCreateModule() means
that I need to do the widget layout outside from PhAB using C code.

Why? If you pass NULL for the “pos” argument to
ApCreateDBWidgetFamily(), it’ll create the widget at the same position
it has in your PhAB module. And if you provide a widget to
ApCreateModule(), it creates the contents of the picture module at the
positions they have in the module.

I prefer to use PhAB to create my complex widgets.

How about creating a picture module with a container and lying out the
widgets in that container? In such case, can I just create and
realize the container widget to get all the widgets inside that
container??? I think I tried this and it only gave me a container
widget and not any other widgets inside of it. I guess my question
is, is there a way to take out all the widgets inside a picture
module with one call instead of taking every individual widgets?
Also in such case, are the widgets retain their position relative to
each other?

That’s exactly what it’s meant to do!.. If it didn’t work for you, we
need to figure out what went wrong.

When you created your widgets, was the parent already realized? Neither
ApCreateDBWidgetFamily() nor ApCreateModule() realizes the new widgets
(well, ApCreateModule() does for other types of modules, but not for
picture modules). The simplest way to realize all the new children of a
realized container is by calling PtReRealizeWidget() – have you tried that?

got it working~ I forgot to add ApAddClass for all the widgets inside
the container. But I used PtRealizeWidget on the container only and
it created all the children.

But now I am also looking into making my own widget subclass from
currently existing PhAB widgets. For example I would like to create
my own mybutton class from PtButton inheriting everything from
PtButton (like draw, extend, etc) but I would like to add my own
default functions to set different resource values. Can you tell me
the if this code should do the trick? I am thinking the code should
be very small since I am inheriting everything from PtButton. Thanks
in advance.

myptbutton.h file

#ifndef __PT_MY_BUTTON_H_INCLUDED
#define __PT_MY_BUTTON_H_INCLUDED

#ifndef __PT_LABEL_H_INCLUDED
#include <photon/PtLabel.h>
#include <photon/PtButton.h>
#endif

#include <photon/PpT.h>
#include <photon/PhPack.h>

#ifdef __cplusplus
extern “C” {
#endif
/*

  • PtMyButton public
    */
    extern PtWidgetClassRef_t *PtMyButton;

//#define Pt_BUTTON_ID 6

/* Resources /
//#define Pt_ARG_ARM_COLOR Pt_RESOURCE( 6, 0 )
//#define Pt_ARG_ARM_IMAGE Pt_RESOURCE( 6, 1 )
//#define Pt_ARG_ARM_DATA Pt_ARG_ARM_IMAGE
//#define Pt_ARG_ARM_FILL Pt_RESOURCE( 6, 2 )
//#define Pt_ARG_SET_FILL Pt_ARG_ARM_FILL
/

/* Widget structure */
typedef struct Pt_my_button_widget {
PtButtonWidget_t def_button
} PtMyButtonWidget_t;

/* Widget union */
typedef union Pt_my_button_union {
PtWidget_t core;
PtBasicWidget_t basic;
PtLabelWidget_t label;
PtMyButtonWidget_t button;
} PtMyButtonUnion_t;

#ifdef __cplusplus
};
#endif
#include <photon/PhPackPop.h>
#endif


myptbutton.c file

#include <Ph.h>
#include <photon/PpProto.h>
#include <stdlib.h>
#include <string.h>

#include “PtMyButton.h”

static PtWidgetClass_t *PtCreateButtonClass( void );
static PtWidgetClassRef_t button_class_ref = { NULL,
PtCreateButtonClass };
PtWidgetClassRef_t *PtMyButton = &button_class_ref;

//
// Defaults Function
//

static void button_dflts( PtWidget_t *widget )

{
PtMyButtonWidget_t *button = (PtMyButtonWidget_t *)widget;

/* set button widget flags to highlight/selectable */
widget->flags |= Pt_SELECTABLE | Pt_HIGHLIGHTED |
Pt_GETS_FOCUS | Pt_ETCH_HIGHLIGHT;

/* initialize button resources */
button->def_button.arm_color = PgGrey( 0xff );
button->def_button.arm_fill = 1;
button->def_button.label.h_alignment =
button->def_button.label.v_alignment = Pt_CENTER;
button->def_button.label.string = strdup(“DSI”);
button->def_button.label.basic.fill_color = Pg_GREEN;
button->def_button.label.basic.color = Pg_BLUE;
button->def_button.label.basic.flags = Pt_ALL_ETCHES |
Pt_ALL_OUTLINES | Pt_ALL_BEVELS | Pt_STATIC_GRADIENT ;
}
//
// Button Class Creation Function
//
static PtWidgetClass_t *PtCreateButtonClass( void )
{
static const PtClassArg_t args[] = {
{ Pt_SET_DFLTS_F, (long) button_dflts },
//{ Pt_SET_DESTROY_F, (long) button_destroy },
{ Pt_SET_DESCRIPTION, (long) “PtMyButton” },
};
static const PtArg_t roargs[] = {
{ Pt_SET_VERSION, 110 },
{ Pt_SET_STATE_LEN, sizeof( PtMyButtonWidget_t ) },
{ Pt_SET_FLAGS, Pt_TRUE, Pt_RECTANGULAR },
//{ Pt_SET_NUM_RESOURCES, sizeof( resources )/sizeof( resources[0] )
},
};
return( PtMyButton->wclass = PtCreateOptWidgetClass(
PtLabel, 0, sizeof( args )/sizeof( args[0] ), args
,sizeof(roargs)/sizeof(roargs[0]),roargs) );
}

I have tried this code, and it seems to work but I think I am having
some travel with some resource values. For example, arm_color is not
working even though I set it to certain color. I know that these
resources

#define Pt_ARG_ARM_COLOR Pt_RESOURCE( 6, 0 )
#define Pt_ARG_ARM_IMAGE Pt_RESOURCE( 6, 1 )
#define Pt_ARG_ARM_DATA Pt_ARG_ARM_IMAGE
#define Pt_ARG_ARM_FILL Pt_RESOURCE( 6, 2 )
#define Pt_ARG_SET_FILL Pt_ARG_ARM_FILL

are extented from PtLabel to PtButton, and I have extended from
PtButton so I should have inherited these resources right?
I guess I am missing something in the code. Any idea?

I fixed above by changing
PtCreateOptWidgetClass( PtLabel, 0, sizeof( args )/sizeof( args[0] ),
args ,sizeof(roargs)/sizeof(roargs[0]),roargs) );
to
PtCreateOptWidgetClass( PtButton, 0, sizeof( args )/sizeof( args[0] ),
args ,sizeof(roargs)/sizeof(roargs[0]),roargs) );
But now I am trying to extend PtWindow with similar code from above
but I am not successful. Any example code for extending PtWindow?
Thanks

“jinma” <matthew.jin@fmcti-dot-com.no-spam.invalid> wrote in message
news:dldsnq$n4h$1@inn.qnx.com

I fixed above by changing
PtCreateOptWidgetClass( PtLabel, 0, sizeof( args )/sizeof( args[0] ),
args ,sizeof(roargs)/sizeof(roargs[0]),roargs) );
to
PtCreateOptWidgetClass( PtButton, 0, sizeof( args )/sizeof( args[0] ),
args ,sizeof(roargs)/sizeof(roargs[0]),roargs) );

Good catch. The missing resources don’t exist in PtLabel.

BTW It’s better to use the documented PtCreateWidgetClass().
PtCreateOptWidgetClass() is an internal function that leaked into the
example in the docs by mistake.

But now I am trying to extend PtWindow with similar code from above
but I am not successful. Any example code for extending PtWindow?

If all you want to override is the default values of some resources, it
should work; but use PtSetResources() or PtSuperClassSetResources() instead
of setting widget members directly. In general, that’s safer, because it
gives your superclass a chance to update whatever internal state might be
affected by the changed value (obviously, this does not apply to members
that your class adds and therefore your superclass has no way of knowing
about). BTW, your code has a memory leak – you’re not freeing the string
that PtLabel’s defaults function has allocated. PtSetResources() would take
care of that.

great!
I am getting hang of this, but still need your help on creating my
custom PtWindow. It seem like PtWindow is a bit different from other
widgets in PhAB because normal widgets can be picked out from list of
widgets and put on to a window. But inorder to add a window I need
to goto “project->add windows” or “project->add dialog” ect…
I have created PtMyWindows like how I did for PtMyButton, and modified
palette.def and added mywindow.pal file so that PhAB can use my
PtMyWindow. But when I drag it out of the widget window it can not
create it self on it’s own. Windows don’t have parents and should be
independent from base window but right now my PtMyWindow is created
inside base window and it doesn’t behave like windows. Also I don’t
have control over it’s resources or put any other widgets inside this
window. Any idea?

jinma wrote:

great!
I am getting hang of this, but still need your help on creating my
custom PtWindow. It seem like PtWindow is a bit different from other
widgets in PhAB because normal widgets can be picked out from list of
widgets and put on to a window. But inorder to add a window I need
to goto “project->add windows” or “project->add dialog” ect…
I have created PtMyWindows like how I did for PtMyButton, and modified
palette.def and added mywindow.pal file so that PhAB can use my
PtMyWindow. But when I drag it out of the widget window it can not
create it self on it’s own. Windows don’t have parents and should be
independent from base window but right now my PtMyWindow is created
inside base window and it doesn’t behave like windows. Also I don’t
have control over it’s resources or put any other widgets inside this
window. Any idea?

Add a line

m=dw

to your mywindow.pal, somewhere after the w=PtMyWindow line. This will
tell PhAB that the widget can be used as the main widget of a dialog or
window module, rather than inside another module. Then you’ll be able
to create a module, right-click on its window widget, and change its
class to PtMyWindow.

BTW I’d recommend not using names that start with Pt. That part of the
namespace should be considered reserved for the Photon library.

I just tried it and it still didn’t change the behavior.
Just to let you know, I made my ptwindow.pal from ptpalette.pal just
copying the entry for ptwindow.
Also I don’t see any documentation on m=dw
can you tell me where I can find this information.

Is this the only way of doing it, meaning do I have to create a window
or dialog out of PtWindow first and then switch class on them from
PtWindow to PtMyWindow? Why couldn’t PhAB create window from
PtMyWindow from beginning?

Let me just post my PtMyWindow class code and ptpalette and
mywindow.pal

palette.def file

l=ptmywindow,<ptmywindow.h>:ph
p=mywindow,My Window

mywindow.pal file

w=PtMyWindow

m=dw

h=5
PtWidget
PtBasic
PtContainer
PtWindow
PtMyWindow

// Resources
r=Pt_ARG_WINDOW_TITLE,Window Title,18015,4008,0,string,Untitled
r=Pt_ARG_WINDOW_TITLE_COLOR,Window Title
Color,18016,0,0,crgb,0xFFFFFFFD
r=Pt_ARG_WINDOW_ACTIVE_COLOR,Window Active
Color,18018,0,0,crgb,0xFFFFFFFD
r=Pt_ARG_WINDOW_INACTIVE_COLOR,Window Inactive
Color,18019,0,0,crgb,0xFFFFFFFD
i=PtContainer,2002 // Pt_ARG_FILL_COLOR
//i=PtContainer,2006 // Pt_ARG_TOP_BORDER_COLOR
//i=PtContainer,2000 // Pt_ARG_BOT_BORDER_COLOR
i=PtBasic,2022 // Pt_ARG_OUTLINE_COLOR
i=PtBasic,2023 // Pt_ARG_INLINE_COLOR
i=PtBasic,2024 // Pt_ARG_LIGHT_FILL_COLOR
i=PtBasic,2025 // Pt_ARG_DARK_FILL_COLOR
r=Pt_ARG_WINDOW_RENDER_FLAGS,Flags:
Render,18013,4004,0,flag,0x73b0,12
Ph_WM_RENDER_ASDIALOG,0x2,0x7
Ph_WM_RENDER_ASPALETTE,0x4,0x7
Ph_WM_RENDER_BORDER,0x10
Ph_WM_RENDER_RESIZE,0x20
Ph_WM_RENDER_TITLE,0x80
Ph_WM_RENDER_MENU,0x100
Ph_WM_RENDER_CLOSE,0x200
Ph_WM_RENDER_HELP,0x400
Ph_WM_RENDER_MIN,0x1000
Ph_WM_RENDER_MAX,0x2000
Ph_WM_RENDER_COLLAPSE,0x4000
Ph_WM_RENDER_INLINE,0x10000

r=Pt_ARG_WINDOW_MANAGED_FLAGS,Flags:
Managed,18011,4005,0,flag,0x4CB7D,18
Ph_WM_CLOSE,0x1
Ph_WM_FOCUS,0x4
Ph_WM_MENU,0x8
Ph_WM_TOFRONT,0x10
Ph_WM_TOBACK,0x20
Ph_WM_HIDE,0x40
Ph_WM_CONSWITCH,0x80
Ph_WM_RESIZE,0x100
Ph_WM_MOVE,0x200
Ph_WM_ICON,0x400
Ph_WM_MAX,0x800
Ph_WM_BACKDROP,0x1000
Ph_WM_HELP,0x2000
Ph_WM_TASKBAR,0x4000
Ph_WM_RESTORE,0x8000
Ph_WM_FFRONT,0x10000
Ph_WM_COLLAPSE,0x40000
Ph_WM_NO_FOCUS_LIST,0x20000

r=Pt_ARG_WINDOW_NOTIFY_FLAGS,Flags:
Notify,18012,4006,0,flag,0x2101,17
Ph_WM_CLOSE,0x1
Ph_WM_FOCUS,0x4
Ph_WM_MENU,0x8
Ph_WM_TOFRONT,0x10
Ph_WM_TOBACK,0x20
Ph_WM_HIDE,0x40
Ph_WM_CONSWITCH,0x80
Ph_WM_RESIZE,0x100
Ph_WM_MOVE,0x200
Ph_WM_ICON,0x400
Ph_WM_MAX,0x800
Ph_WM_BACKDROP,0x1000
Ph_WM_HELP,0x2000
Ph_WM_TASKBAR,0x4000
Ph_WM_RESTORE,0x8000
Ph_WM_FFRONT,0x10000
Ph_WM_COLLAPSE,0x40000

r=Pt_ARG_WINDOW_STATE,Window State,18014,4007,0,flag,0,7
Ph_WM_STATE_ISNORMAL,0x00,0x907
Ph_WM_STATE_ISHIDDEN,0x01,0x05
Ph_WM_STATE_ISMAX,0x02
Ph_WM_STATE_ISCOLLAPSE,0x800
Ph_WM_STATE_ISBACKDROP,0x04,0x905
Ph_WM_STATE_ISFRONT,0x100,0x104
Ph_WM_STATE_ISALTKEY,0x200

r=Pt_ARG_MIN_HEIGHT,Minimum Window Height,18006,18006,1,ushort,23
r=Pt_ARG_MIN_WIDTH,Minimum Window Width,18007,18007,1,ushort,94
r=Pt_ARG_MAX_HEIGHT,Maximum Window Height,18004,18004,1,ushort,0
r=Pt_ARG_MAX_WIDTH,Maximum Window Width,18005,18005,1,ushort,0
i=PtContainer,10005 // Pt_ARG_CONTAINER_FLAGS
i=PtContainer,10007 // Pt_ARG_CONTAINR_TITLE
i=PtContainer,10008 // Pt_ARG_CONTAINER_FONT
// Similar in PtContainer:
// r=Pt_ARG_CURSOR_TYPE,Cursor Type,1002,1006,1,short,0,18
r=Pt_ARG_CURSOR_TYPE,Cursor Type,1002,1006,1,short,59648,17
Ph_CURSOR_POINTER,0xe900
Ph_CURSOR_BIG_POINTER,0xe902
Ph_CURSOR_MOVE,0xe904
Ph_CURSOR_CROSSHAIR,0xe906
Ph_CURSOR_CLOCK,0xe908
Ph_CURSOR_NOINPUT,0xe90A
Ph_CURSOR_FINGER,0xe90C
Ph_CURSOR_INSERT,0xe90E
Ph_CURSOR_DRAG_VERTICAL,0xe910
Ph_CURSOR_DRAG_HORIZONTAL,0xe912
Ph_CURSOR_DRAG_BACKDIAG,0xe914
Ph_CURSOR_DRAG_FOREDIAG,0xe916
Ph_CURSOR_POINT_WAIT,0xe918
Ph_CURSOR_LONG_WAIT,0xe91a
Ph_CURSOR_QUESTION_POINT,0xe91c
Ph_CURSOR_PASTE,0xe91e
Ph_CURSOR_NONE,0xfd
// Similar in PtContainer:
// r=Pt_ARG_CURSOR_COLOR,Color: Cursor,1003,1007,1,crgb,0xffffe0
r=Pt_ARG_CURSOR_COLOR,Cursor Color,1003,1007,1,crgb,0xffffe0
i=PtContainer,1018 // Pt_ARG_EFLAGS
i=PtBasic,1006 // Pt_ARG_FLAGS
//i=PtContainer,2014 // Pt_ARG_HIGHLIGHT_ROUNDNESS
i=PtBasic,1008 // Pt_ARG_RESIZE_FLAGS
i=PtContainer,10015 // Pt_ARG_LAYOUT_TYPE
i=PtContainer,10016 // Pt_ARG_FILL_LAYOUT_INFO
i=PtContainer,10017 // Pt_ARG_ROW_LAYOUT_INFO
i=PtContainer,10018 // Pt_ARG_GRID_LAYOUT_INFO
i=PtWidget,1035 // Pt_ARG_ROW_LAYOUT_DATA
i=PtWidget,1036 // Pt_ARG_GRID_LAYOUT_DATA
r=Pt_ARG_WINDOW_HELP_ROOT,Help Root,18020,18020,0,string,NULL
i=PtContainer,1015 // Pt_ARG_HELP_TOPIC
i=PtContainer,1014 // Pt_ARG_USER_DATA

// Callbacks
n=PtContainer,2009 // Pt_CB_ACTIVATE
n=PtContainer,2007 // Pt_CB_ARM
n=PtContainer,2008 // Pt_CB_DISARM
n=PtLabel,2012 // Pt_CB_REPEAT
n=PtWidget,1022 // Pt_CB_OUTBOUND
n=PtContainer,2016 // Pt_CB_MENU
n=PtContainer,10003 // Pt_CB_RESIZE
n=PtContainer,2010 // Pt_CB_GOT_FOCUS
n=PtContainer,2011 // Pt_CB_LOST_FOCUS
c=Pt_CB_WINDOW,Window Manager,18017,4013
c=Pt_CB_WINDOW_OPENING,Window Opening,18023,18023
c=Pt_CB_WINDOW_CLOSING,Window Closing,18024,18024
c=Pt_CB_WINDOW_TRANSPORT,Window Transported,18021,18021
n=PtContainer,1010 // Pt_CB_HOTKEY
n=PtWidget,1026 // Pt_CB_FILTER
n=PtContainer,1011 // Pt_CB_RAW
n=PtContainer,10006 // Pt_CB_FILTER
n=PtContainer,1012 // Pt_CB_REALIZED
n=PtContainer,1013 // Pt_CB_UNREALIZED
n=PtContainer,1009 // Pt_CB_DESTROYED
n=PtWidget,1020 // Pt_CB_DND
c=Pt_CB_BLOCKED,Blocked,1016,1016


//ptmywindow.h

#ifndef __PTMYWINDOW_H_INCLUDED
#define __PTMYWINDOW_H_INCLUDED


#ifndef __PT_WINDOW_H_INCLUDED
#include <photon/PtWindow.h>
#endif


#include <photon/PpT.h>
#include <photon/PhPack.h>

#ifdef __cplusplus
extern “C” {
#endif

/*

  • PtMyWindow public
    */

extern PtWidgetClassRef_t *PtMyWindow;

/* Widget structure */
typedef struct Pt_my_window_widget {
PtWindowWidget_t def_window;
} PtMyWindowWidget_t;

/* Widget union */
typedef union Pt_my_window_union {
PtWidget_t core;
PtBasicWidget_t basic;
PtContainerWidget_t container;
PtDisjointWidget_t disjoint;
PtWindowWidget_t window;
PtMyWindowWidget_t mywindow;
} PtMyWindowUnion_t;
#ifdef __cplusplus
};
#endif

#include <photon/PhPackPop.h>

#endif //PTMYWINDOW_H

//ptmywindow.c


#include <Ph.h>
#include <photon/PpProto.h>
#include <stdlib.h>
#include <string.h>

#include “ptmywindow.h”

static PtWidgetClass_t *PtCreateWindowClass( void );
static PtWidgetClassRef_t window_class_ref = { NULL,
PtCreateWindowClass };
PtWidgetClassRef_t *PtMyWindow = &window_class_ref;

//
// Defaults Function
//

static void window_dflts( PtWidget_t *widget )
{
PtMyWindowWidget_t *window = (PtMyWindowWidget_t *)widget;

PtSetResource( widget, Pt_ARG_FILL_COLOR, Pg_BLUE, 0 );
PtSetResource( widget,Pt_ARG_COLOR,Pg_RED,0);
PtSetResource( widget,Pt_ARG_WINDOW_TITLE,“DSI2”,0);
}


static PtWidgetClass_t *PtCreateWindowClass( void )
{
static const PtClassArg_t args[] = {
{ Pt_SET_DFLTS_F, (long) window_dflts },
{ Pt_SET_DESCRIPTION, (long) “PtMyWindow” },
};
static const PtArg_t roargs[] = {
{ Pt_SET_VERSION, 110 },
{ Pt_SET_STATE_LEN, sizeof( PtMyWindowWidget_t ) },
//{ Pt_SET_FLAGS, Pt_TRUE, Pt_DISJOINT },
//{Pt_SET_FLAGS,Pt_TRUE,Pt_CONTAINER},
//{ Pt_SET_NUM_RESOURCES, sizeof( resources )/sizeof( resources[0] )
},
};

return( PtMyWindow->wclass = PtCreateOptWidgetClass(
PtWindow, 0, sizeof( args )/sizeof( args[0] ), args
,sizeof(roargs)/sizeof(roargs[0]),roargs) );
}

jinma wrote:

Let me just post my PtMyWindow class code and ptpalette and
mywindow.pal

That’s interesting – I just copied this to palette.def and mywindow.pal
and PhAB allowed me change the class of PtWindows to PtMyWindow and
save it as a template and create new ones from the template. Are you
running 6.3 SP2 or something older?

One thing worth mentioning is that PhAB never uses a real PtWindow or
PtRegion or your PtMyWindow for the main container of a module. Since
those widgets are disjoint, it wouldn’t be possible to make them stay
inside PhAB’s workspace. Instead, PhAB uses a simple container with a
fake window frame around it (you get the frame even for a widget that
never has a frame, such as a PtRegion). But PhAB remembers what class
the widget is really supposed to be, and generates references to that
class in your app’s code.

I am running 6.3 SP2.
I guess I didn’t make my self clear. I could do that too, but I
doesn’t happen it when I change my PtWindows to PtMyWindows Class,
the GUI doesn’t change to the default values I set for PtMywindows
Class. If you look at my ptmywindow.c file I have a default function
which sets the title and fill color etc. I expect when I change from
PtWindow to PtMyWindow class these default values are shown in PhAB
but it is not. To me it just seems like the Class has been changed
but the resources are still PtWindow. Any idea why?

//
// Defaults Function
//

static void window_dflts( PtWidget_t *widget )
{
PtMyWindowWidget_t *window = (PtMyWindowWidget_t *)widget;

PtSetResource( widget, Pt_ARG_FILL_COLOR, Pg_BLUE, 0 );
PtSetResource( widget,Pt_ARG_COLOR,Pg_RED,0);
PtSetResource( widget,Pt_ARG_WINDOW_TITLE,“DSI2”,0);
}

jinma wrote:

I am running 6.3 SP2.
I guess I didn’t make my self clear. I could do that too, but I
doesn’t happen it when I change my PtWindows to PtMyWindows Class,
the GUI doesn’t change to the default values I set for PtMywindows
Class. If you look at my ptmywindow.c file I have a default function
which sets the title and fill color etc. I expect when I change from
PtWindow to PtMyWindow class these default values are shown in PhAB
but it is not. To me it just seems like the Class has been changed
but the resources are still PtWindow. Any idea why?

PhAB takes the defaults from your mywindow.pal file, not from your code.
You need to change the lines

r=Pt_ARG_WINDOW_TITLE,Window Title,18015,4008,0,string,Untitled
i=PtContainer,2002 // Pt_ARG_FILL_COLOR

to

r=Pt_ARG_WINDOW_TITLE,Window Title,18015,4008,0,string,DSI2
r=Pt_ARG_FILL_COLOR,Color: Fill,2002,2001,1,crgb,0xFF

and add a line for Pt_ARG_COLOR:

r=Pt_ARG_COLOR,Color: Pen,2001,2000,1,crgb,0xFF0000

BTW I don’t think PtWindow uses Pt_ARG_COLOR for anything, does it?


//
// Defaults Function
//

static void window_dflts( PtWidget_t *widget )
{
PtMyWindowWidget_t *window = (PtMyWindowWidget_t *)widget;

PtSetResource( widget, Pt_ARG_FILL_COLOR, Pg_BLUE, 0 );
PtSetResource( widget,Pt_ARG_COLOR,Pg_RED,0);
PtSetResource( widget,Pt_ARG_WINDOW_TITLE,“DSI2”,0);
}

Yes, mywindow.pal file is used to set the default value of what is
shown in PhAB but just because you changed the values in mywindow.pal
it doesn’t automatically create ptmywindow object with these default
values. For example, I can change all I want on a ptpalette.pal file
on PtWindows to have these values:

r=Pt_ARG_WINDOW_TITLE,Window Title,18015,4008,0,string,DSI2
r=Pt_ARG_FILL_COLOR,Color: Fill,2002,2001,1,crgb,0xFF

but when I actually create a new window in PhAB I will not see 0xff
color nor DSI2 window, even though that is what is indicated in the
resource window. I would like my ptmywindow to have these default
values as soon as I create it in PhAB.

jinma wrote:

Yes, mywindow.pal file is used to set the default value of what is
shown in PhAB but just because you changed the values in mywindow.pal
it doesn’t automatically create ptmywindow object with these default
values. For example, I can change all I want on a ptpalette.pal file
on PtWindows to have these values:

r=Pt_ARG_WINDOW_TITLE,Window Title,18015,4008,0,string,DSI2
r=Pt_ARG_FILL_COLOR,Color: Fill,2002,2001,1,crgb,0xFF

but when I actually create a new window in PhAB I will not see 0xff
color nor DSI2 window, even though that is what is indicated in the
resource window. I would like my ptmywindow to have these default
values as soon as I create it in PhAB.

Since PhAB doesn’t use actual PtWindow or PtMyWindow widgets to display
your modules, they may not look exactly the same way in PhAB as they do
at runtime. In particular, PhAB borrows the title bar of the window
frame to display the name of the module. Is the window title not set to
“DSI2” when you actually run your application?

How are you creating a new window? If you’re creating it from a
template, it’s possible that the template overrides the default fill
colour. Take a look at its resource list – is “Color: Fill” displayed
in a bold font? If it is, you’ll need to click on it and then on the
“Default” button in the colour editor, and re-save your template.

Another thing about the fill colour indeed looks like a bug though.
From my experimenting, it seems that when you change the class of a
module’s main widget, PhAB forgets to apply any new default values to
the container on the screen. In particular, if the new class has a
different default fill colour, the widget is displayed with the old
colour until you minimize the module, or go to test mode and back, or
save and re-open the application.