Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

init check in

git-svn-id: https://ichm.googlecode.com/svn/trunk@2 e1f60c0e-2a54-0410-99cd-d3f60e83567d
  • Loading branch information...
commit a768321a744c74fa9a48e0d05ff153e323a7ade6 1 parent ed5637c
iamawalrus authored
Showing with 16,594 additions and 0 deletions.
  1. +2 −0  .gitignore
  2. +528 −0 Bookmark.xib
  3. +34 −0 BookmarkController.h
  4. +229 −0 BookmarkController.m
  5. BIN  Bookmarks.xcdatamodel/elements
  6. BIN  Bookmarks.xcdatamodel/layout
  7. +33 −0 CHMBookmark.h
  8. +22 −0 CHMBookmark.m
  9. +115 −0 CHMDocument.h
  10. +1,353 −0 CHMDocument.m
  11. +29 −0 CHMFile.h
  12. +18 −0 CHMFile.m
  13. +16 −0 CHMOutlineView.h
  14. +25 −0 CHMOutlineView.m
  15. +61 −0 CHMTableOfContent.h
  16. +347 −0 CHMTableOfContent.m
  17. +29 −0 CHMTag.h
  18. +18 −0 CHMTag.m
  19. +20 −0 CHMTextEncodingMenu.h
  20. +89 −0 CHMTextEncodingMenu.m
  21. +23 −0 CHMWebView.h
  22. +50 −0 CHMWebView.m
  23. BIN  English.lproj/CHMDocument.strings
  24. +1,197 −0 English.lproj/CHMDocument.xib
  25. BIN  English.lproj/CHMWebView.strings
  26. +602 −0 English.lproj/CHMWebView.xib
  27. +30 −0 English.lproj/Credits.rtf
  28. BIN  English.lproj/InfoPlist.strings
  29. BIN  English.lproj/Localizable.strings
  30. BIN  English.lproj/MainMenu.strings
  31. +2,396 −0 English.lproj/MainMenu.xib
  32. BIN  German.lproj/CHMDocument.strings
  33. +1,182 −0 German.lproj/CHMDocument.xib
  34. BIN  German.lproj/CHMWebView.strings
  35. +600 −0 German.lproj/CHMWebView.xib
  36. BIN  German.lproj/InfoPlist.strings
  37. BIN  German.lproj/Localizable.strings
  38. BIN  German.lproj/MainMenu.strings
  39. +2,209 −0 German.lproj/MainMenu.xib
  40. +23 −0 ICHMApplication.h
  41. +46 −0 ICHMApplication.m
  42. +26 −0 ITSSProtocol.h
  43. +103 −0 ITSSProtocol.m
  44. +52 −0 Info.plist
  45. BIN  TB_Sidebar.png
  46. +70 −0 highlight.js
  47. BIN  home.png
  48. +2 −0  ichm.css
  49. BIN  ichm.xcodeproj/TemplateIcon.icns
  50. +540 −0 ichm.xcodeproj/project.pbxproj
  51. +7 −0 ichm_Prefix.pch
  52. BIN  ichm_file.icns
  53. +142 −0 lcid.h
  54. +14 −0 main.m
  55. BIN  redbird.icns
  56. +97 −0 test.html
  57. +202 −0 textencoding.plist
  58. BIN  zh_CN.lproj/CHMDocument.strings
  59. +1,182 −0 zh_CN.lproj/CHMDocument.xib
  60. BIN  zh_CN.lproj/CHMWebView.strings
  61. +600 −0 zh_CN.lproj/CHMWebView.xib
  62. +1 −0  zh_CN.lproj/InfoPlist.strings
  63. +27 −0 zh_CN.lproj/Localizable.strings
  64. BIN  zh_CN.lproj/MainMenu.strings
  65. +2,203 −0 zh_CN.lproj/MainMenu.xib
