change prototype of Window::Recreate() and throw away almost-duplicated code

This commit is contained in:
Andrzej Rybczak
2009-09-17 02:36:40 +00:00
parent 4426442ed0
commit eee80427fe
4 changed files with 10 additions and 21 deletions

View File

@@ -83,7 +83,7 @@ void Scrollpad::Flush()
space_pos = 0; space_pos = 0;
} }
} }
Recreate(); Recreate(itsWidth, std::max(itsHeight, itsRealHeight));
itsBuffer.SetTemp(&s); itsBuffer.SetTemp(&s);
static_cast<Window &>(*this) << itsBuffer; static_cast<Window &>(*this) << itsBuffer;
itsBuffer.SetTemp(0); itsBuffer.SetTemp(0);
@@ -118,15 +118,6 @@ void Scrollpad::RemoveFormatting()
itsBuffer.RemoveFormatting(itsFoundValueBegin, itsFoundPattern, itsFoundValueEnd, itsFoundForEach); itsBuffer.RemoveFormatting(itsFoundValueBegin, itsFoundPattern, itsFoundValueEnd, itsFoundForEach);
} }
void Scrollpad::Recreate()
{
delwin(itsWindow);
itsWindow = newpad(std::max(itsHeight, itsRealHeight), itsWidth);
SetTimeout(itsWindowTimeout);
SetColor(itsBaseColor, itsBgColor);
keypad(itsWindow, 1);
}
void Scrollpad::Refresh() void Scrollpad::Refresh()
{ {
prefresh(itsWindow, itsBeginning, 0, itsStartY, itsStartX, itsStartY+itsHeight-1, itsStartX+itsWidth-1); prefresh(itsWindow, itsBeginning, 0, itsStartY, itsStartX, itsStartY+itsHeight-1, itsStartX+itsWidth-1);

View File

@@ -119,9 +119,7 @@ namespace NCurses
Scrollpad &operator<<(const std::string &s); Scrollpad &operator<<(const std::string &s);
# endif // _UTF8 # endif // _UTF8
protected: private:
virtual void Recreate();
basic_buffer<my_char_t> itsBuffer; basic_buffer<my_char_t> itsBuffer;
int itsBeginning; int itsBeginning;

View File

@@ -177,7 +177,7 @@ void Window::SetBorder(Border border)
itsStartY--; itsStartY--;
itsHeight += 2; itsHeight += 2;
itsWidth += 2; itsWidth += 2;
Recreate(); Recreate(itsWidth, itsHeight);
} }
else if (border != brNone && itsBorder == brNone) else if (border != brNone && itsBorder == brNone)
{ {
@@ -188,7 +188,7 @@ void Window::SetBorder(Border border)
itsStartY++; itsStartY++;
itsHeight -= 2; itsHeight -= 2;
itsWidth -= 2; itsWidth -= 2;
Recreate(); Recreate(itsWidth, itsHeight);
} }
else else
{ {
@@ -208,13 +208,13 @@ void Window::SetTitle(const std::string &new_title)
{ {
itsStartY += 2; itsStartY += 2;
itsHeight -= 2; itsHeight -= 2;
Recreate(); Recreate(itsWidth, itsHeight);
} }
else if (new_title.empty() && !itsTitle.empty()) else if (new_title.empty() && !itsTitle.empty())
{ {
itsStartY -= 2; itsStartY -= 2;
itsHeight += 2; itsHeight += 2;
Recreate(); Recreate(itsWidth, itsHeight);
} }
itsTitle = new_title; itsTitle = new_title;
} }
@@ -231,10 +231,10 @@ void Window::DeleteHistory()
itsHistory = 0; itsHistory = 0;
} }
void Window::Recreate() void Window::Recreate(size_t width, size_t height)
{ {
delwin(itsWindow); delwin(itsWindow);
itsWindow = newpad(itsHeight, itsWidth); itsWindow = newpad(height, width);
SetTimeout(itsWindowTimeout); SetTimeout(itsWindowTimeout);
SetColor(itsColor, itsBgColor); SetColor(itsColor, itsBgColor);
keypad(itsWindow, 1); keypad(itsWindow, 1);
@@ -273,7 +273,7 @@ void Window::AdjustDimensions(size_t width, size_t height)
void Window::Resize(size_t new_width, size_t new_height) void Window::Resize(size_t new_width, size_t new_height)
{ {
AdjustDimensions(new_width, new_height); AdjustDimensions(new_width, new_height);
Recreate(); Recreate(itsWidth, itsHeight);
} }
void Window::ShowBorder() const void Window::ShowBorder() const

View File

@@ -493,7 +493,7 @@ namespace NCurses
/// @see SetTitle() /// @see SetTitle()
/// @see Resize() /// @see Resize()
/// ///
virtual void Recreate(); virtual void Recreate(size_t width, size_t height);
/// internal WINDOW pointers /// internal WINDOW pointers
WINDOW *itsWindow; WINDOW *itsWindow;