00001 #include <gui/MessageBox.h>
00002 #include <gui/MessageQueue.h>
00003 #include <gui/Button.h>
00004 #include <gui/TextView.h>
00005 #include <gui/TopView.h>
00006 #include <gui/Exceptions.h>
00007 #include <gui/Window.h>
00008 #include <gui/StringView.h>
00009 #include <gui/ApplicationWindow.h>
00010 #include <gui/Application.h>
00011 #include <gui/Menu.h>
00012 #include <gui/StatusBar.h>
00013 #include <gui/CheckBox.h>
00014 #include <os/Thread.h>
00015 #include <os/Time.h>
00016 #include <os/Clipboard.h>
00017 #include <iostream>
00018
00019 using namespace SkyGI;
00020
00021 #define ID_ADD 10000
00022
00023 class MyThread : public Thread
00024 {
00025 public:
00026 MyThread(TextView *pTextView, const String& szName);
00027 int Run();
00028
00029 TextView *m_pTextView;
00030 };
00031
00032 MyThread::MyThread(TextView *pTextView, const String& szName) : Thread(szName)
00033 {
00034 m_pTextView = pTextView;
00035 }
00036
00037 int MyThread::Run()
00038 {
00039 int i=0;
00040 char str[255];
00041
00042 while (1)
00043 {
00044 i++;
00045 sprintf(str, "%d", i);
00046
00047 m_pTextView->Set(str);
00048 ThreadSleep(10);
00049
00050 m_pTextView->GetTop()->SetTitle(str);
00051 }
00052 return 0;
00053 }
00054
00055 class MyThreadTest : public View
00056 {
00057 public:
00058 MyThreadTest(Window *pParent, const Rect &rFrame, unsigned int nWindowLayoutFlags);
00059 ~MyThreadTest();
00060
00061 void OnChange();
00062
00063 void RunThread1(bool bRun);
00064 void RunThread2(bool bRun);
00065
00066 TextView *pThread1View;
00067 TextView *pThread2View;
00068
00069 Thread *pThread1;
00070 Thread *pThread2;
00071 };
00072
00073 MyThreadTest::~MyThreadTest()
00074 {
00075 pThread1->Kill();
00076 pThread2->Kill();
00077
00078 pThread1->WaitFor();
00079 pThread2->WaitFor();
00080 }
00081
00082 void MyThreadTest::RunThread1(bool bRun)
00083 {
00084 if (bRun)
00085 pThread1->Start();
00086 else
00087 pThread1->Stop();
00088 }
00089
00090 void MyThreadTest::RunThread2(bool bRun)
00091 {
00092 if (bRun)
00093 pThread2->Start();
00094 else
00095 pThread2->Stop();
00096 }
00097
00098
00099 MyThreadTest::MyThreadTest(Window *pParent, const Rect &rFrame, unsigned int nWindowLayoutFlags) : View(pParent, rFrame, nWindowLayoutFlags)
00100 {
00101 StringView *pStringView;
00102
00103 pStringView = new StringView(this, Rect(), "Thread1:", 0);
00104 pStringView->SetRect(Point(10, 10), pStringView->GetPreferredSize());
00105
00106 pThread1View = new TextView(this, Rect(10, 30, 200, 50), WINDOW_LAYOUT_FOLLOW_RIGHT , TEXTVIEW_FLAG_SINGLE_LINE);
00107 pThread1View->SetFocus();
00108
00109 pStringView = new StringView(this, Rect(), "Thread2:", 0);
00110 pStringView->SetRect(Point(10, 60), pStringView->GetPreferredSize());
00111
00112 pThread2View = new TextView(this, Rect(10, 80, 200, 100), WINDOW_LAYOUT_FOLLOW_RIGHT , TEXTVIEW_FLAG_SINGLE_LINE);
00113
00114 CheckBox *pCheckBox = new CheckBox(this, Rect(220, 30, 400, 50), "Run", WINDOW_LAYOUT_FOLLOW_H);
00115 pCheckBox->Changed.Connect(this, &MyThreadTest::RunThread1);
00116
00117 pCheckBox = new CheckBox(this, Rect(220, 80, 400, 100), "Run", WINDOW_LAYOUT_FOLLOW_H);
00118 pCheckBox->Changed.Connect(this, &MyThreadTest::RunThread2);
00119
00120 pThread1 = new MyThread(pThread1View, "Thread1");
00121 pThread2 = new MyThread(pThread2View, "Thread2");
00122 }
00123
00124 void ThreadTest()
00125 {
00126 Rect r(Point(100, 100), Point(400, 440));
00127
00128 ApplicationWindow* pApplicationWindow = new ApplicationWindow(r, "Threads", WINDOW_LAYOUT_NOTHING, APPLICATION_WINDOW_NO_VIEW);
00129
00130 pApplicationWindow->GetTitleWindow()->SetFlags( (TitleWindowFlags)(pApplicationWindow->GetTitleWindow()->GetFlags() ));
00131 pApplicationWindow->AttachView(new MyThreadTest(pApplicationWindow, pApplicationWindow->GetClientRect(), WINDOW_LAYOUT_NOTHING));
00132 pApplicationWindow->Show();
00133 }
00134