[vlc-devel] [PATCH] macosx: Display wrapped text in the messages window
Brendon Justin
brendonjustin at gmail.com
Sat Apr 28 21:08:07 CEST 2012
---
Currently messages in the messages window wrap to the next line as necessary,
but only have enough space to display the first line.
These changes are adapted from Apple's sample code at this page:
https://developer.apple.com/library/mac/#samplecode/CocoaTipsAndTricks/Listings/TableViewVariableRowHeights_TableViewVariableRowHeightsAppDelegate_m.html
Apple's license appears to allow incorporating the code without attribution.
One caveat: the code appears to add space for another line below each message.
.../macosx/Resources/English.lproj/MainMenu.xib | 45 +++++++++++++-------
modules/gui/macosx/intf.m | 28 ++++++++++++
2 files changed, 57 insertions(+), 16 deletions(-)
diff --git a/extras/package/macosx/Resources/English.lproj/MainMenu.xib b/extras/package/macosx/Resources/English.lproj/MainMenu.xib
index 1d4a827..45a7494 100644
--- a/extras/package/macosx/Resources/English.lproj/MainMenu.xib
+++ b/extras/package/macosx/Resources/English.lproj/MainMenu.xib
@@ -21,16 +21,17 @@
</object>
<object class="NSMutableArray" key="IBDocument.EditedObjectIDs">
<bool key="EncodedWithXMLCoder">YES</bool>
+ <integer value="205"/>
<integer value="4850"/>
- <integer value="4722"/>
- <integer value="915"/>
+ <integer value="4931"/>
<integer value="2730"/>
- <integer value="1617"/>
- <integer value="205"/>
<integer value="21"/>
- <integer value="4948"/>
- <integer value="4596"/>
+ <integer value="1617"/>
<integer value="2770"/>
+ <integer value="4596"/>
+ <integer value="4722"/>
+ <integer value="4948"/>
+ <integer value="915"/>
</object>
<object class="NSArray" key="IBDocument.PluginDependencies">
<bool key="EncodedWithXMLCoder">YES</bool>
@@ -399,10 +400,11 @@
<int key="NSViewLayerContentsRedrawPolicy">2</int>
<reference key="NSTableView" ref="23448837"/>
</object>
- <object class="_NSCornerView" key="NSCornerView">
- <nil key="NSNextResponder"/>
+ <object class="_NSCornerView" key="NSCornerView" id="884766896">
+ <reference key="NSNextResponder" ref="915491793"/>
<int key="NSvFlags">-2147483392</int>
<string key="NSFrame">{{-26, 0}, {16, 17}}</string>
+ <reference key="NSSuperview" ref="915491793"/>
<int key="NSViewLayerContentsRedrawPolicy">2</int>
</object>
<object class="NSMutableArray" key="NSTableColumns">
@@ -579,6 +581,7 @@
<reference key="NSBGColor" ref="885475112"/>
<int key="NScvFlags">4</int>
</object>
+ <reference ref="884766896"/>
</object>
<string key="NSFrameSize">{404, 254}</string>
<reference key="NSSuperview" ref="440594360"/>
@@ -589,6 +592,7 @@
<reference key="NSHScroller" ref="297523533"/>
<reference key="NSContentView" ref="343242432"/>
<reference key="NSHeaderClipView" ref="576307303"/>
+ <reference key="NSCornerView" ref="884766896"/>
<bytes key="NSScrollAmts">QSAAAEEgAABBiAAAQYgAAA</bytes>
</object>
</object>
@@ -2583,7 +2587,7 @@
<string key="NSWindowContentMaxSize">{1.7976931348623157e+308, 1.7976931348623157e+308}</string>
<string key="NSWindowContentMinSize">{599, 368}</string>
<object class="NSView" key="NSWindowView" id="584094047">
- <nil key="NSNextResponder"/>
+ <reference key="NSNextResponder"/>
<int key="NSvFlags">256</int>
<object class="NSMutableArray" key="NSSubviews">
<bool key="EncodedWithXMLCoder">YES</bool>
@@ -2677,8 +2681,8 @@
<reference key="NSTextColor" ref="141148336"/>
</object>
<object class="NSTextFieldCell" key="NSDataCell" id="1020558889">
- <int key="NSCellFlags">604110400</int>
- <int key="NSCellFlags2">1073747968</int>
+ <int key="NSCellFlags">604110336</int>
+ <int key="NSCellFlags2">1073745920</int>
<string key="NSContents">Text Cell</string>
<reference key="NSSupport" ref="747390061"/>
<reference key="NSControlView" ref="694979328"/>
@@ -2788,6 +2792,7 @@
</object>
</object>
<string key="NSFrameSize">{599, 368}</string>
+ <reference key="NSSuperview"/>
</object>
<string key="NSScreenRect">{{0, 0}, {1280, 778}}</string>
<string key="NSMinSize">{599, 384}</string>
@@ -3931,7 +3936,7 @@ LCAuLi4</string>
<int key="NSTCFlags">1</int>
</object>
<object class="NSTextViewSharedData" key="NSSharedData">
- <int key="NSFlags">100675555</int>
+ <int key="NSFlags">33566691</int>
<int key="NSTextCheckingTypes">0</int>
<nil key="NSMarkedAttributes"/>
<reference key="NSBackgroundColor" ref="712893775"/>
@@ -7971,6 +7976,14 @@ LCAuLi4</string>
</object>
<int key="connectionID">5086</int>
</object>
+ <object class="IBConnectionRecord">
+ <object class="IBOutletConnection" key="connection">
+ <string key="label">delegate</string>
+ <reference key="source" ref="694979328"/>
+ <reference key="destination" ref="199714555"/>
+ </object>
+ <int key="connectionID">5087</int>
+ </object>
</object>
<object class="IBMutableOrderedSet" key="objectRecords">
<object class="NSArray" key="orderedObjects">
@@ -12268,9 +12281,9 @@ LCAuLi4</string>
<string>com.apple.InterfaceBuilder.CocoaPlugin</string>
<object class="NSAffineTransform"/>
<boolean value="YES"/>
- <string>{{369, 306}, {599, 368}}</string>
+ <string>{{657, 147}, {599, 368}}</string>
<string>com.apple.InterfaceBuilder.CocoaPlugin</string>
- <string>{{369, 306}, {599, 368}}</string>
+ <string>{{657, 147}, {599, 368}}</string>
<boolean value="YES"/>
<boolean value="YES"/>
<string>{599, 368}</string>
@@ -12673,7 +12686,7 @@ LCAuLi4</string>
</object>
<string>com.apple.InterfaceBuilder.CocoaPlugin</string>
<object class="NSAffineTransform">
- <bytes key="NSTransformStruct">P4AAAL+AAABCRAAAw5kAAA</bytes>
+ <bytes key="NSTransformStruct">P4AAAL+AAAC/gAAAw7eAAA</bytes>
</object>
<string>com.apple.InterfaceBuilder.CocoaPlugin</string>
<string>com.apple.InterfaceBuilder.CocoaPlugin</string>
@@ -12849,7 +12862,7 @@ LCAuLi4</string>
</object>
</object>
<nil key="sourceID"/>
- <int key="maxID">5086</int>
+ <int key="maxID">5087</int>
</object>
<object class="IBClassDescriber" key="IBDocument.Classes">
<object class="NSMutableArray" key="referencedPartialClassDescriptions">
diff --git a/modules/gui/macosx/intf.m b/modules/gui/macosx/intf.m
index 90f7c6c..db9e1f4 100644
--- a/modules/gui/macosx/intf.m
+++ b/modules/gui/macosx/intf.m
@@ -8,6 +8,7 @@
* Christophe Massiot <massiot at via.ecp.fr>
* Derk-Jan Hartman <hartman at videolan.org>
* Felix Paul Kühne <fkuehne at videolan dot org>
+ * Brendon Justin <brendonjustin at gmail.com>
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
@@ -2020,6 +2021,33 @@ unsigned int CocoaKeyToVLC( unichar i_key )
return @"";
}
+- (CGFloat)tableView:(NSTableView *)aTableView heightOfRow:(NSInteger)row
+{
+ /* Adapted from an Apple code sample:
+ * http://developer.apple.com/mac/library/samplecode/CocoaTipsAndTricks/Listings/TableViewVariableRowHeights_TableViewVariableRowHeightsAppDelegate_m.html
+ */
+ // It is important to use a constant value when calculating the height.
+ // Querying the tableColumn width will not work, since it dynamically changes as the user resizes --
+ // however, we don't get a notification that the user "did resize" it until after the mouse is let go.
+ // We use the latter as a hook for telling the table that the heights changed. We must return the same
+ // height from this method every time, until we tell the table the heights have changed. Not doing so
+ // will quicly cause drawing problems.
+
+ // Grab the fully prepared cell with our content filled in. Note that in IB the cell's Layout is set to Wraps.
+ NSCell *cell = [aTableView preparedCellAtColumn:0 row:row];
+
+ // See how tall it naturally would want to be if given a restricted with, but unbound height
+ NSRect constrainedBounds = NSMakeRect(0, 0, [[aTableView.tableColumns objectAtIndex:0] width], CGFLOAT_MAX);
+ NSSize naturalSize = [cell cellSizeForBounds:constrainedBounds];
+
+ // Make sure we have a minimum height -- use the table's set height as the minimum.
+ if (naturalSize.height > [aTableView rowHeight]) {
+ return naturalSize.height;
+ } else {
+ return [aTableView rowHeight];
+ }
+}
+
- (void)processReceivedlibvlcMessage:(const msg_item_t *) item ofType: (int)i_type withStr: (char *)str
{
if (o_msg_arr)
--
1.7.7.5 (Apple Git-26)
More information about the vlc-devel
mailing list