Ticket #7772: Deskbar_truncate_label_cleanup_2.diff

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

There is no reason to check if the label is NULL after truncating since I am using a BString which will not return NULL for a truncated string.

  • src/apps/deskbar/TeamMenuItem.cpp

    diff --git a/src/apps/deskbar/TeamMenuItem.cpp b/src/apps/deskbar/TeamMenuItem.cpp
    index a3f3619..4be5f6c 100644
    a b 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
    470     if (!label)
    471         label = Label();
    472 
    473464    TBarView* barview = (static_cast<TBarApp*>(be_app))->BarView();
    474465    bool canHandle = !barview->Dragging()
    475466        || barview->AppCanHandleTypes(Signature());
    TTeamMenuItem::DrawContentLabel()  
    479470    else
    480471        menu->SetLowColor(menu->ViewColor());
    481472
    482     menu->DrawString(label);
    483 
    484     free(truncLabel);
     473    menu->DrawString(label.String());
    485474}
    486475
    487476