MRESULT InitMainWindow(HWND hwnd, /* handle to the main client window */ MPARAM mp1, /* first parameter of WM_CREATE message */ MPARAM mp2) /* second parameter of WM_CREATE message */ { FONTMETRICS fm; HPS hps; hps = WinGetPS (hwnd) ; GpiQueryFontMetrics (hps, (LONG) sizeof fm, &fm) ; cxChar = fm.lAveCharWidth ; cxCaps = fm.lEmInc ; cyChar = fm.lMaxBaselineExt ; cyDesc = fm.lMaxDescender ; WinReleasePS (hps) ; cxTextTotal = MESSAGE_LEN * cxChar ; hwndHscroll = WinWindowFromID ( WinQueryWindow (hwnd, QW_PARENT), FID_HORZSCROLL) ; hwndVscroll = WinWindowFromID ( WinQueryWindow (hwnd, QW_PARENT), FID_VERTSCROLL) ; return (MRFROMLONG(0)); }
/****************************************************************\ * Routine to start semaphore example * *--------------------------------------------------------------* * * * Name: StartSemExample(VOID) * * * * Purpose: Calls routines to create semaphores and draw * * resources. Creates consumer threads. * * * * Usage: Called in file usercmd.c when the user selects * * start from the semaphore menu. * * * * Method: Uses routines in paint.c to draw consumers and * * resources. This is done by creating a paint * * message, not calling the draw routines directly. * * * * Returns: TRUE if start succeeds, FALSE if start fails * * * \****************************************************************/ INT StartSemExample(VOID) { TID tid=0; ULONG rc; INT i; FONTMETRICS fntmet; HPS hps; SWP swp; InitSemaphExample(); rc = CreateAllSems(); if (rc) return FALSE; /****************************************************************\ * Create consumer threads. Note that values can be passed to * * threads in OS/2 2.0. We pass the ordinal number of the child * * to each child. * \****************************************************************/ for (usConsumerThreadsCreated = 0; usConsumerThreadsCreated < cNumUsers; usConsumerThreadsCreated++) { rc = DosCreateThread((PTID) &tid, (PFNTHREAD)ThreadConsumer, (ULONG) usConsumerThreadsCreated, (ULONG)1,(ULONG) STACKSIZE); if (rc) { SemError("DosCreateThread",rc); return FALSE; } else { thrConsumers[usConsumerThreadsCreated].tid = tid; thrConsumers[usConsumerThreadsCreated].lHits = 0L; } } for (i = 0; i < (INT) cNumUsers; i++) { DosResumeThread (thrConsumers[i].tid); } hps = WinGetPS (hwndMain); if (hps) { GpiQueryFontMetrics (hps, (LONG) sizeof fntmet, &fntmet); WinQueryWindowPos (hwndMain, &swp); SetRectPositions((SHORT)swp.cx, (SHORT)swp.cy, (SHORT) fntmet.lMaxBaselineExt, (SHORT) fntmet.lMaxDescender); DrawRects (hps); WinReleasePS (hps); } return TRUE; }
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); }
static VOID CalcLineHeight(HPS hps, PLONG plLineHeight, PLONG plDescender ) { FONTMETRICS FontMetrics; GpiQueryFontMetrics(hps, sizeof(FontMetrics), &FontMetrics ); *plLineHeight = FontMetrics.lMaxBaselineExt + FontMetrics.lExternalLeading + FontMetrics.lInternalLeading ; *plDescender = FontMetrics.lMaxDescender + FontMetrics.lExternalLeading + FontMetrics.lInternalLeading ; return; } /*CalcLineHeight() */
void OListBox::auto_scroll() { FONTMETRICS FontMetrics; WinQueryWindowRect(hwnd, &rcl); hps = WinGetPS(hwnd); GpiQueryFontMetrics(hps, sizeof(FONTMETRICS), &FontMetrics); WinReleasePS(hps); if (queryItemCount() > ((rcl.yTop - rcl.yBottom) / FontMetrics.lMaxBaselineExt)) { if ((rcl.yTop - rcl.yBottom) % FontMetrics.lMaxBaselineExt) setToTop(queryTopItem()+2); else setToTop(queryTopItem()+1); } }
static LONG GetFontByDlg(HWND hwndOwner, PPRINTSETUP pPrintSetup, char *pchFont, ULONG idFontDisp) { FONTDLG FontDlg; char pchFamily[FACESIZE+5]=""; long lTemp; FONTMETRICS FontMetrics; HPS hps; hps = WinGetPS(WinWindowFromID(hwndOwner, idFontDisp)); GpiQueryFontMetrics(hps, sizeof(FontMetrics), &FontMetrics); strcpy(pchFamily, FontMetrics.szFamilyname); WinReleasePS(hps); lTemp = strtol(pchFont, NULL, 10); memset(&FontDlg, 0, sizeof(FontDlg)); FontDlg.cbSize = sizeof(FontDlg); FontDlg.hpsPrinter = pPrintSetup->hpsPrinterInfo; FontDlg.pszFamilyname = pchFamily; FontDlg.usFamilyBufLen = sizeof(pchFamily); FontDlg.fxPointSize = MAKEFIXED(lTemp, 0); FontDlg.fl = FNTS_CENTER | FNTS_VECTORONLY; FontDlg.flFlags = FNTF_NOVIEWSCREENFONTS; FontDlg.clrFore = CLR_BLACK; FontDlg.clrBack = CLR_WHITE; WinFontDlg(HWND_DESKTOP, hwndOwner, &FontDlg); if (FontDlg.lReturn == DID_OK) { sprintf(pchFont, "%d.%s", (int) FIXEDINT(FontDlg.fxPointSize), FontDlg.fAttrs.szFacename); } return FontDlg.lReturn; }
void GetFontMetrics( HWND hwndWnd, BOOL fCopy ) { HPS hpsClient; FONTMETRICS fmFontMetrics; hpsClient = WinGetPS( hwndWnd ); GpiQueryFontMetrics( hpsClient, sizeof( fmFontMetrics ), &fmFontMetrics ); cxChar = fmFontMetrics.lAveCharWidth; cxCaps = fmFontMetrics.lEmInc; cyChar = fmFontMetrics.lMaxBaselineExt; cyDesc = fmFontMetrics.lMaxDescender; WinReleasePS( hpsClient ); if ( fCopy ) { // Transfer the default font attributes into the FATTRS block of the FontDlg fdFontDlg.fAttrs.fsSelection = 0; fdFontDlg.fAttrs.lMatch = fmFontMetrics.lMatch; strcpy( fdFontDlg.fAttrs.szFacename, fmFontMetrics.szFacename ); } }
static void AddNotebookTab( HWND hwndNotebook, HWND hwndNotebookPage, USHORT usType, char *szTabText, char *szStatusText, ULONG *pulPageID, unsigned short *pusTabTextLength, unsigned short *pusTabTextHeight ) { HPS hps; FONTMETRICS fmFontMetrics; POINTL aptlTabText[TXTBOX_COUNT]; // Query dimensions of this tab text: hps = WinGetPS(hwndNotebook); memset(&fmFontMetrics, 0, sizeof(FONTMETRICS)); if ((GpiQueryFontMetrics(hps, sizeof(FONTMETRICS), &fmFontMetrics)) && (*pusTabTextHeight < fmFontMetrics.lMaxBaselineExt*2)) *pusTabTextHeight = fmFontMetrics.lMaxBaselineExt*2; if ((GpiQueryTextBox(hps, strlen(szTabText), szTabText, TXTBOX_COUNT, aptlTabText)) && (*pusTabTextLength < aptlTabText[TXTBOX_CONCAT].x)) *pusTabTextLength = aptlTabText[TXTBOX_CONCAT].x; // Now add page *pulPageID = (ULONG) WinSendMsg( hwndNotebook, BKM_INSERTPAGE, 0L, MPFROM2SHORT( (BKA_STATUSTEXTON | BKA_AUTOPAGESIZE | usType ), BKA_LAST ) ); // And set text for it WinSendMsg( hwndNotebook, BKM_SETTABTEXT, MPFROMLONG( *pulPageID ), MPFROMP( szTabText ) ); WinSendMsg( hwndNotebook, BKM_SETSTATUSLINETEXT, MPFROMLONG( *pulPageID ), MPFROMP( szStatusText ) ); WinSendMsg(hwndNotebook, BKM_SETPAGEWINDOWHWND, MPFROMP(*pulPageID), MPFROMP(hwndNotebookPage)); }
void PaintClient (HPS hps, SHORT cxClient, SHORT cyClient) { static CHAR szText [] = "Hello!" ; FONTMETRICS fm ; int iPtHt, iPtWd ; POINTL ptl, aptl[TXTBOX_COUNT] ; // Create the logical font, select it, and scale it CreateOutlineFont (hps, LCID_FONT, "Helvetica", 0, 0) ; GpiSetCharSet (hps, LCID_FONT) ; ScaleOutlineFont (hps, 120, 120) ; // Scale font to client window size GpiQueryTextBox (hps, strlen (szText), szText, TXTBOX_COUNT, aptl) ; iPtHt = (int) (120 * cyClient / (aptl[TXTBOX_TOPLEFT].y - aptl[TXTBOX_BOTTOMLEFT].y)) ; iPtWd = (int) (120 * cxClient / aptl[TXTBOX_CONCAT].x) ; ScaleOutlineFont (hps, iPtHt, iPtWd) ; // Display the text string GpiQueryFontMetrics (hps, sizeof (FONTMETRICS), &fm) ; ptl.x = 0 ; ptl.y = cyClient - fm.lMaxAscender ; GpiCharStringAt (hps, &ptl, strlen (szText), szText) ; // Select the default font; delete the logical font GpiSetCharSet (hps, LCID_DEFAULT) ; GpiDeleteSetId (hps, LCID_FONT) ; }
VOID InitApp(HWND hwndFrame, HWND hwndClient, PSZ pszWindowListTitle) { HPS hPS; /* Presentation Space Handle */ SWCNTRL swCtl; /* Task Switch Control Structure */ /* Get a temporary presentation space so that */ /* the system's font metrics can be found and */ /* the proper sizing of owner draw list boxes */ /* can be performed properly */ if ( (hPS = WinGetPS(hwndClient)) != (HPS)NULL ) { GpiQueryFontMetrics(hPS, sizeof(FONTMETRICS), &fm); /* Release the temporary presentation space */ WinReleasePS(hPS); } if ( pszWindowListTitle ) { /* Fill Switch Entry structure with required */ /* values before adding program name to Task */ /* Manager switch list */ swCtl.hwnd = hwndFrame; swCtl.hwndIcon = (HWND)NULL; swCtl.hprog = (HPROGRAM)NULL; swCtl.idProcess = swCtl.idSession = 0; swCtl.uchVisibility = SWL_VISIBLE; swCtl.fbJump = SWL_JUMPABLE; strcpy(swCtl.szSwtitle, pszWindowListTitle); hSwitch = WinAddSwitchEntry(&swCtl); } }
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 ); }
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 ); }
/**************************************************************************** Titlebar Dialog Procedure *****************************************************************************/ MRESULT EXPENTRY TitleBarProc (HWND hWnd, ULONG msg, MPARAM mp1, MPARAM mp2) { BOOL Handled = TRUE; MRESULT mReturn = 0; RECTL Rectl; POINTL Pointl; CHARBUNDLE cb; FONTMETRICS Fontsz; PSZ TitleText = szTitle; ULONG temp; HPS hps; switch (msg) { case WM_SETWINDOWPARAMS: if( ((WNDPARAMS*)mp1)->fsStatus & WPM_TEXT ) { TitleText = ((WNDPARAMS*)mp1)->pszText; } Handled = FALSE; break; case TBM_SETHILITE: mReturn = (MRESULT)TRUE; hps = WinGetPS(hWnd); WinQueryWindowRect(hWnd,&Rectl); WinFillRect(hps, &Rectl, CLR_BLACK); GpiQueryFontMetrics(hps,sizeof(FONTMETRICS),(PFONTMETRICS)&Fontsz); Pointl.x = 10; Pointl.y = (Rectl.yTop - Fontsz.lMaxAscender) / 2; cb.lColor = CLR_GREEN; cb.lBackColor = CLR_BLACK; cb.usMixMode = BM_OVERPAINT; cb.usBackMixMode = BM_OVERPAINT; GpiSetAttrs(hps,PRIM_CHAR, CBB_COLOR | CBB_BACK_COLOR | CBB_MIX_MODE | CBB_BACK_MIX_MODE, 0,(PBUNDLE)&cb); GpiCharStringAt(hps, &Pointl, strlen(TitleText), TitleText); WinEndPaint(hps); WinReleasePS(hps); break; case WM_PAINT: hps = WinBeginPaint(hWnd, 0, 0); WinQueryWindowRect(hWnd,&Rectl); WinFillRect(hps, &Rectl, CLR_BLACK); GpiQueryFontMetrics(hps,sizeof(FONTMETRICS),(PFONTMETRICS)&Fontsz); Pointl.x = 10; Pointl.y = (Rectl.yTop - Fontsz.lMaxAscender) / 2; cb.lColor = CLR_GREEN; cb.lBackColor = CLR_BLACK; cb.usMixMode = BM_OVERPAINT; cb.usBackMixMode = BM_OVERPAINT; GpiSetAttrs(hps,PRIM_CHAR, CBB_COLOR | CBB_BACK_COLOR | CBB_MIX_MODE | CBB_BACK_MIX_MODE, 0,(PBUNDLE)&cb); GpiCharStringAt(hps, &Pointl, strlen(TitleText), TitleText); WinEndPaint(hps); break; default: Handled = FALSE; break; } if (!Handled) mReturn = (*TitleDefProc)(hWnd, msg, mp1, mp2); return (mReturn); }
//Draw the Plugin effect into the given presentation space BOOL CBZPluginRender(PSPAINT * pPaint, PVOID pData, short sActive) { POINTL point; //should allocate all this data dynamically, to keep it off int i, y; // the stack!!! FONTMETRICS font; PLUGINSHARE *pPluginData; pPluginData = (PLUGINSHARE *) pData; if (pPluginData == NULL) return (FALSE); if (((sActive == TRUE) && !(pPluginData->bActiveEnabled)) || ((sActive == FALSE) && !(pPluginData->bInactiveEnabled))) return (TRUE); GpiQueryFontMetrics(pPaint->hpsWin, sizeof(font), &(font)); GpiSetLineType(pPaint->hps, pPluginData->lLineStyle); // if no text if (pPaint->rectlText.xLeft == pPaint->rectlText.xRight) { for (y = 4; y < pPaint->rectlWindow.yTop - 4; y += 3) { if (sActive == TRUE) GpiSetColor(pPaint->hps, pPluginData->lActiveShadowColor); else GpiSetColor(pPaint->hps, pPluginData->lInactiveShadowColor); point.x = pPaint->rectlWindow.xLeft + 6; point.y = y; GpiMove(pPaint->hps, &point); point.x = pPaint->rectlWindow.xRight - 5; GpiLine(pPaint->hps, &point); if (sActive == TRUE) GpiSetColor(pPaint->hps, pPluginData->lActiveLineColor); else GpiSetColor(pPaint->hps, pPluginData->lInactiveLineColor); point.x = pPaint->rectlWindow.xLeft + 5; point.y++; GpiMove(pPaint->hps, &point); point.x = pPaint->rectlWindow.xRight - 6; GpiLine(pPaint->hps, &point); } } else //text exists... draw around it. { if (pPaint->rectlWindow.xRight > (pPaint->rectlText.xRight + font.lAveCharWidth)) { for (y = 4; y < pPaint->rectlWindow.yTop - 4; y += 3) { if (sActive == TRUE) GpiSetColor(pPaint->hps, pPluginData->lActiveShadowColor); else GpiSetColor(pPaint->hps, pPluginData->lInactiveShadowColor); point.x = pPaint->rectlText.xRight + 6; point.y = y; GpiMove(pPaint->hps, &point); point.x = pPaint->rectlWindow.xRight - 5; GpiLine(pPaint->hps, &point); if (sActive == TRUE) GpiSetColor(pPaint->hps, pPluginData->lActiveLineColor); else GpiSetColor(pPaint->hps, pPluginData->lInactiveLineColor); point.x = pPaint->rectlText.xRight + 5; point.y++; GpiMove(pPaint->hps, &point); point.x = pPaint->rectlWindow.xRight - 6; GpiLine(pPaint->hps, &point); } } if ((pPaint->rectlWindow.xLeft + font.lAveCharWidth) < (pPaint->rectlText.xLeft)) { for (y = 4; y < pPaint->rectlWindow.yTop - 4; y += 3) { if (sActive == TRUE) GpiSetColor(pPaint->hps, pPluginData->lActiveShadowColor); else GpiSetColor(pPaint->hps, pPluginData->lInactiveShadowColor); point.x = pPaint->rectlWindow.xLeft + 6; point.y = y; GpiMove(pPaint->hps, &point); point.x = pPaint->rectlText.xLeft - 5; GpiLine(pPaint->hps, &point); if (sActive == TRUE) GpiSetColor(pPaint->hps, pPluginData->lActiveLineColor); else GpiSetColor(pPaint->hps, pPluginData->lInactiveLineColor); point.x = pPaint->rectlWindow.xLeft + 5; point.y++; GpiMove(pPaint->hps, &point); point.x = pPaint->rectlText.xLeft - 6; GpiLine(pPaint->hps, &point); } } } return (TRUE); }
BOOL APIENTRY WfontDlg(HWND hwnd, PSZ pszTitle, PSZ pszSample, PSZ pszFont, ULONG cbFont, PULONG pfl) { PFONTDLG pfd = NULL; PFONTMETRICS pfm = NULL; PSZ psz; BOOL rc = FALSE; if (!(pfd = (PFONTDLG)malloc(sizeof(FONTDLG)))) goto end; memset((PVOID)pfd, 0, sizeof(FONTDLG)); if (!(pfm = (PFONTMETRICS)malloc(sizeof (FONTMETRICS)))) goto end; memset((PVOID)pfm, 0, sizeof(FONTMETRICS)); pfd->cbSize = sizeof(FONTDLG); pfd->pszFamilyname = psz = pszFont; pfd->usFamilyBufLen = cbFont; pfd->pszTitle = pszTitle; pfd->pszPreview = pszSample; pfd->clrFore = CLR_NEUTRAL; pfd->clrBack = SYSCLR_WINDOW; pfd->hpsScreen = WinGetPS(hwnd); // subclassa la procedura del dialogo solo se *pfl = TRUE pfd->pfnDlgProc = *pfl? NewFontDlgProc: NULL; if (!GpiQueryFontMetrics(pfd->hpsScreen, sizeof(FONTMETRICS), pfm)) goto end; // inizializza la struttura FATTRS di FONTDLG pfd->fAttrs.usRecordLength = sizeof(FATTRS); // inizializza gli attributi del font while (*psz != '.') pfd->ulUser = pfd->ulUser * 10 + *psz++ - '0'; pfd->fxPointSize = pfd->ulUser << 16; while (*psz) { if (!strncmp(psz, ".Italic", 7)) { pfd->fAttrs.fsSelection |= FATTR_SEL_ITALIC; psz += 7; } else if (!strncmp(psz, ".Bold", 5)) { pfd->fAttrs.fsSelection |= FATTR_SEL_BOLD; psz += 5; } else if (!strncmp(psz, ".Underscore", 11)) { pfd->fAttrs.fsSelection |= FATTR_SEL_UNDERSCORE; psz += 11; } else if (!strncmp(psz, ".Outline", 8)) { pfd->fAttrs.fsSelection |= FATTR_SEL_OUTLINE; psz += 8; } else if (!strncmp(psz, ".Strikeout", 10)) { pfd->fAttrs.fsSelection |= FATTR_SEL_STRIKEOUT; psz += 10; } else { psz++; } /* endif */ } /* endwhile */ pfd->fAttrs.lMatch = pfm->lMatch; pfd->fAttrs.idRegistry = pfm->idRegistry; pfd->fAttrs.usCodePage = pfm->usCodePage; if (!(pfm->fsDefn & FM_DEFN_OUTLINE)) { pfd->fAttrs.lMaxBaselineExt = pfm->lMaxBaselineExt; pfd->fAttrs.lAveCharWidth = pfm->lAveCharWidth; } // end if // tipo font pfd->fAttrs.fsType |= pfm->fsType & FM_TYPE_KERNING? FATTR_TYPE_KERNING: 0; pfd->fAttrs.fsType |= pfm->fsType & FM_TYPE_DBCS? FATTR_TYPE_DBCS: 0; pfd->fAttrs.fsType |= pfm->fsType & FM_TYPE_MBCS? FATTR_TYPE_MBCS: 0; strcpy(pfd->fAttrs.szFacename, pfm->szFacename); // the fontdlg style flags pfd->fl = FNTS_CENTER | FNTS_INITFROMFATTRS | FNTS_RESETBUTTON; pfd->usWeight = pfm->usWeightClass; pfd->usWidth = pfm->usWidthClass; if (!WinFontDlg(HWND_DESKTOP, hwnd, pfd)) goto end; if (pfd->lReturn == DID_OK) { *pfl = TRUE; sprintf(pszFont, "%d.%s", FIXEDINT(pfd->fxPointSize), pfd->fAttrs.szFacename); if (pfd->fAttrs.fsSelection & FATTR_SEL_ITALIC) strcat(pszFont, ".Italic"); if (pfd->fAttrs.fsSelection & FATTR_SEL_UNDERSCORE) strcat(pszFont, ".Underscore"); if (pfd->fAttrs.fsSelection & FATTR_SEL_STRIKEOUT) strcat(pszFont, ".Strikeout"); if (pfd->fAttrs.fsSelection&FATTR_SEL_BOLD) strcat(pszFont, ".Bold"); if (pfd->fAttrs.fsSelection&FATTR_SEL_OUTLINE) strcat(pszFont, ".Outline"); } else { *pfl = FALSE; } // end if rc = TRUE; end: if (pfd) { if (pfd->hpsScreen) WinReleasePS(pfd->hpsScreen); free(pfd); free(pfm); } // end if return rc; }
MRESULT EXPENTRY ClientWndProc (HWND hwnd, ULONG msg, MPARAM mp1, MPARAM mp2) { static CHAR szErrorMsg [] = "File not found or could not be opened" ; static INT cxClient, cyClient, cxChar, cyChar, cyDesc ; CHAR *pcReadBuffer ; FILE *fileInput ; FONTMETRICS fm ; HPS hps ; INT iLength ; POINTL ptl ; switch (msg) { case WM_CREATE: hps = WinGetPS (hwnd) ; EzfQueryFonts (hps) ; if (!EzfCreateLogFont (hps, LCID_FIXEDFONT, FONTFACE_MONO, FONTSIZE_10, 0)) { WinReleasePS (hps) ; WinMessageBox (HWND_DESKTOP, HWND_DESKTOP, "Cannot find a fixed-pitch font. Load the Courier " "fonts from the Control Panel and try again.", szClientClass, 0, MB_OK | MB_WARNING) ; return MRFROMSHORT (1) ; } GpiQueryFontMetrics (hps, (LONG) sizeof fm, &fm) ; cxChar = fm.lAveCharWidth ; cyChar = fm.lMaxBaselineExt ; cyDesc = fm.lMaxDescender ; GpiSetCharSet (hps, LCID_DEFAULT) ; GpiDeleteSetId (hps, LCID_FIXEDFONT) ; WinReleasePS (hps) ; return 0 ; case WM_SIZE: cxClient = SHORT1FROMMP (mp2) ; cyClient = SHORT2FROMMP (mp2) ; return 0 ; case WM_COMMAND: switch (COMMANDMSG(&msg)->cmd) { case IDM_OPEN: if (WinDlgBox (HWND_DESKTOP, hwnd, OpenDlgProc, NULLHANDLE, IDD_OPEN, NULL)) WinInvalidateRect (hwnd, NULL, FALSE) ; return 0 ; case IDM_ABOUT: WinDlgBox (HWND_DESKTOP, hwnd, AboutDlgProc, NULLHANDLE, IDD_ABOUT, NULL) ; return 0 ; } break ; case WM_PAINT: hps = WinBeginPaint (hwnd, NULLHANDLE, NULL) ; GpiErase (hps) ; if (szFileName [0] != '\0') { EzfCreateLogFont (hps, LCID_FIXEDFONT, FONTFACE_MONO, FONTSIZE_10, 0) ; EzfCreateLogFont (hps, LCID_BOLDFONT, FONTFACE_MONO, FONTSIZE_10, FATTR_SEL_BOLD) ; GpiSetCharSet (hps, LCID_BOLDFONT) ; ptl.x = cxChar ; ptl.y = cyClient - cyChar + cyDesc ; GpiCharStringAt (hps, &ptl, strlen (szFileName), szFileName) ; ptl.y -= cyChar ; if ((fileInput = fopen (szFileName, "r")) != NULL) { GpiSetCharSet (hps, LCID_FIXEDFONT) ; pcReadBuffer = (PCHAR) malloc (cxClient / cxChar) ; while ((ptl.y -= cyChar) > 0 && fgets (pcReadBuffer, cxClient / cxChar - 2, fileInput) != NULL) { iLength = strlen (pcReadBuffer) ; if (pcReadBuffer [iLength - 1] == '\n') iLength-- ; if (iLength > 0) GpiCharStringAt (hps, &ptl, iLength, pcReadBuffer) ; } free (pcReadBuffer) ; fclose (fileInput) ; } else // file cannot be opened { ptl.y -= cyChar ; GpiCharStringAt (hps, &ptl, strlen (szErrorMsg), szErrorMsg) ; } GpiSetCharSet (hps, LCID_DEFAULT) ; GpiDeleteSetId (hps, LCID_FIXEDFONT) ; GpiDeleteSetId (hps, LCID_BOLDFONT) ; } WinEndPaint (hps) ; return 0 ; } return WinDefWindowProc (hwnd, msg, mp1, mp2) ; }
void SetAutoSize( VRIconButton *somSelf ) { FONTMETRICS fm; HWND hwnd; HPS hps; POINTL aptl[ TXTBOX_COUNT ]; LONG lMinW = 8, // We always require border+margin of at least 8 pixels lMinH = 8, lStrW = 0, lStrH = 0; VRIconButtonData *somThis = VRIconButtonGetData(somSelf); hwnd = _vrGetWindowHandle( somSelf ); if ( _pszText && *_pszText ) { // Get the required size for the text string hps = WinGetPS( hwnd ); GpiQueryFontMetrics( hps, sizeof( FONTMETRICS ), &fm ); GpiQueryTextBox( hps, strlen( _pszText ), _pszText, TXTBOX_COUNT, aptl ); WinReleasePS( hps ); lStrW = aptl[TXTBOX_TOPRIGHT].x - aptl[TXTBOX_TOPLEFT].x; lStrW += ( 2 * fm.lAveCharWidth ); lStrH = fm.lMaxBaselineExt + fm.lInternalLeading + fm.lMaxDescender; // We have an image as well as text if ( _pPic && ( !_fResize || ( _pPic->type & MEMP_ICON ))) { switch ( _bAlign ) { case ALIGN_LEFT: case ALIGN_RIGHT: lMinW += _pPic->width + lStrW + 7; lMinH += max( _pPic->height + 6, lStrH ); break; case ALIGN_TOP: case ALIGN_BOTTOM: lMinW += max( _pPic->width + 6, lStrW ); lMinH += _pPic->height + lStrH + 7; break; default: // ALIGN_CENTER lMinW += max( _pPic->width + 6, lStrW ); lMinH += max( _pPic->height + 6, lStrH ); break; } } // We have only text (or if there is an image, it's auto-scaled) else { lMinW += lStrW; lMinH += lStrH; } } else if ( _pPic ) { // Image (non-rescaled) only lMinW += _pPic->width + 6; lMinH += _pPic->height + 6; } WinSetWindowPos( hwnd, NULLHANDLE, 0, 0, lMinW, lMinH, SWP_SIZE ); }
BOOL CreateNotebookWindow( HWND hwndFrame ) { BOOL fSuccess = TRUE; // Make the notebook's id FID_CLIENT so we don't need a client window. This // will make the notebook automatically size with the frame window and // eliminate the need for a client window. hwndBook = WinCreateWindow( hwndFrame, WC_NOTEBOOK, NULL, BKS_BACKPAGESBR | BKS_MAJORTABRIGHT | BKS_ROUNDEDTABS | BKS_STATUSTEXTCENTER | BKS_SPIRALBIND | WS_VISIBLE, 0, 0, 0, 0, hwndFrame, HWND_TOP, FID_CLIENT, NULL, NULL ); if( hwndBook ) { int i, cxTab = 0, cyTab = 0, cxPage = 0, cyPage = 0; FONTMETRICS fm; HPS hps = WinGetPS( hwndBook ); if( GpiQueryFontMetrics( hps, sizeof fm, &fm ) ) { cyTab = fm.lMaxBaselineExt; // Set the page background color to grey so it is the same as // a dialog box. if( !WinSendMsg( hwndBook, BKM_SETNOTEBOOKCOLORS, MPFROMLONG( SYSCLR_FIELDBACKGROUND ), MPFROMSHORT( BKA_BACKGROUNDPAGECOLORINDEX ) ) ) Msg( "BKM_SETNOTEBOOKCOLRS (BACKPAGE) RC(%X)", HWNDERR( hwndBook ) ); // Set the tab background color to grey so it is the same as // the page background. Note that the page packground also // dictates the color of the foreground tab (the one attached // to the top page). We want to make the background of all the // tabs to be the same color. if( !WinSendMsg( hwndBook, BKM_SETNOTEBOOKCOLORS, MPFROMLONG( SYSCLR_FIELDBACKGROUND ), MPFROMSHORT( BKA_BACKGROUNDMAJORCOLORINDEX ) ) ) Msg( "BKM_SETNOTEBOOKCOLRS (BACKTAB) RC(%X)", HWNDERR( hwndBook ) ); // Insert all the pages into the notebook and configure them. // The dialog boxes will also be loaded now. Also, the width and // height of the biggest dialog will be passed back as well as the // width of the widest tab text. for( i = 0; i < PAGE_COUNT && fSuccess; i++ ) fSuccess = SetUpPage( hps, &PgConsts[ i ], &cxTab, &cxPage, &cyPage ); if( fSuccess ) { // Set the tab height and width based on the biggest bitmap. WinSendMsg( hwndBook, BKM_SETDIMENSIONS, MPFROM2SHORT( cxTab + TAB_CX_MARGIN, cyTab + TAB_CY_MARGIN ), MPFROMSHORT( BKA_MAJORTAB ) ); // Set the minor tab height/width to zero so we get rid of the // bottom part of the notebook. WinSendMsg( hwndBook, BKM_SETDIMENSIONS, MPFROM2SHORT( 0, 0 ), MPFROMSHORT( BKA_MINORTAB ) ); fSuccess = SetFramePos( hwndFrame, cxPage, cyPage ); if( !fSuccess ) WinDestroyWindow( hwndBook ); } else WinDestroyWindow( hwndBook ); } else { fSuccess = FALSE; WinDestroyWindow( hwndBook ); Msg( "CreateNBWindow GpiQuery..Metrics RC(%X)", HWNDERR(hwndBook) ); } WinReleasePS( hps ); } else { fSuccess = FALSE; Msg( "CreateNotebookWindow WinCreateWindow RC(%X)",HWNDERR(hwndFrame)); } return fSuccess; }
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; }
MRESULT EXPENTRY ClientWndProc (HWND hwnd, ULONG msg, MPARAM mp1, MPARAM mp2) { static CHAR *szButtonLabel[] = { "Smaller", "Larger" } ; static HWND hwndFrame, hwndButton[2] ; static INT cxClient, cyClient, cxChar, cyChar ; FONTMETRICS fm ; HPS hps ; INT id ; RECTL rcl ; switch (msg) { case WM_CREATE : hwndFrame = WinQueryWindow (hwnd, QW_PARENT) ; hps = WinGetPS (hwnd) ; GpiQueryFontMetrics (hps, sizeof fm, &fm) ; cxChar = fm.lAveCharWidth ; cyChar = fm.lMaxBaselineExt ; WinReleasePS (hps) ; for (id = 0 ; id < 2 ; id++) hwndButton[id] = WinCreateWindow ( hwnd, // Parent WC_BUTTON, // Class szButtonLabel[id], // Text WS_VISIBLE | // Style BS_PUSHBUTTON, 0, 0, // Position 12 * cxChar, // Width 2 * cyChar, // Height hwnd, // Owner HWND_BOTTOM, // Placement id, // ID NULL, // Ctrl Data NULL) ; // Pres Params return 0 ; case WM_SIZE : cxClient = SHORT1FROMMP (mp2) ; cyClient = SHORT2FROMMP (mp2) ; for (id = 0 ; id < 2 ; id++) WinSetWindowPos (hwndButton[id], NULLHANDLE, cxClient / 2 + (14 * id - 13) * cxChar, (cyClient - 2 * cyChar) / 2, 0, 0, SWP_MOVE) ; return 0 ; case WM_COMMAND: WinQueryWindowRect (hwnd, &rcl) ; WinMapWindowPoints (hwnd, HWND_DESKTOP, (PPOINTL) &rcl, 2) ; switch (COMMANDMSG(&msg)->cmd) // Child ID { case 0: // "Smaller" rcl.xLeft += cxClient / 20 ; rcl.xRight -= cxClient / 20 ; rcl.yBottom += cyClient / 20 ; rcl.yTop -= cyClient / 20 ; break ; case 1: // "Larger" rcl.xLeft -= cxClient / 20 ; rcl.xRight += cxClient / 20 ; rcl.yBottom -= cyClient / 20 ; rcl.yTop += cyClient / 20 ; break ; } WinCalcFrameRect (hwndFrame, &rcl, FALSE) ; WinSetWindowPos (hwndFrame, NULLHANDLE, rcl.xLeft, rcl.yBottom, rcl.xRight - rcl.xLeft, rcl.yTop - rcl.yBottom, SWP_MOVE | SWP_SIZE) ; return 0 ; case WM_ERASEBACKGROUND: return MRFROMSHORT (1) ; } return WinDefWindowProc (hwnd, msg, mp1, mp2) ; }
// SET THE DIMENSIONS OF THE NOTEBOOK TABS. BOOL SetTabDimensions(PNBHDR pNotebookHdr) { HWND hwndNB = pNotebookHdr->hwndNB; HPS hps = WinGetPS(hwndNB); FONTMETRICS fm; POINTL aptl[TXTBOX_COUNT]; INT i, iSize, iLongestMajText = 0, iLongestMinText = 0; if (!hps) return FALSE; memset(&fm, 0, sizeof(FONTMETRICS)); // Calculate the height of a tab as the height of an average font character // plus a margin value. if (GpiQueryFontMetrics(hps, sizeof(FONTMETRICS), &fm)) fm.lMaxBaselineExt += (TAB_HEIGHT_MARGIN * 2); else fm.lMaxBaselineExt = DEFAULT_NB_TAB_HEIGHT + (TAB_HEIGHT_MARGIN * 2); // Calculate the longest tab text for both the MAJOR and MINOR pages for (i = 0; i < pNotebookHdr->nPages; i++) { if (!GpiQueryTextBox(hps, strlen(pNotebookHdr->PageArray[i].pszTabText), pNotebookHdr->PageArray[i].pszTabText, TXTBOX_COUNT, aptl)) iSize = 0; else iSize = aptl[TXTBOX_CONCAT].x; if (pNotebookHdr->PageArray[i].usTabType == BKA_MAJOR) { if (iSize > iLongestMajText) iLongestMajText = iSize; } else { if (iSize > iLongestMinText) iLongestMinText = iSize; } } WinReleasePS(hps); // Add a margin amount to the longest tab text if (iLongestMajText) iLongestMajText += TAB_WIDTH_MARGIN; if (iLongestMinText) iLongestMinText += TAB_WIDTH_MARGIN; // Set the tab dimensions for the MAJOR and MINOR pages. Note that the // docs as of this writing say to use BKA_MAJOR and BKA_MINOR in mp2 but // you really need BKA_MAJORTAB and BKA_MINORTAB. if (iLongestMajText) { if (!WinSendMsg(hwndNB, BKM_SETDIMENSIONS, MPFROM2SHORT(iLongestMajText, (SHORT)fm.lMaxBaselineExt), MPFROMSHORT(BKA_MAJORTAB))) return FALSE; } // If no minor tab text, set dimensions to 0 if (!WinSendMsg(hwndNB, BKM_SETDIMENSIONS, (iLongestMinText ? MPFROM2SHORT(iLongestMinText, (SHORT)fm.lMaxBaselineExt) : MP0), MPFROMSHORT(BKA_MINORTAB))) return FALSE; return TRUE; }
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 HWND hwndFrame, hwndButton[10]; static INT cxClient, cyClient, cyChar; static LONG ButtonWidth, ButtonHeight; static CLR buttonColour; CHAR szBuffer[32]; FONTMETRICS fm; HAB hab; HPS hps; INT id; RECTL rcl; switch(msg) { case WM_CREATE: hab = WinQueryAnchorBlock(hwnd); hwndFrame = WinQueryWindow(hwnd, QW_PARENT); hps = WinGetPS(hwnd); GpiQueryFontMetrics(hps, sizeof(fm),&fm); cyChar = fm.lMaxBaselineExt; WinReleasePS(hps); buttonColour.Index = 0x00CCCCCC; // Buttons should be big enough to hold the pointer, with a 4 pixel border ButtonWidth = WinQuerySysValue(HWND_DESKTOP, SV_CXPOINTER) + 4; ButtonHeight = WinQuerySysValue(HWND_DESKTOP, SV_CYPOINTER) + 4; hwndButton[0] = WinCreateWindow(hwnd, SHADEDBTNCLASS, "100", WS_VISIBLE | GBT_NORIGHTLINE | GBT_GRAPHIC, 0, 0, ButtonWidth, ButtonHeight, hwnd, HWND_BOTTOM, 0, NULL, NULL); hwndButton[1] = WinCreateWindow(hwnd, SHADEDBTNCLASS, "101", WS_VISIBLE | GBT_NOLEFTLINE | GBT_GRAPHIC, 0, 0, ButtonWidth, ButtonHeight, hwnd, HWND_BOTTOM, 1, NULL, NULL); // This is the status bar hwndButton[2] = WinCreateWindow(hwnd, SHADEDBTNCLASS, "Status Bar", WS_VISIBLE | GBT_NOPUSH, 0, 0, 0, cyChar * 5 / 4, hwnd, HWND_BOTTOM, 2, NULL, NULL); sprintf(szBuffer, "Red: %d Green: %d Blue: %d", buttonColour.rgb.red, buttonColour.rgb.green, buttonColour.rgb.blue); WinSetWindowText(hwndButton[2], szBuffer); // Buttons to change the colour of the about button hwndButton[3] = WinCreateWindow(hwnd, SHADEDBTNCLASS, "<", WS_VISIBLE | GBT_NORIGHTLINE, 0, 0, ButtonWidth, cyChar * 5 / 4, hwnd, HWND_BOTTOM, 3, NULL, NULL); hwndButton[4] = WinCreateWindow(hwnd, SHADEDBTNCLASS, ">", WS_VISIBLE | GBT_NOLEFTLINE, 0, 0, ButtonWidth, cyChar * 5 / 4, hwnd, HWND_BOTTOM, 4, NULL, NULL); hwndButton[5] = WinCreateWindow(hwnd, SHADEDBTNCLASS, "<", WS_VISIBLE | GBT_NORIGHTLINE, 0, 0, ButtonWidth, cyChar * 5 / 4, hwnd, HWND_BOTTOM, 5, NULL, NULL); hwndButton[6] = WinCreateWindow(hwnd, SHADEDBTNCLASS, ">", WS_VISIBLE | GBT_NOLEFTLINE, 0, 0, ButtonWidth, cyChar * 5 / 4, hwnd, HWND_BOTTOM, 6, NULL, NULL); hwndButton[7] = WinCreateWindow(hwnd, SHADEDBTNCLASS, "<", WS_VISIBLE | GBT_NORIGHTLINE, 0, 0, ButtonWidth, cyChar * 5 / 4, hwnd, HWND_BOTTOM, 7, NULL, NULL); hwndButton[8] = WinCreateWindow(hwnd, SHADEDBTNCLASS, ">", WS_VISIBLE | GBT_NOLEFTLINE, 0, 0, ButtonWidth, cyChar * 5 / 4, hwnd, HWND_BOTTOM, 8, NULL, NULL); // info about this program hwndButton[9] = WinCreateWindow(hwnd, SHADEDBTNCLASS, "About", WS_VISIBLE | GBT_RIGHTROUND | GBT_LEFTROUND, 0, 0, 2 * ButtonWidth, cyChar * 5 / 4, hwnd, HWND_BOTTOM, 9, NULL, NULL); // change the colour of the buttons WinSendMsg(hwndButton[3], GBM_SETCOLOR, MPFROMLONG(0x00FFCCCC), NULL); WinSendMsg(hwndButton[4], GBM_SETCOLOR, MPFROMLONG(0x00FFCCCC), NULL); WinSendMsg(hwndButton[5], GBM_SETCOLOR, MPFROMLONG(0x00CCFFCC), NULL); WinSendMsg(hwndButton[6], GBM_SETCOLOR, MPFROMLONG(0x00CCFFCC), NULL); WinSendMsg(hwndButton[7], GBM_SETCOLOR, MPFROMLONG(0x00CCCCFF), NULL); WinSendMsg(hwndButton[8], GBM_SETCOLOR, MPFROMLONG(0x00CCCCFF), NULL); WinSendMsg(hwndButton[9], GBM_SETCOLOR, MPFROMLONG(buttonColour.Index), NULL); return 0; case WM_SIZE: hps = WinGetPS(hwnd); GpiQueryFontMetrics(hps, sizeof(fm),&fm); cyChar = fm.lMaxBaselineExt; WinReleasePS(hps); cxClient = SHORT1FROMMP(mp2); cyClient = SHORT2FROMMP(mp2); // Center the buttons for(id = 0; id < 2; id++) WinSetWindowPos(hwndButton[id], NULLHANDLE, (cxClient >> 1) + ButtonWidth * (id - 1), (cyClient - ButtonHeight) >> 1, 0, 0, SWP_MOVE); for(id = 3; id < 9; id++) WinSetWindowPos(hwndButton[id], NULLHANDLE, (cxClient >> 1) + ButtonWidth * (-(id % 2)), ((cyClient + ButtonHeight) >> 1) + (3 - (id-1) / 2) * cyChar * 5 / 4, 0, 0, SWP_MOVE); WinSetWindowPos(hwndButton[9], NULLHANDLE, (cxClient >> 1) - ButtonWidth, ((cyClient - ButtonHeight) >> 1) - cyChar * 15 / 8, 0, 0, SWP_MOVE); // make the status bar span the width of the window WinSetWindowPos(hwndButton[2], NULLHANDLE, 0, 0, cxClient, cyChar * 5 / 4, SWP_SIZE); // Enable "Smaller" button if window is large enough for the buttons if (!WinIsWindowEnabled(hwndButton[0]) && ((9 * cxClient / 10) >= (2 * ButtonWidth)) && ((9 * cyClient / 10) >= (ButtonHeight + cyChar * 15 / 2))) WinEnableWindow(hwndButton[0], TRUE); // Disable "Smaller" button if window is too small for the buttons if (WinIsWindowEnabled(hwndButton[0]) && (((9 * cxClient / 10) < (2 * ButtonWidth)) || ((9 * cyClient / 10) < (ButtonHeight + cyChar * 15 / 2)))) WinEnableWindow(hwndButton[0], FALSE); return 0; case WM_COMMAND: WinQueryWindowRect(hwnd, &rcl); WinMapWindowPoints(hwnd, HWND_DESKTOP, (PPOINTL) &rcl, 2); switch(COMMANDMSG(&msg)->cmd) { case 0: // "Smaller" rcl.xLeft += cxClient / 20; rcl.xRight -= cxClient / 20; rcl.yBottom += cyClient / 20; rcl.yTop -= cyClient / 20; break; case 1: // "Larger" rcl.xLeft -= cxClient / 20; rcl.xRight += cxClient / 20; rcl.yBottom -= cyClient / 20; rcl.yTop += cyClient / 20; break; case 3: // change red buttonColour.rgb.red--; if (buttonColour.rgb.red == 0) WinEnableWindow(hwndButton[3], FALSE); if (!WinIsWindowEnabled(hwndButton[4])) WinEnableWindow(hwndButton[4], TRUE); break; case 4: buttonColour.rgb.red++; if (buttonColour.rgb.red == 255) WinEnableWindow(hwndButton[4], FALSE); if (!WinIsWindowEnabled(hwndButton[3])) WinEnableWindow(hwndButton[3], TRUE); break; case 5: // change green buttonColour.rgb.green--; if (buttonColour.rgb.green == 0) WinEnableWindow(hwndButton[5], FALSE); if (!WinIsWindowEnabled(hwndButton[6])) WinEnableWindow(hwndButton[6], TRUE); break; case 6: buttonColour.rgb.green++; if (buttonColour.rgb.green == 255) WinEnableWindow(hwndButton[6], FALSE); if (!WinIsWindowEnabled(hwndButton[5])) WinEnableWindow(hwndButton[5], TRUE); break; case 7:// change blue buttonColour.rgb.blue--; if (buttonColour.rgb.blue == 0) WinEnableWindow(hwndButton[7], FALSE); if (!WinIsWindowEnabled(hwndButton[8])) WinEnableWindow(hwndButton[8], TRUE); break; case 8: buttonColour.rgb.blue++; if (buttonColour.rgb.blue == 255) WinEnableWindow(hwndButton[8], FALSE); if (!WinIsWindowEnabled(hwndButton[7])) WinEnableWindow(hwndButton[7], TRUE); break; case 9: WinDlgBox(HWND_DESKTOP, hwnd, AboutDlgProc, NULLHANDLE, IDD_ABOUT, NULL); return 0; } sprintf(szBuffer, "Red: %d Green: %d Blue: %d", buttonColour.rgb.red, buttonColour.rgb.green, buttonColour.rgb.blue); WinSetWindowText(hwndButton[2], szBuffer); WinCalcFrameRect(hwndFrame, &rcl, FALSE); WinSetWindowPos(hwndFrame, NULLHANDLE, rcl.xLeft, rcl.yBottom, rcl.xRight - rcl.xLeft, rcl.yTop - rcl.yBottom, SWP_MOVE | SWP_SIZE); WinPostMsg(hwndButton[9], GBM_SETCOLOR, MPFROMLONG(buttonColour.Index), NULL); return 0; case WM_ERASEBACKGROUND: WinFillRect((HPS)LONGFROMMP(mp1), PVOIDFROMMP(mp2), CLR_PALEGRAY); return 0; } return WinDefWindowProc(hwnd, msg, mp1, mp2); }
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 ); }
/* * * BrowseWndProc * * DESCRIPTION: * * Processes messages for the Browse-O-Matic client window. * */ MRESULT EXPENTRY BrowseWndProc( HWND hwnd, ULONG msg, MPARAM mp1, MPARAM mp2) { switch( msg){ case WM_CREATE: { CHAR pszTitle[ MAX_TITLE_LENGTH]; PBROWSEDATA pWindowData; pWindowData = (PBROWSEDATA)mp1; WinSetWindowPtr( hwnd, QWL_USER, pWindowData); /*******************/ /* Load the object */ /*******************/ _LoadObject( pWindowData->somSelf, pWindowData->pszObjectName, &pWindowData->ulFileLength, &pWindowData->pBuffer, &pWindowData->pLines, &pWindowData->usNumberOfTextLines, &pWindowData->usNumberOfTextColumns); _GetLinesAndColumns( pWindowData->somSelf, pWindowData->bDisplay, &pWindowData->sTotalLines, &pWindowData->sTotalColumns, pWindowData->usNumberOfTextLines, pWindowData->usNumberOfTextColumns, pWindowData->ulFileLength); /*********************************************/ /* Get the window handle for the scroll bars */ /*********************************************/ pWindowData->hwndVscroll = WinWindowFromID( WinQueryWindow( hwnd, QW_PARENT), FID_VERTSCROLL); pWindowData->hwndHscroll = WinWindowFromID( WinQueryWindow( hwnd, QW_PARENT), FID_HORZSCROLL); /*************************/ /* Save font information */ /*************************/ WinSendMsg( hwnd, IDL_SETFONTINFO, (MPARAM)0, (MPARAM)0); /*****************/ /* Get the focus */ /*****************/ WinSetFocus( HWND_DESKTOP, hwnd); /*****************************************************/ /* Create the title for the Browse-O-Matic title bar */ /*****************************************************/ if( pWindowData->bDisplay == PMBROWSE_HEX_DISPLAY_MODE) sprintf( pszTitle, "Object: %s (%d Bytes)", pWindowData->pszObjectName, pWindowData->ulFileLength); else sprintf( pszTitle, "Object: %s (%hd Lines)", pWindowData->pszObjectName, pWindowData->sTotalLines); /************************************************/ /* Register the current open view of the object */ /************************************************/ _wpAddToObjUseList( pWindowData->somSelf, &(pWindowData->UseItem)); _wpRegisterView( pWindowData->somSelf, WinQueryWindow( hwnd, QW_PARENT), pszTitle); } break; case WM_CLOSE: { HWND hwndFrame; PBROWSEDATA pWindowData; pWindowData = (PBROWSEDATA) WinQueryWindowPtr( hwnd, QWL_USER); hwndFrame = WinQueryWindow( hwnd, QW_PARENT); /*****************************************************/ /* Save the window info - size, location, and fonts. */ /*****************************************************/ WinStoreWindowPos( APPL_NAME, pWindowData->pszApplKey, hwndFrame); /**********************************************************/ /* Free the window data and unload the file system object */ /**********************************************************/ if( pWindowData){ if( pWindowData->pszObjectName) _wpFreeMem( pWindowData->somSelf, ( PBYTE)pWindowData->pszObjectName); _wpFreeMem( pWindowData->somSelf, ( PBYTE)pWindowData); } _UnloadObject( pWindowData->somSelf, pWindowData->pBuffer, pWindowData->pLines); _wpDeleteFromObjUseList( pWindowData->somSelf, &pWindowData->UseItem); /*******************/ /* Kill the window */ /*******************/ WinPostMsg( hwnd, WM_QUIT, 0, 0 ); WinDestroyWindow( hwndFrame); } break; /*******************************************************************/ /* The font characteristics have changed. This happens when a font */ /* from the font palette is dropped on the client window. */ /*******************************************************************/ case WM_PRESPARAMCHANGED: { PBROWSEDATA pWindowData; pWindowData = (PBROWSEDATA) WinQueryWindowPtr( hwnd, QWL_USER); if( (ULONG)mp1 == PP_FONTNAMESIZE){ /***********************************************/ /* Get the new font information and redraw the */ /* window with the new font/font size. */ /***********************************************/ WinSendMsg( hwnd, IDL_SETFONTINFO, (MPARAM)0, (MPARAM)0); WinSendMsg( hwnd, WM_SIZE, 0, MPFROM2SHORT( pWindowData->sClientWidth, pWindowData->sClientHeight)); } } break; case WM_SIZE: { PBROWSEDATA pWindowData; pWindowData = (PBROWSEDATA) WinQueryWindowPtr( hwnd, QWL_USER); /***************************************/ /* Save client window size information */ /***************************************/ pWindowData->sClientWidth = SHORT1FROMMP( mp2); pWindowData->sClientHeight = SHORT2FROMMP( mp2); pWindowData->sPageHeight = pWindowData->sClientHeight/ pWindowData->sCharHeight; pWindowData->sPageWidth = pWindowData->sClientWidth / pWindowData->sCharWidth; /**************************************/ /* Set the ranges for the scroll bars */ /**************************************/ WinPostMsg( pWindowData->hwndVscroll, SBM_SETSCROLLBAR, (MPARAM)pWindowData->sCurrentLine, MPFROM2SHORT( 0, pWindowData->sTotalLines - pWindowData->sPageHeight)); WinPostMsg( pWindowData->hwndHscroll, SBM_SETSCROLLBAR, (MPARAM)pWindowData->sCurrentColumn, MPFROM2SHORT( 0, pWindowData->sTotalColumns - pWindowData->sPageWidth)); /*************************************/ /* Set scroll bar thumb control size */ /*************************************/ WinPostMsg( pWindowData->hwndVscroll, SBM_SETTHUMBSIZE, MPFROM2SHORT( pWindowData->sPageHeight, pWindowData->sTotalLines), (MPARAM) 0); WinPostMsg( pWindowData->hwndHscroll, SBM_SETTHUMBSIZE, MPFROM2SHORT( pWindowData->sPageWidth, pWindowData->sTotalColumns), (MPARAM) 0); /************************************************************/ /* If the all the lines and/or columns can fit in the new */ /* sized window, set the sCurrentLine and/or sCurrentColumn */ /* to the top/right side. */ /************************************************************/ if( pWindowData->sPageHeight >= pWindowData->sTotalLines) pWindowData->sCurrentLine = 0; if( pWindowData->sPageWidth >= pWindowData->sTotalColumns) pWindowData->sCurrentColumn = 0; /********************************************/ /* Repaint window with new size information */ /********************************************/ WinInvalidateRect( hwnd, NULL, FALSE); } return( 0); case WM_PAINT: { HPS hps; CHAR pszText[255]; UINT nLength = 0; RECTL rect; POINTL point; SHORT sLine; SHORT sTopLine; SHORT sBottomLine; SHORT sLinesFromTop; PBROWSEDATA pWindowData; pWindowData = (PBROWSEDATA) WinQueryWindowPtr( hwnd, QWL_USER); hps = WinBeginPaint( hwnd, NULLHANDLE, &rect); /*******************************************/ /* Clear the area that needs to be redrawn */ /*******************************************/ GpiErase( hps); /********************************/ /* Determine first clipped line */ /********************************/ sLinesFromTop = ( pWindowData->sClientHeight - rect.yTop) / pWindowData->sCharHeight; rect.yTop = pWindowData->sClientHeight - ( pWindowData->sCharHeight * sLinesFromTop); /***************************************************************/ /* Determine the first position to write at. NOTE: PM handles */ /* clipping for point.x < 0. Any characters written before the */ /* the first column or after the last column are clipped. */ /***************************************************************/ point.y = rect.yTop - pWindowData->sCharHeight + pWindowData->sCharDescender; point.x = pWindowData->sCurrentColumn*pWindowData->sCharWidth * -1; /***********************************************/ /* Determine the top and bottom lines to write */ /***********************************************/ sTopLine = rect.yTop / pWindowData->sCharHeight; sBottomLine = rect.yBottom / pWindowData->sCharHeight; /*********************************************************/ /* Make sure that we aren't trying to display more lines */ /* then are available. */ /*********************************************************/ if( pWindowData->sPageHeight - sBottomLine + 1 > pWindowData->sTotalLines - pWindowData->sCurrentLine) sBottomLine=pWindowData->sPageHeight-(pWindowData->sTotalLines - pWindowData->sCurrentLine) + 1; /********************************/ /* Redraw the invalid rectangle */ /********************************/ for( sLine = sTopLine; sLine >= sBottomLine; sLine--){ /*******************************************/ /* Get the line of text or hex information */ /* that we are going to write. */ /*******************************************/ if( pWindowData->bDisplay == PMBROWSE_HEX_DISPLAY_MODE) nLength = _GetHexLine( pWindowData->somSelf, pWindowData->sPageHeight-sLine+pWindowData->sCurrentLine +1, pWindowData->pBuffer, pWindowData->ulFileLength, pszText); else nLength = _GetTextLine( pWindowData->somSelf, pWindowData->sPageHeight-sLine+pWindowData->sCurrentLine +1, pWindowData->pLines, pszText); /******************/ /* Write the text */ /******************/ if( nLength != 0) GpiCharStringAt( hps, &point, nLength, pszText); point.y -= pWindowData->sCharHeight; } WinEndPaint( hps); } return( 0); /*******************************************/ /* Keyboard support for scrolling and help */ /*******************************************/ case WM_CHAR: /****************************************/ /* Show general help if user selects F1 */ /****************************************/ if( CHARMSG( &msg)->vkey == VK_F1){ PBROWSEDATA pWindowData; pWindowData = (PBROWSEDATA) WinQueryWindowPtr(hwnd,QWL_USER); _wpDisplayHelp( pWindowData->somSelf, PANEL_MAIN, "browse.hlp"); return 0; } if( (CHARMSG( &msg)->fs & KC_KEYUP)) return 0; switch( CHARMSG( &msg)->vkey){ case VK_UP: WinPostMsg( hwnd, WM_VSCROLL, 0, MPFROM2SHORT( 0, SB_LINEUP)); return 0; case VK_DOWN: WinPostMsg( hwnd, WM_VSCROLL, 0, MPFROM2SHORT( 0, SB_LINEDOWN)); return 0; case VK_RIGHT: /************************************************************/ /* Ctrl-Right scrolls one page to the right. Right scrolls */ /* to the right. */ /************************************************************/ if( (CHARMSG( &msg)->fs & KC_CTRL)) WinPostMsg( hwnd, WM_HSCROLL, 0, MPFROM2SHORT(0, SB_PAGERIGHT)); else WinPostMsg( hwnd, WM_HSCROLL, 0, MPFROM2SHORT(0, SB_LINERIGHT)); return 0; case VK_LEFT: /*********************************************************/ /* Ctrl-Left scrolls one page to the left. Left scrolls */ /* to the Left. */ /*********************************************************/ if( (CHARMSG( &msg)->fs & KC_CTRL)) WinPostMsg( hwnd, WM_HSCROLL, 0, MPFROM2SHORT( 0, SB_PAGELEFT)); else WinPostMsg( hwnd, WM_HSCROLL, 0, MPFROM2SHORT( 0, SB_LINELEFT)); return 0; case VK_PAGEUP: WinPostMsg( hwnd, WM_VSCROLL, 0, MPFROM2SHORT( 0, SB_PAGEUP)); return 0; case VK_PAGEDOWN: WinPostMsg( hwnd, WM_VSCROLL, 0, MPFROM2SHORT( 0, SB_PAGEDOWN)); return 0; case VK_HOME: { PBROWSEDATA pWindowData; pWindowData = (PBROWSEDATA) WinQueryWindowPtr(hwnd,QWL_USER); /*********************************************************/ /* Ctrl-Home positions at the first line, Home positions */ /* at the beginning of the current line. */ /*********************************************************/ if( (CHARMSG( &msg)->fs & KC_CTRL)){ WinPostMsg( hwnd, WM_VSCROLL, (MPARAM)0, MPFROM2SHORT( 0, SB_SLIDERPOSITION)); WinPostMsg( pWindowData->hwndVscroll, SBM_SETPOS, MPFROMSHORT( 0), 0); } else{ WinPostMsg( hwnd, WM_HSCROLL, (MPARAM)0, MPFROM2SHORT( 0, SB_SLIDERPOSITION)); WinPostMsg( pWindowData->hwndHscroll, SBM_SETPOS, MPFROMSHORT( 0), 0); } return 0; } case VK_END: { PBROWSEDATA pWindowData; pWindowData = (PBROWSEDATA) WinQueryWindowPtr(hwnd,QWL_USER); /*********************************************************/ /* Ctrl-End positions at the last line, End positions at */ /* the end of the current line. */ /*********************************************************/ if( (CHARMSG( &msg)->fs & KC_CTRL)){ WinPostMsg( hwnd, WM_VSCROLL, (MPARAM)0, MPFROM2SHORT( pWindowData->sTotalLines - pWindowData->sPageHeight, SB_SLIDERPOSITION)); WinPostMsg( pWindowData->hwndVscroll, SBM_SETPOS, MPFROMSHORT( pWindowData->sTotalLines - pWindowData->sPageHeight), 0); } else{ WinPostMsg( hwnd, WM_HSCROLL, (MPARAM)0, MPFROM2SHORT( pWindowData->sTotalColumns - pWindowData->sPageWidth, SB_SLIDERPOSITION)); WinPostMsg( pWindowData->hwndHscroll, SBM_SETPOS, MPFROMSHORT( pWindowData->sTotalColumns - pWindowData->sPageWidth), 0); } return 0; } } break; /******************/ /* Scroll Up/Down */ /******************/ case WM_VSCROLL: { PBROWSEDATA pWindowData; pWindowData = (PBROWSEDATA) WinQueryWindowPtr(hwnd,QWL_USER); switch( SHORT2FROMMP( mp2)){ case SB_LINEUP: if( pWindowData->sCurrentLine > 0){ pWindowData->sCurrentLine--; WinPostMsg( pWindowData->hwndVscroll, SBM_SETPOS, (MPARAM)pWindowData->sCurrentLine, 0); WinScrollWindow( hwnd, 0, pWindowData->sCharHeight * -1, NULL, NULL, NULLHANDLE, NULL, SW_INVALIDATERGN); } return( 0); case SB_LINEDOWN: if( pWindowData->sCurrentLine < pWindowData->sTotalLines - pWindowData->sPageHeight){ pWindowData->sCurrentLine++; WinPostMsg( pWindowData->hwndVscroll, SBM_SETPOS, (MPARAM)pWindowData->sCurrentLine, 0); WinScrollWindow( hwnd, 0, pWindowData->sCharHeight, NULL, NULL, NULLHANDLE, NULL, SW_INVALIDATERGN); } return( 0); case SB_PAGEUP: if( pWindowData->sCurrentLine > 0){ pWindowData->sCurrentLine = max( 0, pWindowData->sCurrentLine - pWindowData->sPageHeight); WinPostMsg( pWindowData->hwndVscroll, SBM_SETPOS, (MPARAM)pWindowData->sCurrentLine,0); WinInvalidateRect( hwnd, NULL, FALSE); } return( 0); case SB_PAGEDOWN: if( pWindowData->sCurrentLine < pWindowData->sTotalLines - pWindowData->sPageHeight){ pWindowData->sCurrentLine= min( pWindowData->sTotalLines - pWindowData->sPageHeight, pWindowData->sCurrentLine + pWindowData->sPageHeight); WinPostMsg( pWindowData->hwndVscroll, SBM_SETPOS, (MPARAM)pWindowData->sCurrentLine,0); WinInvalidateRect( hwnd, NULL, FALSE); } return( 0); case SB_SLIDERPOSITION: /***********************************************************/ /* Can't change current line if all the text fits in the */ /* window. */ /***********************************************************/ if( pWindowData->sTotalLines > pWindowData->sPageHeight){ pWindowData->sCurrentLine = SHORT1FROMMP( mp2); WinInvalidateRect( hwnd, NULL, FALSE); } return( 0); } } break; /*********************/ /* Scroll Right/Left */ /*********************/ case WM_HSCROLL: { PBROWSEDATA pWindowData; pWindowData = ( PBROWSEDATA)WinQueryWindowPtr( hwnd, QWL_USER); switch( SHORT2FROMMP( mp2)){ case SB_LINELEFT: if( pWindowData->sCurrentColumn > 0){ pWindowData->sCurrentColumn = max( 0, pWindowData->sCurrentColumn - 1); WinPostMsg( pWindowData->hwndHscroll, SBM_SETPOS, (MPARAM)pWindowData->sCurrentColumn,0); WinScrollWindow( hwnd, pWindowData->sCharWidth, 0, NULL, NULL, NULLHANDLE, NULL, SW_INVALIDATERGN); } return( 0); case SB_LINERIGHT: if(pWindowData->sCurrentColumn < pWindowData->sTotalColumns - pWindowData->sPageWidth){ pWindowData->sCurrentColumn=min(pWindowData->sTotalColumns, pWindowData->sCurrentColumn + 1); WinPostMsg( pWindowData->hwndHscroll, SBM_SETPOS, (MPARAM)pWindowData->sCurrentColumn, 0); WinScrollWindow( hwnd, pWindowData->sCharWidth * -1, 0, NULL, NULL, NULLHANDLE, NULL, SW_INVALIDATERGN); } return( 0); case SB_PAGELEFT: if( pWindowData->sCurrentColumn > 0){ pWindowData->sCurrentColumn = max( 0, pWindowData->sCurrentColumn - pWindowData->sPageWidth); WinPostMsg( pWindowData->hwndHscroll, SBM_SETPOS, (MPARAM)pWindowData->sCurrentColumn, 0); WinInvalidateRect( hwnd, NULL, FALSE); } return( 0); case SB_PAGERIGHT: if(pWindowData->sCurrentColumn < pWindowData->sTotalColumns - pWindowData->sPageWidth){ pWindowData->sCurrentColumn=min(pWindowData->sTotalColumns - pWindowData->sPageWidth, pWindowData->sCurrentColumn + pWindowData->sPageWidth); WinPostMsg( pWindowData->hwndHscroll, SBM_SETPOS, (MPARAM)pWindowData->sCurrentColumn, 0); WinInvalidateRect( hwnd, NULL, FALSE); } return( 0); case SB_SLIDERPOSITION: /***********************************************************/ /* Can't change current column if all the text fits in the */ /* window. */ /***********************************************************/ if( pWindowData->sTotalColumns > pWindowData->sPageWidth){ pWindowData->sCurrentColumn = SHORT1FROMMP( mp2); WinInvalidateRect( hwnd, NULL, FALSE); } return( 0); } } break; /*****************************/ /* Get font size information */ /*****************************/ case IDL_SETFONTINFO: { HPS hps; FONTMETRICS fm; PBROWSEDATA pWindowData; pWindowData = ( PBROWSEDATA)WinQueryWindowPtr( hwnd, QWL_USER); hps = WinGetPS( hwnd); GpiQueryFontMetrics( hps, sizeof( fm), &fm); WinReleasePS( hps); /***********************************************************/ /* The character width is average of the average uppercase */ /* and average lower case widths. */ /***********************************************************/ pWindowData->sCharWidth = (SHORT)fm.lMaxCharInc; pWindowData->sCharHeight = (SHORT)fm.lMaxBaselineExt; pWindowData->sCharDescender = (SHORT)fm.lMaxDescender; } return( 0); /*********************************************/ /* Display no help available message to user */ /*********************************************/ case HM_HELPSUBITEM_NOT_FOUND: return( ( MRESULT)FALSE); /**************************************/ /* Return name of help for keys panel */ /**************************************/ case HM_QUERY_KEYS_HELP: return( ( MRESULT)PANEL_HELPKEYS); } /********************************************************/ /* Let the default window procedure process the message */ /********************************************************/ return( WinDefWindowProc( hwnd, msg, mp1, mp2)); }