home *** CD-ROM | disk | FTP | other *** search
- {$if not def UTILITY_PACK_MACROS_H} CONST UTILITY_PACK_MACROS_H=true;
-
- { ****************************************************************
- ** KickPascal-Include-Datei "utility/pack.h" zu Kickstart 3.0 **
- ** Ergänzung der MACROS als Pascal FUNCTIONen by JS **
- **************************************************************** }
-
- {$if not def UTILITY_PACK_H;incl "utility/pack.h";endif}
-
- Function PK_BITNUM1(flg:Long):Long;
- begin
- case flg of
- $01: PK_BITNUM1:=0;
- $02: PK_BITNUM1:=1;
- $04: PK_BITNUM1:=2;
- $08: PK_BITNUM1:=3;
- $10: PK_BITNUM1:=4;
- $20: PK_BITNUM1:=5;
- $40: PK_BITNUM1:=6;
- else
- PK_BITNUM1:=7;
- end;
- end;
- Function PK_BITNUM2(flg:Long):Long;
- begin
- if flg<$100 then
- PK_BITNUM2:=PK_BITNUM1(flg)
- else
- PK_BITNUM2:=8+PK_BITNUM1(flg shr 8);
- end;
- Function PK_BITNUM(flg:Long):Long;
- begin
- if flg<$10000 then
- PK_BITNUM:=PK_BITNUM2(flg)
- else
- PK_BITNUM:=16+PK_BITNUM2(flg shr 16);
- end;
- Function PK_WORDOFFSET(flg:Long):Long;
- begin
- if flg<$100 then
- PK_WORDOFFSET:=1
- else
- PK_WORDOFFSET:=0;
- end;
- Function PK_LONGOFFSET(flg:Long):Long;
- begin
- if flg<$1000000 then
- begin
- if flg<$10000 then
- begin
- if flg<$100 then
- begin
- PK_LONGOFFSET:=1;
- end
- else
- begin
- PK_LONGOFFSET:=2;
- end;
- end
- else
- begin
- PK_LONGOFFSET:=3;
- end;
- end
- else
- begin
- PK_LONGOFFSET:=0;
- end;
- end;
- Function PK_CALCOFFSET(t,field:Ptr):Long;
- begin
- PK_CALCOFFSET:=Long(field)-Long(t);
- end;
-
-
- (* Some handy dandy macros to easily create pack tables
- *
- * Use PACK_STARTTABLE() at the start of a pack table. You pass it the
- * base tag value that will be handled in the following chunk of the pack
- * table.
- *
- * PACK_ENDTABLE() is used to mark the end of a pack table.
- *
- * PACK_NEWOFFSET() lets you change the base tag value used for subsequent
- * entries in the table
- *
- * PACK_ENTRY() lets you define an entry in the pack table. You pass it the
- * base tag value, the tag of interest, the type of the structure to use,
- * the field name in the structure to affect and control bits (combinations of
- * the various PKCTRL_XXX bits)
- *
- * PACK_BYTEBIT() lets you define a bit-control entry in the pack table. You
- * pass it the same data as PACK_ENTRY, plus the flag bit pattern this tag
- * affects. This macro should be used when the field being affected is byte
- * sized.
- *
- * PACK_WORDBIT() lets you define a bit-control entry in the pack table. You
- * pass it the same data as PACK_ENTRY, plus the flag bit pattern this tag
- * affects. This macro should be used when the field being affected is word
- * sized.
- *
- * PACK_LONGBIT() lets you define a bit-control entry in the pack table. You
- * pass it the same data as PACK_ENTRY, plus the flag bit pattern this tag
- * affects. This macro should be used when the field being affected is longword
- * sized.
- *
- * EXAMPLE:
- *
- * ULONG packTable[] =
- * {
- * PACK_STARTTABLE(GA_Dummy),
- * PACK_ENTRY(GA_Dummy,GA_Left,Gadget,LeftEdge,PKCTRL_WORD|PKCTRL_PACKUNPACK),
- * PACK_ENTRY(GA_Dummy,GA_Top,Gadget,TopEdge,PKCTRL_WORD|PKCTRL_PACKUNPACK),
- * PACK_ENTRY(GA_Dummy,GA_Width,Gadget,Width,PKCTRL_UWORD|PKCTRL_PACKUNPACK),
- * PACK_ENTRY(GA_Dummy,GA_Height,Gadget,Height,PKCTRL_UWORD|PKCTRL_PACKUNPACK),
- * PACK_WORDBIT(GA_Dummy,GA_RelVerify,Gadget,Activation,PKCTRL_BIT|PKCTRL_PACKUNPACK,GACT_RELVERIFY)
- * PACK_ENDTABLE
- * };
- *)
-
- (* Änderungen gegenüber C-Original:
- Type - Feld (t) und field - Feld sind Pointer auf einen RECORD und ein Feld daraus.
-
- entsprechende Änderung im Beispiel:
-
- PACK_ENTRY(GA_Dummy,GA_Left,^gg,^gg.LeftEdge,PKCTRL_WORD or PKCTRL_PACKUNPACK),
-
- wobei für gg gilt:
- VAR gg:Gadget;
- *)
-
- Function PACK_STARTTABLE(tagbase:Long):Long;
- begin
- PACK_STARTTABLE:=tagbase;
- end;
-
- {Function PACK_NEWOFFSET(tagbase:Long):Long;
- begin
- (* (-1),(tagbase)
- mehrere Ergebnisse in KP nicht möglich! *)
- end;}
-
- Function PACK_ENDTABLE:Long;
- begin
- PACK_ENDTABLE:=0;
- end;
-
- (* Function gegenüber C geändert *)
- Function PACK_ENTRY(tagbase,tag:Long;t,field:Ptr;control:Long):Long;
- begin
- PACK_ENTRY:=(control or ((tag-tagbase) shl 16) or PK_CALCOFFSET(t,field));
- end;
-
- Function PACK_BYTEBIT(tagbase,tag:Long;t,field:Ptr;control,flags:Long):Long;
- begin
- PACK_BYTEBIT:=(control or ((tag-tagbase) shl 16) or PK_CALCOFFSET(t,field) or (PK_BITNUM(flags) shl 13));
- end;
-
- Function PACK_WORDBIT(tagbase,tag:Long;t,field:Ptr;control,flags:Long):Long;
- begin
- PACK_WORDBIT:=(control or ((tag-tagbase) shl 16) or (PK_CALCOFFSET(t,field)+PK_WORDOFFSET(flags)) or ((PK_BITNUM(flags)and 7) shl 13));
- end;
-
- Function PACK_LONGBIT(tagbase,tag:Long;t,field:Ptr;control,flags:Long):Long;
- begin
- PACK_LONGBIT:=(control or ((tag-tagbase) shl 16) or (PK_CALCOFFSET(t,field)+PK_LONGOFFSET(flags)) or ((PK_BITNUM(flags)and 7) shl 13));
- end;
-
- {$endif}
-