1 /******************************************************************************
3 * COPYRIGHT: Unless otherwise noted, all files are Copyright (c) 1992-1999
4 * Amiga, Inc. All rights reserved.
6 * DISCLAIMER: This software is provided "as is". No representations or
7 * warranties are made with respect to the accuracy, reliability, performance,
8 * currentness, or operation of this software, and all use is at your own risk.
9 * Neither Amiga nor the authors assume any responsibility or liability
10 * whatsoever with respect to your use of this software.
12 ******************************************************************************
14 * How to embed a DataType object within an Intuition window
15 * Written by David N. Junod
19 #include <exec/types.h>
20 #include <exec/memory.h>
21 #include <exec/libraries.h>
23 #include <dos/rdargs.h>
24 #include <datatypes/datatypes.h>
25 #include <datatypes/datatypesclass.h>
26 #include <datatypes/pictureclass.h>
27 #include <intuition/intuition.h>
28 #include <intuition/icclass.h>
29 #include <graphics/gfx.h>
30 #include <graphics/displayinfo.h>
35 #include <proto/alib.h>
36 #include <proto/datatypes.h>
37 #include <proto/dos.h>
38 #include <proto/exec.h>
39 #include <proto/graphics.h>
40 #include <proto/intuition.h>
41 #include <proto/utility.h>
43 /*****************************************************************************/
46 struct IntuitionBase
*IntuitionBase
;
47 struct GfxBase
*GfxBase
;
48 struct UtilityBase
*UtilityBase
;
49 struct Library
*DataTypesBase
;
51 /*****************************************************************************/
53 #define TEMPLATE "NAME/A"
57 /*****************************************************************************/
59 #define IDCMP_FLAGS IDCMP_CLOSEWINDOW | IDCMP_VANILLAKEY | IDCMP_IDCMPUPDATE
61 /*****************************************************************************/
63 void PrintErrorMsg (ULONG errnum
, STRPTR name
)
67 if (errnum
>= DTERROR_UNKNOWN_DATATYPE
)
68 sprintf (errbuff
, GetDTString (errnum
), name
);
70 Fault (errnum
, NULL
, errbuff
, sizeof (errbuff
));
72 printf ("%s\nerror #%ld\n", errbuff
, (long)errnum
);
75 /*****************************************************************************/
77 int main (int argc
, char **argv
)
82 ULONG modeid
= INVALID_ID
;
83 ULONG nomwidth
, nomheight
;
84 BOOL useScreen
= FALSE
;
85 struct dtFrameBox dtf
;
91 struct IntuiMessage
*imsg
;
94 const struct TagItem
*tstate
;
100 IPTR options
[NUM_OPTS
];
101 struct RDArgs
*rdargs
;
103 /* Parse the arguments. Note that this simple example assumes
104 * that it was started from the shell. */
105 memset (options
, 0, sizeof (options
));
106 if ((rdargs
= ReadArgs (TEMPLATE
, options
, NULL
)))
109 if ((DataTypesBase
= OpenLibrary ("datatypes.library", 39)))
111 /* Open the other libraries */
112 IntuitionBase
= (struct IntuitionBase
*)OpenLibrary ("intuition.library", 39);
113 GfxBase
= (struct GfxBase
*)OpenLibrary ("graphics.library", 39);
114 UtilityBase
= (struct UtilityBase
*)OpenLibrary ("utility.library", 39);
116 /* Get a DataType object */
117 if ((dto
= NewDTObject ((APTR
) options
[OPT_NAME
], TAG_DONE
, TAG_DONE
)))
119 /* Get information about the object */
121 /* Get the name of the object */
122 DTA_ObjName
, (IPTR
) &name
,
124 /* Get the desired size */
125 DTA_NominalHoriz
, (IPTR
) &nomwidth
,
126 DTA_NominalVert
, (IPTR
) &nomheight
,
128 /* Get the mode ID for graphical objects */
129 PDTA_ModeID
, (IPTR
) &modeid
,
133 /* Display any information we obtained */
135 printf ("opened \"%s\"\n", name
);
137 /* Show the mode ID */
138 printf ("mode ID %08lx\n", (unsigned long)modeid
);
140 /* Display the nominal size */
141 printf ("nominal width %ld, height %ld\n", (long)nomwidth
, (long)nomheight
);
144 /* Ask the object what kind of environment it needs */
145 memset (&dtf
, 0, sizeof (struct dtFrameBox
));
146 memset (&fri
, 0, sizeof (struct FrameInfo
));
147 dtf
.MethodID
= DTM_FRAMEBOX
;
148 dtf
.dtf_FrameInfo
= &fri
;
149 dtf
.dtf_ContentsInfo
= &fri
;
150 dtf
.dtf_SizeFrameInfo
= sizeof (struct FrameInfo
);
152 if (DoDTMethodA (dto
, NULL
, NULL
, (Msg
) &dtf
) && fri
.fri_Dimensions
.Depth
)
154 printf ("PropertyFlags : 0x%lx\n", (unsigned long)fri
.fri_PropertyFlags
);
155 printf ("RedBits : 0x%x\n", fri
.fri_RedBits
);
156 printf ("GreenBits : 0x%x\n", fri
.fri_GreenBits
);
157 printf ("BlueBits : 0x%x\n", fri
.fri_BlueBits
);
158 printf ("Width : %ld\n", (long) fri
.fri_Dimensions
.Width
);
159 printf ("Height : %ld\n", (long) fri
.fri_Dimensions
.Height
);
160 printf ("Depth : %ld\n", (long) fri
.fri_Dimensions
.Depth
);
161 printf ("Screen : 0x%p\n", fri
.fri_Screen
);
162 printf ("ColorMap : 0x%p\n", fri
.fri_ColorMap
);
164 if ((fri
.fri_PropertyFlags
& DIPF_IS_HAM
) ||
165 (fri
.fri_PropertyFlags
& DIPF_IS_EXTRAHALFBRITE
))
167 printf ("HAM or ExtraHalfBrite\n");
171 if ((fri
.fri_PropertyFlags
== 0) && (modeid
& 0x800) && (modeid
!= INVALID_ID
))
173 printf ("ModeID=0x%08lx\n", (unsigned long)modeid
);
178 printf ("couldn't obtain environment information\n");
182 printf ("this object requires a private screen\n");
184 /* Get a lock on the default public screen */
185 else if ((scr
= LockPubScreen (NULL
)))
187 /* Make sure we have the dimensions */
188 nomwidth
= ((nomwidth
) ? nomwidth
: 600);
189 nomheight
= ((nomheight
) ? nomheight
: 175);
191 /* Open the window */
193 if ((win
= OpenWindowTags (NULL
,
194 WA_InnerWidth
, nomwidth
,
195 WA_InnerHeight
, nomheight
,
196 WA_Title
, (IPTR
) name
,
197 WA_IDCMP
, IDCMP_FLAGS
,
199 WA_DepthGadget
, TRUE
,
200 WA_CloseGadget
, TRUE
,
202 WA_SimpleRefresh
, TRUE
,
203 WA_BusyPointer
, TRUE
,
206 WA_SizeBBottom
, TRUE
,
215 /* Set the dimensions of the DataType object. */
216 SetDTAttrs (dto
, NULL
, NULL
,
217 GA_Left
, win
->BorderLeft
,
218 GA_Top
, win
->BorderTop
,
219 GA_RelWidth
, - win
->BorderLeft
- win
->BorderRight
,
220 GA_RelHeight
, - win
->BorderTop
- win
->BorderBottom
,
221 ICA_TARGET
, ICTARGET_IDCMP
,
224 /* Add the object to the window */
225 AddDTObject (win
, NULL
, dto
, -1);
227 /* Refresh the DataType object */
228 RefreshDTObjectA (dto
, win
, NULL
, NULL
);
230 /* Keep going until we're told to stop */
233 /* Wait for an event */
234 sigr
= Wait ((1L << win
->UserPort
->mp_SigBit
) | SIGBREAKF_CTRL_C
);
236 /* Did we get a break signal */
237 if (sigr
& SIGBREAKF_CTRL_C
)
240 /* Pull Intuition messages */
241 while ((imsg
= (struct IntuiMessage
*) GetMsg (win
->UserPort
)))
243 /* Handle each message */
246 case IDCMP_CLOSEWINDOW
:
250 case IDCMP_VANILLAKEY
:
261 case IDCMP_IDCMPUPDATE
:
262 tstate
= tags
= (struct TagItem
*) imsg
->IAddress
;
263 while ((tag
= NextTagItem(&tstate
)))
265 tidata
= tag
->ti_Data
;
268 /* Change in busy state */
271 SetWindowPointer (win
, WA_BusyPointer
, TRUE
, TAG_DONE
);
273 SetWindowPointer (win
, WA_Pointer
, NULL
, TAG_DONE
);
280 errnum
= GetTagData (DTA_ErrorNumber
, 0, tags
);
281 PrintErrorMsg (errnum
, (STRPTR
) options
[OPT_NAME
]);
285 /* Time to refresh */
287 /* Refresh the DataType object */
288 RefreshDTObjectA (dto
, win
, NULL
, NULL
);
295 /* Done with the message, so reply to it */
296 ReplyMsg ((struct Message
*) imsg
);
300 /* Remove the object from the window */
301 RemoveDTObject (win
, dto
);
303 /* Close the window now */
307 printf ("couldn't open window\n");
309 /* Unlock the screen */
310 UnlockPubScreen (NULL
, scr
);
313 printf ("couldn't lock default public screen\n");
315 /* Dispose of the DataType object */
316 DisposeDTObject (dto
);
319 PrintErrorMsg (IoErr (), (STRPTR
) options
[OPT_NAME
]);
321 /* Close the libraries */
322 CloseLibrary ((struct Library
*)UtilityBase
);
323 CloseLibrary ((struct Library
*)GfxBase
);
324 CloseLibrary ((struct Library
*)IntuitionBase
);
325 CloseLibrary (DataTypesBase
);
328 printf ("couldn't open datatypes.library\n");
333 PrintErrorMsg (IoErr (), NULL
);