🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: news.software.readers
Article #234007

--

#234007
From: _
Date: Fri, 26 Jun 2009 11:02
586 lines
24877 bytes
Life is just a party and, for me, X.ZIP is hella fun.

I promote homeSpun newsReaders, not X.ZIP per se, not UTF-8.
Honestly, I don't care if you prefer HTML over plainText,
or UTF-7 over UTF-8.

>From  www.JeffRelf.F-M.FM/X.CPP  here's how I handle events...

For example, on re·deActivation, settings are reLoaded and,
if the taskBar changed position ( a screen resolution change ? )
the window is reSized and glyphs are reCached.

X.ZIP employs 123 columns on a maximized window
no matter what the screen resolution might be.
For a 1280 wide screen, that's 10+ pixels per glyph.

Floating point numbers are used a lot.

ScreenShot of X.ZIP showing selected glyphs:
  www.JeffRelf.F-M.FM/UTF-8.PNG

Listing code, like I do here, helps me improve it.
I've commented sections that recently interested me.

__stdcall WinMain( HINSTANCE  PID, HINSTANCE, LPSTR, int ) {  
  insFont( L"DejaVuSansMono.TTF", L"DejaVu Sans Mono (TrueType)" );
  ScrW = ScrRight = GetSystemMetrics( SM_CXSCREEN );
  ScrH = ScrBot = GetSystemMetrics( SM_CYSCREEN );
  ScrLeft = ScrTop = 0, TaskBar = FindWindow( L"Shell_TrayWnd", 0 );

  BSaveAll_VS.vt = VT_BSTR ;
  BSaveAll_VS.bstrVal = SysAllocString( L"File.SaveAll" );
  CoInitialize( 0 );
  rv = CoCreateInstance( 
    CLSID_CMultiLanguage
    , 0, CLSCTX_ALL, IID_IMultiLanguage3, ( void * * ) & Outlook );
    
  FndCS( _CharSet, 0 )  _8_Bit = _CharSet.uiInternetEncoding ;
  QueryPerformanceFrequency( ( DubInt * ) & Secnd ), Secnd_Dub = Secnd ;
  NewHeap;  Int_Div = ( __int64 ( 1 ) << 32 ) * 1000 / Secnd ;
  { LnP CC = L"Aa0+/";  int X = -1 ;
    Loop( strSz ( CC ) ) { 
      int L = J > 2 ? 1 : J == 2 ? 10 : 26 ; wchar_t  C = CC [ J ] - 1 ;
      Loop( L ) A_63 [ _63_A [ X ] = ++ C ] = ++ X ;  } }
  HICON Icon = LoadIcon( PID, L"X" ); RegW( WinProc )
  Win = CreateWindowExW(
    0, L"WinProc", L"", Vis | WS_POPUP, 0,0,0,0, 0, 0, PID, 0 );
  
  DirectDrawCreate( 0, & _Direct_Draw, 0 ); 
  _Direct_Draw->QueryInterface(
     IID_IDirectDraw7, (VOID**) & DirectDraw );
  if ( ! _Direct_Draw ) return ;
  DirectDraw->SetCooperativeLevel( Win, DDSCL_NORMAL );  
  Z.ddsCaps.dwCaps= DDSCAPS_PRIMARYSURFACE;  
  DirectDraw->CreateSurface( & Z, & WinSur, 0 );
  Z.dwFlags |= DDSD_HEIGHT | DDSD_WIDTH ;
  
  GdiplusStartupInput  Plus_;
  GdiplusStartup( ( ulong * ) & rv, & Plus_, 0 );
    
  WhiteInk = CreatePen( PS_SOLID, 2, RGB( 255, 255, 255 ) );
  Black = CreateSolidBrush( 0 );
  SetCursor( LoadCursor( 0, IDC_ARROW ) );
  gEvent(0);
  
  nxEvent:  
  
  //  This is the main event loop.
  Tb_Hit = 0, SetFocus( Win );  while( ! gEvent( Any ) );
  if ( OnUp && ButUp ) {  * ButDwnE = 0 ;
    LoopXx ( Tb, Tb )
      if ( Eq ( ButDwn, P->ButtNym ) ) {
        //  This toolBar item was hit: 
        Tb_Hit = P, * ButDwnE = 32 ;  goto Hit ;  }
    * ButDwnE = 32 ;  }
  goto  nxEvent ;  
      ―――――――――――――――――――
  if (  Eq ( Tb_Hit->Handler, L"GrDown" ) ) {
    //  Save all files in the code editor(Visual Studio)
    //  and downLoad the latest posts for 
    //  the specified newsGroup(Tb_Hit->Newsgroup), e.g. Rdr.TXT
    SaveAll_VS();  TopChatter;
―――――――――――――――――――――――――――――――――――――――――――――――――――――――――
//  The glyph-caching and event handling code...

  CharSurT & CacheGlyph( GyP P, const ulong * Hue );
  const int  Lowest_Ascii = 32, Highest_Ascii = 126 ;
GyP  _Gy( wchar_t  Ch ) {  GyP  P ;  int  Greater_Ch = 0 ;
  if ( Ch >= Lowest_Ascii && Ch <= Highest_Ascii )
    return  Gy.BB [ Ch - Lowest_Ascii ];
  GyA
     BB = Gy.BB + ( Highest_Ascii - Lowest_Ascii + 1 )
   , EE = Gy.PP + 1, PP = BB ;
  LOOP {  PP = BB + ( EE - BB ) / 2 ;  
    if ( PP == Gy.PP + 1 ) {  Greater_Ch = 0 ; break ; } 
    P = * PP ;  Greater_Ch = Ch - P->Ch ;
    if ( ! Greater_Ch )  return  P ;
    if ( Greater_Ch > 0 ) {  if ( PP >= EE )  break ;  BB = PP + 1 ; }
    else {  if ( PP <= BB )  break ;  EE = PP - 1 ; } }
  int  _PP =  PP - Gy.BB ;  ✚✚( Gy );
  EE = Gy.PP + 1, PP = Gy.BB + _PP ;  int  After = EE - PP - 1 ;
  if ( Greater_Ch > 0 )  PP ++, -- After ;
  if ( After > 0 )  memmove( PP + 1, PP, After * szPtr );
  * PP = P = ( GyP ) Malloc ( sizeof * P ) ;
  P->Ch = Ch, CacheGlyph( P, 0 );  return  P ;  }

  #define Okay  (  \
    rv >= 0 || rv == DDERR_WASSTILLDRAWING || rv == DDERR_SURFACELOST )
  LnP  DXErr ;
int Chk( int rv ) {  if ( Okay )  return rv ;
  DXErr = LnP( DXGetErrorString8( rv ) );  return rv ;  } 

  RECT  WinRecL ;  
void Fast_Paint ( _SurT SurFrom, RECT FromR, RECT ToR ) {  
  if( ! SurFrom ) return;  int X = ToR.left, Y = ToR.top;  
  int * P = Lng ToR - 1, * V = Lng WinRecL; 
  Loop( 4 ) { int X= J & 1;
  * P = Bound( * ++P, V[ X ? 1 : 0 ], V[ X ? 3 : 2 ]); }
  P= Lng ToR; int W= P[2]-P[0], H= P[3]-P[1]; if( !W|| !H) return;
  P= Lng FromR; 
  if(X< 0) P[0]= P[2]- W; else P[2]= P[0]+ W;
  if(Y< 0) P[1]= P[3]- H; else P[3]= P[1]+ H;
  Chk( DrawSur->BltFast(
    ToR.left, ToR.top, SurFrom
    , & FromR, SurFrom == ImgSur ? 0 : DDBLTFAST_SRCCOLORKEY ) );  }

  int  UseKey ;
NewSur( _SurT  & Sur, int  W, int  H  ) {
  int K = UseKey ; UseKey = 1 ;
  //  “ UseKey == 1 ” after:
  //  “ UseKey = 0, NewSur( DrawSur, WinW, WinH ); ” !
  Z.dwWidth = W , Z.dwHeight = H , Z.ddsCaps.dwCaps = DDSCAPS_VIDEOMEMORY ; 
  if ( 0 > DirectDraw->CreateSurface( & Z, & Sur, 0 ) )
    Z.ddsCaps.dwCaps = DDSCAPS_TEXTURE
    , DirectDraw->CreateSurface( & Z, & Sur, 0 );
  if ( ! Sur )  exit( 1 );  static DDCOLORKEY BlackKey ;  
  if ( K )  Sur->SetColorKey( DDCKEY_SRCBLT, & BlackKey );  }

  #define  Try( F )  \
    if ( F ) {  \
      SetPtr( DC, F );  \
      GetGlyphIndices(  \
        DC, B, 1, pUShort( & Good ), GGI_MARK_NONEXISTING_GLYPHS );  \
      if ( Good != -1 )  goto  HaveGlyph ;  }
      
  int mxCacheW, mxCacheH, chH ;    POINT XY ;
  float CharW, CharH, CharW•3, chH•3, CharW•4 ; 
  int CacheW, iHueSel = pInt( & Hues.Sel_Color ) - pInt( & Hues );
  HFONT  fnDeath, DejaVu•3, caps, DejaVu•1
  , Consolas, Courier, NSimSun, Mincho, Musical ;
  const float  •3 = 3, •4 = 4, •2·33 = 2.33
  , x∕X = .8, •1­x∕X = 1 - x∕X * 1.065 ;
  int  I_Cache, ColsDC ;
  #define IncCache  (  \
    I_Cache = 0, NewSur( ✚✚( Ca ),  \
    mxCacheW + ColsDC * CacheW, mxCacheH ), aCache = * Ca.PP )
    
