home *** CD-ROM | disk | FTP | other *** search
- #include "LabelDef.h"
- #include <exec/memory.h>
- #include <libraries/dos.h>
-
-
- void
- ChangeCoords( The_Text, NewY)
- struct LabelText *The_Text;
- int NewY;
- {
- if ( The_Text != NULL)
- {
- The_Text->TopEdge = NewY;
- }
- }
-
-
-
- void
- ChangeText( The_Text, FontName, Size, Style,
- Align, Place, Border, BgCol, FgCol, Text, AttrNr)
- struct LabelText *The_Text;
- BYTE *FontName, *Text;
- int Size, Style, Align, Place, Border, BgCol, FgCol, AttrNr;
- {
- int help;
-
- if ( The_Text != NULL)
- {
- help = Size +1;
- if ( Border & LTB_TOP) help++;
- if ( Border & LTB_BOTTOM) help++;
- strncpy( &The_Text->FontName[0], FontName, 21);
- strncpy( &The_Text->Text[0], Text, 61);
- The_Text->AttrNumber = (LONG) AttrNr;
- The_Text->FontSize = (SHORT)(Size);
- The_Text->Style = (BYTE)(Style);
- The_Text->Alignment = (BYTE)(Align);
- The_Text->Placement = (BYTE)(Place);
- The_Text->Border = (BYTE)(Border);
- The_Text->BgColor = (BYTE)(BgCol);
- The_Text->FgColor = (BYTE)(FgCol);
- The_Text->Width = (SHORT)(help);
- }
-
- }
-
-
-
- struct LabelText
- *CreateText( FontName, Size, Style, Align, Place, Border,
- BgCol, FgCol, Text, AttrNr)
- BYTE *FontName, *Text;
- int Size, Style, Align, Place, Border, BgCol, FgCol, AttrNr;
- {
- struct LabelText *HelpText;
-
- HelpText = NULL;
- if (HelpText = AllocMem( sizeof( struct LabelText), MEMF_PUBLIC))
- {
- HelpText->PrevText = NULL;
- HelpText->NextText = NULL;
- ChangeText( HelpText, FontName, Size, Style,
- Align, Place, Border, BgCol, FgCol, Text, AttrNr);
- ChangeCoords( HelpText, 0);
- }
- return( HelpText);
- }
-
-
-
- struct LabelText
- *DeleteText( The_Text)
- struct LabelText *The_Text;
- {
- struct LabelText *Before, *After, *Back;
-
- Back = NULL;
- if ( The_Text != NULL)
- {
- Before = The_Text->PrevText;
- After = The_Text->NextText;
- if ( After != NULL)
- {
- After->PrevText = Before;
- Back = After;
- }
- if ( Before != NULL)
- {
- Before->NextText = After;
- Back = Before;
- }
- FreeMem( The_Text, sizeof( struct LabelText));
- }
- return( Back);
- }
-
-
-
- struct LabelText
- *InsertText( Location, The_Text, Where)
- struct LabelText *Location, *The_Text;
- int Where;
- {
- struct LabelText *Back, *Help;
-
- Back = NULL;
- if (( Location != NULL)&&( The_Text != NULL)&&(Location != The_Text))
- {
- Back = The_Text;
- if ( Where == 1) /* before */
- {
- Help = Location->PrevText;
- if ( Help != NULL) Help->NextText = The_Text;
- Location->PrevText = The_Text;
- The_Text->PrevText = Help;
- The_Text->NextText = Location;
- }
- else /* after */
- {
- Help = Location->NextText;
- if ( Help != NULL) Help->PrevText = The_Text;
- Location->NextText = The_Text;
- The_Text->PrevText = Location;
- The_Text->NextText = Help;
- }
- }
- return( Back);
- }
-
-
-
- struct LabelText
- *ReplaceText( The_Text, Dest_Text, Where)
- struct LabelText *The_Text, *Dest_Text;
- int Where;
- {
- struct LabelText *Back, *Help, *Before, *After;
-
- Back = NULL;
- if (( The_Text != NULL)&&(Dest_Text != NULL)&&(The_Text != Dest_Text))
- {
- Help = The_Text;
- Before = Help->PrevText;
- After = Help->NextText;
- if ( After != NULL)
- {
- After->PrevText = Before;
- }
- if ( Before != NULL)
- {
- Before->NextText = After;
- }
- Back = InsertText( Dest_Text, The_Text, Where);
- }
- return( Back);
- }
-
-
-
- struct LabelText
- *FindStart( The_Text)
- struct LabelText *The_Text;
- {
- struct LabelText *Back;
-
- Back = The_Text;
- if ( Back != NULL)
- {
- while ( Back->PrevText != NULL)
- {
- Back = Back->PrevText;
- }
- }
- return( Back);
- }
-
-
-
- struct LabelText
- *FindEnd( The_Text)
- struct LabelText *The_Text;
- {
- struct LabelText *Back;
-
- Back = The_Text;
- if ( Back != NULL)
- {
- while ( Back->NextText != NULL)
- {
- Back = Back->NextText;
- }
- }
- return( Back);
- }
-
-
-
- void
- DeleteAllTexts( Start)
- struct LabelText *Start;
- {
- struct LabelText *Back, *Curr, *Begin;
- int finished;
-
- if (Start != NULL)
- {
- Begin = FindStart( Start);
- if (Begin != NULL)
- {
- finished =0;
- while ( finished != 1)
- {
- Back = FindEnd( Begin);
- if ( Back != Begin)
- {
- Curr = Back->PrevText;
- FreeMem( Back, sizeof( struct LabelText));
- if ( Curr != NULL)
- {
- Curr->NextText = NULL;
- }
- else
- {
- finished = 1;
- }
- }
- else
- {
- finished =1;
- if ( Begin != NULL) FreeMem( Begin, sizeof( struct LabelText));
- }
- }
- }
- }
- }
-
-
-
-
- struct LabelText
- *AddText( Root_Text, The_Text)
- struct LabelText *Root_Text, *The_Text;
- {
- struct LabelText *Help_Text, *Back;
-
- Back = NULL;
- if ((Root_Text != NULL)&&(The_Text != NULL)&&(Root_Text != The_Text))
- {
- Help_Text = FindEnd( Root_Text);
- if ( Help_Text != NULL)
- {
- Back = InsertText( Help_Text, The_Text, 2);
- }
- }
- return( Back);
- }
-
-
-
- struct LabelText
- *LoadText( fh)
- struct FileHandle *fh;
- {
- struct LabelText Bxt, *Back;
- BYTE IDBuffer[5];
- LONG LongBuffer;
- LONG LabelTextSize;
- int ok;
-
- Back = NULL;
- LabelTextSize = sizeof( struct LabelText) -12;
- if ((ok = Read( fh, IDBuffer, 4L)) == 4)
- {
- if ( strncmp( IDBuffer, "LMTC", 4) ==0)
- {
- ok = Read( fh, &LongBuffer, 4L);
- if ((ok == 4)&&(LongBuffer == LabelTextSize))
- {
- ok = Read( fh, &Bxt, LabelTextSize);
- if ( ok == LabelTextSize)
- {
- Back = CreateText( Bxt.FontName, Bxt.FontSize, Bxt.Style,
- Bxt.Alignment, Bxt.Placement, Bxt.Border,
- Bxt.BgColor, Bxt.FgColor, Bxt.Text, 0);
- if ( Back != NULL)
- {
- ChangeCoords( Back, Bxt.TopEdge);
- }
- }
- }
- }
- }
- return( Back);
- }
-
-
-
- int
- SaveText( fh, The_Text)
- struct FileHandle *fh;
- struct LabelText *The_Text;
- {
- BYTE IDBuffer[5];
- int back, ok;
- LONG LongBuffer;
- LONG LabelTextSize;
-
- back =0;
- LabelTextSize = sizeof( struct LabelText) -12;
- if ( The_Text != NULL)
- {
- strcpy( IDBuffer, "LMTC");
- if (( ok= Write( fh, IDBuffer, 4L)) == 4)
- {
- LongBuffer = LabelTextSize;
- if (( ok= Write( fh, &LongBuffer, 4L)) == 4)
- {
- ok = Write( fh, The_Text, LabelTextSize);
- if ( ok == LabelTextSize)
- {
- back = 1;
- }
- }
- }
- }
- return( back);
- }
-
-
-