Author: stpere Date: 2010-01-20 00:31:58 +0100 (Wed, 20 Jan 2010) New Revision: 35188 Changeset: http://dev.haiku-os.org/changeset/35188/haiku Ticket: http://dev.haiku-os.org/ticket/5280 Modified: haiku/trunk/src/apps/expander/ExpanderWindow.cpp haiku/trunk/src/apps/expander/ExpanderWindow.h Log: [Expander] : Window Sizing enhancements * Now takes the screen size into consideration when enlarging the window (fixing ticket #5280) * Enables Zooming capabilities * Remembers the last height of the window so that clicking Show contents on and off just returns it to the previous height. Modified: haiku/trunk/src/apps/expander/ExpanderWindow.cpp =================================================================== --- haiku/trunk/src/apps/expander/ExpanderWindow.cpp 2010-01-19 23:29:15 UTC (rev 35187) +++ haiku/trunk/src/apps/expander/ExpanderWindow.cpp 2010-01-19 23:31:58 UTC (rev 35188) @@ -25,6 +25,7 @@ #include <MenuBar.h> #include <MenuItem.h> #include <Path.h> +#include <Screen.h> #include <ScrollView.h> #include <StringView.h> #include <TextView.h> @@ -44,7 +45,7 @@ ExpanderWindow::ExpanderWindow(BRect frame, const entry_ref* ref, BMessage* settings) : - BWindow(frame, "Expander", B_TITLED_WINDOW, B_NOT_ZOOMABLE), + BWindow(frame, "Expander", B_TITLED_WINDOW, B_NORMAL_WINDOW_FEEL), fSourcePanel(NULL), fDestPanel(NULL), fSourceChanged(true), @@ -76,10 +77,11 @@ fListingText->SetText(""); fListingText->MakeEditable(false); fListingText->SetStylable(false); + fListingText->SetWordWrap(false); BFont font = be_fixed_font; fListingText->SetFontAndColor(&font); BScrollView* scrollView = new BScrollView("", fListingText, - B_INVALIDATE_AFTER_LAYOUT, false, true); + B_INVALIDATE_AFTER_LAYOUT, true, true); BView* topView = layout->View(); const float spacing = be_control_look->DefaultItemSpacing(); @@ -111,6 +113,8 @@ ResizeTo(Bounds().Width(), fSizeLimit); SetSizeLimits(size.Width(), 32767.0f, fSizeLimit, fSizeLimit); + SetZoomLimits(Bounds().Width(), fSizeLimit); + fPreviousHeight = -1; Show(); } @@ -158,19 +162,6 @@ void -ExpanderWindow::FrameResized(float width, float height) -{ - if (fListingText->DoesWordWrap()) { - BRect textRect; - textRect = fListingText->Bounds(); - textRect.OffsetTo(B_ORIGIN); - textRect.InsetBy(1, 1); - fListingText->SetTextRect(textRect); - } -} - - -void ExpanderWindow::MessageReceived(BMessage* msg) { switch (msg->what) { @@ -318,12 +309,11 @@ BString string; int32 i = 0; while (msg->FindString("output", i++, &string) == B_OK) { - // expand the window if we need... - float delta = fListingText->StringWidth(string.String()) - - fListingText->Frame().Width(); - if (delta > fLargestDelta) { - fLargestDelta = delta; - } + float length = fListingText->StringWidth(string.String()); + + if (length > fLongestLine) + fLongestLine = length; + fListingText->Insert(string.String()); } fListingText->ScrollToSelection(); @@ -338,12 +328,10 @@ StopExpanding(); OpenDestFolder(); CloseWindowOrKeepOpen(); - } else if (fListingStarted){ + } else if (fListingStarted) { fSourceChanged = false; StopListing(); - if (fLargestDelta > 0.0f) - ResizeBy(fLargestDelta, 0.0f); - fLargestDelta = 0.0f; + _ExpandListingText(); } else fStatusView->SetText(""); break; @@ -563,6 +551,38 @@ void +ExpanderWindow::_ExpandListingText() +{ + float delta = fLongestLine - fListingText->Frame().Width(); + + if (delta > 0) { + BScreen screen; + BRect screenFrame = screen.Frame(); + + if (Frame().right + delta > screenFrame.right) + delta = screenFrame.right - Frame().right - 4.0f; + + ResizeBy(delta, 0.0f); + } + + float minWidth, maxWidth, minHeight, maxHeight; + GetSizeLimits(&minWidth, &maxWidth, &minHeight, &maxHeight); + + if (minWidth < Frame().Width() + delta) { + // set the Zoom limit as the minimal required size + SetZoomLimits(Frame().Width() + delta, + fSizeLimit + fListingText->TextRect().Height() + + fLineHeight + B_H_SCROLL_BAR_HEIGHT + 1.0f); + } else { + // set the zoom limit based on minimal window size allowed + SetZoomLimits(minWidth, + fSizeLimit + fListingText->TextRect().Height() + + fLineHeight + B_H_SCROLL_BAR_HEIGHT + 1.0f); + } +} + + +void ExpanderWindow::_UpdateWindowSize(bool showContents) { float minWidth, maxWidth, minHeight, maxHeight; @@ -571,17 +591,25 @@ float bottom = fSizeLimit; if (showContents) { - font_height fontHeight; - be_plain_font->GetHeight(&fontHeight); - float lineHeight = ceilf(fontHeight.ascent + fontHeight.descent - + fontHeight.leading); + if (fPreviousHeight < 0.0) { + BFont font; + font_height fontHeight; + fListingText->GetFont(&font); + font.GetHeight(&fontHeight); + fLineHeight = ceilf(fontHeight.ascent + fontHeight.descent + + fontHeight.leading); - minHeight = bottom + 5.0 * lineHeight; + minHeight = bottom + 5.0 * fLineHeight; + maxHeight = 32767.0; + fPreviousHeight = minHeight + 10.0 * fLineHeight; + } + minHeight = bottom + 5.0 * fLineHeight; maxHeight = 32767.0; - bottom = minHeight + 10.0 * lineHeight; + bottom = fPreviousHeight; } else { minHeight = fSizeLimit; maxHeight = fSizeLimit; + fPreviousHeight = Frame().Height(); } SetSizeLimits(minWidth, maxWidth, minHeight, maxHeight); @@ -594,11 +622,13 @@ { _UpdateWindowSize(true); - fLargestDelta = 0.0f; - if (!fSourceChanged) return; + fPreviousHeight = -1.0; + + fLongestLine = 0.0f; + ExpanderRule* rule = fRules.MatchingRule(&fSourceRef); if (!rule) return; Modified: haiku/trunk/src/apps/expander/ExpanderWindow.h =================================================================== --- haiku/trunk/src/apps/expander/ExpanderWindow.h 2010-01-19 23:29:15 UTC (rev 35187) +++ haiku/trunk/src/apps/expander/ExpanderWindow.h 2010-01-19 23:31:58 UTC (rev 35188) @@ -34,7 +34,6 @@ const entry_ref* ref, BMessage* settings); virtual ~ExpanderWindow(); - virtual void FrameResized(float width, float height); virtual void MessageReceived(BMessage* msg); virtual bool QuitRequested(); @@ -52,6 +51,7 @@ void StartExpanding(); void StopExpanding(); void _UpdateWindowSize(bool showContents); + void _ExpandListingText(); void StartListing(); void StopListing(); bool ValidateDest(); @@ -90,8 +90,10 @@ ExpanderPreferences* fPreferences; ExpanderRules fRules; - float fLargestDelta; + float fLongestLine; + float fLineHeight; float fSizeLimit; + float fPreviousHeight; }; #endif /* EXPANDER_WINDOW_H */