Exemple #1
0
static HPS hpsDrawText(HPS hPS,	PTEXTFIELD ptf)

{
FONTMETRICS fm3D;		   /* Font Metrics Holder		*/
RECTL	    rcl;		   /* Rectangle	Holder			*/
register LONG i, k, n;		   /* String Length Counter		*/

		       /* Get the presentation space for the control	*/
		       /* and set the colour table to RGB mode		*/

GpiCreateLogColorTable(hPS, 0L,	LCOLF_RGB, 0L, 0L, (PLONG)NULL);

		       /* Check	to see if any text present and if the	*/
		       /* case,	draw it	within the rectangle		*/

if ( ptf->cText	)
		       /* Check	to see if the text is to be broken over	*/
		       /* more than one	line if	the length of the text	*/
		       /* is greater than the width of the control	*/

   if (	ptf->flStyle & DT_WORDBREAK )
       {
		       /* Word break style specified, set the drawing	*/
		       /* of the text within a loop such that it can	*/
		       /* be drawn on successive lines			*/
       n = ptf->cText;
       GpiQueryFontMetrics(hPS,	sizeof(FONTMETRICS), &fm3D);
       rcl = ptf->rcl;
       i = 0;
       do
	   {
	   n -=	(k = WinDrawText(hPS, n, &ptf->pszText[i], &rcl, ptf->lClrText,
				 ptf->lClrBackground, ptf->flFormat));
	   i +=	k;
	   if (	(rcl.yTop -= fm3D.lMaxBaselineExt) < rcl.yBottom )
	       break;
	   } while ( n > 0 );
       }
   else
       WinDrawText(hPS,	ptf->cText, ptf->pszText, &ptf->rcl, ptf->lClrText,
		   ptf->lClrBackground,	ptf->flFormat);
else
   WinFillRect(hPS, &ptf->rcl, ptf->lClrBackground);

GpiSetColor(hPS, ptf->lClrLeftTop);

GpiMove(hPS, &ptf->aptl[3]);
GpiPolyLine(hPS, 2L, ptf->aptl);

GpiSetColor(hPS, ptf->lClrBottomRight);
GpiPolyLine(hPS, 2L, &ptf->aptl[2]);

return(hPS);
}
void MyRenderWin::paint(HWND& hwnd, HPS& hps, RECTL& rcl, MiniWin* win)
{
	hwnd;				// suppress warning

  time_t    timer;
  struct tm tblock;

  timer = time(0);
  tblock = *localtime(&timer);

  char string[2+1+2+1];

  switch (timeFmt)
    {
    case 0:   // 12 hour
      {
        int hour = tblock.tm_hour;
        if ((hour %= 12) == 0)
          hour = 12;

        sprintf(string, "%01d:%02d%c",
                hour,
                tblock.tm_min,
                tblock.tm_hour <= 12 ? 'a' : 'p');
        break;
      }
    case 1:   // 24 hour
      sprintf(string, "%02d:%02d", tblock.tm_hour, tblock.tm_min);
      break;
    default:
      strcpy(string, "?time?");
      break;
    }

  rcl.xLeft--; rcl.yBottom++;
  WinDrawText(hps,
              strlen(string),
              (PSZ)string,
              &rcl,
              SYSCLR_BUTTONLIGHT,
              win->bgnd(),
              DT_CENTER | DT_VCENTER);
  rcl.xLeft++; rcl.yBottom--;
  WinDrawText(hps,
              strlen(string),
              (PSZ)string,
              &rcl,
              win->fgnd(),
              win->bgnd(),
              DT_CENTER | DT_VCENTER);
}
static BOOL DrawItem(PATTRIBSELECTDATA pWinData, POWNERITEM pOwnerItem)
{
   if (pOwnerItem->idItem == VDA_ITEM)
   {
      int iItem;
      ULONG ulMask;

      iItem = (SHORT1FROMMP(pOwnerItem->hItem)-1) * 8+
              (SHORT2FROMMP(pOwnerItem->hItem)-1);
      ulMask = 1UL << iItem;

      if ((pWinData->ulAttrib & ulMask) &&
          (pWinData->ulAttribMask & ulMask))
      {
         /* gesetzt */
         WinDrawText(pOwnerItem->hps, -1, AttribText[iItem],
                     &pOwnerItem->rclItem, CLR_WHITE, CLR_RED,
                     DT_CENTER | DT_VCENTER | DT_ERASERECT);

         return TRUE;
      }
      else
         return FALSE;
   }
   else
      return FALSE;
}
Exemple #4
0
MRESULT EXPENTRY ClientWndProc(HWND hwnd, ULONG msg, MPARAM mp1, MPARAM mp2)
{
   HPS      hps;
   RECTL    rcl;
   static ULONG    i = 1;
   ULONG    ulMem;
   char     szBuf[200];

   switch (msg) {
      case WM_CREATE:
         /* use smaller text */
         WinSetPresParam(hwnd, PP_FONTNAMESIZE, 7, (PVOID)"8.Helv");
         /* start the timer (ticks each 0.5 sec.) */
         AddFloat(WinQueryWindow(hwnd, QW_PARENT));
         WinStartTimer(hab, hwnd, ID_TIMER, 500);
         break;

      /* make window always stay on top (if desired) */
      case WM_VRNENABLED:
         if (bFloat)
            WinSetWindowPos(hwndFrame, HWND_TOP, 0, 0, 0, 0, SWP_ZORDER);
         break;

      case WM_COMMAND:  /* why doesn't WM_SYSCOMMAND work? */
         if (LOUSHORT(mp1) == IDM_FLOAT) {
            bFloat = !bFloat;
            WinCheckMenuItem(hwndSysSubmenu, IDM_FLOAT, bFloat);
         }
         break;

      case WM_TIMER:
         if (++i > 13)
            i = 1;
         WinInvalidateRect(hwnd, NULL, FALSE);
         return FALSE;

      case WM_PAINT:
         hps = WinBeginPaint(hwnd, NULLHANDLE, &rcl);
         /* necessary to avoid incorrectly repainting window */
         WinQueryWindowRect(hwnd, &rcl);

/*         sprintf(szBuf, " Current use %dK  Maximum ever used %dK  Errors %d",
                 meminfo->used / 1024,
                 meminfo->maxused / 1024, meminfo->num_err);*/
         sprintf(szBuf, " Current use %dB  Maximum ever used %dK  Errors %d",
                 meminfo->used,
                 meminfo->maxused / 1024, meminfo->num_err);
         WinDrawText(hps, -1, szBuf, &rcl, CLR_BLACK, CLR_WHITE,
                     DT_CENTER | DT_VCENTER | DT_ERASERECT);

         WinEndPaint(hps);
         break;
   }

   return WinDefWindowProc(hwnd, msg, mp1, mp2);
}
void XText::Draw( XGraphicDevice * dev)
{
   if (!(settings & GO_HIDE))
   {
      SetupDevice(dev);

      if (p2.GetX() == 0)
      {
         POINTL pnt;

         pnt.x = p.GetX();
         pnt.y = p.GetY();
         GpiCharStringAt(dev->hps, &pnt, text.GetLength(), (PSZ) (char*) text);
      }
      else
      {
         RECTL rc;

         rc.yBottom = p.y + dev->yOffset;
         rc.yTop = p2.y + dev->yOffset;
         rc.xLeft = p.x + dev->xOffset;
         rc.xRight = p2.x + dev->xOffset;
         char *t = text;

         if (style & DT_WORDBREAK)
         {
            int drawn = 0, totalDrawn, length = text.GetLength();

            for (totalDrawn = 0; totalDrawn < length; rc.yTop -= (LONG) (font->realSize))
            {
               drawn = WinDrawText(dev->hps, length - totalDrawn, (PSZ) t + totalDrawn, &rc, color.GetColor(), 0, style);
               if (drawn)
                  totalDrawn += drawn;
               else
                  break;
            }
         }
         else
            WinDrawText(dev->hps, text.GetLength(), (PCH) t, &rc, color.GetColor(), 0, style);
      }
      return;
   }
}
Exemple #6
0
MRESULT clbPaint(PCLBOX pclb) {
   HPS hps;
   if (pclb &&
       NULLHANDLE != (hps = WinBeginPaint(pclb->hwnd, NULLHANDLE, NULL))) {
      if (!(pclb->fl & (CLBXS_CHECK | CLBXS_NOCAPT))) {
         ULONG fl = DT_VCENTER | DT_ERASERECT | DT_MNEMONIC;
         GpiCreateLogColorTable(hps, 0, LCOLF_RGB, 0, 0, NULL);
         WinDrawText(hps, -1, pclb->psz, &pclb->rclcpt, pclb->lfgnd,
                     pclb->lbkgnd, (pclb->is.enbl? fl: fl | DT_HALFTONE));
      } /* endif */
      WinEndPaint(hps);
   } /* endif */
   return (MRESULT)FALSE;
}
MRESULT
DrawMenuItem( POWNERITEM poi )
{
  TASKDATA* data = (TASKDATA*)poi->hItem;
  BOOL   select  = (poi->fsAttribute & MIA_HILITED) ? TRUE : FALSE;
  ULONG  cx_icon = WinQuerySysValue( HWND_DESKTOP, SV_CXICON );
  ULONG  cy_icon = WinQuerySysValue( HWND_DESKTOP, SV_CYICON );
  POINTL pos;
  RECTL  rect = poi->rclItem;

  WinFillRect( poi->hps, &rect, select ? SYSCLR_MENUHILITEBGND : SYSCLR_MENU );

  rect.xLeft += 2;
  rect.yBottom += ( rect.yTop - rect.yBottom - cy_icon/2 ) / 2;
  if( data->hIcon != NULLHANDLE ) {
    WinDrawPointer( poi->hps, rect.xLeft + 1, rect.yBottom + 1, data->hIcon, DP_MINI );
  }

  rect.xLeft += cx_icon/2 + 5;
  rect.yBottom = poi->rclItem.yBottom;
  WinDrawText( poi->hps, -1, data->szTitle, &rect,
                    select ? SYSCLR_MENUHILITE : SYSCLR_MENUTEXT, 0,
                    DT_LEFT | DT_VCENTER );

  // Well well well... And now ;) we are going to fix A great-Warp4-Menu-Bug
  // Make to redraw erased parts of menu's window border
  // Define something like #ifdef WARP_3 if you are running OS/2 Warp 3.x

  // vertical "light" line
  pos.x = poi->rclItem.xLeft;
  pos.y = 1;
  GpiSetColor( poi->hps, SYSCLR_BUTTONLIGHT );
  GpiMove( poi->hps, &pos );
  pos.y = poi->rclItem.yTop;
  GpiLine( poi->hps, &pos );

  // horizontal "dark" line
  pos.x = 1;
  pos.y = 1;
  GpiSetColor( poi->hps, SYSCLR_BUTTONDARK );
  GpiMove( poi->hps, &pos );
  pos.x = poi->rclItem.xRight;
  GpiLine( poi->hps, &pos );

  poi->fsAttributeOld = (poi->fsAttribute &= ~MIA_HILITED);
  return MRFROMLONG( TRUE );
}
static  void    kstDraw(HWND hwnd, KSTPTR p)
{
    HPS     hps    ;
    RECTL   rct    ;
    LONG    fore, back ;

#ifdef DEBUG
    TRACE("kstDraw %s\n", p->keyName) ; fflush(stdout) ;
#endif
    fore = p->clrFore ;
    back = p->keyDown ? p->clrDn : p->clrUp ;
    hps = WinBeginPaint(hwnd, NULLHANDLE, NULL) ;
    WinQueryWindowRect(hwnd, &rct) ;
    WinDrawText(hps, strlen(p->keyName), p->keyName, &rct,
                    fore, back, (DT_CENTER | DT_VCENTER | DT_ERASERECT)) ;
    WinEndPaint(hps) ;
}
MRESULT
MeasureMenuItem( POWNERITEM poi )
{
  TASKDATA* data = (TASKDATA*)poi->hItem;
  ULONG cx_icon = WinQuerySysValue( HWND_DESKTOP, SV_CXICON );
  ULONG cy_icon = WinQuerySysValue( HWND_DESKTOP, SV_CYICON );

  RECTL rect = { 0, 0, 32000, 32000 };

  WinDrawText( poi->hps, -1, data->szTitle, &rect, 0, 0, DT_QUERYEXTENT | DT_LEFT | DT_VCENTER );

  poi->rclItem.xLeft   = 0;
  poi->rclItem.xRight  = max( cx_icon/2 + 4, rect.xRight - rect.xLeft   ) + 10;
  poi->rclItem.yBottom = 0;
  poi->rclItem.yTop    = max( cy_icon/2 + 2, rect.yTop   - rect.yBottom ) + 1;

  return MRFROMLONG( poi->rclItem.yTop );
}
// disegna il controllo groupbox
MRESULT PaintGroupBox(HWND hwnd) {
   PCTL pgb = stGetData(hwnd);
   if (pgb) {
      RECTL rcl = {0, 0, pgb->wr.cx, pgb->wr.cy};
      HPS hps = WinBeginPaint(hwnd, NULLHANDLE, NULL);
      ULONG brd = pgb->fl & 0x7;
      ULONG frm = brd;
      GpiCreateLogColorTable(hps, 0, LCOLF_RGB, 0, 0, NULL);
      // disegna bordo groupbox
      WinDrawBorder(hps, &rcl, brd, brd, 0, 0,
                    (pgb->fl & CCTL_RAISED? 0x400: 0x800));
      // se necessario disegnare anche frame
      if (pgb->fl & CCTL_FRAME6) {
         frm = brd * ((pgb->fl & 0x38) >> 3);
         rcl.xLeft = frm;
         rcl.yBottom = frm;
         rcl.xRight -= frm; 
         rcl.yTop -= frm; 
         WinDrawBorder(hps, &rcl, brd, brd, 0, 0,
                       (pgb->fl & CCTL_RAISED? 0x800: 0x400));
      } /* endif */
      // se il testo Š presente
      if (pgb->psz) {
         // cancella background
         rcl.xLeft = frm;
         rcl.yBottom = pgb->wr.cy - pgb->cyFont - 2 * frm - 2;
         rcl.xRight = pgb->wrtxt.cx + 2 * frm + 3;
         rcl.yTop = pgb->wr.cy - frm;
         WinFillRect(hps, &rcl, pgb->lbkgnd);
         // disegna testo
         rcl.yBottom += 2;
         WinDrawText(hps, -1, pgb->psz, &rcl, pgb->lfgnd, pgb->lbkgnd,
                     DT_CENTER | DT_TOP | DT_MNEMONIC | DT_EXTERNALLEADING |
                     ((pgb->fl & WS_DISABLED)? DT_HALFTONE: 0));
         // disegna bordo inferiore e a destra del testo
         rcl.yBottom -= 2;
         GpiSetColor(hps, (pgb->fl & CCTL_RAISED? pgb->lshadow: pgb->lhilite));
         GpiMove(hps, (PPOINTL)&rcl);
         rcl.xLeft = rcl.xRight;
         rcl.yTop -= 1;
         GpiPolyLine(hps, 2, (PPOINTL)&rcl);
      } /* endif */
      WinEndPaint(hps);
   } /* endif */
bool PaintButton( VRIconButton *somSelf, PUSERBUTTON pbtn )
{
    FONTMETRICS fm;
    HAB    hab;
    RECTL  rcl,
           rclTxt,
           rclImg;
    POINTL ptl,
           aptl[ TXTBOX_COUNT ];
    LONG   lFlags,
           flPic,
           flTxt,
           lStrW,
           lStrH,
           lOffset,
           lClr;
    ULONG  cb;
    BOOL   fPosition;

//FILE *f = fopen("c:\\iconbtn.log", "a");

    VRIconButtonData *somThis = VRIconButtonGetData(somSelf);
    lFlags = _vrGetWindowFlags( somSelf );

//fprintf(f, "----[ Entering PaintButton ] ----\n");

    if ( !pbtn || ( ! WinQueryWindowRect( pbtn->hwnd, &rcl )))
        return FALSE;

    // Get the current background colour
    cb = WinQueryPresParam( pbtn->hwnd, PP_BACKGROUNDCOLOR,
                            PP_BACKGROUNDCOLORINDEX, NULL,
                            sizeof( lClr ), &lClr, QPF_ID2COLORINDEX );
    if ( cb )
        GpiCreateLogColorTable( pbtn->hps, 0, LCOLF_RGB, 0, 0, NULL );
    else
        lClr = GpiQueryRGBColor( pbtn->hps, 0, SYSCLR_BUTTONMIDDLE );

    // Fill in the button background
    WinFillRect( pbtn->hps, &rcl, lClr );

    ptl.x = rcl.xLeft;
    ptl.y = rcl.yBottom;
    GpiMove( pbtn->hps, &ptl );
    ptl.x = rcl.xRight - 1;
    ptl.y = rcl.yTop - 1;
    // Draw the "default" state outline if applicable
    if ( pbtn->fsState & BDS_DEFAULT ) {
        GpiSetColor( pbtn->hps, SYSCLR_BUTTONDEFAULT );
        GpiBox( pbtn->hps, DRO_OUTLINE, &ptl, 0, 0 );
    }
    else {
        cb = WinQueryPresParam( WinQueryWindow( pbtn->hwnd, QW_PARENT ),
                                PP_BACKGROUNDCOLOR, PP_BACKGROUNDCOLORINDEX,
                                NULL, sizeof( lClr ), &lClr, QPF_ID2COLORINDEX );
        if ( cb )
            GpiSetColor( pbtn->hps, lClr );
        else
            GpiSetColor( pbtn->hps, SYSCLR_DIALOGBACKGROUND );
        GpiBox( pbtn->hps, DRO_OUTLINE, &ptl, 0, 0 );
    }

    if ( !( lFlags & BS_NOBORDER )) {
        /* Draw the button border (if appropriate) depending on the current
         * state(s).
         */
        GpiSetColor( pbtn->hps, ( _fDown || ( pbtn->fsState & BDS_HILITED )) ?
                                CLR_BLACK: SYSCLR_BUTTONDARK );
        ptl.x = rcl.xLeft + 1;
        ptl.y = rcl.yBottom + 2;
        GpiMove( pbtn->hps, &ptl );
        ptl.y = rcl.yTop - 2;
        GpiLine( pbtn->hps, &ptl );
        GpiMove( pbtn->hps, &ptl );
        ptl.x = rcl.xRight - 2;
        GpiLine( pbtn->hps, &ptl );
        GpiSetColor( pbtn->hps, ( _fDown || ( pbtn->fsState & BDS_HILITED )) ?
                                SYSCLR_BUTTONDARK: CLR_BLACK );
        ptl.x = rcl.xLeft + 1;
        ptl.y = rcl.yBottom + 1;
        GpiMove( pbtn->hps, &ptl );
        ptl.x = rcl.xRight - 2;
        GpiLine( pbtn->hps, &ptl );
        GpiMove( pbtn->hps, &ptl );
        ptl.y = rcl.yTop - 3;
        GpiLine( pbtn->hps, &ptl );

        GpiSetColor( pbtn->hps, ( _fDown || ( pbtn->fsState & BDS_HILITED )) ?
                                SYSCLR_BUTTONLIGHT: SYSCLR_BUTTONDARK );
        ptl.x = rcl.xLeft + 2;
        ptl.y = rcl.yBottom + 2;
        GpiMove( pbtn->hps, &ptl );
        ptl.x = rcl.xRight - 3;
        GpiLine( pbtn->hps, &ptl );
        GpiMove( pbtn->hps, &ptl );
        ptl.y = rcl.yTop - 3;
        GpiLine( pbtn->hps, &ptl );
        GpiSetColor( pbtn->hps, ( _fDown || ( pbtn->fsState & BDS_HILITED )) ?
                                SYSCLR_BUTTONDARK: SYSCLR_BUTTONLIGHT );
        ptl.x = rcl.xLeft + 2;
        ptl.y = rcl.yBottom + 3;
        GpiMove( pbtn->hps, &ptl );
        ptl.y = rcl.yTop - 3;
        GpiLine( pbtn->hps, &ptl );
        GpiMove( pbtn->hps, &ptl );
        ptl.x = rcl.xRight - 3;
        GpiLine( pbtn->hps, &ptl );

        if ( pbtn->fsState & BDS_HILITED ) {
            GpiSetColor( pbtn->hps, SYSCLR_BUTTONLIGHT );
            ptl.x = rcl.xLeft + 3;
            ptl.y = rcl.yBottom + 3;
            GpiMove( pbtn->hps, &ptl );
            ptl.x = rcl.xRight - 4;
            GpiLine( pbtn->hps, &ptl );
            GpiMove( pbtn->hps, &ptl );
            ptl.y = rcl.yTop - 4;
            GpiLine( pbtn->hps, &ptl );
            GpiSetColor( pbtn->hps, SYSCLR_BUTTONDARK );
            ptl.x = rcl.xLeft + 3;
            ptl.y = rcl.yBottom + 4;
            GpiMove( pbtn->hps, &ptl );
            ptl.y = rcl.yTop - 4;
            GpiLine( pbtn->hps, &ptl );
            GpiMove( pbtn->hps, &ptl );
            ptl.x = rcl.xRight - 4;
            GpiLine( pbtn->hps, &ptl );
        }

    } // if ( !( lFlags & BS_NOBORDER ))

    /* After this point, rcl is used for the clipping boundaries of the entire
     * button contents exclusive of the border.  Separate bounding rectangles
     * for the image and the text will now be calculated within this area.
     */
    if ( rcl.xRight > 6 ) {
        rcl.xLeft += 3;
        rcl.xRight -= 3;
    }
    if ( rcl.yTop > 6 ) {
        rcl.yBottom += 3;
        rcl.yTop -= 3;
    }
    memcpy( &rclTxt, &rcl, sizeof( RECTL ));
    if ( RECTL_WIDTH( rclTxt ) > 4 ) {
        rclTxt.xLeft += 2;
        rclTxt.xRight -= 2;
    }
    if ( RECTL_WIDTH( rclTxt ) > 4 ) {
        rclTxt.yBottom += 2;
        rclTxt.yTop -= 2;
    }
    if ( _pPic && ( _pPic->type & MEMP_BITMAP ) && _fResize )
        memcpy( &rclImg, &rcl, sizeof( RECTL ));
    else {
        rclImg.xLeft   = ( RECTL_WIDTH( rclTxt ) > 6 )  ?
                         rclTxt.xLeft + 3   : rclTxt.xLeft;
        rclImg.xRight  = ( RECTL_WIDTH( rclTxt ) > 6 )  ?
                         rclTxt.xRight - 3  : rclTxt.xRight;
        rclImg.yBottom = ( RECTL_HEIGHT( rclTxt ) > 6 ) ?
                         rclTxt.yBottom + 3 : rclTxt.yBottom;
        rclImg.yTop    = ( RECTL_HEIGHT( rclTxt ) > 6 ) ?
                         rclTxt.yTop - 3    : rclTxt.yTop;
    }

//fprintf(f, "rcl     = {%d %d %d %d}, width = %d, height= %d\n", rcl.xLeft, rcl.yBottom, rcl.xRight, rcl.yTop, RECTL_WIDTH(rcl), RECTL_HEIGHT(rcl) );
//fprintf(f, "rclImg  = {%d %d %d %d}, width = %d, height= %d\n", rclImg.xLeft, rclImg.yBottom, rclImg.xRight, rclImg.yTop, RECTL_WIDTH(rclImg), RECTL_HEIGHT(rclImg) );

    fPosition = _pPic && ( !_fResize || _pPic->type & MEMP_ICON ) &&
                (( _bAlign == ALIGN_LEFT ) || ( _bAlign == ALIGN_RIGHT )) ?
                TRUE : FALSE;

    /* We won't draw the text until after the image... but unless we're scaling
     * the image into the whole button, we need to calculate how much space the
     * text is going to require so we can fit the image next to it.  (Note that
     * we behave differently for top/bottom alignment vs left/right alignment -
     * with top/bottom, the text area is fixed to the height of the string plus
     * a certain margin.  With left/right alignment, the image rectangle is set
     * to the physical image size, and the text rectangle is offset from that.)
     */
    lStrW = 0;
    lStrH = 0;
    GpiQueryFontMetrics( pbtn->hps, sizeof( FONTMETRICS ), &fm );
    if ( _pszText && *_pszText ) {

        // Get the width of the text as it would be rendered in the current font
        GpiQueryTextBox( pbtn->hps, strlen( _pszText ),
                         _pszText, TXTBOX_COUNT, aptl );

        lStrW = aptl[TXTBOX_TOPRIGHT].x - aptl[TXTBOX_TOPLEFT].x;
        lStrW += ( 2 * fm.lAveCharWidth );
        lStrH = fm.lMaxBaselineExt + fm.lInternalLeading + fm.lMaxDescender;

        // Adjust the bounding rectangles for the text and image
        switch ( _bAlign ) {
            case ALIGN_TOP:
                rclTxt.yBottom = rclTxt.yTop - lStrH;
                if ( _pPic && ( !_fResize || _pPic->type & MEMP_ICON )) {
                    if (( rclTxt.yBottom - rclImg.yBottom ) > _pPic->height )
                        rclImg.yTop = rclTxt.yBottom - 1;
                    else if (( rcl.yTop - rclImg.yBottom ) > _pPic->height )
                        rclImg.yTop = rcl.yBottom + _pPic->height;
                }
                break;
            case ALIGN_BOTTOM:
                rclTxt.yTop = rclTxt.yBottom + lStrH;
                if ( _pPic && ( !_fResize || _pPic->type & MEMP_ICON )) {
                    if ((( rclImg.yTop - rclTxt.yTop ) > _pPic->height ))
                        rclImg.yBottom = rclTxt.yTop + 1;
                    else if (( rclImg.yTop - rcl.yBottom ) > _pPic->height )
                        rclImg.yBottom = (LONG) ( rcl.yTop - _pPic->height );
                }
                break;
            case ALIGN_LEFT:
                if ( fPosition ) {
                    if (( rclTxt.xLeft + lStrW + _pPic->width ) < rclImg.xRight ) {
                        rclImg.xLeft = rclImg.xRight - _pPic->width;
                        rclTxt.xRight = rclImg.xLeft - 1;
                    }
                    else  {
                        rclTxt.xRight = rclTxt.xLeft + lStrW;
                        if (( rclImg.xRight - _pPic->width ) < RECTL_WIDTH( rcl ))
                            rclImg.xLeft = (LONG) ( rclImg.xRight - _pPic->width );
                    }
                }
                else
                    rclTxt.xRight = rclTxt.xLeft + lStrW;
                break;
            case ALIGN_RIGHT:
                if ( fPosition ) {
                    if (( rclImg.xLeft + _pPic->width + lStrW ) < rclImg.xRight ) {
                        rclImg.xRight = rclImg.xLeft + _pPic->width;
                        rclTxt.xLeft = rclImg.xRight + 1;
                    }
                    else {
                        rclTxt.xLeft = rclTxt.xRight - lStrW;
                        if (( rclImg.xLeft + _pPic->width ) < RECTL_WIDTH( rcl ))
                            rclImg.xRight = rclImg.xLeft + _pPic->width;
                    }
                }
                else
                    rclTxt.xLeft = rclTxt.xRight - lStrW;
                break;
            default: break;   // ALIGN_CENTER, no adjustment needed
        }
        if ( rclTxt.yBottom < rcl.yBottom ) rclTxt.yBottom = rcl.yBottom;
        if ( rclTxt.yTop > rcl.yTop ) rclTxt.yTop = rcl.yTop;
        if ( rclTxt.xLeft < rcl.xLeft ) rclTxt.xLeft = rcl.xLeft;
        if ( rclTxt.xRight > rcl.xRight ) rclTxt.xRight = rcl.xRight;
    }

    // Draw the image, if one is defined
    if ( _pPic ) {

        if (( pbtn->fsState & BDS_HILITED ) &&
            !( _fResize && ( _pPic->type & MEMP_BITMAP )))
        {
            rclImg.xLeft++;
            rclImg.xRight++;
            rclImg.yBottom--;
            rclImg.yTop--;
        }

        flPic = PICTDRAW_CENTER_ICON;
        if ( pbtn->fsState & BDS_DISABLED ) flPic |= PICTDRAW_DISABLE;
        if ( _pPic->type & MEMP_BITMAP ) {
            if ( _fResize )
                flPic |= PICTDRAW_STRETCH_BITMAP;
            else {
                ptl.x = ((LONG)( RECTL_WIDTH( rclImg ) - _pPic->width ) / 2 );
                ptl.y = ((LONG)( RECTL_HEIGHT( rclImg ) - _pPic->height ) / 2 );
                if ( ptl.x > 0 ) rclImg.xLeft += ptl.x;
                if ( ptl.y > 0 ) rclImg.yBottom += ptl.y;
            }
        }

        VRPictDisplay( pbtn->hwnd, pbtn->hps, _pPic, &rclImg, flPic );
    }

    // Now draw the text, if any
    if ( _pszText && *_pszText ) {

        // Get the current foreground colour
        if ( pbtn->fsState & BDS_DISABLED )
            lClr = GpiQueryRGBColor( pbtn->hps, 0, SYSCLR_MENUDISABLEDTEXT );
        else {
            cb = WinQueryPresParam( pbtn->hwnd, PP_FOREGROUNDCOLOR,
                                    PP_FOREGROUNDCOLORINDEX, NULL,
                                    sizeof( lClr ), &lClr, QPF_ID2COLORINDEX );
            if ( !cb )
                lClr = GpiQueryRGBColor( pbtn->hps, 0, SYSCLR_WINDOWTEXT );
        }
        GpiSetColor( pbtn->hps, lClr );

        // Now position and draw the button text
        switch ( _bAlign ) {

            case ALIGN_TOP:
#ifdef GPI_DRAWTEXT
                ptl.x = rclTxt.xLeft + ( RECTL_WIDTH( rclTxt ) / 2 );
                ptl.y = ( RECTL_HEIGHT( rclTxt ) < lStrH ) ? rclTxt.yTop :
                        rclTxt.yTop - ( 2 * fm.lInternalLeading );
                GpiSetTextAlignment( pbtn->hps, TA_CENTER, TA_TOP );
#else
                flTxt = DT_CENTER | (( RECTL_HEIGHT( rclTxt ) < lStrH )
                                    ? DT_TOP : DT_VCENTER ) |
                        DT_TEXTATTRS | DT_MNEMONIC;
#endif
                break;

            case ALIGN_BOTTOM:
#ifdef GPI_DRAWTEXT
                ptl.x = rclTxt.xLeft + ( RECTL_WIDTH( rclTxt ) / 2 );
                ptl.y = ( RECTL_HEIGHT( rclTxt ) < lStrH ) ? rclTxt.yBottom :
                        rclTxt.yBottom + ( 2 * fm.lInternalLeading );
                GpiSetTextAlignment( pbtn->hps, TA_CENTER, TA_BOTTOM );
#else
                flTxt = DT_CENTER | (( RECTL_HEIGHT( rclTxt ) < lStrH ) ?
                                    DT_BOTTOM : DT_VCENTER ) |
                        DT_TEXTATTRS | DT_MNEMONIC;
#endif
                break;

            case ALIGN_LEFT:
#ifdef GPI_DRAWTEXT
                ptl.x = rclTxt.xLeft + fm.lAveCharWidth;
                ptl.y = rclTxt.yBottom + (( RECTL_HEIGHT( rclTxt ) - fm.lXHeight ) / 2 );
                GpiSetTextAlignment( pbtn->hps, TA_NORMAL_HORIZ, TA_BASE );
#else
                flTxt = DT_LEFT | DT_VCENTER | DT_TEXTATTRS | DT_MNEMONIC;
                rclTxt.xLeft += fm.lAveCharWidth;
#endif
                break;

            case ALIGN_RIGHT:
#ifdef GPI_DRAWTEXT
                ptl.x = rclTxt.xLeft + fm.lAveCharWidth;
                ptl.y = rclTxt.yBottom + (( RECTL_HEIGHT( rclTxt ) - fm.lXHeight ) / 2 );
                GpiSetTextAlignment( pbtn->hps, TA_NORMAL_HORIZ, TA_BASE );
#else
                flTxt = (fPosition? DT_LEFT: DT_RIGHT) | DT_VCENTER | DT_TEXTATTRS | DT_MNEMONIC;
                if ( RECTL_WIDTH( rclTxt ) > fm.lAveCharWidth ) {
                    if ( fPosition )
                        rclTxt.xLeft += fm.lAveCharWidth;
                    else
                        rclTxt.xRight -= fm.lAveCharWidth;
                }
#endif
                break;

            default:    // ALIGN_CENTER
#ifdef GPI_DRAWTEXT
                ptl.x = rclTxt.xLeft + ( RECTL_WIDTH( rclTxt ) / 2 );
                ptl.y = rclTxt.yBottom + (( RECTL_HEIGHT( rclTxt ) - fm.lXHeight ) / 2 );
                GpiSetTextAlignment( pbtn->hps, TA_CENTER, TA_BASE );
#else
                flTxt = DT_CENTER | DT_VCENTER | DT_TEXTATTRS | DT_MNEMONIC;
#endif
                break;
        }
        if ( pbtn->fsState & BDS_HILITED ) {
            ptl.x++;
            ptl.y--;
        }
        cb = strlen( _pszText );
#ifdef GPI_DRAWTEXT
        GpiCharStringPosAt( pbtn->hps, &ptl, &rclTxt, CHS_CLIP, cb, _pszText, NULL );
#else
        WinDrawText( pbtn->hps, cb, _pszText, &rclTxt, 0, 0, flTxt );
#endif
    }

//fprintf(f, "----[ Leaving PaintButton ] ----\n\n");
//fclose(f);

    return TRUE;
}
Exemple #12
0
static MRESULT EXPENTRY LinkLabelProc( HWND hwnd, ULONG msg, MPARAM mp1, MPARAM mp2 )
{
    linkData *ld = (linkData *)WinQueryWindowULong( hwnd, QWL_USER );
    switch ( msg )
    {
    case WM_PAINT:
    {
        FONTMETRICS fm;
        FATTRS fat;
        HPS hps;
        ULONG style;
        char *text = (char *)malloc( MAXTEXTLEN );
        WinQueryWindowText( hwnd, MAXTEXTLEN, text);
        hps = WinBeginPaint( hwnd , 0L , 0L );
        GpiQueryFontMetrics( hps , sizeof( FONTMETRICS ) , &fm );
        memset( &fat , 0 , sizeof( fat ) );
        fat.usRecordLength = sizeof( FATTRS );
        fat.lMatch = fm.lMatch;
        fat.fsSelection = FATTR_SEL_UNDERSCORE;
        strcpy( fat.szFacename , fm.szFacename );
        GpiDeleteSetId( hps , 1 );
        GpiCreateLogFont( hps , 0 , 1 , &fat );
        GpiSetCharSet( hps , 1 );
        WinQueryWindowRect( hwnd , &ld->textRect );
        style = WinQueryWindowULong( hwnd, QWL_STYLE );
        style &= DT_LEFT|DT_CENTER|DT_RIGHT|DT_TOP|DT_VCENTER|DT_BOTTOM;
        WinDrawText( hps, -1, text, &ld->textRect,
                     CLR_BLUE, SYSCLR_DIALOGBACKGROUND,
                     style | DT_ERASERECT | DT_UNDERSCORE );
        WinDrawText( hps, -1, text, &ld->textRect,
                     CLR_BLUE, SYSCLR_DIALOGBACKGROUND,
                     style | DT_QUERYEXTENT | DT_UNDERSCORE );
        WinEndPaint( hps );
        free( text );
    }
    return (MRESULT)FALSE;

    case WM_MOUSEMOVE:
    {
        if ( handPtr != NULLHANDLE )
        {
            POINTL ptl;
            ptl.x = SHORT1FROMMP( mp1 );
            ptl.y = SHORT2FROMMP( mp1 );
            if ( WinPtInRect( WinQueryAnchorBlock( hwnd ), &ld->textRect, &ptl) )
            {
                WinSetPointer( HWND_DESKTOP, handPtr );
                return (MRESULT)FALSE;
            }
        }
    }
    break;

    case WM_BUTTON1CLICK:
    {
        PROGDETAILS pd;
        char *text;
        POINTL ptl;

        if ( strcmp( browserExe, "" ) == 0 )  break;

        ptl.x = SHORT1FROMMP( mp1 );
        ptl.y = SHORT2FROMMP( mp1 );
        if ( !WinPtInRect( WinQueryAnchorBlock( hwnd ), &ld->textRect, &ptl) )
            break;

        if ( ld->url == NULL )
        {
            text = (char *)malloc( MAXTEXTLEN );
            WinQueryWindowText( hwnd, MAXTEXTLEN, text);
        }
        else  text = strdup( ld->url );

        pd.Length          = sizeof( PROGDETAILS );
        pd.progt.progc     = PROG_DEFAULT;
        pd.progt.fbVisible = SHE_VISIBLE;
        pd.pszTitle        = NULL;
        pd.pszExecutable   = browserExe;
        pd.pszParameters   = NULL;
        pd.pszStartupDir   = ( browserDir[0] == 0 ) ? NULL : browserDir;
        pd.pszIcon         = NULL;
        pd.pszEnvironment  = NULL;
        pd.swpInitial.fl   = SWP_ACTIVATE;
        pd.swpInitial.cy   = 0;
        pd.swpInitial.cx   = 0;
        pd.swpInitial.y    = 0;
        pd.swpInitial.x    = 0;
        pd.swpInitial.hwndInsertBehind = HWND_TOP;
        pd.swpInitial.hwnd             = NULLHANDLE;
        pd.swpInitial.ulReserved1      = 0;
        pd.swpInitial.ulReserved2      = 0;
        WinStartApp( NULLHANDLE , &pd , text , NULL , 0 );
        free( text );
    }
    break;

    case WM_DESTROY:
        ld->labelProc( hwnd, msg, mp1, mp2 );
        if ( ld->url != NULL )  free( ld->url );
        free( ld );
        return (MRESULT)FALSE;
    }
    return ld->labelProc( hwnd, msg, mp1, mp2 );
}
VOID DrawDigitalTime(HWND hwnd)
{
    RECTL rcl;
    RECTL rclChar;
    RECTL rclCharOld;
    RECTL rclTime;
    RECTL rclAmPm;
    RECTL rclDate;
    HPS hpsWnd;
    SIZEF sizef;
    USHORT usi;
    ULONG  ulCharWidth,ulCharModulu;
    char achTime[9];
    char achFinalDate[9];
    time_t     tTime;
    struct tm  *pLocalTime;

    WinQueryWindowRect (hwnd, &rcl);
    hpsWnd = WinGetPS (hwnd);

    memset(achTime,0,sizeof(achTime) );
    memset(achFinalDate,0,sizeof(achFinalDate) );

    GpiCreateLogColorTable (hpsWnd, LCOL_RESET, LCOLF_RGB, 0, 0,
                                 (PLONG) NULL);

    /*
     *if black hands and black background
     *selected force the background to
     *blue
     */

    if( !cp.clrMinuteHand && !cp.clrBackground )
    {
          cp.clrBackground = RGB_BLUE;
    }



    switch (cp.usDispMode & (DM_TIME | DM_DATE))
    {
    case DM_DATE:
        rclDate = rcl;
        break;

    case DM_TIME | DM_DATE:
        if (!fIconic)
        {
            rclTime = rclDate = rcl;
            rclTime.yBottom = rclDate.yTop = rcl.yTop / 2;
            break;
        } /*else fall through*/

    case DM_TIME:
        rclTime = rcl;
        break;
    }

    if (cp.usDispMode & DM_TIME)
    {

        rclAmPm = rclTime;
        time(&tTime);
        pLocalTime = localtime(&tTime);
        if (bTwelveHourFormat)
        {
           strftime(achTime, sizeof(achTime), "%I %M %S", pLocalTime);
        }
        else
        {
           strftime(achTime, sizeof(achTime), "%H %M %S", pLocalTime);
        }

        /*insert country time separator*/
        achTime[2] = achTime[5] = szTimeSep[0];
        achTime[8] = '\000';
        /*Process 12 hours mode*/
        if (bTwelveHourFormat)
        {

            if (fIconic)
            {
                rclTime.yBottom = rclAmPm.yTop = rclTime.yTop / 2;
            }
            else
            {
                rclTime.xRight = rcl.xRight * 8 / 11;
                rclAmPm.xLeft = rclTime.xRight;
            }

            strcpy(achAmPm,szAnteMeridian);

            if (pLocalTime->tm_hour >= 12)
            {
                strcpy(achAmPm,szPostMeridian);
            }

        }

        GpiSetCharMode(hpsWnd, CM_MODE3);

        if (fIconic)
        {
            sizef.cx = MAKEFIXED(LOUSHORT((rclTime.xRight - rclTime.xLeft)
                    / 3), 0);
            sizef.cy = MAKEFIXED(LOUSHORT((rclTime.yTop - rclTime.yBottom)
                    * 1400 / 1000), 0);
        }
        else
        {
            sizef.cx = MAKEFIXED(LOUSHORT((rclTime.xRight - rclTime.xLeft)
                    / 6), 8000);
            sizef.cy = MAKEFIXED(LOUSHORT((rclTime.yTop - rclTime.yBottom)
                    * 1000 / 1500), 0);
        }

        GpiSetCharBox(hpsWnd, &sizef);

        if (bTwelveHourFormat)
        {

            if( strcmp(achAmPm,achOldAmPm) )
            {
                WinFillRect(hpsWnd, &rclAmPm, cp.clrBackground);
                WinDrawText(hpsWnd, sizeof(achAmPm) - 1, (PSZ)achAmPm,
                        (PRECTL)&rclAmPm, cp.clrMinuteHand, cp.clrBackground,
                        DT_CENTER | DT_VCENTER );
            }
        }

        if (!fIconic)
        {

            WinDrawText(hpsWnd, sizeof(achTime) - 1 , (PSZ)achTime,
                    (PRECTL)&rclTime, cp.clrMinuteHand, cp.clrBackground,
                    DT_CENTER | DT_VCENTER | DT_QUERYEXTENT);

            ulCharWidth = (rclTime.xRight - rclTime.xLeft) / (sizeof(achTime) - 1 );
            ulCharModulu = (rclTime.xRight - rclTime.xLeft) % (sizeof(achTime) - 1 );
            rclCharOld.xRight = rclTime.xLeft;

            rclChar.yTop = rclTime.yTop;
            rclChar.yBottom = rclTime.yBottom;

            for (usi = 0; usi < (sizeof(achTime)); usi++)
            {
                rclChar.xLeft = rclCharOld.xRight + (ULONG)1;
                rclChar.xRight = rclChar.xLeft + ulCharWidth +
                        ((ulCharModulu > 0L) ? 1L : 0L);

                if (ulCharModulu)
                    ulCharModulu--;

                if (achTime[usi] == szTimeSep[0])
                {
                    rclChar.xRight -= 3;
                }
                else
                {
                    rclChar.xRight += 1;
                }

                rclCharOld = rclChar;

                if (achTime[usi] != achOldTime[usi])
                {
                    WinFillRect (hpsWnd, &rclChar, cp.clrBackground);
                    if (!((usi == 0) && (achTime[0] == '0') &&
                            (bTwelveHourFormat)))
                        WinDrawText (hpsWnd, 1, (PSZ)&achTime[usi], &rclChar,
                                cp.clrMinuteHand, cp.clrBackground,
                                DT_CENTER | DT_VCENTER);
                }
            }
        }
        else
        {   /*Iconic. just draw if minute changed*/

            if (strncmp(achTime,achOldTime,5))
            {
                WinFillRect(hpsWnd,&rclTime,cp.clrBackground);
                WinDrawText(hpsWnd, sizeof(achTime) - 4 , (PSZ)achTime,
                        (PRECTL)&rclTime, cp.clrMinuteHand, cp.clrBackground,
                        DT_CENTER | DT_VCENTER);
            }
        }
    }

    if ((!(cp.usDispMode & DM_TIME)) || ((cp.usDispMode & DM_DATE) &&
            (!fIconic)))
    {
        GetArrangedDate(achFinalDate);
        if (strncmp(achFinalDate, achOldDate,
                sizeof(achFinalDate) - fIconic ? 4 : 1))
        {

            WinFillRect (hpsWnd, &rclDate, cp.clrBackground);
            GpiSetCharMode (hpsWnd, CM_MODE3);

            sizef.cx = MAKEFIXED(LOUSHORT(
                            (rclDate.xRight - rclDate.xLeft) / 5), 0);
            sizef.cy = MAKEFIXED(LOUSHORT(
                            (rclDate.yTop - rclDate.yBottom) * 1000 / 1500), 0);

            GpiSetCharBox(hpsWnd, &sizef);
            WinDrawText(hpsWnd,
                        (sizeof(achFinalDate) - (fIconic ? 4 : 1) ),
                        (PSZ)achFinalDate,(PRECTL)&rclDate,
                        (LONG)cp.clrMinuteHand,
                        (LONG)cp.clrBackground,
                        (ULONG )(DT_CENTER | DT_VCENTER ) );
        }
    }

    WinReleasePS(hpsWnd);

    strncpy(achOldTime,achTime,sizeof(achOldTime));
    strncpy(achOldAmPm,achAmPm,sizeof(achOldAmPm));
    strncpy(achOldDate,achFinalDate,sizeof(achOldDate));
}
MRESULT EXPENTRY fnSaverWindowProc(HWND hwnd, ULONG msg, MPARAM mp1, MPARAM mp2)
{
  SWP swpDlg, swpParent;
  HWND hwndDlg;
  int rc;

  switch( msg )
  {
    case WM_SUBCLASS_INIT:
		case WM_CREATE: {
			RECTL rclRect;
			// Any initialization of the window and variables should come here.

			// the timer for the moving text
			ulAnimationTimerID = WinStartTimer(WinQueryAnchorBlock(hwnd), hwnd, ANIMATION_TIMER_ID, 20);

			// setup the initial coordinates for the scrolling text
			WinQueryWindowRect(hwnd, &rclRect);
			textX = rclRect.xRight;
			textY = rclRect.yTop/2;

			// Hide mouse pointer, if we're in real screen-saving mode!
			if (!bOnlyPreviewMode) WinShowPointer(HWND_DESKTOP, FALSE);
			// Initialize WMCHAR record
			internal_InitWMCHARRecord();
		break; }

		case WM_CHAR:
		if (!bOnlyPreviewMode) internal_SaveWMCHAREventToRecord(mp1, mp2);
		break;

    case WM_ASKPASSWORD:
      {
        // Get parameters
        char *pchPwdBuff = (char *) mp1;
	int iPwdBuffSize = (int) mp2;

	// Show mouse pointer, if we're screensaving.
	if (!bOnlyPreviewMode)
	  WinShowPointer(HWND_DESKTOP, TRUE);

	hwndDlg = WinLoadDlg(hwnd, hwnd,
			     fnAutoHiderDlgProc,
			     hmodOurDLLHandle,
			     DLG_PASSWORDPROTECTION,
			     NULL);
	if (!hwndDlg)
	{
	  // Could not load dialog window resources!
	  if (!bOnlyPreviewMode)
	    WinShowPointer(HWND_DESKTOP, FALSE);

	  return (MRESULT) SSMODULE_ERROR_INTERNALERROR;
	}

        // Ok, dialog window loaded!

        // Now set its texts (NLS)
        internal_SetPageFont(hwndDlg);
        internal_SetPwdProtWindowText(hwndDlg);

        // Resize the window so text will fit!
        internal_ArrangePwdProtWindowControls(hwndDlg);

	// Initialize control(s)!
	WinSendDlgItemMsg(hwndDlg, EF_PASSWORD,
			  EM_SETTEXTLIMIT,
			  (MPARAM) (iPwdBuffSize-1),
			  (MPARAM) 0);
	WinSetDlgItemText(hwndDlg, EF_PASSWORD, "");

	// Center dialog in screen
	if (WinQueryWindowPos(hwndDlg, &swpDlg))
	  if (WinQueryWindowPos(hwnd, &swpParent))
	  {
	    // Center dialog box within the screen
	    int ix, iy;
	    ix = swpParent.x + (swpParent.cx - swpDlg.cx)/2;
	    iy = swpParent.y + (swpParent.cy - swpDlg.cy)/2;
	    WinSetWindowPos(hwndDlg, HWND_TOP, ix, iy, 0, 0,
			    SWP_MOVE);
	  }
	WinSetWindowPos(hwndDlg, HWND_TOP, 0, 0, 0, 0,
			SWP_SHOW | SWP_ACTIVATE | SWP_ZORDER);

		// Re-send WM_CHAR messages if needed
		if (bFirstKeyGoesToPwdWindow) internal_ReplayWMCHARRecord();

	// Process the dialog!
	rc = WinProcessDlg(hwndDlg);

	if (rc!=PB_OK)
	{
	  // The user pressed cancel!
          rc = SSMODULE_ERROR_USERPRESSEDCANCEL;
	} else
	{
	  // The user pressed OK!
	  // Get the entered password
	  WinQueryDlgItemText(hwndDlg, EF_PASSWORD,
			      iPwdBuffSize,
			      pchPwdBuff);
          rc = SSMODULE_NOERROR;
	}

	// Destroy window
	WinDestroyWindow(hwndDlg);

	// Hide mouse pointer again, if we're screensaving.
	if (!bOnlyPreviewMode)
	  WinShowPointer(HWND_DESKTOP, FALSE);

	return (MRESULT) rc;
      }

    case WM_SHOWWRONGPASSWORD:

      // Show mouse pointer, if we're screensaving.
      if (!bOnlyPreviewMode)
	WinShowPointer(HWND_DESKTOP, TRUE);

      hwndDlg = WinLoadDlg(hwnd, hwnd,
                           fnAutoHiderDlgProc,
                           hmodOurDLLHandle,
                           DLG_WRONGPASSWORD,
                           NULL);
      if (!hwndDlg)
      {
	// Could not load dialog window resources!

	if (!bOnlyPreviewMode)
          WinShowPointer(HWND_DESKTOP, FALSE);

        return (MRESULT) SSMODULE_ERROR_INTERNALERROR;
      }

      // Ok, dialog window loaded!

      // Now set its texts (NLS)
      internal_SetPageFont(hwndDlg);
      internal_SetWrongPwdWindowText(hwndDlg);

      // Resize the window so text will fit!
      internal_ArrangeWrongPwdWindowControls(hwndDlg);

      // Center dialog in screen
      if (WinQueryWindowPos(hwndDlg, &swpDlg))
        if (WinQueryWindowPos(hwnd, &swpParent))
        {
          // Center dialog box within the screen
          int ix, iy;
          ix = swpParent.x + (swpParent.cx - swpDlg.cx)/2;
          iy = swpParent.y + (swpParent.cy - swpDlg.cy)/2;
          WinSetWindowPos(hwndDlg, HWND_TOP, ix, iy, 0, 0,
                          SWP_MOVE);
        }
      WinSetWindowPos(hwndDlg, HWND_TOP, 0, 0, 0, 0,
                      SWP_SHOW | SWP_ACTIVATE | SWP_ZORDER);

      // Process the dialog!
      rc = WinProcessDlg(hwndDlg);

      // Destroy window
      WinDestroyWindow(hwndDlg);

      // Hide mouse pointer again, if we're screensaving.
      if (!bOnlyPreviewMode)
        WinShowPointer(HWND_DESKTOP, FALSE);

      return (MRESULT) SSMODULE_NOERROR;

    case WM_SUBCLASS_UNINIT:
    case WM_DESTROY:
      // All kinds of cleanup (the opposite of everything done in WM_CREATE)
      // should come here.


      WinStopTimer(WinQueryAnchorBlock(hwnd), hwnd, ulAnimationTimerID);


      // Restore mouse pointer, if we're in real screen-saving mode!
      if (!bOnlyPreviewMode)
        WinShowPointer(HWND_DESKTOP, TRUE);
      break;

    case WM_ADJUSTWINDOWPOS:
      if (!bOnlyPreviewMode)
      {
	SWP *pSWP;

	// The following is required so that this window will be on
        // top of the xCenter window, evenif that is set to be always on top!

	// Real screensaving, here we should stay on top!
        // Set WS_TOPMOST flag again!
	WinSetWindowBits(hwnd, QWL_STYLE, WS_TOPMOST, WS_TOPMOST);

	pSWP = (SWP *) mp1;
	pSWP->hwndInsertBehind = HWND_TOP;
        pSWP->fl |= SWP_ZORDER;
      }
      break;
		case WM_PAINT: {
			HPS hpsBeginPaint;
			RECTL rclRect, blank, rclWindow;
			FONTMETRICS fm;
			int len;

			#ifdef DEBUG_LOGGING
				AddLog("WM_PAINT\n");
			#endif

			hpsBeginPaint = WinBeginPaint(hwnd, NULLHANDLE, &rclRect);
			WinQueryWindowRect(hwnd, &rclRect);
			WinQueryWindowRect(hwnd, &rclWindow);

			WinSetWindowFontMy(hwnd, "10.Courier");	
			GpiQueryFontMetrics(hpsBeginPaint, sizeof(fm), &fm);

			rclRect.xLeft = textX;
			rclRect.yTop  = textY;
			len = strlen(CfgDlgInit.pchText);
			rclRect.xRight = rclRect.xLeft + fm./*lAveCharWidth*/lMaxCharInc * len+5;
			rclRect.yBottom = rclRect.yTop - fm.lMaxBaselineExt;
			WinDrawText(hpsBeginPaint, len ,CfgDlgInit.pchText, &rclRect, CLR_WHITE, CLR_BLACK, DT_ERASERECT | DT_LEFT | DT_VCENTER);
			/* paint the black around the text*/
			blank.xLeft = 0; blank.yBottom = 0; blank.xRight = rclRect.xLeft; blank.yTop = rclWindow.yTop; WinFillRect(hpsBeginPaint, &blank, CLR_BLACK);
			blank.xLeft = rclRect.xLeft-2; blank.yBottom = rclRect.yTop; blank.xRight = rclWindow.xRight; blank.yTop = rclWindow.yTop; WinFillRect(hpsBeginPaint, &blank, CLR_BLACK);
			blank.xLeft = rclRect.xRight; blank.yBottom = 0; blank.xRight = rclWindow.xRight; blank.yTop = rclRect.yTop; WinFillRect(hpsBeginPaint, &blank, CLR_BLACK);
			blank.xLeft = rclRect.xLeft-2; blank.yBottom = 0; blank.xRight = rclRect.xRight+2; blank.yTop = rclRect.yBottom; WinFillRect(hpsBeginPaint, &blank, CLR_BLACK);
			if (rclRect.xRight <= -10) {
				WinQueryWindowRect(hwnd, &rclRect);
				textX = rclRect.xRight;
				textY = rclRect.yTop/2;
			}
			WinEndPaint(hpsBeginPaint);

			#ifdef DEBUG_LOGGING
				AddLog("WM_PAINT done\n");
			#endif
			return (MRESULT) FALSE;
		}

     case WM_TIMER:
      if (((SHORT)mp1)==ANIMATION_TIMER_ID)
      {
	// Timer, so make new image position
	textX -= 2;
	WinInvalidateRect(hwnd, NULL, FALSE);
      }
      break;

    default:
      break;
  }

  return WinDefWindowProc( hwnd, msg, mp1, mp2 );
}
Exemple #15
0
MRESULT EXPENTRY DirDialogProc( HWND hwndDlg, ULONG msg, MPARAM mp1, MPARAM mp2)
{
   switch ( msg ) {
      case WM_INITDLG:
         {
         SWP swpFileST;
         SWP swpDirST;
         SWP swpDirLB;
         SWP swpDriveST;
         SWP swpDriveCB;
         SWP swpDriveCBEF;
         SWP swpOK;
         SWP swpCancel;
         HWND hwndFileST;
         HWND hwndDirST;
         HWND hwndDirLB;
         HWND hwndDriveST;
         HWND hwndDriveCB;
         HWND hwndOK;
         HWND hwndCancel;
         HENUM henum;
         HWND hwndNext;
         ULONG ulCurY, ulCurX;
         LONG lScreenX, lScreenY, lDlgFrameX, lDlgFrameY, lTitleBarY;

         lScreenX = WinQuerySysValue(HWND_DESKTOP, SV_CXSCREEN);
         lScreenY = WinQuerySysValue(HWND_DESKTOP, SV_CYSCREEN);
         lDlgFrameX = WinQuerySysValue(HWND_DESKTOP, SV_CXDLGFRAME);
         lDlgFrameY = WinQuerySysValue(HWND_DESKTOP, SV_CYDLGFRAME);
         lTitleBarY = WinQuerySysValue(HWND_DESKTOP, SV_CYTITLEBAR);

         hwndFileST = WinWindowFromID(hwndDlg, DID_FILENAME_TXT);
         hwndDirST = WinWindowFromID(hwndDlg, DID_DIRECTORY_TXT);
         hwndDirLB = WinWindowFromID(hwndDlg, DID_DIRECTORY_LB);
         hwndDriveST = WinWindowFromID(hwndDlg, DID_DRIVE_TXT);
         hwndDriveCB = WinWindowFromID(hwndDlg, DID_DRIVE_CB);
         hwndOK = WinWindowFromID(hwndDlg, DID_OK);
         hwndCancel = WinWindowFromID(hwndDlg, DID_CANCEL);
         
#define SPACING 10
         // Reposition drives combobox
         ulCurY = SPACING;
         ulCurX = SPACING + lDlgFrameX;
         WinQueryWindowPos(hwndOK, &swpOK);
         WinSetWindowPos(hwndOK, 0, ulCurX, ulCurY, 0, 0, SWP_MOVE);
         ulCurY += swpOK.cy + SPACING;
         WinQueryWindowPos(hwndCancel, &swpCancel);
         WinSetWindowPos(hwndCancel, 0, ulCurX+swpOK.cx+10, SPACING, 0, 0, SWP_MOVE);
         WinQueryWindowPos(hwndDirLB, &swpDirLB);
         WinSetWindowPos(hwndDirLB, 0, ulCurX, ulCurY, swpDirLB.cx, swpDirLB.cy, SWP_MOVE | SWP_SIZE);
         ulCurY += swpDirLB.cy + SPACING;
         WinQueryWindowPos(hwndDirST, &swpDirST);
         WinSetWindowPos(hwndDirST, 0, ulCurX, ulCurY, swpDirST.cx, swpDirST.cy, SWP_MOVE | SWP_SIZE);
         ulCurY += swpDirST.cy + SPACING;
         WinQueryWindowPos(hwndDriveCB, &swpDriveCB);
         WinQueryWindowPos(WinWindowFromID(hwndDriveCB, CBID_EDIT), &swpDriveCBEF);
         WinSetWindowPos(hwndDriveCB, 0, ulCurX, ulCurY-(swpDriveCB.cy-swpDriveCBEF.cy)+5,
                                         swpDirLB.cx,
                                         swpDriveCB.cy,
                                         SWP_SIZE | SWP_MOVE);
         ulCurY += swpDriveCBEF.cy + SPACING;
         WinQueryWindowPos(hwndDriveST, &swpDriveST);
         WinSetWindowPos(hwndDriveST, 0, ulCurX, ulCurY, swpDriveST.cx, swpDriveST.cy, SWP_MOVE | SWP_SIZE);
         ulCurY += swpDriveST.cy + SPACING;
         WinQueryWindowPos(hwndFileST, &swpFileST);
         WinSetWindowPos(hwndFileST, 0, ulCurX, ulCurY, swpFileST.cx, swpFileST.cy, SWP_MOVE | SWP_SIZE);
         ulCurY += swpFileST.cy + SPACING;

         // Hide unused stuff
         henum = WinBeginEnumWindows(hwndDlg);
         while ((hwndNext = WinGetNextWindow(henum)) != NULLHANDLE)
         {
           USHORT usID = WinQueryWindowUShort(hwndNext, QWS_ID);
           if (usID != DID_FILENAME_TXT &&
               usID != DID_DIRECTORY_TXT &&
               usID != DID_DIRECTORY_LB &&
               usID != DID_DRIVE_TXT &&
               usID != DID_DRIVE_CB &&
               usID != DID_OK &&
               usID != DID_CANCEL &&
               usID != FID_TITLEBAR &&
               usID != FID_SYSMENU &&
               usID != FID_MINMAX) 
           {
             WinShowWindow(hwndNext, FALSE);
           }
         }

         WinSetWindowPos(hwndDlg,
                         HWND_TOP,
                         (lScreenX/2)-((swpDirLB.cx+2*SPACING+2*lDlgFrameX)/2),
                         (lScreenY/2)-((ulCurY+2*lDlgFrameY+lTitleBarY)/2),
                         swpDirLB.cx+2*SPACING+2*lDlgFrameX,
                         ulCurY+2*lDlgFrameY+lTitleBarY,
                         SWP_MOVE | SWP_SIZE);
         }
         break;
      case WM_CONTROL:
         {
         PFILEDLG pfiledlg;
         pfiledlg = (PFILEDLG)WinQueryWindowPtr(hwndDlg, QWL_USER);

         HPS           hps;
         SWP           swp;
         HWND          hwndST;
         RECTL         rectlString = {0,0,1000,1000};
         char          *ptr = NULL;
         int           iHalfLen;
         int           iLength;
         CHAR          szString[CCHMAXPATH];

         hwndST = WinWindowFromID(hwndDlg, DID_FILENAME_TXT);
       
         strcpy(szString, pfiledlg->szFullFile);
         iLength = strlen(pfiledlg->szFullFile);
         /* If we are not just a drive */
         if (iLength > 3) {
           if (szString[iLength-1] == '\\') {
             szString[iLength-1] = '\0';
             iLength--;
           }
         }
       
         hps = WinGetPS(hwndST);
         WinQueryWindowPos(hwndST, &swp);
       
         WinDrawText(hps, iLength, szString,
                          &rectlString, 0, 0, 
                          DT_BOTTOM | DT_QUERYEXTENT | DT_TEXTATTRS);
         while(rectlString.xRight > swp.cx)
         {
           iHalfLen = iLength / 2;
           if(iHalfLen == 2)
             break;
       
           ptr = szString + iHalfLen;
           memmove(ptr - 1, ptr, strlen(ptr) + 1);
           szString[iHalfLen - 2] = '.';
           szString[iHalfLen - 1] = '.';
           szString[iHalfLen]     = '.';
           iLength = strlen(szString);
           rectlString.xLeft = rectlString.yBottom = 0;
           rectlString.xRight = rectlString.yTop = 1000;
           WinDrawText(hps, iLength, szString,
                       &rectlString, 0, 0, 
                       DT_BOTTOM | DT_QUERYEXTENT | DT_TEXTATTRS);
         }
       
         WinReleasePS(hps);
         WinSetWindowText(hwndST, szString);
         }
         break;
   }      
   return WinDefFileDlgProc(hwndDlg, msg, mp1, mp2);
}
void DrawShiftText(HPS hps)
{
   RECTL        rcl;

#define CORRECTION      2

 if (!fHexOct) {
   rcl.xLeft = NUMCOL1; rcl.yBottom = ROW1 + KEYHEIGHT - CORRECTION;
   rcl.xRight = NUMCOL1 + NUMWIDTH; rcl.yTop = ROW2;
   WinDrawText(hps, -1, "\343", &rcl, 0, 0,
                DT_TEXTATTRS | DT_CENTER | DT_BOTTOM );
 } /* endif */
   rcl.xLeft = NUMCOL2; rcl.yBottom = ROW1 + KEYHEIGHT - CORRECTION;
   rcl.xRight = NUMCOL2 + NUMWIDTH; rcl.yTop = ROW2;
   WinDrawText(hps, -1, "lstX", &rcl, 0, 0,
                DT_TEXTATTRS | DT_CENTER | DT_BOTTOM );

 if (!fHexOct) {
   rcl.xLeft = NUMCOL1; rcl.yBottom = ROW2 + KEYHEIGHT - CORRECTION;
   rcl.xRight = NUMCOL1 + NUMWIDTH; rcl.yTop = ROW3;
   WinDrawText(hps, -1, "Fix", &rcl, 0, 0,
                DT_TEXTATTRS | DT_CENTER | DT_BOTTOM );
   rcl.xLeft = NUMCOL2; rcl.yBottom = ROW2 + KEYHEIGHT - CORRECTION;
   rcl.xRight = NUMCOL2 + NUMWIDTH; rcl.yTop = ROW3;
   WinDrawText(hps, -1, "Sci", &rcl, 0, 0,
                DT_TEXTATTRS | DT_CENTER | DT_BOTTOM );
   rcl.xLeft = NUMCOL3; rcl.yBottom = ROW2 + KEYHEIGHT - CORRECTION;
   rcl.xRight = NUMCOL3 + NUMWIDTH; rcl.yTop = ROW3;
   WinDrawText(hps, -1, "Eng", &rcl, 0, 0,
                DT_TEXTATTRS | DT_CENTER | DT_BOTTOM );

   rcl.xLeft = NUMCOL1; rcl.yBottom = ROW3 + KEYHEIGHT - CORRECTION;
   rcl.xRight = NUMCOL1 + NUMWIDTH; rcl.yTop = ROW4;
   WinDrawText(hps, -1, "\344y\375", &rcl, 0, 0,
                DT_TEXTATTRS | DT_CENTER | DT_BOTTOM );
   rcl.xLeft = NUMCOL2; rcl.yBottom = ROW3 + KEYHEIGHT - CORRECTION;
   rcl.xRight = NUMCOL2 + NUMWIDTH; rcl.yTop = ROW4;
   WinDrawText(hps, -1, "P\032R", &rcl, 0, 0,
                DT_TEXTATTRS | DT_CENTER | DT_BOTTOM );
   rcl.xLeft = NUMCOL3; rcl.yBottom = ROW3 + KEYHEIGHT - CORRECTION;
   rcl.xRight = NUMCOL3 + NUMWIDTH; rcl.yTop = ROW4;
   WinDrawText(hps, -1, "R\032P", &rcl, 0, 0,
                DT_TEXTATTRS | DT_CENTER | DT_BOTTOM );

   rcl.xLeft = NUMCOL1; rcl.yBottom = ROW4 + KEYHEIGHT - CORRECTION;
   rcl.xRight = NUMCOL1 + NUMWIDTH; rcl.yTop = ROW5;
   WinDrawText(hps, -1, "\344x\375", &rcl, 0, 0,
                DT_TEXTATTRS | DT_CENTER | DT_BOTTOM );
   rcl.xLeft = NUMCOL2; rcl.yBottom = ROW4 + KEYHEIGHT - CORRECTION;
   rcl.xRight = NUMCOL2 + NUMWIDTH; rcl.yTop = ROW5;
   WinDrawText(hps, -1, "Mean", &rcl, 0, 0,
                DT_TEXTATTRS | DT_CENTER | DT_BOTTOM );
   rcl.xLeft = NUMCOL3; rcl.yBottom = ROW4 + KEYHEIGHT - CORRECTION;
   rcl.xRight = NUMCOL3 + NUMWIDTH; rcl.yTop = ROW5;
   WinDrawText(hps, -1, "SDev", &rcl, 0, 0,
                DT_TEXTATTRS | DT_CENTER | DT_BOTTOM );

   rcl.xLeft = COL1; rcl.yBottom = ROW4 + KEYHEIGHT - CORRECTION;
   rcl.xRight = COL1 + NUMWIDTH; rcl.yTop = ROW5;
   WinDrawText(hps, -1, "\344x", &rcl, 0, 0,
                DT_TEXTATTRS | DT_CENTER | DT_BOTTOM );
   rcl.xLeft = COL1; rcl.yBottom = ROW3 + KEYHEIGHT - CORRECTION;
   rcl.xRight = COL1 + NUMWIDTH; rcl.yTop = ROW4;
   WinDrawText(hps, -1, "\344y", &rcl, 0, 0,
                DT_TEXTATTRS | DT_CENTER | DT_BOTTOM );
   rcl.xLeft = COL1; rcl.yBottom = ROW2 + KEYHEIGHT - CORRECTION;
   rcl.xRight = COL1 + NUMWIDTH; rcl.yTop = ROW3;
   WinDrawText(hps, -1, "\344xy", &rcl, 0, 0,
                DT_TEXTATTRS | DT_CENTER | DT_BOTTOM );
   rcl.xLeft = COL1; rcl.yBottom = ROW1 + KEYHEIGHT - CORRECTION;
   rcl.xRight = COL1 + NUMWIDTH; rcl.yTop = ROW2;
   WinDrawText(hps, -1, "n", &rcl, 0, 0,
                DT_TEXTATTRS | DT_CENTER | DT_BOTTOM );

   rcl.xLeft = COL3; rcl.yBottom = ROW5 + KEYHEIGHT - CORRECTION;
   rcl.xRight = COL3 + NUMWIDTH; rcl.yTop = ROW6;
   WinDrawText(hps, -1, "Mod", &rcl, 0, 0,
                DT_TEXTATTRS | DT_CENTER | DT_BOTTOM );
   rcl.xLeft = COL4; rcl.yBottom = ROW5 + KEYHEIGHT - CORRECTION;
   rcl.xRight = COL4 + NUMWIDTH; rcl.yTop = ROW6;
   WinDrawText(hps, -1, "FEx", &rcl, 0, 0,
                DT_TEXTATTRS | DT_CENTER | DT_BOTTOM );
 } /* endif */

   rcl.xLeft = COL5; rcl.yBottom = ROW5 + KEYHEIGHT - CORRECTION;
   rcl.xRight = COL5 + NUMWIDTH; rcl.yTop = ROW6;
   WinDrawText(hps, -1, "CLx", &rcl, 0, 0,
                DT_TEXTATTRS | DT_CENTER | DT_BOTTOM );

 if (!fHexOct) {
/*
   rcl.xLeft = COL2; rcl.yBottom = ROW6 + KEYHEIGHT - CORRECTION;
   rcl.xRight = COL2 + NUMWIDTH; rcl.yTop = ROW8;
   WinDrawText(hps, -1, "Asn", &rcl, 0, 0,
                DT_TEXTATTRS | DT_CENTER | DT_BOTTOM );
*/
   rcl.xLeft = COL3; rcl.yBottom = ROW6 + KEYHEIGHT - CORRECTION;
   rcl.xRight = COL3 + NUMWIDTH; rcl.yTop = ROW8;
   WinDrawText(hps, -1, "\032Hr", &rcl, 0, 0,
                DT_TEXTATTRS | DT_CENTER | DT_BOTTOM );
   rcl.xLeft = COL4; rcl.yBottom = ROW6 + KEYHEIGHT - CORRECTION;
   rcl.xRight = COL4 + NUMWIDTH; rcl.yTop = ROW8;
   WinDrawText(hps, -1, "Hms", &rcl, 0, 0,
                DT_TEXTATTRS | DT_CENTER | DT_BOTTOM );

   rcl.xLeft = COL5; rcl.yBottom = ROW6 + KEYHEIGHT - CORRECTION;
   rcl.xRight = COL5 + NUMWIDTH; rcl.yTop = ROW8;
   WinDrawText(hps, -1, "n!", &rcl, 0, 0,
                DT_TEXTATTRS | DT_CENTER | DT_BOTTOM );

   rcl.xLeft = COL1; rcl.yBottom = ROW7 + KEYHEIGHT - CORRECTION;
   rcl.xRight = COL1 + NUMWIDTH; rcl.yTop = ROW8;
   WinDrawText(hps, -1, "CL\344", &rcl, 0, 0,
                DT_TEXTATTRS | DT_CENTER | DT_BOTTOM );
   rcl.xLeft = COL2; rcl.yBottom = ROW7 + KEYHEIGHT - CORRECTION;
   rcl.xRight = COL2 + NUMWIDTH; rcl.yTop = ROW8;
   WinDrawText(hps, -1, "%", &rcl, 0, 0,
                DT_TEXTATTRS | DT_CENTER | DT_BOTTOM );
   rcl.xLeft = COL3 - CORRECTION; rcl.yBottom = ROW7 + KEYHEIGHT - CORRECTION;
   rcl.xRight = COL3 + NUMWIDTH; rcl.yTop = ROW8;
   WinDrawText(hps, -1, "aSin", &rcl, 0, 0,
                DT_TEXTATTRS | DT_CENTER | DT_BOTTOM );
   rcl.xLeft = COL4 - CORRECTION; rcl.yBottom = ROW7 + KEYHEIGHT - CORRECTION;
   rcl.xRight = COL4 + NUMWIDTH; rcl.yTop = ROW8;
   WinDrawText(hps, -1, "aCos", &rcl, 0, 0,
                DT_TEXTATTRS | DT_CENTER | DT_BOTTOM );
   rcl.xLeft = COL5 - CORRECTION; rcl.yBottom = ROW7 + KEYHEIGHT - CORRECTION;
   rcl.xRight = COL5 + NUMWIDTH; rcl.yTop = ROW8;
   WinDrawText(hps, -1, "aTan", &rcl, 0, 0,
                DT_TEXTATTRS | DT_CENTER | DT_BOTTOM );

   rcl.xLeft = COL1; rcl.yBottom = ROW8 + KEYHEIGHT - CORRECTION;
   rcl.xRight = COL1 + NUMWIDTH; rcl.yTop = rcl.yBottom + FUNCWIDTH;
   WinDrawText(hps, -1, "\344-", &rcl, 0, 0,
                DT_TEXTATTRS | DT_CENTER | DT_BOTTOM );
   rcl.xLeft = COL2; rcl.yBottom = ROW8 + KEYHEIGHT;
   rcl.xRight = COL2 + NUMWIDTH; rcl.yTop = rcl.yBottom + FUNCWIDTH;
   WinDrawText(hps, -1, "y^x", &rcl, 0, 0,
                DT_TEXTATTRS | DT_CENTER | DT_BOTTOM );
   rcl.xLeft = COL3; rcl.yBottom = ROW8 + KEYHEIGHT - CORRECTION;
   rcl.xRight = COL3 + NUMWIDTH; rcl.yTop = rcl.yBottom + FUNCWIDTH;
   WinDrawText(hps, -1, "x\375", &rcl, 0, 0,
                DT_TEXTATTRS | DT_CENTER | DT_BOTTOM );
   rcl.xLeft = COL4; rcl.yBottom = ROW8 + KEYHEIGHT - CORRECTION;
   rcl.xRight = COL4 + NUMWIDTH; rcl.yTop = rcl.yBottom + FUNCWIDTH;
   WinDrawText(hps, -1, "10^x", &rcl, 0, 0,
                DT_TEXTATTRS | DT_CENTER | DT_BOTTOM );
   rcl.xLeft = COL5; rcl.yBottom = ROW8 + KEYHEIGHT - CORRECTION;
   rcl.xRight = COL5 + NUMWIDTH; rcl.yTop = rcl.yBottom + FUNCWIDTH;
   WinDrawText(hps, -1, "e^x", &rcl, 0, 0,
                DT_TEXTATTRS | DT_CENTER | DT_BOTTOM );
 } /* endif */
   rcl.xLeft = COL5 + FUNCWIDTH*2/3; rcl.yBottom = ROWDISPLAY;
   rcl.xRight = rcl.xLeft + FUNCWIDTH; rcl.yTop = rcl.yBottom + KEYHEIGHT;
   WinDrawText(hps, -1, ":X", &rcl, 0, 0,
                DT_TEXTATTRS | DT_LEFT | DT_VCENTER );
   rcl.xLeft = COL5 + FUNCWIDTH*2/3; rcl.yBottom = ROWDISPLAY+KEYHEIGHT*4/3;
   rcl.xRight = rcl.xLeft + FUNCWIDTH; rcl.yTop = rcl.yBottom + KEYHEIGHT;
   WinDrawText(hps, -1, ":Y", &rcl, 0, 0,
                DT_TEXTATTRS | DT_LEFT | DT_VCENTER );
   rcl.xLeft = COL5 + FUNCWIDTH*2/3; rcl.yBottom = ROWDISPLAY+KEYHEIGHT*8/3;
   rcl.xRight = rcl.xLeft + FUNCWIDTH; rcl.yTop = rcl.yBottom + KEYHEIGHT;
   WinDrawText(hps, -1, ":Z", &rcl, 0, 0,
                DT_TEXTATTRS | DT_LEFT | DT_VCENTER );
   rcl.xLeft = COL5 + FUNCWIDTH*2/3; rcl.yBottom = ROWDISPLAY+KEYHEIGHT*12/3;
   rcl.xRight = rcl.xLeft + FUNCWIDTH; rcl.yTop = rcl.yBottom + KEYHEIGHT;
   WinDrawText(hps, -1, ":T", &rcl, 0, 0,
                DT_TEXTATTRS | DT_LEFT | DT_VCENTER );
}
VOID MainPaint(HWND hwnd)
{
    RECTL  rclUpdate;
    RECTL  rclWnd;
    RECTL  rclDraw;

    HPS hps;
    POINTL pt;
    LONG        LineHeight;
    LONG        Descender;
    PCHAR  pText;
    LONG   ptTextStart;
static
    LONG   Inc[] = { 10, 10, 10,
                     12, 12, 12,
                     14, 14, 14,
                     16, 16, 16,
                     18, 18, 18,
                     20, 20, 20,
                     22, 22, 22,
                     24, 24, 24
                   };

//BIDI
static
    PCHAR   TextLines[] = {
            "~DrawText",             //0
            "CharString",            //1
            "CharStringAt",          //2
            "CharStringPos",         //3
            "CharStringPosAt",       //4
            "DrawText(QueryRect)",   //5
            "QueryCharStringPos",    //6
            "QueryCharStringPosAt",  //7
            "QueryTextBox"           //8
            };

static
    PCHAR   TextLines_API[] = {
            "WinDrawText:",                 //0
            "GpiCharString:",               //1
            "GpiCharStringAt:",             //2
            "GpiCharStringPos:",            //3
            "GpiCharStringPosAt:",          //4
            "WinDrawText(QueryRect):",      //5
            "GpiQueryCharStringPos:",       //6
            "GpiQueryCharStringPosAt:",     //7
            "GpiQueryTextBox:",             //8
            "Current Clipboard TextBuffer:" //9
            };

    ULONG   GpiBidiAttr;
    ULONG   NullBidiAttr = 0L;

    hps = WinBeginPaint(hwnd, NULLHANDLE, (PRECTL)&rclUpdate);

    // Get the bidi attribute of the presentation space, so that
    // we can flip/flip between a NULL bidiattribute and this one
    //
    GpiBidiAttr = GpiQueryBidiAttr(hps);


    /* fill update rectangle with window color */
    WinFillRect(hps, (PRECTL)&rclUpdate, SYSCLR_PAGEBACKGROUND );

    CalcLineHeight(hps, &LineHeight, &Descender);

    GpiSetColor    ( hps, CLR_BLUE ) ;
    GpiSetBackColor( hps, CLR_RED  ) ;

    WinQueryWindowRect(hwnd, (PRECTL)&rclWnd);
    ptTextStart = rclWnd.xRight * 2/5  ;

    // -------------------------------------
    // WinDrawText!
    // -------------------------------------
    pt.x = 0;
    pt.y = rclWnd.yTop - LineHeight + Descender;

    rclDraw.xLeft   = rclWnd.xLeft;
    rclDraw.xRight  = rclWnd.xRight;
    rclDraw.yBottom = pt.y - Descender;
    rclDraw.yTop    = rclDraw.yBottom + LineHeight ;

    GpiSetBidiAttr(hps, NullBidiAttr);

    pText = TextLines_API[0];
    WinDrawText ( hps, strlen(pText), pText, &rclDraw, 0L, 0L,
                  DT_LEFT | DT_ERASERECT | DT_TEXTATTRS | DT_MNEMONIC );

    rclDraw.xLeft = ptTextStart;

    GpiSetBidiAttr(hps, GpiBidiAttr);

    pText = TextLines[0];
    WinDrawText ( hps, strlen(pText), pText, &rclDraw, 0L, 0L,
                  DT_LEFT | DT_ERASERECT | DT_TEXTATTRS | DT_MNEMONIC );

    // -------------------------------------
    // GpiCharString
    // -------------------------------------
    pt.y -=  LineHeight;
    pt.x = 0;
    GpiSetCurrentPosition( hps, &pt ) ;
    pText = TextLines_API[1];
    GpiSetBidiAttr(hps, NullBidiAttr);
    GpiCharString(hps, strlen(pText), pText);

    pt.x = ptTextStart;
    GpiSetCurrentPosition( hps, &pt ) ;
    pText = TextLines[1];
    GpiSetBidiAttr(hps, GpiBidiAttr);
    GpiCharString(hps, strlen(pText), pText);

    // -------------------------------------
    //  GpiCharStringAt
    // -------------------------------------
    pt.y -=  LineHeight ;
    pt.x = 0;
    pText = TextLines_API[2];
    GpiSetBidiAttr(hps, NullBidiAttr);
    GpiCharStringAt(hps, &pt, strlen(pText), pText);

    pt.x = ptTextStart;
    pText = TextLines[2];
    GpiSetBidiAttr(hps, GpiBidiAttr);
    GpiCharStringAt(hps, &pt, strlen(pText), pText);

    // -------------------------------------
    //  GpiCharStringPos
    // -------------------------------------
    pt.y -=  LineHeight ;
    pt.x = 0;
    GpiSetCurrentPosition( hps, &pt ) ;

    rclDraw.xLeft   = rclWnd.xLeft;
    rclDraw.xRight  = ptTextStart - 4;
    rclDraw.yBottom = pt.y - Descender;
    rclDraw.yTop    = rclDraw.yBottom + LineHeight ;

    pText = TextLines_API[3];
    GpiSetBidiAttr(hps, NullBidiAttr);
    GpiCharStringPos(hps, &rclDraw, CHS_VECTOR | CHS_OPAQUE,
                     strlen(pText), pText, &Inc[0] );

    rclDraw.xLeft   = ptTextStart;
    rclDraw.xRight  = rclWnd.xRight;
    rclDraw.yBottom = pt.y - Descender  ;
    rclDraw.yTop    = rclDraw.yBottom + LineHeight ;

    pt.x            = ptTextStart;
    GpiSetCurrentPosition( hps, &pt ) ;

    pText = TextLines[3];
    GpiSetBidiAttr(hps, GpiBidiAttr);
    GpiCharStringPos(hps, &rclDraw, CHS_VECTOR | CHS_OPAQUE,
                     strlen(pText), pText, &Inc[0]);


    // -------------------------------------
    //  GpiCharStringPosAt
    // -------------------------------------
    pt.y -=  LineHeight ;
    pt.x = 0;

    rclDraw.xLeft   = rclWnd.xLeft;
    rclDraw.xRight  = ptTextStart - 4;
    rclDraw.yBottom = pt.y - Descender  ;
    rclDraw.yTop    = rclDraw.yBottom + LineHeight ;

    pText = TextLines_API[4];
    GpiSetBidiAttr(hps, NullBidiAttr);
    GpiCharStringPosAt(hps, &pt, &rclDraw, CHS_VECTOR | CHS_OPAQUE,
                       strlen(pText), pText, &Inc[0] );

    rclDraw.xLeft   = ptTextStart;
    rclDraw.xRight  = rclWnd.xRight;
    rclDraw.yBottom = pt.y - Descender  ;
    rclDraw.yTop    = rclDraw.yBottom + LineHeight ;
    pt.x            = ptTextStart;

    pText = TextLines[4];
    GpiSetBidiAttr(hps, GpiBidiAttr);
    GpiCharStringPosAt(hps, &pt, &rclDraw, CHS_VECTOR | CHS_OPAQUE,
                       strlen(pText), pText, &Inc[0]);

    // -------------------------------------
    //  Current Clipboard TextBuffer
    //
    //  This is used as a means of "looking inside" the
    //  clipbaord. (This is a clipboard viewer for the poor...)
    //  This part shows the text in szPasteText.
    //  To operate:
    //  - Copy/Cut text from anywhere to the clipbaord.
    //  - select:    Edit --> Paste --> No Conversion
    //  - The clipboard text will be shown (UNMODIFIED BUFFER)
    //    in our window.
    // -------------------------------------
    pt.y -=  LineHeight ;
    pt.x = 0;

    pText = TextLines_API[9];
    GpiSetBidiAttr(hps, NullBidiAttr);
    GpiCharStringAt(hps, &pt, strlen(pText), pText);

    pt.x            = ptTextStart;
    pText           = szPasteText;
    GpiCharStringAt(hps, &pt, strlen(pText), pText);

//BIDI- end

    /*
     * Add painting routines here.  Hps is now the HPS for
     * the window and rclUpdate contains the update rectangle.
     */

    WinEndPaint(hps);

}   /* MainPaint() */
Exemple #18
0
MRESULT	EXPENTRY DriverWndProc(HWND hWnd, ULONG	msg, MPARAM mp1, MPARAM	mp2)

{
CHAR	     szFile[CCHMAXPATH];   /* File HOlder			*/
FILEFINDBUF3 findbuf;		   /* File Find	Buffer			*/
FONTMETRICS  fm;		   /* Font Metrics Structure		*/
HDIR	     hDir = (HDIR)HDIR_CREATE; /* Directory Handle		*/
HPS	     hPS;		   /* Presentation Space Handle		*/
HWND	     hwndListBox;	   /* List Box Window Handle		*/
LISTBOXCDATA lbwcd;		   /* List Box Window Control Data	*/
POWNERITEM   poi;		   /* Owner Item			*/
RECTL	     rcl;		   /* Client Window Rectangle		*/
ULONG	     ulFileCnt = 1UL;	   /* File Counter Holder		*/
register INT i,	k, n;		   /* Loop Counter			*/

switch ( msg )
   {
		       /* Perform window initialization			*/
   case	WM_CREATE :
       hptrArrow = WinQuerySysPointer(HWND_DESKTOP, SPTR_ARROW,	FALSE);
       WinSetPointer(HWND_DESKTOP, hptrWait = WinQuerySysPointer(HWND_DESKTOP, SPTR_WAIT, FALSE));
       memset(&lbwcd, 0, sizeof(LISTBOXCDATA));
       lbwcd.cb	= sizeof(LISTBOXCDATA);
       lbwcd.ulVersion = LBV_110;
       lbwcd.vdata.lbcd1_1.flExtStyles = LSXS_CHECKBOX | LSXS_EDITABLE;

       hwndList1 = WinCreateWindow(hWnd, "ListBoxWindow", "", LS_HORZSCROLL | LS_EXTENDEDSEL | WS_VISIBLE,
				   10L,	10L, 100L, 175L, hWnd,
				   HWND_TOP, 1024UL, (PVOID)&lbwcd, (PVOID)NULL);

       hwndListx = WinCreateWindow(hWnd, "ListBoxWindow", "", LS_HORZSCROLL | LS_EXTENDEDSEL | WS_VISIBLE,
				   125L, 10L, 100L, 175L, hWnd,
				   HWND_TOP, 1024UL, (PVOID)&lbwcd, (PVOID)NULL);

       hwndList2 = WinCreateWindow(hWnd, "ListBoxWindow", "", WS_VISIBLE, 10L, 190L, 250L, 200L, hWnd,
				   HWND_TOP, 1025UL, (PVOID)&lbwcd, (PVOID)NULL);

       WinSendMsg(hwndList1, LMXM_SETSOUNDEVENT, MPFROMLONG(LSND_SINGLECLICK),
		  MPFROMP("ahooga.wav"));
       WinSendMsg(hwndListx, LMXM_SETSOUNDEVENT, MPFROMLONG(LSND_DOUBLECLICK),
		  MPFROMP("flush.wav"));

       hwndListA = WinCreateWindow(hWnd, WC_LISTBOX, "", LS_OWNERDRAW |	LS_HORZSCROLL |	LS_MULTIPLESEL | WS_VISIBLE,
				   275L, 10L, 100L, 175L, hWnd,
				   HWND_TOP, 1026UL, (PVOID)NULL, (PVOID)NULL);

		       /* Sub-class the	default	window procedure with	*/
		       /* new one which	will handle specific messages	*/
		       /* allowing better control over the sizing frame	*/

       hwndListB = WinCreateWindow(hWnd, WC_LISTBOX, "", WS_VISIBLE | LS_EXTENDEDSEL, 275L, 190L, 250L,	200L, hWnd,
				   HWND_TOP, 1027UL, (PVOID)NULL, (PVOID)NULL);

       for ( i = 0; i <	10; i++	)
	   {
	   sprintf(szFile, "Item %04d Item %04d Item %04d", i, i, i);
	       WinSendMsg(hwndListx, LM_INSERTITEM,
			  MPFROMLONG(LIT_END),
			  MPFROMP(szFile));
	   }

       n = (INT)WinSendMsg(hwndList2, LMX_CALCLINECOUNT, MPFROMLONG(175L), 0L);

       k = 0;

       WinSendMsg(hwndList2, LM_SETITEMHEIGHT, MPFROMLONG(36L),	0L);

       if ( !DosFindFirst("*.*", &hDir,	FILE_NORMAL,
			  (PVOID)&findbuf, sizeof(FILEFINDBUF3),
			  &ulFileCnt, FIL_STANDARD) )
	   {
	   do
	       {
	       WinSendMsg(hwndList2, LM_INSERTITEM,
			  MPFROMLONG(LIT_SORTDESCENDING),
			  MPFROMP(findbuf.achName));
	       WinSendMsg(hwndList1, LM_INSERTITEM,
			  MPFROMLONG(LIT_SORTASCENDING),
			  MPFROMP(findbuf.achName));
	       if ( ++k	> n )
		   WinSendMsg(hwndList2, LM_SETTOPINDEX, MPFROMLONG(k -	n), 0L);
	       WinSendMsg(hwndListB, LM_INSERTITEM,
			  MPFROMLONG(LIT_SORTDESCENDING),
			  MPFROMP(findbuf.achName));
	       WinSendMsg(hwndListA, LM_INSERTITEM,
			  MPFROMLONG(LIT_SORTASCENDING),
			  MPFROMP(findbuf.achName));
	       }
	       while ( !DosFindNext(hDir, &findbuf, sizeof(FILEFINDBUF3), &ulFileCnt) );
	   DosFindClose(hDir);
	   }
       break;

   case	WM_BUTTON1DOWN :
       WinEnableWindowUpdate(hwndListA,	FALSE);
       WinEnableWindowUpdate(hwndList1,	FALSE);

       WinSendMsg(hwndListA, LM_DELETEALL, 0L, 0L);
       WinSendMsg(hwndList1, LM_DELETEALL, 0L, 0L);
       i = 0;
       if ( !DosFindFirst("*.*", &hDir,	FILE_NORMAL,
			  (PVOID)&findbuf, sizeof(FILEFINDBUF3),
			  &ulFileCnt, FIL_STANDARD) )
	   {
	   do
	       {
	       WinSendMsg(hwndListA, LM_INSERTITEM,
			  MPFROMLONG(LIT_SORTASCENDING),
			  MPFROMP(findbuf.achName));
	       WinSendMsg(hwndList1, LM_INSERTITEM,
			  MPFROMLONG(LIT_SORTASCENDING),
			  MPFROMP(findbuf.achName));
	       ++i;
	       }
	       while ( !DosFindNext(hDir, &findbuf, sizeof(FILEFINDBUF3), &ulFileCnt) );
	   DosFindClose(hDir);
	   }
       WinShowWindow(hwndListA,	TRUE);
       WinShowWindow(hwndList1,	TRUE);

       while ( i )
	   {
	   if (	i % 2 )
	       {
	       WinSendMsg(hwndListA, LM_SELECTITEM, MPFROMLONG(i - 1), MPFROMLONG(TRUE));
	       WinSendMsg(hwndList1, LM_SELECTITEM, MPFROMLONG(i - 1), MPFROMLONG(TRUE));
	       }
	   --i;
	   }
       break;

   case	WM_CONTROL :
       switch (	SHORT2FROMMP(mp1) )
	   {
		       /* Process double click on a List Box		*/

	   case	LN_SELECT :
	       switch (	SHORT1FROMMP(mp1) )
		   {
		   case	1024UL :
		   /*  WinAlarm(HWND_DESKTOP, WA_NOTE);	  */
		       break;

		   case	1027UL :
		   /*  WinAlarm(HWND_DESKTOP, WA_ERROR);  */
		       break;
		   }
	       break;
	   }
       break;


   case	WM_MEASUREITEM :
       GpiQueryFontMetrics(hPS = WinGetPS(hWnd), sizeof(FONTMETRICS), &fm);
       WinReleasePS(hPS);
       return(MRFROMLONG(fm.lMaxBaselineExt));

		       /* Draw a list box item				*/
   case	WM_DRAWITEM :

       if ( SHORT1FROMMP(mp1) == 1024 )
	   hwndListBox = hwndList1;
       else
	   if (	SHORT1FROMMP(mp1) == 1026 )
	       hwndListBox = hwndListA;

		       /* Point	to Owner Item information		*/

       poi = (POWNERITEM)mp2;
       GpiCreateLogColorTable(poi->hps,	0L, LCOLF_RGB, 0L, 0L, (PLONG)NULL);

       i = (INT)LONGFROMMR(WinSendMsg(hwndListBox, LM_QUERYITEMTEXTLENGTH,
				      MPFROMLONG(poi->idItem), 0L));

       i = (INT)LONGFROMMR(WinSendMsg(hwndListBox, LM_QUERYITEMTEXT,
				      MPFROM2SHORT(poi->idItem,	CCHMAXPATH),
				      MPFROMP(szFile)));

		       /* Check	to see if item to be drawn or		*/
		       /* highlighted					*/

       if ( poi->fsState != poi->fsStateOld )
	   {
	   WinFillRect(poi->hps, &poi->rclItem,	RGBCLR_DIALOGBACKGROUND);

	   if (	poi->fsState )
	       WinDrawText(poi->hps, -1L, szFile, &poi->rclItem,
			   RGB_BLACK, RGBCLR_DIALOGBACKGROUND, DT_LEFT | DT_VCENTER |
			   DT_ERASERECT);

		       /* Set item highlighting	by inverting the items	*/
		       /* rectangle colour				*/

	   WinInvertRect(poi->hps, &poi->rclItem);

	   if (	!poi->fsState )
	       WinDrawText(poi->hps, -1L, szFile, &poi->rclItem,
			   RGB_BLACK, RGBCLR_DIALOGBACKGROUND, DT_LEFT | DT_VCENTER |
			   DT_ERASERECT);
	   poi->fsState	= poi->fsStateOld = 0;
	   }
       else
	   {
		       /* Item needs to	be drawn, get item rectangle	*/
		       /* item position					*/

	   WinFillRect(poi->hps, &poi->rclItem,	RGBCLR_DIALOGBACKGROUND);

	   WinDrawText(poi->hps, -1L, szFile, &poi->rclItem,
		       RGB_BLACK, RGBCLR_DIALOGBACKGROUND, DT_LEFT | DT_VCENTER	|
		       DT_ERASERECT);
	   }
       return(MRFROMLONG(TRUE));

   case	WM_BUTTON1DBLCLK :
       i = 0;
       if ( !DosFindFirst("*.*", &hDir,	FILE_NORMAL,
			  (PVOID)&findbuf, sizeof(FILEFINDBUF3),
			  &ulFileCnt, FIL_STANDARD) )
	   {
	   do
	       {
	       ++i;
	       }
	       while ( !DosFindNext(hDir, &findbuf, sizeof(FILEFINDBUF3), &ulFileCnt) );
	   DosFindClose(hDir);
	   }

       while ( i )
	   {
	   if (	i % 2 )
	       {
	       WinSendMsg(hwndListA, LM_SELECTITEM, MPFROMLONG(i - 1), MPFROMLONG(FALSE));
	       WinSendMsg(hwndList1, LM_SELECTITEM, MPFROMLONG(i - 1), MPFROMLONG(FALSE));
	       }
	   --i;
	   }
       break;

   case	WM_BUTTON2DOWN :

       for ( i = 0; i <	5; i++ )
	   WinSendMsg(hwndListx, LM_DELETEITEM,	MPFROMSHORT(2),	0L);

#if 0
       WinSendMsg(hwndListA, LM_SELECTITEM, MPFROMLONG(LIT_NONE), MPFROMLONG(TRUE));

       i = LIT_FIRST;
       while ( (i = (INT)LONGFROMMR(WinSendMsg(hwndList1, LM_QUERYSELECTION, MPFROMLONG(i), 0L))) != LIT_NONE )
	   WinSendMsg(hwndList1, LM_SELECTITEM,	MPFROMLONG(i), MPFROMLONG(FALSE));
#endif
       break;
		       /* Erase	background				*/

   case	WM_ERASEBACKGROUND :
       WinQueryWindowRect(hWnd,	&rcl);
       WinFillRect((HPS)mp1, &rcl, SYSCLR_DIALOGBACKGROUND);
       break;
		       /* Paint	the main client	window			*/
   case	WM_PAINT :
       WinSetPointer(HWND_DESKTOP, hptrWait);

       WinFillRect(hPS = WinBeginPaint(hWnd, (HPS)NULL,	&rcl), &rcl, SYSCLR_DIALOGBACKGROUND);

       WinEndPaint(hPS);
       WinSetPointer(HWND_DESKTOP, hptrArrow);
       break;
		       /* Close	Down					*/
   case	WM_CLOSE :

       WinPostMsg(hWnd,	WM_QUIT, 0L, 0L);
       break;

   case	WM_DESTROY :
       WinDestroyPointer(hptrArrow);
       WinDestroyPointer(hptrWait);
       break;
		       /* Default message processing			*/
   default:
       return(WinDefWindowProc(hWnd, msg, mp1, mp2));
   }
return(0L);
}
MRESULT EXPENTRY ClientWndProc (HWND hwnd, ULONG msg, MPARAM mp1, MPARAM mp2)
     {
     static INT aiPuzzle[NUMROWS][NUMCOLS],
                iBlankRow, iBlankCol, cxSquare, cySquare ;
     CHAR       szNum[10] ;
     HPS        hps ;
     HWND       hwndFrame ;
     INT        iRow, iCol, iMouseRow, iMouseCol, i ;
     POINTL     ptl ;
     RECTL      rcl, rclInvalid, rclIntersect ;
     SIZEL      sizl ;

     switch (msg)
          {
          case WM_CREATE:
                              // Calculate square size in pixels

               hps = WinGetPS (hwnd) ;
               sizl.cx = sizl.cy = 0 ;
               GpiSetPS (hps, &sizl, PU_LOENGLISH) ;
               ptl.x = SQUARESIZE ;
               ptl.y = SQUARESIZE ;
               GpiConvert (hps, CVTC_PAGE, CVTC_DEVICE, 1L, &ptl) ;
               WinReleasePS (hps) ;

               cxSquare = ptl.x ;
               cySquare = ptl.y ;

                              // Calculate client window size and position

               rcl.xLeft   = (WinQuerySysValue (HWND_DESKTOP, SV_CXSCREEN) -
                                           NUMCOLS * cxSquare) / 2 ;
               rcl.yBottom = (WinQuerySysValue (HWND_DESKTOP, SV_CYSCREEN) -
                                           NUMROWS * cySquare) / 2 ;
               rcl.xRight  = rcl.xLeft   + NUMCOLS * cxSquare ;
               rcl.yTop    = rcl.yBottom + NUMROWS * cySquare ;

                              // Set frame window position and size

               hwndFrame = WinQueryWindow (hwnd, QW_PARENT) ;
               WinCalcFrameRect (hwndFrame, &rcl, FALSE) ;
               WinSetWindowPos  (hwndFrame, NULLHANDLE,
                                 rcl.xLeft, rcl.yBottom,
                                 rcl.xRight - rcl.xLeft,
                                 rcl.yTop - rcl.yBottom,
                                 SWP_MOVE | SWP_SIZE | SWP_ACTIVATE) ;

                              // Initialize the aiPuzzle array

               WinSendMsg (hwnd, WM_COMMAND, MPFROMSHORT (IDM_NORMAL), NULL) ;
               return 0 ;

          case WM_PAINT:
               hps = WinBeginPaint (hwnd, NULLHANDLE, &rclInvalid) ;

                              // Draw the squares

               for (iRow = NUMROWS - 1 ; iRow >= 0 ; iRow--)
                    for (iCol = 0 ; iCol < NUMCOLS ; iCol++)
                         {
                         rcl.xLeft   = cxSquare * iCol ;
                         rcl.yBottom = cySquare * iRow ;
                         rcl.xRight  = rcl.xLeft   + cxSquare ;
                         rcl.yTop    = rcl.yBottom + cySquare ;

                         if (!WinIntersectRect (0, &rclIntersect,
                                                &rcl, &rclInvalid))
                              continue ;

                         if (iRow == iBlankRow && iCol == iBlankCol)
                              WinFillRect (hps, &rcl, CLR_BLACK) ;
                         else
                              {
                              WinDrawBorder (hps, &rcl, 5, 5,
                                             CLR_PALEGRAY, CLR_DARKGRAY,
                                             DB_STANDARD | DB_INTERIOR) ;

                              WinDrawBorder (hps, &rcl, 2, 2,
                                             CLR_BLACK, 0L, DB_STANDARD) ;

                              sprintf (szNum, "%d", aiPuzzle[iRow][iCol]) ;

                              WinDrawText (hps, -1, szNum,
                                           &rcl, CLR_WHITE, CLR_DARKGRAY,
                                           DT_CENTER | DT_VCENTER) ;
                              }
                         }
               WinEndPaint (hps) ;
               return 0 ;

          case WM_BUTTON1DOWN:
               iMouseCol = MOUSEMSG(&msg)->x / cxSquare ;
               iMouseRow = MOUSEMSG(&msg)->y / cySquare ;

                              // Check if mouse was in valid area

               if ( iMouseRow < 0          || iMouseCol < 0           ||
                    iMouseRow >= NUMROWS   || iMouseCol >= NUMCOLS    ||
                   (iMouseRow != iBlankRow && iMouseCol != iBlankCol) ||
                   (iMouseRow == iBlankRow && iMouseCol == iBlankCol))
                         break ;

                              // Move a row right or left

               if (iMouseRow == iBlankRow)
                    {
                    if (iMouseCol < iBlankCol)
                         for (iCol = iBlankCol ; iCol > iMouseCol ; iCol--)
                              aiPuzzle[iBlankRow][iCol] =
                                   aiPuzzle[iBlankRow][iCol - 1] ;
                    else
                         for (iCol = iBlankCol ; iCol < iMouseCol ; iCol++)
                              aiPuzzle[iBlankRow][iCol] =
                                   aiPuzzle[iBlankRow][iCol + 1] ;
                    }
                              // Move a column up or down
               else
                    {
                    if (iMouseRow < iBlankRow)
                         for (iRow = iBlankRow ; iRow > iMouseRow ; iRow--)
                              aiPuzzle[iRow][iBlankCol] =
                                   aiPuzzle[iRow - 1][iBlankCol] ;
                    else
                         for (iRow = iBlankRow ; iRow < iMouseRow ; iRow++)
                              aiPuzzle[iRow][iBlankCol] =
                                   aiPuzzle[iRow + 1][iBlankCol] ;
                    }
                              // Calculate invalid rectangle

               rcl.xLeft   = cxSquare *  min (iMouseCol, iBlankCol) ;
               rcl.yBottom = cySquare *  min (iMouseRow, iBlankRow) ;
               rcl.xRight  = cxSquare * (max (iMouseCol, iBlankCol) + 1) ;
               rcl.yTop    = cySquare * (max (iMouseRow, iBlankRow) + 1) ;

                              // Set new array and blank values

               iBlankRow = iMouseRow ;
               iBlankCol = iMouseCol ;
               aiPuzzle[iBlankRow][iBlankCol] = 0 ;

                              // Invalidate rectangle

               WinInvalidateRect (hwnd, &rcl, FALSE) ;
               break ;

          case WM_CHAR:
               if (!(CHARMSG(&msg)->fs & KC_VIRTUALKEY) ||
                     CHARMSG(&msg)->fs & KC_KEYUP)
                         return 0 ;

                              // Mimic a WM_BUTTON1DOWN message

               iMouseCol = iBlankCol ;
               iMouseRow = iBlankRow ;

               switch (CHARMSG(&msg)->vkey)
                    {
                    case VK_LEFT:   iMouseCol++ ;  break ;
                    case VK_RIGHT:  iMouseCol-- ;  break ;
                    case VK_UP:     iMouseRow-- ;  break ;
                    case VK_DOWN:   iMouseRow++ ;  break ;
                    default:        return 0 ;
                    }
               WinSendMsg (hwnd, WM_BUTTON1DOWN,
                           MPFROM2SHORT (iMouseCol * cxSquare,
                                         iMouseRow * cySquare), NULL) ;
               return 0 ;

          case WM_COMMAND:
               switch (COMMANDMSG(&msg)->cmd)
                    {
                              // Initialize aiPuzzle array

                    case IDM_NORMAL:
                    case IDM_INVERT:
                         for (iRow = 0 ; iRow < NUMROWS ; iRow++)
                              for (iCol = 0 ; iCol < NUMCOLS ; iCol++)
                                   aiPuzzle[iRow][iCol] = iCol + 1 +
                                        NUMCOLS * (NUMROWS - iRow - 1) ;

                         if (COMMANDMSG(&msg)->cmd == IDM_INVERT)
                              {
                              aiPuzzle[0][NUMCOLS-2] = NUMCOLS * NUMROWS - 2 ;
                              aiPuzzle[0][NUMCOLS-3] = NUMCOLS * NUMROWS - 1 ;
                              }
                         aiPuzzle[iBlankRow = 0][iBlankCol = NUMCOLS - 1] = 0 ;
                         WinInvalidateRect (hwnd, NULL, FALSE) ;
                         return 0 ;

                              // Randomly scramble the squares

                    case IDM_SCRAMBLE:
                         WinSetPointer (HWND_DESKTOP, WinQuerySysPointer (
                                        HWND_DESKTOP, SPTR_WAIT, FALSE)) ;

                         srand ((int) WinGetCurrentTime (0)) ;

                         for (i = 0 ; i < SCRAMBLEREP ; i++)
                              {
                              WinSendMsg (hwnd, WM_BUTTON1DOWN,
                                   MPFROM2SHORT (rand() % NUMCOLS * cxSquare,
                                        iBlankRow * cySquare), NULL) ;
                              WinUpdateWindow (hwnd) ;

                              WinSendMsg (hwnd, WM_BUTTON1DOWN,
                                   MPFROM2SHORT (iBlankCol * cxSquare,
                                        rand() % NUMROWS * cySquare), NULL) ;
                              WinUpdateWindow (hwnd) ;
                              }
                         WinSetPointer (HWND_DESKTOP, WinQuerySysPointer (
                                        HWND_DESKTOP, SPTR_ARROW, FALSE));
                         return 0 ;
                    }
               break ;
          }
     return WinDefWindowProc (hwnd, msg, mp1, mp2) ;
     }
MRESULT EXPENTRY miscMainWinProc( HWND hwnd, ULONG msg, MPARAM mp1, MPARAM mp2)
{
static HPS hpsMain;
static ULONG lCodePage;
static LONG lFontHeight, lAveWidth;
static LONG desk_cx, desk_cy;
    RECTL rectl;
    HWND hwndEditorWin, hwndEditorClient;
    ULONG flCreate;
    FONTDLG fontDlg;
    char szFamilyname[FACESIZE];
    char szExmpl[128];
    ULONG stringID[NUM_MAINTEXT] = {IDS_MAINTEXT1, IDS_MAINTEXT2,
                                    IDS_MAINTEXT3 };
    static char* sText=NULL;
    static char* sTextEnjoy;
    void setFont( HWND hwnd, HPS hps, PFATTRS pAttrs );

    switch(msg)
    {
        case WM_CREATE:
        {
        int i;
        SIZEL sizl;
        HDC hdc;
        HWND hwndFrame;
        ULONG dataLength;
        char buf[BUFSIZ];
        LONG x,y,cx,cy;

            /* Read message text */
            for (i = 0; i < NUM_MAINTEXT; i++)
            {
              WinLoadString( hab, NULLHANDLE,
                             stringID[i], sizeof(buf), buf );
              if( sText == NULL )
              {
                 sText = malloc(strlen(buf)+1);
                 *sText = '\0';
              }
              else
                 sText = realloc( sText, strlen(sText)+strlen(buf)+1 );

              strcat( sText, buf );
            }

            WinLoadString( hab, NULLHANDLE,
                           IDS_TEXTENJOY, sizeof(buf), buf );

            sTextEnjoy = malloc( strlen(buf)+1 );
            strcpy( sTextEnjoy, buf );

            sizl.cx = 0L;
            sizl.cy = 0L;

            hdc = WinOpenWindowDC( hwnd );
            hpsMain = GpiCreatePS( hab,
                                   hdc,
                                   (PSIZEL)&sizl,
                                   (ULONG)PU_PELS | GPIT_MICRO | GPIA_ASSOC
                                  );
            /* Query the environment */
            DosQueryCp( sizeof(lCodePage), &lCodePage, &dataLength );

            GetFontSize( hpsMain, &lAveWidth, &lFontHeight );

            hwndFrame = WinQueryWindow(hwnd, QW_PARENT);

            desk_cx = WinQuerySysValue( HWND_DESKTOP, SV_CXSCREEN );
            desk_cy = WinQuerySysValue( HWND_DESKTOP, SV_CYSCREEN );

            /* set window width to show maximum 40 SBCS characters */
            cx = (lAveWidth*MAIN_WIN_WIDTH>desk_cx) ? desk_cx : lAveWidth*MAIN_WIN_WIDTH;
            /* set window height large enough to show a string pointed to by sText.*/
            cy = (((strlen(sText)/MAIN_WIN_WIDTH)+10)*lFontHeight>desk_cy) ?
                  desk_cy : ((strlen(sText)/40) + 10)*lFontHeight;

            x = (cx<desk_cx) ? (desk_cx-cx)/2 : 0;
            y = (cy<desk_cy) ? (desk_cy-cy)/2 : 0;
            WinSetWindowPos(hwndFrame,
                            HWND_BOTTOM,
                            x, y, cx, cy,
                            SWP_MOVE | SWP_SIZE | SWP_ACTIVATE);

            return(MRESULT)(FALSE);
        }

        case WM_COMMAND:
            switch (SHORT1FROMMP(mp1))
            {
                case MID_CONV:    /* CPCONV */
                {
                  WinDlgBox(HWND_DESKTOP, hwnd, (PFNWP) cpConvDlgProc,
                            NULLHANDLE, DID_CONV, &lCodePage);
                  break;
                }

                case MID_EDITOR:  /* Simple Editor */
                  flCreate= FCF_SIZEBORDER | FCF_MENU | FCF_MAXBUTTON | FCF_MINBUTTON
                          | FCF_SYSMENU | FCF_TITLEBAR | FCF_DBE_APPSTAT;
                  hwndEditorWin = WinCreateStdWindow(HWND_DESKTOP,
                                                    WS_VISIBLE,
                                                    &flCreate,
                                                    "editorWindow",
                                                    "Simple Editor",
                                                    0L,
                                                    NULLHANDLE,
                                                    WID_EDITOR,
                                                    (PHWND) & hwndEditorClient);

                  WinSetWindowPos(hwndEditorWin,
                                  HWND_BOTTOM,
                                  190, 130, 500, 300,
                                  SWP_MOVE | SWP_SIZE | SWP_ACTIVATE);
                  break;

                case MID_WORD:    /* Word Break */
                {
                  WinDlgBox(HWND_DESKTOP, hwnd, (PFNWP) wordDlgProc,
                            NULLHANDLE, DID_WORD, &lCodePage);
                  break;
                }

                case MID_EXIT:    /* Exit */
                  WinSendMsg (hwnd, WM_CLOSE,mp1,mp2);
                  break;
            }
            break;

        case WM_PAINT:
        {
         int i;
         LONG lTotLen, lWrittenLen, lDrawn;
         SWP swp;

            WinBeginPaint( hwnd, hpsMain, (PRECTL)&rectl );
            /* Always update whole window - CS_SIZEREDRAW? */
            WinQueryWindowPos( hwnd, &swp );
            rectl.xLeft = rectl.yBottom = 0;
            rectl.xRight = swp.cx;
            rectl.yTop = swp.cy;

            WinFillRect( hpsMain, (PRECTL) &rectl, CLR_BACKGROUND );

            lTotLen = (LONG)strlen(sText);

            /* make some space between the text and the frame window */
            rectl.xLeft+=lAveWidth;
            rectl.xRight-=lAveWidth;
            rectl.yTop-=lFontHeight;

            for (lWrittenLen = 0; lWrittenLen != lTotLen; rectl.yTop -= lFontHeight)
            {
              lDrawn = WinDrawText( hpsMain, lTotLen - lWrittenLen,
                                    sText+lWrittenLen, &rectl, 0L, 0L,
                                    DT_WORDBREAK | DT_TOP | DT_LEFT | DT_TEXTATTRS);

              if( lDrawn != 0 )
                lWrittenLen  += lDrawn;
              else
                break;
            }

            rectl.yTop -= lFontHeight;
            WinDrawText( hpsMain, strlen(sTextEnjoy), sTextEnjoy, &rectl,
                         CLR_RED, CLR_BACKGROUND,
                         DT_TOP | DT_CENTER );
            WinEndPaint( hpsMain );
            break;
        }

        case WM_DESTROY:
            GpiDestroyPS( hpsMain );
            break;

        default:
            return(WinDefWindowProc(hwnd,msg,mp1,mp2));
    }
  return(MRFROMLONG(NULL));
}
Exemple #21
0
static
MRESULT EXPENTRY helpWndProc( HWND hwnd, ULONG msg, MPARAM mp1, MPARAM mp2 )
{
    static CHAR szText[ 256 ] = "";
    static HPS hps = NULLHANDLE;
    static USHORT width = 0, height = 0;

    switch( msg )
    {
        case WM_CREATE :
        {
            FONTMETRICS fm;

            strcpy( szText, (( PCREATESTRUCT )mp2 )->pszText );

            hps = WinGetPS( hwnd );
            GpiQueryFontMetrics( hps, sizeof( fm ), &fm );
            width = fm.lAveCharWidth;
            height = fm.lMaxAscender + fm.lMaxDescender;

            return MRFROMSHORT( FALSE );
        }

        case WM_DESTROY :
            WinReleasePS( hps );

            return MRFROMSHORT( FALSE );

        case WM_SETWINDOWPARAMS :
        {
            PWNDPARAMS  pwp;

            pwp = ( PWNDPARAMS )mp1;
            if( pwp->fsStatus & WPM_TEXT )
                strcpy( szText, pwp->pszText );

            return MRFROMSHORT( TRUE );
        }

        case WM_PAINT :
        {
            RECTL   rcl;

            WinBeginPaint( hwnd, hps, NULL );

            WinQueryWindowRect( hwnd, &rcl );

            WinDrawBorder( hps, &rcl, 1, 1, CLR_BLACK, CLR_YELLOW, DB_INTERIOR );
            WinDrawText( hps, -1, szText, &rcl, CLR_BLACK, CLR_YELLOW,
                         DT_CENTER | DT_VCENTER );

            WinEndPaint( hps );

            return MRFROMSHORT( 0 );
        }

        case WM_QUERY_CHAR_WIDTH :
            return MRFROMSHORT( width );

        case WM_QUERY_CHAR_HEIGHT :
            return MRFROMSHORT( height );
    }

    return WinDefWindowProc( hwnd, msg, mp1, mp2 );
}
// Handle the drawing of the list box items.
Boolean DrawHandler::drawItem( IListBoxDrawItemEvent& event,
                               Boolean selected)
{
  IListBox* list = (IListBox*)event.controlWindow();
  IRectangle rect = event.itemRect();
  RECTL rectl = rect.asRECTL();

  // Fill the background. 
  WinFillRect(event.itemPresSpaceHandle(), &rectl,
              selected?CLR_BLACK:SYSCLR_ENTRYFIELD);

  // Convert the item data from the list box item text
  ListItem* data = 
     (ListItem*)(list->itemText(event.itemId()).asUnsigned());

  // Determine the indent for the class based on the
  // number of inherited classes.
  if (data->inheritedClasses() != 0)
  {
     ISize indentSize = ISize(
                data->inheritedClasses() * (_indent+1), 0);
     rect.moveBy(indentSize);
  }

  // Draw a bitmap based on the collapsed flag
  // if the class is not a leaf.
  if(data->children())
  {
    // Make the bitmap a square the size of an item
    IRectangle rectBitmap(rect.bottomLeft(),
                        ISize(rect.height(),
                              rect.height()));
    rectl = rectBitmap.asRECTL();
    WinDrawBitmap(event.itemPresSpaceHandle(),
                data->collapsed()? _collapseIcon:_expandIcon,
                0, 
                (PPOINTL)&rectl,
                selected?CLR_WHITE:CLR_BLACK,
                selected?CLR_BLACK:SYSCLR_ENTRYFIELD,
                DBM_STRETCH );
  }

  // Calculate the rectangle for the text based
  // on the current font of the listbox.
  IFont font(list);
  rect
    .moveBy(ISize(rect.height(),0))
    .sizeTo(ISize(font.textWidth(data->text())+3,
            rect.size().height()));
  rectl = rect.asRECTL();
                          
  // Draw the text.
  unsigned long style =  DT_VCENTER | DT_LEFT;
  WinDrawText(event.itemPresSpaceHandle(), 
              -1,
              data->text(),
              &rectl, 
              selected?CLR_WHITE:CLR_BLACK,
              selected?CLR_BLACK:SYSCLR_ENTRYFIELD,
              style);
  return true;
}