Ticket #7772: Deskbar_truncate_label_cleanup.diff

File Deskbar_truncate_label_cleanup.diff, 1.3 KB (added by jscipione, 13 years ago)

A patch that replaces a malloc and free of a char* and a const char* with a single BString.

  • src/apps/deskbar/TeamMenuItem.cpp

    diff --git src/apps/deskbar/TeamMenuItem.cpp src/apps/deskbar/TeamMenuItem.cpp
    index a3f3619..ffbe332 100644
    TTeamMenuItem::DrawContentLabel()  
    445445    if (Submenu() && fVertical)
    446446        cachedWidth += 18;
    447447
    448     const char* label = Label();
    449     char* truncLabel = NULL;
     448    BString label(Label());
    450449    float max = 0;
    451450
    452451    if (static_cast<TBarApp*>(be_app)->Settings()->superExpando && fVertical)
    TTeamMenuItem::DrawContentLabel()  
    458457        BPoint penloc = menu->PenLocation();
    459458        BRect frame = Frame();
    460459        float offset = penloc.x - frame.left;
    461         if (cachedWidth + offset > max) {
    462             truncLabel = (char*)malloc(strlen(label) + 4);
    463             if (!truncLabel)
    464                 return;
    465             TruncateLabel(max-offset, truncLabel);
    466             label = truncLabel;
    467         }
     460        if (cachedWidth + offset > max)
     461            menu->TruncateString(&label, B_TRUNCATE_MIDDLE, max - offset);
    468462    }
    469463
    470464    if (!label)
    471         label = Label();
     465        label = BString(Label());
    472466
    473467    TBarView* barview = (static_cast<TBarApp*>(be_app))->BarView();
    474468    bool canHandle = !barview->Dragging()
    TTeamMenuItem::DrawContentLabel()  
    479473    else
    480474        menu->SetLowColor(menu->ViewColor());
    481475
    482     menu->DrawString(label);
    483 
    484     free(truncLabel);
     476    menu->DrawString(label.String());
    485477}
    486478
    487479