Files
Work/nntp/LOGVIEW.CPP
2024-08-07 09:16:27 -04:00

114 lines
2.9 KiB
C++

#include <nntp/logview.hpp>
#include <common/odlstalt.hpp>
#include <common/crsctrl.hpp>
#include <fileio/fileio.hpp>
#include <statbar/statbarx.hpp>
#include <printman/printman.hpp>
LogView::LogView(void)
{
mCreateHandler.setCallback(this,&LogView::createHandler);
mSizeHandler.setCallback(this,&LogView::sizeHandler);
insertHandler(VectorHandler::CreateHandler,&mCreateHandler);
insertHandler(VectorHandler::SizeHandler,&mSizeHandler);
}
LogView::~LogView()
{
removeHandler(VectorHandler::CreateHandler,&mCreateHandler);
removeHandler(VectorHandler::SizeHandler,&mSizeHandler);
}
CallbackData::ReturnType LogView::createHandler(CallbackData &someCallbackData)
{
Rect winRect;
Rect statRect;
clientRect(winRect);
mStatusBar=::new StatusBarEx(*this,StatusBarID);
mStatusBar.disposition(PointerDisposition::Delete);
mStatusBar->clientRect(statRect);
winRect.bottom(winRect.bottom()-(statRect.bottom()));
mListBox=new OwnerDrawListAltColor(*this,winRect,ListBoxID,RGBColor(255,255,232),RGBColor(192,220,192),RGBColor(0,255,255));
mListBox.disposition(PointerDisposition::Delete);
mListBox->show(SW_SHOW);
return FALSE;
}
CallbackData::ReturnType LogView::sizeHandler(CallbackData &someCallbackData)
{
Rect winRect;
Rect statRect;
if(SIZE_RESTORED==someCallbackData.wParam())mListBox->show(SW_SHOWNORMAL);
clientRect(winRect);
mStatusBar->clientRect(statRect);
winRect.bottom(winRect.bottom()-statRect.bottom());
mListBox->moveWindow(winRect,TRUE);
return FALSE;
}
void LogView::setText(const String &strLine)
{
if(!mListBox.isOkay())return;
mMutex.requestMutex();
if(LB_ERR==mListBox->insertString(strLine)){clear();mListBox->insertString(strLine);}
mListBox->setCurrent(mListBox->getCount()-1);
mMutex.releaseMutex();
}
DWORD LogView::getText(Block<String> &strLines)
{
String strLine;
DWORD lineCount;
strLines.remove();
if(!mListBox.isOkay())return FALSE;
mMutex.requestMutex();
lineCount=mListBox->getCount();
for(int index=0;index<lineCount;index++)
{
mListBox->getText(strLine,index);
strLines.insert(&strLine);
}
mMutex.releaseMutex();
return strLines.size();
}
void LogView::clear(void)
{
if(!mListBox.isOkay())return;
mMutex.requestMutex();
mListBox->setRedraw(FALSE);
mListBox->resetContent();
mListBox->setRedraw(TRUE);
mMutex.releaseMutex();
}
void LogView::print(void)
{
PrintManager printManager;
String strPrinter;
Block<String> pageLines;
Font pageFont("Helv",36);
if(!printManager.choosePrinter((GUIWindow&)(*getFrame()),strPrinter))return;
if(!printManager.openPrinter(strPrinter,*this,"NewsCrawler Log"))return;
mStatusBar->setText("Sending document to printer...");
getText(pageLines);
if(!pageLines.size())return;
printManager.printLines(pageLines,pageFont,Point(10,10));
printManager.endDoc();
mStatusBar->setText(" ");
}
// *** virtuals
void LogView::preRegister(WNDCLASS &wndClass)
{
}
void LogView::preCreate(MDICREATESTRUCT &/*createStruct*/)
{
}