📄 mdi.cpp
字号:
for (i = 0; i < 8; i++) delete bitmaps[i];}// ---------------------------------------------------------------------------// MyCanvas// ---------------------------------------------------------------------------// Define a constructor for my canvasMyCanvas::MyCanvas(wxWindow *parent, const wxPoint& pos, const wxSize& size) : wxScrolledWindow(parent, -1, pos, size, wxSUNKEN_BORDER | wxVSCROLL | wxHSCROLL){ ;}void MyCanvas::DrawChild(wxDC& dc, wxCoord x, wxCoord y, wxCoord width, wxCoord height,MonthDataElem*pchild){ wxDouble total=0; for ( childvalueList::Node *node = pchild->children.GetFirst(); node; node = node->GetNext() ) { childvalueElem*current = node->GetData(); total += current->value; } if (total==0) return; wxDouble start=0; for ( childvalueList::Node *node = pchild->children.GetFirst(); node; node = node->GetNext() ) { childvalueElem*current = node->GetData(); if (current->value==0) continue; ColourDescList::Node *node = mycolors.Item(current->valuetype); ColourDescElem *colordesc = node->GetData(); dc.SetBrush(*colordesc->color); wxDouble currange = (current->value / total) * 360; dc.DrawEllipticArc(x,y,width,height,start,start+currange); start+=currange; }}// Define the repainting behaviourvoid MyCanvas::OnDraw(wxDC& dc){ //Erase BackGround int Width,Height; GetSize(&Width,&Height); dc.SetBrush(*wxWHITE_BRUSH); dc.DrawRectangle(0,0,Width,Height); //Get Max Value and Min value; bool initMaxValue=TRUE,initMinValue=TRUE,initMaxMonth=TRUE,initMinMonth=TRUE; wxDouble MaxValue,MinValue; wxDateTime MaxMonth,MinMonth; if (valuelist.GetCount()<=1) return; for ( MonthDataList::Node *node = valuelist.GetFirst(); node; node = node->GetNext() ) { MonthDataElem *current = node->GetData(); if ((initMaxValue)||(current->value>MaxValue)) { initMaxValue=FALSE; MaxValue = current->value; } if ((initMinValue)||(current->value<MaxValue)) { initMinValue=FALSE; MinValue = current->value; } if ((initMaxMonth)||(current->thedate>MaxMonth)) { initMaxMonth=FALSE; MaxMonth= current->thedate; } if ((initMinMonth)||(current->value<MaxMonth)) { initMinMonth=FALSE; MinMonth= current->thedate; } } //caculate delta value wxDouble deltaValue = MaxValue; if (deltaValue==0) deltaValue =1; wxInt32 deltaMonth = valuelist.GetCount() + 1; #define CHART_DELTA_WIDTH 30 #define CHART_DELTA_HEIGHT 30 #define CHART_RIGHT_MORE_WIDTH 100 #define CHART_TOP_MORE_HEIGHT 100 #define CHART_LEFT_MORE_WIDTH 30 #define CHART_BUTTOM_MORE_HEIGHT 100 #define CHART_CHILD_RADIO 30 //calc delta width and delta height. wxInt16 DeltaWidth=CHART_DELTA_WIDTH; wxDouble DeltaHeight=CHART_DELTA_HEIGHT; DeltaWidth = (Width - CHART_RIGHT_MORE_WIDTH - CHART_LEFT_MORE_WIDTH) / deltaMonth; if (deltaValue==0) { DeltaHeight = Height - CHART_TOP_MORE_HEIGHT - CHART_BUTTOM_MORE_HEIGHT; } else { DeltaHeight =(Height - CHART_TOP_MORE_HEIGHT - CHART_BUTTOM_MORE_HEIGHT) / deltaValue; } //draw chat example int csx1 = Width - CHART_RIGHT_MORE_WIDTH; int csy1 = CHART_TOP_MORE_HEIGHT; for ( ColourDescList::Node *node = mycolors.GetFirst(); node; node = node->GetNext() ) { ColourDescElem *colordesc = node->GetData(); dc.SetBrush(*colordesc->color); int csdeltawidth = 10; int csdeltaheight = dc.GetCharHeight(); dc.DrawRectangle(csx1,csy1,csdeltawidth,csdeltaheight); dc.DrawText(colordesc->desc, csx1 + csdeltawidth + 5,csy1); csy1 += csdeltaheight; } //Draw X,Y dc.SetPen(*wxBLACK_PEN); dc.DrawLine(CHART_LEFT_MORE_WIDTH, 0, CHART_LEFT_MORE_WIDTH, (int)(deltaValue * DeltaHeight + CHART_TOP_MORE_HEIGHT + CHART_BUTTOM_MORE_HEIGHT)); dc.DrawLine(0, (int)(deltaValue * DeltaHeight + CHART_TOP_MORE_HEIGHT) , (int)(deltaMonth * DeltaWidth+ CHART_LEFT_MORE_WIDTH + CHART_RIGHT_MORE_WIDTH), (int)(deltaValue * DeltaHeight + CHART_TOP_MORE_HEIGHT) ); MonthDataList::Node *node = valuelist.GetFirst(); MonthDataElem *current = node->GetData(); wxDouble svalue = current->value; wxDateTime sdatevalue = current->thedate; wxInt16 sdate = valuelist.IndexOf(current); int x1,y1,x2,y2; x1 = (int)(CHART_LEFT_MORE_WIDTH + (sdate) * DeltaWidth); y1 = (int)((deltaValue - svalue) * DeltaHeight + CHART_TOP_MORE_HEIGHT); wxString tmp = wxString::Format(_("$%.2f"),svalue); wxString tmp1 = wxString::Format(_("%04d.%02d"),sdatevalue.GetYear(),sdatevalue.GetMonth()+1); dc.DrawText(tmp, x1, y1); dc.DrawText(tmp1, x1, y1 + dc.GetCharHeight()); int radio = (int)(DeltaWidth / 2); DrawChild(dc,x1,y1 + 2*dc.GetCharHeight(),radio,radio,current); //loop draw line for (node = node->GetNext(); node; node = node->GetNext() ) { current = node->GetData(); wxDouble dvalue = current->value; wxInt16 ddate = valuelist.IndexOf(current); wxDateTime ddatevalue = current->thedate; x1 = CHART_LEFT_MORE_WIDTH + (sdate) * DeltaWidth; y1 = (int)((deltaValue - svalue) * DeltaHeight + CHART_TOP_MORE_HEIGHT); x2 = CHART_LEFT_MORE_WIDTH + (ddate) * DeltaWidth; y2 = (int)((deltaValue - dvalue) * DeltaHeight + CHART_TOP_MORE_HEIGHT); tmp.assign(wxString::Format(_("$%.2f"),dvalue)); tmp1.assign(wxString::Format(_("%04d.%02d"),ddatevalue.GetYear(),ddatevalue.GetMonth()+1)); dc.DrawText(tmp, x2, y2); dc.DrawText(tmp1, x2, y2 + dc.GetCharHeight()); DrawChild(dc,x2,y2 + 2*dc.GetCharHeight(),radio,radio,current); dc.DrawLine(x1,y1,x2,y2); svalue = dvalue; sdate = ddate; } //draw title wxCoord titlew,titlwh; dc.GetTextExtent(title,&titlew,&titlwh); dc.DrawText(title, (Width - titlew)/2, (CHART_TOP_MORE_HEIGHT - titlwh)/2); }// This implements a tiny doodling program! Drag the mouse using the left// button.void MyCanvas::OnEvent(wxMouseEvent& event){ wxClientDC dc(this); PrepareDC(dc); wxPoint pt(event.GetLogicalPosition(dc)); if (xpos > -1 && ypos > -1 && event.Dragging()) { dc.SetPen(*wxBLACK_PEN); dc.DrawLine(xpos, ypos, pt.x, pt.y); } xpos = pt.x; ypos = pt.y;}// ---------------------------------------------------------------------------// MyChild// ---------------------------------------------------------------------------MyChild::MyChild(wxMDIParentFrame *parent, const wxString& title, const wxPoint& pos, const wxSize& size, const long style) : wxMDIChildFrame(parent, -1, title, pos, size, style | wxNO_FULL_REPAINT_ON_RESIZE){ // Give it an icon#ifdef __WXMSW__ SetIcon(wxIcon(_T("chrt_icn")));#else SetIcon(wxIcon( mondrian_xpm ));#endif canvas = NULL; int width, height; GetClientSize(&width, &height); canvas = new MyCanvas(this, wxPoint(0, 0), wxSize(width, height)); canvas->SetCursor(wxCursor(wxCURSOR_PENCIL)); frame->CreateMainMenu(this); // this should work for MDI frames as well as for normal ones SetSizeHints(100, 100);}MyChild::~MyChild(){}void MyChild::OnQuit(wxCommandEvent& WXUNUSED(event)){ Close(TRUE);}void MyChild::OnRefresh(wxCommandEvent& WXUNUSED(event)){ if ( canvas ) canvas->Refresh();}void MyChild::OnChangePosition(wxCommandEvent& WXUNUSED(event)){ Move(10, 10);}void MyChild::OnChangeSize(wxCommandEvent& WXUNUSED(event)){ SetClientSize(100, 100);}void MyChild::OnChangeTitle(wxCommandEvent& WXUNUSED(event)){//#if wxUSE_TEXTDLG static wxString s_title = _("Canvas Frame"); wxString title = wxGetTextFromUser(_("Enter the new title for MDI child"), _("MDI sample question"), s_title, GetParent()->GetParent()); if ( !title ) return; s_title = title; SetTitle(s_title);//#endif}void MyChild::OnActivate(wxActivateEvent& event){ if ( event.GetActive() && canvas ) canvas->SetFocus();}void MyChild::OnMove(wxMoveEvent& event){ event.Skip();}void MyChild::OnSize(wxSizeEvent& event){ event.Skip();}void MyChild::OnClose(wxCloseEvent& event){ event.Skip();}MyGridFrame::MyGridFrame(wxMDIParentFrame *parent, const wxString& title, const wxPoint& pos, const wxSize& size, const long style) : wxMDIChildFrame(parent, -1, title, pos, size, style | wxNO_FULL_REPAINT_ON_RESIZE ){ EnableAutoModify = FALSE; my_children.Append(this); totalValue=0; recheight = 20; colwidth[0] = 70, colwidth[1] = 70, colwidth[2] = 100, m_text1 = new wxTextCtrl(this, MTEXT_1, wxDateTime::Today().FormatISODate().c_str(), wxPoint(30, 0), wxSize(70, 20), wxSIMPLE_BORDER | wxTE_CENTER | wxTE_PROCESS_TAB | wxTE_PROCESS_ENTER); m_text2 = new wxTextCtrl(this, MTEXT_2, _("20.58"), wxPoint(100, 0), wxSize(70, 20), wxSIMPLE_BORDER | wxTE_CENTER | wxTE_PROCESS_TAB | wxTE_PROCESS_ENTER ); m_text3 = new wxTextCtrl(this, MTEXT_3, _("Fill here the memo of this acount"), wxPoint(170, 0), wxSize(100, 20), wxSIMPLE_BORDER | wxTE_PROCESS_ENTER); frame->CreateMainMenu(this); grid = new wxGrid( this, -1, wxPoint( 0, 20), wxSize( 400, 300 ),wxSIMPLE_BORDER |wxWANTS_CHARS); grid->SetDefaultCellAlignment(wxALIGN_CENTRE,wxALIGN_CENTRE); grid->CreateGrid(1, 3); grid->SetCellSize(0, 0, 1, 2); grid->SetCellAlignment(0, 2, wxALIGN_LEFT, wxALIGN_CENTRE); grid->SetCellValue(0, 2, _("Total In Grid!")); grid->SetReadOnly(0,0,TRUE); grid->SetReadOnly(0,2,TRUE); grid->SetRowLabelSize(30); grid->SetColLabelSize(0); grid->SetColSize(0, 70); grid->SetColSize(1, 70); m_text1->SetFocus(); wxAcceleratorEntry entries[4]; entries[0].Set(wxACCEL_NORMAL, WXK_UP, NORMAL_UP_ID); entries[1].Set(wxACCEL_NORMAL, WXK_DOWN, NORMAL_DOWN_ID); entries[2].Set(wxACCEL_NORMAL, WXK_F3, VIEW_MONTH_OUT); entries[3].Set(wxACCEL_NORMAL, WXK_TAB, NORMAL_TAB_ID); wxAcceleratorTable accel(4, entries); SetAcceleratorTable(accel); }MyGridFrame::~MyGridFrame(){ gridobject.DeleteContents(TRUE); my_children.DeleteObject(this);}void MyGridFrame::UpdateUIBaseOnSize(){ int width,height; GetClientSize(&width,&height); colwidth[2] = width-30-colwidth[0]-colwidth[1]-10; m_text1->Move(30,0); m_text1->SetSize(colwidth[0],recheight); m_text2->Move(colwidth[0]+30,0); m_text2->SetSize(colwidth[1],recheight); m_text3->Move(colwidth[0]+colwidth[1]+30,0); m_text3->SetSize(colwidth[2],recheight); for (int i=0; i<3;i++) { grid->SetColSize(i, colwidth[i]); } grid->Move(0,recheight); grid->SetDefaultRowSize(recheight, TRUE); grid->SetSize(width,height-recheight); grid->ForceRefresh();}void MyGridFrame::UpdateStatusBar(){ grid->SetCellValue(0, 0, wxString::Format(_("Current Total:%.2f"),totalValue)); frame->UpdateStatusBar();}wxDouble MyGridFrame::GetTotalFromUi(){ wxDouble ret=0; for (int i=1; i<grid->GetRows(); i++) { wxDouble db; grid->GetCellValue(i,1).ToDouble(&db); ret += db; } return ret;}void MyGridFrame::OnDeleteRec(wxCommandEvent& WXUNUSED(event)){ wxArrayInt allrows = grid->GetSelectedRows(); if (allrows.Count()>0) { wxMessageDialog dialog( NULL, _("Are you sure you want delete All this record?"), _("Delete records confirm"), wxNO_DEFAULT|wxYES_NO|wxICON_INFORMATION); switch ( dialog.ShowModal() ) { case wxID_YES: break; case wxID_NO: default: return; } int objcnt=gridobject.GetCount(); for (size_t i=allrows.Count()-1;;i--) { int index = allrows.Item(i); if (index==0) break; index--; xmlnodeGNode *dataitem = gridobject.Item(index)->GetData(); frame->moneybook->DeleteRec(dataitem->xmlNode); gridobject.DeleteNode(gridobject.Item(index)); wxString tmp(grid->GetCellValue(index+1,1)); wxDouble db; tmp.ToDouble(&db); totalValue-=db; UpdateStatusBar(); grid->DeleteRows(index+1); //Remove other window's same rec in grid //TODO improve the performance of these few line code. wxNode *node =my_children.GetFirst(); while (node) { MyGridFrame* peerframe = (MyGridFrame*)node->GetData(); if (peerframe==this) { node = node->GetNext(); continue; } MyXmlNodeList::Node *wxxmlnode = peerframe->gridobject.GetFirst(); while (NULL!=wxxmlnode) { xmlnodeGNode *xmlnodec = wxxmlnode->GetData(); if (xmlnodec->xmlNode == dataitem->xmlNode) { peerframe->totalValue-=db; peerframe->UpdateStatusBar(); peerframe->grid->DeleteRows(peerframe->gridobject.IndexOf(xmlnodec)+1); peerframe->gridobject.DeleteNode(wxxmlnode); break; } wxxmlnode =wxxmlnode->GetNext(); } node = node->GetNext(); } delete(dataitem); //loop end here if (i==0) break; } frame->UpdateStatusBar(); } else { wxLogError(_("you should select at least one line!")); }}void MyGridFrame::OnQuit(wxCommandEvent& WXUNUSED(event)){ Close(TRUE);}void MyGridFrame::OnClose(wxCloseEvent& event){ gs_nFrames--; event.Skip();}void MyGridFrame::AddRecToGrid(xmlnodeGNode*nodedata, wxString s1,wxString s2,wxString s3){ wxDateTime thedate; wxDouble db; if ((NULL==thedate.ParseDate(s1.mb_str())) ||(!s2.ToDouble(&db)) ||(s3.IsEmpty())) { wxLogError(_("The format of date or money is error in AddRec!")); return;
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -