home *** CD-ROM | disk | FTP | other *** search
Text File | 1993-07-02 | 5.2 KB | 194 lines | [TEXT/KAHL] |
- /**********************************************************************
- CRawText.c
-
- A Pane containing a text string
-
- This is a text string that can be left justified, center justified,
- or right justified. For now, we can just set it LEFT justified.
-
- The pane's size will be changed depending on the text size. For
- instance, when the text is LEFT justified, the RIGHT side of the
- pane will move out (or in) to just fit the text to be displayed.
-
- **********************************************************************/
-
- #include "Global.h"
- #include "CView.h"
- #include "CPane.h"
- #include "CBureaucrat.h"
- #include "CRawText.h"
- #include "TBUtilities.h"
- #include <time.h>
- #include <stdio.h>
-
- /**********************************************************************
-
- **********************************************************************/
- void CRawText::IRawText(CView *anEnclosure, CBureaucrat *aSupervisor,
- ConstStr255Param theText, short Hencl, short Vencl,
- short iWidth, short iHeight,
- short afont, Style astyle, short asize,
- short ajustification)
- {
- /*
- * We set the pane to have no height or width yet until
- * after we create it. Then later, we will change
- * the height and width depending on the font, style, and
- * size chosen as input.
- */
-
- CPane::IPane(anEnclosure, aSupervisor, iWidth, iHeight,
- Hencl, Vencl, sizFIXEDLEFT, sizFIXEDTOP);
-
- /*
- * Initialize out instance variables, first set font and
- * size and style, then set justification.
- */
-
- SetText(theText, ajustification);
- SetTextFont(afont, asize, astyle);
- SetWantsClicks(TRUE);
- }
-
- /*******************************************************************
-
- *******************************************************************/
- void CRawText::JustifyText(short just)
- {
-
- FontInfo fi;
-
- Prepare();
-
- TextFont(font);
- TextFace(style);
- TextSize(size);
-
- /*
- * Now, we set the text width according to our text
- * and the justification.
- */
-
- textWidth = StringWidth(itsText);
- justification = just;
-
- /*
- * Depending on justification value, set the start
- * position of the text.
- */
-
-
- GetFontInfo(&fi);
-
- TextPosn.v = fi.ascent + fi.descent + fi.leading;
-
- switch(justification) {
-
- case teJustLeft:
- TextPosn.h = 1;
- break;
-
- case teJustCenter:
- if (textWidth > width) {
- TextPosn.h = 1; /* Insure first chrs */
- } else {
- TextPosn.h = (width - textWidth)/2;
- }
- break;
-
- case teJustRight:
- if (textWidth > width) {
- TextPosn.h = 1;
- } else {
- TextPosn.h = (width - textWidth) - 3;
- }
- break;
- }
- }
-
- /**********************************************************************
-
- **********************************************************************/
- void CRawText::Draw(Rect *area)
- {
- TextFont(font);
- TextFace(style);
- TextSize(size);
- MoveTo(TextPosn.h, TextPosn.v - 3);
- DrawString(itsText);
- }
-
- /********************************************************************
-
- *********************************************************************/
- void CRawText::DoClick(Point hitPt, short modifierKeys, long when)
- {
- Rect aFrame;
-
- Prepare();
- SetRect(&aFrame, 0, 0, width-1, height-1);
- FrameRect(&aFrame);
- }
-
- /*********************************************************************
-
- *********************************************************************/
- void CRawText::PutValue(long aValue)
- {
- Str255 string;
-
- NumToString(aValue, string);
- SetText(string, teJustRight);
-
- }
-
- /**********************************************************************
-
- **********************************************************************/
- void CRawText::SetText(ConstStr255Param newText, short just)
- {
- CopyPString(newText, itsText);
- JustifyText(just);
- Refresh();
- }
- /*********************************************************************
-
- *********************************************************************/
- void CRawText::SetTextFont(short afont, short asize, Style astyle)
- {
- font = afont;
- style = astyle;
- size = asize;
- JustifyText(justification);
- }
-
-
- /**********************************************************************
-
- **********************************************************************/
- void CTimeText::ITimeText(CView *anEnclosure, CBureaucrat *aSupervisor,
- ConstStr255Param theText, short Hencl, short Vencl,
- short iWidth, short iHeight,
- short afont, Style astyle, short asize,
- short ajustification)
- {
- IRawText(anEnclosure, aSupervisor, theText, Hencl, Vencl, iWidth, iHeight, afont, astyle, asize, ajustification);
- }
-
- /*********************************************************************
- aValue is microseconds of time.
-
- *********************************************************************/
- void CTimeText::PutValue(long aValue)
- {
- unsigned long value = (unsigned long)aValue;
- unsigned long thous = ((value % 1000000) / 100); // get thousandths of seconds
- unsigned long secs = ((value / 0x100000) % 60); // get seconds
- unsigned long mins = (value / (0x100000 * 60)); // get minutes
- Str255 string;
-
- sprintf((char *)&string[1], "%2.0lu:%2.2lu.%4.4lu", mins, secs, thous);
- string[0] = 11;
- SetText(string, teJustRight);
- }
-