4 * Copyright (C) 2008 Adam Williams <broadcast at earthling dot net>
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation; either version 2 of the License, or
9 * (at your option) any later version.
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
16 * You should have received a copy of the GNU General Public License
17 * along with this program; if not, write to the Free Software
18 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
23 #include "bcdisplayinfo.h"
24 #include "bcprogress.h"
25 #include "bcprogressbox.h"
26 #include "bcresources.h"
32 BC_ProgressBox::BC_ProgressBox(int x, int y, const char *text, int64_t length)
35 // Calculate default x, y
38 BC_DisplayInfo display_info;
39 x = display_info.get_abs_cursor_x();
40 y = display_info.get_abs_cursor_y();
41 // preloads boarder data (if not already loaded)
42 // without reopening display, also avoids a bug in X
43 display_info.get_top_border();
46 pwindow = new BC_ProgressWindow(x, y);
47 pwindow->create_objects(text, length);
51 BC_ProgressBox::~BC_ProgressBox()
57 void BC_ProgressBox::run()
59 int result = pwindow->run_window();
60 if(result) cancelled = 1;
63 int BC_ProgressBox::update(int64_t position, int lock_it)
67 if(lock_it) pwindow->lock_window("BC_ProgressBox::update");
68 pwindow->bar->update(position);
69 if(lock_it) pwindow->unlock_window();
74 int BC_ProgressBox::update_title(const char *title, int lock_it)
76 if(lock_it) pwindow->lock_window("BC_ProgressBox::update_title");
77 pwindow->caption->update(title);
78 if(lock_it) pwindow->unlock_window();
82 int BC_ProgressBox::update_length(int64_t length, int lock_it)
84 if(lock_it) pwindow->lock_window("BC_ProgressBox::update_length");
85 pwindow->bar->update_length(length);
86 if(lock_it) pwindow->unlock_window();
91 int BC_ProgressBox::is_cancelled()
96 int BC_ProgressBox::stop_progress()
98 if( Thread::running() ) {
105 void BC_ProgressBox::lock_window()
107 pwindow->lock_window("BC_ProgressBox::lock_window");
110 void BC_ProgressBox::unlock_window()
112 pwindow->unlock_window();
117 BC_ProgressWindow::BC_ProgressWindow(int x, int y)
118 : BC_Window(_("Progress"),
119 x, y, xS(340), yS(100) + get_resources()->ok_images[0]->get_h(),
124 BC_ProgressWindow::~BC_ProgressWindow()
128 int BC_ProgressWindow::create_objects(const char *text, int64_t length)
130 int x = xS(10), y = yS(10);
131 lock_window("BC_ProgressWindow::create_objects");
132 // Recalculate width based on text
135 int text_w = get_text_width(MEDIUMFONT, text);
136 int new_w = text_w + x + xS(10), scr_w = get_screen_w(0, -1);
137 if(new_w > scr_w) new_w = scr_w;
138 if(new_w > get_w()) {
139 resize_window(new_w, get_h());
144 add_tool(caption = new BC_Title(x, y, text));
145 y += caption->get_h() + yS(20);
146 add_tool(bar = new BC_ProgressBar(x, y, get_w() - xS(20), length));
147 add_tool(new BC_CancelButton(this));