From 4c9fc671be4a343cab4fccd9d7f91e7e67ddda40 Mon Sep 17 00:00:00 2001 From: rakshasa Date: Fri, 28 Jul 2006 00:17:54 +0000 Subject: [PATCH] * Allow Frame's to be located in both rows and columns. Improved min height/width for windows. git-svn-id: svn://rakshasa.no/libtorrent/trunk/rtorrent@748 e378c898-3ddf-0310-93e7-cc216c733640 --- rak/functional.h | 39 ++++++ src/display/canvas.h | 4 +- src/display/frame.cc | 136 ++++++++++++++----- src/display/frame.h | 6 +- src/display/window.cc | 33 +++-- src/display/window.h | 35 +++-- src/display/window_download_chunks_seen.cc | 10 +- src/display/window_download_chunks_seen.h | 4 +- src/display/window_download_list.cc | 8 +- src/display/window_download_list.h | 4 +- src/display/window_download_statusbar.cc | 38 +++--- src/display/window_download_transfer_list.cc | 8 +- src/display/window_download_transfer_list.h | 2 +- src/display/window_file_list.cc | 6 +- src/display/window_http_queue.cc | 4 +- src/display/window_input.cc | 4 +- src/display/window_input.h | 12 +- src/display/window_log.cc | 8 +- src/display/window_log_complete.cc | 6 +- src/display/window_peer_info.cc | 2 +- src/display/window_peer_list.cc | 4 +- src/display/window_statusbar.cc | 6 +- src/display/window_statusbar.h | 4 +- src/display/window_string_list.cc | 12 +- src/display/window_title.cc | 2 +- src/display/window_title.h | 2 +- src/display/window_tracker_list.cc | 24 ++-- src/input/bindings.cc | 2 +- src/input/bindings.h | 8 +- src/input/path_input.cc | 2 + src/input/text_input.cc | 6 +- src/input/text_input.h | 7 +- src/ui/download_list.cc | 79 +++++++---- src/ui/element_chunks_seen.cc | 4 +- src/ui/element_download_list.cc | 1 + src/ui/element_file_list.cc | 4 +- src/ui/element_log_complete.cc | 1 + src/ui/element_transfer_list.cc | 4 +- src/ui/root.cc | 13 +- src/ui/root.h | 2 +- 40 files changed, 363 insertions(+), 193 deletions(-) diff --git a/rak/functional.h b/rak/functional.h index 74fea735..15da5c9e 100644 --- a/rak/functional.h +++ b/rak/functional.h @@ -208,6 +208,24 @@ greater(Type t, Ftor f) { return _greater(t, f); } +template +struct greater2_t : public std::binary_function { + greater2_t(FtorA f_a, FtorB f_b) : m_f_a(f_a), m_f_b(f_b) {} + + bool operator () (typename FtorA::argument_type a, typename FtorB::argument_type b) { + return m_f_a(a) > m_f_b(b); + } + + FtorA m_f_a; + FtorB m_f_b; +}; + +template +inline greater2_t +greater2(FtorA f_a, FtorB f_b) { + return greater2_t(f_a,f_b); +} + template struct less_equal_t { typedef bool result_type; @@ -277,6 +295,27 @@ on(Src s, Dest d) { } // Creates a functor for accessing a member. +template +struct mem_ptr_t : public std::unary_function { + mem_ptr_t(Member Class::*m) : m_member(m) {} + + Member& operator () (Class* c) { + return c->*m_member; + } + + const Member& operator () (const Class* c) { + return c->*m_member; + } + + Member Class::*m_member; +}; + +template +inline mem_ptr_t +mem_ptr(Member Class::*m) { + return mem_ptr_t(m); +} + template struct mem_ptr_ref_t : public std::unary_function { mem_ptr_ref_t(Member Class::*m) : m_member(m) {} diff --git a/src/display/canvas.h b/src/display/canvas.h index 1d5e59f3..9c2ddf67 100644 --- a/src/display/canvas.h +++ b/src/display/canvas.h @@ -61,8 +61,8 @@ public: int get_x() { int x, y; getyx(m_window, y, x); return x; } int get_y() { int x, y; getyx(m_window, y, x); return y; } - int get_width() { int x, y; getmaxyx(m_window, y, x); return x; } - int get_height() { int x, y; getmaxyx(m_window, y, x); return y; } + int width() { int x, y; getmaxyx(m_window, y, x); return x; } + int height() { int x, y; getmaxyx(m_window, y, x); return y; } chtype get_background() { return getbkgd(m_window); } void set_background(chtype c) { return wbkgdset(m_window, c); } diff --git a/src/display/frame.cc b/src/display/frame.cc index 84df2897..1ab51116 100644 --- a/src/display/frame.cc +++ b/src/display/frame.cc @@ -56,18 +56,39 @@ Frame::Frame() : } bool -Frame::is_dynamic() const { +Frame::is_width_dynamic() const { switch (m_type) { case TYPE_NONE: return false; case TYPE_WINDOW: - return m_window->is_active() && m_window->is_dynamic(); + return m_window->is_active() && m_window->is_width_dynamic(); case TYPE_ROW: case TYPE_COLUMN: for (size_type i = 0; i < m_containerSize; ++i) - if (m_container[i]->is_dynamic()) + if (m_container[i]->is_width_dynamic()) + return true; + + return false; + } + + return false; +} + +bool +Frame::is_height_dynamic() const { + switch (m_type) { + case TYPE_NONE: + return false; + + case TYPE_WINDOW: + return m_window->is_active() && m_window->is_height_dynamic(); + + case TYPE_ROW: + case TYPE_COLUMN: + for (size_type i = 0; i < m_containerSize; ++i) + if (m_container[i]->is_height_dynamic()) return true; return false; @@ -83,7 +104,10 @@ Frame::preferred_size() const { return pair_type(0, 0); case TYPE_WINDOW: - return m_window->is_active() ? pair_type(0, m_window->get_min_height()) : pair_type(0, 0); + if (m_window->is_active()) + return pair_type(std::max(m_window->min_width(), 1), std::max(m_window->min_height(), 1)); + else + return pair_type(0, 0); case TYPE_ROW: case TYPE_COLUMN: @@ -129,14 +153,29 @@ Frame::initialize_window(Window* window) { } void -Frame::initialize_container(Type containerType, size_type size) { - if (m_type != TYPE_NONE || (containerType != TYPE_ROW && containerType != TYPE_COLUMN)) +Frame::initialize_row(size_type size) { + if (m_type != TYPE_NONE) throw torrent::client_error("Frame::initialize_container(...) Invalid state."); if (size > max_size) throw torrent::client_error("Frame::initialize_container(...) size >= max_size."); - m_type = containerType; + m_type = TYPE_ROW; + m_containerSize = size; + + for (size_type i = 0; i < m_containerSize; ++i) + m_container[i] = new Frame(); +} + +void +Frame::initialize_column(size_type size) { + if (m_type != TYPE_NONE) + throw torrent::client_error("Frame::initialize_container(...) Invalid state."); + + if (size > max_size) + throw torrent::client_error("Frame::initialize_container(...) size >= max_size."); + + m_type = TYPE_COLUMN; m_containerSize = size; for (size_type i = 0; i < m_containerSize; ++i) @@ -193,47 +232,78 @@ Frame::balance(uint32_t x, uint32_t y, uint32_t width, uint32_t height) { return; if (m_type == TYPE_WINDOW) { - if (m_window->is_active()) - m_window->resize(x, y, width, height); + if (!m_window->is_active()) + return; + m_window->resize(x, y, width, height); + m_window->mark_dirty(); return; } - uint32_t size; + // Find the size of the static frames. The dynamic frames are added + // to a temporary list for the second pass. Each frame uses the + // m_width and m_height as temporary storage for width and height in + // this algorithm. + size_type dynamicSize = 0; + Frame* dynamicFrames[max_size]; + + int remaining = m_type == TYPE_ROW ? height : width; + + for (Frame **itr = m_container, **last = m_container + m_containerSize; itr != last; ++itr) { + pair_type p = (*itr)->preferred_size(); + (*itr)->m_width = p.first; + (*itr)->m_height = p.second; + + if ((m_type == TYPE_ROW && (*itr)->is_height_dynamic()) || (m_type == TYPE_COLUMN && (*itr)->is_width_dynamic())) + dynamicFrames[dynamicSize++] = *itr; + else + remaining -= m_type == TYPE_ROW ? p.second : p.first; + } + + // Sort the dynamic frames by the min size in the direction we are + // interested in. Then try to satisfy the largest first, and if we + // have any remaining space we can use that to extend it and any + // following frames. + // + // Else if we're short, only give each what they require. if (m_type == TYPE_ROW) - size = height - std::min(height, preferred_size().second); + std::sort(dynamicFrames, dynamicFrames + dynamicSize, rak::greater2(rak::mem_ptr(&Frame::m_height), rak::mem_ptr(&Frame::m_height))); else - size = width - std::min(width, preferred_size().first); + std::sort(dynamicFrames, dynamicFrames + dynamicSize, rak::greater2(rak::mem_ptr(&Frame::m_width), rak::mem_ptr(&Frame::m_width))); - uint32_t dynamicCount = std::count_if(m_container, m_container + m_containerSize, std::mem_fun(&Frame::is_dynamic)); + for (Frame **itr = dynamicFrames, **last = dynamicFrames + dynamicSize; itr != last; ++itr, --dynamicSize) { + uint32_t s = std::max((std::max(remaining, 0) + dynamicSize - 1) / dynamicSize, + m_type == TYPE_ROW ? (*itr)->m_height : (*itr)->m_width); + + remaining -= s; + + if (m_type == TYPE_ROW) + (*itr)->m_height = s; + else + (*itr)->m_width = s; + } + + // Expand/shrink m_w/h according to what is required to fill the min + // height/width. +// if (m_type == TYPE_ROW) +// m_height -= remaining; +// else +// m_width -= remaining; for (Frame **itr = m_container, **last = m_container + m_containerSize; itr != last; ++itr) { - uint32_t s; - - if ((*itr)->is_dynamic()) { - s = (size + dynamicCount - 1) / dynamicCount; - - size -= s; - dynamicCount--; - - } else { - s = 0; - } - if (m_type == TYPE_ROW) { - s += (*itr)->preferred_size().second; - - (*itr)->balance(x, y, m_width, s); - y += s; + (*itr)->balance(x, y, m_width, (*itr)->m_height); + y += (*itr)->m_height; } else { - s += (*itr)->preferred_size().first; - - (*itr)->balance(x, y, s, height); - x += s; + (*itr)->balance(x, y, (*itr)->m_width, m_height); + x += (*itr)->m_width; } } + + if ((m_type == TYPE_ROW && y != m_height) || (m_type == TYPE_COLUMN && x != m_width)) + throw torrent::client_error("Frame::balance(...) The algorithm did not end up with the correct remainder."); } } diff --git a/src/display/frame.h b/src/display/frame.h index 843f9a2e..8171dccc 100644 --- a/src/display/frame.h +++ b/src/display/frame.h @@ -59,7 +59,8 @@ public: Frame(); - bool is_dynamic() const; + bool is_width_dynamic() const; + bool is_height_dynamic() const; pair_type preferred_size() const; @@ -80,7 +81,8 @@ public: void set_container_size(size_type size); void initialize_window(Window* window); - void initialize_container(Type containerType, size_type size); + void initialize_row(size_type size); + void initialize_column(size_type size); void clear(); diff --git a/src/display/window.cc b/src/display/window.cc index 295dc9e9..19c96a4f 100644 --- a/src/display/window.cc +++ b/src/display/window.cc @@ -46,28 +46,37 @@ Window::SlotTimer Window::m_slotSchedule; Window::SlotWindow Window::m_slotUnschedule; Window::Slot Window::m_slotAdjust; -Window::Window(Canvas* c, bool d, int h) : - m_canvas(c), - m_active(true), - m_dynamic(d), - m_minHeight(h) { +Window::Window(Canvas* canvas, int flags, extent_type minWidth, extent_type minHeight) : + m_canvas(canvas), + m_flags(flags), + m_minWidth(minWidth), + m_minHeight(minHeight) { m_taskUpdate.set_slot(rak::mem_fn(this, &Window::redraw)); + + if (flags & flag_active) + mark_dirty(); } Window::~Window() { - m_slotUnschedule(this); + if (is_active()) + m_slotUnschedule(this); + delete m_canvas; } void -Window::set_active(bool a) { - if (a) - mark_dirty(); - else - m_slotUnschedule(this); +Window::set_active(bool state) { + if (state == is_active()) + return; - m_active = a; + if (state) { + m_flags |= flag_active; + mark_dirty(); + } else { + m_flags &= ~flag_active; + m_slotUnschedule(this); + } } void diff --git a/src/display/window.h b/src/display/window.h index a6f6c9bb..91bba898 100644 --- a/src/display/window.h +++ b/src/display/window.h @@ -50,30 +50,38 @@ class Manager; class Window { public: + typedef uint32_t extent_type; + typedef rak::mem_fun0 Slot; typedef rak::mem_fun1 SlotWindow; typedef rak::mem_fun2 SlotTimer; - Window(Canvas* c = NULL, bool d = false, int h = 1); + static const int flag_active = (1 << 0); + static const int flag_width_dynamic = (1 << 1); + static const int flag_height_dynamic = (1 << 2); + + Window(Canvas* canvas, int flags, extent_type minWidth, extent_type minHeight); virtual ~Window(); - bool is_active() { return m_active; } - bool is_dynamic() { return m_dynamic; } + bool is_active() const { return m_flags & flag_active; } + void set_active(bool state); + + bool is_width_dynamic() const { return m_flags & flag_width_dynamic; } + bool is_height_dynamic() const { return m_flags & flag_height_dynamic; } + bool is_dirty() { return m_taskUpdate.is_queued(); } + void mark_dirty() { m_slotSchedule(this, cachedTime + 1); } - int get_min_height() const { return m_minHeight; } + extent_type min_width() const { return m_minWidth; } + extent_type min_height() const { return m_minHeight; } - bool get_active() { return m_active; } - void set_active(bool a); + extent_type width() const { return m_canvas->width(); } + extent_type height() const { return m_canvas->height(); } void refresh() { m_canvas->refresh(); } void resize(int x, int y, int w, int h); - int get_height() const { return m_canvas->get_height(); } - - void mark_dirty() { m_slotSchedule(this, cachedTime + 1); } - virtual void redraw() = 0; rak::priority_item* task_update() { return &m_taskUpdate; } @@ -93,9 +101,10 @@ protected: Canvas* m_canvas; - bool m_active; - bool m_dynamic; - int m_minHeight; + int m_flags; + + extent_type m_minWidth; + extent_type m_minHeight; rak::priority_item m_taskUpdate; }; diff --git a/src/display/window_download_chunks_seen.cc b/src/display/window_download_chunks_seen.cc index ef6935db..a10817a5 100644 --- a/src/display/window_download_chunks_seen.cc +++ b/src/display/window_download_chunks_seen.cc @@ -52,7 +52,7 @@ namespace display { WindowDownloadChunksSeen::WindowDownloadChunksSeen(core::Download* d, unsigned int *focus) : - Window(new Canvas, true), + Window(new Canvas, flag_width_dynamic | flag_height_dynamic, 0, 0), m_download(d), m_focus(focus) { } @@ -63,7 +63,7 @@ WindowDownloadChunksSeen::redraw() { m_slotSchedule(this, (cachedTime + rak::timer::from_seconds(10)).round_seconds()); m_canvas->erase(); - if (m_canvas->get_height() < 3 || m_canvas->get_width() < 18) + if (m_canvas->height() < 3 || m_canvas->width() < 18) return; m_canvas->print(2, 0, "Chunks seen: [C/A/D %i/%i/%.2f]", @@ -102,7 +102,7 @@ WindowDownloadChunksSeen::redraw() { while (itrTransfer != transferChunks.end() && (uint32_t)(chunk - seen) > (*itrTransfer)->index()) itrTransfer++; - for (int y = 1; y < m_canvas->get_height() && chunk < last; ++y) { + for (int y = 1; y < m_canvas->height() && chunk < last; ++y) { m_canvas->print(0, y, "%5u ", (int)(chunk - seen)); while (chunk < last) { @@ -124,7 +124,7 @@ WindowDownloadChunksSeen::redraw() { chunk++; if ((chunk - seen) % 10 == 0) { - if (m_canvas->get_x() + 12 > m_canvas->get_width()) + if (m_canvas->get_x() + 12 > m_canvas->width()) break; m_canvas->print_char(' '); @@ -135,7 +135,7 @@ WindowDownloadChunksSeen::redraw() { unsigned int WindowDownloadChunksSeen::rows() const { - if (m_canvas->get_width() < 18) + if (m_canvas->width() < 18) return 0; return (m_download->download()->chunks_total() + chunks_per_row() - 1) / chunks_per_row(); diff --git a/src/display/window_download_chunks_seen.h b/src/display/window_download_chunks_seen.h index 92a95c04..1f877605 100644 --- a/src/display/window_download_chunks_seen.h +++ b/src/display/window_download_chunks_seen.h @@ -54,9 +54,9 @@ public: virtual void redraw(); unsigned int rows() const; - unsigned int chunks_per_row() const { return (m_canvas->get_width() - 6) / 11 * 10; } + unsigned int chunks_per_row() const { return (width() - 6) / 11 * 10; } - unsigned int max_focus() const { return std::max(rows() - get_height() + 1, 0); } + unsigned int max_focus() const { return std::max(rows() - height() + 1, 0); } private: core::Download* m_download; diff --git a/src/display/window_download_list.cc b/src/display/window_download_list.cc index 6a4ebd07..da14d333 100644 --- a/src/display/window_download_list.cc +++ b/src/display/window_download_list.cc @@ -73,7 +73,7 @@ WindowDownloadList::redraw() { m_canvas->print(0, 0, "%s", ("[View: " + m_view->name() + "]").c_str()); - if (m_view->empty_visible() || m_canvas->get_width() < 5 || m_canvas->get_height() < 2) + if (m_view->empty_visible() || m_canvas->width() < 5 || m_canvas->height() < 2) return; typedef std::pair Range; @@ -81,7 +81,7 @@ WindowDownloadList::redraw() { Range range = rak::advance_bidirectional(m_view->begin_visible(), m_view->focus() != m_view->end_visible() ? m_view->focus() : m_view->begin_visible(), m_view->end_visible(), - m_canvas->get_height() / 3); + m_canvas->height() / 3); // Make sure we properly fill out the last lines so it looks like // there are more torrents, yet don't hide it if we got the last one @@ -92,9 +92,9 @@ WindowDownloadList::redraw() { int pos = 1; while (range.first != range.second) { - char buffer[m_canvas->get_width()]; + char buffer[m_canvas->width()]; char* position; - char* last = buffer + m_canvas->get_width() - 2; + char* last = buffer + m_canvas->width() - 2; position = print_download_title(buffer, last, *range.first); m_canvas->print(0, pos++, "%c %s", range.first == m_view->focus() ? '*' : ' ', buffer); diff --git a/src/display/window_download_list.h b/src/display/window_download_list.h index 8c22ad17..f121dfe5 100644 --- a/src/display/window_download_list.h +++ b/src/display/window_download_list.h @@ -51,7 +51,9 @@ namespace display { class WindowDownloadList : public Window { public: - WindowDownloadList() : Window(new Canvas, true), m_view(NULL) {} + WindowDownloadList() : + Window(new Canvas, flag_width_dynamic | flag_height_dynamic, 120, 1), + m_view(NULL) {} ~WindowDownloadList(); virtual void redraw(); diff --git a/src/display/window_download_statusbar.cc b/src/display/window_download_statusbar.cc index f1ad2704..c52e761a 100644 --- a/src/display/window_download_statusbar.cc +++ b/src/display/window_download_statusbar.cc @@ -49,7 +49,7 @@ namespace display { WindowDownloadStatusbar::WindowDownloadStatusbar(core::Download* d) : - Window(new Canvas, false, 3), + Window(new Canvas, flag_width_dynamic, 0, 3), m_download(d) { } @@ -59,35 +59,33 @@ WindowDownloadStatusbar::redraw() { m_canvas->erase(); - char buffer[m_canvas->get_width()]; + char buffer[m_canvas->width()]; char* position; - char* last = buffer + m_canvas->get_width() - 2; + char* last = buffer + m_canvas->width() - 2; position = print_download_info(buffer, last, m_download); m_canvas->print(0, 0, "%s", buffer); position = buffer + std::max(snprintf(buffer, last - buffer, "Peers: %i(%i) Min/Max: %i/%i Uploads: %i U/I/C/A: %i/%i/%i/%i Failed: %i", - (int)m_download->download()->peers_connected(), - (int)m_download->download()->peers_not_connected(), - (int)m_download->download()->peers_min(), - (int)m_download->download()->peers_max(), - (int)m_download->download()->uploads_max(), - (int)m_download->download()->peers_currently_unchoked(), - (int)m_download->download()->peers_currently_interested(), - (int)m_download->download()->peers_complete(), - (int)m_download->download()->peers_accounted(), - (int)m_download->chunks_failed()), - 0); -// position = buffer + std::max(snprintf(position, last - buffer, " Priority: %s", -// core::Download::priority_to_string(m_download->variable()->get("priority").as_value())), -// 0); + (int)m_download->download()->peers_connected(), + (int)m_download->download()->peers_not_connected(), + (int)m_download->download()->peers_min(), + (int)m_download->download()->peers_max(), + (int)m_download->download()->uploads_max(), + (int)m_download->download()->peers_currently_unchoked(), + (int)m_download->download()->peers_currently_interested(), + (int)m_download->download()->peers_complete(), + (int)m_download->download()->peers_accounted(), + (int)m_download->chunks_failed()), + 0); + m_canvas->print(0, 1, "%s", buffer); position = print_download_status(buffer, last, m_download); m_canvas->print(0, 2, "[%c:%i] %s", - m_download->tracker_list()->is_busy() ? 'C' : ' ', - (int)(m_download->download()->tracker_list().timeout() / 1000000), - buffer); + m_download->tracker_list()->is_busy() ? 'C' : ' ', + (int)(m_download->download()->tracker_list().timeout() / 1000000), + buffer); } } diff --git a/src/display/window_download_transfer_list.cc b/src/display/window_download_transfer_list.cc index 52dde386..0a23a053 100644 --- a/src/display/window_download_transfer_list.cc +++ b/src/display/window_download_transfer_list.cc @@ -49,7 +49,7 @@ namespace display { WindowDownloadTransferList::WindowDownloadTransferList(core::Download* d, unsigned int *focus) : - Window(new Canvas, true), + Window(new Canvas, flag_width_dynamic | flag_height_dynamic, 0, 0), m_download(d), m_focus(focus) { } @@ -60,7 +60,7 @@ WindowDownloadTransferList::redraw() { m_slotSchedule(this, (cachedTime + rak::timer::from_seconds(1)).round_seconds()); m_canvas->erase(); - if (m_canvas->get_height() < 3 || m_canvas->get_width() < 18) + if (m_canvas->height() < 3 || m_canvas->width() < 18) return; const torrent::TransferList* transfers = m_download->download()->transfer_list(); @@ -73,7 +73,7 @@ WindowDownloadTransferList::redraw() { // is just something i threw in there, someone really should // prettify this. (This is a very subtle hint) - for (int y = 1; y < m_canvas->get_height() && itr != transfers->end(); ++y, ++itr) { + for (int y = 1; y < m_canvas->height() && itr != transfers->end(); ++y, ++itr) { m_canvas->print(0, y, "%5u [P: %u F: %u]", (*itr)->index(), (*itr)->priority(), (*itr)->failed()); // Handle window size. @@ -106,7 +106,7 @@ WindowDownloadTransferList::redraw() { unsigned int WindowDownloadTransferList::rows() const { - if (m_canvas->get_width() < 18) + if (m_canvas->width() < 18) return 0; // return (m_download->download()->chunks_total() + chunks_per_row() - 1) / chunks_per_row(); diff --git a/src/display/window_download_transfer_list.h b/src/display/window_download_transfer_list.h index 619dabf9..8c500eb4 100644 --- a/src/display/window_download_transfer_list.h +++ b/src/display/window_download_transfer_list.h @@ -65,7 +65,7 @@ public: virtual void redraw(); unsigned int rows() const; - unsigned int max_focus() const { return std::max(rows() - get_height() + 1, 0); } + unsigned int max_focus() const { return std::max(rows() - height() + 1, 0); } private: char key_id(torrent::BlockTransfer::key_type key); diff --git a/src/display/window_file_list.cc b/src/display/window_file_list.cc index a7dbf9c8..c75a35fe 100644 --- a/src/display/window_file_list.cc +++ b/src/display/window_file_list.cc @@ -49,7 +49,7 @@ namespace display { WindowFileList::WindowFileList(core::Download* d, unsigned int* focus) : - Window(new Canvas, true), + Window(new Canvas, flag_width_dynamic | flag_height_dynamic, 0, 0), m_download(d), m_focus(focus) { } @@ -78,7 +78,7 @@ WindowFileList::redraw() { torrent::FileList fl = m_download->download()->file_list(); - if (fl.size() == 0 || m_canvas->get_height() < 2) + if (fl.size() == 0 || m_canvas->height() < 2) return; int pos = 0; @@ -95,7 +95,7 @@ WindowFileList::redraw() { if (*m_focus >= fl.size()) throw std::logic_error("WindowFileList::redraw() called on an object with a bad focus value"); - Range range = rak::advance_bidirectional(0, *m_focus, fl.size(), m_canvas->get_height() - pos); + Range range = rak::advance_bidirectional(0, *m_focus, fl.size(), m_canvas->height() - pos); while (range.first != range.second) { torrent::File e = fl.get(range.first); diff --git a/src/display/window_http_queue.cc b/src/display/window_http_queue.cc index f85aab87..a65aefc0 100644 --- a/src/display/window_http_queue.cc +++ b/src/display/window_http_queue.cc @@ -48,7 +48,7 @@ namespace display { WindowHttpQueue::WindowHttpQueue(core::HttpQueue* q) : - Window(new Canvas, false, 1), + Window(new Canvas, flag_width_dynamic, 0, 1), m_queue(q) { set_active(false); @@ -75,7 +75,7 @@ WindowHttpQueue::redraw() { int pos = 10; Container::iterator itr = m_container.begin(); - while (itr != m_container.end() && pos + 20 < m_canvas->get_width()) { + while (itr != m_container.end() && pos + 20 < m_canvas->width()) { if (itr->m_http == NULL) m_canvas->print(pos, 0, "%s done", itr->m_name.c_str()); diff --git a/src/display/window_input.cc b/src/display/window_input.cc index b7c6eede..ac8e56a1 100644 --- a/src/display/window_input.cc +++ b/src/display/window_input.cc @@ -46,10 +46,10 @@ namespace display { void WindowInput::redraw() { m_canvas->erase(); - m_canvas->print(0, 0, "> %s", m_input != NULL ? m_input->c_str() : ""); + m_canvas->print(0, 0, "%s> %s", m_title.c_str(), m_input != NULL ? m_input->c_str() : ""); if (m_focus) - m_canvas->set_attr(m_input->get_pos() + 2, 0, 1, A_REVERSE, COLOR_PAIR(0)); + m_canvas->set_attr(m_input->get_pos() + 2 + m_title.size(), 0, 1, A_REVERSE, COLOR_PAIR(0)); } } diff --git a/src/display/window_input.h b/src/display/window_input.h index 529d1f2c..bbcedba2 100644 --- a/src/display/window_input.h +++ b/src/display/window_input.h @@ -37,6 +37,8 @@ #ifndef RTORRENT_DISPLAY_WINDOW_INPUT_H #define RTORRENT_DISPLAY_WINDOW_INPUT_H +#include + #include "window.h" namespace input { @@ -47,11 +49,17 @@ namespace display { class WindowInput : public Window { public: - WindowInput() : Window(new Canvas, false, 1), m_input(NULL), m_focus(false) {} + WindowInput() : + Window(new Canvas, flag_width_dynamic, 0, 1), + m_input(NULL), + m_focus(false) {} input::TextInput* input() { return m_input; } void set_input(input::TextInput* input) { m_input = input; } + const std::string& title() const { return m_title; } + void set_title(const std::string& str) { m_title = str; } + bool focus() const { return m_focus; } void set_focus(bool f) { mark_dirty(); m_focus = f; } @@ -59,6 +67,8 @@ public: private: input::TextInput* m_input; + std::string m_title; + bool m_focus; }; diff --git a/src/display/window_log.cc b/src/display/window_log.cc index 220ece09..d1bc77df 100644 --- a/src/display/window_log.cc +++ b/src/display/window_log.cc @@ -45,11 +45,9 @@ namespace display { WindowLog::WindowLog(core::Log* l) : - Window(new Canvas, false, 0), + Window(new Canvas, flag_width_dynamic, 0, 0), m_log(l) { - m_active = false; - // We're trying out scheduled tasks instead. m_connUpdate = l->signal_update().connect(sigc::mem_fun(*this, &WindowLog::receive_update)); } @@ -69,7 +67,7 @@ WindowLog::redraw() { int pos = 0; - for (core::Log::iterator itr = m_log->begin(), end = find_older(); itr != end && pos < m_canvas->get_height(); ++itr) { + for (core::Log::iterator itr = m_log->begin(), end = find_older(); itr != end && pos < m_canvas->height(); ++itr) { char buffer[16]; print_hhmmss_local(buffer, buffer + 16, static_cast(itr->first.seconds())); @@ -80,7 +78,7 @@ WindowLog::redraw() { void WindowLog::receive_update() { iterator itr = find_older(); - int h = std::min(std::distance(m_log->begin(), itr), (std::iterator_traits::difference_type)10); + extent_type h = std::min(std::distance(m_log->begin(), itr), (std::iterator_traits::difference_type)10); if (h != m_minHeight) { set_active(h != 0); diff --git a/src/display/window_log_complete.cc b/src/display/window_log_complete.cc index 56b5bf45..51f3c38a 100644 --- a/src/display/window_log_complete.cc +++ b/src/display/window_log_complete.cc @@ -45,7 +45,7 @@ namespace display { WindowLogComplete::WindowLogComplete(core::Log* l) : - Window(new Canvas, true), + Window(new Canvas, flag_width_dynamic | flag_height_dynamic, 30, 1), m_log(l) { // We're trying out scheduled tasks instead. @@ -67,9 +67,9 @@ WindowLogComplete::redraw() { int pos = 0; -// m_canvas->print(std::max(0, (int)m_canvas->get_width() / 2 - 5), pos++, "*** Log ***"); +// m_canvas->print(std::max(0, (int)m_canvas->width() / 2 - 5), pos++, "*** Log ***"); - for (core::Log::iterator itr = m_log->begin(), e = m_log->end(); itr != e && pos < m_canvas->get_height(); ++itr) { + for (core::Log::iterator itr = m_log->begin(), e = m_log->end(); itr != e && pos < m_canvas->height(); ++itr) { char buffer[16]; print_hhmmss_local(buffer, buffer + 16, static_cast(itr->first.seconds())); diff --git a/src/display/window_peer_info.cc b/src/display/window_peer_info.cc index 4702c1e0..0e00f646 100644 --- a/src/display/window_peer_info.cc +++ b/src/display/window_peer_info.cc @@ -54,7 +54,7 @@ namespace display { WindowPeerInfo::WindowPeerInfo(core::Download* d, PList* l, PList::iterator* f) : - Window(new Canvas, true), + Window(new Canvas, flag_width_dynamic | flag_height_dynamic, 0, 0), m_download(d), m_list(l), m_focus(f) { diff --git a/src/display/window_peer_list.cc b/src/display/window_peer_list.cc index b6f6c3ec..4535efbb 100644 --- a/src/display/window_peer_list.cc +++ b/src/display/window_peer_list.cc @@ -52,7 +52,7 @@ namespace display { WindowPeerList::WindowPeerList(core::Download* d, PList* l, PList::iterator* f) : - Window(new Canvas, true), + Window(new Canvas, flag_width_dynamic | flag_height_dynamic, 0, 0), m_download(d), m_list(l), m_focus(f) { @@ -87,7 +87,7 @@ WindowPeerList::redraw() { Range range = rak::advance_bidirectional(m_list->begin(), *m_focus != m_list->end() ? *m_focus : m_list->begin(), m_list->end(), - m_canvas->get_height() - y); + m_canvas->height() - y); if (m_download->download()->chunks_total() <= 0) throw std::logic_error("WindowPeerList::redraw() m_slotChunksTotal() returned invalid value"); diff --git a/src/display/window_statusbar.cc b/src/display/window_statusbar.cc index 8bd0531c..9ed91340 100644 --- a/src/display/window_statusbar.cc +++ b/src/display/window_statusbar.cc @@ -53,9 +53,9 @@ WindowStatusbar::redraw() { m_canvas->erase(); // TODO: Make a buffer with size = get_width? - char buffer[m_canvas->get_width() + 1]; + char buffer[m_canvas->width() + 1]; char* position; - char* last = buffer + m_canvas->get_width(); + char* last = buffer + m_canvas->width(); // if (torrent::up_throttle() == 0) // position = std::max(snprintf(buffer, 128, "off/"), 0); @@ -96,7 +96,7 @@ WindowStatusbar::redraw() { if (last > buffer) { position = print_status_extra(buffer, last, control); - m_canvas->print(m_canvas->get_width() - (position - buffer), 0, "%s", buffer); + m_canvas->print(m_canvas->width() - (position - buffer), 0, "%s", buffer); } m_lastTick = control->tick(); diff --git a/src/display/window_statusbar.h b/src/display/window_statusbar.h index ffa2c638..47837fa9 100644 --- a/src/display/window_statusbar.h +++ b/src/display/window_statusbar.h @@ -45,7 +45,9 @@ namespace display { class WindowStatusbar : public Window { public: - WindowStatusbar() : Window(new Canvas, false, 1), m_lastTick(0) {} + WindowStatusbar() : + Window(new Canvas, flag_width_dynamic, 0, 1), + m_lastTick(0) {} virtual void redraw(); diff --git a/src/display/window_string_list.cc b/src/display/window_string_list.cc index 2b75edd9..48adc9fd 100644 --- a/src/display/window_string_list.cc +++ b/src/display/window_string_list.cc @@ -43,7 +43,7 @@ namespace display { WindowStringList::WindowStringList() : - Window(new Canvas, true) { + Window(new Canvas, flag_width_dynamic | flag_height_dynamic, 0, 0) { } WindowStringList::~WindowStringList() { @@ -61,22 +61,22 @@ WindowStringList::redraw() { while (itr != m_last) { - if (ypos == (size_t)m_canvas->get_height()) { + if (ypos == (size_t)m_canvas->height()) { ypos = 0; xpos += width + 2; - if (xpos + 20 >= (size_t)m_canvas->get_width()) - break; + if (xpos + 20 >= (size_t)m_canvas->width()) + break; width = 0; } width = std::max(itr->size(), width); - if (xpos + itr->size() <= (size_t)m_canvas->get_width()) + if (xpos + itr->size() <= (size_t)m_canvas->width()) m_canvas->print(xpos, ypos++, "%s", itr->c_str()); else - m_canvas->print(xpos, ypos++, "%s", itr->substr(0, m_canvas->get_width() - xpos).c_str()); + m_canvas->print(xpos, ypos++, "%s", itr->substr(0, m_canvas->width() - xpos).c_str()); ++itr; } diff --git a/src/display/window_title.cc b/src/display/window_title.cc index 509a1a77..c23b4405 100644 --- a/src/display/window_title.cc +++ b/src/display/window_title.cc @@ -46,7 +46,7 @@ WindowTitle::redraw() { m_slotSchedule(this, (cachedTime + rak::timer::from_seconds(1)).round_seconds()); m_canvas->erase(); - m_canvas->print(std::max(0, (m_canvas->get_width() - (int)m_title.size()) / 2 - 4), 0, + m_canvas->print(std::max(0, (m_canvas->width() - (int)m_title.size()) / 2 - 4), 0, "*** %s ***", m_title.c_str()); } diff --git a/src/display/window_title.h b/src/display/window_title.h index 62504ccf..261f2494 100644 --- a/src/display/window_title.h +++ b/src/display/window_title.h @@ -44,7 +44,7 @@ namespace display { class WindowTitle : public Window { public: - WindowTitle() : Window(new Canvas, false, 1) {} + WindowTitle() : Window(new Canvas, flag_width_dynamic, 0, 1) {} const std::string& title() const { return m_title; } void set_title(const std::string& title) { m_title = title; mark_dirty(); } diff --git a/src/display/window_tracker_list.cc b/src/display/window_tracker_list.cc index 8d26102a..02f1a35d 100644 --- a/src/display/window_tracker_list.cc +++ b/src/display/window_tracker_list.cc @@ -49,7 +49,7 @@ namespace display { WindowTrackerList::WindowTrackerList(core::Download* d, unsigned int* focus) : - Window(new Canvas, true), + Window(new Canvas, flag_width_dynamic | flag_height_dynamic, 0, 0), m_download(d), m_focus(focus) { } @@ -74,24 +74,24 @@ WindowTrackerList::redraw() { typedef std::pair Range; - Range range = rak::advance_bidirectional(0, *m_focus, tl->size(), (m_canvas->get_height() + 1) / 2); + Range range = rak::advance_bidirectional(0, *m_focus, tl->size(), (m_canvas->height() + 1) / 2); while (range.first != range.second) { torrent::Tracker t = tl->get(range.first); m_canvas->print(0, pos++, "%c %s", - range.first == *m_focus ? '*' : ' ', - t.url().c_str()); + range.first == *m_focus ? '*' : ' ', + t.url().c_str()); m_canvas->print(0, pos++, "%c Group: %2i Id: %s Focus: %s Enabled: %s Open: %s S/L: %u/%u", - range.first == *m_focus ? '*' : ' ', - t.group(), - rak::copy_escape_html(t.tracker_id()).c_str(), - range.first == tl->focus() ? "yes" : " no", - t.is_enabled() ? "yes" : " no", - t.is_open() ? "yes" : " no", - t.scrape_complete(), - t.scrape_incomplete()); + range.first == *m_focus ? '*' : ' ', + t.group(), + rak::copy_escape_html(t.tracker_id()).c_str(), + range.first == tl->focus() ? "yes" : " no", + t.is_enabled() ? "yes" : " no", + t.is_open() ? "yes" : " no", + t.scrape_complete(), + t.scrape_incomplete()); ++range.first; } diff --git a/src/input/bindings.cc b/src/input/bindings.cc index c3ceedc5..53263a97 100644 --- a/src/input/bindings.cc +++ b/src/input/bindings.cc @@ -44,7 +44,7 @@ namespace input { bool Bindings::pressed(int key) { - if (!m_active) + if (!m_enabled) return false; const_iterator itr = find(key); diff --git a/src/input/bindings.h b/src/input/bindings.h index 0e9fae67..b84a5945 100644 --- a/src/input/bindings.h +++ b/src/input/bindings.h @@ -63,17 +63,17 @@ public: using Base::operator[]; - Bindings() : m_active(true) {} + Bindings() : m_enabled(true) {} - void activate() { m_active = true; } - void disable() { m_active = false; } + void enable() { m_enabled = true; } + void disable() { m_enabled = false; } bool pressed(int key); void ignore(int key) { (*this)[key] = Slot(); } private: - bool m_active; + bool m_enabled; }; } diff --git a/src/input/path_input.cc b/src/input/path_input.cc index 863e0649..b64074fa 100644 --- a/src/input/path_input.cc +++ b/src/input/path_input.cc @@ -51,6 +51,8 @@ PathInput::PathInput() : bool PathInput::pressed(int key) { + // Consider binding tab in m_bindings instead. + if (key != '\t') { m_showNext = false; return TextInput::pressed(key); diff --git a/src/input/text_input.cc b/src/input/text_input.cc index f505ed6c..dbe96a6d 100644 --- a/src/input/text_input.cc +++ b/src/input/text_input.cc @@ -44,7 +44,10 @@ namespace input { bool TextInput::pressed(int key) { - if (m_alt) { + if (m_bindings.pressed(key)) { + return true; + + } else if (m_alt) { m_alt = false; switch (key) { @@ -123,7 +126,6 @@ TextInput::pressed(int key) { m_slotDirty(); return true; - } } diff --git a/src/input/text_input.h b/src/input/text_input.h index be9d454a..fc39cb35 100644 --- a/src/input/text_input.h +++ b/src/input/text_input.h @@ -38,7 +38,8 @@ #define RTORRENT_INPUT_TEXT_INPUT_H #include -#include + +#include "bindings.h" namespace input { @@ -68,11 +69,15 @@ public: std::string& str() { return *this; } + Bindings& bindings() { return m_bindings; } + private: size_type m_pos; bool m_alt; SlotDirty m_slotDirty; + + Bindings m_bindings; }; } diff --git a/src/ui/download_list.cc b/src/ui/download_list.cc index dcfaccdf..56d4d218 100644 --- a/src/ui/download_list.cc +++ b/src/ui/download_list.cc @@ -117,11 +117,7 @@ DownloadList::disable() { if (!is_active()) throw std::logic_error("ui::DownloadList::disable() called on an already disabled object"); -// if (m_windowTextInput->is_active()) { -// m_windowTextInput->get_input()->clear(); -// receive_exit_input(INPUT_NONE); -// } - + receive_exit_input(INPUT_NONE); activate_display(DISPLAY_NONE); m_frame = NULL; @@ -133,10 +129,10 @@ DownloadList::disable() { void DownloadList::activate_display(Display displayType) { if (!is_active()) - throw std::logic_error("ui::DownloadList::activate_display(...) !is_active()."); + throw torrent::client_error("ui::DownloadList::activate_display(...) !is_active()."); if (displayType >= DISPLAY_MAX_SIZE) - throw std::logic_error("ui::DownloadList::activate_display(...) out of bounds"); + throw torrent::client_error("ui::DownloadList::activate_display(...) out of bounds"); if (displayType == m_state) return; @@ -146,6 +142,11 @@ DownloadList::activate_display(Display displayType) { // Cleanup previous state. switch (m_state) { case DISPLAY_DOWNLOAD_LIST: + m_uiArray[DISPLAY_DOWNLOAD_LIST]->disable(); + m_uiArray[DISPLAY_LOG]->disable(); + m_frame->clear(); + break; + case DISPLAY_LOG: m_uiArray[m_state]->disable(); break; @@ -162,14 +163,13 @@ DownloadList::activate_display(Display displayType) { break; case DISPLAY_DOWNLOAD_LIST: - control->ui()->window_title()->set_title("rTorrent " VERSION " - libTorrent " + std::string(torrent::version())); + m_frame->initialize_column(2); - m_uiArray[displayType]->activate(m_frame); + m_uiArray[DISPLAY_DOWNLOAD_LIST]->activate(m_frame->frame(0)); + m_uiArray[DISPLAY_LOG]->activate(m_frame->frame(1)); break; case DISPLAY_LOG: - control->ui()->window_title()->set_title("Log"); - m_uiArray[displayType]->activate(m_frame); break; @@ -177,6 +177,13 @@ DownloadList::activate_display(Display displayType) { break; } + // Set title. + switch (displayType) { + case DISPLAY_DOWNLOAD_LIST: control->ui()->window_title()->set_title("rTorrent " VERSION " - libTorrent " + std::string(torrent::version())); break; + case DISPLAY_LOG: control->ui()->window_title()->set_title("Log"); break; + default: break; + } + control->display()->adjust_layout(); } @@ -224,8 +231,10 @@ DownloadList::receive_close_download() { if (m_view->focus() == m_view->end_visible()) return; - control->core()->download_list()->stop_normal(*m_view->focus()); - control->core()->download_list()->close(*m_view->focus()); + core::Download* download = *m_view->focus(); + + control->core()->download_list()->stop_normal(download); + control->core()->download_list()->close(download); m_view->set_last_changed(); } @@ -323,23 +332,39 @@ DownloadList::receive_view_input(Input type) { input::PathInput* input = new input::PathInput; + const char* title; + switch (type) { + case INPUT_LOAD_DEFAULT: + title = "load_start"; + break; + + case INPUT_LOAD_MODIFIED: + title = "load"; + break; + case INPUT_CHANGE_DIRECTORY: + title = "change_directory"; + input->str() = control->variable()->get_string("directory"); input->set_pos(input->str().length()); break; - default: + case INPUT_COMMAND: + title = "command"; break; + + default: + throw torrent::client_error("DownloadList::receive_view_input(...) Invalid input type."); } - control->ui()->enable_input(input); + input->bindings()['\n'] = sigc::bind(sigc::mem_fun(*this, &DownloadList::receive_exit_input), type); + input->bindings()[KEY_ENTER] = sigc::bind(sigc::mem_fun(*this, &DownloadList::receive_exit_input), type); + input->bindings()['\x07'] = sigc::bind(sigc::mem_fun(*this, &DownloadList::receive_exit_input), INPUT_NONE); - // These bindings should be moved to f.ex TextInput? - m_bindings['\n'] = sigc::bind(sigc::mem_fun(*this, &DownloadList::receive_exit_input), type); - m_bindings[KEY_ENTER] = sigc::bind(sigc::mem_fun(*this, &DownloadList::receive_exit_input), type); - m_bindings['\x07'] = sigc::bind(sigc::mem_fun(*this, &DownloadList::receive_exit_input), INPUT_NONE); + m_bindings.disable(); + control->ui()->enable_input(title, input); } void @@ -351,14 +376,7 @@ DownloadList::receive_exit_input(Input type) { return; control->ui()->disable_input(); - - // Urgh... this is ugly... - m_bindings.erase('\n'); - m_bindings.erase(KEY_ENTER); - m_bindings.erase('\x07'); - - m_bindings['\n'] = sigc::bind(sigc::mem_fun(*this, &DownloadList::receive_view_input), INPUT_LOAD_MODIFIED); - m_bindings[KEY_ENTER] = sigc::bind(sigc::mem_fun(*this, &DownloadList::receive_view_input), INPUT_LOAD_MODIFIED); + m_bindings.enable(); try { @@ -382,6 +400,9 @@ DownloadList::receive_exit_input(Input type) { case INPUT_COMMAND: control->variable()->process_command(input->str()); break; + + default: + throw torrent::client_error("DownloadList::receive_exit_input(...) Invalid input type."); } } catch (torrent::input_error& e) { @@ -460,8 +481,8 @@ DownloadList::setup_keys() { m_bindings['6'] = sigc::bind(sigc::mem_fun(*this, &DownloadList::receive_change_view), "incomplete"); m_bindings['7'] = sigc::bind(sigc::mem_fun(*this, &DownloadList::receive_change_view), "hashing"); - m_uiArray[DISPLAY_LOG]->bindings()[' '] = sigc::bind(sigc::mem_fun(*this, &DownloadList::activate_display), DISPLAY_DOWNLOAD_LIST); - m_uiArray[DISPLAY_LOG]->bindings()[KEY_RIGHT] = sigc::bind(sigc::mem_fun(*this, &DownloadList::activate_display), DISPLAY_DOWNLOAD_LIST); + m_uiArray[DISPLAY_LOG]->bindings()[' '] = sigc::bind(sigc::mem_fun(*this, &DownloadList::activate_display), DISPLAY_DOWNLOAD_LIST); + m_uiArray[DISPLAY_LOG]->bindings()[KEY_LEFT] = sigc::bind(sigc::mem_fun(*this, &DownloadList::activate_display), DISPLAY_DOWNLOAD_LIST); } // void diff --git a/src/ui/element_chunks_seen.cc b/src/ui/element_chunks_seen.cc index ed0462a3..85668706 100644 --- a/src/ui/element_chunks_seen.cc +++ b/src/ui/element_chunks_seen.cc @@ -128,7 +128,7 @@ ElementChunksSeen::receive_pagenext() { if (m_window == NULL) throw torrent::client_error("ui::ElementChunksSeen::receive_pagenext(...) called on a disabled object"); - unsigned int visible = m_window->get_height() - 1; + unsigned int visible = m_window->height() - 1; unsigned int scrollable = std::max(m_window->rows() - visible, 0); if (scrollable == 0 || m_focus == scrollable) @@ -146,7 +146,7 @@ ElementChunksSeen::receive_pageprev() { if (m_window == NULL) throw torrent::client_error("ui::ElementChunksSeen::receive_pageprev(...) called on a disabled object"); - unsigned int visible = m_window->get_height() - 1; + unsigned int visible = m_window->height() - 1; unsigned int scrollable = std::max(m_window->rows() - visible, 0); if (m_focus > visible / 2) diff --git a/src/ui/element_download_list.cc b/src/ui/element_download_list.cc index 4f42d4b5..c1ebf983 100644 --- a/src/ui/element_download_list.cc +++ b/src/ui/element_download_list.cc @@ -55,6 +55,7 @@ ElementDownloadList::activate(display::Frame* frame) { control->input()->push_front(&m_bindings); m_window = new WDownloadList(); + m_window->set_active(true); m_window->set_view(m_view); m_frame = frame; diff --git a/src/ui/element_file_list.cc b/src/ui/element_file_list.cc index 126f38d8..f368021b 100644 --- a/src/ui/element_file_list.cc +++ b/src/ui/element_file_list.cc @@ -121,7 +121,7 @@ ElementFileList::receive_pagenext() { if (m_window == NULL) throw torrent::client_error("ui::ElementFileList::receive_pagenext(...) called on a disabled object"); - unsigned int count = (m_window->get_height() - 1) / 2; + unsigned int count = (m_window->height() - 1) / 2; if (m_focus + count < m_download->download()->file_list().size()) m_focus += count; @@ -143,7 +143,7 @@ ElementFileList::receive_pageprev() { if (fl.size() == 0) return; - unsigned int count = (m_window->get_height() - 1) / 2; + unsigned int count = (m_window->height() - 1) / 2; if (m_focus > count) m_focus -= count; diff --git a/src/ui/element_log_complete.cc b/src/ui/element_log_complete.cc index e13be405..aef986e0 100644 --- a/src/ui/element_log_complete.cc +++ b/src/ui/element_log_complete.cc @@ -61,6 +61,7 @@ ElementLogComplete::activate(display::Frame* frame) { control->input()->push_front(&m_bindings); m_window = new WLogComplete(m_log); + m_window->set_active(true); m_frame = frame; m_frame->initialize_window(m_window); diff --git a/src/ui/element_transfer_list.cc b/src/ui/element_transfer_list.cc index 6fa9d8b2..8f665302 100644 --- a/src/ui/element_transfer_list.cc +++ b/src/ui/element_transfer_list.cc @@ -128,7 +128,7 @@ ElementTransferList::receive_pagenext() { // if (m_window == NULL) // throw torrent::client_error("ui::ElementTransferList::receive_pagenext(...) called on a disabled object"); -// unsigned int visible = m_window->get_height() - 1; +// unsigned int visible = m_window->height() - 1; // unsigned int scrollable = std::max(m_window->rows() - visible, 0); // if (scrollable == 0 || m_focus == scrollable) @@ -146,7 +146,7 @@ ElementTransferList::receive_pageprev() { // if (m_window == NULL) // throw torrent::client_error("ui::ElementTransferList::receive_pageprev(...) called on a disabled object"); -// unsigned int visible = m_window->get_height() - 1; +// unsigned int visible = m_window->height() - 1; // unsigned int scrollable = std::max(m_window->rows() - visible, 0); // if (m_focus > visible / 2) diff --git a/src/ui/root.cc b/src/ui/root.cc index 984f4c4d..03ad8d4d 100644 --- a/src/ui/root.cc +++ b/src/ui/root.cc @@ -83,16 +83,14 @@ Root::init(Control* c) { display::Frame* rootFrame = m_control->display()->root_frame(); - rootFrame->initialize_container(display::Frame::TYPE_ROW, 5); + rootFrame->initialize_row(5); rootFrame->frame(0)->initialize_window(m_windowTitle); rootFrame->frame(2)->initialize_window(m_windowHttpQueue); rootFrame->frame(3)->initialize_window(m_windowInput); rootFrame->frame(4)->initialize_window(m_windowStatusbar); - m_control->display()->schedule(m_windowTitle, cachedTime); - m_control->display()->schedule(m_windowStatusbar, cachedTime); - - m_windowInput->set_active(false); + m_windowTitle->set_active(true); + m_windowStatusbar->set_active(true); setup_keys(); @@ -187,7 +185,7 @@ Root::adjust_up_throttle(int throttle) { } void -Root::enable_input(input::TextInput* input) { +Root::enable_input(const std::string& title, input::TextInput* input) { if (m_windowInput->input() != NULL) throw torrent::client_error("Root::enable_input(...) m_windowInput->input() != NULL."); @@ -196,8 +194,9 @@ Root::enable_input(input::TextInput* input) { m_windowStatusbar->set_active(false); m_windowInput->set_active(true); - m_windowInput->set_focus(true); m_windowInput->set_input(input); + m_windowInput->set_title(title); + m_windowInput->set_focus(true); control->input()->set_text_input(input); control->display()->adjust_layout(); diff --git a/src/ui/root.h b/src/ui/root.h index bc905dea..d3a2873a 100644 --- a/src/ui/root.h +++ b/src/ui/root.h @@ -84,7 +84,7 @@ public: void adjust_down_throttle(int throttle); void adjust_up_throttle(int throttle); - void enable_input(input::TextInput* input); + void enable_input(const std::string& title, input::TextInput* input); void disable_input(); input::TextInput* current_input();