CharSurT & CacheGlyph( GyP P, const ulong * Hue ) {
  if ( !Hue )  Hue = & Hues.NormColor ;
  int iHue = Hue - ( ulong * ) & Hues ;  
  CharSurT  * C = & P->CharSur [ iHue ];  
  if ( C->Cached )  return  * C ;
  //  The “Death” glyph is a special case,
  //  as is the Bass Clef and the “smallCaps”.
  int  Ch = P->Ch, Death = Ch == L'☠', Zero = Ch == '0'
  , capsCh = Ch >= 'a' && Ch <= 'z'
  , Bass = Ch >= 0xDC00 && Ch <= 0xDFFF ;

  static wchar_t  B[ 2 ];  
  B[ Bass ] = P->Blank ? L'‽' : Zero ? L'°' : !capsCh ? Ch : Ch - 32 ;  
  if ( Bass )  * B = 0xD834 ;
  HDC  DC ;  
  Chk( aCache->GetDC( & DC ) ),  
  SetTextAlign(  DC , TA_LEFT | TA_TOP | TA_UPDATECP );
  
  short  Good ;
  if ( Death ) {  Try( fnDeath )  }
  if ( Bass && Musical ) { SetPtr( DC, Musical ); goto  HaveGlyph ;  }
  if ( capsCh && caps ) {  SetPtr( DC, caps ); goto  HaveGlyph ;  }
  Try( DejaVu•1 ) Try( Consolas ) 
  Try( Courier ) Try( NSimSun ) Try( Mincho )
  Chk( aCache->ReleaseDC( DC ) );  P->Blank = 1 ;  goto Known ;

  HaveGlyph:     
  int X = I_Cache * CacheW ;
  
  if ( !Zero && !capsCh ) MvTo( X, 0 ); else MvTo( X + •1­x∕X * CharW, •1­x∕X * chH );
  
  SetBkColor( DC, iHue != iHueSel ? 0 : RGB( 77, 0, 77 ) );
  SetTextColor( DC, * ( ( ulong * ) & Hues + iHue ) );
  { RECT CacheR = _R( X, 0, mxCacheW, mxCacheH );
    ExtTextOut(
      DC, 0, 0, ETO_CLIPPED | ETO_OPAQUE, & CacheR, B, 1 + Bass, 0 );  }
      
  SIZE  XY ; GetTextExtentPoint32( DC, B, 1 + Bass, &XY );  
  Chk( aCache->ReleaseDC( DC ) );
  //  The width of the funky-ass Bass Clef has to be hard-coded.
  //  This font has problems, etc.
  P->ColsCh = Bass ? 2 : 1 + --XY.cx / CharW, 
  P->RowsCh = 1 + --XY.cy / CharH ;
  P->Blank = !P->ColsCh ;
  
  Known:
  C->Cached = aCache, C->I = I_Cache ;
  if ( ( I_Cache += P->ColsCh ) > ColsDC )  IncCache;  
  return  * C ;  }

  int Col, Row ;
PrnChar ( GyP  P, const ulong * Hue ) {  
  CharSurT & C = CacheGlyph( P, Hue );
  
  //  Don't exceed “ mxCacheW x mxCacheH ”
  int  WW = er( mxCacheW, CacheW * P->ColsCh )
  , HH = er( mxCacheH, chH * P->RowsCh );
  Fast_Paint(
    C.Cached, _R( C.I * CacheW, 0, WW, HH )
    , _R( Round( Col * CharW ), Row * chH, WW, HH ) );
  Col += P->ColsCh ;  }

long __stdcall WinProc ( HWND Wnd, uint _WM, uint C, long C2 ) {
  //  Do the default handling, then pass it on to gEvent().  
  DefWindowProc( Wnd, _WM, C, C2 );  PostMessage( Win, _WM, C, C2 );
  return 1 ;  }

  int  ToolBarLines = 1 ;
_VisLn( int L ) {  VisLn = Bound ( L, 0, Scro_Max );  }

    struct { int ii, i ; } sAnk, sB, sE ;
    int  C, C2 ;  
    ushort * P_C = ( ushort * ) & C, * P_C2 = ( ushort * ) & C2 ;
    
  int Col_to_Index( int ii ) {
    //  From a click on the screen, locate the buffer.
    if ( Ln.BB + ii > Ln.PP || !Ln.BB[ ii ] )  return 0 ;
    LnP B = Ln.BB[ ii ], P = B, E = P + int( * P_C2 / CharW );
    While( Ch && P < ( E += Is_Color ? 1 : 1 - _Gy( Ch )->ColsCh ) );
    return  P - B ;  }

    int szToClip ;
  SzClip( LnP D ) {
  
    //  Tell me the size of the selected text;
    //  when there's a buffer, copy the selected text.
    szToClip = 9 ; int Szing = ! D -- ;  LnA  PP = Ln.BB + sB.ii - 1 ;
    int virEE = Ln.BB + sE.ii > Ln.PP ;
    Loop( 1 + sE.ii - sB.ii - virEE ) {
      int Last = J == LLL - 1 ;  LnP  oD = D, B = * ++ PP, P = B, E ;
      if ( !B ) continue ;  E = B + strSz( B );
      if ( ! J )  P = B + sB.i ;  
      if ( !virEE && Last ) {  E = B + sE.i ; if ( *E )  E ++ ;  }
      if ( Szing ) {
        szToClip += E - B + 2 ;  
        if ( Last ) {  szToClip *= szChr ; return ;  }  continue ;  }
      While( Ch && P < E )
        if ( ! Is_Color )  * ++ D = Ch ;
      if ( !virEE && Last ) {
        D[ !( LLL > 1 && D - oD == 1 ) ] = 0 ;  return ;  }
      * ++ D = 13, * ++ D = 10 ;  
      if ( virEE && Last )  * ++ D = 0 ;  } }

  gFont( HFONT &F, LnP  N, int H ) {
    FontFamily Nym( N );  if ( ! Nym.IsAvailable() ) return ;
    DeleteObject( F ), 
    F = CreateFont( H, 0,0,0,0,0,0,0,0,0,0,0, FIXED_PITCH, N );
    if ( !caps )
      caps = CreateFont(
        1 + x∕X * H, 0,0,0,0,0,0,0,0,0,0,0, FIXED_PITCH, N );  }

  float WinW, WinH ;
  int ColsWin, ScrRight, ScrBot, ScrLeft, ScrTop
  , ScrW, ScrH, RowsWin, Lines_Per_Pg
  , ImgW, ImgH, WinRight, WinBot, WinLeft, WinTop ;
  RECT  WinRecG, CursorRec ;  HPEN WhiteInk;  int  Cur_Pix ;
  HWND  TaskBar ;  RECT  TB ;  const int SzTB = sizeof TB ;
  #define Trash( Buf )  (  \
    ! ( Buf ) ? 0 : ( ( Buf )->Release(), Buf = 0 ) )
  HWND Wnd ;  LnP  ButDwn, ButDwnE, ButWas ;
  int  WM, WasInX, OnScroll, ButUp,  OnUp, OnDwn, OnLD, OnMD, OnRD
  , LD, MD, RD, OnLU, OnMU, OnRU ;
  #define IncY  ShowCursor( 1 )
  #define DecY  ShowCursor( 0 )
  SetCur( int X ) {
    int Y = DecY ; 
    if ( Y > X ) while ( DecY > X ); 
    else if ( Y < X ) while ( IncY < X );  }

  int  Leaving, WasCtl ;
  #define WantsOut  (  \
    WM == WM_APPCOMMAND && P_C2[ 1 ] == APPCOMMAND_CLOSE  \
    || WM == WM_SYSKEYDOWN && C == VK_F4  \
    || WM == WM_KEYDOWN && ( ( Leaving = C == 27 || C == VK_F4 
    || WasCtl && C == 'W' ), WasCtl = C == 17, Leaving )  )

  const int Any = 1, Spun = 0;  MSG Msg; 
