📄 ngstatusbar.cpp
字号:
/*****************************************************************************
*
* Class: CNGStatusBarPaneInfo, CNGStatusBar
* Files: CNGStatusBar.Cpp, CNGStatusBar.H
* Description: With this class complex status lines can be administered.
* So can be represented in each Pane texts, bit-maps or
* progress Bars, be gescrollt horizontal, vertically or diagonally
* and be aligned left, on the right or centered. Also each time
* between the individual modes can be shifted up and down.
* For each Pane can be defined both switching on on and a switching
* off text, - background or - bit-map.
*
* Functions: operator=(), SetDefault(), SetFont(), SetMode(),
* (CNGStatusBarPaneInfo) SetFgColor(), SetBkColor(), SetBitmap(), SetText(),
* SetNumber(), HScroll(), VScroll(),
* Functions: CreateStatusBar(), SetIndicators(), OnPaint(),
* (CNGStatusBar) DrawSizing(), DrawTextPane(), DrawBitmapPane(),
* DrawProgressPane(), GetCNGStatusBarPaneInfo(), OnTimer(),
* SetStyle(), SetWidth(), GetStyle(), GetWidth(), GetID(),
* OnDestroy(), SavePane(), RestorePane(),
* GetPaneAtPosition(), OnMouseMove(),
* OnLButtonUp(), OnMButtonUp(), OnRButtonUp(),
* OnLButtonDown(), OnMButtonDown(), OnRButtonDown(),
* OnLButtonDblClk(), OnMButtonDblClk(), OnRButtonDblClk(),
*
****************************************************************************/
#include "StdAfx.h"
#include "NGStatusBar.h"
#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif
volatile static char jrrcid[] = "%J%";
#define IDC_JRLIB_STATUSBAR_TIMER 20000
/*****************************************************************************
* Klasse: CNGStatusBarPaneInfo
* Funktion: CNGStatusBarPaneInfo, ~CNGStatusBarPaneInfo
* Parameter: -
* Return:
*
* The constructor initialize a Pane. In the Desturktor a possibly
* available progress check is again deleted.
*
****************************************************************************/
CNGStatusBarPaneInfo::CNGStatusBarPaneInfo()
{
progress = NULL;
hScrollPos = 0;
vScrollPos = 0;
SetDefault();
}
CNGStatusBarPaneInfo::CNGStatusBarPaneInfo(const CNGStatusBarPaneInfo& paneInfo)
{
for (int i = 0; i < 2; i++)
{
fgColor[i] = paneInfo.fgColor[i];
bkColor[i] = paneInfo.bkColor[i];
string[i] = paneInfo.string[i];
}
font = paneInfo.font;
mode = paneInfo.mode;
progress = NULL;
hScrollPos = paneInfo.hScrollPos;
vScrollPos = paneInfo.vScrollPos;
}
CNGStatusBarPaneInfo::~CNGStatusBarPaneInfo()
{
if (progress) delete progress;
progress = NULL;
}
/*****************************************************************************
* Klasse: CNGStatusBarPaneInfo
* Funktion: operator=
* Parameter: paneInfo Zweites CNGStatusBarPaneInfo-Element, dessen Informationen
* kopiert werden.
* Return: Kopie des CNGStatusBarPaneInfo-Elements
*
* Allocation operator!!! NOTE!!! ' progress ' is not copied! Possibly
* available progress bar one deletes
*
*
****************************************************************************/
CNGStatusBarPaneInfo CNGStatusBarPaneInfo::operator=(const CNGStatusBarPaneInfo& paneInfo)
{
for (int i = 0; i < 2; i++)
{
fgColor[i] = paneInfo.fgColor[i];
bkColor[i] = paneInfo.bkColor[i];
string[i] = paneInfo.string[i];
}
font = paneInfo.font;
mode = paneInfo.mode;
hScrollPos = paneInfo.hScrollPos;
vScrollPos = paneInfo.vScrollPos;
if (progress) delete progress;
progress = NULL;
return *this;
}
/*****************************************************************************
* Klasse: CNGStatusBarPaneInfo
* Funktion: SetDefault
* Parameter: -
* Return: -
*
* Here the Members is initialized
****************************************************************************/
void CNGStatusBarPaneInfo::SetDefault()
{
bkColor[1] = COLORREF(GetSysColor(COLOR_3DFACE));
bkColor[0] = bkColor[1];
fgColor[1] = GetSysColor(COLOR_BTNTEXT);
fgColor[0] = RGB(GetRValue(bkColor[1])/2, GetGValue(bkColor[1])/2, GetBValue(bkColor[1])/2);
mode = XSB_TEXT | DT_LEFT;
SetFont(CFont::FromHandle((HFONT) GetStockObject(ANSI_VAR_FONT)));
if (progress) delete progress;
progress = NULL;
}
/*****************************************************************************
* Klasse: CNGStatusBarPaneInfo
* Funktion: SetFont
* Parameter: name Name der Schriftart (Bsp.: Arial)
* size Gr鲞e der Schriftart in 1/10 Pt (Bsp.: 120)
* Return: -
*
* The Font for a Pane sets on the basis the font name and the point size
* (10 * Point).
****************************************************************************/
void CNGStatusBarPaneInfo::SetFont(LPCSTR name, int size)
{
CFont pointFont;
pointFont.CreatePointFont(size, name);
pointFont.GetLogFont(&font);
}
/*****************************************************************************
* Klasse: CNGStatusBarPaneInfo
* Funktion: SetMode
* Parameter: newMode Neuer Anzeigemodus
* Return: -
*
* Sets the mode for the current Pane. If this Pane were filled with progress
* CTRL before, this is deleted before.
*
****************************************************************************/
void CNGStatusBarPaneInfo::SetMode(int newMode)
{
if ((mode = newMode) & XSB_PROGRESS)
{
if (!progress)
{
UINT style = WS_VISIBLE | WS_CHILD;
if (mode & XSB_SMOOTH) style |= PBS_SMOOTH;
progress = new CProgressCtrl();
progress->Create(style, CRect(0,0,0,0), CNGStatusBar::aktBar, 1);
}
}
else if (progress)
{
delete progress;
progress = NULL;
}
}
/*****************************************************************************
* Klasse: CNGStatusBarPaneInfo
* Funktion: SetFgColor
* Parameter: on Text-Farbe im aktiven Zustand
* off Text-Farbe im inaktiven Zustand
* Return: -
*
* Defines the colours for a displayed text. Here two colours for the active
* and the inactive status can be defined. If the second colour is forgotten,
* it is pre-defined with the half intensity of the background colour.
****************************************************************************/
void CNGStatusBarPaneInfo::SetFgColor(COLORREF on, COLORREF off)
{
fgColor[1] = on;
if (off != -1)
fgColor[0] = off;
else
{
COLORREF bk = GetSysColor(COLOR_3DFACE);
fgColor[0] = RGB(GetRValue(bk)/2, GetGValue(bk)/2, GetBValue(bk)/2);
}
}
/*****************************************************************************
* Klasse: CNGStatusBarPaneInfo
* Funktion: SetBkColor
* Parameter: on Hintergrundfarbe im aktiven Zustand
* off Hintergrundfarbe im inaktiven Zustand
* Return: -
*
* Defines the background colours for a displayed text. Here two colours for
* the active and the inactive status can be defined. If the second colour is
* forgotten, it is pre-defined with the background colour.
****************************************************************************/
void CNGStatusBarPaneInfo::SetBkColor(COLORREF on, COLORREF off)
{
bkColor[1] = on;
if (off != -1) bkColor[0] = off;
else bkColor[0] = GetSysColor(COLOR_3DFACE);
}
/*****************************************************************************
* Klasse: CNGStatusBarPaneInfo
* Funktion: SetBitmap, SetText, SetNumber
* Parameter: newBitmap Name des im Pane anzuzeigenden Bitmaps
* newText Im Pane anzuzeigender Text
* newNumber Im Pane anzuzeigende Nummer
* Return: -
*
* With these functions the bit-maps, texts or numbers for the display
* in the current Pane are set.
****************************************************************************/
void CNGStatusBarPaneInfo::SetBitmap(LPCSTR newOnBitmap, LPCSTR newOffBitmap)
{
string[1] = newOnBitmap;
string[0] = newOffBitmap;
}
void CNGStatusBarPaneInfo::SetText(LPCSTR newOnText, LPCSTR newOffText)
{
string[1] = newOnText;
string[0] = newOffText;
}
void CNGStatusBarPaneInfo::SetIconAndText(DWORD iconResourceID, LPCSTR text)
{
string[1].Format("%d", iconResourceID);
string[0] = text;
}
void CNGStatusBarPaneInfo::SetNumber(int newOnNumber, int newOffNumber)
{
string[1].Format("%d", newOnNumber);
string[0].Format("%d", newOffNumber);
}
/*****************************************************************************
* Klasse: CNGStatusBarPaneInfo
* Funktion: HScroll, VScroll
* Parameter: rect Ausgaberechteck des aktuellen Panes
* maxWidth Maximale Breite, bzw. H鰄e beim Scrollen
* maxHeight (z. B. Textl鋘ge oder Bitmapbreite)
* nullValue Wert f黵 Turnaround
* Return: -
*
* Increments the respective Scrollvariable, so that the text or the bit-map
* of the current Panes is gescrollt represented. If the max. size is exceeded,
* the scrolling begins again from the front.
****************************************************************************/
void CNGStatusBarPaneInfo::HScroll(CRect& rect, int maxWidth, int nullValue)
{
if (++hScrollPos > maxWidth) hScrollPos = nullValue;
rect.left -= hScrollPos;
}
void CNGStatusBarPaneInfo::VScroll(CRect& rect, int maxHeight, int nullValue)
{
if (++vScrollPos > maxHeight) vScrollPos = nullValue;
rect.top -= vScrollPos;
}
/*****************************************************************************
* Klasse: CNGStatusBarPaneInfo
* Funktion: Dump, AssertValid, operator<<
* Parameter: dc CDumpContext
* paneInfo Ausgabelement
* Return: -
*
*
*
*
****************************************************************************/
#ifdef _DEBUG
void CNGStatusBarPaneInfo::Dump(CDumpContext& dc) const
{
dc << "FgColor / BkColor / Value:\t"
<< fgColor[1] << " - " << fgColor[0] << " / "
<< bkColor[1] << " - " << bkColor[0] << " / "
<< string[1] << " - " << string[0] << "\n"
<< "Mode:\t" << mode << "\n";
}
void CNGStatusBarPaneInfo::AssertValid() const
{
ASSERT((progress == NULL) || _CrtIsValidHeapPointer(progress));
}
CDumpContext& AFXAPI operator<<(CDumpContext& dc, CNGStatusBarPaneInfo& paneInfo)
{
paneInfo.Dump(dc);
return dc;
}
#endif // _DEBUG
//****************************************************************************
//****************************************************************************
//****************************************************************************
CNGStatusBar *CNGStatusBar::aktBar = NULL;
/*****************************************************************************
* Klasse: CNGStatusBar
* Funktion: CNGStatusBar, ~CNGStatusBar
* Parameter: -
* Return:
*
* Constructor and Destructor.
****************************************************************************/
CNGStatusBar::CNGStatusBar()
{
aktBar = this;
timerID = 0;
}
CNGStatusBar::~CNGStatusBar()
{}
BEGIN_MESSAGE_MAP(CNGStatusBar, CStatusBar)
//{{AFX_MSG_MAP(CNGStatusBar)
ON_WM_DESTROY()
ON_WM_TIMER()
ON_WM_PAINT()
ON_WM_LBUTTONDBLCLK()
ON_WM_LBUTTONDOWN()
ON_WM_LBUTTONUP()
ON_WM_MBUTTONDBLCLK()
ON_WM_MBUTTONDOWN()
ON_WM_MBUTTONUP()
ON_WM_MOUSEMOVE()
ON_WM_RBUTTONDBLCLK()
ON_WM_RBUTTONDOWN()
ON_WM_RBUTTONUP()
ON_WM_CREATE()
ON_WM_ERASEBKGND()
//}}AFX_MSG_MAP
END_MESSAGE_MAP()
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -