[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. git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@35188 a95241bf-73f2-0310-859d-f6bbb57e9c96
This commit is contained in:
@@ -25,6 +25,7 @@
|
|||||||
#include <MenuBar.h>
|
#include <MenuBar.h>
|
||||||
#include <MenuItem.h>
|
#include <MenuItem.h>
|
||||||
#include <Path.h>
|
#include <Path.h>
|
||||||
|
#include <Screen.h>
|
||||||
#include <ScrollView.h>
|
#include <ScrollView.h>
|
||||||
#include <StringView.h>
|
#include <StringView.h>
|
||||||
#include <TextView.h>
|
#include <TextView.h>
|
||||||
@@ -44,7 +45,7 @@ const uint32 MSG_SHOWCONTENTS = 'mSCT';
|
|||||||
ExpanderWindow::ExpanderWindow(BRect frame, const entry_ref* ref,
|
ExpanderWindow::ExpanderWindow(BRect frame, const entry_ref* ref,
|
||||||
BMessage* settings)
|
BMessage* settings)
|
||||||
:
|
:
|
||||||
BWindow(frame, "Expander", B_TITLED_WINDOW, B_NOT_ZOOMABLE),
|
BWindow(frame, "Expander", B_TITLED_WINDOW, B_NORMAL_WINDOW_FEEL),
|
||||||
fSourcePanel(NULL),
|
fSourcePanel(NULL),
|
||||||
fDestPanel(NULL),
|
fDestPanel(NULL),
|
||||||
fSourceChanged(true),
|
fSourceChanged(true),
|
||||||
@@ -76,10 +77,11 @@ ExpanderWindow::ExpanderWindow(BRect frame, const entry_ref* ref,
|
|||||||
fListingText->SetText("");
|
fListingText->SetText("");
|
||||||
fListingText->MakeEditable(false);
|
fListingText->MakeEditable(false);
|
||||||
fListingText->SetStylable(false);
|
fListingText->SetStylable(false);
|
||||||
|
fListingText->SetWordWrap(false);
|
||||||
BFont font = be_fixed_font;
|
BFont font = be_fixed_font;
|
||||||
fListingText->SetFontAndColor(&font);
|
fListingText->SetFontAndColor(&font);
|
||||||
BScrollView* scrollView = new BScrollView("", fListingText,
|
BScrollView* scrollView = new BScrollView("", fListingText,
|
||||||
B_INVALIDATE_AFTER_LAYOUT, false, true);
|
B_INVALIDATE_AFTER_LAYOUT, true, true);
|
||||||
|
|
||||||
BView* topView = layout->View();
|
BView* topView = layout->View();
|
||||||
const float spacing = be_control_look->DefaultItemSpacing();
|
const float spacing = be_control_look->DefaultItemSpacing();
|
||||||
@@ -111,6 +113,8 @@ ExpanderWindow::ExpanderWindow(BRect frame, const entry_ref* ref,
|
|||||||
|
|
||||||
ResizeTo(Bounds().Width(), fSizeLimit);
|
ResizeTo(Bounds().Width(), fSizeLimit);
|
||||||
SetSizeLimits(size.Width(), 32767.0f, fSizeLimit, fSizeLimit);
|
SetSizeLimits(size.Width(), 32767.0f, fSizeLimit, fSizeLimit);
|
||||||
|
SetZoomLimits(Bounds().Width(), fSizeLimit);
|
||||||
|
fPreviousHeight = -1;
|
||||||
|
|
||||||
Show();
|
Show();
|
||||||
}
|
}
|
||||||
@@ -157,19 +161,6 @@ ExpanderWindow::ValidateDest()
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
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
|
void
|
||||||
ExpanderWindow::MessageReceived(BMessage* msg)
|
ExpanderWindow::MessageReceived(BMessage* msg)
|
||||||
{
|
{
|
||||||
@@ -318,12 +309,11 @@ ExpanderWindow::MessageReceived(BMessage* msg)
|
|||||||
BString string;
|
BString string;
|
||||||
int32 i = 0;
|
int32 i = 0;
|
||||||
while (msg->FindString("output", i++, &string) == B_OK) {
|
while (msg->FindString("output", i++, &string) == B_OK) {
|
||||||
// expand the window if we need...
|
float length = fListingText->StringWidth(string.String());
|
||||||
float delta = fListingText->StringWidth(string.String())
|
|
||||||
- fListingText->Frame().Width();
|
if (length > fLongestLine)
|
||||||
if (delta > fLargestDelta) {
|
fLongestLine = length;
|
||||||
fLargestDelta = delta;
|
|
||||||
}
|
|
||||||
fListingText->Insert(string.String());
|
fListingText->Insert(string.String());
|
||||||
}
|
}
|
||||||
fListingText->ScrollToSelection();
|
fListingText->ScrollToSelection();
|
||||||
@@ -338,12 +328,10 @@ ExpanderWindow::MessageReceived(BMessage* msg)
|
|||||||
StopExpanding();
|
StopExpanding();
|
||||||
OpenDestFolder();
|
OpenDestFolder();
|
||||||
CloseWindowOrKeepOpen();
|
CloseWindowOrKeepOpen();
|
||||||
} else if (fListingStarted){
|
} else if (fListingStarted) {
|
||||||
fSourceChanged = false;
|
fSourceChanged = false;
|
||||||
StopListing();
|
StopListing();
|
||||||
if (fLargestDelta > 0.0f)
|
_ExpandListingText();
|
||||||
ResizeBy(fLargestDelta, 0.0f);
|
|
||||||
fLargestDelta = 0.0f;
|
|
||||||
} else
|
} else
|
||||||
fStatusView->SetText("");
|
fStatusView->SetText("");
|
||||||
break;
|
break;
|
||||||
@@ -562,6 +550,38 @@ ExpanderWindow::StopExpanding(void)
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
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
|
void
|
||||||
ExpanderWindow::_UpdateWindowSize(bool showContents)
|
ExpanderWindow::_UpdateWindowSize(bool showContents)
|
||||||
{
|
{
|
||||||
@@ -571,17 +591,25 @@ ExpanderWindow::_UpdateWindowSize(bool showContents)
|
|||||||
float bottom = fSizeLimit;
|
float bottom = fSizeLimit;
|
||||||
|
|
||||||
if (showContents) {
|
if (showContents) {
|
||||||
font_height fontHeight;
|
if (fPreviousHeight < 0.0) {
|
||||||
be_plain_font->GetHeight(&fontHeight);
|
BFont font;
|
||||||
float lineHeight = ceilf(fontHeight.ascent + fontHeight.descent
|
font_height fontHeight;
|
||||||
+ fontHeight.leading);
|
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;
|
maxHeight = 32767.0;
|
||||||
bottom = minHeight + 10.0 * lineHeight;
|
bottom = fPreviousHeight;
|
||||||
} else {
|
} else {
|
||||||
minHeight = fSizeLimit;
|
minHeight = fSizeLimit;
|
||||||
maxHeight = fSizeLimit;
|
maxHeight = fSizeLimit;
|
||||||
|
fPreviousHeight = Frame().Height();
|
||||||
}
|
}
|
||||||
|
|
||||||
SetSizeLimits(minWidth, maxWidth, minHeight, maxHeight);
|
SetSizeLimits(minWidth, maxWidth, minHeight, maxHeight);
|
||||||
@@ -594,11 +622,13 @@ ExpanderWindow::StartListing()
|
|||||||
{
|
{
|
||||||
_UpdateWindowSize(true);
|
_UpdateWindowSize(true);
|
||||||
|
|
||||||
fLargestDelta = 0.0f;
|
|
||||||
|
|
||||||
if (!fSourceChanged)
|
if (!fSourceChanged)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
|
fPreviousHeight = -1.0;
|
||||||
|
|
||||||
|
fLongestLine = 0.0f;
|
||||||
|
|
||||||
ExpanderRule* rule = fRules.MatchingRule(&fSourceRef);
|
ExpanderRule* rule = fRules.MatchingRule(&fSourceRef);
|
||||||
if (!rule)
|
if (!rule)
|
||||||
return;
|
return;
|
||||||
|
|||||||
@@ -34,7 +34,6 @@ public:
|
|||||||
const entry_ref* ref, BMessage* settings);
|
const entry_ref* ref, BMessage* settings);
|
||||||
virtual ~ExpanderWindow();
|
virtual ~ExpanderWindow();
|
||||||
|
|
||||||
virtual void FrameResized(float width, float height);
|
|
||||||
virtual void MessageReceived(BMessage* msg);
|
virtual void MessageReceived(BMessage* msg);
|
||||||
virtual bool QuitRequested();
|
virtual bool QuitRequested();
|
||||||
|
|
||||||
@@ -52,6 +51,7 @@ private:
|
|||||||
void StartExpanding();
|
void StartExpanding();
|
||||||
void StopExpanding();
|
void StopExpanding();
|
||||||
void _UpdateWindowSize(bool showContents);
|
void _UpdateWindowSize(bool showContents);
|
||||||
|
void _ExpandListingText();
|
||||||
void StartListing();
|
void StartListing();
|
||||||
void StopListing();
|
void StopListing();
|
||||||
bool ValidateDest();
|
bool ValidateDest();
|
||||||
@@ -90,8 +90,10 @@ private:
|
|||||||
ExpanderPreferences* fPreferences;
|
ExpanderPreferences* fPreferences;
|
||||||
ExpanderRules fRules;
|
ExpanderRules fRules;
|
||||||
|
|
||||||
float fLargestDelta;
|
float fLongestLine;
|
||||||
|
float fLineHeight;
|
||||||
float fSizeLimit;
|
float fSizeLimit;
|
||||||
|
float fPreviousHeight;
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif /* EXPANDER_WINDOW_H */
|
#endif /* EXPANDER_WINDOW_H */
|
||||||
|
|||||||
Reference in New Issue
Block a user