home *** CD-ROM | disk | FTP | other *** search
/ MacFormat 1995 May / macformat-024.iso / Shareware City / Developers / BoxMaker++ / ll-R ƒ / ll_r_shell.h < prev    next >
Encoding:
C/C++ Source or Header  |  1995-01-20  |  2.8 KB  |  139 lines  |  [TEXT/KAHL]

  1.  
  2. class ll_r_settings
  3. {
  4.     public:
  5.         enum
  6.         {
  7.             kType = 1,
  8.             kCreator,
  9.             kSize,
  10.             kCreatDate,
  11.             kModDate,
  12.             kBakDate,
  13.             kTimes,
  14.  
  15.             kTabs,
  16.             kSpaces,
  17.             kAskFileName,
  18.             kIndentFolders,
  19.             kNumButtons
  20.         };
  21.         Boolean myPrefs[ kNumButtons];
  22. };
  23.  
  24. typedef preferences<ll_r_settings> ll_r_prefs;
  25.  
  26. #pragma template preferences<ll_r_settings>;
  27.  
  28. class ll_r_shell : public boxmaker, public ll_r_prefs
  29. {
  30.     public:
  31.         ll_r_shell( Str255 prefsFileName, ll_r_settings defaultsettings);
  32.         ~ll_r_shell();
  33.  
  34.         virtual void EnterFolder( Boolean opening);
  35.         virtual void OpenDoc( Boolean opening);
  36.         virtual void CantEnterFolder( Boolean opening);
  37.         virtual void ExitFolder( Boolean opening);
  38.  
  39.         virtual void StartABunch( long numTopLevelItems, Boolean opening);
  40.  
  41.         virtual void HandleDialogEvent( short itemHit, DialogPtr theDialog);
  42.  
  43.     private:
  44.         short outFileNo;
  45.         long  outVRefNum;
  46.                 
  47.         void SetupDialog( DialogPtr theDialog);
  48.         void FlipButton( DialogPtr theDialog, short theItem);
  49.  
  50.         long indentationLevel;
  51.         unsigned char plentySpace[ 1000];
  52.         unsigned char delimiter;
  53.         //
  54.         // 'append' appends the specified string to 'plentySpace'
  55.         // without checking for running out of space. It uses and
  56.         // updates 'currentEnd', and also appends a delimiter as
  57.         // specified by the preferences.
  58.         //
  59.         unsigned char *currentEnd;
  60.         void append( char letter);
  61.         void append( char *item, int len);
  62.         void append( unsigned char *item);        // appends a Pascal string
  63.         void append( char *item);                // appends a C string
  64.         void appendDate( unsigned long seconds);
  65.         void append2Digits( short number);
  66.         void RemoveLastChar();
  67.         void ChangeLastToNewLine();
  68.         void StartNewLine();
  69.         long KiloBytes( long bytes);
  70. };
  71.  
  72. inline void ll_r_shell::EnterFolder( Boolean opening)
  73. {
  74.     if( myPrefs[ kIndentFolders])
  75.     {
  76.         //
  77.         // Note: we do not use 'delimiter' for the first characters.
  78.         // Instead we always use a tab there. I think this looks nicer.
  79.         //
  80.         plentySpace[ indentationLevel] = '\t';
  81.         indentationLevel += 1;
  82.     }
  83. }
  84.  
  85. inline void ll_r_shell::ExitFolder( Boolean opening)
  86. {
  87.     if( myPrefs[ kIndentFolders])
  88.     {
  89.         indentationLevel -= 1;
  90.     }
  91. }
  92.  
  93. inline void ll_r_shell::append( char letter)
  94. {
  95.     *currentEnd++ = letter;
  96. }
  97.  
  98. inline void ll_r_shell::append( unsigned char *item)
  99. {
  100.     const int len = *item;
  101.     append( (char *)item + 1, len);
  102. }
  103.  
  104. inline void ll_r_shell::append( char *item)
  105. {
  106.     while( *item != 0)
  107.     {
  108.         *currentEnd++ = *item++;
  109.     }
  110. }
  111.  
  112. inline void ll_r_shell::append2Digits( short number)
  113. {
  114.     const short lastdigit  = number % 10;
  115.     const short firstdigit = (number / 10) % 10;
  116.     append( firstdigit + '0');
  117.     append( lastdigit  + '0');
  118. }
  119.  
  120. inline void ll_r_shell::RemoveLastChar()
  121. {
  122.     currentEnd -= 1;
  123. }
  124.  
  125. inline void ll_r_shell::ChangeLastToNewLine()
  126. {
  127.     currentEnd[ -1] = '\r';
  128. }
  129.  
  130. inline void ll_r_shell::StartNewLine()
  131. {
  132.     currentEnd = &plentySpace[ indentationLevel];
  133. }
  134.  
  135. inline long ll_r_shell::KiloBytes( long bytes)
  136. {
  137.     return ((bytes + 1023) >> 10);
  138. }
  139.