Ticket #5280: patch

File patch, 4.1 KB (added by stpere, 14 years ago)

Potential solution

  • src/apps/expander/ExpanderWindow.cpp

     
    2525#include <MenuBar.h>
    2626#include <MenuItem.h>
    2727#include <Path.h>
     28#include <Screen.h>
    2829#include <ScrollView.h>
    2930#include <StringView.h>
    3031#include <TextView.h>
     
    7677    fListingText->SetText("");
    7778    fListingText->MakeEditable(false);
    7879    fListingText->SetStylable(false);
     80    fListingText->SetWordWrap(false);
    7981    BFont font = be_fixed_font;
    8082    fListingText->SetFontAndColor(&font);
    8183    BScrollView* scrollView = new BScrollView("", fListingText,
    82         B_INVALIDATE_AFTER_LAYOUT, false, true);
     84        B_INVALIDATE_AFTER_LAYOUT, true, true);
    8385
    8486    BView* topView = layout->View();
    8587    const float spacing = be_control_look->DefaultItemSpacing();
     
    158160
    159161
    160162void
    161 ExpanderWindow::FrameResized(float width, float height)
    162 {
    163     if (fListingText->DoesWordWrap()) {
    164         BRect textRect;
    165         textRect = fListingText->Bounds();
    166         textRect.OffsetTo(B_ORIGIN);
    167         textRect.InsetBy(1, 1);
    168         fListingText->SetTextRect(textRect);
    169     }
    170 }
    171 
    172 
    173 void
    174163ExpanderWindow::MessageReceived(BMessage* msg)
    175164{
    176165    switch (msg->what) {
     
    318307                BString string;
    319308                int32 i = 0;
    320309                while (msg->FindString("output", i++, &string) == B_OK) {
    321                     // expand the window if we need...
    322                     float delta = fListingText->StringWidth(string.String())
    323                         - fListingText->Frame().Width();
    324                     if (delta > fLargestDelta) {
    325                         fLargestDelta = delta;
    326                     }
     310                    float lineLength = fListingText->StringWidth(string.String());
     311
     312                    if (lineLength > fLongestLine)
     313                        fLongestLine = lineLength;
     314
    327315                    fListingText->Insert(string.String());
    328316                }
    329317                fListingText->ScrollToSelection();
     
    338326                StopExpanding();
    339327                OpenDestFolder();
    340328                CloseWindowOrKeepOpen();
    341             } else if (fListingStarted){
     329            } else if (fListingStarted) {
    342330                fSourceChanged = false;
    343331                StopListing();
    344                 if (fLargestDelta > 0.0f)
    345                     ResizeBy(fLargestDelta, 0.0f);
    346                 fLargestDelta = 0.0f;
     332
     333                _ExpandListingText();
    347334            } else
    348335                fStatusView->SetText("");
    349336            break;
     
    563550
    564551
    565552void
     553ExpanderWindow::_ExpandListingText()
     554{
     555    if (fLongestLine > fListingText->Frame().Width()) {
     556        BScreen screen;
     557        BRect screenFrame = screen.Frame();
     558        float delta = fLongestLine - fListingText->Frame().Width();
     559                   
     560        if (Frame().right + delta > screenFrame.right)
     561            delta = screenFrame.right - Frame().right - 4.0f;
     562   
     563        ResizeBy(delta, 0.0f);
     564    }
     565}
     566
     567
     568void
    566569ExpanderWindow::_UpdateWindowSize(bool showContents)
    567570{
    568571    float minWidth, maxWidth, minHeight, maxHeight;
     
    571574    float bottom = fSizeLimit;
    572575
    573576    if (showContents) {
     577        BFont font;
    574578        font_height fontHeight;
    575         be_plain_font->GetHeight(&fontHeight);
     579        fListingText->GetFont(&font);       
     580        font.GetHeight(&fontHeight);
    576581        float lineHeight = ceilf(fontHeight.ascent + fontHeight.descent
    577582            + fontHeight.leading);
    578583
     
    594599{
    595600    _UpdateWindowSize(true);
    596601
    597     fLargestDelta = 0.0f;
    598 
    599     if (!fSourceChanged)
     602    if (!fSourceChanged) {
     603        _ExpandListingText();
    600604        return;
     605    }
    601606
     607    fLongestLine = 0.0f;
     608
    602609    ExpanderRule* rule = fRules.MatchingRule(&fSourceRef);
    603610    if (!rule)
    604611        return;
  • src/apps/expander/ExpanderWindow.h

     
    3434                                    const entry_ref* ref, BMessage* settings);
    3535    virtual                     ~ExpanderWindow();
    3636
    37     virtual void                FrameResized(float width, float height);
    3837    virtual void                MessageReceived(BMessage* msg);
    3938    virtual bool                QuitRequested();
    4039
     
    5251            void                StartExpanding();
    5352            void                StopExpanding();
    5453            void                _UpdateWindowSize(bool showContents);
     54            void                _ExpandListingText();
    5555            void                StartListing();
    5656            void                StopListing();
    5757            bool                ValidateDest();
     
    9090            ExpanderPreferences*    fPreferences;
    9191            ExpanderRules       fRules;
    9292
    93             float               fLargestDelta;
     93            float               fLongestLine;
    9494            float               fSizeLimit;
    9595};
    9696