Commit 5b965904 authored by aroben's avatar aroben
Browse files

Reviewed by Adele.

        Remove no-longer-used PopUpButton.

        * WebCore.vcproj/WebCore/WebCore.vcproj: Remove PopUpButton.h
        * WebCore.xcodeproj/project.pbxproj: Remove PopUpButton.h,
	PopUpButtonMac.mm
        * platform/PopUpButton.h: Removed.
        * platform/mac/PopUpButtonMac.mm: Removed.
        * platform/win/TemporaryLinkStubs.cpp: Remove PopUpButton:: methods
        * rendering/DeprecatedRenderSelect.cpp: Change #include of
	PopUpButton.h to ListBox.h



git-svn-id: http://svn.webkit.org/repository/webkit/trunk@16624 268f45cc-cd09-0410-ab3c-d52691b4dbfc
parent f40ae62c
2006-09-28 Adam Roben <aroben@apple.com>
Reviewed by Adele.
Remove no-longer-used PopUpButton.
* WebCore.vcproj/WebCore/WebCore.vcproj: Remove PopUpButton.h
* WebCore.xcodeproj/project.pbxproj: Remove PopUpButton.h,
PopUpButtonMac.mm
* platform/PopUpButton.h: Removed.
* platform/mac/PopUpButtonMac.mm: Removed.
* platform/win/TemporaryLinkStubs.cpp: Remove PopUpButton:: methods
* rendering/DeprecatedRenderSelect.cpp: Change #include of
PopUpButton.h to ListBox.h
2006-09-28 Darin Adler <darin@apple.com>
 
