OSDN Git Service

The text edit in MyListCtrl seems weird. Hopefully fixed.
[molby/Molby.git] / wxSources / ProgressFrame.cpp
1 /*
2  *  ProgressFrame.cpp
3  *  Molby
4  *
5  *  Created by Toshi Nagata on 09/07/15.
6  *  Copyright 2009 Toshi Nagata. All rights reserved.
7  *
8  This program is free software; you can redistribute it and/or modify
9  it under the terms of the GNU General Public License as published by
10  the Free Software Foundation version 2 of the License.
11  
12  This program is distributed in the hope that it will be useful,
13  but WITHOUT ANY WARRANTY; without even the implied warranty of
14  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
15  GNU General Public License for more details.
16  */
17
18 #include "ProgressFrame.h"
19 #include "MyApp.h"
20
21 #include "wx/stattext.h"
22 #include "wx/gauge.h"
23 #include "wx/sizer.h"
24
25 #if __WXMAC__
26 #include <Carbon/Carbon.h>
27 #endif
28
29 BEGIN_EVENT_TABLE(ProgressFrame, wxFrame)
30 //    EVT_TEXT_ENTER(-1, ConsoleFrame::OnEnterPressed)
31 //      EVT_CHAR(ConsoleFrame::OnChar)
32 //      EVT_RICHTEXT_RETURN(-1, ConsoleFrame::OnEnterPressed)
33 END_EVENT_TABLE()
34
35 ProgressFrame::ProgressFrame(const wxString &title, const wxString &mes):
36         wxFrame(NULL, wxID_ANY, title, wxDefaultPosition, wxDefaultSize, wxCAPTION)
37 {
38         //  Vertical sizer containing (1) message text, (2) progress gauge, (3) note text
39         wxBoxSizer *sizer = new wxBoxSizer(wxVERTICAL);
40         
41         m_messageText = new wxStaticText(this, -1, wxT("Message"), wxDefaultPosition, wxSize(240, 40), wxST_NO_AUTORESIZE);
42         sizer->Add(m_messageText, 0, wxALL | wxEXPAND, 10);   // Can expand horizontally
43         
44         m_progressGauge = new wxGauge(this, -1, 10000, wxDefaultPosition, wxSize(240, 24), wxGA_HORIZONTAL);
45         sizer->Add(m_progressGauge, 0, wxALL | wxEXPAND, 10);
46         
47         wxStaticText *noteText = new wxStaticText(this, -1, wxT("Press ESC to interrupt"), wxDefaultPosition, wxSize(240, 20), wxALIGN_CENTRE | wxST_NO_AUTORESIZE);
48 /*      wxFont smallFont(noteText->GetFont());
49         int size = smallFont.GetPointSize();
50         if (size >= 14)
51                 size = 12;
52         else if (size >= 12)
53                 size = 10;
54         else if (size >= 10)
55                 size = 9;
56         smallFont.SetPointSize(size);
57         noteText->SetFont(smallFont); */
58         noteText->SetFont(*wxSMALL_FONT);
59         sizer->Add(noteText, 0, wxALL | wxEXPAND, 10);
60
61         m_value = -1.0;
62         m_progressGauge->Pulse();
63         m_messageText->SetLabel(mes);
64         
65         m_interruptValue = 0;
66
67         sizer->Layout();
68         this->SetSizerAndFit(sizer);
69         this->Centre();
70         this->Show();
71         
72 #if __WXMAC__
73 //      ::SetWindowModality(((WindowRef)MacGetWindowRef()), kWindowModalityAppModal, NULL);
74 #endif
75 }
76
77 ProgressFrame::~ProgressFrame()
78 {
79 }
80
81 void
82 ProgressFrame::SetProgressMessage(const wxString &mes)
83 {
84         m_messageText->SetLabel(mes);
85         if (m_value < 0)
86                 m_progressGauge->Pulse();
87         Update();
88 }
89
90 void
91 ProgressFrame::SetProgressValue(double value)
92 {
93         m_value = value;
94         if (value < 0)
95                 m_progressGauge->Pulse();
96         else
97                 m_progressGauge->SetValue((int)(value * 10000));
98         Update();
99 }
100
101 void
102 ProgressFrame::SetInterruptValue(int value)
103 {
104         m_interruptValue = value;
105 }
106
107 int
108 ProgressFrame::CheckInterrupt()
109 {
110         if (this != NULL && m_interruptValue) {
111                 int save = m_interruptValue;
112                 m_interruptValue = 0;
113                 return save;
114         }
115
116 #if __WXMAC__
117         ::wxYield();
118 #else
119         {
120                 wxWindow *activeWin = NULL;
121                 if (this != NULL)
122                         activeWin = this;
123                 // else
124                 //      activeWin = GetMainFrame()->GetActiveChild();
125                 ::wxSafeYield(activeWin);
126         }
127 #endif
128         if (::wxGetKeyState(WXK_ESCAPE))
129                 return 1;
130         else return 0;
131 }