//#include "Debug.CPP"
int gEvent( int TheGirl ) {
  static int  OnStage = -1, MayReactivate, rv ;

  if ( !chH )  goto reInit ;
  Wnd = 0, 
  WM = C = C2 = OnScroll = OnUp = OnDwn = OnLD 
  = OnMD = OnRD = OnLU = OnMU = OnRU = 0 ;
  GetCursorPos( & XY );  
  int  MouseX = XY.x, MouseY = XY.y
  , InX = MouseY >= WinTop && MouseY <= WinBot 
  && MouseX >= WinLeft && MouseX <= WinRight ;
  
  if ( PeekMessage( & Msg, 0,0,0, PM_REMOVE ) ) {
    static float Y_Was ;  
    WM = Msg.message, C = Msg.wParam, C2 = Msg.lParam, Wnd = Msg.hwnd ;
// ShWM  //  “ShWM” shows selected messages.
    if ( WM == WM_MOUSEWHEEL )
      OnScroll =  short( P_C [ 1 ] ) < 0 ? 1 : -1 ;
    OnLD = WM == WM_LBUTTONDOWN, 
    OnMD = WM == WM_MBUTTONDOWN, OnRD = WM == WM_RBUTTONDOWN ;
    OnDwn = OnLD || OnMD || OnRD ;
    OnLU = WM == WM_LBUTTONUP, 
    OnMU = WM == WM_MBUTTONUP,  OnRU = WM == WM_RBUTTONUP ;
    if ( OnUp = OnLU || OnMU || OnRU ) {
      if ( LD < 0 )  OnLU = LD = 0 ; 
      if ( MD < 0 )  OnMU = MD = 0 ; if ( RD < 0 )  OnRU = RD = 0 ;  } 
    if ( OnLD )  LD = 1 ;  if ( OnLU )  LD = 0;
    if ( OnMD )  MD = 1 ;  if ( OnMU )  MD = 0;  
    if ( OnRD )  RD = 1, Y_Was = P_C2 [ 1 ] - chH ;  
    if ( OnRU )  RD = 0;
    int  Row = P_C2 [ 1 ] / chH ;  

    if ( OnDwn || OnUp ) {
      if ( Row || ! BarB )  goto No ;  float  Col = * P_C2 / CharW ;
      LnP B = BarB, P, E = B + strSz( B )
      , M = er( E, B + int( Col ) )
      , L = ER( B, M - 1 ), R = er( E, B + int( Col + .5 ) );
      
      if ( * L <= 32 && * M <= 32 && * R <= 32 )  goto No ;  
      PaintReq = 1 ;
      P = 1 + ( * M > 32 ? M : * L > 32 ? L : R );  
      int Sav = * P ;  * ( E = P ) = 0 ;  
      WhileBac( Ch > 32 );  * E = Sav ;
      if ( Ch2 <= 32 ) {
        No: ButDwn = ButDwnE = 0, ButUp = 0, PaintReq = 1 ;  }
      else {
        if ( OnDwn )  ButDwn = ButWas = ++ P ;  
        else  ButUp = ++ P == ButDwn ;  
        WhileBlack;  if ( OnDwn )  ButDwnE = P ;  } }

    if ( ButUp && ( OnLD || OnLU ) ) {  static int Cancel ;
      if ( ! Row ) {  
        if ( OnLD )  Cancel = 1 ;  
        else if ( Cancel && OnLU )
          //  This cancels a download, it's semi-borked.
          Due = Secs ;  }
      if ( OnLU )  Cancel = 0 ;  }

    if ( Row >= ToolBarLines && OnLD && VisLn != -1 ) {
      PaintReq = 1 ;  int ii = VisLn + Row - ToolBarLines ;
      if ( Selctd = ii >= 0 && Ln.BB + ii <= Ln.PP + 1 )
        sAnk.ii = ii, sAnk.i = Col_to_Index( ii ), sB = sE = sAnk ;  }
                                       
    if ( Row >= ToolBarLines 
    && OnLU && Selctd && OpenClipboard( Win ) ) {

      SzClip( 0 ), EmptyClipboard();  
      HGLOBAL  Mem = GlobalAlloc( GMEM_MOVEABLE, szToClip );  
      SzClip( ( LnP ) GlobalLock( Mem ) ), GlobalUnlock ( Mem ), 
      SetClipboardData( CF_UNICODETEXT, Mem );
      CloseClipboard();  }

    int  Scroll = 
      WM != WM_KEYDOWN 
      ? OnScroll * ( ! RD ? 1 : Lines_Per_Pg )
      : C == VK_PRIOR 
        ? -Lines_Per_Pg 
        : C == VK_NEXT 
          ? Lines_Per_Pg 
          : C == VK_UP ? -1 : C == VK_DOWN ? 1 : 0 ;
    if ( Scroll )  PaintReq = 1, _VisLn( VisLn + Scroll );
    if ( WM == WM_MOUSEMOVE ) {
      PaintReq = 1 ; int ii = VisLn + Row - ToolBarLines ;
      if ( LD && Selctd && ii >= 0 && Ln.BB + ii <= Ln.PP + 1 ) {
        int i = Col_to_Index( ii );
        if ( ii < sAnk.ii )  sE = sAnk, sB.ii = ii, sB.i = i ;
        else if ( ii > sAnk.ii )  sB = sAnk, sE.ii = ii, sE.i = i;
        else {  sB.ii = sE.ii = ii ;
          if ( i <= sAnk.i )  sB.i = i, sE.i = sAnk.i ;
          else  sB.i = sAnk.i, sE.i = i;  } }
      
      if ( RD ) {  float  Y = P_C2 [ 1 ] - chH, HH = WinH - chH ;
        _VisLn( 
          Y < 3
          ? 0 
          : Y >= HH - 3 
            ? Scro_Max 
            : Y_Was - Y >= 0 
              ? Y / Y_Was * VisLn
              : Scro_Max 
                - ( ( HH - Y ) / ( HH - Y_Was ) * ( Scro_Max - VisLn)));
        Y_Was = Y ; } }

    if ( WantsOut )  exit( 1 );
    if ( MayReactivate && WM == WM_NCACTIVATE ) {

      OnStage = C, PaintReq = 1 ;
      ShowWindow( Win, OnStage ? SW_SHOW : SW_SHOWMINNOACTIVE );
      if ( !OnStage ) {  PaintReq = 0 ;  goto Done;  } 
      ShowWindow( Win, SW_RESTORE ); goto reInit ;  }
    
    MayReactivate = 1 ;
    if ( WM == 0x0313 || WM == WM_ACTIVATEAPP && C && ! C2 )
      //  taskBar Entry was Right-clicked... minimize
      PaintReq = 1, LD = MD = RD = OnStage = MayReactivate = 0, 
      ShowWindow( Win, SW_SHOWMINNOACTIVE );
      
    if ( WM == WM_SYNCPAINT || WM == WM_PAINT )
      PaintReq = 1, ValidateRect( Win, & WinRecL );  }

  if ( PaintReq || WasInX && ! InX )  goto Paint ;

  Done:     
  int GotIt = TheGirl <= Any && WM || TheGirl > Any && WM == TheGirl ;
  if ( TheGirl == Any && ! OnUp && ButUp )
    ButUp = 0, ButDwn = ButDwnE = 0, PaintReq = 1 ;
  else if ( ! GotIt && TheGirl != Spun )  Sleep( 999 / 24 );
  return  GotIt ;

  reInit:  //  re·deActivate !
  //  reSize the window and reCache glyphs, if need be.
  
  gSettings();  //  Check if X.ZIP's settings have changed.
  RECT  cTB ; 
  if ( GetWindowRect( TaskBar, & cTB ), !memcmp( & cTB, & TB, SzTB ) )
    //  The screen resolution hasn't changed and the taskBar
    //  hasn't changed size or location... keep the maximized window.
    goto Paint ;
    
  memmove( & TB, &cTB, SzTB ); 
  WinLeft = ScrLeft, WinRight = ScrRight
  , WinBot = ScrBot, WinTop = ScrTop ;
  int  Left, Top, TBW = TB.right - TB.left
  , TBH = TB.bottom - TB.top, Tall = TBH > TBW ;
  
  if ( Tall ) {
    if ( Left = TB.right < ScrW / 2 )  WinLeft = TB.right - 1 ; 
     else  WinRight = TB.left + 1 ;  } 
  else if ( Top = TB.bottom < ScrH / 2 )  WinTop = TB.bottom - 1 ;  
       else  WinBot = TB.top + 1 ;

  WinW = WinRight - WinLeft, WinH = WinBot - WinTop ;
  WinRecG = _R( WinLeft, WinTop, WinW, WinH ), 
  WinRecL = _R( 0, 0, WinW, WinH );
  SetWindowPos( Win, HWND_TOP, WinLeft, WinTop, WinW, WinH, 0 );

  #define  _chH( W, H )  ( CacheW / ( float( W ) / H ) )

  CharW = WinW / ( ColsWin = 123 ), 
  CacheW = CharW + 1, ColsDC = WinW / CacheW ;
  CharH = _chH( 132, 256 ), chH = CharH ;
  PaintReq = 1, DeleteObject( caps ), caps = 0 ;  
  gFont( DejaVu•1, L"DejaVu Sans Mono", chH );
  if ( !caps )  gFont( Consolas, L"Consolas", _chH( 120, 256 ) );
  if ( !caps )  gFont( Courier, L"Courier New", _chH( 120, 256 ) );
  gFont( NSimSun, L"NSimSun", .9 * CharH );
  gFont( Mincho, L"MS Mincho", .9 * CharH );
  gFont( Musical, L"Musical Symbols", _chH( 1, 4 ) );

  CharW•3 = CharW * •3, chH•3 = chH * •3, mxCacheW = •4 * CacheW, mxCacheH = •2·33 * chH ; 
  //  Commented-out code... used in Games.CPP:
  //  gFont( DejaVu•3, L"DejaVu Sans Mono", chH•3 );
  
  //  The “Death” glyph is 4 chars wide, 2.33 tall.
  gFont( fnDeath, L"MS Mincho", mxCacheH );

  RowsWin = WinH / chH, Lines_Per_Pg = RowsWin - 1 - ToolBarLines ;

  { LoopXx( Gy, Gy )  free( P ), * PP = 0 ;  }  { LoopXx( Ca, Ca )  Trash( P ), * PP = 0 ;  }
  aCache = 0, free( Ca.BB ), Zero( Ca ), free( Gy.BB ), Zero( Gy ), Trash( DrawSur ), Trash( Cursor );
  { Loop( Highest_Ascii - Lowest_Ascii + 1 ) { 
      GyP P = ✚✚( Gy ) = ( GyP ) Malloc ( sizeof * P );
      P->Ch = Lowest_Ascii + J, P->ColsCh = 1 ;  } }
  Cur_Pix = CacheW * 2, CursorRec = _R( 0, 0, Cur_Pix, Cur_Pix );
  UseKey = 0, NewSur( DrawSur, WinW, WinH ), NewSur( Cursor, Cur_Pix, Cur_Pix ), IncCache ;  
  HDC  DC ;  Chk( Cursor->GetDC( & DC ) ); FillRect( DC, & CursorRec, Black );
  { Graphics  Plus( DC );
    Plus.SetSmoothingMode( SmoothingModeAntiAlias );
    Pen  Ink( Color( 255, 255, 255, 255 ), 2 );
    
    //  Draw the cursor, Anti-Aliased, Smoothed.
    Plus.DrawLine( & Ink, 0, 0, Cur_Pix / 2, Cur_Pix );
    Plus.DrawLine( & Ink, 0, 0, Cur_Pix, Cur_Pix / 2 );  }
  
  Chk( Cursor->ReleaseDC( DC ) );  goto Done ;

  Paint:  if ( !OnStage ) goto Done ;  
  static double PaintAlarm ;  if ( Secs < PaintAlarm )  goto Done ;  
  PaintAlarm = _Secs + 1 / 24.;
  DrawSur->Blt( & WinRecL, 0,0, DDBLT_ROP, & ErBlack );
   
  if ( BarB ) {  LnP  P = BarB ;  int Ch, Ch2 ;  Col = 0, Row = 0 ;
    While ( Ch ) {
      //  Draw the taskbar, underline/highlight stuff.
      PrnChar( _Gy( Ch > 32 ? '_' : 32 ), & Hues.NormColor ), Col -- ;
      PrnChar( _Gy( Ch )
      , P < ButDwn || P >= ButDwnE 
        ? & Hues.BarColor : ButUp ? & Hues.NewColor : & Hues.Yellow );
    } }
  if ( Ln.BB && VisLn >= 0 ) { LnA PP = Ln.BB + VisLn - 1 ;
    Loop( RowsWin ) {  if ( ++ PP > Ln.PP ) break;
      LnP  B = * PP ;  if ( ! B ) continue ;  
      Row = J + ToolBarLines , Col = 0 ;  int NoNum = 0 ;
      int  ii = J + VisLn ;  LnP hiB = LnP( -1 ), hiE = 0 ;
      if ( Selctd && ii >= sB.ii && ii <= sE.ii )
        //  The entire line is to be highLighted, from 0 to 999.
        hiB = B + ( ii == sB.ii ? sB.i : 0 ), 
        hiE = B + ( ii == sE.ii ? sE.i : 999 );
      const ulong  * Color = & Hues.NormColor ; LnP  P = * PP - 1 ;
      Next_Ch:  wchar_t  Ch = * ++ P ;

      #define ChHue( Ch, On, Hue )  \
        case  Ch:  NoNum = On, Color = & Hues.Hue ; goto Next_Ch ;
        
      switch ( Ch ) {   case  0: case  13: case  10: continue;
        ChHue( ChNorm, 0, NormColor )
        ChHue( ChNormNoNum, 1, NormColor )  ChHue( ChGrey, 1, Grey )
        ChHue( ChNew, 1, NewColor )  ChHue( ChOdd, 1, OddColor )
        ChHue( ChYell, 1, Yellow )  ChHue( ChRed, 1, Red )
        case  ChImg:  
          Fast_Paint(
            ImgSur, _R( 0, 0, ImgW, ImgH )
            , _R( 0, Row * chH, ImgW, ImgH ) );
          goto Next_Ch ;
        default:  GyP  _Ch = _Gy( Ch );
        
          //  Print a glyph, why not ?
          PrnChar( _Ch,
            P >= hiB && P <= hiE
            ? & Hues.Sel_Color 
            : Ch < 32 || _Ch->Blank
              ? & Hues.Grey 
              : NoNum 
                ? Color 
                : isDigit( Ch ) 
                  ? & Hues.NumColor 
                  : _Ch->ColsCh == •2
                    ? & Hues.OddColor
                    : Iden( Ch ) ? Color : & Hues.Grey );  
          goto Next_Ch ;  } } }
          
  if ( InX )
    Fast_Paint(
      Cursor, CursorRec
      , _R( MouseX - WinLeft, MouseY - WinTop, Cur_Pix, Cur_Pix ) );
  
  SetCur( - InX ), PaintReq = 0 ;
  
  if ( GetForegroundWindow() != Win )
    //  Last-minute check ! don't draw if the focus has changed.
    goto Done ;
    
  WinSur->Blt( & WinRecG, DrawSur, 0, DDBLT_DDFX, & VSync );
  if ( WasInX && ! InX )  SetCur( 0 );  WasInX = InX ;  goto  Done ;  }

