BorderlessTextButton

FWCollectionSummaryWidgetConnectionHolder

R__dummyintdefault661_c

Line Code
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661
// -*- C++ -*-
//
// Package:     Core
// Class  :     FWCollectionSummaryWidget
//
// Implementation:
//     <Notes on implementation>
//
// Original Author:  Chris Jones
//         Created:  Sat Feb 14 10:02:32 CST 2009
//

// system include files
#include <iostream>
#include <vector>
#include <functional>
#include "TGButton.h"
#include "TGResourcePool.h"
#include "TVirtualX.h"
#include "Fireworks/Core/src/FWColorSelect.h"
#include "Fireworks/Core/src/FWBoxIconButton.h"
#include "Fireworks/Core/src/FWCheckBoxIcon.h"
#include "Fireworks/Core/src/FWColorBoxIcon.h"

// user include files
#include "Fireworks/Core/src/FWCollectionSummaryWidget.h"
#include "Fireworks/Core/interface/FWEventItem.h"
#include "Fireworks/Core/interface/FWCustomIconsButton.h"

#include "Fireworks/Core/src/FWCollectionSummaryTableManager.h"
#include "Fireworks/TableWidget/interface/FWTableWidget.h"

#include "Fireworks/Core/interface/FWSelectionManager.h"
#include "Fireworks/Core/interface/FWModelChangeManager.h"
#include "Fireworks/Core/interface/FWColorManager.h"

//
// constants, enums and typedefs
//
struct FWCollectionSummaryWidgetConnectionHolder {
  std::vector<sigc::connection> m_connections;

  ~FWCollectionSummaryWidgetConnectionHolder() {
    for_each(
        m_connections.begin(), m_connections.end(), std::bind(&sigc::connection::disconnect, std::placeholders::_1));
  }
  void push_back(const sigc::connection& iC) { m_connections.push_back(iC); }
  void reserve(size_t iSize) { m_connections.reserve(iSize); }
};

//
// static data member definitions
//
namespace {
  class BorderlessTextButton : public TGTextButton {
  public:
    BorderlessTextButton(const TGWindow* p = nullptr,
                         const char* s = nullptr,
                         Int_t id = -1,
                         GContext_t norm = GetDefaultGC()(),
                         FontStruct_t font = GetDefaultFontStruct())
        : TGTextButton(p, s, id, norm, font, 0) {
      //by default, it uses too much padding
      fMTop = -3;
      fMBottom = -3;
    }

    void DoRedraw() override;
  };

  void BorderlessTextButton::DoRedraw() {
    gVirtualX->ClearArea(fId, fBorderWidth, fBorderWidth, fWidth - (fBorderWidth << 1), fHeight - (fBorderWidth << 1));
    //TGFrame::DoRedraw();

    int x, y;
    if (fTMode & kTextLeft) {
      x = fMLeft + 4;
    } else if (fTMode & kTextRight) {
      x = fWidth - fTWidth - fMRight - 4;
    } else {
      x = (fWidth - fTWidth + fMLeft - fMRight) >> 1;
    }

    if (fTMode & kTextTop) {
      y = fMTop + 3;
    } else if (fTMode & kTextBottom) {
      y = fHeight - fTHeight - fMBottom - 3;
    } else {
      y = (fHeight - fTHeight + fMTop - fMBottom) >> 1;
    }

    Int_t hotpos = fLabel->GetHotPos();

    fTLayout->DrawText(fId, fNormGC, x, y, 0, -1);
    if (hotpos)
      fTLayout->UnderlineChar(fId, fNormGC, x, y, hotpos - 1);
  }
}  // namespace

static const TGPicture* filtered(bool iBackgroundIsBlack) {
  if (iBackgroundIsBlack) {
    static const TGPicture* s = gClient->GetPicture(FWCheckBoxIcon::coreIcondir() + "filtered-blackbg.png");
    return s;
  }
  static const TGPicture* s = gClient->GetPicture(FWCheckBoxIcon::coreIcondir() + "filtered-whitebg.png");
  return s;
}

static const TGPicture* filtered_over(bool iBackgroundIsBlack) {
  if (iBackgroundIsBlack) {
    static const TGPicture* s = gClient->GetPicture(FWCheckBoxIcon::coreIcondir() + "filtered-whitebg-over.png");
    return s;
  }
  static const TGPicture* s = gClient->GetPicture(FWCheckBoxIcon::coreIcondir() + "filtered-whitebg-over.png");
  return s;
}

static const TGPicture* alert_over(bool iBackgroundIsBlack) {
  if (iBackgroundIsBlack) {
    static const TGPicture* s = gClient->GetPicture(FWCheckBoxIcon::coreIcondir() + "icon-alert-blackbg-over.png");
    return s;
  }
  static const TGPicture* s = gClient->GetPicture(FWCheckBoxIcon::coreIcondir() + "icon-alert-whitebg-over.png");
  return s;
}

static const TGPicture* alert(bool iBackgroundIsBlack) {
  if (iBackgroundIsBlack) {
    static const TGPicture* s = gClient->GetPicture(FWCheckBoxIcon::coreIcondir() + "icon-alert-blackbg.png");
    return s;
  }
  static const TGPicture* s = gClient->GetPicture(FWCheckBoxIcon::coreIcondir() + "icon-alert-whitebg.png");
  return s;
}

static const TGPicture* unfiltered(bool iBackgroundIsBlack) {
  if (iBackgroundIsBlack) {
    static const TGPicture* s = gClient->GetPicture(FWCheckBoxIcon::coreIcondir() + "unfiltered-blackbg.png");
    return s;
  }
  static const TGPicture* s = gClient->GetPicture(FWCheckBoxIcon::coreIcondir() + "unfiltered-whitebg.png");
  return s;
}
static const TGPicture* unfiltered_over(bool iBackgroundIsBlack) {
  if (iBackgroundIsBlack) {
    static const TGPicture* s = gClient->GetPicture(FWCheckBoxIcon::coreIcondir() + "unfiltered-blackbg-over.png");
    return s;
  }
  static const TGPicture* s = gClient->GetPicture(FWCheckBoxIcon::coreIcondir() + "unfiltered-whitebg-over.png");
  return s;
}

static const TGPicture* info(bool iBackgroundIsBlack) {
  if (iBackgroundIsBlack) {
    static const TGPicture* s = gClient->GetPicture(FWCheckBoxIcon::coreIcondir() + "info2-blackbg.png");
    return s;
  }
  static const TGPicture* s = gClient->GetPicture(FWCheckBoxIcon::coreIcondir() + "info2-whitebg.png");
  return s;
}

static const TGPicture* info_over(bool iBackgroundIsBlack) {
  if (iBackgroundIsBlack) {
    static const TGPicture* s = gClient->GetPicture(FWCheckBoxIcon::coreIcondir() + "info2-blackbg-over.png");
    return s;
  }
  static const TGPicture* s = gClient->GetPicture(FWCheckBoxIcon::coreIcondir() + "info2-whitebg-over.png");
  return s;
}

static const TGPicture* info_disabled(bool iBackgroundIsBlack) {
  if (iBackgroundIsBlack) {
    static const TGPicture* s = gClient->GetPicture(FWCheckBoxIcon::coreIcondir() + "info2-blackbg-disabled.png");
    return s;
  }
  static const TGPicture* s = gClient->GetPicture(FWCheckBoxIcon::coreIcondir() + "info2-whitebg-disabled.png");
  return s;
}

static const TGPicture* arrow_right(bool iBackgroundIsBlack) {
  if (iBackgroundIsBlack) {
    static const TGPicture* s = gClient->GetPicture(FWCheckBoxIcon::coreIcondir() + "arrow-white-right-blackbg.png");
    return s;
  }
  static const TGPicture* s = gClient->GetPicture(FWCheckBoxIcon::coreIcondir() + "arrow-black-right-whitebg.png");
  return s;
}

static const TGPicture* arrow_right_disabled(bool iBackgroundIsBlack) {
  if (iBackgroundIsBlack) {
    static const TGPicture* s =
        gClient->GetPicture(FWCheckBoxIcon::coreIcondir() + "arrow-white-right-disabled-blackbg.png");
    return s;
  }
  static const TGPicture* s =
      gClient->GetPicture(FWCheckBoxIcon::coreIcondir() + "arrow-black-right-disabled-whitebg.png");
  return s;
}

static const TGPicture* arrow_down(bool iBackgroundIsBlack) {
  if (iBackgroundIsBlack) {
    static const TGPicture* s = gClient->GetPicture(FWCheckBoxIcon::coreIcondir() + "arrow-white-down-blackbg.png");
    return s;
  }
  static const TGPicture* s = gClient->GetPicture(FWCheckBoxIcon::coreIcondir() + "arrow-black-down-whitebg.png");
  return s;
}

