00001 #include "bcbutton.h"
00002 #include "bcdisplayinfo.h"
00003 #include "bcprogress.h"
00004 #include "bcprogressbox.h"
00005 #include "bcresources.h"
00006 #include "bctitle.h"
00007 #include "bcwindow.h"
00008 #include "vframe.h"
00009
00010 BC_ProgressBox::BC_ProgressBox(int x, int y, char *text, int64_t length)
00011 : Thread()
00012 {
00013 set_synchronous(1);
00014
00015
00016 if(x < 0 || y < 0)
00017 {
00018 BC_DisplayInfo display_info;
00019 x = display_info.get_abs_cursor_x();
00020 y = display_info.get_abs_cursor_y();
00021 }
00022
00023 pwindow = new BC_ProgressWindow(x, y);
00024 pwindow->create_objects(text, length);
00025 cancelled = 0;
00026 }
00027
00028 BC_ProgressBox::~BC_ProgressBox()
00029 {
00030 delete pwindow;
00031 }
00032
00033 void BC_ProgressBox::run()
00034 {
00035 int result = pwindow->run_window();
00036 if(result) cancelled = 1;
00037 }
00038
00039 int BC_ProgressBox::update(int64_t position, int lock_it)
00040 {
00041 if(!cancelled)
00042 {
00043 if(lock_it) pwindow->lock_window("BC_ProgressBox::update");
00044 pwindow->bar->update(position);
00045 if(lock_it) pwindow->unlock_window();
00046 }
00047 return cancelled;
00048 }
00049
00050 int BC_ProgressBox::update_title(char *title, int lock_it)
00051 {
00052 if(lock_it) pwindow->lock_window("BC_ProgressBox::update_title");
00053 pwindow->caption->update(title);
00054 if(lock_it) pwindow->unlock_window();
00055 return cancelled;
00056 }
00057
00058 int BC_ProgressBox::update_length(int64_t length, int lock_it)
00059 {
00060 if(lock_it) pwindow->lock_window("BC_ProgressBox::update_length");
00061 pwindow->bar->update_length(length);
00062 if(lock_it) pwindow->unlock_window();
00063 return cancelled;
00064 }
00065
00066
00067 int BC_ProgressBox::is_cancelled()
00068 {
00069 return cancelled;
00070 }
00071
00072 int BC_ProgressBox::stop_progress()
00073 {
00074 pwindow->set_done(0);
00075 Thread::join();
00076 return 0;
00077 }
00078
00079 void BC_ProgressBox::lock_window()
00080 {
00081 pwindow->lock_window("BC_ProgressBox::lock_window");
00082 }
00083
00084 void BC_ProgressBox::unlock_window()
00085 {
00086 pwindow->unlock_window();
00087 }
00088
00089
00090
00091 BC_ProgressWindow::BC_ProgressWindow(int x, int y)
00092 : BC_Window("Progress",
00093 x,
00094 y,
00095 340,
00096 100 + get_resources()->ok_images[0]->get_h(),
00097 0,
00098 0,
00099 0)
00100 {
00101 }
00102
00103 BC_ProgressWindow::~BC_ProgressWindow()
00104 {
00105 }
00106
00107 int BC_ProgressWindow::create_objects(char *text, int64_t length)
00108 {
00109 int x = 10, y = 10;
00110
00111
00112 if(text)
00113 {
00114 int text_w = get_text_width(MEDIUMFONT, text);
00115 int new_w = text_w + x + 10;
00116
00117 if(new_w > get_root_w()) new_w = get_root_w();
00118 if(new_w > get_w())
00119 {
00120 resize_window(new_w, get_h());
00121 }
00122 }
00123
00124 this->text = text;
00125 add_tool(caption = new BC_Title(x, y, text));
00126 y += caption->get_h() + 20;
00127 add_tool(bar = new BC_ProgressBar(x, y, get_w() - 20, length));
00128 add_tool(new BC_CancelButton(this));
00129
00130 return 0;
00131 }