View
2  .gitignore
@@ -0,0 +1,2 @@
+build/
+ichm.xcodeproj/splyb.*
View
528 Bookmark.xib
@@ -0,0 +1,528 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<archive type="com.apple.InterfaceBuilder3.Cocoa.XIB" version="7.02">
+ <data>
+ <int key="IBDocument.SystemTarget">1050</int>
+ <string key="IBDocument.SystemVersion">9E17</string>
+ <string key="IBDocument.InterfaceBuilderVersion">670</string>
+ <string key="IBDocument.AppKitVersion">949.33</string>
+ <string key="IBDocument.HIToolboxVersion">352.00</string>
+ <object class="NSMutableArray" key="IBDocument.EditedObjectIDs">
+ <bool key="EncodedWithXMLCoder">YES</bool>
+ <integer value="21"/>
+ </object>
+ <object class="NSArray" key="IBDocument.PluginDependencies">
+ <bool key="EncodedWithXMLCoder">YES</bool>
+ <string>com.apple.InterfaceBuilderKit</string>
+ <string>com.apple.InterfaceBuilder.CocoaPlugin</string>
+ </object>
+ <object class="NSMutableArray" key="IBDocument.RootObjects" id="1000">
+ <bool key="EncodedWithXMLCoder">YES</bool>
+ <object class="NSCustomObject" id="1001">
+ <string key="NSClassName">BookmarkController</string>
+ </object>
+ <object class="NSCustomObject" id="1003">
+ <string key="NSClassName">FirstResponder</string>
+ </object>
+ <object class="NSCustomObject" id="1004">
+ <string key="NSClassName">NSApplication</string>
+ </object>
+ <object class="NSWindowTemplate" id="109038487">
+ <int key="NSWindowStyleMask">87</int>
+ <int key="NSWindowBacking">2</int>
+ <string key="NSWindowRect">{{196, 376}, {435, 134}}</string>
+ <int key="NSWTFlags">-1543502848</int>
+ <string key="NSWindowTitle">Window</string>
+ <string key="NSWindowClass">NSWindow</string>
+ <nil key="NSViewClass"/>
+ <string key="NSWindowContentMaxSize">{3.40282e+38, 3.40282e+38}</string>
+ <object class="NSView" key="NSWindowView" id="437202143">
+ <reference key="NSNextResponder"/>
+ <int key="NSvFlags">256</int>
+ <object class="NSMutableArray" key="NSSubviews">
+ <bool key="EncodedWithXMLCoder">YES</bool>
+ <object class="NSTextField" id="947288821">
+ <reference key="NSNextResponder" ref="437202143"/>
+ <int key="NSvFlags">268</int>
+ <string key="NSFrame">{{17, 97}, {38, 17}}</string>
+ <reference key="NSSuperview" ref="437202143"/>
+ <bool key="NSEnabled">YES</bool>
+ <object class="NSTextFieldCell" key="NSCell" id="1032422399">
+ <int key="NSCellFlags">68288064</int>
+ <int key="NSCellFlags2">272630784</int>
+ <string key="NSContents">Title:</string>
+ <object class="NSFont" key="NSSupport" id="369980128">
+ <string key="NSName">LucidaGrande</string>
+ <double key="NSSize">1.300000e+01</double>
+ <int key="NSfFlags">1044</int>
+ </object>
+ <reference key="NSControlView" ref="947288821"/>
+ <object class="NSColor" key="NSBackgroundColor" id="74996181">
+ <int key="NSColorSpace">6</int>
+ <string key="NSCatalogName">System</string>
+ <string key="NSColorName">controlColor</string>
+ <object class="NSColor" key="NSColor">
+ <int key="NSColorSpace">3</int>
+ <bytes key="NSWhite">MC42NjY2NjY2OQA</bytes>
+ </object>
+ </object>
+ <object class="NSColor" key="NSTextColor" id="177624219">
+ <int key="NSColorSpace">6</int>
+ <string key="NSCatalogName">System</string>
+ <string key="NSColorName">controlTextColor</string>
+ <object class="NSColor" key="NSColor" id="939875636">
+ <int key="NSColorSpace">3</int>
+ <bytes key="NSWhite">MAA</bytes>
+ </object>
+ </object>
+ </object>
+ </object>
+ <object class="NSTextField" id="157383008">
+ <reference key="NSNextResponder" ref="437202143"/>
+ <int key="NSvFlags">268</int>
+ <string key="NSFrame">{{17, 65}, {39, 17}}</string>
+ <reference key="NSSuperview" ref="437202143"/>
+ <bool key="NSEnabled">YES</bool>
+ <object class="NSTextFieldCell" key="NSCell" id="332196678">
+ <int key="NSCellFlags">68288064</int>
+ <int key="NSCellFlags2">272630784</int>
+ <string key="NSContents">Tags:</string>
+ <reference key="NSSupport" ref="369980128"/>
+ <reference key="NSControlView" ref="157383008"/>
+ <reference key="NSBackgroundColor" ref="74996181"/>
+ <reference key="NSTextColor" ref="177624219"/>
+ </object>
+ </object>
+ <object class="NSTextField" id="420816584">
+ <reference key="NSNextResponder" ref="437202143"/>
+ <int key="NSvFlags">268</int>
+ <string key="NSFrame">{{68, 92}, {347, 22}}</string>
+ <reference key="NSSuperview" ref="437202143"/>
+ <bool key="NSEnabled">YES</bool>
+ <object class="NSTextFieldCell" key="NSCell" id="757422542">
+ <int key="NSCellFlags">-1804468671</int>
+ <int key="NSCellFlags2">272630784</int>
+ <string key="NSContents"/>
+ <reference key="NSSupport" ref="369980128"/>
+ <reference key="NSControlView" ref="420816584"/>
+ <bool key="NSDrawsBackground">YES</bool>
+ <object class="NSColor" key="NSBackgroundColor" id="434197410">
+ <int key="NSColorSpace">6</int>
+ <string key="NSCatalogName">System</string>
+ <string key="NSColorName">textBackgroundColor</string>
+ <object class="NSColor" key="NSColor">
+ <int key="NSColorSpace">3</int>
+ <bytes key="NSWhite">MQA</bytes>
+ </object>
+ </object>
+ <object class="NSColor" key="NSTextColor" id="86400202">
+ <int key="NSColorSpace">6</int>
+ <string key="NSCatalogName">System</string>
+ <string key="NSColorName">textColor</string>
+ <reference key="NSColor" ref="939875636"/>
+ </object>
+ </object>
+ </object>
+ <object class="NSTextField" id="810068274">
+ <reference key="NSNextResponder" ref="437202143"/>
+ <int key="NSvFlags">268</int>
+ <string key="NSFrame">{{68, 60}, {347, 22}}</string>
+ <reference key="NSSuperview" ref="437202143"/>
+ <bool key="NSEnabled">YES</bool>
+ <object class="NSTextFieldCell" key="NSCell" id="398524192">
+ <int key="NSCellFlags">-1804468671</int>
+ <int key="NSCellFlags2">272630784</int>
+ <string key="NSContents"/>
+ <reference key="NSSupport" ref="369980128"/>
+ <reference key="NSControlView" ref="810068274"/>
+ <bool key="NSDrawsBackground">YES</bool>
+ <reference key="NSBackgroundColor" ref="434197410"/>
+ <reference key="NSTextColor" ref="86400202"/>
+ </object>
+ </object>
+ <object class="NSTextField" id="1060076365">
+ <reference key="NSNextResponder" ref="437202143"/>
+ <int key="NSvFlags">268</int>
+ <string key="NSFrame">{{65, 35}, {146, 17}}</string>
+ <reference key="NSSuperview" ref="437202143"/>
+ <bool key="NSEnabled">YES</bool>
+ <object class="NSTextFieldCell" key="NSCell" id="171169959">
+ <int key="NSCellFlags">68288064</int>
+ <int key="NSCellFlags2">272630784</int>
+ <string key="NSContents">comma separated list</string>
+ <reference key="NSSupport" ref="369980128"/>
+ <reference key="NSControlView" ref="1060076365"/>
+ <reference key="NSBackgroundColor" ref="74996181"/>
+ <reference key="NSTextColor" ref="177624219"/>
+ </object>
+ </object>
+ <object class="NSButton" id="869693595">
+ <reference key="NSNextResponder" ref="437202143"/>
+ <int key="NSvFlags">268</int>
+ <string key="NSFrame">{{325, 12}, {96, 32}}</string>
+ <reference key="NSSuperview" ref="437202143"/>
+ <int key="NSTag">1</int>
+ <bool key="NSEnabled">YES</bool>
+ <object class="NSButtonCell" key="NSCell" id="781166857">
+ <int key="NSCellFlags">67239424</int>
+ <int key="NSCellFlags2">134217728</int>
+ <string key="NSContents">Add</string>
+ <reference key="NSSupport" ref="369980128"/>
+ <reference key="NSControlView" ref="869693595"/>
+ <int key="NSButtonFlags">-2038284033</int>
+ <int key="NSButtonFlags2">129</int>
+ <string key="NSAlternateContents"/>
+ <string key="NSKeyEquivalent"/>
+ <int key="NSPeriodicDelay">200</int>
+ <int key="NSPeriodicInterval">25</int>
+ </object>
+ </object>
+ <object class="NSButton" id="753371883">
+ <reference key="NSNextResponder" ref="437202143"/>
+ <int key="NSvFlags">268</int>
+ <string key="NSFrame">{{229, 12}, {96, 32}}</string>
+ <reference key="NSSuperview" ref="437202143"/>
+ <bool key="NSEnabled">YES</bool>
+ <object class="NSButtonCell" key="NSCell" id="941102160">
+ <int key="NSCellFlags">67239424</int>
+ <int key="NSCellFlags2">134217728</int>
+ <string key="NSContents">Cancel</string>
+ <reference key="NSSupport" ref="369980128"/>
+ <reference key="NSControlView" ref="753371883"/>
+ <int key="NSButtonFlags">-2038284033</int>
+ <int key="NSButtonFlags2">129</int>
+ <string key="NSAlternateContents"/>
+ <string key="NSKeyEquivalent"/>
+ <int key="NSPeriodicDelay">200</int>
+ <int key="NSPeriodicInterval">25</int>
+ </object>
+ </object>
+ </object>
+ <string key="NSFrameSize">{435, 134}</string>
+ <reference key="NSSuperview"/>
+ </object>
+ <string key="NSScreenRect">{{0, 0}, {1920, 1178}}</string>
+ <string key="NSMaxSize">{3.40282e+38, 3.40282e+38}</string>
+ </object>
+ </object>
+ <object class="IBObjectContainer" key="IBDocument.Objects">
+ <object class="NSMutableArray" key="connectionRecords">
+ <bool key="EncodedWithXMLCoder">YES</bool>
+ <object class="IBConnectionRecord">
+ <object class="IBOutletConnection" key="connection">
+ <string key="label">addPanel</string>
+ <reference key="source" ref="1001"/>
+ <reference key="destination" ref="109038487"/>
+ </object>
+ <int key="connectionID">53</int>
+ </object>
+ <object class="IBConnectionRecord">
+ <object class="IBActionConnection" key="connection">
+ <string key="label">endAddBookmark:</string>
+ <reference key="source" ref="1001"/>
+ <reference key="destination" ref="753371883"/>
+ </object>
+ <int key="connectionID">54</int>
+ </object>
+ <object class="IBConnectionRecord">
+ <object class="IBActionConnection" key="connection">
+ <string key="label">endAddBookmark:</string>
+ <reference key="source" ref="1001"/>
+ <reference key="destination" ref="869693595"/>
+ </object>
+ <int key="connectionID">55</int>
+ </object>
+ <object class="IBConnectionRecord">
+ <object class="IBOutletConnection" key="connection">
+ <string key="label">titleField</string>
+ <reference key="source" ref="1001"/>
+ <reference key="destination" ref="420816584"/>
+ </object>
+ <int key="connectionID">56</int>
+ </object>
+ <object class="IBConnectionRecord">
+ <object class="IBOutletConnection" key="connection">
+ <string key="label">tagField</string>
+ <reference key="source" ref="1001"/>
+ <reference key="destination" ref="810068274"/>
+ </object>
+ <int key="connectionID">57</int>
+ </object>
+ </object>
+ <object class="IBMutableOrderedSet" key="objectRecords">
+ <object class="NSArray" key="orderedObjects">
+ <bool key="EncodedWithXMLCoder">YES</bool>
+ <object class="IBObjectRecord">
+ <int key="objectID">0</int>
+ <object class="NSArray" key="object" id="1002">
+ <bool key="EncodedWithXMLCoder">YES</bool>
+ </object>
+ <reference key="children" ref="1000"/>
+ <nil key="parent"/>
+ </object>
+ <object class="IBObjectRecord">
+ <int key="objectID">-2</int>
+ <reference key="object" ref="1001"/>
+ <reference key="parent" ref="1002"/>
+ <string type="base64-UTF8" key="objectName">RmlsZSdzIE93bmVyA</string>
+ </object>
+ <object class="IBObjectRecord">
+ <int key="objectID">-1</int>
+ <reference key="object" ref="1003"/>
+ <reference key="parent" ref="1002"/>
+ <string key="objectName">First Responder</string>
+ </object>
+ <object class="IBObjectRecord">
+ <int key="objectID">-3</int>
+ <reference key="object" ref="1004"/>
+ <reference key="parent" ref="1002"/>
+ <string key="objectName">Application</string>
+ </object>
+ <object class="IBObjectRecord">
+ <int key="objectID">20</int>
+ <reference key="object" ref="109038487"/>
+ <object class="NSMutableArray" key="children">
+ <bool key="EncodedWithXMLCoder">YES</bool>
+ <reference ref="437202143"/>
+ </object>
+ <reference key="parent" ref="1002"/>
+ </object>
+ <object class="IBObjectRecord">
+ <int key="objectID">21</int>
+ <reference key="object" ref="437202143"/>
+ <object class="NSMutableArray" key="children">
+ <bool key="EncodedWithXMLCoder">YES</bool>
+ <reference ref="157383008"/>
+ <reference ref="810068274"/>
+ <reference ref="420816584"/>
+ <reference ref="947288821"/>
+ <reference ref="1060076365"/>
+ <reference ref="869693595"/>
+ <reference ref="753371883"/>
+ </object>
+ <reference key="parent" ref="109038487"/>
+ </object>
+ <object class="IBObjectRecord">
+ <int key="objectID">28</int>
+ <reference key="object" ref="753371883"/>
+ <object class="NSMutableArray" key="children">
+ <bool key="EncodedWithXMLCoder">YES</bool>
+ <reference ref="941102160"/>
+ </object>
+ <reference key="parent" ref="437202143"/>
+ </object>
+ <object class="IBObjectRecord">
+ <int key="objectID">29</int>
+ <reference key="object" ref="941102160"/>
+ <reference key="parent" ref="753371883"/>
+ </object>
+ <object class="IBObjectRecord">
+ <int key="objectID">27</int>
+ <reference key="object" ref="869693595"/>
+ <object class="NSMutableArray" key="children">
+ <bool key="EncodedWithXMLCoder">YES</bool>
+ <reference ref="781166857"/>
+ </object>
+ <reference key="parent" ref="437202143"/>
+ </object>
+ <object class="IBObjectRecord">
+ <int key="objectID">30</int>
+ <reference key="object" ref="781166857"/>
+ <reference key="parent" ref="869693595"/>
+ </object>
+ <object class="IBObjectRecord">
+ <int key="objectID">26</int>
+ <reference key="object" ref="1060076365"/>
+ <object class="NSMutableArray" key="children">
+ <bool key="EncodedWithXMLCoder">YES</bool>
+ <reference ref="171169959"/>
+ </object>
+ <reference key="parent" ref="437202143"/>
+ </object>
+ <object class="IBObjectRecord">
+ <int key="objectID">31</int>
+ <reference key="object" ref="171169959"/>
+ <reference key="parent" ref="1060076365"/>
+ </object>
+ <object class="IBObjectRecord">
+ <int key="objectID">25</int>
+ <reference key="object" ref="157383008"/>
+ <object class="NSMutableArray" key="children">
+ <bool key="EncodedWithXMLCoder">YES</bool>
+ <reference ref="332196678"/>
+ </object>
+ <reference key="parent" ref="437202143"/>
+ </object>
+ <object class="IBObjectRecord">
+ <int key="objectID">32</int>
+ <reference key="object" ref="332196678"/>
+ <reference key="parent" ref="157383008"/>
+ </object>
+ <object class="IBObjectRecord">
+ <int key="objectID">24</int>
+ <reference key="object" ref="810068274"/>
+ <object class="NSMutableArray" key="children">
+ <bool key="EncodedWithXMLCoder">YES</bool>
+ <reference ref="398524192"/>
+ </object>
+ <reference key="parent" ref="437202143"/>
+ </object>
+ <object class="IBObjectRecord">
+ <int key="objectID">33</int>
+ <reference key="object" ref="398524192"/>
+ <reference key="parent" ref="810068274"/>
+ </object>
+ <object class="IBObjectRecord">
+ <int key="objectID">23</int>
+ <reference key="object" ref="420816584"/>
+ <object class="NSMutableArray" key="children">
+ <bool key="EncodedWithXMLCoder">YES</bool>
+ <reference ref="757422542"/>
+ </object>
+ <reference key="parent" ref="437202143"/>
+ </object>
+ <object class="IBObjectRecord">
+ <int key="objectID">34</int>
+ <reference key="object" ref="757422542"/>
+ <reference key="parent" ref="420816584"/>
+ </object>
+ <object class="IBObjectRecord">
+ <int key="objectID">22</int>
+ <reference key="object" ref="947288821"/>
+ <object class="NSMutableArray" key="children">
+ <bool key="EncodedWithXMLCoder">YES</bool>
+ <reference ref="1032422399"/>
+ </object>
+ <reference key="parent" ref="437202143"/>
+ </object>
+ <object class="IBObjectRecord">
+ <int key="objectID">35</int>
+ <reference key="object" ref="1032422399"/>
+ <reference key="parent" ref="947288821"/>
+ </object>
+ </object>
+ </object>
+ <object class="NSMutableDictionary" key="flattenedProperties">
+ <bool key="EncodedWithXMLCoder">YES</bool>
+ <object class="NSMutableArray" key="dict.sortedKeys">
+ <bool key="EncodedWithXMLCoder">YES</bool>
+ <string>-1.IBPluginDependency</string>
+ <string>-2.IBPluginDependency</string>
+ <string>-3.IBPluginDependency</string>
+ <string>20.IBEditorWindowLastContentRect</string>
+ <string>20.IBPluginDependency</string>
+ <string>20.IBWindowTemplateEditedContentRect</string>
+ <string>20.NSWindowTemplate.visibleAtLaunch</string>
+ <string>20.windowTemplate.maxSize</string>
+ <string>21.IBPluginDependency</string>
+ <string>22.IBPluginDependency</string>
+ <string>23.IBPluginDependency</string>
+ <string>24.IBPluginDependency</string>
+ <string>25.IBPluginDependency</string>
+ <string>26.IBPluginDependency</string>
+ <string>27.IBPluginDependency</string>
+ <string>28.IBPluginDependency</string>
+ <string>29.IBPluginDependency</string>
+ <string>30.IBPluginDependency</string>
+ <string>31.IBPluginDependency</string>
+ <string>32.IBPluginDependency</string>
+ <string>33.IBPluginDependency</string>
+ <string>34.IBPluginDependency</string>
+ <string>35.IBPluginDependency</string>
+ </object>
+ <object class="NSMutableArray" key="dict.values">
+ <bool key="EncodedWithXMLCoder">YES</bool>
+ <string>com.apple.InterfaceBuilder.CocoaPlugin</string>
+ <string>com.apple.InterfaceBuilderKit</string>
+ <string>com.apple.InterfaceBuilderKit</string>
+ <string>{{504, 949}, {435, 134}}</string>
+ <string>com.apple.InterfaceBuilder.CocoaPlugin</string>
+ <string>{{504, 949}, {435, 134}}</string>
+ <integer value="0"/>
+ <string>{3.40282e+38, 3.40282e+38}</string>
+ <string>com.apple.InterfaceBuilder.CocoaPlugin</string>
+ <string>com.apple.InterfaceBuilder.CocoaPlugin</string>
+ <string>com.apple.InterfaceBuilder.CocoaPlugin</string>
+ <string>com.apple.InterfaceBuilder.CocoaPlugin</string>
+ <string>com.apple.InterfaceBuilder.CocoaPlugin</string>
+ <string>com.apple.InterfaceBuilder.CocoaPlugin</string>
+ <string>com.apple.InterfaceBuilder.CocoaPlugin</string>
+ <string>com.apple.InterfaceBuilder.CocoaPlugin</string>
+ <string>com.apple.InterfaceBuilder.CocoaPlugin</string>
+ <string>com.apple.InterfaceBuilder.CocoaPlugin</string>
+ <string>com.apple.InterfaceBuilder.CocoaPlugin</string>
+ <string>com.apple.InterfaceBuilder.CocoaPlugin</string>
+ <string>com.apple.InterfaceBuilder.CocoaPlugin</string>
+ <string>com.apple.InterfaceBuilder.CocoaPlugin</string>
+ <string>com.apple.InterfaceBuilder.CocoaPlugin</string>
+ </object>
+ </object>
+ <object class="NSMutableDictionary" key="unlocalizedProperties">
+ <bool key="EncodedWithXMLCoder">YES</bool>
+ <object class="NSArray" key="dict.sortedKeys">
+ <bool key="EncodedWithXMLCoder">YES</bool>
+ </object>
+ <object class="NSMutableArray" key="dict.values">
+ <bool key="EncodedWithXMLCoder">YES</bool>
+ </object>
+ </object>
+ <nil key="activeLocalization"/>
+ <object class="NSMutableDictionary" key="localizations">
+ <bool key="EncodedWithXMLCoder">YES</bool>
+ <object class="NSArray" key="dict.sortedKeys">
+ <bool key="EncodedWithXMLCoder">YES</bool>
+ </object>
+ <object class="NSMutableArray" key="dict.values">
+ <bool key="EncodedWithXMLCoder">YES</bool>
+ </object>
+ </object>
+ <nil key="sourceID"/>
+ <int key="maxID">57</int>
+ </object>
+ <object class="IBClassDescriber" key="IBDocument.Classes">
+ <object class="NSMutableArray" key="referencedPartialClassDescriptions">
+ <bool key="EncodedWithXMLCoder">YES</bool>
+ <object class="IBPartialClassDescription">
+ <string key="className">BookmarkController</string>
+ <string key="superclassName">NSWindowController</string>
+ <object class="NSMutableDictionary" key="actions">
+ <bool key="EncodedWithXMLCoder">YES</bool>
+ <object class="NSMutableArray" key="dict.sortedKeys">
+ <bool key="EncodedWithXMLCoder">YES</bool>
+ <string>endAddBookmark:</string>
+ <string>showAddBookmark:</string>
+ </object>
+ <object class="NSMutableArray" key="dict.values">
+ <bool key="EncodedWithXMLCoder">YES</bool>
+ <string>id</string>
+ <string>id</string>
+ </object>
+ </object>
+ <object class="NSMutableDictionary" key="outlets">
+ <bool key="EncodedWithXMLCoder">YES</bool>
+ <object class="NSMutableArray" key="dict.sortedKeys">
+ <bool key="EncodedWithXMLCoder">YES</bool>
+ <string>addPanel</string>
+ <string>managePanel</string>
+ <string>tagField</string>
+ <string>titleField</string>
+ </object>
+ <object class="NSMutableArray" key="dict.values">
+ <bool key="EncodedWithXMLCoder">YES</bool>
+ <string>NSWindow</string>
+ <string>NSPanel</string>
+ <string>NSTextField</string>
+ <string>NSTextField</string>
+ </object>
+ </object>
+ <object class="IBClassDescriptionSource" key="sourceIdentifier">
+ <string key="majorKey">IBProjectSource</string>
+ <string key="minorKey">BookmarkController.h</string>
+ </object>
+ </object>
+ </object>
+ </object>
+ <int key="IBDocument.localizationMode">0</int>
+ <string key="IBDocument.LastKnownRelativeProjectPath">ichm.xcodeproj</string>
+ <int key="IBDocument.defaultPropertyAccessControl">3</int>
+ </data>
+</archive>
View
34 BookmarkController.h
@@ -0,0 +1,34 @@
+//
+// BookmarkController.h
+// ichm
+//
+// Created by Robin Lu on 8/10/08.
+// Copyright 2008 __MyCompanyName__. All rights reserved.
+//
+
+#import <Cocoa/Cocoa.h>
+@class CHMFile;
+
+@interface BookmarkController : NSWindowController {
+ IBOutlet NSWindow* addPanel;
+ IBOutlet NSTextField* titleField;
+ IBOutlet NSTextField* tagField;
+ IBOutlet NSMenu *bookmarkMenu;
+
+ IBOutlet NSPanel* managePanel;
+
+ NSManagedObjectModel *managedObjectModel;
+ NSManagedObjectContext *managedObjectContext;
+
+}
+
+- (IBAction)showAddBookmark:(id)sender;
+- (IBAction)endAddBookmark:(id)sender;
+- (IBAction)openBookmark:(id)sender;
+- (void)addBookmarkDidEnd:(NSWindow *)sheet returnCode:(int)returnCode contextInfo:(void *)contextInfo;
+
+- (NSManagedObjectModel *)managedObjectModel;
+- (NSManagedObjectContext *)managedObjectContext;
+
+- (CHMFile *)fileByPath:(NSString*)path;
+@end
View
229 BookmarkController.m
@@ -0,0 +1,229 @@
+//
+// BookmarkController.m
+// ichm
+//
+// Created by Robin Lu on 8/10/08.
+// Copyright 2008 __MyCompanyName__. All rights reserved.
+//
+
+#import "BookmarkController.h"
+#import "CHMDocument.h"
+#import "CHMFile.h"
+#import "CHMBookmark.h"
+
+
+@implementation BookmarkController
+- (id)init
+{
+ if (![super initWithWindowNibName:@"Bookmark"])
+ return nil;
+ return self;
+}
+
+- (void)windowDidLoad
+{
+ NSLog(@"Nib file is loaded");
+}
+
+- (IBAction)showAddBookmark:(id)sender
+{
+ // force load of nib
+ [self window];
+
+
+ CHMDocument *doc = (CHMDocument*)sender;
+ [titleField setStringValue:[doc currentTitle]];
+ [titleField selectText:self];
+ [NSApp beginSheet:addPanel modalForWindow:[doc windowForSheet] modalDelegate:self didEndSelector:@selector(addBookmarkDidEnd:returnCode:contextInfo:) contextInfo:doc];
+
+}
+
+- (IBAction)endAddBookmark:(id)sender
+{
+ unsigned int tag = [sender tag];
+ [NSApp endSheet:addPanel returnCode:tag];
+ [addPanel orderOut:sender];
+}
+
+- (void)addBookmarkDidEnd:(NSWindow *)sheet returnCode:(int)returnCode contextInfo:(void *)contextInfo
+{
+ NSLog(@"add bookmark ended with return code:%d", returnCode);
+ if( 0 == returnCode || !contextInfo)
+ return;
+
+ CHMDocument *doc = contextInfo;
+ NSError *error = nil;
+ NSManagedObjectContext *context =[self managedObjectContext];
+
+ CHMFile *chmFile = [self fileByPath:[doc filePath]] ;
+ if (!chmFile)
+ {
+ chmFile = [NSEntityDescription
+ insertNewObjectForEntityForName:@"File"
+ inManagedObjectContext:context];
+ [chmFile setPath:[doc filePath]];
+ [context save:&error];
+ if ( ![context save:&error] )
+ NSLog(@"Can not fetch file info: %d",error );
+ }
+
+ CHMBookmark *bookmark = [NSEntityDescription
+ insertNewObjectForEntityForName:@"Bookmark"
+ inManagedObjectContext:context];
+ [bookmark setPath:[doc currentURL]];
+ [bookmark setTitle:[titleField stringValue]];
+ [bookmark setCreatedAt:[NSDate date]];
+ [bookmark setFile:chmFile];
+ if ( ![context save:&error] )
+ {
+ NSLog(@"Can not fetch file info: %d",error );
+ return;
+ }
+
+ NSMenuItem *newitem = [[[NSMenuItem alloc] init] autorelease];
+ [newitem setTitle:bookmark.title];
+ [newitem setTarget:self];
+ [newitem setAction:@selector(openBookmark:)];
+ [newitem setRepresentedObject:bookmark];
+ [newitem setEnabled:YES];
+ [bookmarkMenu insertItem:newitem atIndex:3];
+}
+
+#pragma mark CoreData context
+- (NSString *)applicationSupportFolder {
+
+ NSString *applicationSupportFolder = nil;
+ NSArray *paths = NSSearchPathForDirectoriesInDomains(NSApplicationSupportDirectory, NSUserDomainMask, YES);
+ if ( [paths count] == 0 ) {
+ NSRunAlertPanel(@"Alert", @"Can't find application support folder", @"Quit", nil, nil);
+ [[NSApplication sharedApplication] terminate:self];
+ } else {
+ applicationSupportFolder = [[paths objectAtIndex:0] stringByAppendingPathComponent:@"iChm"];
+ }
+ return applicationSupportFolder;
+}
+
+- (NSManagedObjectModel *)managedObjectModel {
+ if (managedObjectModel) return managedObjectModel;
+
+ NSMutableSet *allBundles = [[NSMutableSet alloc] init];
+ [allBundles addObject: [NSBundle mainBundle]];
+
+ managedObjectModel = [[NSManagedObjectModel mergedModelFromBundles: [allBundles allObjects]] retain];
+ [allBundles release];
+
+ return managedObjectModel;
+}
+
+- (NSManagedObjectContext *) managedObjectContext {
+ NSError *error;
+ NSString *applicationSupportFolder = nil;
+ NSURL *url;
+ NSFileManager *fileManager;
+ NSPersistentStoreCoordinator *coordinator;
+
+ if (managedObjectContext) {
+ return managedObjectContext;
+ }
+
+ fileManager = [NSFileManager defaultManager];
+ applicationSupportFolder = [self applicationSupportFolder];
+ if ( ![fileManager fileExistsAtPath:applicationSupportFolder isDirectory:NULL] ) {
+ [fileManager createDirectoryAtPath:applicationSupportFolder attributes:nil];
+ }
+
+ url = [NSURL fileURLWithPath: [applicationSupportFolder stringByAppendingPathComponent: @"Bookmarks.sqlite"]];
+ coordinator = [[NSPersistentStoreCoordinator alloc] initWithManagedObjectModel: [self managedObjectModel]];
+ if ([coordinator addPersistentStoreWithType:NSSQLiteStoreType configuration:nil URL:url options:nil error:&error]){
+ managedObjectContext = [[NSManagedObjectContext alloc] init];
+ [managedObjectContext setPersistentStoreCoordinator: coordinator];
+ } else {
+ [[NSApplication sharedApplication] presentError:error];
+ }
+ [coordinator release];
+
+ return managedObjectContext;
+}
+
+#pragma mark data accessing
+- (CHMFile *)fileByPath:(NSString*)path
+{
+ if (!path)
+ return nil;
+
+ NSManagedObjectContext *context =[self managedObjectContext];
+ NSFetchRequest *request = [[[NSFetchRequest alloc] init] autorelease];
+ NSEntityDescription *fileEntity = [NSEntityDescription
+ entityForName:@"File" inManagedObjectContext:context];
+ [request setEntity:fileEntity];
+ NSPredicate *predicate = [NSPredicate predicateWithFormat:
+ @"path == %@", path];
+ [request setPredicate:predicate];
+ NSError *error = nil;
+ NSArray *array = [context executeFetchRequest:request error:&error];
+ if (array == nil)
+ {
+ NSLog(@"Can not fetch file info: %d",error );
+ return nil;
+ }
+ if ([array count] == 0)
+ {
+ NSLog(@"Can not fetch file with path: %%",path );
+ return nil;
+ }
+ return [array objectAtIndex:0];
+}
+
+#pragma mark Bookmark Menu
+
+#define BOOKMAKR_LIMIT 15
+
+- (void)menuNeedsUpdate:(NSMenu *)menu
+{
+ NSDocumentController *controller = [NSDocumentController sharedDocumentController];
+ [[menu itemWithTag:0] setEnabled:(nil != [controller currentDocument])];
+
+ while ([menu numberOfItems] > 3)
+ {
+ [menu removeItemAtIndex:3];
+ }
+
+ NSManagedObjectContext *context =[self managedObjectContext];
+ NSFetchRequest *request = [[[NSFetchRequest alloc] init] autorelease];
+ NSEntityDescription *bookmarkEntity = [NSEntityDescription
+ entityForName:@"Bookmark" inManagedObjectContext:context];
+ [request setEntity:bookmarkEntity];
+ [request setFetchLimit:BOOKMAKR_LIMIT];
+ NSSortDescriptor *sortDescriptor = [[NSSortDescriptor alloc]
+ initWithKey:@"createdAt" ascending:NO];
+ [request setSortDescriptors:[NSArray arrayWithObject:sortDescriptor]];
+ [sortDescriptor release];
+
+ NSError *error = nil;
+ NSArray *array = [context executeFetchRequest:request error:&error];
+ if (array == nil)
+ {
+ NSLog(@"Can not fetch file info: %d",error );
+ return;
+ }
+ for (CHMBookmark* bm in array) {
+ NSMenuItem *newitem = [[[NSMenuItem alloc] init] autorelease];
+ [newitem setTitle:[bm title]];
+ [newitem setTarget:self];
+ [newitem setAction:@selector(openBookmark:)];
+ [newitem setRepresentedObject:bm];
+ [newitem setEnabled:YES];
+ [menu addItem:newitem];
+ }
+}
+
+- (IBAction)openBookmark:(id)sender
+{
+ NSDocumentController *controller = [NSDocumentController sharedDocumentController];
+ NSError *error = nil;
+ CHMBookmark * bm = (CHMBookmark*)[sender representedObject];
+ NSURL *url = [NSURL fileURLWithPath:bm.file.path];
+ CHMDocument* doc = [controller openDocumentWithContentsOfURL:url display:YES error:&error];
+ [doc loadURL:[NSURL URLWithString:bm.path]];
+}
+@end
View
BIN  Bookmarks.xcdatamodel/elements
Binary file not shown
View
BIN  Bookmarks.xcdatamodel/layout
Binary file not shown
View
33 CHMBookmark.h
@@ -0,0 +1,33 @@
+//
+// CHMBookmark.h
+// ichm
+//
+// Created by Robin Lu on 8/11/08.
+// Copyright 2008 __MyCompanyName__. All rights reserved.
+//
+
+#import <CoreData/CoreData.h>
+
+@class CHMFile;
+@class CHMTag;
+
+@interface CHMBookmark : NSManagedObject
+{
+}
+
+@property (retain) NSString * path;
+@property (retain) NSString * title;
+@property (retain) NSDate * createdAt;
+@property (retain) CHMFile * file;
+@property (retain) NSSet* tags;
+
+@end
+
+@interface CHMBookmark (CoreDataGeneratedAccessors)
+- (void)addTagsObject:(CHMTag *)value;
+- (void)removeTagsObject:(CHMTag *)value;
+- (void)addTags:(NSSet *)value;
+- (void)removeTags:(NSSet *)value;
+
+@end
+
View
22 CHMBookmark.m
@@ -0,0 +1,22 @@
+//
+// CHMBookmark.m
+// ichm
+//
+// Created by Robin Lu on 8/11/08.
+// Copyright 2008 __MyCompanyName__. All rights reserved.
+//
+
+#import "CHMBookmark.h"
+
+#import "CHMFile.h"
+#import "CHMTag.h"
+
+@implementation CHMBookmark
+
+@dynamic path;
+@dynamic title;
+@dynamic createdAt;
+@dynamic file;
+@dynamic tags;
+
+@end
View
115 CHMDocument.h
@@ -0,0 +1,115 @@
+//
+// CHMDocument.h
+// ichm
+//
+// Created by Robin Lu on 7/16/08.
+// Copyright __MyCompanyName__ 2008 . All rights reserved.
+//
+
+
+#import <Cocoa/Cocoa.h>
+
+@class WebView;
+@class CHMTableOfContent;
+@class CHMSearchResult;
+@class LinkItem;
+@class PSMTabBarControl;
+@class CHMConsole;
+struct chmFile;
+
+@interface CHMDocument : NSDocument {
+ IBOutlet PSMTabBarControl *tabBar;
+ IBOutlet NSTabView *docTabView;
+ IBOutlet NSOutlineView *tocView;
+ IBOutlet NSWindow *documentWindow;
+ IBOutlet NSSegmentedControl *historyItemView;
+ IBOutlet NSButton *homeItemView;
+ IBOutlet NSSegmentedControl *textSizeItemView;
+ IBOutlet NSButton* sidebarItemView;
+ IBOutlet NSSearchField *searchItemView;
+ IBOutlet NSSplitView *splitView;
+ IBOutlet NSMenuItem *textEncodingMenu;
+ IBOutlet NSPanel *addBookmarkPanel;
+
+ struct chmFile *chmFileHandle;
+ NSString *filePath;
+
+ NSString *docTitle;
+ NSString *homePath;
+ NSString *tocPath;
+ NSString *indexPath;
+
+ float sidebarWidth;
+
+ CHMTableOfContent *tocSource ;
+ CHMSearchResult *searchSource;
+
+ SKIndexRef skIndex;
+ NSMutableData *searchIndexObject;
+ NSMutableArray *webViews;
+ WebView *curWebView;
+ CHMConsole *console;
+
+ int customizedEncodingTag;
+ NSString* encodingName;
+}
+
+@property (readonly) NSString* filePath;
+- (NSString*)currentURL;
+- (NSString*)currentTitle;
+
+- (BOOL) exist: (const char *)path;
+- (NSData *)content: (NSString *)path;
+- (BOOL)loadMetadata;
+
+- (NSString *)findHomeForPath: (NSString *)basePath;
+- (void)highlightString:(NSString*)pattern;
+- (void)removeHighlight;
+- (void)buildSearchIndex;
+
+- (void)loadURL:(NSURL *)url;
+
+- (IBAction)changeTopic:(id)sender;
+- (IBAction)openInNewTab:(id)sender;
+
+- (IBAction)goForward:(id)sender;
+- (IBAction)goBack:(id)sender;
+- (IBAction)goHistory:(id)sender;
+- (IBAction)goHome:(id)sender;
+
+- (IBAction)locateTOC:(id)sender;
+
+- (IBAction)searchInFile:(id)sender;
+
+- (IBAction)zoom:(id)sender;
+- (IBAction)zoomIn:(id)sender;
+- (IBAction)zoomOut:(id)sender;
+
+- (IBAction)toggleSidebar:(id)sender;
+- (IBAction)hideSidebar:(id)sender;
+
+- (void)addToSearchIndex:(const char*)path;
+
+// find panel
+- (IBAction)showFindPanel:(id)sender;
+- (IBAction)beginFind:(id)sender;
+- (IBAction)findNext:(id)sender;
+- (IBAction)findPrev:(id)sender;
+- (IBAction)findInFile:(id)sender;
+- (IBAction)doneFind:(id)sender;
+
+// bookmark
+- (IBAction)showAddBookmark:(id)sender;
+
+// tab
+- (IBAction)addNewTab:(id)sender;
+- (IBAction)closeTab:(id)sender;
+
+//text encoding
+- (void)setupEncodingMenu;
+- (void)resetEncodingMenu;
+- (IBAction)changeEncoding:(id)sender;
+- (NSString*)getEncodingByTag:(int)tag;
+- (NSString*)currentEncodingName;
+
+@end
View
1,353 CHMDocument.m
@@ -0,0 +1,1353 @@
+//
+// CHMDocument.m
+// ichm
+//
+// Created by Robin Lu on 7/16/08.
+// Copyright __MyCompanyName__ 2008 . All rights reserved.
+//
+
+#import <WebKit/WebKit.h>
+#import "CHMDocument.h"
+#import <chm_lib/chm_lib.h>
+#import <PSMTabBarControl/PSMTabBarControl.h>
+#import "ITSSProtocol.h"
+#import "CHMTableOfContent.h"
+#import "CHMWebView.h"
+#import "ICHMApplication.h"
+#import "CHMTextEncodingMenu.h"
+#import "BookmarkController.h"
+#import "lcid.h"
+
+static NSString* ICHMToolbarIdentifier = @"ICHM Toolbar Identifier";
+static NSString* HistoryToolbarItemIdentifier = @"History Item Identifier";
+static NSString* TextSizeToolbarItemIdentifier = @"Text Size Item Identifier";
+static NSString* SearchToolbarItemIdentifier = @"Search Item Identifier";
+static NSString* HomeToolbarItemIdentifier = @"Home Item Identifier";
+static NSString* SidebarToolbarItemIdentifier = @"Sidebar Item Identifier";
+static NSString* WebVewPreferenceIndentifier = @"iCHM WebView Preferences";
+static int MinSidebarWidth = 180;
+
+@interface CHMConsole : NSObject
+{
+}
+
+- (void)log:(NSString*)string;
+@end
+
+@implementation CHMConsole
+
+- (void)log:(NSString*)string
+{
+ NSLog(string);
+}
+
++ (BOOL)isSelectorExcludedFromWebScript:(SEL)selector {
+ if (selector == @selector(log:)) {
+ return NO;
+ }
+ return YES;
+}
+
++ (NSString *) webScriptNameForSelector:(SEL)selector {
+ if (@selector(log:)) {
+ return @"log";
+ }
+ return nil;
+}
+
+@end
+
+@interface CHMDocument (Private)
+- (void)setupToolbar;
+- (void)updateHistoryButton;
+- (void)loadPath:(NSString *)path;
+
+- (void)prepareSearchIndex;
+
+- (void)setupTabBar;
+- (void)loadJavascript;
+- (void)runJavascript:(NSString*)script;
+
+- (void)after_zoom;
+
+- (NSTabViewItem*)createWebViewInTab:(id)sender;
+
+- (void)setupTOCSource;
+@end
+
+@implementation CHMDocument
+
+@synthesize filePath;
+
+- (id)init
+{
+ self = [super init];
+ if (self) {
+
+ // Add your subclass-specific initialization here.
+ // If an error occurs here, send a [self release] message and return nil.
+ chmFileHandle = nil;
+ filePath = nil;
+
+ docTitle = nil;
+ homePath = nil;
+ tocPath = nil;
+ indexPath = nil;
+
+ skIndex = nil;
+ searchIndexObject = nil;
+
+ tocSource = nil;
+ searchSource = nil;
+ webViews = [[NSMutableArray alloc] init];
+ console = [[CHMConsole alloc] init];
+ curWebView = nil;
+
+ sidebarWidth = MinSidebarWidth;
+
+ customizedEncodingTag = 0;
+ }
+ return self;
+}
+
+- (void) dealloc
+{
+ if( chmFileHandle ) {
+ chm_close( chmFileHandle );
+ }
+
+ [filePath release];
+ [docTitle release];
+ [homePath release];
+ [tocPath release];
+ [indexPath release];
+ [sidebarItemView release];
+ [historyItemView release];
+ [tocSource release];
+ [searchSource release];
+
+ if(!skIndex)
+ SKIndexClose(skIndex);
+ [searchIndexObject release];
+ [webViews release];
+ [super dealloc];
+}
+
+#pragma mark Basic CHM reading operations
+static inline NSStringEncoding nameToEncoding(NSString* name) {
+ if(!name || [name length] == 0)
+ return NSUTF8StringEncoding;
+ return CFStringConvertEncodingToNSStringEncoding(
+ CFStringConvertIANACharSetNameToEncoding((CFStringRef) name));
+}
+
+static inline unsigned short readShort( NSData *data, unsigned int offset ) {
+ NSRange valueRange = { offset, 2 };
+ unsigned short value;
+
+ [data getBytes:(void *)&value range:valueRange];
+ return NSSwapLittleShortToHost( value );
+}
+
+static inline unsigned long readLong( NSData *data, unsigned int offset ) {
+ NSRange valueRange = { offset, 4 };
+ unsigned long value;
+
+ [data getBytes:(void *)&value range:valueRange];
+ return NSSwapLittleLongToHost( value );
+}
+
+static inline NSString * readString( NSData *data, unsigned long offset, NSString *encodingName ) {
+ const char *stringData = (char *)[data bytes] + offset;
+ return [[NSString alloc] initWithCString:stringData encoding:nameToEncoding(encodingName)];
+}
+
+static inline NSString * readTrimmedString( NSData *data, unsigned long offset, NSString *encodingName ) {
+ NSString *str = readString(data, offset,encodingName);
+ return [str stringByTrimmingCharactersInSet:[NSCharacterSet whitespaceAndNewlineCharacterSet]];
+}
+
+static inline NSString * LCIDtoEncodingName(unsigned int lcid) {
+ NSString * name= nil;
+ switch (lcid) {
+ case LCID_CS: //1250
+ case LCID_HR: //1250
+ case LCID_HU: //1250
+ case LCID_PL: //1250
+ case LCID_RO: //1250
+ case LCID_SK: //1250
+ case LCID_SL: //1250
+ case LCID_SQ: //1250
+ case LCID_SR_SP: //1250
+ name = @"CP1250";
+ break;
+ case LCID_AZ_CY: //1251
+ case LCID_BE: //1251
+ case LCID_BG: //1251
+ case LCID_MS_MY: //1251
+ case LCID_RU: //1251
+ case LCID_SB: //1251
+ case LCID_SR_SP2: //1251
+ case LCID_TT: //1251
+ case LCID_UK: //1251
+ case LCID_UZ_UZ2: //1251
+ case LCID_YI: //1251
+ name = @"CP1251";
+ break;
+ case LCID_AF: //1252
+ case LCID_CA: //1252
+ case LCID_DA: //1252
+ case LCID_DE_AT: //1252
+ case LCID_DE_CH: //1252
+ case LCID_DE_DE: //1252
+ case LCID_DE_LI: //1252
+ case LCID_DE_LU: //1252
+ case LCID_EN_AU: //1252
+ case LCID_EN_BZ: //1252
+ case LCID_EN_CA: //1252
+ case LCID_EN_CB: //1252
+ case LCID_EN_GB: //1252
+ case LCID_EN_IE: //1252
+ case LCID_EN_JM: //1252
+ case LCID_EN_NZ: //1252
+ case LCID_EN_PH: //1252
+ case LCID_EN_TT: //1252
+ case LCID_EN_US: //1252
+ case LCID_EN_ZA: //1252
+ case LCID_ES_AR: //1252
+ case LCID_ES_BO: //1252
+ case LCID_ES_CL: //1252
+ case LCID_ES_CO: //1252
+ case LCID_ES_CR: //1252
+ case LCID_ES_DO: //1252
+ case LCID_ES_EC: //1252
+ case LCID_ES_ES: //1252
+ case LCID_ES_GT: //1252
+ case LCID_ES_HN: //1252
+ case LCID_ES_MX: //1252
+ case LCID_ES_NI: //1252
+ case LCID_ES_PA: //1252
+ case LCID_ES_PE: //1252
+ case LCID_ES_PR: //1252
+ case LCID_ES_PY: //1252
+ case LCID_ES_SV: //1252
+ case LCID_ES_UY: //1252
+ case LCID_ES_VE: //1252
+ case LCID_EU: //1252
+ case LCID_FI: //1252
+ case LCID_FO: //1252
+ case LCID_FR_BE: //1252
+ case LCID_FR_CA: //1252
+ case LCID_FR_CH: //1252
+ case LCID_FR_FR: //1252
+ case LCID_FR_LU: //1252
+ case LCID_GD: //1252
+ case LCID_HI: //1252
+ case LCID_ID: //1252
+ case LCID_IS: //1252
+ case LCID_IT_CH: //1252
+ case LCID_IT_IT: //1252
+ case LCID_MS_BN: //1252
+ case LCID_NL_BE: //1252
+ case LCID_NL_NL: //1252
+ case LCID_NO_NO: //1252
+ case LCID_NO_NO2: //1252
+ case LCID_PT_BR: //1252
+ case LCID_PT_PT: //1252
+ case LCID_SV_FI: //1252
+ case LCID_SV_SE: //1252
+ case LCID_SW: //1252
+ name = @"CP1252";
+ break;
+ case LCID_EL: //1253
+ name = @"CP1253";
+ break;
+ case LCID_AZ_LA: //1254
+ case LCID_TR: //1254
+ case LCID_UZ_UZ: //1254
+ name = @"CP1254";
+ break;
+ case LCID_HE: //1255
+ name = @"CP1255";
+ break;
+ case LCID_AR_AE: //1256
+ case LCID_AR_BH: //1256
+ case LCID_AR_DZ: //1256
+ case LCID_AR_EG: //1256
+ case LCID_AR_IQ: //1256
+ case LCID_AR_JO: //1256
+ case LCID_AR_KW: //1256
+ case LCID_AR_LB: //1256
+ case LCID_AR_LY: //1256
+ case LCID_AR_MA: //1256
+ case LCID_AR_OM: //1256
+ case LCID_AR_QA: //1256
+ case LCID_AR_SA: //1256
+ case LCID_AR_SY: //1256
+ case LCID_AR_TN: //1256
+ case LCID_AR_YE: //1256
+ case LCID_FA: //1256
+ case LCID_UR: //1256
+ name = @"CP1256";
+ break;
+ case LCID_ET: //1257
+ case LCID_LT: //1257
+ case LCID_LV: //1257
+ name = @"CP1257";
+ break;
+ case LCID_VI: //1258
+ name = @"CP1258";
+ break;
+ case LCID_TH: //874
+ name = @"CP874";
+ break;
+ case LCID_JA: //932
+ name = @"CP932";
+ break;
+ case LCID_ZH_CN: //936
+ case LCID_ZH_SG: //936
+ name = @"CP936";
+ break;
+ case LCID_KO: //949
+ name = @"CP949";
+ break;
+ case LCID_ZH_HK: //950
+ case LCID_ZH_MO: //950
+ case LCID_ZH_TW: //950
+ name = @"CP950";
+ break;
+ case LCID_GD_IE: //??
+ case LCID_MK: //??
+ case LCID_RM: //??
+ case LCID_RO_MO: //??
+ case LCID_RU_MO: //??
+ case LCID_ST: //??
+ case LCID_TN: //??
+ case LCID_TS: //??
+ case LCID_XH: //??
+ case LCID_ZU: //??
+ case LCID_HY: //0
+ case LCID_MR: //0
+ case LCID_MT: //0
+ case LCID_SA: //0
+ case LCID_TA: //0
+ default:
+ break;
+ }
+ return name;
+}
+
+# pragma mark chmlib
+- (BOOL) exist: (const char *)path
+{
+ struct chmUnitInfo info;
+ if (chmFileHandle)
+ return chm_resolve_object( chmFileHandle, path, &info ) != CHM_RESOLVE_SUCCESS;
+ return NO;
+}
+
+- (NSData *)content: (NSString *)path
+{
+ if( !path ) {
+ return nil;
+ }
+
+ if( [path hasPrefix:@"/"] ) {
+ if( [path hasPrefix:@"///"] ) {
+ path = [path substringFromIndex:2];
+ }
+ }
+ else {
+ path = [NSString stringWithFormat:@"/%@", path];
+ }
+
+ struct chmUnitInfo info;
+ if (chm_resolve_object( chmFileHandle, [path UTF8String], &info ) != CHM_RESOLVE_SUCCESS)
+ {
+ return nil;
+ }
+
+ void *buffer = malloc( info.length );
+
+ if( !buffer ) {
+ // Allocation failed
+ NSLog( @"Failed to allocate %qu bytes for %@", (long long)info.length, path );
+ return nil;
+ }
+
+ if( !chm_retrieve_object( chmFileHandle, &info, buffer, 0, info.length ) ) {
+ NSLog( @"Failed to load %qu bytes for %@", (long long)info.length, path );
+ free( buffer );
+ return nil;
+ }
+
+ return [NSData dataWithBytesNoCopy:buffer length:info.length];
+
+}
+
+- (BOOL)loadMetadata {
+ //--- Start with WINDOWS object ---
+ NSData *windowsData = [self content:@"/#WINDOWS"];
+ NSData *stringsData = [self content:@"/#STRINGS"];
+
+ if( windowsData && stringsData ) {
+ const unsigned long entryCount = readLong( windowsData, 0 );
+ const unsigned long entrySize = readLong( windowsData, 4 );
+
+ for( int entryIndex = 0; entryIndex < entryCount; ++entryIndex ) {
+ unsigned long entryOffset = 8 + ( entryIndex * entrySize );
+
+ if( !docTitle || ( [docTitle length] == 0 ) ) {
+ docTitle = readTrimmedString( stringsData, readLong( windowsData, entryOffset + 0x14), encodingName );
+ NSLog(@"STRINGS title: %@", docTitle);
+ }
+
+ if( !tocPath || ( [tocPath length] == 0 ) ) {
+ tocPath = readString( stringsData, readLong( windowsData, entryOffset + 0x60 ), encodingName );
+ NSLog(@"STRINGS path of TOC: %@", tocPath);
+ }
+
+ if( !indexPath || ( [indexPath length] == 0 ) ) {
+ indexPath = readString( stringsData, readLong( windowsData, entryOffset + 0x64 ), encodingName );
+ NSLog(@"STRINGS path of index file: %@", indexPath);
+ }
+
+ if( !homePath || ( [homePath length] == 0 ) ) {
+ homePath = readString( stringsData, readLong( windowsData, entryOffset + 0x68 ), encodingName );
+ NSLog(@"STRINGS path of home: %@", homePath);
+ }
+ }
+ }
+
+ //--- Use SYSTEM object ---
+ NSData *systemData = [self content:@"/#SYSTEM"];
+ if( systemData == nil ) {
+ return NO;
+ }
+
+ unsigned int maxOffset = [systemData length];
+ unsigned int offset = 4;
+ for( ;offset<maxOffset; ) {
+ switch( readShort( systemData, offset ) ) {
+ case 0:
+ if( !tocPath || ( [tocPath length] == 0 ) ) {
+ tocPath = readString( systemData, offset + 4, encodingName );
+ NSLog( @"SYSTEM Table of contents: %@", tocPath );
+ }
+ break;
+ case 1:
+ if( !indexPath || ( [indexPath length] == 0 ) ) {
+ indexPath = readString( systemData, offset + 4, encodingName );
+ NSLog( @"SYSTEM Index: %@", indexPath );
+ }
+ break;
+ case 2:
+ if( !homePath || ( [homePath length] == 0 ) ) {
+ homePath = readString( systemData, offset + 4, encodingName );
+ NSLog( @"SYSTEM Home: %@", homePath );
+ }
+ break;
+ case 3:
+ if( !docTitle || ( [docTitle length] == 0 ) ) {
+ docTitle = readTrimmedString( systemData, offset + 4, encodingName );
+ NSLog( @"SYSTEM Title: %@", docTitle );
+ }
+ break;
+ case 4:
+ {
+ unsigned int lcid = readLong(systemData, offset + 4);
+ NSLog(@"SYSTEM LCID: %d", lcid);
+ encodingName = LCIDtoEncodingName(lcid);
+ NSLog(@"SYSTEM encoding: %@", encodingName);
+ }
+ break;
+ case 6:
+ {
+ const char *data = (const char *)([systemData bytes] + offset + 4);
+ char *tmpname = malloc(strlen(data)+5);
+ if( !tocPath || [tocPath length] == 0 ) {
+ sprintf(tmpname, "/%s.hhc", data);
+ if ([self exist:tmpname])
+ {
+ tocPath = [[NSString alloc] initWithCString:tmpname encoding:nameToEncoding(encodingName)];
+ }
+ }
+ if ( !indexPath || [indexPath length] == 0 )
+ {
+ sprintf(tmpname, "/%s.hhk", data);
+ if ([self exist:tmpname])
+ {
+ indexPath = [[NSString alloc] initWithCString:tmpname encoding:nameToEncoding(encodingName)];
+ }
+ }
+ free(tmpname);
+ NSLog( @"SYSTEM Table of contents: %@", tocPath );
+ }
+ break;
+ case 9:
+ NSLog( @"SYSTEM Compiler: %@", readString( systemData, offset + 4, encodingName ) );
+ break;
+ case 16:
+ NSLog( @"SYSTEM Default font: %@", readString( systemData, offset + 4, encodingName ) );
+ break;
+ default:
+ NSLog(@"SYSTEM unhandled value:%d", readShort( systemData, offset ));
+ break;
+ }
+ offset += readShort(systemData, offset+2) + 4;
+ }
+
+ // Check for empty string titles
+ if( [docTitle length] == 0 ) {
+ docTitle = nil;
+ }
+ else {
+ [docTitle retain];
+ }
+
+ // Check for lack of index page
+ if( !homePath ) {
+ homePath = [self findHomeForPath:@"/"];
+ NSLog( @"Implicit home: %@", homePath );
+ }
+
+ [homePath retain];
+ [tocPath retain];
+ [indexPath retain];
+
+ return YES;
+}
+
+- (NSString *)findHomeForPath: (NSString *)basePath
+{
+ NSString *testPath;
+
+ NSString *separator = [basePath hasSuffix:@"/"]? @"" : @"/";
+ testPath = [NSString stringWithFormat:@"%@%@index.htm", basePath, separator];
+ if( [self exist:[testPath UTF8String]] ) {
+ return testPath;
+ }
+
+ testPath = [NSString stringWithFormat:@"%@%@default.html", basePath, separator];
+ if( [self exist:[testPath UTF8String]] ) {
+ return testPath;
+ }
+
+ testPath = [NSString stringWithFormat:@"%@%@default.htm", basePath, separator];
+ if( [self exist:[testPath UTF8String]] ) {
+ return testPath;
+ }
+
+ return [NSString stringWithFormat:@"%@%@index.html", basePath, separator];
+}
+
+# pragma mark NSDocument
+- (NSString *)windowNibName
+{
+ // Override returning the nib file name of the document
+ // If you need to use a subclass of NSWindowController or if your document supports multiple NSWindowControllers, you should remove this method and override -makeWindowControllers instead.
+ return @"CHMDocument";
+}
+
+- (void)windowControllerDidLoadNib:(NSWindowController *) aController
+{
+ [super windowControllerDidLoadNib:aController];
+
+ [self setupTabBar];
+ [self addNewTab:self];
+
+ [self goHome:self];
+
+ [tocView setDataSource:tocSource];
+ [tocView setAutoresizesOutlineColumn:NO];
+ if([tocSource rootChildrenCount]==0)
+ [self hideSidebar:self];
+
+ [self setupToolbar];
+
+ float curWidth = [tocView frame].size.width;
+ if(curWidth > MinSidebarWidth)
+ sidebarWidth = curWidth;
+
+ [self prepareSearchIndex];
+}
+
+- (NSData *)dataOfType:(NSString *)typeName error:(NSError **)outError
+{
+ // Insert code here to write your document to data of the specified type. If the given outError != NULL, ensure that you set *outError when returning nil.
+
+ // You can also choose to override -fileWrapperOfType:error:, -writeToURL:ofType:error:, or -writeToURL:ofType:forSaveOperation:originalContentsURL:error: instead.
+
+ // For applications targeted for Panther or earlier systems, you should use the deprecated API -dataRepresentationOfType:. In this case you can also choose to override -fileWrapperRepresentationOfType: or -writeToFile:ofType: instead.
+
+ if ( outError != NULL ) {
+ *outError = [NSError errorWithDomain:NSOSStatusErrorDomain code:unimpErr userInfo:NULL];
+ }
+ return nil;
+}
+
+- (void)setupTOCSource{
+ if(tocPath){
+ NSData * tocData = [self content:tocPath];
+ CHMTableOfContent* newTOC = [[CHMTableOfContent alloc] initWithData:tocData encodingName:[self currentEncodingName]];
+ CHMTableOfContent* oldTOC = tocSource;
+ tocSource = newTOC;
+
+ if(oldTOC)
+ [oldTOC release];
+ }
+}
+
+- (BOOL)readFromFile:(NSString *)fileName ofType:(NSString *)docType {
+ NSLog( @"CHMDocument:readFromFile:%@", fileName );
+ if(filePath) [filePath release];
+ filePath = fileName;
+ [filePath retain];
+
+ chmFileHandle = chm_open( [fileName fileSystemRepresentation] );
+ if( !chmFileHandle ) return NO;
+
+
+ [self loadMetadata];
+ [self setupTOCSource];
+ return YES;
+}
+
+- (void)close
+{
+ [self resetEncodingMenu];
+ [super close];
+}
+
+- (void)loadPath:(NSString *)path
+{
+ NSURL *url = [NSURL URLWithString:[NSString stringWithFormat:@"itss://chm/%@", path]];
+ [self loadURL:url];
+}
+
+- (void)loadURL:(NSURL *)url
+{
+ if( url ) {
+ NSURLRequest *req = [NSURLRequest requestWithURL:url];
+ [[curWebView mainFrame] loadRequest:req];
+ }
+}
+
+#pragma mark Properties
+- (NSString*)currentURL
+{
+ if(curWebView)
+ return [curWebView mainFrameURL];
+ return nil;
+}
+
+- (NSString*)currentTitle
+{
+ if(curWebView)
+ return [[docTabView selectedTabViewItem] label];
+ return nil;
+}
+
+# pragma mark WebFrameLoadDelegate
+- (void)webView:(WebView *)sender didFinishLoadForFrame:(WebFrame *)frame
+{
+ [self updateHistoryButton];
+ [self locateTOC:sender];
+
+ // set label for tab bar
+ NSURL * url = [NSURL URLWithString:[sender mainFrameURL]];
+ NSString *path = [url path];
+ LinkItem* item = [tocSource itemForPath:path withStack:nil];
+ NSTabViewItem *tabItem = [docTabView selectedTabViewItem];
+ NSString *name = [item name];
+ if(name && [name length]>0)
+ [tabItem setLabel:name];
+ else
+ [tabItem setLabel:NSLocalizedString(@"(Untitled)",@"(Untitled)")];
+
+ if (frame == [sender mainFrame])
+ {
+ [[curWebView windowScriptObject] setValue:console forKey:@"console"];
+ [self loadJavascript];
+
+ NSString *searchString = [searchItemView stringValue];
+
+ if (0 != [searchString length])
+ {
+ [self highlightString:searchString];
+ [self findNext:self];
+ }
+ }
+}
+
+# pragma mark Javascript
+- (void)loadJavascript
+{
+ NSString *scriptPath = [[NSBundle mainBundle] pathForResource:@"highlight" ofType:@"js"];
+ [self runJavascript:[NSString stringWithContentsOfFile:scriptPath]];
+}
+
+- (void)runJavascript:(NSString*)script
+{
+ [[curWebView windowScriptObject]
+ evaluateWebScript:[NSString stringWithFormat:@"try{ %@; } catch(e){console.log(e.toString());}", script]];
+}
+# pragma mark WebPolicyDelegate
+- (void)webView:(WebView *)sender decidePolicyForNavigationAction:(NSDictionary *)actionInformation
+ request:(NSURLRequest *)request
+ frame:(WebFrame *)frame decisionListener:(id<WebPolicyDecisionListener>)listener
+{
+ if( [ITSSProtocol canInitWithRequest:request] ) {
+
+ int navigationType = [[actionInformation objectForKey:WebActionNavigationTypeKey] intValue];
+ unsigned int modifier = [[actionInformation objectForKey:WebActionModifierFlagsKey] unsignedIntValue];
+
+ // link click
+ if (navigationType == WebNavigationTypeLinkClicked && modifier) {
+ [self addNewTab:self];
+ [[curWebView mainFrame] loadRequest:request];
+ [listener ignore];
+ return;
+ }
+
+ [listener use];
+ } else {
+ [[NSWorkspace sharedWorkspace] openURL:[request URL]];
+ [listener ignore];
+ }
+}
+
+- (void)webView:(WebView *)sender
+decidePolicyForNewWindowAction:(NSDictionary *)actionInformation
+ request:(NSURLRequest *)request
+ newFrameName:(NSString *)frameName
+ decisionListener:(id<WebPolicyDecisionListener>)listener
+{
+ if( [ITSSProtocol canInitWithRequest:request] ) {
+ [listener use];
+ } else {
+ [[NSWorkspace sharedWorkspace] openURL:[request URL]];
+ [listener ignore];
+ }
+}
+
+# pragma mark WebResourceLoadDelegate
+-(NSURLRequest *)webView:(WebView *)sender resource:(id)identifier
+ willSendRequest:(NSURLRequest *)request redirectResponse:(NSURLResponse *)redirectResponse
+ fromDataSource:(WebDataSource *)dataSource
+{
+ if( [ITSSProtocol canInitWithRequest:request] ) {
+ NSMutableURLRequest *specialURLRequest = [[request mutableCopy] autorelease];
+ [specialURLRequest setChmDoc:self];
+ [specialURLRequest setEncodingName:[self currentEncodingName ]];
+ return specialURLRequest;
+ } else {
+ return request;
+ }
+}
+
+# pragma mark WebUIDelegate
+- (WebView *)webView:(WebView *)sender createWebViewWithRequest:(NSURLRequest *)request
+{
+ WebView* wv = [[[self createWebViewInTab:sender] identifier] webView];
+ [[wv mainFrame] loadRequest:request];
+ return wv;
+}
+
+- (void)webViewShow:(WebView *)sender
+{
+ for(NSTabViewItem* item in [docTabView tabViewItems])
+ {
+ CHMWebView *chmwv = [item identifier];
+ if([chmwv webView] == sender)
+ {
+ curWebView = sender;
+ [docTabView selectTabViewItem:item];
+ }
+ }
+}
+
+# pragma mark actions
+- (IBAction)toggleSidebar:(id)sender
+{
+ float curWidth = [tocView frame].size.width;
+ if(curWidth>30)
+ {
+ [self hideSidebar:sender];
+ }
+ else
+ {
+ float newpos = [splitView frame].size.width - sidebarWidth;
+ [splitView setPosition:newpos ofDividerAtIndex:0];
+ }
+}
+
+- (IBAction)hideSidebar:(id)sender
+{
+ float curWidth = [tocView frame].size.width;
+ if(curWidth > MinSidebarWidth)
+ sidebarWidth = curWidth;
+ [splitView setPosition:[splitView maxPossiblePositionOfDividerAtIndex:0] ofDividerAtIndex:0];
+}
+
+- (IBAction)changeTopic:(id)sender
+{
+ int selectedRow = [tocView selectedRow];
+
+ if( selectedRow >= 0 ) {
+ LinkItem *topic = [tocView itemAtRow:selectedRow];
+ [self loadPath:[topic path]];
+ }
+}
+
+- (IBAction)openInNewTab:(id)sender
+{
+ [self addNewTab:sender];
+ [self changeTopic:sender];
+}
+
+- (IBAction)goForward:(id)sender
+{
+ [curWebView goForward];
+}
+
+- (IBAction)goBack:(id)sender
+{
+ [curWebView goBack];
+}
+
+- (IBAction)goHome:(id)sender
+{
+ [self loadPath:homePath];
+}
+
+- (IBAction)goHistory:(id)sender
+{
+ NSSegmentedCell * segCell = sender;
+ switch ([segCell selectedSegment]) {
+ case 0:
+ [self goBack:sender];
+ break;
+ case 1:
+ [self goForward:sender];
+ break;
+ default:
+ break;
+ }
+}
+
+- (IBAction)locateTOC:(id)sender
+{
+ NSString * path = [[NSURL URLWithString:[curWebView mainFrameURL]] path];
+ NSMutableArray *tocStack = [[NSMutableArray alloc] init];
+ LinkItem* item = [tocSource itemForPath:path withStack:tocStack];
+ NSEnumerator *enumerator = [tocStack reverseObjectEnumerator];
+ for (LinkItem *p in enumerator) {
+ [tocView expandItem:p];
+ }
+ NSInteger idx = [tocView rowForItem:item];
+ NSIndexSet *idxSet = [[NSIndexSet alloc] initWithIndex:idx];
+ [tocView selectRowIndexes:idxSet byExtendingSelection:NO];
+ [tocStack release];
+}
+
+- (IBAction)zoomIn:(id)sender
+{
+ [ curWebView makeTextLarger:sender ];
+ [self after_zoom];
+}
+
+- (IBAction)zoom:(id)sender
+{
+ NSSegmentedCell * segCell = sender;
+ switch ([segCell selectedSegment]) {
+ case 0:
+ [self zoomIn:sender];
+ break;
+ case 1:
+ [self zoomOut:sender];
+ break;
+ default:
+ break;
+ }
+}
+
+- (IBAction)zoomOut:(id)sender
+{
+ [ curWebView makeTextSmaller:sender ];
+ [self after_zoom];
+}
+
+- (void)after_zoom
+{
+ [textSizeItemView setEnabled:[curWebView canMakeTextLarger] forSegment:0];
+ [textSizeItemView setEnabled:[curWebView canMakeTextSmaller] forSegment:1];
+ float zoomFactor = [curWebView textSizeMultiplier];
+ [[NSUserDefaults standardUserDefaults] setFloat:zoomFactor forKey:@"zoom factor"];
+}
+
+
+- (IBAction)printDocument:(id)sender
+{
+ NSView *docView = [[[curWebView mainFrame] frameView] documentView];
+
+ NSPrintOperation *op = [NSPrintOperation printOperationWithView:docView
+ printInfo:[self printInfo]];
+
+ [op setShowPanels:YES];
+
+ [self runModalPrintOperation:op
+ delegate:nil
+ didRunSelector:NULL
+ contextInfo:NULL];
+
+}
+
+- (void)updateHistoryButton
+{
+ [historyItemView setEnabled:[curWebView canGoBack] forSegment:0];
+ [historyItemView setEnabled:[curWebView canGoForward] forSegment:1];
+}
+
+# pragma mark TabVew
+- (void) setupTabBar
+{
+ [tabBar setTabView:docTabView];
+ [tabBar setPartnerView:docTabView];
+ [tabBar setStyleNamed:@"Unified"];
+ [tabBar setDelegate:self];
+ [tabBar setShowAddTabButton:YES];
+ [tabBar setSizeCellsToFit:YES];
+ [[tabBar addTabButton] setTarget:self];
+ [[tabBar addTabButton] setAction:@selector(addNewTab:)];
+}
+
+- (NSTabViewItem*)createWebViewInTab:(id)sender
+{
+ CHMWebView * chmWebView = [[CHMWebView alloc] init];
+
+ // init the webview
+ WebView *newView = [chmWebView webView];
+ [newView setPreferencesIdentifier:WebVewPreferenceIndentifier];
+ if ([webViews count] == 0)
+ {
+ // set preference
+ WebPreferences *pref = [newView preferences];
+ [pref setJavaScriptEnabled:YES];
+ [pref setUserStyleSheetEnabled:YES];
+ [pref setJavaScriptCanOpenWindowsAutomatically:YES];
+ [pref setAutosaves:YES];
+ NSString *stylePath = [[NSBundle mainBundle] pathForResource:@"ichm" ofType:@"css"];
+ NSURL *styleURL = [[NSURL alloc] initFileURLWithPath:stylePath];
+ [pref setUserStyleSheetLocation:styleURL];
+ [styleURL release];
+ }
+ [newView setPolicyDelegate:self];
+ [newView setFrameLoadDelegate:self];
+ [newView setUIDelegate:self];
+ [newView setResourceLoadDelegate:self];
+ if([[NSUserDefaults standardUserDefaults] floatForKey:@"zoom factor"]!=0)
+ {
+ [newView setTextSizeMultiplier:[[NSUserDefaults standardUserDefaults] floatForKey:@"zoom factor"]];
+ }
+
+ // create new tab item
+ NSTabViewItem *newItem = [[[NSTabViewItem alloc] init] autorelease];
+ [newItem setView:[chmWebView view]];
+ [newItem setLabel:@"(Untitled)"];
+ [newItem setIdentifier:chmWebView];
+
+ // add to tab view
+ [docTabView addTabViewItem:newItem];
+ [webViews addObject:newView];
+
+ [chmWebView autorelease];
+ return newItem;
+}
+
+- (IBAction)addNewTab:(id)sender
+{
+ NSTabViewItem *item = [self createWebViewInTab:sender];
+ curWebView = [[item identifier] webView];
+ [docTabView selectTabViewItem:item];
+}
+
+- (IBAction)closeTab:(id)sender
+{
+ if([webViews count] > 1)
+ {
+ NSTabViewItem * item = [docTabView selectedTabViewItem];
+ [item retain];
+ [docTabView removeTabViewItem:item];
+ [[tabBar delegate] tabView:docTabView didCloseTabViewItem:item];
+ [item release];
+ }
+}
+
+- (void)tabView:(NSTabView *)tabView didCloseTabViewItem:(NSTabViewItem *)tabViewItem
+{
+ [webViews removeObject:[[tabViewItem identifier] webView]];
+}
+
+- (void)tabView:(NSTabView *)tabView didSelectTabViewItem:(NSTabViewItem *)tabViewItem
+{
+ curWebView = [[tabViewItem identifier] webView];
+}
+
+- (IBAction)selectNextTabViewItem:(id)sender
+{
+ [docTabView selectNextTabViewItem:sender];
+}
+
+- (IBAction)selectPreviousTabViewItem:(id)sender;
+{
+ [docTabView selectPreviousTabViewItem:sender];
+}
+
+# pragma mark Toolbar
+- (void)setupToolbar
+{
+ NSToolbar *toolbar = [[[NSToolbar alloc] initWithIdentifier: ICHMToolbarIdentifier] autorelease];
+
+ [toolbar setAllowsUserCustomization: YES];
+ [toolbar setAutosavesConfiguration: YES];
+
+ [toolbar setDelegate: self];
+
+ [documentWindow setToolbar: toolbar];
+
+}
+
+- (NSArray *) toolbarDefaultItemIdentifiers: (NSToolbar *) toolbar {
+ return [NSArray arrayWithObjects: HistoryToolbarItemIdentifier, TextSizeToolbarItemIdentifier, NSToolbarSeparatorItemIdentifier, NSToolbarPrintItemIdentifier,
+ NSToolbarSpaceItemIdentifier, NSToolbarFlexibleSpaceItemIdentifier,SidebarToolbarItemIdentifier, SearchToolbarItemIdentifier, nil];
+}
+
+- (NSArray *) toolbarAllowedItemIdentifiers: (NSToolbar *) toolbar {
+ return [NSArray arrayWithObjects: HistoryToolbarItemIdentifier, HomeToolbarItemIdentifier, TextSizeToolbarItemIdentifier, NSToolbarPrintItemIdentifier, NSToolbarSeparatorItemIdentifier,
+ NSToolbarSpaceItemIdentifier, NSToolbarFlexibleSpaceItemIdentifier,SidebarToolbarItemIdentifier, SearchToolbarItemIdentifier, nil];
+}
+
+- (NSToolbarItem *) toolbar: (NSToolbar *)toolbar itemForItemIdentifier: (NSString *) itemIdent willBeInsertedIntoToolbar:(BOOL) willBeInserted {
+ NSToolbarItem *toolbarItem = nil;
+ if ([itemIdent isEqual: TextSizeToolbarItemIdentifier]) {
+ toolbarItem = [[[NSToolbarItem alloc] initWithItemIdentifier: itemIdent] autorelease];
+
+ [toolbarItem setLabel: NSLocalizedString(@"Zoom",@"Zoom")];
+ [toolbarItem setPaletteLabel: NSLocalizedString(@"Zoom",@"Zoom")];
+
+ [toolbarItem setToolTip: NSLocalizedString(@"Zoom",@"Zoom")];
+ [toolbarItem setView: textSizeItemView];
+ [textSizeItemView setEnabled:[curWebView canMakeTextLarger] forSegment:0];
+ [textSizeItemView setEnabled:[curWebView canMakeTextSmaller] forSegment:1];
+ }else if ([itemIdent isEqual: HistoryToolbarItemIdentifier]) {
+ toolbarItem = [[[NSToolbarItem alloc] initWithItemIdentifier: itemIdent] autorelease];
+
+ [toolbarItem setLabel: NSLocalizedString(@"History",@"History")];
+ [toolbarItem setPaletteLabel: NSLocalizedString(@"History",@"History")];
+
+ [toolbarItem setToolTip: NSLocalizedString(@"Navigate in History",@"Navigate in History")];
+ [toolbarItem setView: historyItemView];
+ [historyItemView setEnabled:NO forSegment:0];
+ [historyItemView setEnabled:NO forSegment:1];
+ }else if ([itemIdent isEqual: HomeToolbarItemIdentifier]) {
+ toolbarItem = [[[NSToolbarItem alloc] initWithItemIdentifier: itemIdent] autorelease];
+
+ [toolbarItem setLabel: NSLocalizedString(@"Home",@"Home")];
+ [toolbarItem setPaletteLabel: NSLocalizedString(@"Home",@"Home")];
+
+ [toolbarItem setToolTip: NSLocalizedString(@"Back to Home",@"Back to Home")];
+ [toolbarItem setView: homeItemView];
+ }else if ([itemIdent isEqual: SidebarToolbarItemIdentifier]) {
+ toolbarItem = [[[NSToolbarItem alloc] initWithItemIdentifier: itemIdent] autorelease];
+
+ [toolbarItem setLabel: NSLocalizedString(@"Sidebar",@"Sidebar")];
+ [toolbarItem setPaletteLabel: NSLocalizedString(@"Sidebar",@"Sidebar")];
+
+ [toolbarItem setToolTip: NSLocalizedString(@"Toggle Sidebar",@"Toggle Sidebar")];
+ [toolbarItem setView: sidebarItemView];
+ } else if ([itemIdent isEqual:SearchToolbarItemIdentifier]) {
+ toolbarItem = [[[NSToolbarItem alloc] initWithItemIdentifier: itemIdent] autorelease];
+
+ [toolbarItem setLabel: NSLocalizedString(@"Search",@"Search")];
+ [toolbarItem setPaletteLabel: NSLocalizedString(@"Search",@"Search")];
+
+ [toolbarItem setToolTip: NSLocalizedString(@"Search",@"Search")];
+ [toolbarItem setView: searchItemView];
+
+ } else {
+ // itemIdent refered to a toolbar item that is not provide or supported by us or cocoa
+ // Returning nil will inform the toolbar this kind of item is not supported
+ toolbarItem = nil;
+ }
+ return toolbarItem;
+}
+
+# pragma mark Search
+- (void)prepareSearchIndex
+{
+ [searchIndexObject release];
+ searchIndexObject = [[NSMutableData dataWithCapacity: 2^22] retain];
+ if(!skIndex)
+ SKIndexClose(skIndex);
+
+ skIndex = SKIndexCreateWithMutableData((CFMutableDataRef) searchIndexObject,
+ NULL,
+ kSKIndexInverted ,
+ (CFDictionaryRef) NULL
+ );
+ [NSThread detachNewThreadSelector:@selector(buildSearchIndex) toTarget:self withObject:nil];
+}
+
+static int forEachFile(struct chmFile *h,
+ struct chmUnitInfo *ui,
+ void *context)
+{
+ if (ui->path[0] != '/' || strstr(ui->path, "/../") != NULL || ui->path[strlen(ui->path)-1] == '/')
+ return CHM_ENUMERATOR_CONTINUE;
+
+ CHMDocument* doc = (CHMDocument*)context;
+ [doc addToSearchIndex:ui->path];
+ return CHM_ENUMERATOR_CONTINUE;
+}
+
+- (void)buildSearchIndex
+{
+ [NSThread sleepForTimeInterval:1];
+
+ NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];
+ chm_enumerate(chmFileHandle, CHM_ENUMERATE_FILES||CHM_ENUMERATE_NORMAL, forEachFile, (void*)self);
+ [pool release];
+}
+
+- (void)addToSearchIndex:(const char*)path
+{
+ NSString *filepath = [NSString stringWithCString:path encoding:nameToEncoding(encodingName)];
+ if([filepath hasPrefix:@"/"])
+ filepath = [filepath substringFromIndex:1];
+
+ NSData *data = [self content:filepath];
+ NSURL *url = [NSURL URLWithString:[NSString stringWithFormat:@"itss://chm/%@", filepath]];
+
+ if(!url)
+ return;
+
+ SKDocumentRef doc = SKDocumentCreateWithURL ((CFURLRef) url);
+ [(id) doc autorelease];
+
+ NSString *contents = [[NSString alloc] initWithData:data encoding:nameToEncoding(encodingName)];
+ SKIndexAddDocumentWithText (skIndex,doc,(CFStringRef) contents,(Boolean) true);
+}
+
+- (IBAction)searchInFile:(id)sender
+{
+ NSString *searchString = [searchItemView stringValue];
+
+ if (0 == [searchString length])
+ {
+ [tocView setDataSource:tocSource];
+ [searchSource release];
+ [self removeHighlight];
+ searchSource = nil;
+ [self locateTOC:sender];
+ return;
+ }
+
+ if (searchSource)
+ [searchSource release];
+
+ searchSource = [[CHMSearchResult alloc] initwithTOC:tocSource];
+
+ SKSearchOptions options = kSKSearchOptionDefault;
+ SKIndexFlush(skIndex);
+ SKSearchRef search = SKSearchCreate (skIndex,
+ (CFStringRef) searchString,
+ options);
+ [(id) search autorelease];
+
+ Boolean more = true;
+ UInt32 totalCount = 0;
+ UInt32 kSearchMax = 10;
+
+ while (more) {
+ SKDocumentID foundDocIDs [kSearchMax];
+ float foundScores [kSearchMax];
+ SKDocumentRef foundDocRefs [kSearchMax];
+
+ float * scores;
+
+ scores = foundScores;
+
+ CFIndex foundCount = 0;
+ CFIndex pos;
+
+ more = SKSearchFindMatches (search,
+ kSearchMax,
+ foundDocIDs,
+ scores,
+ 1, // maximum time before func returns, in seconds
+ &foundCount
+ );
+
+ totalCount += foundCount;
+
+ //..........................................................................
+ // get document locations for matches and display results.
+ // alternatively, you can collect results over iterations of this loop
+ // for display later.
+
+ SKIndexCopyDocumentRefsForDocumentIDs (
+ (SKIndexRef) skIndex,
+ (CFIndex) foundCount,
+ (SKDocumentID *) foundDocIDs,
+ (SKDocumentRef *) foundDocRefs
+ );
+
+ for (pos = 0; pos < foundCount; pos++) {
+ SKDocumentRef doc = (SKDocumentRef) [(id) foundDocRefs [pos] autorelease];
+ NSURL * url = [(id) SKDocumentCopyURL (doc) autorelease];
+
+ [searchSource addPath:[url path] Score:foundScores[pos]];
+ }
+ }
+ [searchSource sort];
+ [tocView setDataSource:searchSource];
+ [tocView reloadData];
+}
+# pragma mark find panel
+- (IBAction)showFindPanel:(id)sender
+{
+ CHMWebView * chmWebView = (CHMWebView*)[[docTabView selectedTabViewItem] identifier];
+ return [chmWebView showFindPanel:sender];
+}
+
+- (IBAction)beginFind:(id)sender
+{
+ NSString *searchString = [[[[docTabView selectedTabViewItem] identifier] searchField] stringValue];
+ if (0 == [searchString length])
+ {
+ [self removeHighlight];
+ return;
+ }
+
+ [self highlightString:searchString];
+ [self findNext:sender];
+}
+
+- (void)highlightString:(NSString*)pattern
+{
+ [self runJavascript:[NSString stringWithFormat:@"highlight(document.body, '%@')", pattern]];
+}
+
+- (void)removeHighlight
+{
+