static const TGPicture* arrow_down_disabled(bool iBackgroundIsBlack) {
  if (iBackgroundIsBlack) {
    static const TGPicture* s =
        gClient->GetPicture(FWCheckBoxIcon::coreIcondir() + "arrow-white-down-disabled-blackbg.png");
    return s;
  }
  static const TGPicture* s =
      gClient->GetPicture(FWCheckBoxIcon::coreIcondir() + "arrow-black-down-disabled-whitebg.png");
  return s;
}

static const unsigned long kWidgetColor = 0x2f2f2f;
static const unsigned long kWidgetColorLight = 0xdfdfdf;
//
// constructors and destructor
//
FWCollectionSummaryWidget::FWCollectionSummaryWidget(TGFrame* iParent, FWEventItem& iItem, TGLayoutHints* iHints)
    : TGCompositeFrame(iParent),
      m_collection(&iItem),
      m_hints(iHints),
      m_parent(iParent),
      m_collectionShown(false),
      m_tableContext(nullptr),
      m_indexForColor(-1),
      m_colorPopup(nullptr),
      m_tableManager(nullptr),
      m_tableWidget(nullptr),
      m_backgroundIsWhite(false),
      m_connectionHolder(new FWCollectionSummaryWidgetConnectionHolder) {
  SetBackgroundColor(kWidgetColor);
  const unsigned int backgroundColor = kBlack;

  TGCompositeFrame* hFrame = new TGHorizontalFrame(this, 10, 10, 0, backgroundColor);
  m_holder = hFrame;
  this->AddFrame(hFrame, new TGLayoutHints(kLHintsTop | kLHintsExpandX));

  m_showHideButton = new FWCustomIconsButton(this,
                                             arrow_right(!m_backgroundIsWhite),
                                             arrow_right_disabled(!m_backgroundIsWhite),
                                             arrow_right_disabled(!m_backgroundIsWhite));
  m_showHideButton->Connect("Clicked()", "FWCollectionSummaryWidget", this, "toggleShowHide()");
  m_showHideButton->SetToolTipText("show/hide individual collection items");
  m_collectionShown = false;
  hFrame->AddFrame(m_showHideButton, new TGLayoutHints(kLHintsCenterY | kLHintsLeft, 6, 10));

  //m_isVisibleButton = new TGCheckButton(this,"");
  //m_isVisibleButton->SetState(kButtonDown, kFALSE);
  m_isVisibleCheckBox = new FWCheckBoxIcon(12);
  m_isVisibleButton = new FWBoxIconButton(this, m_isVisibleCheckBox, -1, GetWhiteGC()());
  m_isVisibleButton->SetBackgroundColor(backgroundColor);
  m_isVisibleButton->SetToolTipText("make all items in collection visible/invisible");
  hFrame->AddFrame(m_isVisibleButton, new TGLayoutHints(kLHintsCenterY | kLHintsLeft, 0, 1));
  m_isVisibleButton->Connect("Clicked()", "FWCollectionSummaryWidget", this, "toggleItemVisible()");

  m_colorSelectBox = new FWColorBoxIcon(12);
  m_colorSelectWidget = new FWBoxIconButton(this, m_colorSelectBox, -1, GetWhiteGC()());
  hFrame->AddFrame(m_colorSelectWidget, new TGLayoutHints(kLHintsCenterY | kLHintsLeft, 1));
  //m_colorSelectWidget->Connect("ColorSelected(Pixel_t)", "FWCollectionSummaryWidget", this, "colorChangeRequested(Pixel_t)");
  m_colorSelectWidget->Connect("Clicked()", "FWCollectionSummaryWidget", this, "colorClicked()");
  m_colorSelectWidget->SetBackgroundColor(backgroundColor);
  m_colorSelectWidget->SetToolTipText("set default color of items in collection");
  GCValues_t t = *(GetWhiteGC().GetAttributes());
  m_graphicsContext = gClient->GetResourcePool()->GetGCPool()->GetGC(&t, kTRUE);
  m_colorSelectBox->setColor(m_graphicsContext->GetGC());

  m_label = new BorderlessTextButton(this, m_collection->name().c_str());
  m_label->SetBackgroundColor(backgroundColor);
  m_label->SetTextJustify(kTextLeft | kTextCenterY);
  m_label->SetTextColor(static_cast<Pixel_t>(gVirtualX->GetPixel(kWhite)));
  hFrame->AddFrame(m_label, new TGLayoutHints(kLHintsCenterY | kLHintsLeft | kLHintsExpandX, 5, 5));
  m_label->Connect("Clicked()", "FWCollectionSummaryWidget", this, "labelClicked()");
  m_label->SetToolTipText("select collection and show controller");

  m_stateButton = new FWCustomIconsButton(this,
                                          unfiltered(!m_backgroundIsWhite),
                                          unfiltered_over(!m_backgroundIsWhite),
                                          unfiltered_over(!m_backgroundIsWhite));
  hFrame->AddFrame(m_stateButton, new TGLayoutHints(kLHintsCenterY | kLHintsLeft));
  itemChanged();
  displayChanged();
  m_stateButton->Connect("Clicked()", "FWCollectionSummaryWidget", this, "stateClicked()");
  m_stateButton->SetToolTipText("select collection and show filter");

  m_infoButton = new FWCustomIconsButton(
      this, info(!m_backgroundIsWhite), info_over(!m_backgroundIsWhite), info_disabled(!m_backgroundIsWhite));
  hFrame->AddFrame(m_infoButton, new TGLayoutHints(kLHintsCenterY | kLHintsRight, 2, 2));
  m_infoButton->Connect("Clicked()", "FWCollectionSummaryWidget", this, "infoClicked()");
  m_infoButton->SetToolTipText("select collection and show data info");

  m_connectionHolder->reserve(3);
  m_connectionHolder->push_back(m_collection->defaultDisplayPropertiesChanged_.connect(
      std::bind(&FWCollectionSummaryWidget::displayChanged, this)));
  m_connectionHolder->push_back(
      m_collection->itemChanged_.connect(std::bind(&FWCollectionSummaryWidget::itemChanged, this)));
  m_connectionHolder->push_back(
      m_collection->filterChanged_.connect(std::bind(&FWCollectionSummaryWidget::itemChanged, this)));

  MapSubwindows();
  Layout();
  MapWindow();
}