Reviewed by Alice.
......@@ -1410,10 +1410,6 @@
RelativePath="..\..\platform\PlugInInfoStore.h"
>
</File>
<File
RelativePath="..\..\platform\PopUpButton.h"
>
</File>
<File
RelativePath="..\..\platform\RegularExpression.cpp"
>
......@@ -1625,10 +1621,10 @@
RelativePath="..\..\platform\win\GlyphMapWin.cpp"
>
</File>
<File
RelativePath="..\..\platform\win\GraphicsContextWin.cpp"
>
</File>
<File
RelativePath="..\..\platform\win\GraphicsContextWin.cpp"
>
</File>
<File
RelativePath="..\..\platform\win\ImageWin.cpp"
>
......@@ -2510,14 +2506,14 @@
RelativePath="..\..\css\CSSComputedStyleDeclaration.h"
>
</File>
<File
RelativePath="..\..\css\CSSCursorImageValue.cpp"
>
</File>
<File
RelativePath="..\..\css\CSSCursorImageValue.h"
>
</File>
<File
RelativePath="..\..\css\CSSCursorImageValue.cpp"
>
</File>
<File
RelativePath="..\..\css\CSSCursorImageValue.h"
>
</File>
<File
RelativePath="..\..\css\CSSFontFaceRule.cpp"
>
......
......@@ -1086,7 +1086,6 @@
93F1991808245E59001E9ABC /* Range.h in Headers */ = {isa = PBXBuildFile; fileRef = F523D30402DE4476018635CA /* Range.h */; };
93F1992108245E59001E9ABC /* XMLTokenizer.h in Headers */ = {isa = PBXBuildFile; fileRef = F523D30A02DE4476018635CA /* XMLTokenizer.h */; };
93F1992908245E59001E9ABC /* DeprecatedCString.h in Headers */ = {isa = PBXBuildFile; fileRef = F587868302DE3B8601EA4122 /* DeprecatedCString.h */; };
93F1992E08245E59001E9ABC /* PopUpButton.h in Headers */ = {isa = PBXBuildFile; fileRef = F587868202DE3B8601EA4122 /* PopUpButton.h */; };
93F1992F08245E59001E9ABC /* Cursor.h in Headers */ = {isa = PBXBuildFile; fileRef = F587868402DE3B8601EA4122 /* Cursor.h */; };
93F1994F08245E59001E9ABC /* Settings.h in Headers */ = {isa = PBXBuildFile; fileRef = F587863A02DE3A1401EA4122 /* Settings.h */; };
93F1995008245E59001E9ABC /* CachePolicy.h in Headers */ = {isa = PBXBuildFile; fileRef = F587864902DE3A9A01EA4122 /* CachePolicy.h */; };
......@@ -1144,7 +1143,6 @@
93F19A0908245E59001E9ABC /* southWestResizeCursor.tiff in Resources */ = {isa = PBXBuildFile; fileRef = 84C0FA2C052B966D000440A1 /* southWestResizeCursor.tiff */; };
93F19A0A08245E59001E9ABC /* waitCursor.tiff in Resources */ = {isa = PBXBuildFile; fileRef = 84C0FA2D052B966D000440A1 /* waitCursor.tiff */; };
93F19A0B08245E59001E9ABC /* westResizeCursor.tiff in Resources */ = {isa = PBXBuildFile; fileRef = 84C0FA2E052B966D000440A1 /* westResizeCursor.tiff */; };
93F19A1708245E59001E9ABC /* PopUpButtonMac.mm in Sources */ = {isa = PBXBuildFile; fileRef = F58784D202DE375901EA4122 /* PopUpButtonMac.mm */; };
93F19A1808245E59001E9ABC /* DeprecatedCString.cpp in Sources */ = {isa = PBXBuildFile; fileRef = F58784D502DE375901EA4122 /* DeprecatedCString.cpp */; };
93F19A2608245E59001E9ABC /* CursorMac.mm in Sources */ = {isa = PBXBuildFile; fileRef = F58784F002DE375901EA4122 /* CursorMac.mm */; };
93F19A2E08245E59001E9ABC /* JavaAppletWidget.mm in Sources */ = {isa = PBXBuildFile; fileRef = F58784FF02DE375901EA4122 /* JavaAppletWidget.mm */; };
......@@ -4906,7 +4904,6 @@
F56234E003026D7301629B47 /* WebCoreEncodings.mm */ = {isa = PBXFileReference; fileEncoding = 30; indentWidth = 4; lastKnownFileType = sourcecode.cpp.objcpp; path = WebCoreEncodings.mm; sourceTree = "<group>"; tabWidth = 8; usesTabs = 0; };
F565AE8502ECA583018635CA /* WebCoreSettings.h */ = {isa = PBXFileReference; fileEncoding = 30; indentWidth = 4; lastKnownFileType = sourcecode.c.h; path = WebCoreSettings.h; sourceTree = "<group>"; tabWidth = 8; usesTabs = 0; };
F565AE8602ECA583018635CA /* WebCoreSettings.mm */ = {isa = PBXFileReference; fileEncoding = 30; indentWidth = 4; lastKnownFileType = sourcecode.cpp.objcpp; path = WebCoreSettings.mm; sourceTree = "<group>"; tabWidth = 8; usesTabs = 0; };
F58784D202DE375901EA4122 /* PopUpButtonMac.mm */ = {isa = PBXFileReference; fileEncoding = 30; indentWidth = 4; lastKnownFileType = sourcecode.cpp.objcpp; path = PopUpButtonMac.mm; sourceTree = "<group>"; tabWidth = 8; usesTabs = 0; };
F58784D502DE375901EA4122 /* DeprecatedCString.cpp */ = {isa = PBXFileReference; fileEncoding = 4; indentWidth = 4; lastKnownFileType = sourcecode.cpp.cpp; path = DeprecatedCString.cpp; sourceTree = "<group>"; tabWidth = 8; usesTabs = 0; };
F58784F002DE375901EA4122 /* CursorMac.mm */ = {isa = PBXFileReference; fileEncoding = 30; indentWidth = 4; lastKnownFileType = sourcecode.cpp.objcpp; path = CursorMac.mm; sourceTree = "<group>"; tabWidth = 8; usesTabs = 0; };
F58784FF02DE375901EA4122 /* JavaAppletWidget.mm */ = {isa = PBXFileReference; fileEncoding = 30; indentWidth = 4; lastKnownFileType = sourcecode.cpp.objcpp; path = JavaAppletWidget.mm; sourceTree = "<group>"; tabWidth = 8; usesTabs = 0; };
......@@ -4931,7 +4928,6 @@
F587864502DE3A7701EA4122 /* JavaAppletWidget.h */ = {isa = PBXFileReference; fileEncoding = 30; indentWidth = 4; lastKnownFileType = sourcecode.c.h; path = JavaAppletWidget.h; sourceTree = "<group>"; tabWidth = 8; usesTabs = 0; };
F587864902DE3A9A01EA4122 /* CachePolicy.h */ = {isa = PBXFileReference; fileEncoding = 30; indentWidth = 4; lastKnownFileType = sourcecode.c.h; path = CachePolicy.h; sourceTree = "<group>"; tabWidth = 8; usesTabs = 0; };
F587866202DE3B1101EA4122 /* SSLKeyGenerator.h */ = {isa = PBXFileReference; fileEncoding = 30; indentWidth = 4; lastKnownFileType = sourcecode.c.h; path = SSLKeyGenerator.h; sourceTree = "<group>"; tabWidth = 8; usesTabs = 0; };
F587868202DE3B8601EA4122 /* PopUpButton.h */ = {isa = PBXFileReference; fileEncoding = 30; indentWidth = 4; lastKnownFileType = sourcecode.c.h; path = PopUpButton.h; sourceTree = "<group>"; tabWidth = 8; usesTabs = 0; };
F587868302DE3B8601EA4122 /* DeprecatedCString.h */ = {isa = PBXFileReference; fileEncoding = 4; indentWidth = 4; lastKnownFileType = sourcecode.c.h; path = DeprecatedCString.h; sourceTree = "<group>"; tabWidth = 8; usesTabs = 0; };
F587868402DE3B8601EA4122 /* Cursor.h */ = {isa = PBXFileReference; fileEncoding = 30; indentWidth = 4; lastKnownFileType = sourcecode.c.h; path = Cursor.h; sourceTree = "<group>"; tabWidth = 8; usesTabs = 0; };
F587869802DE3B8601EA4122 /* TextField.h */ = {isa = PBXFileReference; fileEncoding = 30; indentWidth = 4; lastKnownFileType = sourcecode.c.h; path = TextField.h; sourceTree = "<group>"; tabWidth = 8; usesTabs = 0; };
......@@ -5591,7 +5587,6 @@
935C476F09AC4D7300A6AAB4 /* PlatformMouseEventMac.mm */,
BC3FCAA80AC3DB5800BA54AD /* PlatformScrollBar.h */,
A82398A709B3ACF500B60641 /* PlugInInfoStoreMac.mm */,
F58784D202DE375901EA4122 /* PopUpButtonMac.mm */,
6582A15409999D6D00BEEB6D /* ScreenMac.mm */,
BC7B2AF90450824100A8000F /* PlatformScrollBarMac.mm */,
BCAA90C20A7EBA60008B1229 /* ScrollBar.cpp */,
......@@ -7418,7 +7413,6 @@
93CD4FEB0995FD2A007ECC97 /* PlatformString.h */,
935C476A09AC4D4F00A6AAB4 /* PlatformWheelEvent.h */,
A82398A509B3ACDB00B60641 /* PlugInInfoStore.h */,
F587868202DE3B8601EA4122 /* PopUpButton.h */,
F587852B02DE375901EA4122 /* RegularExpression.cpp */,
F58786B302DE3B8601EA4122 /* RegularExpression.h */,
6545F66C09B82FED0013006F /* ResourceLoader.cpp */,
......@@ -7931,7 +7925,6 @@
93F1991808245E59001E9ABC /* Range.h in Headers */,
93F1992108245E59001E9ABC /* XMLTokenizer.h in Headers */,
93F1992908245E59001E9ABC /* DeprecatedCString.h in Headers */,
93F1992E08245E59001E9ABC /* PopUpButton.h in Headers */,
93F1992F08245E59001E9ABC /* Cursor.h in Headers */,
93F1994F08245E59001E9ABC /* Settings.h in Headers */,
93F1995008245E59001E9ABC /* CachePolicy.h in Headers */,
......@@ -9206,7 +9199,6 @@
isa = PBXSourcesBuildPhase;
buildActionMask = 2147483647;
files = (
93F19A1708245E59001E9ABC /* PopUpButtonMac.mm in Sources */,
93F19A1808245E59001E9ABC /* DeprecatedCString.cpp in Sources */,
93F19A2608245E59001E9ABC /* CursorMac.mm in Sources */,
93F19A2E08245E59001E9ABC /* JavaAppletWidget.mm in Sources */,
/*
* Copyright (C) 2004 Apple Computer, Inc. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
*
* THIS SOFTWARE IS PROVIDED BY APPLE COMPUTER, INC. ``AS IS'' AND ANY
* EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
* PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE COMPUTER, INC. OR
* CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
* EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
* PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
* PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
* OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
#ifndef PopUpButton_h
#define PopUpButton_h
#include "ListBox.h"
#ifdef __OBJC__
@class WebCorePopUpButtonAdapter;
#else
class WebCorePopUpButtonAdapter;
class NSMenuItem;
class NSFont;
#endif
namespace WebCore {
class PopUpButton : public Widget {
public:
PopUpButton();
~PopUpButton();
void clear();
void appendItem(const DeprecatedString& text, bool enabled) { appendItem(text, ListBoxOption, enabled); }
void appendGroupLabel(const DeprecatedString& text) { appendItem(text, ListBoxGroupLabel, false); }
void appendSeparator() { appendItem(DeprecatedString::null, ListBoxSeparator, true); }
int currentItem() const { return _currentItem; }
void setCurrentItem(int);
IntSize sizeHint() const;
IntRect frameGeometry() const;
void setFrameGeometry(const IntRect&);
int baselinePosition(int height) const;
void setFont(const Font&);
void itemSelected();
virtual FocusPolicy focusPolicy() const;
void setWritingDirection(TextDirection);
virtual void populate();
void populateMenu();
private:
void appendItem(const DeprecatedString&, ListBoxItemType, bool);
const int* dimensions() const;
NSFont* labelFont() const;
void setTitle(NSMenuItem*, const ListBoxItem&);
mutable int _width;
mutable bool _widthGood;
mutable int _currentItem;
// A Vector<ListBoxItem> may be more efficient for large menus.
DeprecatedValueList<ListBoxItem> _items;
mutable bool _menuPopulated;
mutable NSFont *_labelFont;
};
}
#endif
/*
* Copyright (C) 2004, 2005, 2006 Apple Computer, Inc. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
*
* THIS SOFTWARE IS PROVIDED BY APPLE COMPUTER, INC. ``AS IS'' AND ANY
* EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
* PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE COMPUTER, INC. OR
* CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
* EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
* PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
* PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
* OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
#import "config.h"
#import "PopUpButton.h"
#import "BlockExceptions.h"
#import "Font.h"
#import "FontData.h"
#import "FoundationExtras.h"
#import "FrameMac.h"
#import "RenderView.h"
#import "RenderWidget.h"
#import "TextField.h"
#import "TextStyle.h"
#import "WebCoreFrameBridge.h"
#import "WebCoreWidgetHolder.h"
#import "WidgetClient.h"
using namespace WebCore;
@interface NSCell (WebCorePopUpButtonKnowsAppKitSecrets)
- (NSMutableDictionary *)_textAttributes;
@end
enum {
topMargin,
bottomMargin,
leftMargin,
rightMargin,
baselineFudgeFactor,
widthNotIncludingText,
minimumTextWidth
};
@interface WebCorePopUpButtonCell : NSPopUpButtonCell <WebCoreWidgetHolder>
{
PopUpButton *box;
NSWritingDirection baseWritingDirection;
}
- (id)initWithQComboBox:(PopUpButton *)b;
- (void)detachQComboBox;
- (void)setBaseWritingDirection:(NSWritingDirection)direction;
- (NSWritingDirection)baseWritingDirection;
@end
@interface WebCorePopUpButton : NSPopUpButton <WebCoreWidgetHolder>
{
BOOL inNextValidKeyView;
BOOL populatingMenu;
}
- (void)setPopulatingMenu:(BOOL)populating;
@end
PopUpButton::PopUpButton()
: _widthGood(false)
, _currentItem(0)
, _menuPopulated(true)
, _labelFont(nil)
{
BEGIN_BLOCK_OBJC_EXCEPTIONS;
WebCorePopUpButton *button = [[WebCorePopUpButton alloc] init];
setView(button);
[button release];
WebCorePopUpButtonCell *cell = [[WebCorePopUpButtonCell alloc] initWithQComboBox:this];
// Work around problem where the pop-up menu gets a "..." in it
// by turning off the default "ellipsizing" behavior.
[cell setLineBreakMode:NSLineBreakByClipping];
[button setCell:cell];
[cell release];
[button setTarget:button];
[button setAction:@selector(action:)];
[[button cell] setControlSize:NSSmallControlSize];
[button setFont:[NSFont systemFontOfSize:[NSFont systemFontSizeForControlSize:NSSmallControlSize]]];
[button setAutoenablesItems:NO];
END_BLOCK_OBJC_EXCEPTIONS;
}
PopUpButton::~PopUpButton()
{
BEGIN_BLOCK_OBJC_EXCEPTIONS;
WebCorePopUpButton *button = (WebCorePopUpButton *)getView();
[button setTarget:nil];
[[button cell] detachQComboBox];
HardRelease(_labelFont);
END_BLOCK_OBJC_EXCEPTIONS;
}
void PopUpButton::setTitle(NSMenuItem *menuItem, const ListBoxItem &title)
{
if (title.type == ListBoxGroupLabel) {
NSDictionary *attributes = [[NSDictionary alloc] initWithObjectsAndKeys:labelFont(), NSFontAttributeName, nil];
NSAttributedString *string = [[NSAttributedString alloc] initWithString:title.string.getNSString() attributes:attributes];
[menuItem setAttributedTitle:string];
[string release];
[attributes release];
[menuItem setEnabled:NO];
} else {
[menuItem setTitle:title.string.getNSString()];
[menuItem setEnabled:title.enabled];
}
}
void PopUpButton::appendItem(const DeprecatedString &text, ListBoxItemType type, bool enabled)
{
const ListBoxItem listItem(text, type, enabled);
_items.append(listItem);
if (_menuPopulated) {
WebCorePopUpButton *button = (WebCorePopUpButton *)getView();
if (![[button cell] isHighlighted]) {
_menuPopulated = false;
} else {
BEGIN_BLOCK_OBJC_EXCEPTIONS;
if (type == ListBoxSeparator) {
NSMenuItem *separator = [NSMenuItem separatorItem];
[[button menu] addItem:separator];
} else {
// We must add the item with no title and then set the title because
// addItemWithTitle does not allow duplicate titles.
[button addItemWithTitle:@""];
NSMenuItem *menuItem = [button lastItem];
setTitle(menuItem, listItem);
}
END_BLOCK_OBJC_EXCEPTIONS;
}
}
_widthGood = false;
}
IntSize PopUpButton::sizeHint() const
{
BEGIN_BLOCK_OBJC_EXCEPTIONS;
WebCorePopUpButton *button = (WebCorePopUpButton *)getView();
if (!_widthGood) {
float width = 0;
DeprecatedValueListConstIterator<ListBoxItem> i = const_cast<const DeprecatedValueList<ListBoxItem> &>(_items).begin();
DeprecatedValueListConstIterator<ListBoxItem> e = const_cast<const DeprecatedValueList<ListBoxItem> &>(_items).end();
if (i != e) {
RenderWidget *client = static_cast<RenderWidget *>(Widget::client());
bool isPrinting = client->view()->printingMode();
FontPlatformData itemFont([button font]);
FontPlatformData labelFont(this->labelFont());
Font itemRenderer(itemFont, isPrinting);
Font labelRenderer(labelFont, isPrinting);
do {
const DeprecatedString &s = (*i).string;
bool isGroupLabel = ((*i).type == ListBoxGroupLabel);
++i;
TextRun run(reinterpret_cast<const UniChar *>(s.unicode()), s.length());
TextStyle style;
style.disableRoundingHacks();
Font* renderer = isGroupLabel ? &labelRenderer : &itemRenderer;
float textWidth = renderer->floatWidth(run, style);
width = max(width, textWidth);
} while (i != e);
}
_width = max(static_cast<int>(ceilf(width)), dimensions()[minimumTextWidth]);
_widthGood = true;
}
return IntSize(_width + dimensions()[widthNotIncludingText],
static_cast<int>([[button cell] cellSize].height) - (dimensions()[topMargin] + dimensions()[bottomMargin]));
END_BLOCK_OBJC_EXCEPTIONS;
return IntSize(0, 0);
}
IntRect PopUpButton::frameGeometry() const
{
IntRect r = Widget::frameGeometry();
return IntRect(r.x() + dimensions()[leftMargin], r.y() + dimensions()[topMargin],
r.width() - (dimensions()[leftMargin] + dimensions()[rightMargin]),
r.height() - (dimensions()[topMargin] + dimensions()[bottomMargin]));
}
void PopUpButton::setFrameGeometry(const IntRect& r)
{
Widget::setFrameGeometry(IntRect(-dimensions()[leftMargin] + r.x(), -dimensions()[topMargin] + r.y(),
dimensions()[leftMargin] + r.width() + dimensions()[rightMargin],
dimensions()[topMargin] + r.height() + dimensions()[bottomMargin]));
}
int PopUpButton::baselinePosition(int height) const
{
// Menu text is at the top.
WebCorePopUpButton *button = (WebCorePopUpButton *)getView();
return static_cast<int>(ceilf(-dimensions()[topMargin] + dimensions()[baselineFudgeFactor] + [[button font] ascender]));
}
void PopUpButton::clear()
{
WebCorePopUpButton *button = (WebCorePopUpButton *)getView();
[button removeAllItems];
_widthGood = false;
_currentItem = 0;
_items.clear();
_menuPopulated = true;
}
void PopUpButton::setCurrentItem(int index)
{
ASSERT(index < (int)_items.count());
BEGIN_BLOCK_OBJC_EXCEPTIONS;
WebCorePopUpButton *button = (WebCorePopUpButton *)getView();
if (_menuPopulated) {
[button selectItemAtIndex:index];
} else {
[button removeAllItems];
[button addItemWithTitle:@""];
NSMenuItem *menuItem = [button itemAtIndex:0];
setTitle(menuItem, _items[index]);
}
END_BLOCK_OBJC_EXCEPTIONS;
_currentItem = index;
}
void PopUpButton::itemSelected()
{
ASSERT(_menuPopulated);
BEGIN_BLOCK_OBJC_EXCEPTIONS;
WebCorePopUpButton *button = (WebCorePopUpButton *)getView();
int i = [button indexOfSelectedItem];
if (_currentItem == i) {
return;
}
_currentItem = i;
END_BLOCK_OBJC_EXCEPTIONS;
if (client())
client()->valueChanged(this);
}
void PopUpButton::setFont(const Font& f)
{
Widget::setFont(f);
const NSControlSize size = ControlSizeForFont(f);
NSControl * const button = static_cast<NSControl *>(getView());
BEGIN_BLOCK_OBJC_EXCEPTIONS;
if (size != [[button cell] controlSize]) {
[[button cell] setControlSize:size];
[button setFont:[NSFont systemFontOfSize:[NSFont systemFontSizeForControlSize:size]]];
HardRelease(_labelFont);
_labelFont = nil;
_widthGood = false;
}
END_BLOCK_OBJC_EXCEPTIONS;
}
NSFont *PopUpButton::labelFont() const
{
if (_labelFont == nil) {
NSControl * const button = static_cast<NSControl *>(getView());
_labelFont = HardRetain([NSFont boldSystemFontOfSize:[[button font] pointSize]]);
}
return _labelFont;
}
const int *PopUpButton::dimensions() const
{
// We empirically determined these dimensions.
// It would be better to get this info from AppKit somehow.
static const int w[3][7] = {
{ 2, 3, 3, 3, 4, 34, 9 },
{ 1, 3, 3, 3, 3, 31, 5 },
{ 0, 0, 1, 1, 2, 32, 0 }
};
NSControl * const button = static_cast<NSControl *>(getView());
BEGIN_BLOCK_OBJC_EXCEPTIONS;
return w[[[button cell] controlSize]];
END_BLOCK_OBJC_EXCEPTIONS;
return w[NSSmallControlSize];
}
Widget::FocusPolicy PopUpButton::focusPolicy() const
{
FocusPolicy policy = Widget::focusPolicy();
return policy == TabFocus ? StrongFocus : policy;
}
void PopUpButton::setWritingDirection(TextDirection direction)
{
BEGIN_BLOCK_OBJC_EXCEPTIONS;
WebCorePopUpButton *button = static_cast<WebCorePopUpButton *>(getView());
WebCorePopUpButtonCell *cell = [button cell];
NSWritingDirection d = direction == RTL ? NSWritingDirectionRightToLeft : NSWritingDirectionLeftToRight;
if ([cell baseWritingDirection] != d) {
[cell setBaseWritingDirection:d];
[button setNeedsDisplay:YES];
}
END_BLOCK_OBJC_EXCEPTIONS;
}
void PopUpButton::populateMenu()
{
if (!_menuPopulated) {
BEGIN_BLOCK_OBJC_EXCEPTIONS;
WebCorePopUpButton *button = static_cast<WebCorePopUpButton *>(getView());
[button setPopulatingMenu:YES];
[button removeAllItems];
DeprecatedValueListConstIterator<ListBoxItem> i = const_cast<const DeprecatedValueList<ListBoxItem> &>(_items).begin();
DeprecatedValueListConstIterator<ListBoxItem> e = const_cast<const DeprecatedValueList<ListBoxItem> &>(_items).end();
for (; i != e; ++i) {
if ((*i).type == ListBoxSeparator) {
NSMenuItem *separator = [NSMenuItem separatorItem];
[[button menu] addItem:separator];
} else {
// We must add the item with no title and then set the title because
// addItemWithTitle does not allow duplicate titles.
[button addItemWithTitle:@""];
NSMenuItem *menuItem = [button lastItem];
setTitle(menuItem, *i);
}
}
[button selectItemAtIndex:_currentItem];
[button setPopulatingMenu:NO];
END_BLOCK_OBJC_EXCEPTIONS;
_menuPopulated = true;
}
}
void PopUpButton::populate()
{
populateMenu();
}
@implementation WebCorePopUpButtonCell
- (id)initWithQComboBox:(PopUpButton *)b
{
box = b;
return [super init];
}
- (void)detachQComboBox
{
box = 0;
}