ShBot() {
  VisLn =  ER ( 0, Ln.PP - Ln.BB - Lines_Per_Pg ), PaintReq = 1 ;  }

inline OnScreen() {  if ( VisLn < 0 )  VisLn = 0 ;
  if ( Ln.PP - Ln.BB - Lines_Per_Pg <= VisLn )  PaintReq = 1 ;  }
                                
int _Sh( LnP B ) {  //  “Sh()” is like printf().
  LnP P = B, E ; int Ch, Ch2, Hgh2 = 0, Hgh = * B == ChNew ;
  aLine:  While ( ! CRLF );  E = P ; int Two = -1 ; 
  While ( CRLF ) if ( Ch == 10 ) Two ++ ;
  *E = 0 ; int Len = 1 + E - B + Hgh2 ; 
  
  LnP  D = ✚✚( Ln ) = MallocTmp ( Len * szChr );
  *D = ChNew, wmemmove( D + Hgh2, B, Len - Hgh2 ), OnScreen(); 
  if ( Two > 0 )  P -- ;  if ( ! * P )  return -- Len ;  
  if ( Hgh && ! Hgh2 )  Hgh2 = 1;  B = P ; goto aLine ;  }

  #define Printed (  \
    Sz_Sh = Str_Stk ( B_Sh, MaxSh - 3, S, ( __LnP ) & S + szPtr ) )
    
  #define Sh_Silent  \
    while ( Printed < 0 )  \
      B_Sh = MallocTmp( ( MaxSh *= 2) * szChr ), B_Sh[ MaxSh - 3] = 0 ;
    
  int  MaxSh, Sz_Sh ;  LnP B_Sh ;