// FWCollectionSummaryWidget::FWCollectionSummaryWidget(const FWCollectionSummaryWidget& rhs)
// {
//    // do actual copying here;
// }

FWCollectionSummaryWidget::~FWCollectionSummaryWidget() {
  delete m_colorPopup;
  /* the following deletes lead to an infinite loop at the end of the job
   delete m_hints;
   delete m_showHideButton;
   delete m_isVisibleButton;
   delete m_colorSelectWidget;
   delete m_stateButton;
   delete m_infoButton;
    */
  gClient->GetResourcePool()->GetGCPool()->FreeGC(m_graphicsContext->GetGC());
  delete m_connectionHolder;
}

//
// assignment operators
//
// const FWCollectionSummaryWidget& FWCollectionSummaryWidget::operator=(const FWCollectionSummaryWidget& rhs)
// {
//   //An exception safe implementation is
//   FWCollectionSummaryWidget temp(rhs);
//   swap(rhs);
//
//   return *this;
// }

//
// member functions
//
static void setLabelBackgroundColor(TGTextButton* iLabel, bool iIsSelected, bool iBackgroundIsWhite) {
  if (iIsSelected) {
    if (iBackgroundIsWhite) {
      iLabel->SetBackgroundColor(0x7777FF);
    } else {
      iLabel->SetBackgroundColor(0x0000FF);
    }
  } else {
    if (iBackgroundIsWhite) {
      iLabel->SetBackgroundColor(0xFFFFFF);
    } else {
      iLabel->SetBackgroundColor(0x000000);
    }
  }
}

void FWCollectionSummaryWidget::displayChanged() {
  m_graphicsContext->SetForeground(gVirtualX->GetPixel(m_collection->defaultDisplayProperties().color()));
  fClient->NeedRedraw(m_colorSelectWidget);
  m_isVisibleCheckBox->setChecked(m_collection->defaultDisplayProperties().isVisible());
  fClient->NeedRedraw(m_isVisibleButton);
  setLabelBackgroundColor(m_label, m_collection->itemIsSelected(), m_backgroundIsWhite);
  fClient->NeedRedraw(m_label);
}

