diff --git a/extras/juce demo/Source/demos/TableDemo.cpp b/extras/juce demo/Source/demos/TableDemo.cpp index ae82204411..fcebdc092c 100644 --- a/extras/juce demo/Source/demos/TableDemo.cpp +++ b/extras/juce demo/Source/demos/TableDemo.cpp @@ -42,30 +42,31 @@ public: loadData(); // Create our table component and add it to this component.. - addAndMakeVisible (table = new TableListBox ("demo table", this)); + addAndMakeVisible (&table); + table.setModel (this); // give it a border - table->setColour (ListBox::outlineColourId, Colours::grey); - table->setOutlineThickness (1); + table.setColour (ListBox::outlineColourId, Colours::grey); + table.setOutlineThickness (1); // Add some columns to the table header, based on the column list in our database.. forEachXmlChildElement (*columnList, columnXml) { - table->getHeader()->addColumn (columnXml->getStringAttribute ("name"), - columnXml->getIntAttribute ("columnId"), - columnXml->getIntAttribute ("width"), - 50, 400, - TableHeaderComponent::defaultFlags); + table.getHeader().addColumn (columnXml->getStringAttribute ("name"), + columnXml->getIntAttribute ("columnId"), + columnXml->getIntAttribute ("width"), + 50, 400, + TableHeaderComponent::defaultFlags); } // we could now change some initial settings.. - table->getHeader()->setSortColumnId (1, true); // sort forwards by the ID column - table->getHeader()->setColumnVisible (7, false); // hide the "length" column until the user shows it + table.getHeader().setSortColumnId (1, true); // sort forwards by the ID column + table.getHeader().setColumnVisible (7, false); // hide the "length" column until the user shows it // un-comment this line to have a go of stretch-to-fit mode - // table->getHeader()->setStretchToFitActive (true); + // table.getHeader().setStretchToFitActive (true); - table->setMultipleSelectionEnabled (true); + table.setMultipleSelectionEnabled (true); } ~TableDemoComponent() @@ -119,7 +120,7 @@ public: DemoDataSorter sorter (getAttributeNameForColumnId (newSortColumnId), isForwards); dataList->sortChildElements (sorter); - table->updateContent(); + table.updateContent(); } } @@ -190,14 +191,14 @@ public: void resized() { // position our table with a gap around its edge - table->setBoundsInset (BorderSize (8)); + table.setBoundsInset (BorderSize (8)); } //============================================================================== juce_UseDebuggingNewOperator private: - ScopedPointer table; // the table component itself + TableListBox table; // the table component itself Font font; ScopedPointer demoData; // This is the XML document loaded from the embedded file "demo table data.xml" diff --git a/extras/the jucer/src/ui/jucer_PrefsPanel.cpp b/extras/the jucer/src/ui/jucer_PrefsPanel.cpp index 0490955d4b..d12bc1973e 100644 --- a/extras/the jucer/src/ui/jucer_PrefsPanel.cpp +++ b/extras/the jucer/src/ui/jucer_PrefsPanel.cpp @@ -142,7 +142,7 @@ public: } else if (pageName == keysPage) { - return new KeyMappingEditorComponent (commandManager->getKeyMappings(), true); + return new KeyMappingEditorComponent (*commandManager->getKeyMappings(), true); } else if (pageName == aboutPage) { diff --git a/extras/the jucer/src/ui/jucer_ResourceEditorPanel.cpp b/extras/the jucer/src/ui/jucer_ResourceEditorPanel.cpp index 689b91d330..878eeade19 100644 --- a/extras/the jucer/src/ui/jucer_ResourceEditorPanel.cpp +++ b/extras/the jucer/src/ui/jucer_ResourceEditorPanel.cpp @@ -95,11 +95,11 @@ ResourceEditorPanel::ResourceEditorPanel (JucerDocument& document_) delButton->setEnabled (false); addAndMakeVisible (listBox = new TableListBox (String::empty, this)); - listBox->getHeader()->addColumn (T("name"), 1, 150, 80, 400); - listBox->getHeader()->addColumn (T("original file"), 2, 350, 80, 800); - listBox->getHeader()->addColumn (T("size"), 3, 100, 40, 150); - listBox->getHeader()->addColumn (T("reload"), 4, 100, 100, 100, TableHeaderComponent::notResizableOrSortable); - listBox->getHeader()->setStretchToFitActive (true); + listBox->getHeader().addColumn (T("name"), 1, 150, 80, 400); + listBox->getHeader().addColumn (T("original file"), 2, 350, 80, 800); + listBox->getHeader().addColumn (T("size"), 3, 100, 40, 150); + listBox->getHeader().addColumn (T("reload"), 4, 100, 100, 100, TableHeaderComponent::notResizableOrSortable); + listBox->getHeader().setStretchToFitActive (true); listBox->setColour (ListBox::outlineColourId, Colours::darkgrey); listBox->setOutlineThickness (1); diff --git a/juce_amalgamated.cpp b/juce_amalgamated.cpp index 0a738cf8e6..01b8f70290 100644 --- a/juce_amalgamated.cpp +++ b/juce_amalgamated.cpp @@ -40571,36 +40571,43 @@ const Rectangle Component::getScreenBounds() const namespace CoordinateHelpers { - const Point convertFromParentSpace (const Component* comp, const Point& pointInParentSpace) + inline bool hitTest (Component& comp, const Point& localPoint) { - return pointInParentSpace - comp->getPosition(); + return ((unsigned int) localPoint.getX()) < (unsigned int) comp.getWidth() + && ((unsigned int) localPoint.getY()) < (unsigned int) comp.getHeight() + && comp.hitTest (localPoint.getX(), localPoint.getY()); } - const Rectangle convertFromParentSpace (const Component* comp, const Rectangle& areaInParentSpace) + const Point convertFromParentSpace (const Component& comp, const Point& pointInParentSpace) { - return areaInParentSpace - comp->getPosition(); + return pointInParentSpace - comp.getPosition(); } - const Point convertToParentSpace (const Component* comp, const Point& pointInLocalSpace) + const Rectangle convertFromParentSpace (const Component& comp, const Rectangle& areaInParentSpace) { - return pointInLocalSpace + comp->getPosition(); + return areaInParentSpace - comp.getPosition(); } - const Rectangle convertToParentSpace (const Component* comp, const Rectangle& areaInLocalSpace) + const Point convertToParentSpace (const Component& comp, const Point& pointInLocalSpace) { - return areaInLocalSpace + comp->getPosition(); + return pointInLocalSpace + comp.getPosition(); + } + + const Rectangle convertToParentSpace (const Component& comp, const Rectangle& areaInLocalSpace) + { + return areaInLocalSpace + comp.getPosition(); } template - const Type convertFromDistantParentSpace (const Component* parent, const Component* target, Type coordInParent) + const Type convertFromDistantParentSpace (const Component* parent, const Component& target, Type coordInParent) { - const Component* const directParent = target->getParentComponent(); + const Component* const directParent = target.getParentComponent(); jassert (directParent != 0); if (directParent == parent) return convertFromParentSpace (target, coordInParent); - return convertFromParentSpace (target, convertFromDistantParentSpace (parent, directParent, coordInParent)); + return convertFromParentSpace (target, convertFromDistantParentSpace (parent, *directParent, coordInParent)); } template @@ -40612,7 +40619,7 @@ namespace CoordinateHelpers return p; if (source->isParentOf (target)) - return convertFromDistantParentSpace (source, target, p); + return convertFromDistantParentSpace (source, *target, p); if (source->isOnDesktop()) { @@ -40621,7 +40628,7 @@ namespace CoordinateHelpers } else { - p = convertToParentSpace (source, p); + p = convertToParentSpace (*source, p); source = source->getParentComponent(); } } @@ -40635,12 +40642,24 @@ namespace CoordinateHelpers if (topLevelComp->isOnDesktop()) p = topLevelComp->getPeer()->globalToLocal (p); else - p = convertFromParentSpace (topLevelComp, p); + p = convertFromParentSpace (*topLevelComp, p); if (topLevelComp == target) return p; - return convertFromDistantParentSpace (topLevelComp, target, p); + return convertFromDistantParentSpace (topLevelComp, *target, p); + } + + const Rectangle getUnclippedArea (const Component& comp) + { + Rectangle r (comp.getLocalBounds()); + + Component* const p = comp.getParentComponent(); + + if (p != 0) + r = r.getIntersection (convertFromParentSpace (comp, getUnclippedArea (*p))); + + return r; } } @@ -40882,15 +40901,11 @@ bool Component::hitTest (int x, int y) { for (int i = getNumChildComponents(); --i >= 0;) { - Component* const c = getChildComponent (i); + Component& child = *getChildComponent (i); - if (c->isVisible() - && c->bounds_.contains (x, y) - && c->hitTest (x - c->getX(), - y - c->getY())) - { + if (child.isVisible() + && CoordinateHelpers::hitTest (child, CoordinateHelpers::convertFromParentSpace (child, Point (x, y)))) return true; - } } } @@ -40911,70 +40926,50 @@ void Component::getInterceptsMouseClicks (bool& allowsClicksOnThisComponent, allowsClicksOnChildComponents = flags.allowChildMouseClicksFlag; } -bool Component::contains (const int x, const int y) +bool Component::contains (const Point& point) { - if (((unsigned int) x) < (unsigned int) getWidth() - && ((unsigned int) y) < (unsigned int) getHeight() - && hitTest (x, y)) + if (CoordinateHelpers::hitTest (*this, point)) { if (parentComponent_ != 0) { - return parentComponent_->contains (x + getX(), - y + getY()); + return parentComponent_->contains (CoordinateHelpers::convertToParentSpace (*this, point)); } else if (flags.hasHeavyweightPeerFlag) { const ComponentPeer* const peer = getPeer(); if (peer != 0) - return peer->contains (Point (x, y), true); + return peer->contains (point, true); } } return false; } -bool Component::reallyContains (int x, int y, const bool returnTrueIfWithinAChild) +bool Component::reallyContains (const int x, const int y, const bool returnTrueIfWithinAChild) { - if (! contains (x, y)) - return false; - - Component* p = this; - - while (p->parentComponent_ != 0) - { - x += p->getX(); - y += p->getY(); + const Point p (x, y); - p = p->parentComponent_; - } + if (! contains (p)) + return false; - const Component* const c = p->getComponentAt (x, y); + Component* const top = getTopLevelComponent(); + const Component* const compAtPosition = top->getComponentAt (top->getLocalPoint (this, p)); - return (c == this) || (returnTrueIfWithinAChild && isParentOf (c)); + return (compAtPosition == this) || (returnTrueIfWithinAChild && isParentOf (compAtPosition)); } Component* Component::getComponentAt (const Point& position) { - return getComponentAt (position.getX(), position.getY()); -} - -Component* Component::getComponentAt (const int x, const int y) -{ - if (flags.visibleFlag - && ((unsigned int) x) < (unsigned int) getWidth() - && ((unsigned int) y) < (unsigned int) getHeight() - && hitTest (x, y)) + if (flags.visibleFlag && CoordinateHelpers::hitTest (*this, position)) { for (int i = childComponentList_.size(); --i >= 0;) { - Component* const child = childComponentList_.getUnchecked(i); - - Component* const c = child->getComponentAt (x - child->getX(), - y - child->getY()); + Component* child = childComponentList_.getUnchecked(i); + child = child->getComponentAt (CoordinateHelpers::convertFromParentSpace (*child, position)); - if (c != 0) - return c; + if (child != 0) + return child; } return this; @@ -40983,6 +40978,11 @@ Component* Component::getComponentAt (const int x, const int y) return 0; } +Component* Component::getComponentAt (const int x, const int y) +{ + return getComponentAt (Point (x, y)); +} + void Component::addChildComponent (Component* const child, int zOrder) { // if component methods are being called from threads other than the message @@ -41694,27 +41694,6 @@ const Rectangle Component::getParentOrMainMonitorBounds() const : Desktop::getInstance().getMainMonitorArea(); } -const Rectangle Component::getUnclippedArea() const -{ - int x = 0, y = 0, w = getWidth(), h = getHeight(); - - Component* p = parentComponent_; - int px = getX(); - int py = getY(); - - while (p != 0) - { - if (! Rectangle::intersectRectangles (x, y, w, h, -px, -py, p->getWidth(), p->getHeight())) - return Rectangle(); - - px += p->getX(); - py += p->getY(); - p = p->parentComponent_; - } - - return Rectangle (x, y, w, h); -} - void Component::clipObscuredRegions (Graphics& g, const Rectangle& clipRect, const int deltaX, const int deltaY) const { @@ -41746,7 +41725,7 @@ void Component::clipObscuredRegions (Graphics& g, const Rectangle& clipRect void Component::getVisibleArea (RectangleList& result, const bool includeSiblings) const { result.clear(); - const Rectangle unclipped (getUnclippedArea()); + const Rectangle unclipped (CoordinateHelpers::getUnclippedArea (*this)); if (! unclipped.isEmpty()) { @@ -42872,8 +42851,8 @@ Component* Desktop::findComponentAt (const Point& screenPosition) const { const Point relative (c->getLocalPoint (0, screenPosition)); - if (c->contains (relative.getX(), relative.getY())) - return c->getComponentAt (relative.getX(), relative.getY()); + if (c->contains (relative)) + return c->getComponentAt (relative); } } @@ -47556,13 +47535,10 @@ ComboBox::ComboBox (const String& name) isButtonDown (false), separatorPending (false), menuActive (false), - label (0) + noChoicesMessage (TRANS("(no choices)")) { - noChoicesMessage = TRANS("(no choices)"); setRepaintsOnMouseActivity (true); - lookAndFeelChanged(); - currentId.addListener (this); } @@ -47574,7 +47550,6 @@ ComboBox::~ComboBox() PopupMenu::dismissAllActiveMenus(); label = 0; - deleteAllChildren(); } void ComboBox::setEditableText (const bool isEditable) @@ -47937,30 +47912,33 @@ void ComboBox::lookAndFeelChanged() { repaint(); - Label* const newLabel = getLookAndFeel().createComboBoxTextBox (*this); - - if (label != 0) { - newLabel->setEditable (label->isEditable()); - newLabel->setJustificationType (label->getJustificationType()); - newLabel->setTooltip (label->getTooltip()); - newLabel->setText (label->getText(), false); - } + ScopedPointer