+void BC_ScrollTextBox::update_scrollbars()
+{
+ int view_w = w, view_rows = rows;
+ int view_h = BC_TextBox::calculate_row_h(view_rows, parent_window);
+ int text_rows = text->get_text_rows();
+ int text_width = parent_window->get_text_width(text->font, text->get_wtext());
+ BC_Resources *resources = parent_window->get_resources();
+ int need_xscroll = 0, need_yscroll = 0;
+
+// Create scrollbars as needed
+ int resize = 1;
+ while( resize ) {
+ resize = 0;
+ if( !need_xscroll && (text->get_text_x() != text->left_margin ||
+ text_width >= view_w - text->left_margin - text->right_margin) ) {
+ resize = need_xscroll = 1;
+ view_h -= resources->hscroll_data[SCROLL_HANDLE_UP]->get_h();
+ view_rows = BC_TextBox::pixels_to_rows(parent_window, text->font, view_h);
+ }
+ if( !need_yscroll && (text->get_text_y() != text->top_margin ||
+ text_rows > view_rows) ) {
+ resize = need_yscroll = 1;
+ view_w -= resources->vscroll_data[SCROLL_HANDLE_UP]->get_w();
+ }
+ }
+
+ if( !need_xscroll && xscroll ) {
+ text->yscroll = 0;
+ delete xscroll; xscroll = 0;
+ }
+ if( !need_yscroll && yscroll ) {
+ text->yscroll = 0;
+ delete yscroll; yscroll = 0;
+ }
+
+ if( view_rows != text->get_rows() || view_w != text->get_w() ) {
+ text->reposition_window(x, y, view_w, view_rows);
+ }
+ if( need_xscroll && !xscroll ) {
+ xscroll = new BC_ScrollTextBoxXScroll(this);
+ parent_window->add_subwindow(xscroll);
+ text->xscroll = xscroll;
+ xscroll->bound_to = text;
+ xscroll->show_window();
+ }
+ if( need_yscroll && !yscroll ) {
+ yscroll = new BC_ScrollTextBoxYScroll(this);
+ parent_window->add_subwindow(yscroll);
+ text->yscroll = yscroll;
+ yscroll->bound_to = text;
+ yscroll->show_window();
+ }
+ if( xscroll ) {
+ xscroll->reposition_window(x, y + text->get_h(), view_w);
+ int xpos = get_x_pos();
+ if( xpos != xscroll->get_value() )
+ xscroll->update_value(xpos);
+ if( text_width != xscroll->get_length() ||
+ view_w != xscroll->get_handlelength() )
+ xscroll->update_length(text_width, xpos, view_w, 0);
+ }
+ if( yscroll ) {
+ yscroll->reposition_window(x + w - yscroll->get_span(), y, text->get_h());
+ int text_row = text->get_text_row();
+ if( text_row != yscroll->get_value() )
+ yscroll->update_value(text_row);
+ if( text_rows != yscroll->get_length() ||
+ view_rows != yscroll->get_handlelength() )
+ yscroll->update_length(text_rows, text_row, view_rows, 0);
+ }
+}
+