void FWCollectionSummaryWidget::itemChanged() {
  const TGPicture* picture = nullptr;
  const TGPicture* down = nullptr;
  const TGPicture* disabled = nullptr;
  if (m_collection->hasError()) {
    picture = alert(!m_backgroundIsWhite);
    down = alert_over(!m_backgroundIsWhite);
    disabled = alert_over(!m_backgroundIsWhite);
    m_stateButton->SetToolTipText(m_collection->errorMessage().c_str());
  } else {
    if (!m_collection->filterExpression().empty()) {
      picture = filtered(!m_backgroundIsWhite);
      down = filtered_over(!m_backgroundIsWhite);
      disabled = filtered_over(!m_backgroundIsWhite);
    } else {
      picture = unfiltered(!m_backgroundIsWhite);
      down = unfiltered_over(!m_backgroundIsWhite);
      disabled = unfiltered_over(!m_backgroundIsWhite);
    }
    m_stateButton->SetToolTipText("select collection and show filter");
  }
  m_stateButton->swapIcons(picture, down, disabled);
}

void FWCollectionSummaryWidget::colorChangeRequested(Color_t color) {
  if (-1 == m_indexForColor) {
    FWDisplayProperties changeProperties = m_collection->defaultDisplayProperties();
    changeProperties.setColor(color);
    m_collection->setDefaultDisplayProperties(changeProperties);
    return;
  }

  FWDisplayProperties changeProperties = m_collection->modelInfo(m_indexForColor).displayProperties();
  changeProperties.setColor(color);
  m_collection->setDisplayProperties(m_indexForColor, changeProperties);
}

void FWCollectionSummaryWidget::toggleItemVisible() {
  m_isVisibleCheckBox->setChecked(!m_isVisibleCheckBox->isChecked());
  FWDisplayProperties changeProperties = m_collection->defaultDisplayProperties();
  changeProperties.setIsVisible(m_isVisibleCheckBox->isChecked());
  m_collection->setDefaultDisplayProperties(changeProperties);
  fClient->NeedRedraw(m_isVisibleButton);
}

static TGGC* selectContext() {
  static TGGC* s_context = nullptr;
  if (nullptr == s_context) {
    GCValues_t hT = *(gClient->GetResourcePool()->GetSelectedGC()->GetAttributes());
    s_context = gClient->GetResourcePool()->GetGCPool()->GetGC(&hT, kTRUE);
    s_context->SetForeground(s_context->GetBackground());
    //s_context->SetForeground(gVirtualX->GetPixel(kBlue+2));
  }
  return s_context;
}

void FWCollectionSummaryWidget::toggleShowHide() {
  const TGPicture* picture = nullptr;
  const TGPicture* down = nullptr;
  const TGPicture* disabled = nullptr;

  if (m_collectionShown) {
    picture = arrow_right(!m_backgroundIsWhite);
    down = arrow_right_disabled(!m_backgroundIsWhite);
    disabled = arrow_right_disabled(!m_backgroundIsWhite);
    m_collectionShown = false;
    HideFrame(m_tableWidget);
    m_hints->SetLayoutHints(kLHintsExpandX);
  } else {
    picture = arrow_down(!m_backgroundIsWhite);
    down = arrow_down_disabled(!m_backgroundIsWhite);
    disabled = arrow_down_disabled(!m_backgroundIsWhite);
    m_collectionShown = true;

    if (nullptr == m_tableManager) {
      GCValues_t t = *(GetWhiteGC().GetAttributes());
      t.fFont = gClient->GetResourcePool()->GetIconFont()->GetFontHandle();
      m_tableContext = gClient->GetResourcePool()->GetGCPool()->GetGC(&t, kTRUE);

      TGGC* hilightContext = selectContext();
      m_tableManager = new FWCollectionSummaryTableManager(m_collection, m_tableContext, hilightContext, this);
      m_tableWidget = new FWTableWidget(m_tableManager, this);
      m_tableWidget->SetHeaderBackgroundColor(fClient->GetResourcePool()->GetFrameGC()->GetBackground());
      colorTable();
      AddFrame(m_tableWidget, new TGLayoutHints(kLHintsBottom | kLHintsExpandX | kLHintsExpandY));
      m_tableWidget->Connect("rowClicked(Int_t,Int_t,Int_t,Int_t,Int_t)",
                             "FWCollectionSummaryWidget",
                             this,
                             "modelSelected(Int_t,Int_t,Int_t,Int_t,Int_t)");

      MapSubwindows();
      Layout();
    }
    ShowFrame(m_tableWidget);
    m_hints->SetLayoutHints(kLHintsExpandX | kLHintsExpandY);
    //NOTE: if I don't do the resize then the vertical scrollbars for the table are
    // messed up when the number of entries in the table can be fully scene but
    // a scrollbar is still added which thinks only a tiny area of the list can be seen
    m_tableWidget->Resize(m_tableWidget->GetWidth(), m_tableWidget->GetHeight());
  }

  if (nullptr != m_parent) {
    m_parent->Layout();
  }
  m_showHideButton->swapIcons(picture, down, disabled);
}

