00001
00002
00003
00004
00005 #include "MFCBase.h"
00006 #include "LogWndFrame.h"
00007 #include "MessageBoxDLG.h"
00008
00009
00010 #ifdef _DEBUG
00011 #define new DEBUG_NEW
00012 #undef THIS_FILE
00013 static char THIS_FILE[] = __FILE__;
00014 #endif
00015
00016
00017 using namespace jbxl;
00018 using namespace jbxwl;
00019
00020
00022
00023
00024 IMPLEMENT_DYNCREATE(CLogWndFrame, CExTextFrame)
00025
00026 CLogWndFrame::CLogWndFrame()
00027 {
00028
00029
00030 pDoc = NULL;
00031 pView = NULL;
00032 pApp = NULL;
00033 }
00034
00035
00036
00037 CLogWndFrame::~CLogWndFrame()
00038 {
00039 DEBUG_INFO("DESTRUCTOR: CLogWndFrame: START\n");
00040
00041 DEBUG_INFO("DESTRUCTOR: CLogWndFrame: END\n");
00042 }
00043
00044
00045 BEGIN_MESSAGE_MAP(CLogWndFrame, CExTextFrame)
00046
00047 ON_COMMAND(ID_LOG_COPY, OnLogCopy)
00048 ON_COMMAND(ID_LOG_SAVE, OnLogSave)
00049 ON_COMMAND(ID_LOG_CLEAR, OnLogClear)
00050 ON_WM_CREATE()
00051
00052
00053 END_MESSAGE_MAP()
00054
00055
00056
00058
00059
00060 int CLogWndFrame::OnCreate(LPCREATESTRUCT lpCreateStruct)
00061 {
00062 if (CExTextFrame::OnCreate(lpCreateStruct) == -1) return -1;
00063
00064
00065
00066 toolBar = new CExToolBar();
00067 if (!toolBar->CreateEx(this, TBSTYLE_FLAT, WS_CHILD | WS_VISIBLE | CBRS_TOP
00068 | CBRS_GRIPPER | CBRS_TOOLTIPS | CBRS_FLYBY | CBRS_SIZE_DYNAMIC | WS_CLIPCHILDREN) ||
00069 !toolBar->LoadToolBar(IDR_LOG_WND_TOOLBAR))
00070 {
00071 TRACE0("Failed to create toolbar\n");
00072 return -1;
00073 }
00074
00075
00076 toolBar->EnableDocking(CBRS_ALIGN_ANY);
00077 EnableDocking(CBRS_ALIGN_ANY);
00078 DockControlBar(toolBar);
00079
00080 return 0;
00081 }
00082
00083
00084
00085 void CLogWndFrame::OnLogCopy()
00086 {
00087 CString data = pView->getCopyData();
00088
00089 char* mbstr = ts2mbs((LPCTSTR)data);
00090 int size = (int)strlen(mbstr);
00091 if (size<=0) {
00092 ::free(mbstr);
00093 return;
00094 }
00095
00096 HGLOBAL hMem = ::GlobalAlloc(GHND, size+1);
00097 char* pszptr = (char*)::GlobalLock(hMem);
00098 memcpy(pszptr, mbstr, size+1);
00099 ::GlobalUnlock(hMem);
00100 ::free(mbstr);
00101
00102 if (!OpenClipboard()) {
00103 ::GlobalFree(hMem);
00104 DEBUG_ERROR("CLogWndFrame::OnLogCopy(): ERROR: Clipboad open error!!\n");
00105 return;
00106 }
00107
00108 EmptyClipboard();
00109 SetClipboardData(CF_TEXT, hMem);
00110 CloseClipboard();
00111 ::GlobalFree(hMem);
00112
00113 return;
00114 }
00115
00116
00117
00118 void CLogWndFrame::OnLogSave()
00119 {
00120 if (pDoc->save_fname==_T("")) {
00121 CString mesg;
00122 mesg.LoadString(IDS_STR_SPECIFY_SAVE_FILE);
00123 pDoc->save_fname = pDoc->easyGetSaveFileName(mesg, pView->m_hWnd);
00124 }
00125 if (pDoc->save_fname==_T("")) return;
00126 int ret = pDoc->writeLogFile();
00127
00128 if (ret<0) MessageBoxDLG(IDS_STR_ERROR, IDS_STR_ERR_WRITE_FILE, MB_OK, NULL);
00129 }
00130
00131
00132
00133 void CLogWndFrame::OnLogClear()
00134 {
00135 CString mesg, noti;
00136 mesg.LoadString(IDS_STR_ASK_LOG_CLEAR);
00137 noti.LoadString(IDS_STR_CNFRM);
00138 int ret = MessageBox(mesg, noti, MB_YESNO | MB_ICONQUESTION);
00139 if (ret==IDYES) pView->clearViewDoc();
00140 }
00141
00142
00143
00144
00146
00147
00148 CLogWndFrame* jbxwl::ExecLogWnd(CMultiDocTemplate* pDocTempl, LPCTSTR title, CAppCallBack* app)
00149 {
00150
00151 CLogWndDoc* pdoc = (CLogWndDoc*)pDocTempl->CreateNewDocument();
00152 CLogWndFrame* pfrm = (CLogWndFrame*)pDocTempl->CreateNewFrame((CDocument*)pdoc, NULL);
00153 CLogWndView* pviw = pdoc->GetView();
00154 pfrm->pTempl = pDocTempl;
00155
00156 if (pdoc==NULL || pfrm==NULL || pviw==NULL) return NULL;
00157
00158 pdoc->pView = pfrm->pView = pviw;
00159 pdoc->pFrame = pviw->pFrame = pfrm;
00160 pviw->pDoc = pfrm->pDoc = pdoc;
00161 pfrm->pApp = pviw->pApp = app;
00162 pfrm->Title = title;
00163
00164 pfrm->CExTextFrame::pView = (CExTextView*) pviw;
00165 pfrm->CExTextFrame::pDoc = (CDocument*) pdoc;
00166 pviw->CExTextView::pFrame = (CExTextFrame*)pfrm;
00167 pviw->CExTextView::pDoc = (CDocument*) pdoc;
00168
00169
00170 pfrm->ShowWindow(SW_SHOW);
00171 pfrm->SetFocus();
00172 pfrm->pView->SetFocus();
00173
00174 if (!pfrm->Title.IsEmpty()) {
00175 pfrm->pView->SetTitle(pfrm->Title);
00176 }
00177
00178 return pfrm;
00179 }
00180
00181