int Sh ( LnP S, ... ) {  Sh_Silent  return _Sh( B_Sh );  }
Technical Details
Message-ID: <_@Jeff_Relf.Seattle.2009_Jun26.4.02am.3E>
Path: mbox-mo1.pugleaf.net!archive.usenet.blueworldhosting.com!illumos!news.pugleaf.net!.TX!archive.pugleaf.net!archive.newsdeef.eu!mbox2nntp-news.software.readers.20140922.mbox.gz!border2.nntp.dca.giganews.com!nntp.giganews.com!news.glorb.com!news-spur2.glorb.com!homer.glorb.com!not-for-mail
References: <_@Jeff_Relf.Seattle.2009_Jun21.4.34pm.2K> <h1mo75$rrf$1@pcls6.std.com> <_@Jeff_Relf.Seattle.2009_Jun21.8.29pm.4N> <12vlxg6x91o9z$.1ipmnga819en9.dlg@40tude.net> <_@Jeff_Relf.Seattle.2009_Jun22.2.34am.gO> <9f259ijpifyi.7stgknd40js0$.dlg@40tude.net>

Show Full Headers
Complete Article Headers
Message-ID: <_@Jeff_Relf.Seattle.2009_Jun26.4.02am.3E>
Subject: --
Date: Fri, 26 Jun 2009 11:02:06 +0000
From: _@Jeff_Relf.Seattle.inValid
References: <_@Jeff_Relf.Seattle.2009_Jun21.4.34pm.2K> <h1mo75$rrf$1@pcls6.std.com> <_@Jeff_Relf.Seattle.2009_Jun21.8.29pm.4N> <12vlxg6x91o9z$.1ipmnga819en9.dlg@40tude.net> <_@Jeff_Relf.Seattle.2009_Jun22.2.34am.gO> <9f259ijpifyi.7stgknd40js0$.dlg@40tude.net>
Path: mbox-mo1.pugleaf.net!archive.usenet.blueworldhosting.com!illumos!news.pugleaf.net!.TX!archive.pugleaf.net!archive.newsdeef.eu!mbox2nntp-news.software.readers.20140922.mbox.gz!border2.nntp.dca.giganews.com!nntp.giganews.com!news.glorb.com!news-spur2.glorb.com!homer.glorb.com!not-for-mail
Newsgroups: news.software.readers
Organization: Glorb Internet Services, http://www.glorb.com
Lines: 586
NNTP-Posting-Host: miQk5iuGJiy0Vlyebfb5RA.user.posting2.glorb.com
Mime-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
X-Complaints-To: abuse@glorb.com
NNTP-Posting-Date: Fri, 26 Jun 2009 11:02:06 +0000 (UTC)
X-Notice: Scanned by Mr. Bill
User-Agent: JeffRelf.F-M.FM/X.ZIP