void FWCollectionSummaryWidget::createColorPopup() {
  if (nullptr == m_colorPopup) {
    std::vector<Color_t> colors;
    m_collection->colorManager()->fillLimitedColors(colors);

    m_colorPopup = new FWColorPopup(gClient->GetDefaultRoot(), m_collection->defaultDisplayProperties().color());
    m_colorPopup->InitContent(m_collection->name().c_str(), colors);
    m_colorPopup->Connect("ColorSelected(Color_t)", "FWCollectionSummaryWidget", this, "colorChangeRequested(Color_t)");
  }
}

void FWCollectionSummaryWidget::colorClicked() {
  FWColorManager* cm = m_collection->colorManager();
  m_indexForColor = -1;

  createColorPopup();
  Window_t wdummy;
  Int_t ax, ay;
  gVirtualX->TranslateCoordinates(m_colorSelectWidget->GetId(),
                                  gClient->GetDefaultRoot()->GetId(),
                                  0,
                                  m_colorSelectWidget->GetHeight(),
                                  ax,
                                  ay,
                                  wdummy);
  m_colorPopup->SetName(m_collection->name().c_str());
  std::vector<Color_t> colors;
  cm->fillLimitedColors(colors);
  m_colorPopup->ResetColors(colors, cm->backgroundColorIndex() == FWColorManager::kBlackIndex);
  m_colorPopup->SetSelection(m_collection->defaultDisplayProperties().color());
  m_colorPopup->PlacePopup(ax, ay, m_colorPopup->GetDefaultWidth(), m_colorPopup->GetDefaultHeight());
}

void FWCollectionSummaryWidget::itemColorClicked(int iIndex, Int_t iRootX, Int_t iRootY) {
  FWColorManager* cm = m_collection->colorManager();
  m_indexForColor = iIndex;

  createColorPopup();
  std::vector<Color_t> colors;
  cm->fillLimitedColors(colors);
  m_colorPopup->ResetColors(colors, cm->backgroundColorIndex() == FWColorManager::kBlackIndex);
  m_colorPopup->SetName(m_collection->modelName(iIndex).c_str());
  m_colorPopup->SetSelection(m_collection->modelInfo(iIndex).displayProperties().color());
  m_colorPopup->PlacePopup(iRootX, iRootY, m_colorPopup->GetDefaultWidth(), m_colorPopup->GetDefaultHeight());
}

void FWCollectionSummaryWidget::modelSelected(Int_t iRow, Int_t iButton, Int_t iKeyMod, Int_t iGlobalX, Int_t iGlobalY) {
  if (iKeyMod & kKeyControlMask) {
    m_collection->toggleSelect(iRow);
  } else {
    FWChangeSentry sentry(*(m_collection->changeManager()));
    m_collection->selectionManager()->clearSelection();
    m_collection->select(iRow);
  }
  if (iButton == kButton3) {
    requestForModelContextMenu(iGlobalX, iGlobalY);
  }
}

void FWCollectionSummaryWidget::requestForInfo(FWEventItem* iItem) {
  Emit("requestForInfo(FWEventItem*)", reinterpret_cast<long>(iItem));
}

void FWCollectionSummaryWidget::requestForFilter(FWEventItem* iItem) {
  Emit("requestForFilter(FWEventItem*)", reinterpret_cast<long>(iItem));
}

void FWCollectionSummaryWidget::requestForErrorInfo(FWEventItem* iItem) {
  Emit("requestForErrorInfo(FWEventItem*)", reinterpret_cast<long>(iItem));
}

void FWCollectionSummaryWidget::requestForController(FWEventItem* iItem) {
  Emit("requestForController(FWEventItem*)", reinterpret_cast<long>(iItem));
}

void FWCollectionSummaryWidget::requestForModelContextMenu(Int_t iGlobalX, Int_t iGlobalY) {
  Long_t args[2];
  args[0] = static_cast<Long_t>(iGlobalX);
  args[1] = static_cast<Long_t>(iGlobalY);
  Emit("requestForModelContextMenu(Int_t,Int_t)", args);
}

void FWCollectionSummaryWidget::infoClicked() {
  if (!m_collection->itemIsSelected()) {
    //NOTE: Want to be sure if models are selected then their collection is also selected
    m_collection->selectionManager()->clearSelection();
    m_collection->selectItem();
  }
  requestForInfo(m_collection);
}

void FWCollectionSummaryWidget::stateClicked() {
  if (!m_collection->itemIsSelected()) {
    //NOTE: Want to be sure if models are selected then their collection is also selected
    m_collection->selectionManager()->clearSelection();
    m_collection->selectItem();
  }
  requestForFilter(m_collection);
}

void FWCollectionSummaryWidget::labelClicked() {
  if (!m_collection->itemIsSelected()) {
    //NOTE: Want to be sure if models are selected then their collection is also selected
    m_collection->selectionManager()->clearSelection();
    m_collection->selectItem();
  }
  requestForController(m_collection);
}

void FWCollectionSummaryWidget::setBackgroundToWhite(bool iToWhite) {
  if (iToWhite == m_backgroundIsWhite) {
    return;
  }
  Pixel_t bc = 0x000000;
  Pixel_t fg = 0xffffff;
  if (iToWhite) {
    bc = 0xffffff;
    fg = 0x000000;
    m_backgroundIsWhite = true;
    SetBackgroundColor(kWidgetColorLight);
    m_isVisibleButton->setNormCG(GetBlackGC()());
    m_colorSelectWidget->setNormCG(GetBlackGC()());
    selectContext()->SetForeground(0xafafFF);
  } else {
    m_backgroundIsWhite = false;
    SetBackgroundColor(kWidgetColor);
    m_isVisibleButton->setNormCG(GetWhiteGC()());
    m_colorSelectWidget->setNormCG(GetWhiteGC()());
    selectContext()->SetForeground(gClient->GetResourcePool()->GetSelectedGC()->GetBackground());
  }
  //this forces the icons to be changed to the correct background
  itemChanged();
  m_graphicsContext->SetForeground(gVirtualX->GetPixel(m_collection->defaultDisplayProperties().color()));
  {
    const TGPicture* picture = info(!m_backgroundIsWhite);
    const TGPicture* over = info_over(!m_backgroundIsWhite);
    const TGPicture* disabled = info_disabled(!m_backgroundIsWhite);
    m_infoButton->swapIcons(picture, over, disabled);
  }
  if (m_collectionShown) {
    const TGPicture* picture = arrow_down(!m_backgroundIsWhite);
    const TGPicture* down = arrow_down_disabled(!m_backgroundIsWhite);
    const TGPicture* disabled = arrow_down_disabled(!m_backgroundIsWhite);
    m_showHideButton->swapIcons(picture, down, disabled);
  } else {
    const TGPicture* picture = arrow_right(!m_backgroundIsWhite);
    const TGPicture* down = arrow_right_disabled(!m_backgroundIsWhite);
    const TGPicture* disabled = arrow_right_disabled(!m_backgroundIsWhite);
    m_showHideButton->swapIcons(picture, down, disabled);
  }
  colorTable();
  m_holder->SetBackgroundColor(bc);
  setLabelBackgroundColor(m_label, m_collection->itemIsSelected(), m_backgroundIsWhite);
  m_label->SetTextColor(fg);
  m_isVisibleButton->SetBackgroundColor(bc);
  m_colorSelectWidget->SetBackgroundColor(bc);
  fClient->NeedRedraw(m_isVisibleButton);
  fClient->NeedRedraw(m_colorSelectWidget);
  fClient->NeedRedraw(m_holder);
  fClient->NeedRedraw(this);
}

void FWCollectionSummaryWidget::colorTable() {
  if (nullptr == m_tableWidget) {
    return;
  }
  if (m_backgroundIsWhite) {
    m_tableWidget->SetBackgroundColor(kWidgetColorLight);
    m_tableWidget->SetLineSeparatorColor(0x000000);
    m_tableContext->SetForeground(0x000000);
  } else {
    m_tableWidget->SetBackgroundColor(kWidgetColor);
    m_tableWidget->SetLineSeparatorColor(0xffffff);
    m_tableContext->SetForeground(0xffffff);
  }
}
//
// const member functions
//

//
// static member functions
//

ClassImp(FWCollectionSummaryWidget);