diff options
Diffstat (limited to 'tikzit')
313 files changed, 0 insertions, 40962 deletions
diff --git a/tikzit/.gitignore b/tikzit/.gitignore deleted file mode 100644 index 644b16b..0000000 --- a/tikzit/.gitignore +++ /dev/null @@ -1,29 +0,0 @@ -*~ -*.swp -*.o -.deps -.dirstamp -Makefile -Makefile.in -/aclocal.m4 -/autom4te.cache -/config.guess -/config.log -/config.status -/config.sub -/configure -/depcomp -/install-sh -/missing -/src/tikzit -/src/tikzit.res -/src/common/tikzlexer.h -/src/common/tikzlexer.m -/src/common/tikzparser.m -/src/common/tikzparser.h -/src/gtk/icondata.m -/src/gtk/logodata.m -/src/gtk/edgedecdata.m -/tikzit-*.tar.gz -/tikzit-*.tar.bz2 -xbuild diff --git a/tikzit/AH_latex_head.png b/tikzit/AH_latex_head.png Binary files differdeleted file mode 100644 index b25cf6d..0000000 --- a/tikzit/AH_latex_head.png +++ /dev/null diff --git a/tikzit/AH_latex_tail.png b/tikzit/AH_latex_tail.png Binary files differdeleted file mode 100644 index 0825cda..0000000 --- a/tikzit/AH_latex_tail.png +++ /dev/null diff --git a/tikzit/AH_none.png b/tikzit/AH_none.png Binary files differdeleted file mode 100644 index 6322374..0000000 --- a/tikzit/AH_none.png +++ /dev/null diff --git a/tikzit/AH_plain_head.png b/tikzit/AH_plain_head.png Binary files differdeleted file mode 100644 index 8a398fa..0000000 --- a/tikzit/AH_plain_head.png +++ /dev/null diff --git a/tikzit/AH_plain_tail.png b/tikzit/AH_plain_tail.png Binary files differdeleted file mode 100644 index 45b1876..0000000 --- a/tikzit/AH_plain_tail.png +++ /dev/null diff --git a/tikzit/COPYING b/tikzit/COPYING deleted file mode 100644 index 1f963da..0000000 --- a/tikzit/COPYING +++ /dev/null @@ -1,340 +0,0 @@ - GNU GENERAL PUBLIC LICENSE - Version 2, June 1991 - - Copyright (C) 1989, 1991 Free Software Foundation, Inc., - 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA - Everyone is permitted to copy and distribute verbatim copies - of this license document, but changing it is not allowed. - - Preamble - - The licenses for most software are designed to take away your -freedom to share and change it. By contrast, the GNU General Public -License is intended to guarantee your freedom to share and change free -software--to make sure the software is free for all its users. This -General Public License applies to most of the Free Software -Foundation's software and to any other program whose authors commit to -using it. (Some other Free Software Foundation software is covered by -the GNU Lesser General Public License instead.) You can apply it to -your programs, too. - - When we speak of free software, we are referring to freedom, not -price. Our General Public Licenses are designed to make sure that you -have the freedom to distribute copies of free software (and charge for -this service if you wish), that you receive source code or can get it -if you want it, that you can change the software or use pieces of it -in new free programs; and that you know you can do these things. - - To protect your rights, we need to make restrictions that forbid -anyone to deny you these rights or to ask you to surrender the rights. -These restrictions translate to certain responsibilities for you if you -distribute copies of the software, or if you modify it. - - For example, if you distribute copies of such a program, whether -gratis or for a fee, you must give the recipients all the rights that -you have. You must make sure that they, too, receive or can get the -source code. And you must show them these terms so they know their -rights. - - We protect your rights with two steps: (1) copyright the software, and -(2) offer you this license which gives you legal permission to copy, -distribute and/or modify the software. - - Also, for each author's protection and ours, we want to make certain -that everyone understands that there is no warranty for this free -software. If the software is modified by someone else and passed on, we -want its recipients to know that what they have is not the original, so -that any problems introduced by others will not reflect on the original -authors' reputations. - - Finally, any free program is threatened constantly by software -patents. We wish to avoid the danger that redistributors of a free -program will individually obtain patent licenses, in effect making the -program proprietary. To prevent this, we have made it clear that any -patent must be licensed for everyone's free use or not licensed at all. - - The precise terms and conditions for copying, distribution and -modification follow. - - GNU GENERAL PUBLIC LICENSE - TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION - - 0. This License applies to any program or other work which contains -a notice placed by the copyright holder saying it may be distributed -under the terms of this General Public License. The "Program", below, -refers to any such program or work, and a "work based on the Program" -means either the Program or any derivative work under copyright law: -that is to say, a work containing the Program or a portion of it, -either verbatim or with modifications and/or translated into another -language. (Hereinafter, translation is included without limitation in -the term "modification".) Each licensee is addressed as "you". - -Activities other than copying, distribution and modification are not -covered by this License; they are outside its scope. The act of -running the Program is not restricted, and the output from the Program -is covered only if its contents constitute a work based on the -Program (independent of having been made by running the Program). -Whether that is true depends on what the Program does. - - 1. You may copy and distribute verbatim copies of the Program's -source code as you receive it, in any medium, provided that you -conspicuously and appropriately publish on each copy an appropriate -copyright notice and disclaimer of warranty; keep intact all the -notices that refer to this License and to the absence of any warranty; -and give any other recipients of the Program a copy of this License -along with the Program. - -You may charge a fee for the physical act of transferring a copy, and -you may at your option offer warranty protection in exchange for a fee. - - 2. You may modify your copy or copies of the Program or any portion -of it, thus forming a work based on the Program, and copy and -distribute such modifications or work under the terms of Section 1 -above, provided that you also meet all of these conditions: - - a) You must cause the modified files to carry prominent notices - stating that you changed the files and the date of any change. - - b) You must cause any work that you distribute or publish, that in - whole or in part contains or is derived from the Program or any - part thereof, to be licensed as a whole at no charge to all third - parties under the terms of this License. - - c) If the modified program normally reads commands interactively - when run, you must cause it, when started running for such - interactive use in the most ordinary way, to print or display an - announcement including an appropriate copyright notice and a - notice that there is no warranty (or else, saying that you provide - a warranty) and that users may redistribute the program under - these conditions, and telling the user how to view a copy of this - License. (Exception: if the Program itself is interactive but - does not normally print such an announcement, your work based on - the Program is not required to print an announcement.) - -These requirements apply to the modified work as a whole. If -identifiable sections of that work are not derived from the Program, -and can be reasonably considered independent and separate works in -themselves, then this License, and its terms, do not apply to those -sections when you distribute them as separate works. But when you -distribute the same sections as part of a whole which is a work based -on the Program, the distribution of the whole must be on the terms of -this License, whose permissions for other licensees extend to the -entire whole, and thus to each and every part regardless of who wrote it. - -Thus, it is not the intent of this section to claim rights or contest -your rights to work written entirely by you; rather, the intent is to -exercise the right to control the distribution of derivative or -collective works based on the Program. - -In addition, mere aggregation of another work not based on the Program -with the Program (or with a work based on the Program) on a volume of -a storage or distribution medium does not bring the other work under -the scope of this License. - - 3. You may copy and distribute the Program (or a work based on it, -under Section 2) in object code or executable form under the terms of -Sections 1 and 2 above provided that you also do one of the following: - - a) Accompany it with the complete corresponding machine-readable - source code, which must be distributed under the terms of Sections - 1 and 2 above on a medium customarily used for software interchange; or, - - b) Accompany it with a written offer, valid for at least three - years, to give any third party, for a charge no more than your - cost of physically performing source distribution, a complete - machine-readable copy of the corresponding source code, to be - distributed under the terms of Sections 1 and 2 above on a medium - customarily used for software interchange; or, - - c) Accompany it with the information you received as to the offer - to distribute corresponding source code. (This alternative is - allowed only for noncommercial distribution and only if you - received the program in object code or executable form with such - an offer, in accord with Subsection b above.) - -The source code for a work means the preferred form of the work for -making modifications to it. For an executable work, complete source -code means all the source code for all modules it contains, plus any -associated interface definition files, plus the scripts used to -control compilation and installation of the executable. However, as a -special exception, the source code distributed need not include -anything that is normally distributed (in either source or binary -form) with the major components (compiler, kernel, and so on) of the -operating system on which the executable runs, unless that component -itself accompanies the executable. - -If distribution of executable or object code is made by offering -access to copy from a designated place, then offering equivalent -access to copy the source code from the same place counts as -distribution of the source code, even though third parties are not -compelled to copy the source along with the object code. - - 4. You may not copy, modify, sublicense, or distribute the Program -except as expressly provided under this License. Any attempt -otherwise to copy, modify, sublicense or distribute the Program is -void, and will automatically terminate your rights under this License. -However, parties who have received copies, or rights, from you under -this License will not have their licenses terminated so long as such -parties remain in full compliance. - - 5. You are not required to accept this License, since you have not -signed it. However, nothing else grants you permission to modify or -distribute the Program or its derivative works. These actions are -prohibited by law if you do not accept this License. Therefore, by -modifying or distributing the Program (or any work based on the -Program), you indicate your acceptance of this License to do so, and -all its terms and conditions for copying, distributing or modifying -the Program or works based on it. - - 6. Each time you redistribute the Program (or any work based on the -Program), the recipient automatically receives a license from the -original licensor to copy, distribute or modify the Program subject to -these terms and conditions. You may not impose any further -restrictions on the recipients' exercise of the rights granted herein. -You are not responsible for enforcing compliance by third parties to -this License. - - 7. If, as a consequence of a court judgment or allegation of patent -infringement or for any other reason (not limited to patent issues), -conditions are imposed on you (whether by court order, agreement or -otherwise) that contradict the conditions of this License, they do not -excuse you from the conditions of this License. If you cannot -distribute so as to satisfy simultaneously your obligations under this -License and any other pertinent obligations, then as a consequence you -may not distribute the Program at all. For example, if a patent -license would not permit royalty-free redistribution of the Program by -all those who receive copies directly or indirectly through you, then -the only way you could satisfy both it and this License would be to -refrain entirely from distribution of the Program. - -If any portion of this section is held invalid or unenforceable under -any particular circumstance, the balance of the section is intended to -apply and the section as a whole is intended to apply in other -circumstances. - -It is not the purpose of this section to induce you to infringe any -patents or other property right claims or to contest validity of any -such claims; this section has the sole purpose of protecting the -integrity of the free software distribution system, which is -implemented by public license practices. Many people have made -generous contributions to the wide range of software distributed -through that system in reliance on consistent application of that -system; it is up to the author/donor to decide if he or she is willing -to distribute software through any other system and a licensee cannot -impose that choice. - -This section is intended to make thoroughly clear what is believed to -be a consequence of the rest of this License. - - 8. If the distribution and/or use of the Program is restricted in -certain countries either by patents or by copyrighted interfaces, the -original copyright holder who places the Program under this License -may add an explicit geographical distribution limitation excluding -those countries, so that distribution is permitted only in or among -countries not thus excluded. In such case, this License incorporates -the limitation as if written in the body of this License. - - 9. The Free Software Foundation may publish revised and/or new versions -of the General Public License from time to time. Such new versions will -be similar in spirit to the present version, but may differ in detail to -address new problems or concerns. - -Each version is given a distinguishing version number. If the Program -specifies a version number of this License which applies to it and "any -later version", you have the option of following the terms and conditions -either of that version or of any later version published by the Free -Software Foundation. If the Program does not specify a version number of -this License, you may choose any version ever published by the Free Software -Foundation. - - 10. If you wish to incorporate parts of the Program into other free -programs whose distribution conditions are different, write to the author -to ask for permission. For software which is copyrighted by the Free -Software Foundation, write to the Free Software Foundation; we sometimes -make exceptions for this. Our decision will be guided by the two goals -of preserving the free status of all derivatives of our free software and -of promoting the sharing and reuse of software generally. - - NO WARRANTY - - 11. BECAUSE THE PROGRAM IS LICENSED FREE OF CHARGE, THERE IS NO WARRANTY -FOR THE PROGRAM, TO THE EXTENT PERMITTED BY APPLICABLE LAW. EXCEPT WHEN -OTHERWISE STATED IN WRITING THE COPYRIGHT HOLDERS AND/OR OTHER PARTIES -PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED -OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF -MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. THE ENTIRE RISK AS -TO THE QUALITY AND PERFORMANCE OF THE PROGRAM IS WITH YOU. SHOULD THE -PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF ALL NECESSARY SERVICING, -REPAIR OR CORRECTION. - - 12. IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING -WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MAY MODIFY AND/OR -REDISTRIBUTE THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES, -INCLUDING ANY GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING -OUT OF THE USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED -TO LOSS OF DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY -YOU OR THIRD PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER -PROGRAMS), EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE -POSSIBILITY OF SUCH DAMAGES. - - END OF TERMS AND CONDITIONS - - How to Apply These Terms to Your New Programs - - If you develop a new program, and you want it to be of the greatest -possible use to the public, the best way to achieve this is to make it -free software which everyone can redistribute and change under these terms. - - To do so, attach the following notices to the program. It is safest -to attach them to the start of each source file to most effectively -convey the exclusion of warranty; and each file should have at least -the "copyright" line and a pointer to where the full notice is found. - - <one line to give the program's name and a brief idea of what it does.> - Copyright (C) <year> <name of author> - - 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 - the Free Software Foundation; either version 2 of the License, or - (at your option) any later version. - - This program is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU General Public License for more details. - - You should have received a copy of the GNU General Public License along - with this program; if not, write to the Free Software Foundation, Inc., - 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. - -Also add information on how to contact you by electronic and paper mail. - -If the program is interactive, make it output a short notice like this -when it starts in an interactive mode: - - Gnomovision version 69, Copyright (C) year name of author - Gnomovision comes with ABSOLUTELY NO WARRANTY; for details type `show w'. - This is free software, and you are welcome to redistribute it - under certain conditions; type `show c' for details. - -The hypothetical commands `show w' and `show c' should show the appropriate -parts of the General Public License. Of course, the commands you use may -be called something other than `show w' and `show c'; they could even be -mouse-clicks or menu items--whatever suits your program. - -You should also get your employer (if you work as a programmer) or your -school, if any, to sign a "copyright disclaimer" for the program, if -necessary. Here is a sample; alter the names: - - Yoyodyne, Inc., hereby disclaims all copyright interest in the program - `Gnomovision' (which makes passes at compilers) written by James Hacker. - - <signature of Ty Coon>, 1 April 1989 - Ty Coon, President of Vice - -This General Public License does not permit incorporating your program into -proprietary programs. If your program is a subroutine library, you may -consider it more useful to permit linking proprietary applications with the -library. If this is what you want to do, use the GNU Lesser General -Public License instead of this License. - diff --git a/tikzit/DESIGN-GTK b/tikzit/DESIGN-GTK deleted file mode 100644 index 7952a34..0000000 --- a/tikzit/DESIGN-GTK +++ /dev/null @@ -1,23 +0,0 @@ -Some documentation on how the GTK+ port is designed. - -State classes: - -StyleManager keeps track of what user-defined styles the application -knows about, and which one is currently "active". The active style -is used when creating new nodes. - -Preambles keeps track of the preambles used for previews. - - -GUI classes: - -MainWindow is the core class that manages the application as a whole. -It manages the main GtkWindow and is generally responsible for loading -the various UI elements. It also keeps track of the main application -configuration file, the user-defined styles (via StyleManager) and the -custom preambles (via Preambles). - -The Menu class manages the menu and toolbar for MainWindow. It uses -GtkUiManager to load these from an XML description, and deals with the -GTK+ callbacks for the various actions. - diff --git a/tikzit/ED_arrow.png b/tikzit/ED_arrow.png Binary files differdeleted file mode 100644 index 153d2e1..0000000 --- a/tikzit/ED_arrow.png +++ /dev/null diff --git a/tikzit/ED_none.png b/tikzit/ED_none.png Binary files differdeleted file mode 100644 index f95140c..0000000 --- a/tikzit/ED_none.png +++ /dev/null diff --git a/tikzit/ED_tick.png b/tikzit/ED_tick.png Binary files differdeleted file mode 100644 index a3882fe..0000000 --- a/tikzit/ED_tick.png +++ /dev/null diff --git a/tikzit/INSTALL b/tikzit/INSTALL deleted file mode 100644 index 695982d..0000000 --- a/tikzit/INSTALL +++ /dev/null @@ -1,30 +0,0 @@ -For building on systems other than MacOS/X: - -Dependencies: - GNUstep (core libraries) >= 1.18.0 - gtk+-2.0 >= 2.18.0 - poppler (including glib bindings, which may be in - a separate poppler-glib package) - Objective C compiler (eg: gcc with ObjC support) with - support for properties, optional protocols and - fast enumeration (eg: gcc 4.6 or clang). - -To install, just run: - - ./configure - make - make install - - - -To build from subversion (and for development) you will additionally need: - lex (eg: flex) - yacc (eg: bison) - autoconf >= 2.60 - automake - -and you will need to prepare the source tree by running - ./autogen.sh - - - diff --git a/tikzit/Makefile.am b/tikzit/Makefile.am deleted file mode 100644 index d9793a4..0000000 --- a/tikzit/Makefile.am +++ /dev/null @@ -1,3 +0,0 @@ -SUBDIRS = src share -appdir = $(datarootdir)/tikzit -nobase_dist_app_DATA = shapes/*.tikz diff --git a/tikzit/NEWS b/tikzit/NEWS deleted file mode 100644 index 0efc18f..0000000 --- a/tikzit/NEWS +++ /dev/null @@ -1,68 +0,0 @@ -tikzit 1.0 (2013-05-07): - * GIMP-like user interface (multiple documents, separate toolboxes) - * Preferences now called Configuration, and includes node and edge styles - * Error-highlighting in the code pane - * Single-key-shortcuts for tool selection, and <space> to update the preview - * Edge anchor support - * Option for drag-select to select nodes, edges or both - * Memory leak fixes - * Should now be impossible to use the UI to create a graph that cannot be parsed - -tikzit 0.9 (2012-08-24): - * Compilers without basic Objective C 2 support cannot be - used to compile TikZiT any more - * Add support for scale to node styles - * Add support for editing edge styles - * Add support for multiple custom preambles - * The path to pdflatex is now configurable - * Make everything look a bit better - * Edges now start from the edge of a node, not the centre, - which is what tikz does - * Edges can now have arrow heads and arrow tails - * Nodes and edges have consistent ordering, and this can be - changed with Edge->Arrange - * Edges now have colours - * Edges can now be reversed easily - * Fix various crashes - -tikzit 0.7 (2011-12-06): - * Add bounding box support - * Add support for different node shapes - * Improved error reporting - * Add scrolling support (CTRL+mouse wheel) - * Add a pan tool to move around the graph - * Add edge and graph property palettes - -tikzit 0.6 (2011-02-08): - * Fix the displaying of colours in the styles editor - * Cut, copy and paste support - * More useful buttons on the toolbar - * Improve how previewing works - * Allow custom preambles for preview generation - -tikzit 0.5 (2010-12-01): - * Hide font size commands (\small etc) in node labels - * Always output the "style" node property first - * Provide a list of recent files - * Remember the folder for Open and Save As dialogs - * Remember window dimensions - * Remember the styles list - * Add a "Node properties" pane - * Bring the separate windows into the main application window - * Improve graphics rendering / remove flicker - * Shorten the window title to something useful - -tikzit 0.4 (2010-09-19): - * Support for bounding boxes, variable-precision tikz output - * Fixed stroke width display - * Updated tikz output to handle separate edge/node layers - * Using [Graph tikz] for tikz output, attaching style after parse - * All platforms now use the same lex-based parser - * Added a menu item for showing node styles if closed - * Pre-amble support - * Added test suite - * Added preview and node labels to GTK version - -tikzit 0.3b (2010-05-11): - * Various build-system fixes on Linux - diff --git a/tikzit/README b/tikzit/README deleted file mode 100644 index e5d3c64..0000000 --- a/tikzit/README +++ /dev/null @@ -1,8 +0,0 @@ -TikZit is a cross-platform application that allows the creation and modification of TeX diagrams written using the pgf/TikZ macro library. It is especially geared toward rapidly creating "dot"-diagrams for use in academic papers. - -For more info, see http://tikzit.sf.net - -On OS/X, the Cocoa framework is used. - -On other platforms, GTK+ and GNUstep are used. - diff --git a/tikzit/README.release b/tikzit/README.release deleted file mode 100644 index a6f1642..0000000 --- a/tikzit/README.release +++ /dev/null @@ -1,98 +0,0 @@ -Notes on how to make a release -============================== - -Updating doc files ------------------- - -Put all the user-visible changes since the last release into NEWS. - -Make sure the dependency requirements in INSTALL are correct. - - - -Making the source tarballs --------------------------- - -The version should be set in configure.ac (in AC_INIT) -and the package should be re-configured -(run ./configure). - -Then run `make dist` to create the source tarball in tar.gz format, and -`make dist-bzip2` to get it in tar.bz2 format. - - - -Uploading the source --------------------- - -Update /www/sourceforge/README.mkd - -Log into sourceforge.net, go to -https://sourceforge.net/projects/tikzit/files/ - -Create a folder called tikzit-[version]. - -Upload README.mkd. - -Upload the tar.bz2 and tar.gz files. - -Set the tar.bz2 file as default for everything except windows and mac -(click the (i) symbol on the right for that file to do this). - - - -Updating the website --------------------- - -Edit /www/htdocs/link.php, and update the versions. - -sftp to - [sf-username],tikzit@web.sourceforge.net - -Upload link.php into htdocs. - - - -Updating the packages ---------------------- - -Contact Gard Spreemann about the new version by sending him a message -on Launchpad (https://launchpad.net/~gspreemann). - -Update tikzit.spec (the version, the changelog and the dependencies). - -Test the spec file: -- if you don't have ~/rpmbuild, run rpmdev-setuptree -- copy the tar.bz2 file into ~/rpmbuild/SOURCES -- copy tikzit.spec into ~/rpmbuild/SPECS -- cd into ~/rpmbuild/SPECS -- run `rpmbuild -ba tikzit.spec` -- run `rpmlint ..` and check the warnings (there will be some that are - not important) - -Update the OBS packages: -- https://build.opensuse.org/package/show?package=tikzit&project=home%3Arandomguy3 -- Upload the tar.bz2 file and the tikzit.spec file. -- Wait for the build to finish - -Update the AUR package: -- http://aur.archlinux.org/packages.php?ID=37119 - - -TODO: find out how the Debian build system works - - -Publishing an OSX Update ------------------------------------------ -In OSX, the steps to publish an update are as follows. Firstly all updates are signed, so you need the private key 'tikzit_dsa_priv.pem' in the root of your working directory. This is not in the repository (for obvious reasons), so ask Aleks for a copy. Also, make sure you have ruby in your $PATH to do the actual signing. - -1. Update the SVN and note the revision number -2. In TikZiT-Info.plist, set the Bundle Version key to (MAJOR).(MINOR).(SVN REVISION + 1) -3. In the TikZiT working directory, run scripts/prepare_release.sh -4. Copy and paste the XML output into docs/web/appcast/tikzit.xml -5. Update the release notes in docs/web/appcast/rnotes.html -6. Use SFTP to upload the changed files into htdocs/appcast -7. Commit the SVN - - - diff --git a/tikzit/TODO b/tikzit/TODO deleted file mode 100644 index ca1a1b9..0000000 --- a/tikzit/TODO +++ /dev/null @@ -1,15 +0,0 @@ -GTK port: - - Use GooCanvas for the graph display - - -OSX port: - - node properties toolbox - - support for more than one custom preamble - - -General: - - push more code up into common (make use of RenderContext) - - vi-like mode lines in tikz files - - use mode lines for preamble knowledge - - per-document preamble selection? - diff --git a/tikzit/TikZiT-Info.plist b/tikzit/TikZiT-Info.plist deleted file mode 100644 index a495c5b..0000000 --- a/tikzit/TikZiT-Info.plist +++ /dev/null @@ -1,61 +0,0 @@ -<?xml version="1.0" encoding="UTF-8"?> -<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd"> -<plist version="1.0"> -<dict> - <key>CFBundleDevelopmentRegion</key> - <string>English</string> - <key>CFBundleDocumentTypes</key> - <array> - <dict> - <key>CFBundleTypeExtensions</key> - <array> - <string>tikz</string> - </array> - <key>CFBundleTypeIconFile</key> - <string>tikzitdoc.icns</string> - <key>CFBundleTypeMIMETypes</key> - <array> - <string>text/plain</string> - </array> - <key>CFBundleTypeName</key> - <string>DocumentType</string> - <key>CFBundleTypeOSTypes</key> - <array> - <string>????</string> - </array> - <key>CFBundleTypeRole</key> - <string>Editor</string> - <key>NSDocumentClass</key> - <string>TikzDocument</string> - </dict> - </array> - <key>CFBundleExecutable</key> - <string>${EXECUTABLE_NAME}</string> - <key>CFBundleIconFile</key> - <string>tikzit.icns</string> - <key>CFBundleIdentifier</key> - <string>net.sourceforge.tikzit.${PRODUCT_NAME:rfc1034identifier}</string> - <key>CFBundleInfoDictionaryVersion</key> - <string>6.0</string> - <key>CFBundleName</key> - <string>${PRODUCT_NAME}</string> - <key>CFBundlePackageType</key> - <string>APPL</string> - <key>CFBundleShortVersionString</key> - <string>0.8</string> - <key>CFBundleSignature</key> - <string>????</string> - <key>CFBundleVersion</key> - <string>0.8.398</string> - <key>LSMinimumSystemVersion</key> - <string>${MACOSX_DEPLOYMENT_TARGET}</string> - <key>NSMainNibFile</key> - <string>MainMenu</string> - <key>NSPrincipalClass</key> - <string>NSApplication</string> - <key>SUFeedURL</key> - <string>http://tikzit.sourceforge.net/appcast/tikzit.xml</string> - <key>SUPublicDSAKeyFile</key> - <string>tikzit_dsa_pub.pem</string> -</dict> -</plist> diff --git a/tikzit/TikZiT_Prefix.pch b/tikzit/TikZiT_Prefix.pch deleted file mode 100644 index 78e4d0f..0000000 --- a/tikzit/TikZiT_Prefix.pch +++ /dev/null @@ -1,30 +0,0 @@ -// -// TikZiT_Prefix.pch -// TikZiT -// -// Copyright 2010 Aleks Kissinger. All rights reserved. -// -// -// This file is part of TikZiT. -// -// TikZiT is free software: you can redistribute it and/or modify -// it under the terms of the GNU General Public License as published by -// the Free Software Foundation, either version 3 of the License, or -// (at your option) any later version. -// -// TikZiT is distributed in the hope that it will be useful, -// but WITHOUT ANY WARRANTY; without even the implied warranty of -// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -// GNU General Public License for more details. -// -// You should have received a copy of the GNU General Public License -// along with TikZiT. If not, see <http://www.gnu.org/licenses/>. -// - -// -// Prefix header for all source files of the 'TikZiT' target in the 'TikZiT' project -// - -#ifdef __OBJC__ - #import <Cocoa/Cocoa.h> -#endif diff --git a/tikzit/autogen.sh b/tikzit/autogen.sh deleted file mode 100755 index 132ecd0..0000000 --- a/tikzit/autogen.sh +++ /dev/null @@ -1,1578 +0,0 @@ -#!/bin/sh -# a u t o g e n . s h -# -# Copyright (c) 2005-2009 United States Government as represented by -# the U.S. Army Research Laboratory. -# -# 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. -# -# 3. The name of the author may not be used to endorse or promote -# products derived from this software without specific prior written -# permission. -# -# THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``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 THE AUTHOR 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. -# -### -# -# Script for automatically preparing the sources for compilation by -# performing the myriad of necessary steps. The script attempts to -# detect proper version support, and outputs warnings about particular -# systems that have autotool peculiarities. -# -# Basically, if everything is set up and installed correctly, the -# script will validate that minimum versions of the GNU Build System -# tools are installed, account for several common configuration -# issues, and then simply run autoreconf for you. -# -# If autoreconf fails, which can happen for many valid configurations, -# this script proceeds to run manual preparation steps effectively -# providing a POSIX shell script (mostly complete) reimplementation of -# autoreconf. -# -# The AUTORECONF, AUTOCONF, AUTOMAKE, LIBTOOLIZE, ACLOCAL, AUTOHEADER -# environment variables and corresponding _OPTIONS variables (e.g. -# AUTORECONF_OPTIONS) may be used to override the default automatic -# detection behaviors. Similarly the _VERSION variables will override -# the minimum required version numbers. -# -# Examples: -# -# To obtain help on usage: -# ./autogen.sh --help -# -# To obtain verbose output: -# ./autogen.sh --verbose -# -# To skip autoreconf and prepare manually: -# AUTORECONF=false ./autogen.sh -# -# To verbosely try running with an older (unsupported) autoconf: -# AUTOCONF_VERSION=2.50 ./autogen.sh --verbose -# -# Author: -# Christopher Sean Morrison <morrison@brlcad.org> -# -# Patches: -# Sebastian Pipping <sebastian@pipping.org> -# -###################################################################### - -# set to minimum acceptable version of autoconf -if [ "x$AUTOCONF_VERSION" = "x" ] ; then - AUTOCONF_VERSION=2.60 -fi -# set to minimum acceptable version of automake -if [ "x$AUTOMAKE_VERSION" = "x" ] ; then - AUTOMAKE_VERSION=1.6.0 -fi -# set to minimum acceptable version of libtool -if [ "x$LIBTOOL_VERSION" = "x" ] ; then - LIBTOOL_VERSION=1.4.2 -fi - - -################## -# ident function # -################## -ident ( ) { - # extract copyright from header - __copyright="`grep Copyright $AUTOGEN_SH | head -${HEAD_N}1 | awk '{print $4}'`" - if [ "x$__copyright" = "x" ] ; then - __copyright="`date +%Y`" - fi - - # extract version from CVS Id string - __id="$Id: autogen.sh 33925 2009-03-01 23:27:06Z brlcad $" - __version="`echo $__id | sed 's/.*\([0-9][0-9][0-9][0-9]\)[-\/]\([0-9][0-9]\)[-\/]\([0-9][0-9]\).*/\1\2\3/'`" - if [ "x$__version" = "x" ] ; then - __version="" - fi - - echo "autogen.sh build preparation script by Christopher Sean Morrison" - echo " + config.guess download patch by Sebastian Pipping (2008-12-03)" - echo "revised 3-clause BSD-style license, copyright (c) $__copyright" - echo "script version $__version, ISO/IEC 9945 POSIX shell script" -} - - -################## -# USAGE FUNCTION # -################## -usage ( ) { - echo "Usage: $AUTOGEN_SH [-h|--help] [-v|--verbose] [-q|--quiet] [-d|--download] [--version]" - echo " --help Help on $NAME_OF_AUTOGEN usage" - echo " --verbose Verbose progress output" - echo " --quiet Quiet suppressed progress output" - echo " --download Download the latest config.guess from gnulib" - echo " --version Only perform GNU Build System version checks" - echo - echo "Description: This script will validate that minimum versions of the" - echo "GNU Build System tools are installed and then run autoreconf for you." - echo "Should autoreconf fail, manual preparation steps will be run" - echo "potentially accounting for several common preparation issues. The" - - echo "AUTORECONF, AUTOCONF, AUTOMAKE, LIBTOOLIZE, ACLOCAL, AUTOHEADER," - echo "PROJECT, & CONFIGURE environment variables and corresponding _OPTIONS" - echo "variables (e.g. AUTORECONF_OPTIONS) may be used to override the" - echo "default automatic detection behavior." - echo - - ident - - return 0 -} - - -########################## -# VERSION_ERROR FUNCTION # -########################## -version_error ( ) { - if [ "x$1" = "x" ] ; then - echo "INTERNAL ERROR: version_error was not provided a version" - exit 1 - fi - if [ "x$2" = "x" ] ; then - echo "INTERNAL ERROR: version_error was not provided an application name" - exit 1 - fi - $ECHO - $ECHO "ERROR: To prepare the ${PROJECT} build system from scratch," - $ECHO " at least version $1 of $2 must be installed." - $ECHO - $ECHO "$NAME_OF_AUTOGEN does not need to be run on the same machine that will" - $ECHO "run configure or make. Either the GNU Autotools will need to be installed" - $ECHO "or upgraded on this system, or $NAME_OF_AUTOGEN must be run on the source" - $ECHO "code on another system and then transferred to here. -- Cheers!" - $ECHO -} - -########################## -# VERSION_CHECK FUNCTION # -########################## -version_check ( ) { - if [ "x$1" = "x" ] ; then - echo "INTERNAL ERROR: version_check was not provided a minimum version" - exit 1 - fi - _min="$1" - if [ "x$2" = "x" ] ; then - echo "INTERNAL ERROR: version check was not provided a comparison version" - exit 1 - fi - _cur="$2" - - # needed to handle versions like 1.10 and 1.4-p6 - _min="`echo ${_min}. | sed 's/[^0-9]/./g' | sed 's/\.\././g'`" - _cur="`echo ${_cur}. | sed 's/[^0-9]/./g' | sed 's/\.\././g'`" - - _min_major="`echo $_min | cut -d. -f1`" - _min_minor="`echo $_min | cut -d. -f2`" - _min_patch="`echo $_min | cut -d. -f3`" - - _cur_major="`echo $_cur | cut -d. -f1`" - _cur_minor="`echo $_cur | cut -d. -f2`" - _cur_patch="`echo $_cur | cut -d. -f3`" - - if [ "x$_min_major" = "x" ] ; then - _min_major=0 - fi - if [ "x$_min_minor" = "x" ] ; then - _min_minor=0 - fi - if [ "x$_min_patch" = "x" ] ; then - _min_patch=0 - fi - if [ "x$_cur_minor" = "x" ] ; then - _cur_major=0 - fi - if [ "x$_cur_minor" = "x" ] ; then - _cur_minor=0 - fi - if [ "x$_cur_patch" = "x" ] ; then - _cur_patch=0 - fi - - $VERBOSE_ECHO "Checking if ${_cur_major}.${_cur_minor}.${_cur_patch} is greater than ${_min_major}.${_min_minor}.${_min_patch}" - - if [ $_min_major -lt $_cur_major ] ; then - return 0 - elif [ $_min_major -eq $_cur_major ] ; then - if [ $_min_minor -lt $_cur_minor ] ; then - return 0 - elif [ $_min_minor -eq $_cur_minor ] ; then - if [ $_min_patch -lt $_cur_patch ] ; then - return 0 - elif [ $_min_patch -eq $_cur_patch ] ; then - return 0 - fi - fi - fi - return 1 -} - - -###################################### -# LOCATE_CONFIGURE_TEMPLATE FUNCTION # -###################################### -locate_configure_template ( ) { - _pwd="`pwd`" - if test -f "./configure.ac" ; then - echo "./configure.ac" - elif test -f "./configure.in" ; then - echo "./configure.in" - elif test -f "$_pwd/configure.ac" ; then - echo "$_pwd/configure.ac" - elif test -f "$_pwd/configure.in" ; then - echo "$_pwd/configure.in" - elif test -f "$PATH_TO_AUTOGEN/configure.ac" ; then - echo "$PATH_TO_AUTOGEN/configure.ac" - elif test -f "$PATH_TO_AUTOGEN/configure.in" ; then - echo "$PATH_TO_AUTOGEN/configure.in" - fi -} - - -################## -# argument check # -################## -ARGS="$*" -PATH_TO_AUTOGEN="`dirname $0`" -NAME_OF_AUTOGEN="`basename $0`" -AUTOGEN_SH="$PATH_TO_AUTOGEN/$NAME_OF_AUTOGEN" - -LIBTOOL_M4="${PATH_TO_AUTOGEN}/misc/libtool.m4" - -if [ "x$HELP" = "x" ] ; then - HELP=no -fi -if [ "x$QUIET" = "x" ] ; then - QUIET=no -fi -if [ "x$VERBOSE" = "x" ] ; then - VERBOSE=no -fi -if [ "x$VERSION_ONLY" = "x" ] ; then - VERSION_ONLY=no -fi -if [ "x$DOWNLOAD" = "x" ] ; then - DOWNLOAD=no -fi -if [ "x$AUTORECONF_OPTIONS" = "x" ] ; then - AUTORECONF_OPTIONS="-i -f" -fi -if [ "x$AUTOCONF_OPTIONS" = "x" ] ; then - AUTOCONF_OPTIONS="-f" -fi -if [ "x$AUTOMAKE_OPTIONS" = "x" ] ; then - AUTOMAKE_OPTIONS="-a -c -f" -fi -ALT_AUTOMAKE_OPTIONS="-a -c" -if [ "x$LIBTOOLIZE_OPTIONS" = "x" ] ; then - LIBTOOLIZE_OPTIONS="--automake -c -f" -fi -ALT_LIBTOOLIZE_OPTIONS="--automake --copy --force" -if [ "x$ACLOCAL_OPTIONS" = "x" ] ; then - ACLOCAL_OPTIONS="" -fi -if [ "x$AUTOHEADER_OPTIONS" = "x" ] ; then - AUTOHEADER_OPTIONS="" -fi -if [ "x$CONFIG_GUESS_URL" = "x" ] ; then - CONFIG_GUESS_URL="http://git.savannah.gnu.org/gitweb/?p=gnulib.git;a=blob_plain;f=build-aux/config.guess;hb=HEAD" -fi -for arg in $ARGS ; do - case "x$arg" in - x--help) HELP=yes ;; - x-[hH]) HELP=yes ;; - x--quiet) QUIET=yes ;; - x-[qQ]) QUIET=yes ;; - x--verbose) VERBOSE=yes ;; - x-[dD]) DOWNLOAD=yes ;; - x--download) DOWNLOAD=yes ;; - x-[vV]) VERBOSE=yes ;; - x--version) VERSION_ONLY=yes ;; - *) - echo "Unknown option: $arg" - echo - usage - exit 1 - ;; - esac -done - - -##################### -# environment check # -##################### - -# sanity check before recursions potentially begin -if [ ! -f "$AUTOGEN_SH" ] ; then - echo "INTERNAL ERROR: $AUTOGEN_SH does not exist" - if [ ! "x$0" = "x$AUTOGEN_SH" ] ; then - echo "INTERNAL ERROR: dirname/basename inconsistency: $0 != $AUTOGEN_SH" - fi - exit 1 -fi - -# force locale setting to C so things like date output as expected -LC_ALL=C - -# commands that this script expects -for __cmd in echo head tail pwd ; do - echo "test" | $__cmd > /dev/null 2>&1 - if [ $? != 0 ] ; then - echo "INTERNAL ERROR: '${__cmd}' command is required" - exit 2 - fi -done -echo "test" | grep "test" > /dev/null 2>&1 -if test ! x$? = x0 ; then - echo "INTERNAL ERROR: grep command is required" - exit 1 -fi -echo "test" | sed "s/test/test/" > /dev/null 2>&1 -if test ! x$? = x0 ; then - echo "INTERNAL ERROR: sed command is required" - exit 1 -fi - - -# determine the behavior of echo -case `echo "testing\c"; echo 1,2,3`,`echo -n testing; echo 1,2,3` in - *c*,-n*) ECHO_N= ECHO_C=' -' ECHO_T=' ' ;; - *c*,* ) ECHO_N=-n ECHO_C= ECHO_T= ;; - *) ECHO_N= ECHO_C='\c' ECHO_T= ;; -esac - -# determine the behavior of head -case "x`echo 'head' | head -n 1 2>&1`" in - *xhead*) HEAD_N="n " ;; - *) HEAD_N="" ;; -esac - -# determine the behavior of tail -case "x`echo 'tail' | tail -n 1 2>&1`" in - *xtail*) TAIL_N="n " ;; - *) TAIL_N="" ;; -esac - -VERBOSE_ECHO=: -ECHO=: -if [ "x$QUIET" = "xyes" ] ; then - if [ "x$VERBOSE" = "xyes" ] ; then - echo "Verbose output quelled by quiet option. Further output disabled." - fi -else - ECHO=echo - if [ "x$VERBOSE" = "xyes" ] ; then - echo "Verbose output enabled" - VERBOSE_ECHO=echo - fi -fi - - -# allow a recursive run to disable further recursions -if [ "x$RUN_RECURSIVE" = "x" ] ; then - RUN_RECURSIVE=yes -fi - - -################################################ -# check for help arg and bypass version checks # -################################################ -if [ "x`echo $ARGS | sed 's/.*[hH][eE][lL][pP].*/help/'`" = "xhelp" ] ; then - HELP=yes -fi -if [ "x$HELP" = "xyes" ] ; then - usage - $ECHO "---" - $ECHO "Help was requested. No preparation or configuration will be performed." - exit 0 -fi - - -####################### -# set up signal traps # -####################### -untrap_abnormal ( ) { - for sig in 1 2 13 15; do - trap - $sig - done -} - -# do this cleanup whenever we exit. -trap ' - # start from the root - if test -d "$START_PATH" ; then - cd "$START_PATH" - fi - - # restore/delete backup files - if test "x$PFC_INIT" = "x1" ; then - recursive_restore - fi -' 0 - -# trap SIGHUP (1), SIGINT (2), SIGPIPE (13), SIGTERM (15) -for sig in 1 2 13 15; do - trap ' - $ECHO "" - $ECHO "Aborting $NAME_OF_AUTOGEN: caught signal '$sig'" - - # start from the root - if test -d "$START_PATH" ; then - cd "$START_PATH" - fi - - # clean up on abnormal exit - $VERBOSE_ECHO "rm -rf autom4te.cache" - rm -rf autom4te.cache - - if test -f "acinclude.m4.$$.backup" ; then - $VERBOSE_ECHO "cat acinclude.m4.$$.backup > acinclude.m4" - chmod u+w acinclude.m4 - cat acinclude.m4.$$.backup > acinclude.m4 - - $VERBOSE_ECHO "rm -f acinclude.m4.$$.backup" - rm -f acinclude.m4.$$.backup - fi - - { (exit 1); exit 1; } -' $sig -done - - -############################# -# look for a configure file # -############################# -if [ "x$CONFIGURE" = "x" ] ; then - CONFIGURE="`locate_configure_template`" - if [ ! "x$CONFIGURE" = "x" ] ; then - $VERBOSE_ECHO "Found a configure template: $CONFIGURE" - fi -else - $ECHO "Using CONFIGURE environment variable override: $CONFIGURE" -fi -if [ "x$CONFIGURE" = "x" ] ; then - if [ "x$VERSION_ONLY" = "xyes" ] ; then - CONFIGURE=/dev/null - else - $ECHO - $ECHO "A configure.ac or configure.in file could not be located implying" - $ECHO "that the GNU Build System is at least not used in this directory. In" - $ECHO "any case, there is nothing to do here without one of those files." - $ECHO - $ECHO "ERROR: No configure.in or configure.ac file found in `pwd`" - exit 1 - fi -fi - -#################### -# get project name # -#################### -if [ "x$PROJECT" = "x" ] ; then - PROJECT="`grep AC_INIT $CONFIGURE | grep -v '.*#.*AC_INIT' | tail -${TAIL_N}1 | sed 's/^[ ]*AC_INIT(\([^,)]*\).*/\1/' | sed 's/.*\[\(.*\)\].*/\1/'`" - if [ "x$PROJECT" = "xAC_INIT" ] ; then - # projects might be using the older/deprecated arg-less AC_INIT .. look for AM_INIT_AUTOMAKE instead - PROJECT="`grep AM_INIT_AUTOMAKE $CONFIGURE | grep -v '.*#.*AM_INIT_AUTOMAKE' | tail -${TAIL_N}1 | sed 's/^[ ]*AM_INIT_AUTOMAKE(\([^,)]*\).*/\1/' | sed 's/.*\[\(.*\)\].*/\1/'`" - fi - if [ "x$PROJECT" = "xAM_INIT_AUTOMAKE" ] ; then - PROJECT="project" - fi - if [ "x$PROJECT" = "x" ] ; then - PROJECT="project" - fi -else - $ECHO "Using PROJECT environment variable override: $PROJECT" -fi -$ECHO "Preparing the $PROJECT build system...please wait" -$ECHO - - -######################## -# check for autoreconf # -######################## -HAVE_AUTORECONF=no -if [ "x$AUTORECONF" = "x" ] ; then - for AUTORECONF in autoreconf ; do - $VERBOSE_ECHO "Checking autoreconf version: $AUTORECONF --version" - $AUTORECONF --version > /dev/null 2>&1 - if [ $? = 0 ] ; then - HAVE_AUTORECONF=yes - break - fi - done -else - HAVE_AUTORECONF=yes - $ECHO "Using AUTORECONF environment variable override: $AUTORECONF" -fi - - -########################## -# autoconf version check # -########################## -_acfound=no -if [ "x$AUTOCONF" = "x" ] ; then - for AUTOCONF in autoconf ; do - $VERBOSE_ECHO "Checking autoconf version: $AUTOCONF --version" - $AUTOCONF --version > /dev/null 2>&1 - if [ $? = 0 ] ; then - _acfound=yes - break - fi - done -else - _acfound=yes - $ECHO "Using AUTOCONF environment variable override: $AUTOCONF" -fi - -_report_error=no -if [ ! "x$_acfound" = "xyes" ] ; then - $ECHO "ERROR: Unable to locate GNU Autoconf." - _report_error=yes -else - _version="`$AUTOCONF --version | head -${HEAD_N}1 | sed 's/[^0-9]*\([0-9\.][0-9\.]*\)/\1/'`" - if [ "x$_version" = "x" ] ; then - _version="0.0.0" - fi - $ECHO "Found GNU Autoconf version $_version" - version_check "$AUTOCONF_VERSION" "$_version" - if [ $? -ne 0 ] ; then - _report_error=yes - fi -fi -if [ "x$_report_error" = "xyes" ] ; then - version_error "$AUTOCONF_VERSION" "GNU Autoconf" - exit 1 -fi - - -########################## -# automake version check # -########################## -_amfound=no -if [ "x$AUTOMAKE" = "x" ] ; then - for AUTOMAKE in automake ; do - $VERBOSE_ECHO "Checking automake version: $AUTOMAKE --version" - $AUTOMAKE --version > /dev/null 2>&1 - if [ $? = 0 ] ; then - _amfound=yes - break - fi - done -else - _amfound=yes - $ECHO "Using AUTOMAKE environment variable override: $AUTOMAKE" -fi - - -_report_error=no -if [ ! "x$_amfound" = "xyes" ] ; then - $ECHO - $ECHO "ERROR: Unable to locate GNU Automake." - _report_error=yes -else - _version="`$AUTOMAKE --version | head -${HEAD_N}1 | sed 's/[^0-9]*\([0-9\.][0-9\.]*\)/\1/'`" - if [ "x$_version" = "x" ] ; then - _version="0.0.0" - fi - $ECHO "Found GNU Automake version $_version" - version_check "$AUTOMAKE_VERSION" "$_version" - if [ $? -ne 0 ] ; then - _report_error=yes - fi -fi -if [ "x$_report_error" = "xyes" ] ; then - version_error "$AUTOMAKE_VERSION" "GNU Automake" - exit 1 -fi - - -######################## -# check for libtoolize # -######################## -HAVE_LIBTOOLIZE=yes -HAVE_ALT_LIBTOOLIZE=no -_ltfound=no -if [ "x$LIBTOOLIZE" = "x" ] ; then - LIBTOOLIZE=libtoolize - $VERBOSE_ECHO "Checking libtoolize version: $LIBTOOLIZE --version" - $LIBTOOLIZE --version > /dev/null 2>&1 - if [ ! $? = 0 ] ; then - HAVE_LIBTOOLIZE=no - $ECHO - if [ "x$HAVE_AUTORECONF" = "xno" ] ; then - $ECHO "Warning: libtoolize does not appear to be available." - else - $ECHO "Warning: libtoolize does not appear to be available. This means that" - $ECHO "the automatic build preparation via autoreconf will probably not work." - $ECHO "Preparing the build by running each step individually, however, should" - $ECHO "work and will be done automatically for you if autoreconf fails." - fi - - # look for some alternates - for tool in glibtoolize libtoolize15 libtoolize14 libtoolize13 ; do - $VERBOSE_ECHO "Checking libtoolize alternate: $tool --version" - _glibtoolize="`$tool --version > /dev/null 2>&1`" - if [ $? = 0 ] ; then - $VERBOSE_ECHO "Found $tool --version" - _glti="`which $tool`" - if [ "x$_glti" = "x" ] ; then - $VERBOSE_ECHO "Cannot find $tool with which" - continue; - fi - if test ! -f "$_glti" ; then - $VERBOSE_ECHO "Cannot use $tool, $_glti is not a file" - continue; - fi - _gltidir="`dirname $_glti`" - if [ "x$_gltidir" = "x" ] ; then - $VERBOSE_ECHO "Cannot find $tool path with dirname of $_glti" - continue; - fi - if test ! -d "$_gltidir" ; then - $VERBOSE_ECHO "Cannot use $tool, $_gltidir is not a directory" - continue; - fi - HAVE_ALT_LIBTOOLIZE=yes - LIBTOOLIZE="$tool" - $ECHO - $ECHO "Fortunately, $tool was found which means that your system may simply" - $ECHO "have a non-standard or incomplete GNU Autotools install. If you have" - $ECHO "sufficient system access, it may be possible to quell this warning by" - $ECHO "running:" - $ECHO - sudo -V > /dev/null 2>&1 - if [ $? = 0 ] ; then - $ECHO " sudo ln -s $_glti $_gltidir/libtoolize" - $ECHO - else - $ECHO " ln -s $_glti $_gltidir/libtoolize" - $ECHO - $ECHO "Run that as root or with proper permissions to the $_gltidir directory" - $ECHO - fi - _ltfound=yes - break - fi - done - else - _ltfound=yes - fi -else - _ltfound=yes - $ECHO "Using LIBTOOLIZE environment variable override: $LIBTOOLIZE" -fi - - -############################ -# libtoolize version check # -############################ -_report_error=no -if [ ! "x$_ltfound" = "xyes" ] ; then - $ECHO - $ECHO "ERROR: Unable to locate GNU Libtool." - _report_error=yes -else - _version="`$LIBTOOLIZE --version | head -${HEAD_N}1 | sed 's/[^0-9]*\([0-9\.][0-9\.]*\)/\1/'`" - if [ "x$_version" = "x" ] ; then - _version="0.0.0" - fi - $ECHO "Found GNU Libtool version $_version" - version_check "$LIBTOOL_VERSION" "$_version" - if [ $? -ne 0 ] ; then - _report_error=yes - fi -fi -if [ "x$_report_error" = "xyes" ] ; then - version_error "$LIBTOOL_VERSION" "GNU Libtool" - exit 1 -fi - - -##################### -# check for aclocal # -##################### -if [ "x$ACLOCAL" = "x" ] ; then - for ACLOCAL in aclocal ; do - $VERBOSE_ECHO "Checking aclocal version: $ACLOCAL --version" - $ACLOCAL --version > /dev/null 2>&1 - if [ $? = 0 ] ; then - break - fi - done -else - $ECHO "Using ACLOCAL environment variable override: $ACLOCAL" -fi - - -######################## -# check for autoheader # -######################## -if [ "x$AUTOHEADER" = "x" ] ; then - for AUTOHEADER in autoheader ; do - $VERBOSE_ECHO "Checking autoheader version: $AUTOHEADER --version" - $AUTOHEADER --version > /dev/null 2>&1 - if [ $? = 0 ] ; then - break - fi - done -else - $ECHO "Using AUTOHEADER environment variable override: $AUTOHEADER" -fi - - -######################### -# check if version only # -######################### -$VERBOSE_ECHO "Checking whether to only output version information" -if [ "x$VERSION_ONLY" = "xyes" ] ; then - $ECHO - ident - $ECHO "---" - $ECHO "Version requested. No preparation or configuration will be performed." - exit 0 -fi - - -################################# -# PROTECT_FROM_CLOBBER FUNCTION # -################################# -protect_from_clobber ( ) { - PFC_INIT=1 - - # protect COPYING & INSTALL from overwrite by automake. the - # automake force option will (inappropriately) ignore the existing - # contents of a COPYING and/or INSTALL files (depending on the - # version) instead of just forcing *missing* files like it does - # for AUTHORS, NEWS, and README. this is broken but extremely - # prevalent behavior, so we protect against it by keeping a backup - # of the file that can later be restored. - - for file in COPYING INSTALL ; do - if test -f ${file} ; then - if test -f ${file}.$$.protect_from_automake.backup ; then - $VERBOSE_ECHO "Already backed up ${file} in `pwd`" - else - $VERBOSE_ECHO "Backing up ${file} in `pwd`" - $VERBOSE_ECHO "cp -p ${file} ${file}.$$.protect_from_automake.backup" - cp -p ${file} ${file}.$$.protect_from_automake.backup - fi - fi - done -} - - -############################## -# RECURSIVE_PROTECT FUNCTION # -############################## -recursive_protect ( ) { - - # for projects using recursive configure, run the build - # preparation steps for the subdirectories. this function assumes - # START_PATH was set to pwd before recursion begins so that - # relative paths work. - - # git 'r done, protect COPYING and INSTALL from being clobbered - protect_from_clobber - - if test -d autom4te.cache ; then - $VERBOSE_ECHO "Found an autom4te.cache directory, deleting it" - $VERBOSE_ECHO "rm -rf autom4te.cache" - rm -rf autom4te.cache - fi - - # find configure template - _configure="`locate_configure_template`" - if [ "x$_configure" = "x" ] ; then - return - fi - # $VERBOSE_ECHO "Looking for configure template found `pwd`/$_configure" - - # look for subdirs - # $VERBOSE_ECHO "Looking for subdirs in `pwd`" - _det_config_subdirs="`grep AC_CONFIG_SUBDIRS $_configure | grep -v '.*#.*AC_CONFIG_SUBDIRS' | sed 's/^[ ]*AC_CONFIG_SUBDIRS(\(.*\)).*/\1/' | sed 's/.*\[\(.*\)\].*/\1/'`" - CHECK_DIRS="" - for dir in $_det_config_subdirs ; do - if test -d "`pwd`/$dir" ; then - CHECK_DIRS="$CHECK_DIRS \"`pwd`/$dir\"" - fi - done - - # process subdirs - if [ ! "x$CHECK_DIRS" = "x" ] ; then - $VERBOSE_ECHO "Recursively scanning the following directories:" - $VERBOSE_ECHO " $CHECK_DIRS" - for dir in $CHECK_DIRS ; do - $VERBOSE_ECHO "Protecting files from automake in $dir" - cd "$START_PATH" - eval "cd $dir" - - # recursively git 'r done - recursive_protect - done - fi -} # end of recursive_protect - - -############################# -# RESTORE_CLOBBERED FUNCION # -############################# -restore_clobbered ( ) { - - # The automake (and autoreconf by extension) -f/--force-missing - # option may overwrite COPYING and INSTALL even if they do exist. - # Here we restore the files if necessary. - - spacer=no - - for file in COPYING INSTALL ; do - if test -f ${file}.$$.protect_from_automake.backup ; then - if test -f ${file} ; then - # compare entire content, restore if needed - if test "x`cat ${file}`" != "x`cat ${file}.$$.protect_from_automake.backup`" ; then - if test "x$spacer" = "xno" ; then - $VERBOSE_ECHO - spacer=yes - fi - # restore the backup - $VERBOSE_ECHO "Restoring ${file} from backup (automake -f likely clobbered it)" - $VERBOSE_ECHO "rm -f ${file}" - rm -f ${file} - $VERBOSE_ECHO "mv ${file}.$$.protect_from_automake.backup ${file}" - mv ${file}.$$.protect_from_automake.backup ${file} - fi # check contents - elif test -f ${file}.$$.protect_from_automake.backup ; then - $VERBOSE_ECHO "mv ${file}.$$.protect_from_automake.backup ${file}" - mv ${file}.$$.protect_from_automake.backup ${file} - fi # -f ${file} - - # just in case - $VERBOSE_ECHO "rm -f ${file}.$$.protect_from_automake.backup" - rm -f ${file}.$$.protect_from_automake.backup - fi # -f ${file}.$$.protect_from_automake.backup - done - - CONFIGURE="`locate_configure_template`" - if [ "x$CONFIGURE" = "x" ] ; then - return - fi - - _aux_dir="`grep AC_CONFIG_AUX_DIR $CONFIGURE | grep -v '.*#.*AC_CONFIG_AUX_DIR' | tail -${TAIL_N}1 | sed 's/^[ ]*AC_CONFIG_AUX_DIR(\(.*\)).*/\1/' | sed 's/.*\[\(.*\)\].*/\1/'`" - if test ! -d "$_aux_dir" ; then - _aux_dir=. - fi - - for file in config.guess config.sub ltmain.sh ; do - if test -f "${_aux_dir}/${file}" ; then - $VERBOSE_ECHO "rm -f \"${_aux_dir}/${file}.backup\"" - rm -f "${_aux_dir}/${file}.backup" - fi - done -} # end of restore_clobbered - - -############################## -# RECURSIVE_RESTORE FUNCTION # -############################## -recursive_restore ( ) { - - # restore COPYING and INSTALL from backup if they were clobbered - # for each directory recursively. - - # git 'r undone - restore_clobbered - - # find configure template - _configure="`locate_configure_template`" - if [ "x$_configure" = "x" ] ; then - return - fi - - # look for subdirs - _det_config_subdirs="`grep AC_CONFIG_SUBDIRS $_configure | grep -v '.*#.*AC_CONFIG_SUBDIRS' | sed 's/^[ ]*AC_CONFIG_SUBDIRS(\(.*\)).*/\1/' | sed 's/.*\[\(.*\)\].*/\1/'`" - CHECK_DIRS="" - for dir in $_det_config_subdirs ; do - if test -d "`pwd`/$dir" ; then - CHECK_DIRS="$CHECK_DIRS \"`pwd`/$dir\"" - fi - done - - # process subdirs - if [ ! "x$CHECK_DIRS" = "x" ] ; then - $VERBOSE_ECHO "Recursively scanning the following directories:" - $VERBOSE_ECHO " $CHECK_DIRS" - for dir in $CHECK_DIRS ; do - $VERBOSE_ECHO "Checking files for automake damage in $dir" - cd "$START_PATH" - eval "cd $dir" - - # recursively git 'r undone - recursive_restore - done - fi -} # end of recursive_restore - - -####################### -# INITIALIZE FUNCTION # -####################### -initialize ( ) { - - # this routine performs a variety of directory-specific - # initializations. some are sanity checks, some are preventive, - # and some are necessary setup detection. - # - # this function sets: - # CONFIGURE - # SEARCH_DIRS - # CONFIG_SUBDIRS - - ################################## - # check for a configure template # - ################################## - CONFIGURE="`locate_configure_template`" - if [ "x$CONFIGURE" = "x" ] ; then - $ECHO - $ECHO "A configure.ac or configure.in file could not be located implying" - $ECHO "that the GNU Build System is at least not used in this directory. In" - $ECHO "any case, there is nothing to do here without one of those files." - $ECHO - $ECHO "ERROR: No configure.in or configure.ac file found in `pwd`" - exit 1 - fi - - ##################### - # detect an aux dir # - ##################### - _aux_dir="`grep AC_CONFIG_AUX_DIR $CONFIGURE | grep -v '.*#.*AC_CONFIG_AUX_DIR' | tail -${TAIL_N}1 | sed 's/^[ ]*AC_CONFIG_AUX_DIR(\(.*\)).*/\1/' | sed 's/.*\[\(.*\)\].*/\1/'`" - if test ! -d "$_aux_dir" ; then - _aux_dir=. - else - $VERBOSE_ECHO "Detected auxillary directory: $_aux_dir" - fi - - ################################ - # detect a recursive configure # - ################################ - CONFIG_SUBDIRS="" - _det_config_subdirs="`grep AC_CONFIG_SUBDIRS $CONFIGURE | grep -v '.*#.*AC_CONFIG_SUBDIRS' | sed 's/^[ ]*AC_CONFIG_SUBDIRS(\(.*\)).*/\1/' | sed 's/.*\[\(.*\)\].*/\1/'`" - for dir in $_det_config_subdirs ; do - if test -d "`pwd`/$dir" ; then - $VERBOSE_ECHO "Detected recursive configure directory: `pwd`/$dir" - CONFIG_SUBDIRS="$CONFIG_SUBDIRS `pwd`/$dir" - fi - done - - ########################################################### - # make sure certain required files exist for GNU projects # - ########################################################### - _marker_found="" - _marker_found_message_intro='Detected non-GNU marker "' - _marker_found_message_mid='" in ' - for marker in foreign cygnus ; do - _marker_found_message=${_marker_found_message_intro}${marker}${_marker_found_message_mid} - _marker_found="`grep 'AM_INIT_AUTOMAKE.*'${marker} $CONFIGURE`" - if [ ! "x$_marker_found" = "x" ] ; then - $VERBOSE_ECHO "${_marker_found_message}`basename \"$CONFIGURE\"`" - break - fi - if test -f "`dirname \"$CONFIGURE\"/Makefile.am`" ; then - _marker_found="`grep 'AUTOMAKE_OPTIONS.*'${marker} Makefile.am`" - if [ ! "x$_marker_found" = "x" ] ; then - $VERBOSE_ECHO "${_marker_found_message}Makefile.am" - break - fi - fi - done - if [ "x${_marker_found}" = "x" ] ; then - _suggest_foreign=no - for file in AUTHORS COPYING ChangeLog INSTALL NEWS README ; do - if [ ! -f $file ] ; then - $VERBOSE_ECHO "Touching ${file} since it does not exist" - _suggest_foreign=yes - touch $file - fi - done - - if [ "x${_suggest_foreign}" = "xyes" ] ; then - $ECHO - $ECHO "Warning: Several files expected of projects that conform to the GNU" - $ECHO "coding standards were not found. The files were automatically added" - $ECHO "for you since you do not have a 'foreign' declaration specified." - $ECHO - $ECHO "Considered adding 'foreign' to AM_INIT_AUTOMAKE in `basename \"$CONFIGURE\"`" - if test -f "`dirname \"$CONFIGURE\"/Makefile.am`" ; then - $ECHO "or to AUTOMAKE_OPTIONS in your top-level Makefile.am file." - fi - $ECHO - fi - fi - - ################################################## - # make sure certain generated files do not exist # - ################################################## - for file in config.guess config.sub ltmain.sh ; do - if test -f "${_aux_dir}/${file}" ; then - $VERBOSE_ECHO "mv -f \"${_aux_dir}/${file}\" \"${_aux_dir}/${file}.backup\"" - mv -f "${_aux_dir}/${file}" "${_aux_dir}/${file}.backup" - fi - done - - ############################ - # search alternate m4 dirs # - ############################ - SEARCH_DIRS="" - for dir in m4 ; do - if [ -d $dir ] ; then - $VERBOSE_ECHO "Found extra aclocal search directory: $dir" - SEARCH_DIRS="$SEARCH_DIRS -I $dir" - fi - done - - ###################################### - # remove any previous build products # - ###################################### - if test -d autom4te.cache ; then - $VERBOSE_ECHO "Found an autom4te.cache directory, deleting it" - $VERBOSE_ECHO "rm -rf autom4te.cache" - rm -rf autom4te.cache - fi -# tcl/tk (and probably others) have a customized aclocal.m4, so can't delete it -# if test -f aclocal.m4 ; then -# $VERBOSE_ECHO "Found an aclocal.m4 file, deleting it" -# $VERBOSE_ECHO "rm -f aclocal.m4" -# rm -f aclocal.m4 -# fi - -} # end of initialize() - - -############## -# initialize # -############## - -# stash path -START_PATH="`pwd`" - -# Before running autoreconf or manual steps, some prep detection work -# is necessary or useful. Only needs to occur once per directory, but -# does need to traverse the entire subconfigure hierarchy to protect -# files from being clobbered even by autoreconf. -recursive_protect - -# start from where we started -cd "$START_PATH" - -# get ready to process -initialize - - -######################################### -# DOWNLOAD_GNULIB_CONFIG_GUESS FUNCTION # -######################################### - -# TODO - should make sure wget/curl exist and/or work before trying to -# use them. - -download_gnulib_config_guess () { - # abuse gitweb to download gnulib's latest config.guess via HTTP - config_guess_temp="config.guess.$$.download" - ret=1 - for __cmd in wget curl fetch ; do - $VERBOSE_ECHO "Checking for command ${__cmd}" - ${__cmd} --version > /dev/null 2>&1 - ret=$? - if [ ! $ret = 0 ] ; then - continue - fi - - __cmd_version=`${__cmd} --version | head -n 1 | sed -e 's/^[^0-9]\+//' -e 's/ .*//'` - $VERBOSE_ECHO "Found ${__cmd} ${__cmd_version}" - - opts="" - case ${__cmd} in - wget) - opts="-O" - ;; - curl) - opts="-o" - ;; - fetch) - opts="-t 5 -f" - ;; - esac - - $VERBOSE_ECHO "Running $__cmd \"${CONFIG_GUESS_URL}\" $opts \"${config_guess_temp}\"" - eval "$__cmd \"${CONFIG_GUESS_URL}\" $opts \"${config_guess_temp}\"" > /dev/null 2>&1 - if [ $? = 0 ] ; then - mv -f "${config_guess_temp}" ${_aux_dir}/config.guess - ret=0 - break - fi - done - - if [ ! $ret = 0 ] ; then - $ECHO "Warning: config.guess download failed from: $CONFIG_GUESS_URL" - rm -f "${config_guess_temp}" - fi -} - - -############################## -# LIBTOOLIZE_NEEDED FUNCTION # -############################## -libtoolize_needed () { - ret=1 # means no, don't need libtoolize - for feature in AC_PROG_LIBTOOL AM_PROG_LIBTOOL LT_INIT ; do - $VERBOSE_ECHO "Searching for $feature in $CONFIGURE" - found="`grep \"^$feature.*\" $CONFIGURE`" - if [ ! "x$found" = "x" ] ; then - ret=0 # means yes, need to run libtoolize - break - fi - done - return ${ret} -} - - - -############################################ -# prepare build via autoreconf or manually # -############################################ -reconfigure_manually=no -if [ "x$HAVE_AUTORECONF" = "xyes" ] ; then - $ECHO - $ECHO $ECHO_N "Automatically preparing build ... $ECHO_C" - - $VERBOSE_ECHO "$AUTORECONF $SEARCH_DIRS $AUTORECONF_OPTIONS" - autoreconf_output="`$AUTORECONF $SEARCH_DIRS $AUTORECONF_OPTIONS 2>&1`" - ret=$? - $VERBOSE_ECHO "$autoreconf_output" - - if [ ! $ret = 0 ] ; then - if [ "x$HAVE_ALT_LIBTOOLIZE" = "xyes" ] ; then - if [ ! "x`echo \"$autoreconf_output\" | grep libtoolize | grep \"No such file or directory\"`" = "x" ] ; then - $ECHO - $ECHO "Warning: autoreconf failed but due to what is usually a common libtool" - $ECHO "misconfiguration issue. This problem is encountered on systems that" - $ECHO "have installed libtoolize under a different name without providing a" - $ECHO "symbolic link or without setting the LIBTOOLIZE environment variable." - $ECHO - $ECHO "Restarting the preparation steps with LIBTOOLIZE set to $LIBTOOLIZE" - - export LIBTOOLIZE - RUN_RECURSIVE=no - export RUN_RECURSIVE - untrap_abnormal - - $VERBOSE_ECHO sh $AUTOGEN_SH "$1" "$2" "$3" "$4" "$5" "$6" "$7" "$8" "$9" - sh "$AUTOGEN_SH" "$1" "$2" "$3" "$4" "$5" "$6" "$7" "$8" "$9" - exit $? - fi - fi - - $ECHO "Warning: $AUTORECONF failed" - - if test -f ltmain.sh ; then - $ECHO "libtoolize being run by autoreconf is not creating ltmain.sh in the auxillary directory like it should" - fi - - $ECHO "Attempting to run the preparation steps individually" - reconfigure_manually=yes - else - if [ "x$DOWNLOAD" = "xyes" ] ; then - if libtoolize_needed ; then - download_gnulib_config_guess - fi - fi - fi -else - reconfigure_manually=yes -fi - - -############################ -# LIBTOOL_FAILURE FUNCTION # -############################ -libtool_failure ( ) { - - # libtool is rather error-prone in comparison to the other - # autotools and this routine attempts to compensate for some - # common failures. the output after a libtoolize failure is - # parsed for an error related to AC_PROG_LIBTOOL and if found, we - # attempt to inject a project-provided libtool.m4 file. - - _autoconf_output="$1" - - if [ "x$RUN_RECURSIVE" = "xno" ] ; then - # we already tried the libtool.m4, don't try again - return 1 - fi - - if test -f "$LIBTOOL_M4" ; then - found_libtool="`$ECHO $_autoconf_output | grep AC_PROG_LIBTOOL`" - if test ! "x$found_libtool" = "x" ; then - if test -f acinclude.m4 ; then - rm -f acinclude.m4.$$.backup - $VERBOSE_ECHO "cat acinclude.m4 > acinclude.m4.$$.backup" - cat acinclude.m4 > acinclude.m4.$$.backup - fi - $VERBOSE_ECHO "cat \"$LIBTOOL_M4\" >> acinclude.m4" - chmod u+w acinclude.m4 - cat "$LIBTOOL_M4" >> acinclude.m4 - - # don't keep doing this - RUN_RECURSIVE=no - export RUN_RECURSIVE - untrap_abnormal - - $ECHO - $ECHO "Restarting the preparation steps with libtool macros in acinclude.m4" - $VERBOSE_ECHO sh $AUTOGEN_SH "$1" "$2" "$3" "$4" "$5" "$6" "$7" "$8" "$9" - sh "$AUTOGEN_SH" "$1" "$2" "$3" "$4" "$5" "$6" "$7" "$8" "$9" - exit $? - fi - fi -} - - -########################### -# MANUAL_AUTOGEN FUNCTION # -########################### -manual_autogen ( ) { - - ################################################## - # Manual preparation steps taken are as follows: # - # aclocal [-I m4] # - # libtoolize --automake -c -f # - # aclocal [-I m4] # - # autoconf -f # - # autoheader # - # automake -a -c -f # - ################################################## - - ########### - # aclocal # - ########### - $VERBOSE_ECHO "$ACLOCAL $SEARCH_DIRS $ACLOCAL_OPTIONS" - aclocal_output="`$ACLOCAL $SEARCH_DIRS $ACLOCAL_OPTIONS 2>&1`" - ret=$? - $VERBOSE_ECHO "$aclocal_output" - if [ ! $ret = 0 ] ; then $ECHO "ERROR: $ACLOCAL failed" && exit 2 ; fi - - ############## - # libtoolize # - ############## - if libtoolize_needed ; then - if [ "x$HAVE_LIBTOOLIZE" = "xyes" ] ; then - $VERBOSE_ECHO "$LIBTOOLIZE $LIBTOOLIZE_OPTIONS" - libtoolize_output="`$LIBTOOLIZE $LIBTOOLIZE_OPTIONS 2>&1`" - ret=$? - $VERBOSE_ECHO "$libtoolize_output" - - if [ ! $ret = 0 ] ; then $ECHO "ERROR: $LIBTOOLIZE failed" && exit 2 ; fi - else - if [ "x$HAVE_ALT_LIBTOOLIZE" = "xyes" ] ; then - $VERBOSE_ECHO "$LIBTOOLIZE $ALT_LIBTOOLIZE_OPTIONS" - libtoolize_output="`$LIBTOOLIZE $ALT_LIBTOOLIZE_OPTIONS 2>&1`" - ret=$? - $VERBOSE_ECHO "$libtoolize_output" - - if [ ! $ret = 0 ] ; then $ECHO "ERROR: $LIBTOOLIZE failed" && exit 2 ; fi - fi - fi - - ########### - # aclocal # - ########### - # re-run again as instructed by libtoolize - $VERBOSE_ECHO "$ACLOCAL $SEARCH_DIRS $ACLOCAL_OPTIONS" - aclocal_output="`$ACLOCAL $SEARCH_DIRS $ACLOCAL_OPTIONS 2>&1`" - ret=$? - $VERBOSE_ECHO "$aclocal_output" - - # libtoolize might put ltmain.sh in the wrong place - if test -f ltmain.sh ; then - if test ! -f "${_aux_dir}/ltmain.sh" ; then - $ECHO - $ECHO "Warning: $LIBTOOLIZE is creating ltmain.sh in the wrong directory" - $ECHO - $ECHO "Fortunately, the problem can be worked around by simply copying the" - $ECHO "file to the appropriate location (${_aux_dir}/). This has been done for you." - $ECHO - $VERBOSE_ECHO "cp -p ltmain.sh \"${_aux_dir}/ltmain.sh\"" - cp -p ltmain.sh "${_aux_dir}/ltmain.sh" - $ECHO $ECHO_N "Continuing build preparation ... $ECHO_C" - fi - fi # ltmain.sh - - if [ "x$DOWNLOAD" = "xyes" ] ; then - download_gnulib_config_guess - fi - fi # libtoolize_needed - - ############ - # autoconf # - ############ - $VERBOSE_ECHO - $VERBOSE_ECHO "$AUTOCONF $AUTOCONF_OPTIONS" - autoconf_output="`$AUTOCONF $AUTOCONF_OPTIONS 2>&1`" - ret=$? - $VERBOSE_ECHO "$autoconf_output" - - if [ ! $ret = 0 ] ; then - # retry without the -f and check for usage of macros that are too new - ac2_59_macros="AC_C_RESTRICT AC_INCLUDES_DEFAULT AC_LANG_ASSERT AC_LANG_WERROR AS_SET_CATFILE" - ac2_55_macros="AC_COMPILER_IFELSE AC_FUNC_MBRTOWC AC_HEADER_STDBOOL AC_LANG_CONFTEST AC_LANG_SOURCE AC_LANG_PROGRAM AC_LANG_CALL AC_LANG_FUNC_TRY_LINK AC_MSG_FAILURE AC_PREPROC_IFELSE" - ac2_54_macros="AC_C_BACKSLASH_A AC_CONFIG_LIBOBJ_DIR AC_GNU_SOURCE AC_PROG_EGREP AC_PROG_FGREP AC_REPLACE_FNMATCH AC_FUNC_FNMATCH_GNU AC_FUNC_REALLOC AC_TYPE_MBSTATE_T" - - macros_to_search="" - ac_major="`echo ${AUTOCONF_VERSION}. | cut -d. -f1 | sed 's/[^0-9]//g'`" - ac_minor="`echo ${AUTOCONF_VERSION}. | cut -d. -f2 | sed 's/[^0-9]//g'`" - - if [ $ac_major -lt 2 ] ; then - macros_to_search="$ac2_59_macros $ac2_55_macros $ac2_54_macros" - else - if [ $ac_minor -lt 54 ] ; then - macros_to_search="$ac2_59_macros $ac2_55_macros $ac2_54_macros" - elif [ $ac_minor -lt 55 ] ; then - macros_to_search="$ac2_59_macros $ac2_55_macros" - elif [ $ac_minor -lt 59 ] ; then - macros_to_search="$ac2_59_macros" - fi - fi - - configure_ac_macros=__none__ - for feature in $macros_to_search ; do - $VERBOSE_ECHO "Searching for $feature in $CONFIGURE" - found="`grep \"^$feature.*\" $CONFIGURE`" - if [ ! "x$found" = "x" ] ; then - if [ "x$configure_ac_macros" = "x__none__" ] ; then - configure_ac_macros="$feature" - else - configure_ac_macros="$feature $configure_ac_macros" - fi - fi - done - if [ ! "x$configure_ac_macros" = "x__none__" ] ; then - $ECHO - $ECHO "Warning: Unsupported macros were found in $CONFIGURE" - $ECHO - $ECHO "The `basename \"$CONFIGURE\"` file was scanned in order to determine if any" - $ECHO "unsupported macros are used that exceed the minimum version" - $ECHO "settings specified within this file. As such, the following macros" - $ECHO "should be removed from configure.ac or the version numbers in this" - $ECHO "file should be increased:" - $ECHO - $ECHO "$configure_ac_macros" - $ECHO - $ECHO $ECHO_N "Ignorantly continuing build preparation ... $ECHO_C" - fi - - ################### - # autoconf, retry # - ################### - $VERBOSE_ECHO - $VERBOSE_ECHO "$AUTOCONF" - autoconf_output="`$AUTOCONF 2>&1`" - ret=$? - $VERBOSE_ECHO "$autoconf_output" - - if [ ! $ret = 0 ] ; then - # test if libtool is busted - libtool_failure "$autoconf_output" - - # let the user know what went wrong - cat <<EOF -$autoconf_output -EOF - $ECHO "ERROR: $AUTOCONF failed" - exit 2 - else - # autoconf sans -f and possibly sans unsupported options succeed so warn verbosely - $ECHO - $ECHO "Warning: autoconf seems to have succeeded by removing the following options:" - $ECHO " AUTOCONF_OPTIONS=\"$AUTOCONF_OPTIONS\"" - $ECHO - $ECHO "Removing those options should not be necessary and indicate some other" - $ECHO "problem with the build system. The build preparation is highly suspect" - $ECHO "and may result in configuration or compilation errors. Consider" - if [ "x$VERBOSE_ECHO" = "x:" ] ; then - $ECHO "rerunning the build preparation with verbose output enabled." - $ECHO " $AUTOGEN_SH --verbose" - else - $ECHO "reviewing the minimum GNU Autotools version settings contained in" - $ECHO "this script along with the macros being used in your `basename \"$CONFIGURE\"` file." - fi - $ECHO - $ECHO $ECHO_N "Continuing build preparation ... $ECHO_C" - fi # autoconf ret = 0 - fi # autoconf ret = 0 - - ############## - # autoheader # - ############## - need_autoheader=no - for feature in AM_CONFIG_HEADER AC_CONFIG_HEADER ; do - $VERBOSE_ECHO "Searching for $feature in $CONFIGURE" - found="`grep \"^$feature.*\" $CONFIGURE`" - if [ ! "x$found" = "x" ] ; then - need_autoheader=yes - break - fi - done - if [ "x$need_autoheader" = "xyes" ] ; then - $VERBOSE_ECHO "$AUTOHEADER $AUTOHEADER_OPTIONS" - autoheader_output="`$AUTOHEADER $AUTOHEADER_OPTIONS 2>&1`" - ret=$? - $VERBOSE_ECHO "$autoheader_output" - if [ ! $ret = 0 ] ; then $ECHO "ERROR: $AUTOHEADER failed" && exit 2 ; fi - fi # need_autoheader - - ############ - # automake # - ############ - need_automake=no - for feature in AM_INIT_AUTOMAKE ; do - $VERBOSE_ECHO "Searching for $feature in $CONFIGURE" - found="`grep \"^$feature.*\" $CONFIGURE`" - if [ ! "x$found" = "x" ] ; then - need_automake=yes - break - fi - done - - if [ "x$need_automake" = "xyes" ] ; then - $VERBOSE_ECHO "$AUTOMAKE $AUTOMAKE_OPTIONS" - automake_output="`$AUTOMAKE $AUTOMAKE_OPTIONS 2>&1`" - ret=$? - $VERBOSE_ECHO "$automake_output" - - if [ ! $ret = 0 ] ; then - - ################### - # automake, retry # - ################### - $VERBOSE_ECHO - $VERBOSE_ECHO "$AUTOMAKE $ALT_AUTOMAKE_OPTIONS" - # retry without the -f - automake_output="`$AUTOMAKE $ALT_AUTOMAKE_OPTIONS 2>&1`" - ret=$? - $VERBOSE_ECHO "$automake_output" - - if [ ! $ret = 0 ] ; then - # test if libtool is busted - libtool_failure "$automake_output" - - # let the user know what went wrong - cat <<EOF -$automake_output -EOF - $ECHO "ERROR: $AUTOMAKE failed" - exit 2 - fi # automake retry - fi # automake ret = 0 - fi # need_automake -} # end of manual_autogen - - -##################################### -# RECURSIVE_MANUAL_AUTOGEN FUNCTION # -##################################### -recursive_manual_autogen ( ) { - - # run the build preparation steps manually for this directory - manual_autogen - - # for projects using recursive configure, run the build - # preparation steps for the subdirectories. - if [ ! "x$CONFIG_SUBDIRS" = "x" ] ; then - $VERBOSE_ECHO "Recursively configuring the following directories:" - $VERBOSE_ECHO " $CONFIG_SUBDIRS" - for dir in $CONFIG_SUBDIRS ; do - $VERBOSE_ECHO "Processing recursive configure in $dir" - cd "$START_PATH" - cd "$dir" - - # new directory, prepare - initialize - - # run manual steps for the subdir and any others below - recursive_manual_autogen - done - fi -} - - -################################ -# run manual preparation steps # -################################ -if [ "x$reconfigure_manually" = "xyes" ] ; then - $ECHO - $ECHO $ECHO_N "Preparing build ... $ECHO_C" - - recursive_manual_autogen -fi - - -######################### -# restore and summarize # -######################### -cd "$START_PATH" - -# restore COPYING and INSTALL from backup if necessary -recursive_restore - -# make sure we end up with a configure script -config_ac="`locate_configure_template`" -config="`echo $config_ac | sed 's/\.ac$//' | sed 's/\.in$//'`" -if [ "x$config" = "x" ] ; then - $VERBOSE_ECHO "Could not locate the configure template (from `pwd`)" -fi - -# summarize -$ECHO "done" -$ECHO -if test "x$config" = "x" -o ! -f "$config" ; then - $ECHO "WARNING: The $PROJECT build system should now be prepared but there" - $ECHO "does not seem to be a resulting configure file. This is unexpected" - $ECHO "and likely the result of an error. You should run $NAME_OF_AUTOGEN" - $ECHO "with the --verbose option to get more details on a potential" - $ECHO "misconfiguration." -else - $ECHO "The $PROJECT build system is now prepared. To build here, run:" - $ECHO " $config" - $ECHO " make" -fi - - -# Local Variables: -# mode: sh -# tab-width: 8 -# sh-basic-offset: 4 -# sh-indentation: 4 -# indent-tabs-mode: t -# End: -# ex: shiftwidth=4 tabstop=8 diff --git a/tikzit/build/DEBIAN/control b/tikzit/build/DEBIAN/control deleted file mode 100644 index 25d2f07..0000000 --- a/tikzit/build/DEBIAN/control +++ /dev/null @@ -1,11 +0,0 @@ -Package: tikzit -Version: 0.3 -Section: tex -Priority: optional -Architecture: all -Essential: no -Depends: libgtk2.0-0 -Installed-Size: 156kB -Maintainer: Chris Heunen <chrisheunen@gmail.com> -Provides: tikzit -Description: TikZiT is a GTK+ application that allows the creation and modification of TeX diagrams written using the pgf/TikZ macro library. It is especially geared toward rapidly creating "dot"-diagrams for use in academic papers. diff --git a/tikzit/configure.ac b/tikzit/configure.ac deleted file mode 100644 index 8f791b6..0000000 --- a/tikzit/configure.ac +++ /dev/null @@ -1,127 +0,0 @@ -# -*- Autoconf -*- -# Process this file with autoconf to produce a configure script. - -AC_PREREQ([2.60]) -AC_INIT([TikZiT], [1.0], - [http://sourceforge.net/apps/trac/tikzit], - [tikzit], - [http://tikzit.sourceforge.net]) -AM_INIT_AUTOMAKE([foreign subdir-objects -Wall -Werror]) -AM_SILENT_RULES([yes]) -AC_OUTPUT(Makefile - src/Makefile - share/Makefile -) -AC_CONFIG_SRCDIR([src/gtk/main.m]) - -m4_include([m4/objc.m4]) - -# Checks for programs. -AC_PROG_OBJC([gcc clang objc objcc]) -AC_LANG([Objective C]) - -AC_PROG_LEX -AM_PROG_LEX -AC_PROG_YACC - -# Checks for libraries. -FOUNDATION_OBJCFLAGS=`eval "gnustep-config --objc-flags"` -AS_IF([test "x$FOUNDATION_OBJCFLAGS" = "x"], - [AC_MSG_ERROR([GNUstep not found])]) -FOUNDATION_LIBS=`eval "gnustep-config --base-libs"` -AS_IF([test "x$FOUNDATION_LIBS" = "x"], - [AC_MSG_ERROR([GNUstep not found])]) -AC_SUBST([FOUNDATION_OBJCFLAGS]) -AC_SUBST([FOUNDATION_LIBS]) - -TZ_TEST_OBJCFLAGS="$FOUNDATION_OBJCFLAGS" -TZ_TEST_LDFLAGS="$FOUNDATION_LIBS" - -TZ_OBJC_FOUNDATION -AS_IF([test "x$tz_cv_objc_foundation" != "xyes"], - [AC_MSG_ERROR([Objective C Foundation not found -- missing gnustep-base(-devel)?])]) - -AC_ARG_WITH([poppler], AS_HELP_STRING([--without-poppler], [Ignore presence of poppler, disabling preview support])) - -AS_IF([test "x$with_poppler" != "xno"], - [ - AC_MSG_CHECKING([for poppler-glib]) - PKG_CHECK_EXISTS([poppler-glib >= 0.10], - [have_poppler=yes], - [have_poppler=no]) - AS_IF([test "x$have_poppler" = "xyes"], - [ - AC_MSG_RESULT([yes]) - AC_DEFINE(HAVE_POPPLER, 1) - ], - [ - AC_MSG_RESULT([no]) - AS_IF([test "x$with_poppler" = "xyes"], - [AC_MSG_ERROR([poppler requested but not found (note that poppler-glib is required)])] - ) - ]) - ], - [have_poppler=no]) -AM_CONDITIONAL([HAVE_POPPLER],[test "x$have_poppler" = "xyes"]) - -# Test all the pkg-config stuff together, so that -# dependencies and duplicate flags are correctly handled -AS_IF([test "x$have_poppler" = "xyes"], - [PKG_CHECK_MODULES([GTK], [gtk+-2.0 >= 2.18.0 gdk-pixbuf-2.0 >= 2.16.0 pango >= 1.16 cairo >= 1.4 poppler-glib >= 0.10])], - [PKG_CHECK_MODULES([GTK], [gtk+-2.0 >= 2.18.0 gdk-pixbuf-2.0 >= 2.16.0 pango >= 1.16 cairo >= 1.4])]) - -# Checks for header files. -AC_FUNC_ALLOCA -AC_CHECK_HEADERS([inttypes.h libintl.h limits.h malloc.h stddef.h stdint.h stdlib.h string.h unistd.h]) - -# Checks for typedefs, structures, and compiler characteristics. -AC_TYPE_INT16_T -AC_TYPE_INT32_T -AC_TYPE_INT8_T -AC_TYPE_SIZE_T -AC_TYPE_UINT16_T -AC_TYPE_UINT32_T -AC_TYPE_UINT64_T -AC_TYPE_UINT8_T -AC_HEADER_STDBOOL -AC_HEADER_STAT -AC_CHECK_HEADERS([stdint.h inttypes.h unistd.h sys/time.h time.h]) - -# Checks for library functions. -AC_FUNC_MALLOC -AC_FUNC_REALLOC -AC_CHECK_FUNCS([floor gettimeofday memset mkdtemp sqrt strdup]) - -TZ_OBJC2_FEATURES -AS_IF([test "x$tz_cv_objc_properties$tz_cv_objc_fast_enumeration$tz_cv_objc_optional_keyword" != "xyesyesyes"], - [AC_MSG_ERROR([Your Objective C compiler does not support the required Objective C 2 features])]) - -dnl ---------------------------------------------------------------------------- -dnl -dnl platform-specific stuff. - -AC_CANONICAL_HOST -have_msw="no" -case $host_os in - - *mingw32*) - have_msw="yes" - OBJCFLAGS="$OBJCFLAGS -mwindows" - AC_SUBST([WINDOWS]) - AC_SUBST([WIN32]) - AC_SUBST([_WIN32]) - ;; - -esac - -AM_CONDITIONAL([WINDOWS],[test "x$have_msw" = "xyes"]) - -AS_IF([test "x$with_poppler" != "xno"], - [AS_IF([test "x$have_poppler" != "xyes"], - AC_MSG_WARN([poppler-glib was not found; preview support will be disabled]) - )] - ) - -AC_OUTPUT - -# vi:sts=2:sw=2:et diff --git a/tikzit/docs/Doxyfile b/tikzit/docs/Doxyfile deleted file mode 100644 index 70a27f7..0000000 --- a/tikzit/docs/Doxyfile +++ /dev/null @@ -1,1600 +0,0 @@ -# Doxyfile 1.6.3 - -# This file describes the settings to be used by the documentation system -# doxygen (www.doxygen.org) for a project -# -# All text after a hash (#) is considered a comment and will be ignored -# The format is: -# TAG = value [value, ...] -# For lists items can also be appended using: -# TAG += value [value, ...] -# Values that contain spaces should be placed between quotes (" ") - -#--------------------------------------------------------------------------- -# Project related configuration options -#--------------------------------------------------------------------------- - -# This tag specifies the encoding used for all characters in the config file -# that follow. The default is UTF-8 which is also the encoding used for all -# text before the first occurrence of this tag. Doxygen uses libiconv (or the -# iconv built into libc) for the transcoding. See -# http://www.gnu.org/software/libiconv for the list of possible encodings. - -DOXYFILE_ENCODING = UTF-8 - -# The PROJECT_NAME tag is a single word (or a sequence of words surrounded -# by quotes) that should identify the project. - -PROJECT_NAME = TikZiT - -# The PROJECT_NUMBER tag can be used to enter a project or revision number. -# This could be handy for archiving the generated documentation or -# if some version control system is used. - -PROJECT_NUMBER = 0.3 - -# The OUTPUT_DIRECTORY tag is used to specify the (relative or absolute) -# base path where the generated documentation will be put. -# If a relative path is entered, it will be relative to the location -# where doxygen was started. If left blank the current directory will be used. - -OUTPUT_DIRECTORY = doxygen - -# If the CREATE_SUBDIRS tag is set to YES, then doxygen will create -# 4096 sub-directories (in 2 levels) under the output directory of each output -# format and will distribute the generated files over these directories. -# Enabling this option can be useful when feeding doxygen a huge amount of -# source files, where putting all generated files in the same directory would -# otherwise cause performance problems for the file system. - -CREATE_SUBDIRS = NO - -# The OUTPUT_LANGUAGE tag is used to specify the language in which all -# documentation generated by doxygen is written. Doxygen will use this -# information to generate all constant output in the proper language. -# The default language is English, other supported languages are: -# Afrikaans, Arabic, Brazilian, Catalan, Chinese, Chinese-Traditional, -# Croatian, Czech, Danish, Dutch, Esperanto, Farsi, Finnish, French, German, -# Greek, Hungarian, Italian, Japanese, Japanese-en (Japanese with English -# messages), Korean, Korean-en, Lithuanian, Norwegian, Macedonian, Persian, -# Polish, Portuguese, Romanian, Russian, Serbian, Serbian-Cyrilic, Slovak, -# Slovene, Spanish, Swedish, Ukrainian, and Vietnamese. - -OUTPUT_LANGUAGE = English - -# If the BRIEF_MEMBER_DESC tag is set to YES (the default) Doxygen will -# include brief member descriptions after the members that are listed in -# the file and class documentation (similar to JavaDoc). -# Set to NO to disable this. - -BRIEF_MEMBER_DESC = YES - -# If the REPEAT_BRIEF tag is set to YES (the default) Doxygen will prepend -# the brief description of a member or function before the detailed description. -# Note: if both HIDE_UNDOC_MEMBERS and BRIEF_MEMBER_DESC are set to NO, the -# brief descriptions will be completely suppressed. - -REPEAT_BRIEF = YES - -# This tag implements a quasi-intelligent brief description abbreviator -# that is used to form the text in various listings. Each string -# in this list, if found as the leading text of the brief description, will be -# stripped from the text and the result after processing the whole list, is -# used as the annotated text. Otherwise, the brief description is used as-is. -# If left blank, the following values are used ("$name" is automatically -# replaced with the name of the entity): "The $name class" "The $name widget" -# "The $name file" "is" "provides" "specifies" "contains" -# "represents" "a" "an" "the" - -ABBREVIATE_BRIEF = "The $name class" \ - "The $name widget" \ - "The $name file" \ - is \ - provides \ - specifies \ - contains \ - represents \ - a \ - an \ - the - -# If the ALWAYS_DETAILED_SEC and REPEAT_BRIEF tags are both set to YES then -# Doxygen will generate a detailed section even if there is only a brief -# description. - -ALWAYS_DETAILED_SEC = NO - -# If the INLINE_INHERITED_MEMB tag is set to YES, doxygen will show all -# inherited members of a class in the documentation of that class as if those -# members were ordinary class members. Constructors, destructors and assignment -# operators of the base classes will not be shown. - -INLINE_INHERITED_MEMB = NO - -# If the FULL_PATH_NAMES tag is set to YES then Doxygen will prepend the full -# path before files name in the file list and in the header files. If set -# to NO the shortest path that makes the file name unique will be used. - -FULL_PATH_NAMES = YES - -# If the FULL_PATH_NAMES tag is set to YES then the STRIP_FROM_PATH tag -# can be used to strip a user-defined part of the path. Stripping is -# only done if one of the specified strings matches the left-hand part of -# the path. The tag can be used to show relative paths in the file list. -# If left blank the directory from which doxygen is run is used as the -# path to strip. - -STRIP_FROM_PATH = /Applications/ - -# The STRIP_FROM_INC_PATH tag can be used to strip a user-defined part of -# the path mentioned in the documentation of a class, which tells -# the reader which header file to include in order to use a class. -# If left blank only the name of the header file containing the class -# definition is used. Otherwise one should specify the include paths that -# are normally passed to the compiler using the -I flag. - -STRIP_FROM_INC_PATH = - -# If the SHORT_NAMES tag is set to YES, doxygen will generate much shorter -# (but less readable) file names. This can be useful is your file systems -# doesn't support long names like on DOS, Mac, or CD-ROM. - -SHORT_NAMES = NO - -# If the JAVADOC_AUTOBRIEF tag is set to YES then Doxygen -# will interpret the first line (until the first dot) of a JavaDoc-style -# comment as the brief description. If set to NO, the JavaDoc -# comments will behave just like regular Qt-style comments -# (thus requiring an explicit @brief command for a brief description.) - -JAVADOC_AUTOBRIEF = NO - -# If the QT_AUTOBRIEF tag is set to YES then Doxygen will -# interpret the first line (until the first dot) of a Qt-style -# comment as the brief description. If set to NO, the comments -# will behave just like regular Qt-style comments (thus requiring -# an explicit \brief command for a brief description.) - -QT_AUTOBRIEF = NO - -# The MULTILINE_CPP_IS_BRIEF tag can be set to YES to make Doxygen -# treat a multi-line C++ special comment block (i.e. a block of //! or /// -# comments) as a brief description. This used to be the default behaviour. -# The new default is to treat a multi-line C++ comment block as a detailed -# description. Set this tag to YES if you prefer the old behaviour instead. - -MULTILINE_CPP_IS_BRIEF = NO - -# If the INHERIT_DOCS tag is set to YES (the default) then an undocumented -# member inherits the documentation from any documented member that it -# re-implements. - -INHERIT_DOCS = YES - -# If the SEPARATE_MEMBER_PAGES tag is set to YES, then doxygen will produce -# a new page for each member. If set to NO, the documentation of a member will -# be part of the file/class/namespace that contains it. - -SEPARATE_MEMBER_PAGES = NO - -# The TAB_SIZE tag can be used to set the number of spaces in a tab. -# Doxygen uses this value to replace tabs by spaces in code fragments. - -TAB_SIZE = 8 - -# This tag can be used to specify a number of aliases that acts -# as commands in the documentation. An alias has the form "name=value". -# For example adding "sideeffect=\par Side Effects:\n" will allow you to -# put the command \sideeffect (or @sideeffect) in the documentation, which -# will result in a user-defined paragraph with heading "Side Effects:". -# You can put \n's in the value part of an alias to insert newlines. - -ALIASES = - -# Set the OPTIMIZE_OUTPUT_FOR_C tag to YES if your project consists of C -# sources only. Doxygen will then generate output that is more tailored for C. -# For instance, some of the names that are used will be different. The list -# of all members will be omitted, etc. - -OPTIMIZE_OUTPUT_FOR_C = NO - -# Set the OPTIMIZE_OUTPUT_JAVA tag to YES if your project consists of Java -# sources only. Doxygen will then generate output that is more tailored for -# Java. For instance, namespaces will be presented as packages, qualified -# scopes will look different, etc. - -OPTIMIZE_OUTPUT_JAVA = NO - -# Set the OPTIMIZE_FOR_FORTRAN tag to YES if your project consists of Fortran -# sources only. Doxygen will then generate output that is more tailored for -# Fortran. - -OPTIMIZE_FOR_FORTRAN = NO - -# Set the OPTIMIZE_OUTPUT_VHDL tag to YES if your project consists of VHDL -# sources. Doxygen will then generate output that is tailored for -# VHDL. - -OPTIMIZE_OUTPUT_VHDL = NO - -# Doxygen selects the parser to use depending on the extension of the files it parses. -# With this tag you can assign which parser to use for a given extension. -# Doxygen has a built-in mapping, but you can override or extend it using this tag. -# The format is ext=language, where ext is a file extension, and language is one of -# the parsers supported by doxygen: IDL, Java, Javascript, C#, C, C++, D, PHP, -# Objective-C, Python, Fortran, VHDL, C, C++. For instance to make doxygen treat -# .inc files as Fortran files (default is PHP), and .f files as C (default is Fortran), -# use: inc=Fortran f=C. Note that for custom extensions you also need to set -# FILE_PATTERNS otherwise the files are not read by doxygen. - -EXTENSION_MAPPING = - -# If you use STL classes (i.e. std::string, std::vector, etc.) but do not want -# to include (a tag file for) the STL sources as input, then you should -# set this tag to YES in order to let doxygen match functions declarations and -# definitions whose arguments contain STL classes (e.g. func(std::string); v.s. -# func(std::string) {}). This also make the inheritance and collaboration -# diagrams that involve STL classes more complete and accurate. - -BUILTIN_STL_SUPPORT = NO - -# If you use Microsoft's C++/CLI language, you should set this option to YES to -# enable parsing support. - -CPP_CLI_SUPPORT = NO - -# Set the SIP_SUPPORT tag to YES if your project consists of sip sources only. -# Doxygen will parse them like normal C++ but will assume all classes use public -# instead of private inheritance when no explicit protection keyword is present. - -SIP_SUPPORT = NO - -# For Microsoft's IDL there are propget and propput attributes to indicate getter -# and setter methods for a property. Setting this option to YES (the default) -# will make doxygen to replace the get and set methods by a property in the -# documentation. This will only work if the methods are indeed getting or -# setting a simple type. If this is not the case, or you want to show the -# methods anyway, you should set this option to NO. - -IDL_PROPERTY_SUPPORT = YES - -# If member grouping is used in the documentation and the DISTRIBUTE_GROUP_DOC -# tag is set to YES, then doxygen will reuse the documentation of the first -# member in the group (if any) for the other members of the group. By default -# all members of a group must be documented explicitly. - -DISTRIBUTE_GROUP_DOC = NO - -# Set the SUBGROUPING tag to YES (the default) to allow class member groups of -# the same type (for instance a group of public functions) to be put as a -# subgroup of that type (e.g. under the Public Functions section). Set it to -# NO to prevent subgrouping. Alternatively, this can be done per class using -# the \nosubgrouping command. - -SUBGROUPING = YES - -# When TYPEDEF_HIDES_STRUCT is enabled, a typedef of a struct, union, or enum -# is documented as struct, union, or enum with the name of the typedef. So -# typedef struct TypeS {} TypeT, will appear in the documentation as a struct -# with name TypeT. When disabled the typedef will appear as a member of a file, -# namespace, or class. And the struct will be named TypeS. This can typically -# be useful for C code in case the coding convention dictates that all compound -# types are typedef'ed and only the typedef is referenced, never the tag name. - -TYPEDEF_HIDES_STRUCT = NO - -# The SYMBOL_CACHE_SIZE determines the size of the internal cache use to -# determine which symbols to keep in memory and which to flush to disk. -# When the cache is full, less often used symbols will be written to disk. -# For small to medium size projects (<1000 input files) the default value is -# probably good enough. For larger projects a too small cache size can cause -# doxygen to be busy swapping symbols to and from disk most of the time -# causing a significant performance penality. -# If the system has enough physical memory increasing the cache will improve the -# performance by keeping more symbols in memory. Note that the value works on -# a logarithmic scale so increasing the size by one will rougly double the -# memory usage. The cache size is given by this formula: -# 2^(16+SYMBOL_CACHE_SIZE). The valid range is 0..9, the default is 0, -# corresponding to a cache size of 2^16 = 65536 symbols - -SYMBOL_CACHE_SIZE = 0 - -#--------------------------------------------------------------------------- -# Build related configuration options -#--------------------------------------------------------------------------- - -# If the EXTRACT_ALL tag is set to YES doxygen will assume all entities in -# documentation are documented, even if no documentation was available. -# Private class members and static file members will be hidden unless -# the EXTRACT_PRIVATE and EXTRACT_STATIC tags are set to YES - -EXTRACT_ALL = YES - -# If the EXTRACT_PRIVATE tag is set to YES all private members of a class -# will be included in the documentation. - -EXTRACT_PRIVATE = NO - -# If the EXTRACT_STATIC tag is set to YES all static members of a file -# will be included in the documentation. - -EXTRACT_STATIC = NO - -# If the EXTRACT_LOCAL_CLASSES tag is set to YES classes (and structs) -# defined locally in source files will be included in the documentation. -# If set to NO only classes defined in header files are included. - -EXTRACT_LOCAL_CLASSES = YES - -# This flag is only useful for Objective-C code. When set to YES local -# methods, which are defined in the implementation section but not in -# the interface are included in the documentation. -# If set to NO (the default) only methods in the interface are included. - -EXTRACT_LOCAL_METHODS = NO - -# If this flag is set to YES, the members of anonymous namespaces will be -# extracted and appear in the documentation as a namespace called -# 'anonymous_namespace{file}', where file will be replaced with the base -# name of the file that contains the anonymous namespace. By default -# anonymous namespace are hidden. - -EXTRACT_ANON_NSPACES = NO - -# If the HIDE_UNDOC_MEMBERS tag is set to YES, Doxygen will hide all -# undocumented members of documented classes, files or namespaces. -# If set to NO (the default) these members will be included in the -# various overviews, but no documentation section is generated. -# This option has no effect if EXTRACT_ALL is enabled. - -HIDE_UNDOC_MEMBERS = YES - -# If the HIDE_UNDOC_CLASSES tag is set to YES, Doxygen will hide all -# undocumented classes that are normally visible in the class hierarchy. -# If set to NO (the default) these classes will be included in the various -# overviews. This option has no effect if EXTRACT_ALL is enabled. - -HIDE_UNDOC_CLASSES = YES - -# If the HIDE_FRIEND_COMPOUNDS tag is set to YES, Doxygen will hide all -# friend (class|struct|union) declarations. -# If set to NO (the default) these declarations will be included in the -# documentation. - -HIDE_FRIEND_COMPOUNDS = NO - -# If the HIDE_IN_BODY_DOCS tag is set to YES, Doxygen will hide any -# documentation blocks found inside the body of a function. -# If set to NO (the default) these blocks will be appended to the -# function's detailed documentation block. - -HIDE_IN_BODY_DOCS = NO - -# The INTERNAL_DOCS tag determines if documentation -# that is typed after a \internal command is included. If the tag is set -# to NO (the default) then the documentation will be excluded. -# Set it to YES to include the internal documentation. - -INTERNAL_DOCS = NO - -# If the CASE_SENSE_NAMES tag is set to NO then Doxygen will only generate -# file names in lower-case letters. If set to YES upper-case letters are also -# allowed. This is useful if you have classes or files whose names only differ -# in case and if your file system supports case sensitive file names. Windows -# and Mac users are advised to set this option to NO. - -CASE_SENSE_NAMES = NO - -# If the HIDE_SCOPE_NAMES tag is set to NO (the default) then Doxygen -# will show members with their full class and namespace scopes in the -# documentation. If set to YES the scope will be hidden. - -HIDE_SCOPE_NAMES = NO - -# If the SHOW_INCLUDE_FILES tag is set to YES (the default) then Doxygen -# will put a list of the files that are included by a file in the documentation -# of that file. - -SHOW_INCLUDE_FILES = YES - -# If the FORCE_LOCAL_INCLUDES tag is set to YES then Doxygen -# will list include files with double quotes in the documentation -# rather than with sharp brackets. - -FORCE_LOCAL_INCLUDES = NO - -# If the INLINE_INFO tag is set to YES (the default) then a tag [inline] -# is inserted in the documentation for inline members. - -INLINE_INFO = YES - -# If the SORT_MEMBER_DOCS tag is set to YES (the default) then doxygen -# will sort the (detailed) documentation of file and class members -# alphabetically by member name. If set to NO the members will appear in -# declaration order. - -SORT_MEMBER_DOCS = YES - -# If the SORT_BRIEF_DOCS tag is set to YES then doxygen will sort the -# brief documentation of file, namespace and class members alphabetically -# by member name. If set to NO (the default) the members will appear in -# declaration order. - -SORT_BRIEF_DOCS = NO - -# If the SORT_MEMBERS_CTORS_1ST tag is set to YES then doxygen -# will sort the (brief and detailed) documentation of class members so that -# constructors and destructors are listed first. If set to NO (the default) -# the constructors will appear in the respective orders defined by -# SORT_MEMBER_DOCS and SORT_BRIEF_DOCS. -# This tag will be ignored for brief docs if SORT_BRIEF_DOCS is set to NO -# and ignored for detailed docs if SORT_MEMBER_DOCS is set to NO. - -SORT_MEMBERS_CTORS_1ST = NO - -# If the SORT_GROUP_NAMES tag is set to YES then doxygen will sort the -# hierarchy of group names into alphabetical order. If set to NO (the default) -# the group names will appear in their defined order. - -SORT_GROUP_NAMES = NO - -# If the SORT_BY_SCOPE_NAME tag is set to YES, the class list will be -# sorted by fully-qualified names, including namespaces. If set to -# NO (the default), the class list will be sorted only by class name, -# not including the namespace part. -# Note: This option is not very useful if HIDE_SCOPE_NAMES is set to YES. -# Note: This option applies only to the class list, not to the -# alphabetical list. - -SORT_BY_SCOPE_NAME = NO - -# The GENERATE_TODOLIST tag can be used to enable (YES) or -# disable (NO) the todo list. This list is created by putting \todo -# commands in the documentation. - -GENERATE_TODOLIST = YES - -# The GENERATE_TESTLIST tag can be used to enable (YES) or -# disable (NO) the test list. This list is created by putting \test -# commands in the documentation. - -GENERATE_TESTLIST = YES - -# The GENERATE_BUGLIST tag can be used to enable (YES) or -# disable (NO) the bug list. This list is created by putting \bug -# commands in the documentation. - -GENERATE_BUGLIST = YES - -# The GENERATE_DEPRECATEDLIST tag can be used to enable (YES) or -# disable (NO) the deprecated list. This list is created by putting -# \deprecated commands in the documentation. - -GENERATE_DEPRECATEDLIST= YES - -# The ENABLED_SECTIONS tag can be used to enable conditional -# documentation sections, marked by \if sectionname ... \endif. - -ENABLED_SECTIONS = - -# The MAX_INITIALIZER_LINES tag determines the maximum number of lines -# the initial value of a variable or define consists of for it to appear in -# the documentation. If the initializer consists of more lines than specified -# here it will be hidden. Use a value of 0 to hide initializers completely. -# The appearance of the initializer of individual variables and defines in the -# documentation can be controlled using \showinitializer or \hideinitializer -# command in the documentation regardless of this setting. - -MAX_INITIALIZER_LINES = 30 - -# Set the SHOW_USED_FILES tag to NO to disable the list of files generated -# at the bottom of the documentation of classes and structs. If set to YES the -# list will mention the files that were used to generate the documentation. - -SHOW_USED_FILES = YES - -# If the sources in your project are distributed over multiple directories -# then setting the SHOW_DIRECTORIES tag to YES will show the directory hierarchy -# in the documentation. The default is NO. - -SHOW_DIRECTORIES = NO - -# Set the SHOW_FILES tag to NO to disable the generation of the Files page. -# This will remove the Files entry from the Quick Index and from the -# Folder Tree View (if specified). The default is YES. - -SHOW_FILES = YES - -# Set the SHOW_NAMESPACES tag to NO to disable the generation of the -# Namespaces page. This will remove the Namespaces entry from the Quick Index -# and from the Folder Tree View (if specified). The default is YES. - -SHOW_NAMESPACES = YES - -# The FILE_VERSION_FILTER tag can be used to specify a program or script that -# doxygen should invoke to get the current version for each file (typically from -# the version control system). Doxygen will invoke the program by executing (via -# popen()) the command <command> <input-file>, where <command> is the value of -# the FILE_VERSION_FILTER tag, and <input-file> is the name of an input file -# provided by doxygen. Whatever the program writes to standard output -# is used as the file version. See the manual for examples. - -FILE_VERSION_FILTER = - -# The LAYOUT_FILE tag can be used to specify a layout file which will be parsed by -# doxygen. The layout file controls the global structure of the generated output files -# in an output format independent way. The create the layout file that represents -# doxygen's defaults, run doxygen with the -l option. You can optionally specify a -# file name after the option, if omitted DoxygenLayout.xml will be used as the name -# of the layout file. - -LAYOUT_FILE = - -#--------------------------------------------------------------------------- -# configuration options related to warning and progress messages -#--------------------------------------------------------------------------- - -# The QUIET tag can be used to turn on/off the messages that are generated -# by doxygen. Possible values are YES and NO. If left blank NO is used. - -QUIET = NO - -# The WARNINGS tag can be used to turn on/off the warning messages that are -# generated by doxygen. Possible values are YES and NO. If left blank -# NO is used. - -WARNINGS = YES - -# If WARN_IF_UNDOCUMENTED is set to YES, then doxygen will generate warnings -# for undocumented members. If EXTRACT_ALL is set to YES then this flag will -# automatically be disabled. - -WARN_IF_UNDOCUMENTED = YES - -# If WARN_IF_DOC_ERROR is set to YES, doxygen will generate warnings for -# potential errors in the documentation, such as not documenting some -# parameters in a documented function, or documenting parameters that -# don't exist or using markup commands wrongly. - -WARN_IF_DOC_ERROR = YES - -# This WARN_NO_PARAMDOC option can be abled to get warnings for -# functions that are documented, but have no documentation for their parameters -# or return value. If set to NO (the default) doxygen will only warn about -# wrong or incomplete parameter documentation, but not about the absence of -# documentation. - -WARN_NO_PARAMDOC = YES - -# The WARN_FORMAT tag determines the format of the warning messages that -# doxygen can produce. The string should contain the $file, $line, and $text -# tags, which will be replaced by the file and line number from which the -# warning originated and the warning text. Optionally the format may contain -# $version, which will be replaced by the version of the file (if it could -# be obtained via FILE_VERSION_FILTER) - -WARN_FORMAT = "$file:$line: $text" - -# The WARN_LOGFILE tag can be used to specify a file to which warning -# and error messages should be written. If left blank the output is written -# to stderr. - -WARN_LOGFILE = - -#--------------------------------------------------------------------------- -# configuration options related to the input files -#--------------------------------------------------------------------------- - -# The INPUT tag can be used to specify the files and/or directories that contain -# documented source files. You may enter file names like "myfile.cpp" or -# directories like "/usr/src/myproject". Separate the files or directories -# with spaces. - -INPUT = ../src - -# This tag can be used to specify the character encoding of the source files -# that doxygen parses. Internally doxygen uses the UTF-8 encoding, which is -# also the default input encoding. Doxygen uses libiconv (or the iconv built -# into libc) for the transcoding. See http://www.gnu.org/software/libiconv for -# the list of possible encodings. - -INPUT_ENCODING = UTF-8 - -# If the value of the INPUT tag contains directories, you can use the -# FILE_PATTERNS tag to specify one or more wildcard pattern (like *.cpp -# and *.h) to filter out the source-files in the directories. If left -# blank the following patterns are tested: -# *.c *.cc *.cxx *.cpp *.c++ *.java *.ii *.ixx *.ipp *.i++ *.inl *.h *.hh *.hxx -# *.hpp *.h++ *.idl *.odl *.cs *.php *.php3 *.inc *.m *.mm *.py *.f90 - -FILE_PATTERNS = *.c \ - *.cc \ - *.cxx \ - *.cpp \ - *.c++ \ - *.d \ - *.java \ - *.ii \ - *.ixx \ - *.ipp \ - *.i++ \ - *.inl \ - *.h \ - *.hh \ - *.hxx \ - *.hpp \ - *.h++ \ - *.idl \ - *.odl \ - *.cs \ - *.php \ - *.php3 \ - *.inc \ - *.m \ - *.mm \ - *.dox \ - *.py \ - *.f90 \ - *.f \ - *.vhd \ - *.vhdl - -# The RECURSIVE tag can be used to turn specify whether or not subdirectories -# should be searched for input files as well. Possible values are YES and NO. -# If left blank NO is used. - -RECURSIVE = YES - -# The EXCLUDE tag can be used to specify files and/or directories that should -# excluded from the INPUT source files. This way you can easily exclude a -# subdirectory from a directory tree whose root is specified with the INPUT tag. - -EXCLUDE = ../src/ParseKit - -# The EXCLUDE_SYMLINKS tag can be used select whether or not files or -# directories that are symbolic links (a Unix filesystem feature) are excluded -# from the input. - -EXCLUDE_SYMLINKS = NO - -# If the value of the INPUT tag contains directories, you can use the -# EXCLUDE_PATTERNS tag to specify one or more wildcard patterns to exclude -# certain files from those directories. Note that the wildcards are matched -# against the file with absolute path, so to exclude all test directories -# for example use the pattern */test/* - -EXCLUDE_PATTERNS = - -# The EXCLUDE_SYMBOLS tag can be used to specify one or more symbol names -# (namespaces, classes, functions, etc.) that should be excluded from the -# output. The symbol name can be a fully qualified name, a word, or if the -# wildcard * is used, a substring. Examples: ANamespace, AClass, -# AClass::ANamespace, ANamespace::*Test - -EXCLUDE_SYMBOLS = - -# The EXAMPLE_PATH tag can be used to specify one or more files or -# directories that contain example code fragments that are included (see -# the \include command). - -EXAMPLE_PATH = - -# If the value of the EXAMPLE_PATH tag contains directories, you can use the -# EXAMPLE_PATTERNS tag to specify one or more wildcard pattern (like *.cpp -# and *.h) to filter out the source-files in the directories. If left -# blank all files are included. - -EXAMPLE_PATTERNS = * - -# If the EXAMPLE_RECURSIVE tag is set to YES then subdirectories will be -# searched for input files to be used with the \include or \dontinclude -# commands irrespective of the value of the RECURSIVE tag. -# Possible values are YES and NO. If left blank NO is used. - -EXAMPLE_RECURSIVE = NO - -# The IMAGE_PATH tag can be used to specify one or more files or -# directories that contain image that are included in the documentation (see -# the \image command). - -IMAGE_PATH = - -# The INPUT_FILTER tag can be used to specify a program that doxygen should -# invoke to filter for each input file. Doxygen will invoke the filter program -# by executing (via popen()) the command <filter> <input-file>, where <filter> -# is the value of the INPUT_FILTER tag, and <input-file> is the name of an -# input file. Doxygen will then use the output that the filter program writes -# to standard output. If FILTER_PATTERNS is specified, this tag will be -# ignored. - -INPUT_FILTER = - -# The FILTER_PATTERNS tag can be used to specify filters on a per file pattern -# basis. Doxygen will compare the file name with each pattern and apply the -# filter if there is a match. The filters are a list of the form: -# pattern=filter (like *.cpp=my_cpp_filter). See INPUT_FILTER for further -# info on how filters are used. If FILTER_PATTERNS is empty, INPUT_FILTER -# is applied to all files. - -FILTER_PATTERNS = - -# If the FILTER_SOURCE_FILES tag is set to YES, the input filter (if set using -# INPUT_FILTER) will be used to filter the input files when producing source -# files to browse (i.e. when SOURCE_BROWSER is set to YES). - -FILTER_SOURCE_FILES = NO - -#--------------------------------------------------------------------------- -# configuration options related to source browsing -#--------------------------------------------------------------------------- - -# If the SOURCE_BROWSER tag is set to YES then a list of source files will -# be generated. Documented entities will be cross-referenced with these sources. -# Note: To get rid of all source code in the generated output, make sure also -# VERBATIM_HEADERS is set to NO. - -SOURCE_BROWSER = YES - -# Setting the INLINE_SOURCES tag to YES will include the body -# of functions and classes directly in the documentation. - -INLINE_SOURCES = NO - -# Setting the STRIP_CODE_COMMENTS tag to YES (the default) will instruct -# doxygen to hide any special comment blocks from generated source code -# fragments. Normal C and C++ comments will always remain visible. - -STRIP_CODE_COMMENTS = YES - -# If the REFERENCED_BY_RELATION tag is set to YES -# then for each documented function all documented -# functions referencing it will be listed. - -REFERENCED_BY_RELATION = NO - -# If the REFERENCES_RELATION tag is set to YES -# then for each documented function all documented entities -# called/used by that function will be listed. - -REFERENCES_RELATION = NO - -# If the REFERENCES_LINK_SOURCE tag is set to YES (the default) -# and SOURCE_BROWSER tag is set to YES, then the hyperlinks from -# functions in REFERENCES_RELATION and REFERENCED_BY_RELATION lists will -# link to the source code. Otherwise they will link to the documentation. - -REFERENCES_LINK_SOURCE = YES - -# If the USE_HTAGS tag is set to YES then the references to source code -# will point to the HTML generated by the htags(1) tool instead of doxygen -# built-in source browser. The htags tool is part of GNU's global source -# tagging system (see http://www.gnu.org/software/global/global.html). You -# will need version 4.8.6 or higher. - -USE_HTAGS = NO - -# If the VERBATIM_HEADERS tag is set to YES (the default) then Doxygen -# will generate a verbatim copy of the header file for each class for -# which an include is specified. Set to NO to disable this. - -VERBATIM_HEADERS = NO - -#--------------------------------------------------------------------------- -# configuration options related to the alphabetical class index -#--------------------------------------------------------------------------- - -# If the ALPHABETICAL_INDEX tag is set to YES, an alphabetical index -# of all compounds will be generated. Enable this if the project -# contains a lot of classes, structs, unions or interfaces. - -ALPHABETICAL_INDEX = NO - -# If the alphabetical index is enabled (see ALPHABETICAL_INDEX) then -# the COLS_IN_ALPHA_INDEX tag can be used to specify the number of columns -# in which this list will be split (can be a number in the range [1..20]) - -COLS_IN_ALPHA_INDEX = 5 - -# In case all classes in a project start with a common prefix, all -# classes will be put under the same header in the alphabetical index. -# The IGNORE_PREFIX tag can be used to specify one or more prefixes that -# should be ignored while generating the index headers. - -IGNORE_PREFIX = - -#--------------------------------------------------------------------------- -# configuration options related to the HTML output -#--------------------------------------------------------------------------- - -# If the GENERATE_HTML tag is set to YES (the default) Doxygen will -# generate HTML output. - -GENERATE_HTML = YES - -# The HTML_OUTPUT tag is used to specify where the HTML docs will be put. -# If a relative path is entered the value of OUTPUT_DIRECTORY will be -# put in front of it. If left blank `html' will be used as the default path. - -HTML_OUTPUT = html - -# The HTML_FILE_EXTENSION tag can be used to specify the file extension for -# each generated HTML page (for example: .htm,.php,.asp). If it is left blank -# doxygen will generate files with .html extension. - -HTML_FILE_EXTENSION = .html - -# The HTML_HEADER tag can be used to specify a personal HTML header for -# each generated HTML page. If it is left blank doxygen will generate a -# standard header. - -HTML_HEADER = - -# The HTML_FOOTER tag can be used to specify a personal HTML footer for -# each generated HTML page. If it is left blank doxygen will generate a -# standard footer. - -HTML_FOOTER = - -# The HTML_STYLESHEET tag can be used to specify a user-defined cascading -# style sheet that is used by each HTML page. It can be used to -# fine-tune the look of the HTML output. If the tag is left blank doxygen -# will generate a default style sheet. Note that doxygen will try to copy -# the style sheet file to the HTML output directory, so don't put your own -# stylesheet in the HTML output directory as well, or it will be erased! - -HTML_STYLESHEET = - -# If the HTML_TIMESTAMP tag is set to YES then the footer of each generated HTML -# page will contain the date and time when the page was generated. Setting -# this to NO can help when comparing the output of multiple runs. - -HTML_TIMESTAMP = YES - -# If the HTML_ALIGN_MEMBERS tag is set to YES, the members of classes, -# files or namespaces will be aligned in HTML using tables. If set to -# NO a bullet list will be used. - -HTML_ALIGN_MEMBERS = YES - -# If the HTML_DYNAMIC_SECTIONS tag is set to YES then the generated HTML -# documentation will contain sections that can be hidden and shown after the -# page has loaded. For this to work a browser that supports -# JavaScript and DHTML is required (for instance Mozilla 1.0+, Firefox -# Netscape 6.0+, Internet explorer 5.0+, Konqueror, or Safari). - -HTML_DYNAMIC_SECTIONS = NO - -# If the GENERATE_DOCSET tag is set to YES, additional index files -# will be generated that can be used as input for Apple's Xcode 3 -# integrated development environment, introduced with OSX 10.5 (Leopard). -# To create a documentation set, doxygen will generate a Makefile in the -# HTML output directory. Running make will produce the docset in that -# directory and running "make install" will install the docset in -# ~/Library/Developer/Shared/Documentation/DocSets so that Xcode will find -# it at startup. -# See http://developer.apple.com/tools/creatingdocsetswithdoxygen.html for more information. - -GENERATE_DOCSET = NO - -# When GENERATE_DOCSET tag is set to YES, this tag determines the name of the -# feed. A documentation feed provides an umbrella under which multiple -# documentation sets from a single provider (such as a company or product suite) -# can be grouped. - -DOCSET_FEEDNAME = "Doxygen generated docs" - -# When GENERATE_DOCSET tag is set to YES, this tag specifies a string that -# should uniquely identify the documentation set bundle. This should be a -# reverse domain-name style string, e.g. com.mycompany.MyDocSet. Doxygen -# will append .docset to the name. - -DOCSET_BUNDLE_ID = org.doxygen.Project - -# If the GENERATE_HTMLHELP tag is set to YES, additional index files -# will be generated that can be used as input for tools like the -# Microsoft HTML help workshop to generate a compiled HTML help file (.chm) -# of the generated HTML documentation. - -GENERATE_HTMLHELP = NO - -# If the GENERATE_HTMLHELP tag is set to YES, the CHM_FILE tag can -# be used to specify the file name of the resulting .chm file. You -# can add a path in front of the file if the result should not be -# written to the html output directory. - -CHM_FILE = - -# If the GENERATE_HTMLHELP tag is set to YES, the HHC_LOCATION tag can -# be used to specify the location (absolute path including file name) of -# the HTML help compiler (hhc.exe). If non-empty doxygen will try to run -# the HTML help compiler on the generated index.hhp. - -HHC_LOCATION = - -# If the GENERATE_HTMLHELP tag is set to YES, the GENERATE_CHI flag -# controls if a separate .chi index file is generated (YES) or that -# it should be included in the master .chm file (NO). - -GENERATE_CHI = NO - -# If the GENERATE_HTMLHELP tag is set to YES, the CHM_INDEX_ENCODING -# is used to encode HtmlHelp index (hhk), content (hhc) and project file -# content. - -CHM_INDEX_ENCODING = - -# If the GENERATE_HTMLHELP tag is set to YES, the BINARY_TOC flag -# controls whether a binary table of contents is generated (YES) or a -# normal table of contents (NO) in the .chm file. - -BINARY_TOC = NO - -# The TOC_EXPAND flag can be set to YES to add extra items for group members -# to the contents of the HTML help documentation and to the tree view. - -TOC_EXPAND = NO - -# If the GENERATE_QHP tag is set to YES and both QHP_NAMESPACE and QHP_VIRTUAL_FOLDER -# are set, an additional index file will be generated that can be used as input for -# Qt's qhelpgenerator to generate a Qt Compressed Help (.qch) of the generated -# HTML documentation. - -GENERATE_QHP = NO - -# If the QHG_LOCATION tag is specified, the QCH_FILE tag can -# be used to specify the file name of the resulting .qch file. -# The path specified is relative to the HTML output folder. - -QCH_FILE = - -# The QHP_NAMESPACE tag specifies the namespace to use when generating -# Qt Help Project output. For more information please see -# http://doc.trolltech.com/qthelpproject.html#namespace - -QHP_NAMESPACE = org.doxygen.Project - -# The QHP_VIRTUAL_FOLDER tag specifies the namespace to use when generating -# Qt Help Project output. For more information please see -# http://doc.trolltech.com/qthelpproject.html#virtual-folders - -QHP_VIRTUAL_FOLDER = doc - -# If QHP_CUST_FILTER_NAME is set, it specifies the name of a custom filter to add. -# For more information please see -# http://doc.trolltech.com/qthelpproject.html#custom-filters - -QHP_CUST_FILTER_NAME = - -# The QHP_CUST_FILT_ATTRS tag specifies the list of the attributes of the custom filter to add.For more information please see -# <a href="http://doc.trolltech.com/qthelpproject.html#custom-filters">Qt Help Project / Custom Filters</a>. - -QHP_CUST_FILTER_ATTRS = - -# The QHP_SECT_FILTER_ATTRS tag specifies the list of the attributes this project's -# filter section matches. -# <a href="http://doc.trolltech.com/qthelpproject.html#filter-attributes">Qt Help Project / Filter Attributes</a>. - -QHP_SECT_FILTER_ATTRS = - -# If the GENERATE_QHP tag is set to YES, the QHG_LOCATION tag can -# be used to specify the location of Qt's qhelpgenerator. -# If non-empty doxygen will try to run qhelpgenerator on the generated -# .qhp file. - -QHG_LOCATION = - -# If the GENERATE_ECLIPSEHELP tag is set to YES, additional index files -# will be generated, which together with the HTML files, form an Eclipse help -# plugin. To install this plugin and make it available under the help contents -# menu in Eclipse, the contents of the directory containing the HTML and XML -# files needs to be copied into the plugins directory of eclipse. The name of -# the directory within the plugins directory should be the same as -# the ECLIPSE_DOC_ID value. After copying Eclipse needs to be restarted before -# the help appears. - -GENERATE_ECLIPSEHELP = NO - -# A unique identifier for the eclipse help plugin. When installing the plugin -# the directory name containing the HTML and XML files should also have -# this name. - -ECLIPSE_DOC_ID = org.doxygen.Project - -# The DISABLE_INDEX tag can be used to turn on/off the condensed index at -# top of each HTML page. The value NO (the default) enables the index and -# the value YES disables it. - -DISABLE_INDEX = NO - -# This tag can be used to set the number of enum values (range [1..20]) -# that doxygen will group on one line in the generated HTML documentation. - -ENUM_VALUES_PER_LINE = 4 - -# The GENERATE_TREEVIEW tag is used to specify whether a tree-like index -# structure should be generated to display hierarchical information. -# If the tag value is set to YES, a side panel will be generated -# containing a tree-like index structure (just like the one that -# is generated for HTML Help). For this to work a browser that supports -# JavaScript, DHTML, CSS and frames is required (i.e. any modern browser). -# Windows users are probably better off using the HTML help feature. - -GENERATE_TREEVIEW = NO - -# By enabling USE_INLINE_TREES, doxygen will generate the Groups, Directories, -# and Class Hierarchy pages using a tree view instead of an ordered list. - -USE_INLINE_TREES = NO - -# If the treeview is enabled (see GENERATE_TREEVIEW) then this tag can be -# used to set the initial width (in pixels) of the frame in which the tree -# is shown. - -TREEVIEW_WIDTH = 250 - -# Use this tag to change the font size of Latex formulas included -# as images in the HTML documentation. The default is 10. Note that -# when you change the font size after a successful doxygen run you need -# to manually remove any form_*.png images from the HTML output directory -# to force them to be regenerated. - -FORMULA_FONTSIZE = 10 - -# When the SEARCHENGINE tag is enabled doxygen will generate a search box -# for the HTML output. The underlying search engine uses javascript -# and DHTML and should work on any modern browser. Note that when using -# HTML help (GENERATE_HTMLHELP), Qt help (GENERATE_QHP), or docsets -# (GENERATE_DOCSET) there is already a search function so this one should -# typically be disabled. For large projects the javascript based search engine -# can be slow, then enabling SERVER_BASED_SEARCH may provide a better solution. - -SEARCHENGINE = NO - -# When the SERVER_BASED_SEARCH tag is enabled the search engine will be -# implemented using a PHP enabled web server instead of at the web client -# using Javascript. Doxygen will generate the search PHP script and index -# file to put on the web server. The advantage of the server -# based approach is that it scales better to large projects and allows -# full text search. The disadvances is that it is more difficult to setup -# and does not have live searching capabilities. - -SERVER_BASED_SEARCH = NO - -#--------------------------------------------------------------------------- -# configuration options related to the LaTeX output -#--------------------------------------------------------------------------- - -# If the GENERATE_LATEX tag is set to YES (the default) Doxygen will -# generate Latex output. - -GENERATE_LATEX = NO - -# The LATEX_OUTPUT tag is used to specify where the LaTeX docs will be put. -# If a relative path is entered the value of OUTPUT_DIRECTORY will be -# put in front of it. If left blank `latex' will be used as the default path. - -LATEX_OUTPUT = latex - -# The LATEX_CMD_NAME tag can be used to specify the LaTeX command name to be -# invoked. If left blank `latex' will be used as the default command name. -# Note that when enabling USE_PDFLATEX this option is only used for -# generating bitmaps for formulas in the HTML output, but not in the -# Makefile that is written to the output directory. - -LATEX_CMD_NAME = latex - -# The MAKEINDEX_CMD_NAME tag can be used to specify the command name to -# generate index for LaTeX. If left blank `makeindex' will be used as the -# default command name. - -MAKEINDEX_CMD_NAME = makeindex - -# If the COMPACT_LATEX tag is set to YES Doxygen generates more compact -# LaTeX documents. This may be useful for small projects and may help to -# save some trees in general. - -COMPACT_LATEX = NO - -# The PAPER_TYPE tag can be used to set the paper type that is used -# by the printer. Possible values are: a4, a4wide, letter, legal and -# executive. If left blank a4wide will be used. - -PAPER_TYPE = a4wide - -# The EXTRA_PACKAGES tag can be to specify one or more names of LaTeX -# packages that should be included in the LaTeX output. - -EXTRA_PACKAGES = - -# The LATEX_HEADER tag can be used to specify a personal LaTeX header for -# the generated latex document. The header should contain everything until -# the first chapter. If it is left blank doxygen will generate a -# standard header. Notice: only use this tag if you know what you are doing! - -LATEX_HEADER = - -# If the PDF_HYPERLINKS tag is set to YES, the LaTeX that is generated -# is prepared for conversion to pdf (using ps2pdf). The pdf file will -# contain links (just like the HTML output) instead of page references -# This makes the output suitable for online browsing using a pdf viewer. - -PDF_HYPERLINKS = YES - -# If the USE_PDFLATEX tag is set to YES, pdflatex will be used instead of -# plain latex in the generated Makefile. Set this option to YES to get a -# higher quality PDF documentation. - -USE_PDFLATEX = YES - -# If the LATEX_BATCHMODE tag is set to YES, doxygen will add the \\batchmode. -# command to the generated LaTeX files. This will instruct LaTeX to keep -# running if errors occur, instead of asking the user for help. -# This option is also used when generating formulas in HTML. - -LATEX_BATCHMODE = NO - -# If LATEX_HIDE_INDICES is set to YES then doxygen will not -# include the index chapters (such as File Index, Compound Index, etc.) -# in the output. - -LATEX_HIDE_INDICES = NO - -# If LATEX_SOURCE_CODE is set to YES then doxygen will include -# source code with syntax highlighting in the LaTeX output. -# Note that which sources are shown also depends on other settings -# such as SOURCE_BROWSER. - -LATEX_SOURCE_CODE = NO - -#--------------------------------------------------------------------------- -# configuration options related to the RTF output -#--------------------------------------------------------------------------- - -# If the GENERATE_RTF tag is set to YES Doxygen will generate RTF output -# The RTF output is optimized for Word 97 and may not look very pretty with -# other RTF readers or editors. - -GENERATE_RTF = NO - -# The RTF_OUTPUT tag is used to specify where the RTF docs will be put. -# If a relative path is entered the value of OUTPUT_DIRECTORY will be -# put in front of it. If left blank `rtf' will be used as the default path. - -RTF_OUTPUT = rtf - -# If the COMPACT_RTF tag is set to YES Doxygen generates more compact -# RTF documents. This may be useful for small projects and may help to -# save some trees in general. - -COMPACT_RTF = NO - -# If the RTF_HYPERLINKS tag is set to YES, the RTF that is generated -# will contain hyperlink fields. The RTF file will -# contain links (just like the HTML output) instead of page references. -# This makes the output suitable for online browsing using WORD or other -# programs which support those fields. -# Note: wordpad (write) and others do not support links. - -RTF_HYPERLINKS = NO - -# Load stylesheet definitions from file. Syntax is similar to doxygen's -# config file, i.e. a series of assignments. You only have to provide -# replacements, missing definitions are set to their default value. - -RTF_STYLESHEET_FILE = - -# Set optional variables used in the generation of an rtf document. -# Syntax is similar to doxygen's config file. - -RTF_EXTENSIONS_FILE = - -#--------------------------------------------------------------------------- -# configuration options related to the man page output -#--------------------------------------------------------------------------- - -# If the GENERATE_MAN tag is set to YES (the default) Doxygen will -# generate man pages - -GENERATE_MAN = NO - -# The MAN_OUTPUT tag is used to specify where the man pages will be put. -# If a relative path is entered the value of OUTPUT_DIRECTORY will be -# put in front of it. If left blank `man' will be used as the default path. - -MAN_OUTPUT = man - -# The MAN_EXTENSION tag determines the extension that is added to -# the generated man pages (default is the subroutine's section .3) - -MAN_EXTENSION = .3 - -# If the MAN_LINKS tag is set to YES and Doxygen generates man output, -# then it will generate one additional man file for each entity -# documented in the real man page(s). These additional files -# only source the real man page, but without them the man command -# would be unable to find the correct page. The default is NO. - -MAN_LINKS = NO - -#--------------------------------------------------------------------------- -# configuration options related to the XML output -#--------------------------------------------------------------------------- - -# If the GENERATE_XML tag is set to YES Doxygen will -# generate an XML file that captures the structure of -# the code including all documentation. - -GENERATE_XML = YES - -# The XML_OUTPUT tag is used to specify where the XML pages will be put. -# If a relative path is entered the value of OUTPUT_DIRECTORY will be -# put in front of it. If left blank `xml' will be used as the default path. - -XML_OUTPUT = xml - -# The XML_SCHEMA tag can be used to specify an XML schema, -# which can be used by a validating XML parser to check the -# syntax of the XML files. - -XML_SCHEMA = - -# The XML_DTD tag can be used to specify an XML DTD, -# which can be used by a validating XML parser to check the -# syntax of the XML files. - -XML_DTD = - -# If the XML_PROGRAMLISTING tag is set to YES Doxygen will -# dump the program listings (including syntax highlighting -# and cross-referencing information) to the XML output. Note that -# enabling this will significantly increase the size of the XML output. - -XML_PROGRAMLISTING = YES - -#--------------------------------------------------------------------------- -# configuration options for the AutoGen Definitions output -#--------------------------------------------------------------------------- - -# If the GENERATE_AUTOGEN_DEF tag is set to YES Doxygen will -# generate an AutoGen Definitions (see autogen.sf.net) file -# that captures the structure of the code including all -# documentation. Note that this feature is still experimental -# and incomplete at the moment. - -GENERATE_AUTOGEN_DEF = NO - -#--------------------------------------------------------------------------- -# configuration options related to the Perl module output -#--------------------------------------------------------------------------- - -# If the GENERATE_PERLMOD tag is set to YES Doxygen will -# generate a Perl module file that captures the structure of -# the code including all documentation. Note that this -# feature is still experimental and incomplete at the -# moment. - -GENERATE_PERLMOD = NO - -# If the PERLMOD_LATEX tag is set to YES Doxygen will generate -# the necessary Makefile rules, Perl scripts and LaTeX code to be able -# to generate PDF and DVI output from the Perl module output. - -PERLMOD_LATEX = NO - -# If the PERLMOD_PRETTY tag is set to YES the Perl module output will be -# nicely formatted so it can be parsed by a human reader. This is useful -# if you want to understand what is going on. On the other hand, if this -# tag is set to NO the size of the Perl module output will be much smaller -# and Perl will parse it just the same. - -PERLMOD_PRETTY = YES - -# The names of the make variables in the generated doxyrules.make file -# are prefixed with the string contained in PERLMOD_MAKEVAR_PREFIX. -# This is useful so different doxyrules.make files included by the same -# Makefile don't overwrite each other's variables. - -PERLMOD_MAKEVAR_PREFIX = - -#--------------------------------------------------------------------------- -# Configuration options related to the preprocessor -#--------------------------------------------------------------------------- - -# If the ENABLE_PREPROCESSING tag is set to YES (the default) Doxygen will -# evaluate all C-preprocessor directives found in the sources and include -# files. - -ENABLE_PREPROCESSING = YES - -# If the MACRO_EXPANSION tag is set to YES Doxygen will expand all macro -# names in the source code. If set to NO (the default) only conditional -# compilation will be performed. Macro expansion can be done in a controlled -# way by setting EXPAND_ONLY_PREDEF to YES. - -MACRO_EXPANSION = NO - -# If the EXPAND_ONLY_PREDEF and MACRO_EXPANSION tags are both set to YES -# then the macro expansion is limited to the macros specified with the -# PREDEFINED and EXPAND_AS_DEFINED tags. - -EXPAND_ONLY_PREDEF = NO - -# If the SEARCH_INCLUDES tag is set to YES (the default) the includes files -# in the INCLUDE_PATH (see below) will be search if a #include is found. - -SEARCH_INCLUDES = YES - -# The INCLUDE_PATH tag can be used to specify one or more directories that -# contain include files that are not input files but should be processed by -# the preprocessor. - -INCLUDE_PATH = - -# You can use the INCLUDE_FILE_PATTERNS tag to specify one or more wildcard -# patterns (like *.h and *.hpp) to filter out the header-files in the -# directories. If left blank, the patterns specified with FILE_PATTERNS will -# be used. - -INCLUDE_FILE_PATTERNS = - -# The PREDEFINED tag can be used to specify one or more macro names that -# are defined before the preprocessor is started (similar to the -D option of -# gcc). The argument of the tag is a list of macros of the form: name -# or name=definition (no spaces). If the definition and the = are -# omitted =1 is assumed. To prevent a macro definition from being -# undefined via #undef or recursively expanded use the := operator -# instead of the = operator. - -PREDEFINED = __APPLE__ - -# If the MACRO_EXPANSION and EXPAND_ONLY_PREDEF tags are set to YES then -# this tag can be used to specify a list of macro names that should be expanded. -# The macro definition that is found in the sources will be used. -# Use the PREDEFINED tag if you want to use a different macro definition. - -EXPAND_AS_DEFINED = - -# If the SKIP_FUNCTION_MACROS tag is set to YES (the default) then -# doxygen's preprocessor will remove all function-like macros that are alone -# on a line, have an all uppercase name, and do not end with a semicolon. Such -# function macros are typically used for boiler-plate code, and will confuse -# the parser if not removed. - -SKIP_FUNCTION_MACROS = YES - -#--------------------------------------------------------------------------- -# Configuration::additions related to external references -#--------------------------------------------------------------------------- - -# The TAGFILES option can be used to specify one or more tagfiles. -# Optionally an initial location of the external documentation -# can be added for each tagfile. The format of a tag file without -# this location is as follows: -# TAGFILES = file1 file2 ... -# Adding location for the tag files is done as follows: -# TAGFILES = file1=loc1 "file2 = loc2" ... -# where "loc1" and "loc2" can be relative or absolute paths or -# URLs. If a location is present for each tag, the installdox tool -# does not have to be run to correct the links. -# Note that each tag file must have a unique name -# (where the name does NOT include the path) -# If a tag file is not located in the directory in which doxygen -# is run, you must also specify the path to the tagfile here. - -TAGFILES = - -# When a file name is specified after GENERATE_TAGFILE, doxygen will create -# a tag file that is based on the input files it reads. - -GENERATE_TAGFILE = - -# If the ALLEXTERNALS tag is set to YES all external classes will be listed -# in the class index. If set to NO only the inherited external classes -# will be listed. - -ALLEXTERNALS = NO - -# If the EXTERNAL_GROUPS tag is set to YES all external groups will be listed -# in the modules index. If set to NO, only the current project's groups will -# be listed. - -EXTERNAL_GROUPS = YES - -# The PERL_PATH should be the absolute path and name of the perl script -# interpreter (i.e. the result of `which perl'). - -PERL_PATH = /usr/bin/perl - -#--------------------------------------------------------------------------- -# Configuration options related to the dot tool -#--------------------------------------------------------------------------- - -# If the CLASS_DIAGRAMS tag is set to YES (the default) Doxygen will -# generate a inheritance diagram (in HTML, RTF and LaTeX) for classes with base -# or super classes. Setting the tag to NO turns the diagrams off. Note that -# this option is superseded by the HAVE_DOT option below. This is only a -# fallback. It is recommended to install and use dot, since it yields more -# powerful graphs. - -CLASS_DIAGRAMS = NO - -# You can define message sequence charts within doxygen comments using the \msc -# command. Doxygen will then run the mscgen tool (see -# http://www.mcternan.me.uk/mscgen/) to produce the chart and insert it in the -# documentation. The MSCGEN_PATH tag allows you to specify the directory where -# the mscgen tool resides. If left empty the tool is assumed to be found in the -# default search path. - -MSCGEN_PATH = /Applications/Doxygen.app/Contents/Resources/ - -# If set to YES, the inheritance and collaboration graphs will hide -# inheritance and usage relations if the target is undocumented -# or is not a class. - -HIDE_UNDOC_RELATIONS = YES - -# If you set the HAVE_DOT tag to YES then doxygen will assume the dot tool is -# available from the path. This tool is part of Graphviz, a graph visualization -# toolkit from AT&T and Lucent Bell Labs. The other options in this section -# have no effect if this option is set to NO (the default) - -HAVE_DOT = YES - -# By default doxygen will write a font called FreeSans.ttf to the output -# directory and reference it in all dot files that doxygen generates. This -# font does not include all possible unicode characters however, so when you need -# these (or just want a differently looking font) you can specify the font name -# using DOT_FONTNAME. You need need to make sure dot is able to find the font, -# which can be done by putting it in a standard location or by setting the -# DOTFONTPATH environment variable or by setting DOT_FONTPATH to the directory -# containing the font. - -DOT_FONTNAME = FreeSans - -# The DOT_FONTSIZE tag can be used to set the size of the font of dot graphs. -# The default size is 10pt. - -DOT_FONTSIZE = 10 - -# By default doxygen will tell dot to use the output directory to look for the -# FreeSans.ttf font (which doxygen will put there itself). If you specify a -# different font using DOT_FONTNAME you can set the path where dot -# can find it using this tag. - -DOT_FONTPATH = - -# If the CLASS_GRAPH and HAVE_DOT tags are set to YES then doxygen -# will generate a graph for each documented class showing the direct and -# indirect inheritance relations. Setting this tag to YES will force the -# the CLASS_DIAGRAMS tag to NO. - -CLASS_GRAPH = YES - -# If the COLLABORATION_GRAPH and HAVE_DOT tags are set to YES then doxygen -# will generate a graph for each documented class showing the direct and -# indirect implementation dependencies (inheritance, containment, and -# class references variables) of the class with other documented classes. - -COLLABORATION_GRAPH = YES - -# If the GROUP_GRAPHS and HAVE_DOT tags are set to YES then doxygen -# will generate a graph for groups, showing the direct groups dependencies - -GROUP_GRAPHS = YES - -# If the UML_LOOK tag is set to YES doxygen will generate inheritance and -# collaboration diagrams in a style similar to the OMG's Unified Modeling -# Language. - -UML_LOOK = NO - -# If set to YES, the inheritance and collaboration graphs will show the -# relations between templates and their instances. - -TEMPLATE_RELATIONS = NO - -# If the ENABLE_PREPROCESSING, SEARCH_INCLUDES, INCLUDE_GRAPH, and HAVE_DOT -# tags are set to YES then doxygen will generate a graph for each documented -# file showing the direct and indirect include dependencies of the file with -# other documented files. - -INCLUDE_GRAPH = YES - -# If the ENABLE_PREPROCESSING, SEARCH_INCLUDES, INCLUDED_BY_GRAPH, and -# HAVE_DOT tags are set to YES then doxygen will generate a graph for each -# documented header file showing the documented files that directly or -# indirectly include this file. - -INCLUDED_BY_GRAPH = YES - -# If the CALL_GRAPH and HAVE_DOT options are set to YES then -# doxygen will generate a call dependency graph for every global function -# or class method. Note that enabling this option will significantly increase -# the time of a run. So in most cases it will be better to enable call graphs -# for selected functions only using the \callgraph command. - -CALL_GRAPH = YES - -# If the CALLER_GRAPH and HAVE_DOT tags are set to YES then -# doxygen will generate a caller dependency graph for every global function -# or class method. Note that enabling this option will significantly increase -# the time of a run. So in most cases it will be better to enable caller -# graphs for selected functions only using the \callergraph command. - -CALLER_GRAPH = NO - -# If the GRAPHICAL_HIERARCHY and HAVE_DOT tags are set to YES then doxygen -# will graphical hierarchy of all classes instead of a textual one. - -GRAPHICAL_HIERARCHY = YES - -# If the DIRECTORY_GRAPH, SHOW_DIRECTORIES and HAVE_DOT tags are set to YES -# then doxygen will show the dependencies a directory has on other directories -# in a graphical way. The dependency relations are determined by the #include -# relations between the files in the directories. - -DIRECTORY_GRAPH = YES - -# The DOT_IMAGE_FORMAT tag can be used to set the image format of the images -# generated by dot. Possible values are png, jpg, or gif -# If left blank png will be used. - -DOT_IMAGE_FORMAT = png - -# The tag DOT_PATH can be used to specify the path where the dot tool can be -# found. If left blank, it is assumed the dot tool can be found in the path. - -DOT_PATH = /Applications/Doxygen.app/Contents/Resources/ - -# The DOTFILE_DIRS tag can be used to specify one or more directories that -# contain dot files that are included in the documentation (see the -# \dotfile command). - -DOTFILE_DIRS = - -# The DOT_GRAPH_MAX_NODES tag can be used to set the maximum number of -# nodes that will be shown in the graph. If the number of nodes in a graph -# becomes larger than this value, doxygen will truncate the graph, which is -# visualized by representing a node as a red box. Note that doxygen if the -# number of direct children of the root node in a graph is already larger than -# DOT_GRAPH_MAX_NODES then the graph will not be shown at all. Also note -# that the size of a graph can be further restricted by MAX_DOT_GRAPH_DEPTH. - -DOT_GRAPH_MAX_NODES = 50 - -# The MAX_DOT_GRAPH_DEPTH tag can be used to set the maximum depth of the -# graphs generated by dot. A depth value of 3 means that only nodes reachable -# from the root by following a path via at most 3 edges will be shown. Nodes -# that lay further from the root node will be omitted. Note that setting this -# option to 1 or 2 may greatly reduce the computation time needed for large -# code bases. Also note that the size of a graph can be further restricted by -# DOT_GRAPH_MAX_NODES. Using a depth of 0 means no depth restriction. - -MAX_DOT_GRAPH_DEPTH = 1000 - -# Set the DOT_TRANSPARENT tag to YES to generate images with a transparent -# background. This is disabled by default, because dot on Windows does not -# seem to support this out of the box. Warning: Depending on the platform used, -# enabling this option may lead to badly anti-aliased labels on the edges of -# a graph (i.e. they become hard to read). - -DOT_TRANSPARENT = NO - -# Set the DOT_MULTI_TARGETS tag to YES allow dot to generate multiple output -# files in one run (i.e. multiple -o and -T options on the command line). This -# makes dot run faster, but since only newer versions of dot (>1.8.10) -# support this, this feature is disabled by default. - -DOT_MULTI_TARGETS = NO - -# If the GENERATE_LEGEND tag is set to YES (the default) Doxygen will -# generate a legend page explaining the meaning of the various boxes and -# arrows in the dot generated graphs. - -GENERATE_LEGEND = YES - -# If the DOT_CLEANUP tag is set to YES (the default) Doxygen will -# remove the intermediate dot files that are used to generate -# the various graphs. - -DOT_CLEANUP = YES diff --git a/tikzit/draw-ellipse.png b/tikzit/draw-ellipse.png Binary files differdeleted file mode 100644 index d8e3e6f..0000000 --- a/tikzit/draw-ellipse.png +++ /dev/null diff --git a/tikzit/draw-path.png b/tikzit/draw-path.png Binary files differdeleted file mode 100644 index ec5e691..0000000 --- a/tikzit/draw-path.png +++ /dev/null diff --git a/tikzit/emblem-important.png b/tikzit/emblem-important.png Binary files differdeleted file mode 100644 index 81e9ed2..0000000 --- a/tikzit/emblem-important.png +++ /dev/null diff --git a/tikzit/emblem-unreadable-grey.png b/tikzit/emblem-unreadable-grey.png Binary files differdeleted file mode 100644 index 09572ab..0000000 --- a/tikzit/emblem-unreadable-grey.png +++ /dev/null diff --git a/tikzit/format-indent-less.png b/tikzit/format-indent-less.png Binary files differdeleted file mode 100644 index 7ced16f..0000000 --- a/tikzit/format-indent-less.png +++ /dev/null diff --git a/tikzit/m4/objc.m4 b/tikzit/m4/objc.m4 deleted file mode 100644 index 8c7cc78..0000000 --- a/tikzit/m4/objc.m4 +++ /dev/null @@ -1,135 +0,0 @@ -# Checks for a working Foundation -# tz_cv_objc_foundation -# to either "yes" or "no" -# -AC_DEFUN([TZ_OBJC_FOUNDATION], -[ -AC_LANG_ASSERT([Objective C]) -tz_old_objcflags="$OBJCFLAGS" -OBJCFLAGS="$OBJCFLAGS $TZ_TEST_OBJCFLAGS" - -AC_CACHE_CHECK([for Objective C Foundation], - [tz_cv_objc_foundation], -[AC_COMPILE_IFELSE( - [AC_LANG_SOURCE([[ -#import <Foundation/Foundation.h> - -@interface TestObj : NSObject { - int intVar; - NSObject *objVar; - NSString *strVar; -} --(id)init; -@end - -@implementation TestObj --(id)init { - self = [super init]; - intVar = 0; - objVar = nil; - strVar = @"Foo"; - return self; -} -@end - -int main(void) { - TestObj *obj = [[TestObj alloc] init]; - [obj release]; - return 0; -} - ]])], - [tz_cv_objc_foundation=yes], - [tz_cv_objc_foundation=no])]) - -OBJCFLAGS="$tz_old_objcflags" -]) - - -# Checks for Objective C 2 feature support -# and sets the shell variables -# tz_cv_objc_properties -# tz_cv_objc_fast_enumeration -# tz_cv_objc_optional_keyword -# to either "yes" or "no" -# -AC_DEFUN([TZ_OBJC2_FEATURES], -[ -AC_LANG_ASSERT([Objective C]) -tz_old_objcflags="$OBJCFLAGS" -OBJCFLAGS="$OBJCFLAGS $TZ_TEST_OBJCFLAGS" - -AC_CACHE_CHECK([for Objective C 2 @property support], - [tz_cv_objc_properties], -[AC_COMPILE_IFELSE( - [AC_LANG_SOURCE([[ -#import <Foundation/Foundation.h> - -@interface TestObj : NSObject { - int intProp1; - NSObject *copyObjProp; - NSObject *fooProp; -} -@property (assign,nonatomic) int intProp; -@property (retain,readonly) NSObject *retainObjProp; -@property (copy,readwrite) NSObject *copyObjProp; -@property (retain,getter=foo,setter=foo1:) NSObject *fooProp; -@end - -@implementation TestObj -@synthesize intProp=intProp1; -@dynamic retainObjProp; -- (NSObject*) retainObjProp { return nil; } -@synthesize copyObjProp; -@synthesize fooProp; -@end - -int main(void) { - TestObj *obj = [[TestObj alloc] init]; - obj.intProp = 4; - NSObject *result = obj.retainObjProp; - return 0; -} - ]])], - [tz_cv_objc_properties=yes], - [tz_cv_objc_properties=no])]) - - -AC_CACHE_CHECK([for Objective C 2 fast enumeration support], - [tz_cv_objc_fast_enumeration], -[AC_COMPILE_IFELSE( - [AC_LANG_SOURCE([[ -#import <Foundation/Foundation.h> - -int main(void) { - NSArray *array = [NSArray arrayWithObjects: @"One", @"Two", @"Three", @"Four", nil]; - for (NSString *element in array) { - NSLog(@"element: %@", element); - } - return 0; -} - ]])], - [tz_cv_objc_fast_enumeration=yes], - [tz_cv_objc_fast_enumeration=no])]) - -AC_CACHE_CHECK([for Objective C 2 @optional support], - [tz_cv_objc_optional_keyword], -[AC_COMPILE_IFELSE( - [AC_LANG_SOURCE([[ -#import <Foundation/Foundation.h> - -@protocol Foo -@optional -- (void) foo; -@required -- (void) bar; -@end - -int main(void) { - return 0; -} - ]])], - [tz_cv_objc_optional_keyword=yes], - [tz_cv_objc_optional_keyword=no])]) - -OBJCFLAGS="$tz_old_objcflags" -]) diff --git a/tikzit/scripts/generate_keys.rb b/tikzit/scripts/generate_keys.rb deleted file mode 100755 index b22439c..0000000 --- a/tikzit/scripts/generate_keys.rb +++ /dev/null @@ -1,13 +0,0 @@ -#!/usr/bin/ruby -["dsaparam.pem", "dsa_priv.pem", "dsa_pub.pem"].each do |file| - if File.exist? file - puts "There's already a #{file} here! Move it aside or be more careful!" - end -end -`openssl dsaparam 2048 < /dev/urandom > dsaparam.pem` -`openssl gendsa dsaparam.pem -out dsa_priv.pem` -`openssl dsa -in dsa_priv.pem -pubout -out dsa_pub.pem` -`rm dsaparam.pem` -puts "\nGenerated private and public keys: dsa_priv.pem and dsa_pub.pem.\n -BACK UP YOUR PRIVATE KEY AND KEEP IT SAFE!\n -If you lose it, your users will be unable to upgrade!\n"
\ No newline at end of file diff --git a/tikzit/scripts/prepare_release.sh b/tikzit/scripts/prepare_release.sh deleted file mode 100755 index 5f5edfc..0000000 --- a/tikzit/scripts/prepare_release.sh +++ /dev/null @@ -1,40 +0,0 @@ -set -o errexit - -PROJECT_NAME=TikZiT -APP_BUNDLE=xbuild/Release/$PROJECT_NAME.app - -VERSION=$(defaults read "$(pwd)/$APP_BUNDLE/Contents/Info" CFBundleVersion) -DOWNLOAD_BASE_URL="http://tikzit.sourceforge.net/appcast" -RELEASENOTES_URL="$DOWNLOAD_BASE_URL/rnotes.html" - -ARCHIVE_FILENAME="$PROJECT_NAME $VERSION.tar.bz2" -ARCHIVE_PATH="../www/htdocs/appcast/files/$ARCHIVE_FILENAME" -DOWNLOAD_URL="$DOWNLOAD_BASE_URL/files/$ARCHIVE_FILENAME" - -if [ -e "$ARCHIVE_PATH" ]; then - echo 'Archive already exists. Either remove this archive or increment version.' - exit 1 -fi - -tar cjf "$ARCHIVE_PATH" "$APP_BUNDLE" - -SIZE=$(stat -f %z "$ARCHIVE_PATH") -PUBDATE=$(LC_TIME=en_US date +"%a, %d %b %G %T %z") -SIGNATURE=$(scripts/sign_update.rb "$ARCHIVE_PATH" tikzit_dsa_priv.pem) - -cat <<EOF - <item> - <title>Version $VERSION</title> - <sparkle:releaseNotesLink> - $RELEASENOTES_URL - </sparkle:releaseNotesLink> - <pubDate>$PUBDATE</pubDate> - <enclosure - url="$DOWNLOAD_URL" - sparkle:version="$VERSION" - type="application/octet-stream" - length="$SIZE" - sparkle:dsaSignature="$SIGNATURE" - /> - </item> -EOF diff --git a/tikzit/scripts/sign_update.rb b/tikzit/scripts/sign_update.rb deleted file mode 100755 index 6d03e2e..0000000 --- a/tikzit/scripts/sign_update.rb +++ /dev/null @@ -1,7 +0,0 @@ -#!/usr/bin/ruby -if ARGV.length < 2 - puts "Usage: ruby sign_update.rb update_archive private_key" - exit -end - -puts `openssl dgst -sha1 -binary < "#{ARGV[0]}" | openssl dgst -dss1 -sign "#{ARGV[1]}" | openssl enc -base64`
\ No newline at end of file diff --git a/tikzit/select-rectangular.png b/tikzit/select-rectangular.png Binary files differdeleted file mode 100644 index 866b602..0000000 --- a/tikzit/select-rectangular.png +++ /dev/null diff --git a/tikzit/shapes/cap.tikz b/tikzit/shapes/cap.tikz deleted file mode 100644 index a98ff39..0000000 --- a/tikzit/shapes/cap.tikz +++ /dev/null @@ -1,13 +0,0 @@ -\begin{tikzpicture} - \path [use as bounding box] (-2,-2) rectangle (2,2); - \begin{pgfonlayer}{nodelayer} - \node [style=none] (0) at (0, 0.75) {}; - \node [style=none] (1) at (-0.5, 0) {}; - \node [style=none] (2) at (0.5, 0) {}; - \end{pgfonlayer} - \begin{pgfonlayer}{edgelayer} - \draw [in=0, out=90] (2.center) to (0.center); - \draw [in=270, out=-90, looseness=0.75] (1.center) to (2.center); - \draw [in=90, out=180] (0.center) to (1.center); - \end{pgfonlayer} -\end{tikzpicture}
\ No newline at end of file diff --git a/tikzit/shapes/copants.tikz b/tikzit/shapes/copants.tikz deleted file mode 100644 index d2b8e3c..0000000 --- a/tikzit/shapes/copants.tikz +++ /dev/null @@ -1,19 +0,0 @@ -\begin{tikzpicture} - \path [use as bounding box] (-2,-2) rectangle (2,2); - \begin{pgfonlayer}{nodelayer} - \node [style=none] (0) at (-1.5, 1) {}; - \node [style=none] (1) at (-0.5, 1) {}; - \node [style=none] (2) at (0.5, 1) {}; - \node [style=none] (3) at (1.5, 1) {}; - \node [style=none] (4) at (-0.5, -1) {}; - \node [style=none] (5) at (0.5, -1) {}; - \end{pgfonlayer} - \begin{pgfonlayer}{edgelayer} - \draw [in=-90, out=90, looseness=0.75] (5.center) to (3.center); - \draw [in=90, out=90, looseness=0.75] (4.center) to (5.center); - \draw [in=270, out=-90, looseness=0.75] (1.center) to (0.center); - \draw [in=270, out=-90, looseness=0.75] (3.center) to (2.center); - \draw [in=-270, out=-90, looseness=0.75] (0.center) to (4.center); - \draw [in=-90, out=-90, looseness=1.75] (2.center) to (1.center); - \end{pgfonlayer} -\end{tikzpicture}
\ No newline at end of file diff --git a/tikzit/shapes/cup.tikz b/tikzit/shapes/cup.tikz deleted file mode 100644 index 1dc1faa..0000000 --- a/tikzit/shapes/cup.tikz +++ /dev/null @@ -1,13 +0,0 @@ -\begin{tikzpicture} - \path [use as bounding box] (-2,-2) rectangle (2,2); - \begin{pgfonlayer}{nodelayer} - \node [style=none] (0) at (-0.5, 0) {}; - \node [style=none] (1) at (0.5, 0) {}; - \node [style=none] (2) at (0, -0.75) {}; - \end{pgfonlayer} - \begin{pgfonlayer}{edgelayer} - \draw [in=0, out=-90] (1.center) to (2.center); - \draw [in=-270, out=90, looseness=0.75] (0.center) to (1.center); - \draw [in=-90, out=-180] (2.center) to (0.center); - \end{pgfonlayer} -\end{tikzpicture}
\ No newline at end of file diff --git a/tikzit/shapes/oval.tikz b/tikzit/shapes/oval.tikz deleted file mode 100644 index b5d2891..0000000 --- a/tikzit/shapes/oval.tikz +++ /dev/null @@ -1,11 +0,0 @@ -\begin{tikzpicture} - \path [use as bounding box] (-2,-2) rectangle (2,2); - \begin{pgfonlayer}{nodelayer} - \node [style=none] (0) at (-0.5, 0) {}; - \node [style=none] (1) at (0.5, 0) {}; - \end{pgfonlayer} - \begin{pgfonlayer}{edgelayer} - \draw [in=90, out=90, looseness=0.75] (0.center) to (1.center); - \draw [in=-90, out=270, looseness=0.75] (1.center) to (0.center); - \end{pgfonlayer} -\end{tikzpicture}
\ No newline at end of file diff --git a/tikzit/shapes/pants.tikz b/tikzit/shapes/pants.tikz deleted file mode 100644 index c2c15c2..0000000 --- a/tikzit/shapes/pants.tikz +++ /dev/null @@ -1,19 +0,0 @@ -\begin{tikzpicture} - \path [use as bounding box] (-2,-2) rectangle (2,2); - \begin{pgfonlayer}{nodelayer} - \node [style=none] (0) at (-0.5, 1) {}; - \node [style=none] (1) at (0.5, 1) {}; - \node [style=none] (2) at (-1.5, -1) {}; - \node [style=none] (3) at (-0.5, -1) {}; - \node [style=none] (4) at (0.5, -1) {}; - \node [style=none] (5) at (1.5, -1) {}; - \end{pgfonlayer} - \begin{pgfonlayer}{edgelayer} - \draw [in=90, out=90, looseness=1.75] (4.center) to (3.center); - \draw [in=270, out=90, looseness=0.75] (2.center) to (0.center); - \draw [in=-90, out=-90, looseness=0.75] (0.center) to (1.center); - \draw [in=90, out=-90, looseness=0.75] (1.center) to (5.center); - \draw [in=-270, out=90, looseness=0.75] (5.center) to (4.center); - \draw [in=-270, out=90, looseness=0.75] (3.center) to (2.center); - \end{pgfonlayer} -\end{tikzpicture}
\ No newline at end of file diff --git a/tikzit/share/Makefile.am b/tikzit/share/Makefile.am deleted file mode 100644 index d3b6a9d..0000000 --- a/tikzit/share/Makefile.am +++ /dev/null @@ -1,9 +0,0 @@ -if WINDOWS -else -sharedir = $(datarootdir) -nobase_dist_share_DATA = \ - applications/tikzit.desktop \ - icons/hicolor/*/apps/*.png \ - icons/hicolor/scalable/apps/*.svg -endif - diff --git a/tikzit/share/applications/tikzit.desktop b/tikzit/share/applications/tikzit.desktop deleted file mode 100644 index d1fb908..0000000 --- a/tikzit/share/applications/tikzit.desktop +++ /dev/null @@ -1,10 +0,0 @@ -[Desktop Entry] -Version=1.0 -Type=Application -Name=TikZit -Comment=TeX pgf/TikZ graph editor -GenericName=TikZ Graph Editor -Exec=tikzit -Icon=tikzit -Categories=GTK;Graphics;Education;Science; -StartupNotify=false diff --git a/tikzit/share/icons/hicolor/128x128/apps/tikzit.png b/tikzit/share/icons/hicolor/128x128/apps/tikzit.png Binary files differdeleted file mode 100644 index 51d0151..0000000 --- a/tikzit/share/icons/hicolor/128x128/apps/tikzit.png +++ /dev/null diff --git a/tikzit/share/icons/hicolor/16x16/apps/tikzit.png b/tikzit/share/icons/hicolor/16x16/apps/tikzit.png Binary files differdeleted file mode 100644 index 269ff1c..0000000 --- a/tikzit/share/icons/hicolor/16x16/apps/tikzit.png +++ /dev/null diff --git a/tikzit/share/icons/hicolor/22x22/apps/tikzit.png b/tikzit/share/icons/hicolor/22x22/apps/tikzit.png Binary files differdeleted file mode 100644 index 18ab7c3..0000000 --- a/tikzit/share/icons/hicolor/22x22/apps/tikzit.png +++ /dev/null diff --git a/tikzit/share/icons/hicolor/24x24/apps/tikzit.png b/tikzit/share/icons/hicolor/24x24/apps/tikzit.png Binary files differdeleted file mode 100644 index e8d0c7e..0000000 --- a/tikzit/share/icons/hicolor/24x24/apps/tikzit.png +++ /dev/null diff --git a/tikzit/share/icons/hicolor/32x32/apps/tikzit.png b/tikzit/share/icons/hicolor/32x32/apps/tikzit.png Binary files differdeleted file mode 100644 index 66008b7..0000000 --- a/tikzit/share/icons/hicolor/32x32/apps/tikzit.png +++ /dev/null diff --git a/tikzit/share/icons/hicolor/48x48/apps/tikzit.png b/tikzit/share/icons/hicolor/48x48/apps/tikzit.png Binary files differdeleted file mode 100644 index a54f13a..0000000 --- a/tikzit/share/icons/hicolor/48x48/apps/tikzit.png +++ /dev/null diff --git a/tikzit/share/icons/hicolor/64x64/apps/tikzit.png b/tikzit/share/icons/hicolor/64x64/apps/tikzit.png Binary files differdeleted file mode 100644 index 7f2580d..0000000 --- a/tikzit/share/icons/hicolor/64x64/apps/tikzit.png +++ /dev/null diff --git a/tikzit/share/icons/hicolor/scalable/apps/tikzit.svg b/tikzit/share/icons/hicolor/scalable/apps/tikzit.svg deleted file mode 100644 index bd103ca..0000000 --- a/tikzit/share/icons/hicolor/scalable/apps/tikzit.svg +++ /dev/null @@ -1,138 +0,0 @@ -<?xml version="1.0" encoding="UTF-8" standalone="no"?> -<!-- Created with Inkscape (http://www.inkscape.org/) --> - -<svg - xmlns:svg="http://www.w3.org/2000/svg" - xmlns="http://www.w3.org/2000/svg" - xmlns:xlink="http://www.w3.org/1999/xlink" - version="1.1" - width="640" - height="640" - id="svg2837" - xml:space="preserve"><defs - id="defs2841"><linearGradient - x1="0" - y1="0" - x2="1" - y2="0" - id="linearGradient33921" - gradientUnits="userSpaceOnUse" - gradientTransform="matrix(-1.53e-5,-446.50488,-446.50488,1.53e-5,261.01562,484.2124)" - spreadMethod="pad"><stop - id="stop33923" - style="stop-color:#ffffff;stop-opacity:1" - offset="0" /><stop - id="stop33925" - style="stop-color:#616264;stop-opacity:1" - offset="0.86813402" /><stop - id="stop33927" - style="stop-color:#8e9092;stop-opacity:1" - offset="1" /></linearGradient><linearGradient - x1="0" - y1="0" - x2="100.001" - y2="0" - id="linearGradient33985" - gradientUnits="userSpaceOnUse" - gradientTransform="matrix(2.466568,0,0,1.0813599,-53.365362,-26.941049)"><stop - id="stop33987" - style="stop-color:#000000;stop-opacity:1" - offset="0" /><stop - id="stop33989" - style="stop-color:#000000;stop-opacity:1" - offset="1" /></linearGradient><linearGradient - x1="0" - y1="0" - x2="100.001" - y2="0" - id="linearGradient34027" - gradientUnits="userSpaceOnUse" - gradientTransform="matrix(0.8523865,-2.0862427,1.4763641,1.2044983,160.58887,221.97853)"><stop - id="stop34029" - style="stop-color:#000000;stop-opacity:1" - offset="0" /><stop - id="stop34031" - style="stop-color:#000000;stop-opacity:1" - offset="1" /></linearGradient><linearGradient - x1="0" - y1="0" - x2="1" - y2="0" - id="linearGradient34101" - gradientUnits="userSpaceOnUse" - gradientTransform="matrix(-1.53e-5,446.50391,446.50391,1.53e-5,261.01465,37.708008)" - spreadMethod="pad"><stop - id="stop34103" - style="stop-color:#ffffff;stop-opacity:1" - offset="0" /><stop - id="stop34105" - style="stop-color:#231f20;stop-opacity:1" - offset="0.92308003" /><stop - id="stop34107" - style="stop-color:#231f20;stop-opacity:1" - offset="0.92308003" /><stop - id="stop34109" - style="stop-color:#231f20;stop-opacity:1" - offset="1" /></linearGradient><filter - x="-0.17975496" - y="-0.19057155" - width="1.3595099" - height="1.3811431" - color-interpolation-filters="sRGB" - id="filter34971"><feGaussianBlur - id="feGaussianBlur34973" - stdDeviation="35.454644" /></filter><linearGradient - x1="0" - y1="0" - x2="1" - y2="0" - id="linearGradient35685" - xlink:href="#linearGradient33921" - gradientUnits="userSpaceOnUse" - gradientTransform="matrix(-1.53e-5,-446.50488,-446.50488,1.53e-5,261.01562,484.2124)" - spreadMethod="pad" /><clipPath - id="clipPath35801"><path - d="m 392.42766,225.43729 c -3.74981,0 -7.51523,-0.14136 -11.05624,0.92584 -21.41291,-75.54824 -71.13038,-124.92904 -129.17769,-124.92904 -77.58673,0 -140.4832,94.60943 -140.4832,211.31612 0,47.62467 10.47671,91.56379 28.14834,126.90225 -8.56488,14.68555 -13.76772,33.91447 -13.76772,54.98507 0,46.07995 24.83318,83.43531 55.46718,83.43531 24.19047,0 44.75115,-23.30223 52.33595,-55.79054 5.99045,1.17296 12.09737,1.78401 18.29945,1.78401 6.04939,0 12.0093,-0.5758 17.85699,-1.69214 7.53582,32.62291 28.14054,56.04907 52.39418,56.04907 30.63402,0 55.4672,-37.35429 55.4672,-83.43425 0,-20.97873 -5.15952,-40.13501 -13.65906,-54.79597 7.15303,-14.20804 13.13707,-29.81871 17.74266,-46.50939 3.37978,0.96784 6.86469,1.49556 10.43196,1.49556 30.63399,0 55.46719,-37.35535 55.46719,-83.43423 0,-46.07996 -24.8332,-86.30767 -55.46719,-86.30767 z" - id="path35803" - style="fill:none;stroke:#ff0d0d;stroke-width:0.69681585;stroke-linecap:butt;stroke-linejoin:miter;stroke-miterlimit:4;stroke-opacity:1;stroke-dasharray:none" /></clipPath></defs><g - transform="matrix(1.25,0,0,-1.25,0,640)" - id="g2847"><g - id="g35655"><path - d="m 0,0 c -5.28,0 -10.435,-0.531 -15.421,-1.53 -30.151,70.72 -100.304,120.297 -182.039,120.297 -109.248,0 -197.811,-88.563 -197.811,-197.811 0,-44.581 14.752,-85.712 39.635,-118.792 -12.06,-13.747 -19.386,-31.747 -19.386,-51.471 0,-43.135 34.967,-78.103 78.102,-78.103 34.062,0 63.013,21.813 73.693,52.225 8.435,-1.098 17.034,-1.67 25.767,-1.67 8.518,0 16.91,0.539 25.144,1.584 10.611,-30.538 39.624,-52.467 73.775,-52.467 43.135,0 78.102,34.967 78.102,78.102 0,19.638 -7.265,37.57 -19.233,51.294 10.072,13.3 18.498,27.913 24.983,43.537 4.759,-0.906 9.666,-1.4 14.689,-1.4 43.135,0 78.102,34.968 78.102,78.102 C 78.102,-34.968 43.135,0 0,0 z" - transform="matrix(0.77717341,0,0,0.10093952,375.05839,59.806437)" - id="path34177" - style="opacity:0.53036439;fill:#000000;stroke:#000000;stroke-width:10;stroke-linecap:butt;stroke-linejoin:miter;stroke-miterlimit:4;stroke-opacity:1;stroke-dasharray:none;filter:url(#filter34971)" /><g - id="g35635"><path - d="m 24.329,286.402 c 0,-44.581 14.752,-85.713 39.634,-118.792 l 0,0 C 51.904,153.863 44.578,135.862 44.578,116.139 l 0,0 c 0,-43.136 34.967,-78.103 78.102,-78.103 l 0,0 c 34.061,0 63.012,21.812 73.693,52.225 l 0,0 c 8.434,-1.098 17.033,-1.67 25.767,-1.67 l 0,0 c 8.517,0 16.909,0.539 25.143,1.584 l 0,0 c 10.611,-30.538 39.624,-52.467 73.776,-52.467 l 0,0 c 43.134,0 78.101,34.967 78.101,78.101 l 0,0 c 0,19.639 -7.265,37.571 -19.232,51.295 l 0,0 c 10.072,13.3 18.498,27.912 24.982,43.537 l 0,0 c 4.76,-0.907 9.666,-1.4 14.69,-1.4 l 0,0 c 43.134,0 78.101,34.968 78.101,78.102 l 0,0 c 0,43.135 -34.967,78.103 -78.101,78.103 l 0,0 c -5.281,0 -10.435,-0.531 -15.422,-1.53 l 0,0 C 374.027,434.636 303.875,484.213 222.14,484.213 l 0,0 c -109.248,0 -197.811,-88.564 -197.811,-197.811" - id="path33929" - style="fill:url(#linearGradient35685);stroke:none" /><path - d="m 419.5996,365.4458 c -5.28,0 -10.435,-0.531 -15.421,-1.53 -30.151,70.72 -100.304,120.297 -182.039,120.297 -109.248,0 -197.811,-88.563 -197.811,-197.811 0,-44.581 14.752,-85.712 39.635,-118.792 -12.06,-13.747 -19.386,-31.747 -19.386,-51.471 0,-43.135 34.967,-78.103 78.102,-78.103 34.062,0 63.013,21.813 73.693,52.225 8.435,-1.098 17.034,-1.67 25.767,-1.67 8.518,0 16.91,0.539 25.144,1.584 10.611,-30.538 39.624,-52.467 73.775,-52.467 43.135,0 78.102,34.967 78.102,78.102 0,19.638 -7.265,37.57 -19.233,51.294 10.072,13.3 18.498,27.913 24.983,43.537 4.759,-0.906 9.666,-1.4 14.689,-1.4 43.135,0 78.102,34.968 78.102,78.102 0,43.135 -34.967,78.103 -78.102,78.103 z" - id="path33941" - style="fill:none;stroke:#000000;stroke-width:10;stroke-linecap:butt;stroke-linejoin:miter;stroke-miterlimit:4;stroke-opacity:1;stroke-dasharray:none" /></g><g - id="g35599"><path - d="m 299.6885,288.5244 c 0,43.695 -35.036,78.731 -78.731,78.731 -43.695,0 -78.731,-35.036 -78.731,-78.731 0,-43.694 35.036,-78.73 78.731,-78.73 43.695,0 78.731,35.036 78.731,78.73 z" - id="path33957" - style="fill:#000000;fill-opacity:1;stroke:#000000;stroke-width:2.15199995;stroke-linecap:butt;stroke-linejoin:miter;stroke-miterlimit:10;stroke-opacity:1;stroke-dasharray:none" /><path - d="m 462.0703,288.5244 c 0,24.579 -19.707,44.286 -44.285,44.286 -24.579,0 -44.286,-19.707 -44.286,-44.286 0,-24.578 19.707,-44.286 44.286,-44.286 24.578,0 44.285,19.708 44.285,44.286 z" - id="path33965" - style="fill:#000000;fill-opacity:1;stroke:#000000;stroke-width:2.15199995;stroke-linecap:butt;stroke-linejoin:miter;stroke-miterlimit:10;stroke-opacity:1;stroke-dasharray:none" /><path - d="m 363.6572,118.0664 c 0,24.579 -19.708,44.286 -44.286,44.286 -24.579,0 -44.286,-19.707 -44.286,-44.286 0,-24.577 19.707,-44.285 44.286,-44.285 24.578,0 44.286,19.708 44.286,44.285 z" - id="path34007" - style="fill:#000000;fill-opacity:1;stroke:#000000;stroke-width:2.15199995;stroke-linecap:butt;stroke-linejoin:miter;stroke-miterlimit:10;stroke-opacity:1;stroke-dasharray:none" /><path - d="m 166.8301,118.0664 c 0,24.579 -19.708,44.286 -44.286,44.286 -24.579,0 -44.286,-19.707 -44.286,-44.286 0,-24.577 19.707,-44.285 44.286,-44.285 24.578,0 44.286,19.708 44.286,44.285 z" - id="path34049" - style="fill:#000000;fill-opacity:1;stroke:#000000;stroke-width:2.15199995;stroke-linecap:butt;stroke-linejoin:miter;stroke-miterlimit:10;stroke-opacity:1;stroke-dasharray:none" /><path - d="m 234.93015,209.94152 c 19.39,3.382 32.137,-9.539 41.948,-26.602 l 0,0 5.912,-10.282 c 5.519,-9.59701 8.479,-17.91001 1.348,-26.37901 l 0.1,-0.05 c 8.346,6.08 17.891,11.974 27.41,16.101 l -0.05,0.05 c -10.906,-1.904 -16.571,4.544 -22.089,14.14101 l 0,0 -5.912,10.283 c -9.811,17.062 -14.43731,34.50322 -1.75931,49.55822 l 0.006,0.012 c -16.62837,-10.33021 -29.95181,-17.53833 -46.91681,-26.83533" - id="path34033" - style="fill:#000000;fill-opacity:1;stroke:none" /><path - d="m 296.0669,261.597 c 6.57209,18.496 23.65326,23.052 42.87061,23.052 l 0,0 0,7.75 c -19.21735,0 -36.29852,4.558 -42.87061,23.054 l -0.15,0 c 0.36042,-17.906 -0.13958,-35.95 -0.1,-53.806 m 55.13219,30.752 -12.01158,0 0,-7.75 12.01158,0 c 10.80964,0 20.43158,-0.867 24.12723,-11.271 l 0.25,0.05 c -0.24821,10.088 0.20179,19.956 -0.15,30.244 l -0.1,0 c -3.69565,-10.404 -13.31759,-11.273 -24.12723,-11.273" - id="path33991" - style="fill:#000000;fill-opacity:1;stroke:none" /><path - d="m 159.77751,237.27826 c 12.64561,-15.08306 7.74828,-32.66041 -2.0987,-49.70266 l 0,0 -5.93372,-10.26948 c -5.53797,-9.58609 -11.21221,-16.38495 -22.11486,-14.4595 l -0.0991,-0.21767 c 9.44444,-4.17426 19.39965,-9.30249 27.74211,-15.47069 l 0.0184,0.0683 c -7.11411,8.48266 -4.37418,16.61663 1.16427,26.20185 l 0,0 5.93457,10.26999 c 9.84612,17.04176 22.6192,29.78725 42.00114,26.36315 l 0.0133,4e-4 c -17.27367,9.21065 -29.97707,17.33858 -46.52544,27.35843" - id="path35597" - style="fill:#000000;fill-opacity:1;stroke:none" /></g><path - d="m 541.0918,183.6165 a 264.9606,162.99411 0 1 1 -529.921207,0 264.9606,162.99411 0 1 1 529.921207,0 z" - transform="matrix(1.4366299,0,0,-0.95740149,-140.89006,585.91684)" - clip-path="url(#clipPath35801)" - id="path35470" - style="opacity:0.16599193;fill:#ffffff;fill-opacity:1;stroke:none" /></g></g></svg>
\ No newline at end of file diff --git a/tikzit/share/tikzit b/tikzit/share/tikzit deleted file mode 120000 index a96aa0e..0000000 --- a/tikzit/share/tikzit +++ /dev/null @@ -1 +0,0 @@ -..
\ No newline at end of file diff --git a/tikzit/src/Makefile.am b/tikzit/src/Makefile.am deleted file mode 100644 index e869686..0000000 --- a/tikzit/src/Makefile.am +++ /dev/null @@ -1,175 +0,0 @@ -if WINDOWS -sharedir = ../ -else -sharedir = @datarootdir@/tikzit -endif - -AM_OBJCFLAGS = @FOUNDATION_OBJCFLAGS@ \ - @GTK_CFLAGS@ \ - -I common \ - -I gtk \ - -DTIKZITSHAREDIR=\"$(sharedir)\" \ - -std=c99 \ - -D_GNU_SOURCE -LIBS = @FOUNDATION_LIBS@ \ - @GTK_LIBS@ -AM_YFLAGS = -d -PARSERFILES = common/tikzlexer.m common/tikzparser.m common/tikzparser.h -ICONFILES = ../draw-ellipse.png \ - ../draw-path.png \ - ../select-rectangular.png \ - ../transform-crop-and-resize.png \ - ../transform-move.png -EDGEDECFILES = ../AH_*.png ../ED_*.png - -bin_PROGRAMS = tikzit -BUILT_SOURCES = $(PARSERFILES) -tikzit_SOURCES = gtk/Application.m \ - gtk/BoundingBoxTool.m \ - gtk/CairoRenderContext.m \ - gtk/ColorRGB+IntegerListStorage.m \ - gtk/ColorRGB+Gtk.m \ - gtk/Configuration.m \ - gtk/ContextWindow.m \ - gtk/CreateEdgeTool.m \ - gtk/CreateNodeTool.m \ - gtk/Edge+Render.m \ - gtk/EdgeStyle+Gtk.m \ - gtk/EdgeStyle+Storage.m \ - gtk/EdgeStyleEditor.m \ - gtk/EdgeStyleSelector.m \ - gtk/EdgeStylesModel.m \ - gtk/EdgeStylesPalette.m \ - gtk/FileChooserDialog.m \ - gtk/HandTool.m \ - gtk/GraphEditorPanel.m \ - gtk/GraphRenderer.m \ - gtk/Menu.m \ - gtk/Node+Render.m \ - gtk/NodeStyle+Gtk.m \ - gtk/NodeStyle+Storage.m \ - gtk/NodeStyleEditor.m \ - gtk/NodeStylesModel.m \ - gtk/NodeStyleSelector.m \ - gtk/NodeStylesPalette.m \ - gtk/NSError+Glib.m \ - gtk/NSFileManager+Glib.m \ - gtk/NSString+Glib.m \ - gtk/PropertiesPane.m \ - gtk/PropertyListEditor.m \ - gtk/RecentManager.m \ - gtk/SelectTool.m \ - gtk/SelectionPane.m \ - gtk/SettingsDialog.m \ - gtk/Shape+Render.m \ - gtk/StyleManager+Storage.m \ - gtk/TikzDocument.m \ - gtk/ToolBox.m \ - gtk/WidgetSurface.m \ - gtk/Window.m \ - gtk/cairo_helpers.m \ - gtk/clipboard.m \ - gtk/gtkhelpers.m \ - gtk/logo.m \ - gtk/mkdtemp.m \ - gtk/main.m \ - gtk/tzstockitems.m \ - gtk/tztoolpalette.m \ - common/CircleShape.m \ - common/ColorRGB.m \ - common/DiamondShape.m \ - common/Edge.m \ - common/EdgeStyle.m \ - common/GraphChange.m \ - common/GraphElementData.m \ - common/Graph.m \ - common/Grid.m \ - common/Node.m \ - common/NodeStyle.m \ - common/NSError+Tikzit.m \ - common/NSFileManager+Utils.m \ - common/NSString+LatexConstants.m \ - common/NSString+Tikz.m \ - common/PickSupport.m \ - common/PropertyHolder.m \ - common/GraphElementProperty.m \ - common/RColor.m \ - common/RectangleShape.m \ - common/RegularPolyShape.m \ - common/Shape.m \ - common/StyleManager.m \ - common/SupportDir.m \ - common/TikzGraphAssembler.m \ - common/TikzShape.m \ - common/Transformer.m \ - common/tikzparser.m \ - common/tikzlexer.m \ - common/util.m - -if HAVE_POPPLER -tikzit_SOURCES += \ - common/Preambles.m \ - gtk/PreambleEditor.m \ - gtk/Preambles+Storage.m \ - gtk/PreviewRenderer.m \ - gtk/PreviewWindow.m -endif - -if WINDOWS -tikzit.res: tikzit.rc - $(AM_V_GEN)windres $^ -O coff -o $@ - -tikzit_LDADD = tikzit.res -CLEANFILES = tikzit.res -endif - -common/tikzlexer.m: common/tikzlexer.lm - $(AM_V_GEN)$(LEX) -o $@ $^ - -common/tikzparser.m: common/tikzparser.ym - $(AM_V_GEN)$(YACC) --output=$@ $^ - -common/tikzparser.h: common/tikzparser.m - -gtk/icondata.m: $(ICONFILES) - $(AM_V_GEN)gdk-pixbuf-csource --struct --static --raw --build-list \ - draw_ellipse ../draw-ellipse.png \ - draw_path ../draw-path.png \ - select_rectangular ../select-rectangular.png \ - transform_crop_and_resize ../transform-crop-and-resize.png \ - transform_move ../transform-move.png \ - > $@ - -gtk/logodata.m: ../share/icons/hicolor/*/apps/tikzit.png - $(AM_V_GEN)gdk-pixbuf-csource --struct --static --raw --build-list \ - logo16 ../share/icons/hicolor/16x16/apps/tikzit.png \ - logo24 ../share/icons/hicolor/24x24/apps/tikzit.png \ - logo32 ../share/icons/hicolor/32x32/apps/tikzit.png \ - logo48 ../share/icons/hicolor/48x48/apps/tikzit.png \ - logo64 ../share/icons/hicolor/64x64/apps/tikzit.png \ - logo128 ../share/icons/hicolor/128x128/apps/tikzit.png \ - > $@ - -gtk/edgedecdata.m: $(EDGEDECFILES) - $(AM_V_GEN)gdk-pixbuf-csource --struct --static --raw --build-list \ - AH_none_pixdata ../AH_none.png \ - AH_latex_head_pixdata ../AH_latex_head.png \ - AH_latex_tail_pixdata ../AH_latex_tail.png \ - AH_plain_head_pixdata ../AH_plain_head.png \ - AH_plain_tail_pixdata ../AH_plain_tail.png \ - ED_none_pixdata ../ED_none.png \ - ED_arrow_pixdata ../ED_arrow.png \ - ED_tick_pixdata ../ED_tick.png \ - > $@ - -gtk/Menu.m: gtk/icondata.m -gtk/logo.m: gtk/logodata.m -gtk/EdgeStyleEditor.m: gtk/edgedecdata.m - -EXTRA_DIST = gtk/*.h common/*.h \ - $(PARSERFILES) common/tikzlexer.lm common/tikzparser.ym \ - $(ICONFILES) gtk/icondata.m \ - gtk/logodata.m \ - $(EDGEDECFILES) gtk/edgedecdata.m \ - tikzit.rc ../tikzit.ico -MAINTAINERCLEANFILES = $(PARSERFILES) gtk/icondata.m gtk/logodata.m gtk/edgedecdata.m diff --git a/tikzit/src/common/CircleShape.h b/tikzit/src/common/CircleShape.h deleted file mode 100644 index 8215b92..0000000 --- a/tikzit/src/common/CircleShape.h +++ /dev/null @@ -1,33 +0,0 @@ -// -// CircleShape.h -// TikZiT -// -// Copyright 2011 Aleks Kissinger. All rights reserved. -// -// -// This file is part of TikZiT. -// -// TikZiT is free software: you can redistribute it and/or modify -// it under the terms of the GNU General Public License as published by -// the Free Software Foundation, either version 3 of the License, or -// (at your option) any later version. -// -// TikZiT is distributed in the hope that it will be useful, -// but WITHOUT ANY WARRANTY; without even the implied warranty of -// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -// GNU General Public License for more details. -// -// You should have received a copy of the GNU General Public License -// along with TikZiT. If not, see <http://www.gnu.org/licenses/>. -// - -#import <Foundation/Foundation.h> -#import "Shape.h" - -@interface CircleShape : Shape { -} - - -@end - -// vi:ft=objc:noet:ts=4:sts=4:sw=4 diff --git a/tikzit/src/common/CircleShape.m b/tikzit/src/common/CircleShape.m deleted file mode 100644 index f2d1d52..0000000 --- a/tikzit/src/common/CircleShape.m +++ /dev/null @@ -1,57 +0,0 @@ -// -// CircleShape.m -// TikZiT -// -// Copyright 2011 Aleks Kissinger. All rights reserved. -// -// -// This file is part of TikZiT. -// -// TikZiT is free software: you can redistribute it and/or modify -// it under the terms of the GNU General Public License as published by -// the Free Software Foundation, either version 3 of the License, or -// (at your option) any later version. -// -// TikZiT is distributed in the hope that it will be useful, -// but WITHOUT ANY WARRANTY; without even the implied warranty of -// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -// GNU General Public License for more details. -// -// You should have received a copy of the GNU General Public License -// along with TikZiT. If not, see <http://www.gnu.org/licenses/>. -// - -#import "CircleShape.h" -#import "Node.h" -#import "Edge.h" - -@implementation CircleShape - -- (id)init { - self = [super init]; - if (self) { - Node *n0,*n1,*n2,*n3; - - n0 = [Node nodeWithPoint:NSMakePoint( 0.0f, 0.2f)]; - n1 = [Node nodeWithPoint:NSMakePoint( 0.2f, 0.0f)]; - n2 = [Node nodeWithPoint:NSMakePoint( 0.0f, -0.2f)]; - n3 = [Node nodeWithPoint:NSMakePoint(-0.2f, 0.0f)]; - - Edge *e0,*e1,*e2,*e3; - - e0 = [Edge edgeWithSource:n0 andTarget:n1]; [e0 setBend:-45]; - e1 = [Edge edgeWithSource:n1 andTarget:n2]; [e1 setBend:-45]; - e2 = [Edge edgeWithSource:n2 andTarget:n3]; [e2 setBend:-45]; - e3 = [Edge edgeWithSource:n3 andTarget:n0]; [e3 setBend:-45]; - - paths = [[NSSet alloc] initWithObjects:[NSArray arrayWithObjects:e0,e1,e2,e3,nil],nil]; - - styleTikz = @"circle"; - } - return self; -} - - -@end - -// vi:ft=objc:ts=4:noet:sts=4:sw=4 diff --git a/tikzit/src/common/ColorRGB.h b/tikzit/src/common/ColorRGB.h deleted file mode 100644 index 607ba64..0000000 --- a/tikzit/src/common/ColorRGB.h +++ /dev/null @@ -1,64 +0,0 @@ -// -// ColorRGB.h -// TikZiT -// -// Copyright 2010 Aleks Kissinger. All rights reserved. -// -// -// This file is part of TikZiT. -// -// TikZiT is free software: you can redistribute it and/or modify -// it under the terms of the GNU General Public License as published by -// the Free Software Foundation, either version 3 of the License, or -// (at your option) any later version. -// -// TikZiT is distributed in the hope that it will be useful, -// but WITHOUT ANY WARRANTY; without even the implied warranty of -// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -// GNU General Public License for more details. -// -// You should have received a copy of the GNU General Public License -// along with TikZiT. If not, see <http://www.gnu.org/licenses/>. -// - -#import <Foundation/Foundation.h> -#import "RColor.h" - -@interface ColorRGB : NSObject<NSCopying> { - unsigned short red, green, blue; -} - -@property (assign) unsigned short red; -@property (assign) unsigned short green; -@property (assign) unsigned short blue; - -@property (assign) float redFloat; -@property (assign) float greenFloat; -@property (assign) float blueFloat; - -@property (readonly) NSString *name; - -- (RColor)rColor; -- (RColor)rColorWithAlpha:(CGFloat)alpha; - -- (NSString*)hexName; -- (BOOL)isEqual:(id)col; -- (float)distanceFromColor:(ColorRGB*)col; -- (int)hash; - -- (id)initWithRed:(unsigned short)r green:(unsigned short)g blue:(unsigned short)b; -- (id)initWithFloatRed:(float)r green:(float)g blue:(float)b; -- (id)initWithRColor:(RColor)color; - -- (void)setToClosestHashed; - -+ (ColorRGB*)colorWithRed:(unsigned short)r green:(unsigned short)g blue:(unsigned short)b; -+ (ColorRGB*)colorWithFloatRed:(float)r green:(float)g blue:(float)b; -+ (ColorRGB*)colorWithRColor:(RColor)color; - -+ (void)makeColorHash; -+ (void)releaseColorHash; - -@end - -// vi:ft=objc:noet:ts=4:sts=4:sw=4 diff --git a/tikzit/src/common/ColorRGB.m b/tikzit/src/common/ColorRGB.m deleted file mode 100644 index c108cfe..0000000 --- a/tikzit/src/common/ColorRGB.m +++ /dev/null @@ -1,333 +0,0 @@ -// -// ColorRGB.m -// TikZiT -// -// Copyright 2010 Aleks Kissinger. All rights reserved. -// -// -// This file is part of TikZiT. -// -// TikZiT is free software: you can redistribute it and/or modify -// it under the terms of the GNU General Public License as published by -// the Free Software Foundation, either version 3 of the License, or -// (at your option) any later version. -// -// TikZiT is distributed in the hope that it will be useful, -// but WITHOUT ANY WARRANTY; without even the implied warranty of -// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -// GNU General Public License for more details. -// -// You should have received a copy of the GNU General Public License -// along with TikZiT. If not, see <http://www.gnu.org/licenses/>. -// - -#import "ColorRGB.h" -#import "util.h" - -typedef struct { - NSString *name; - unsigned short r, g, b; -} ColorRGBEntry; - -static const ColorRGBEntry kColors[147] = { - { @"AliceBlue", 240, 248, 255 }, - { @"AntiqueWhite", 250, 235, 215 }, - { @"Aqua", 0, 255, 255 }, - { @"Aquamarine", 127, 255, 212 }, - { @"Azure", 240, 255, 255 }, - { @"Beige", 245, 245, 220 }, - { @"Bisque", 255, 228, 196 }, - { @"Black", 0, 0, 0 }, - { @"BlanchedAlmond", 255, 235, 205 }, - { @"Blue", 0, 0, 255 }, - { @"BlueViolet", 138, 43, 226 }, - { @"Brown", 165, 42, 42 }, - { @"BurlyWood", 222, 184, 135 }, - { @"CadetBlue", 95, 158, 160 }, - { @"Chartreuse", 127, 255, 0 }, - { @"Chocolate", 210, 105, 30 }, - { @"Coral", 255, 127, 80 }, - { @"CornflowerBlue", 100, 149, 237 }, - { @"Cornsilk", 255, 248, 220 }, - { @"Crimson", 220, 20, 60 }, - { @"Cyan", 0, 255, 255 }, - { @"DarkBlue", 0, 0, 139 }, - { @"DarkCyan", 0, 139, 139 }, - { @"DarkGoldenrod", 184, 134, 11 }, - { @"DarkGray", 169, 169, 169 }, - { @"DarkGreen", 0, 100, 0 }, - { @"DarkGrey", 169, 169, 169 }, - { @"DarkKhaki", 189, 183, 107 }, - { @"DarkMagenta", 139, 0, 139 }, - { @"DarkOliveGreen", 85, 107, 47 }, - { @"DarkOrange", 255, 140, 0 }, - { @"DarkOrchid", 153, 50, 204 }, - { @"DarkRed", 139, 0, 0 }, - { @"DarkSalmon", 233, 150, 122 }, - { @"DarkSeaGreen", 143, 188, 143 }, - { @"DarkSlateBlue", 72, 61, 139 }, - { @"DarkSlateGray", 47, 79, 79 }, - { @"DarkSlateGrey", 47, 79, 79 }, - { @"DarkTurquoise", 0, 206, 209 }, - { @"DarkViolet", 148, 0, 211 }, - { @"DeepPink", 255, 20, 147 }, - { @"DeepSkyBlue", 0, 191, 255 }, - { @"DimGray", 105, 105, 105 }, - { @"DimGrey", 105, 105, 105 }, - { @"DodgerBlue", 30, 144, 255 }, - { @"FireBrick", 178, 34, 34 }, - { @"FloralWhite", 255, 250, 240 }, - { @"ForestGreen", 34, 139, 34 }, - { @"Fuchsia", 255, 0, 255 }, - { @"Gainsboro", 220, 220, 220 }, - { @"GhostWhite", 248, 248, 255 }, - { @"Gold", 255, 215, 0 }, - { @"Goldenrod", 218, 165, 32 }, - { @"Gray", 128, 128, 128 }, - { @"Grey", 128, 128, 128 }, - { @"Green", 0, 128, 0 }, - { @"GreenYellow", 173, 255, 47 }, - { @"Honeydew", 240, 255, 240 }, - { @"HotPink", 255, 105, 180 }, - { @"IndianRed", 205, 92, 92 }, - { @"Indigo", 75, 0, 130 }, - { @"Ivory", 255, 255, 240 }, - { @"Khaki", 240, 230, 140 }, - { @"Lavender", 230, 230, 250 }, - { @"LavenderBlush", 255, 240, 245 }, - { @"LawnGreen", 124, 252, 0 }, - { @"LemonChiffon", 255, 250, 205 }, - { @"LightBlue", 173, 216, 230 }, - { @"LightCoral", 240, 128, 128 }, - { @"LightCyan", 224, 255, 255 }, - { @"LightGoldenrodYellow", 250, 250, 210 }, - { @"LightGray", 211, 211, 211 }, - { @"LightGreen", 144, 238, 144 }, - { @"LightGrey", 211, 211, 211 }, - { @"LightPink", 255, 182, 193 }, - { @"LightSalmon", 255, 160, 122 }, - { @"LightSeaGreen", 32, 178, 170 }, - { @"LightSkyBlue", 135, 206, 250 }, - { @"LightSlateGray", 119, 136, 153 }, - { @"LightSlateGrey", 119, 136, 153 }, - { @"LightSteelBlue", 176, 196, 222 }, - { @"LightYellow", 255, 255, 224 }, - { @"Lime", 0, 255, 0 }, - { @"LimeGreen", 50, 205, 50 }, - { @"Linen", 250, 240, 230 }, - { @"Magenta", 255, 0, 255 }, - { @"Maroon", 128, 0, 0 }, - { @"MediumAquamarine", 102, 205, 170 }, - { @"MediumBlue", 0, 0, 205 }, - { @"MediumOrchid", 186, 85, 211 }, - { @"MediumPurple", 147, 112, 219 }, - { @"MediumSeaGreen", 60, 179, 113 }, - { @"MediumSlateBlue", 123, 104, 238 }, - { @"MediumSpringGreen", 0, 250, 154 }, - { @"MediumTurquoise", 72, 209, 204 }, - { @"MediumVioletRed", 199, 21, 133 }, - { @"MidnightBlue", 25, 25, 112 }, - { @"MintCream", 245, 255, 250 }, - { @"MistyRose", 255, 228, 225 }, - { @"Moccasin", 255, 228, 181 }, - { @"NavajoWhite", 255, 222, 173 }, - { @"Navy", 0, 0, 128 }, - { @"OldLace", 253, 245, 230 }, - { @"Olive", 128, 128, 0 }, - { @"OliveDrab", 107, 142, 35 }, - { @"Orange", 255, 165, 0 }, - { @"OrangeRed", 255, 69, 0 }, - { @"Orchid", 218, 112, 214 }, - { @"PaleGoldenrod", 238, 232, 170 }, - { @"PaleGreen", 152, 251, 152 }, - { @"PaleTurquoise", 175, 238, 238 }, - { @"PaleVioletRed", 219, 112, 147 }, - { @"PapayaWhip", 255, 239, 213 }, - { @"PeachPuff", 255, 218, 185 }, - { @"Peru", 205, 133, 63 }, - { @"Pink", 255, 192, 203 }, - { @"Plum", 221, 160, 221 }, - { @"PowderBlue", 176, 224, 230 }, - { @"Purple", 128, 0, 128 }, - { @"Red", 255, 0, 0 }, - { @"RosyBrown", 188, 143, 143 }, - { @"RoyalBlue", 65, 105, 225 }, - { @"SaddleBrown", 139, 69, 19 }, - { @"Salmon", 250, 128, 114 }, - { @"SandyBrown", 244, 164, 96 }, - { @"SeaGreen", 46, 139, 87 }, - { @"Seashell", 255, 245, 238 }, - { @"Sienna", 160, 82, 45 }, - { @"Silver", 192, 192, 192 }, - { @"SkyBlue", 135, 206, 235 }, - { @"SlateBlue", 106, 90, 205 }, - { @"SlateGray", 112, 128, 144 }, - { @"SlateGrey", 112, 128, 144 }, - { @"Snow", 255, 250, 250 }, - { @"SpringGreen", 0, 255, 127 }, - { @"SteelBlue", 70, 130, 180 }, - { @"Tan", 210, 180, 140 }, - { @"Teal", 0, 128, 128 }, - { @"Thistle", 216, 191, 216 }, - { @"Tomato", 255, 99, 71 }, - { @"Turquoise", 64, 224, 208 }, - { @"Violet", 238, 130, 238 }, - { @"Wheat", 245, 222, 179 }, - { @"White", 255, 255, 255 }, - { @"WhiteSmoke", 245, 245, 245 }, - { @"Yellow", 255, 255, 0 }, - { @"YellowGreen", 154, 205, 50 } -}; - -static NSMapTable *colorHash = nil; - -@implementation ColorRGB - -+ (void)initialize { - [self setKeys:[NSArray arrayWithObject:@"red"] triggerChangeNotificationsForDependentKey:@"redFloat"]; - [self setKeys:[NSArray arrayWithObject:@"green"] triggerChangeNotificationsForDependentKey:@"greenFloat"]; - [self setKeys:[NSArray arrayWithObject:@"blue"] triggerChangeNotificationsForDependentKey:@"blueFloat"]; - [self setKeys:[NSArray arrayWithObjects:@"red", @"green", @"blue", nil] - triggerChangeNotificationsForDependentKey:@"name"]; -} - -@synthesize red, green, blue; - -- (float)redFloat { return ((float)red)/255.0f; } -- (void)setRedFloat:(float)r { [self setRed:round(r*255.0f)]; } -- (float)greenFloat { return ((float)green)/255.0f; } -- (void)setGreenFloat:(float)g { [self setGreen:round(g*255.0f)]; } -- (float)blueFloat { return ((float)blue)/255.0f; } -- (void)setBlueFloat:(float)b { [self setBlue:round(b*255.0f)]; } - -- (int)hash { - return (red<<4) + (green<<2) + blue; -} - -- (id)initWithRed:(unsigned short)r green:(unsigned short)g blue:(unsigned short)b { - self = [super init]; - if (self) { - red = r; - green = g; - blue = b; - } - return self; -} - -- (id)initWithFloatRed:(float)r green:(float)g blue:(float)b { - self = [super init]; - if (self) { - red = round(r*255.0f); - green = round(g*255.0f); - blue = round(b*255.0f); - } - return self; -} - -- (id) initWithRColor:(RColor)color { - return [self initWithFloatRed:color.red green:color.green blue:color.blue]; -} - -- (RColor) rColor { - return MakeSolidRColor ([self redFloat], [self greenFloat], [self blueFloat]); -} - -- (RColor) rColorWithAlpha:(CGFloat)alpha { - return MakeRColor ([self redFloat], [self greenFloat], [self blueFloat], alpha); -} - -- (NSString*)name { - if (colorHash == nil) - [ColorRGB makeColorHash]; - return [colorHash objectForKey:self]; -} - -- (NSString*)hexName { - return [NSString stringWithFormat:@"hexcolor0x%.2x%.2x%.2x", red, green, blue]; -} - -- (NSComparisonResult)compare:(ColorRGB*)col { - if (red > [col red]) return NSOrderedDescending; - else if (red < [col red]) return NSOrderedAscending; - else { - if (green > [col green]) return NSOrderedDescending; - else if (green < [col green]) return NSOrderedAscending; - else { - if (blue > [col blue]) return NSOrderedDescending; - else if (blue < [col blue]) return NSOrderedAscending; - else return NSOrderedSame; - } - } -} - -- (BOOL)isEqual:(id)col { - return [self compare:col] == NSOrderedSame; -} - -- (float)distanceFromColor:(ColorRGB *)col { - float dr = (float)(red - [col red]); - float dg = (float)(green - [col green]); - float db = (float)(blue - [col blue]); - return dr*dr + dg*dg + db*db; -} - -- (id)copyWithZone:(NSZone*)zone { - ColorRGB *col = [[ColorRGB allocWithZone:zone] initWithRed:red green:green blue:blue]; - return col; -} - -+ (ColorRGB*)colorWithRed:(unsigned short)r green:(unsigned short)g blue:(unsigned short)b { - ColorRGB *col = [[ColorRGB alloc] initWithRed:r green:g blue:b]; - return [col autorelease]; -} - - -+ (ColorRGB*)colorWithFloatRed:(float)r green:(float)g blue:(float)b { - ColorRGB *col = [[ColorRGB alloc] initWithFloatRed:r green:g blue:b]; - return [col autorelease]; -} - -+ (ColorRGB*) colorWithRColor:(RColor)color { - return [[[self alloc] initWithRColor:color] autorelease]; -} - -+ (void)makeColorHash { - NSMapTable *h = [[NSMapTable alloc] init]; - int i; - for (i = 0; i < 147; ++i) { - ColorRGB *col = [[ColorRGB alloc] initWithRed:kColors[i].r - green:kColors[i].g - blue:kColors[i].b]; - [h setObject:kColors[i].name forKey:col]; - //NSLog(@"adding color %@ (%d)", kColors[i].name, [col hash]); - [col release]; - } - colorHash = h; -} - -+ (void)releaseColorHash { - [colorHash release]; -} - -- (void)setToClosestHashed { - if (colorHash == nil) - [ColorRGB makeColorHash]; - float bestDist = -1; - ColorRGB *bestColor = nil; - NSEnumerator *enumerator = [colorHash keyEnumerator]; - ColorRGB *tryColor; - while ((tryColor = [enumerator nextObject]) != nil) { - float dist = [self distanceFromColor:tryColor]; - if (bestDist<0 || dist<bestDist) { - bestDist = dist; - bestColor = tryColor; - } - } - [self setRed:[bestColor red]]; - [self setGreen:[bestColor green]]; - [self setBlue:[bestColor blue]]; -} - -@end - -// vi:noet:ts=4:sts=4:sw=4 diff --git a/tikzit/src/common/DiamondShape.h b/tikzit/src/common/DiamondShape.h deleted file mode 100644 index 8f63386..0000000 --- a/tikzit/src/common/DiamondShape.h +++ /dev/null @@ -1,34 +0,0 @@ -// -// DiamondShape.h -// TikZiT -// -// Copyright 2012 Alex Merry -// All rights reserved. -// -// -// This file is part of TikZiT. -// -// TikZiT is free software: you can redistribute it and/or modify -// it under the terms of the GNU General Public License as published by -// the Free Software Foundation, either version 3 of the License, or -// (at your option) any later version. -// -// TikZiT is distributed in the hope that it will be useful, -// but WITHOUT ANY WARRANTY; without even the implied warranty of -// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -// GNU General Public License for more details. -// -// You should have received a copy of the GNU General Public License -// along with TikZiT. If not, see <http://www.gnu.org/licenses/>. -// - -#import <Foundation/Foundation.h> -#import "Shape.h" - -@interface DiamondShape : Shape { -} - -@end - -// vi:ft=objc:noet:ts=4:sts=4:sw=4 - diff --git a/tikzit/src/common/DiamondShape.m b/tikzit/src/common/DiamondShape.m deleted file mode 100644 index 1a578b8..0000000 --- a/tikzit/src/common/DiamondShape.m +++ /dev/null @@ -1,63 +0,0 @@ -// -// DiamondShape.m -// TikZiT -// -// Copyright 2011 Aleks Kissinger -// Copyright 2012 Alex Merry -// All rights reserved. -// -// -// This file is part of TikZiT. -// -// TikZiT is free software: you can redistribute it and/or modify -// it under the terms of the GNU General Public License as published by -// the Free Software Foundation, either version 3 of the License, or -// (at your option) any later version. -// -// TikZiT is distributed in the hope that it will be useful, -// but WITHOUT ANY WARRANTY; without even the implied warranty of -// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -// GNU General Public License for more details. -// -// You should have received a copy of the GNU General Public License -// along with TikZiT. If not, see <http://www.gnu.org/licenses/>. -// - -#import "DiamondShape.h" - -#import "Node.h" -#import "Edge.h" - -@implementation DiamondShape - -- (id)init { - self = [super init]; - - if (!self) - return nil; - - Node *n0,*n1,*n2,*n3; - float sz = 0.25f; - - n0 = [Node nodeWithPoint:NSMakePoint(0, sz)]; - n1 = [Node nodeWithPoint:NSMakePoint(sz, 0)]; - n2 = [Node nodeWithPoint:NSMakePoint(0,-sz)]; - n3 = [Node nodeWithPoint:NSMakePoint(-sz,0)]; - - Edge *e0,*e1,*e2,*e3; - - e0 = [Edge edgeWithSource:n0 andTarget:n1]; - e1 = [Edge edgeWithSource:n1 andTarget:n2]; - e2 = [Edge edgeWithSource:n2 andTarget:n3]; - e3 = [Edge edgeWithSource:n3 andTarget:n0]; - - paths = [[NSSet alloc] initWithObjects:[NSArray arrayWithObjects:e0,e1,e2,e3,nil],nil]; - - styleTikz = @"shape=diamond"; - - return self; -} - -@end - -// vi:ft=objc:ts=4:noet:sts=4:sw=4 diff --git a/tikzit/src/common/Edge.h b/tikzit/src/common/Edge.h deleted file mode 100644 index 64da138..0000000 --- a/tikzit/src/common/Edge.h +++ /dev/null @@ -1,396 +0,0 @@ -// -// Edge.h -// TikZiT -// -// Copyright 2010 Aleks Kissinger. All rights reserved. -// -// -// This file is part of TikZiT. -// -// TikZiT is free software: you can redistribute it and/or modify -// it under the terms of the GNU General Public License as published by -// the Free Software Foundation, either version 3 of the License, or -// (at your option) any later version. -// -// TikZiT is distributed in the hope that it will be useful, -// but WITHOUT ANY WARRANTY; without even the implied warranty of -// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -// GNU General Public License for more details. -// -// You should have received a copy of the GNU General Public License -// along with TikZiT. If not, see <http://www.gnu.org/licenses/>. -// - - -// Edge : store the data associated with an edge. Also, lazily compute -// bezier curve control points based on bend and the coordinates of -// the endpoints. - -#import "Node.h" -#import "EdgeStyle.h" - -/*! - @typedef enum EdgeBendMode - @brief Indicates the type of edge bend. - @var EdgeBendModeBasic A basic, one-angle bend. Positive values will be interpreted - as bend left, negative as bend right. - @var EdgeBendModeInOut A two-angle bend mode, using inAngle and outAngle. - */ -typedef enum { - EdgeBendModeBasic, - EdgeBendModeInOut -} EdgeBendMode; - -/*! - @class Edge - @brief A graph edge, with associated bend and style data. - @details A graph edge, with associated bend and style data. This class - also contains methods for computing the bezier control points - and the midpoint of the curve. - */ -@interface Edge : NSObject<NSCopying> { - Node *source; - Node *target; - Node *edgeNode; - int bend; - int inAngle, outAngle; - EdgeBendMode bendMode; - float weight; - EdgeStyle *style; - GraphElementData *data; - NSString *sourceAnchor; - NSString *targetAnchor; - - // When set to YES, lazily create the edge node, and keep it around when set - // to NO (at least until saved/loaded). - BOOL hasEdgeNode; - BOOL dirty; - - // these are all cached values computed from the above - NSPoint src; - NSPoint targ; - NSPoint head; - NSPoint tail; - NSPoint cp1; - NSPoint cp2; - NSPoint mid; - NSPoint midTan; - NSPoint headTan; - NSPoint tailTan; -} - -/*! - @property data - @brief Associated edge data. - */ -@property (copy) GraphElementData *data; - -// KVC methods -- (void) insertObject:(GraphElementProperty*)gep - inDataAtIndex:(NSUInteger)index; -- (void) removeObjectFromDataAtIndex:(NSUInteger)index; -- (void) replaceObjectInDataAtIndex:(NSUInteger)index - withObject:(GraphElementProperty*)gep; - -/*! - @property style - @brief Edge style. - */ -@property (retain) EdgeStyle *style; - -/*! - @property source - @brief Source node. - */ -@property (retain) Node *source; - -/*! - @property target - @brief Target node. - */ -@property (retain) Node *target; - -/*! - @property edgeNode - @brief A node attached to this edge, as in a label or tick. - */ -@property (retain) Node *edgeNode; - -/*! - @property sourceAnchor - @brief The source node anchor point, as in north or center. - */ -@property (copy) NSString *sourceAnchor; - -/*! - @property targetAnchor - @brief The target node anchor point, as in north or center. - */ -@property (copy) NSString *targetAnchor; - -/*! - @property hasEdgeNode - @brief A read/write property. When set to true, a new edge node is actually constructed. -*/ -@property (assign) BOOL hasEdgeNode; - -/*! - @property bend - @brief The degrees by which the edge bends. - */ -@property (assign) int bend; - -/*! - @property weight - @brief How close the edge will pass to control points. - */ -@property (assign) float weight; - -/*! - @property inAngle - @brief The angle by which the edge enters its target. - */ -@property (assign) int inAngle; - -/*! - @property outAngle - @brief The angle by which the edge leaves its target. - */ -@property (assign) int outAngle; - -/*! - @property bendMode - @brief The mode of the edge bend. Either simple bend in in/out style. - */ -@property (assign) EdgeBendMode bendMode; - -/*! - @property head - @brief The starting point of the edge. - @detail This value is computed based on the source, target and - either bend or in/out angles. It is where the edge - makes contact with the source node. - */ -@property (readonly) NSPoint head; - -/*! - @property tail - @brief The ending point of the edge. - @detail This value is computed based on the source, target and - either bend or in/out angles. It is where the edge - makes contact with the target node. - */ -@property (readonly) NSPoint tail; - -/*! - @property cp1 - @brief The first control point of the edge. - @detail This value is computed based on the source, target and - either bend or in/out angles. - */ -@property (readonly) NSPoint cp1; - -/*! - @property cp2 - @brief The second control point of the edge. - @detail This value is computed based on the source, target and - either bend or in/out angles. - */ -@property (readonly) NSPoint cp2; - -/*! - @property mid - @brief The midpoint of the curve. Computed from the source, target, and control points. - */ -@property (readonly) NSPoint mid; - -/*! - @property mid_tan - @brief The second point of a line tangent to the midpoint. (The first is the midpoint itself.) - */ -@property (readonly) NSPoint midTan; - -/*! - @property left_normal - @brief The second point in a line perp. to the edge coming from mid-point. (left side) - */ -@property (readonly) NSPoint leftNormal; - -/*! - @property left_normal - @brief The second point in a line perp. to the edge coming from mid-point. (right side) - */ -@property (readonly) NSPoint rightNormal; - -@property (readonly) NSPoint headTan; - -/*! - @property leftHeadNormal - */ -@property (readonly) NSPoint leftHeadNormal; - -/*! - @property rightHeadNormal - */ -@property (readonly) NSPoint rightHeadNormal; - -@property (readonly) NSPoint tailTan; - -/*! - @property leftTailNormal - */ -@property (readonly) NSPoint leftTailNormal; - -/*! - @property rightTailNormal - */ -@property (readonly) NSPoint rightTailNormal; - -/*! - @property isSelfLoop - @brief Returns YES if this edge is a self loop. - */ -@property (readonly) BOOL isSelfLoop; - -/*! - @property isStraight - @brief Returns YES if this edge can be drawn as a straight line (as opposed to a bezier curve). - */ -@property (readonly) BOOL isStraight; - - -/*! - @brief Construct a blank edge. - @result An edge. - */ -- (id)init; - -/*! - @brief Construct an edge with the given source and target. - @param s the source node. - @param t the target node. - @result An edge. - */ -- (id)initWithSource:(Node*)s andTarget:(Node*)t; - -/*! - @brief Recompute the control points and midpoint. - */ -- (void)updateControls; - -/*! - @brief Push edge properties back into its <tt>GraphElementData</tt>. - */ -- (void)updateData; - -/*! - @brief Set edge properties from fields in <tt>GraphElementData</tt>. - */ -- (void)setAttributesFromData; - -/*! - @brief Use data.style to find and attach the <tt>EdgeStyle</tt> object from the given array. - */ -- (BOOL)attachStyleFromTable:(NSArray*)styles; - -/*! - @brief Convert the bend angle to an inAngle and outAngle. - */ -- (void)convertBendToAngles; - -/*! - @brief Set the bend angle to the average of the in and out angles. - */ -- (void)convertAnglesToBend; - -/*! - @brief Update this edge to look just like the given edge. - @param e an edge to mimic. - */ -- (void)setPropertiesFromEdge:(Edge *)e; - -/*! - @brief Get a bounding rect for this edge. - @detail Note that this may not be a tight bound. - */ -- (NSRect)boundingRect; - -/*! - @brief Moves the first control point, updating edge properties as necessary - @detail This will move a control point and adjust the weight and - bend (or outAngle) to fit. - - A courseness can be specified for both the weight and the - bend, allowing them to be constrained to certain values. For - example, passing 10 as the bend courseness will force the bend - to be a multiple of 5. Passing 0 for either of these will - cause the relevant value to be unconstrained. - @param point the new position of the control point - @param wc force the weight to be a multiple of this value (unless 0) - @param bc force the bend (or outAngle) to be a multiple of this value (unless 0) - @param link when in EdgeBendModeInOut, change both the in and out angles at once - */ -- (void) moveCp1To:(NSPoint)point withWeightCourseness:(float)wc andBendCourseness:(int)bc forceLinkControlPoints:(BOOL)link; - -/*! - @brief Moves the first control point, updating edge properties as necessary - @detail This will move a control point and adjust the weight and - bend (or outAngle) to fit. - - The same as moveCp1To:point withWeightCourseness:0.0f andBendCourseness:0 forceLinkControlPoints:No - @param point the new position of the control point - @param wc force the weight to be a multiple of this value (unless 0) - @param bc force the bend (or outAngle) to be a multiple of this value (unless 0) - @param link when in EdgeBendModeInOut, change both the in and out angles at once - */ -- (void) moveCp1To:(NSPoint)point; - -/*! - @brief Moves the first control point, updating edge properties as necessary - @detail This will move a control point and adjust the weight and - bend (or inAngle) to fit. - - A courseness can be specified for both the weight and the - bend, allowing them to be constrained to certain values. For - example, passing 10 as the bend courseness will force the bend - to be a multiple of 5. Passing 0 for either of these will - cause the relevant value to be unconstrained. - @param point the new position of the control point - @param wc force the weight to be a multiple of this value (unless 0) - @param bc force the bend (or inAngle) to be a multiple of this value (unless 0) - @param link when in EdgeBendModeInOut, change both the in and out angles at once - */ -- (void) moveCp2To:(NSPoint)point withWeightCourseness:(float)wc andBendCourseness:(int)bc forceLinkControlPoints:(BOOL)link; - -/*! - @brief Moves the first control point, updating edge properties as necessary - @detail This will move a control point and adjust the weight and - bend (or inAngle) to fit. - - The same as moveCp2To:point withWeightCourseness:0.0f andBendCourseness:0 forceLinkControlPoints:No - @param point the new position of the control point - */ -- (void) moveCp2To:(NSPoint)point; - -/*! - @brief Reverse edge direction, updating bend/inAngle/outAngle/etc - */ -- (void)reverse; - -/*! - @brief Factory method to make a blank edge. - @result An edge. - */ -+ (Edge*)edge; - -/*! - @brief Factory method to make an edge with the given source and target. - @param s a source node. - @param t a target node. - @result An edge. - */ -+ (Edge*)edgeWithSource:(Node*)s andTarget:(Node*)t; - -@end - -// vi:ft=objc:noet:ts=4:sts=4:sw=4 diff --git a/tikzit/src/common/Edge.m b/tikzit/src/common/Edge.m deleted file mode 100644 index 945503f..0000000 --- a/tikzit/src/common/Edge.m +++ /dev/null @@ -1,673 +0,0 @@ -// -// Edge.m -// TikZiT -// -// Copyright 2010 Aleks Kissinger. All rights reserved. -// -// -// This file is part of TikZiT. -// -// TikZiT is free software: you can redistribute it and/or modify -// it under the terms of the GNU General Public License as published by -// the Free Software Foundation, either version 3 of the License, or -// (at your option) any later version. -// -// TikZiT is distributed in the hope that it will be useful, -// but WITHOUT ANY WARRANTY; without even the implied warranty of -// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -// GNU General Public License for more details. -// -// You should have received a copy of the GNU General Public License -// along with TikZiT. If not, see <http://www.gnu.org/licenses/>. -// - -#import "Edge.h" -#import "Shape.h" -#import "util.h" - -@implementation Edge - -- (id)init { - self = [super init]; - if (self) { - data = [[GraphElementData alloc] init]; - bend = 0; - inAngle = 135; - outAngle = 45; - bendMode = EdgeBendModeBasic; - weight = 0.4f; - dirty = YES; - source = nil; - target = nil; - edgeNode = nil; - sourceAnchor = @""; - targetAnchor = @""; - } - return self; -} - -- (id)initWithSource:(Node*)s andTarget:(Node*)t { - self = [self init]; - if (self) { - [self setSource:s]; - [self setTarget:t]; - edgeNode = nil; - - dirty = YES; - } - return self; -} - -- (BOOL)attachStyleFromTable:(NSArray*)styles { - NSString *style_name = [data propertyForKey:@"style"]; - - [self setStyle:nil]; - if (style_name == nil) return YES; - - for (EdgeStyle *s in styles) { - if ([[s name] compare:style_name]==NSOrderedSame) { - [self setStyle:s]; - return YES; - } - } - - // if we didn't find a style, fill in a default one - style = [[EdgeStyle defaultEdgeStyleWithName:style_name] retain]; - return NO; -} - -- (NSPoint) _findContactPointOn:(Node*)node at:(float)angle { - NSPoint rayStart = [node point]; - Shape *shape = [node shape]; - if (shape == nil) { - return rayStart; - } - - Transformer *shapeTrans = [node shapeTransformer]; - // rounding errors are a pain - NSRect searchArea = NSInsetRect([node boundsUsingShapeTransform:shapeTrans],-0.01,-0.01); - if (!NSPointInRect(rayStart, searchArea)) { - return rayStart; - } - - NSPoint rayEnd = findExitPointOfRay (rayStart, angle, searchArea); - - for (NSArray *path in [shape paths]) { - for (Edge *curve in path) { - NSPoint intersect; - [curve updateControls]; - if (lineSegmentIntersectsBezier (rayStart, rayEnd, - [shapeTrans toScreen:curve->tail], - [shapeTrans toScreen:curve->cp1], - [shapeTrans toScreen:curve->cp2], - [shapeTrans toScreen:curve->head], - &intersect)) { - // we just keep shortening the line - rayStart = intersect; - } - } - } - - return rayStart; -} - -- (NSPoint) _findTanFor:(NSPoint)pt usingSpanFrom:(float)t1 to:(float)t2 { - float dx = bezierInterpolate(t2, tail.x, cp1.x, cp2.x, head.x) - - bezierInterpolate(t1, tail.x, cp1.x, cp2.x, head.x); - float dy = bezierInterpolate(t2, tail.y, cp1.y, cp2.y, head.y) - - bezierInterpolate(t1, tail.y, cp1.y, cp2.y, head.y); - - // normalise - float len = sqrt(dx*dx+dy*dy); - if (len != 0) { - dx = (dx/len) * 0.1f; - dy = (dy/len) * 0.1f; - } - - return NSMakePoint (pt.x + dx, pt.y + dy); -} - -- (void)updateControls { - // check for external modification to the node locations - if (src.x != [source point].x || src.y != [source point].y || - targ.x != [target point].x || targ.y != [target point].y) - { - dirty = YES; - } - - if (dirty) { - src = [source point]; - targ = [target point]; - - float dx = (targ.x - src.x); - float dy = (targ.y - src.y); - - float angleSrc = 0.0f; - float angleTarg = 0.0f; - - if (bendMode == EdgeBendModeBasic) { - float angle = good_atan(dx, dy); - float bnd = (float)bend * (M_PI / 180.0f); - angleSrc = angle - bnd; - angleTarg = M_PI + angle + bnd; - } else if (bendMode == EdgeBendModeInOut) { - angleSrc = (float)outAngle * (M_PI / 180.0f); - angleTarg = (float)inAngle * (M_PI / 180.0f); - } - - tail = [self _findContactPointOn:source at:angleSrc]; - head = [self _findContactPointOn:target at:angleTarg]; - - // give a default distance for self-loops - float cdist = (dx==0.0f && dy==0.0f) ? weight : sqrt(dx*dx + dy*dy) * weight; - - cp1 = NSMakePoint(src.x + (cdist * cos(angleSrc)), - src.y + (cdist * sin(angleSrc))); - - cp2 = NSMakePoint(targ.x + (cdist * cos(angleTarg)), - targ.y + (cdist * sin(angleTarg))); - - mid = bezierInterpolateFull (0.5f, tail, cp1, cp2, head); - midTan = [self _findTanFor:mid usingSpanFrom:0.4f to:0.6f]; - - tailTan = [self _findTanFor:tail usingSpanFrom:0.0f to:0.1f]; - headTan = [self _findTanFor:head usingSpanFrom:1.0f to:0.9f]; - } - dirty = NO; -} - -- (void)convertBendToAngles { - float dx = (targ.x - src.x); - float dy = (targ.y - src.y); - float angle = good_atan(dx, dy); - float bnd = (float)bend * (M_PI / 180.0f); - - [self setOutAngle:round((angle - bnd) * (180.0f/M_PI))]; - [self setInAngle:round((M_PI + angle + bnd) * (180.0f/M_PI))]; - dirty = YES; -} - -- (void)convertAnglesToBend { - float dx = (targ.x - src.x); - float dy = (targ.y - src.y); - int angle = round((180.0f/M_PI) * good_atan(dx, dy)); - - // compute bend1 and bend2 to match inAngle and outAngle, resp. - int bend1, bend2; - - bend1 = outAngle - angle; - bend2 = angle - inAngle; - - [self setBend:(bend1 + bend2) / 2]; -} - -- (BOOL)isSelfLoop { - return (source == target); -} - -- (BOOL)isStraight { - return (bendMode == EdgeBendModeBasic && bend == 0); -} - -- (NSPoint)mid { - [self updateControls]; - return mid; -} - -- (NSPoint)midTan { - [self updateControls]; - return midTan; -} - -- (NSPoint)leftNormal { - [self updateControls]; - return NSMakePoint(mid.x + (mid.y - midTan.y), mid.y - (mid.x - midTan.x)); -} - -- (NSPoint)rightNormal { - [self updateControls]; - return NSMakePoint(mid.x - (mid.y - midTan.y), mid.y + (mid.x - midTan.x)); -} - -- (NSPoint)headTan { - [self updateControls]; - return headTan; -} - -- (NSPoint)leftHeadNormal { - [self updateControls]; - return NSMakePoint(headTan.x + (head.y - headTan.y), headTan.y - (head.x - headTan.x)); -} - -- (NSPoint)rightHeadNormal { - [self updateControls]; - return NSMakePoint(headTan.x - (head.y - headTan.y), headTan.y + (head.x - headTan.x)); -} - -- (NSPoint)tailTan { - [self updateControls]; - return tailTan; -} - -- (NSPoint)leftTailNormal { - [self updateControls]; - return NSMakePoint(tailTan.x + (tail.y - tailTan.y), tailTan.y - (tail.x - tailTan.x)); -} - -- (NSPoint)rightTailNormal { - [self updateControls]; - return NSMakePoint(tailTan.x - (tail.y - tailTan.y), tailTan.y + (tail.x - tailTan.x)); -} - -- (NSPoint) head { - [self updateControls]; - return head; -} - -- (NSPoint) tail { - [self updateControls]; - return tail; -} - -- (NSPoint)cp1 { - [self updateControls]; - return cp1; -} - -- (NSPoint)cp2 { - [self updateControls]; - return cp2; -} - -- (int)inAngle {return inAngle;} -- (void)setInAngle:(int)a { - inAngle = normaliseAngleDeg (a); - dirty = YES; -} - -- (int)outAngle {return outAngle;} -- (void)setOutAngle:(int)a { - outAngle = normaliseAngleDeg (a); - dirty = YES; -} - -- (EdgeBendMode)bendMode {return bendMode;} -- (void)setBendMode:(EdgeBendMode)mode { - bendMode = mode; - dirty = YES; -} - -- (int)bend {return bend;} -- (void)setBend:(int)b { - bend = normaliseAngleDeg (b); - dirty = YES; -} - -- (float)weight {return weight;} -- (void)setWeight:(float)w { -// if (source == target) weight = 1.0f; -// else weight = w; - weight = w; - dirty = YES; -} - -- (EdgeStyle*)style {return style;} -- (void)setStyle:(EdgeStyle*)s { - if (style != s) { - [style release]; - style = [s retain]; - } -} - -- (Node*)source {return source;} -- (void)setSource:(Node *)s { - if (source != s) { - [source removeObserver:self - forKeyPath:@"style"]; - - [source release]; - source = [s retain]; - - if (source==target) { - bendMode = EdgeBendModeInOut; - weight = 1.0f; - } - - [source addObserver:self - forKeyPath:@"style" - options:NSKeyValueObservingOptionNew - context:NULL]; - - dirty = YES; - } -} - -- (Node*)target {return target;} -- (void)setTarget:(Node *)t { - if (target != t) { - [target removeObserver:self - forKeyPath:@"style"]; - - [target release]; - target = [t retain]; - - if (source==target) { - bendMode = EdgeBendModeInOut; - weight = 1.0f; - } - - [target addObserver:self - forKeyPath:@"style" - options:NSKeyValueObservingOptionNew - context:NULL]; - - dirty = YES; - } -} - -- (void)observeValueForKeyPath:(NSString *)keyPath - ofObject:(id)object - change:(NSDictionary *)change - context:(void *)context - -{ - dirty = YES; -} - - -// edgeNode and hasEdgeNode use a bit of key-value observing to help the mac GUI keep up - -- (Node*)edgeNode {return edgeNode;} -- (void)setEdgeNode:(Node *)n { - [self willChangeValueForKey:@"edgeNode"]; - [self willChangeValueForKey:@"hasEdgeNode"]; - if (edgeNode != n) { - hasEdgeNode = (n != nil); - [edgeNode release]; - edgeNode = [n retain]; - // don't set dirty bit, because control points don't need update - } - [self didChangeValueForKey:@"edgeNode"]; - [self didChangeValueForKey:@"hasEdgeNode"]; -} - -- (BOOL)hasEdgeNode { return hasEdgeNode; } -- (void)setHasEdgeNode:(BOOL)b { - [self willChangeValueForKey:@"edgeNode"]; - [self willChangeValueForKey:@"hasEdgeNode"]; - hasEdgeNode = b; - if (hasEdgeNode && edgeNode == nil) { - edgeNode = [[Node alloc] init]; - } - [self didChangeValueForKey:@"edgeNode"]; - [self didChangeValueForKey:@"hasEdgeNode"]; -} - -- (NSString*) sourceAnchor { return sourceAnchor; } -- (void)setSourceAnchor:(NSString *)_sourceAnchor{ - NSString *oldSourceAnchor = sourceAnchor; - if(_sourceAnchor != nil){ - sourceAnchor = [_sourceAnchor copy]; - }else{ - sourceAnchor = @""; - } - [oldSourceAnchor release]; -} - -- (NSString*) targetAnchor { return targetAnchor; } -- (void)setTargetAnchor:(NSString *)_targetAnchor{ - NSString *oldTargetAnchor = targetAnchor; - if(_targetAnchor != nil){ - targetAnchor = [_targetAnchor copy]; - }else{ - targetAnchor = @""; - } - [oldTargetAnchor release]; -} - -@synthesize data; -- (void) insertObject:(GraphElementProperty*)gep - inDataAtIndex:(NSUInteger)index { - [data insertObject:gep atIndex:index]; -} -- (void) removeObjectFromDataAtIndex:(NSUInteger)index { - [data removeObjectAtIndex:index]; -} -- (void) replaceObjectInDataAtIndex:(NSUInteger)index - withObject:(GraphElementProperty*)gep { - [data replaceObjectAtIndex:index withObject:gep]; -} - -- (void)updateData { - // unset everything to avoid redundant defs - [data unsetAtom:@"loop"]; - [data unsetProperty:@"in"]; - [data unsetProperty:@"out"]; - [data unsetAtom:@"bend left"]; - [data unsetAtom:@"bend right"]; - [data unsetProperty:@"bend left"]; - [data unsetProperty:@"bend right"]; - [data unsetProperty:@"looseness"]; - - if (style == nil) { - [data unsetProperty:@"style"]; - } else { - [data setProperty:[style name] forKey:@"style"]; - } - - if (bendMode == EdgeBendModeBasic && bend != 0) { - NSString *bendkey = @"bend right"; - int b = [self bend]; - if (b < 0) { - bendkey = @"bend left"; - b = -b; - } - - if (b == 30) { - [data setAtom:bendkey]; - } else { - [data setProperty:[NSString stringWithFormat:@"%d",b] forKey:bendkey]; - } - - } else if (bendMode == EdgeBendModeInOut) { - [data setProperty:[NSString stringWithFormat:@"%d",inAngle] - forKey:@"in"]; - [data setProperty:[NSString stringWithFormat:@"%d",outAngle] - forKey:@"out"]; - } - - // loop needs to come after in/out - if (source == target) [data setAtom:@"loop"]; - - if (![self isSelfLoop] && ![self isStraight]) - { - [data setProperty:[NSString stringWithFormat:@"%.2f",weight*2.5f] - forKey:@"looseness"]; - } -} - -- (void)setAttributesFromData { - bendMode = EdgeBendModeBasic; - - if ([data isAtomSet:@"bend left"]) { - [self setBend:-30]; - } else if ([data isAtomSet:@"bend right"]) { - [self setBend:30]; - } else if ([data propertyForKey:@"bend left"] != nil) { - NSString *bnd = [data propertyForKey:@"bend left"]; - [self setBend:-[bnd intValue]]; - } else if ([data propertyForKey:@"bend right"] != nil) { - NSString *bnd = [data propertyForKey:@"bend right"]; - [self setBend:[bnd intValue]]; - } else { - [self setBend:0]; - - if ([data propertyForKey:@"in"] != nil && [data propertyForKey:@"out"] != nil) { - bendMode = EdgeBendModeInOut; - [self setInAngle:[[data propertyForKey:@"in"] intValue]]; - [self setOutAngle:[[data propertyForKey:@"out"] intValue]]; - } - } - - if ([data propertyForKey:@"looseness"] != nil) { - weight = [[data propertyForKey:@"looseness"] floatValue] / 2.5f; - } else { - weight = ([self isSelfLoop]) ? 1.0f : 0.4f; - } -} - -- (void)setPropertiesFromEdge:(Edge*)e { - Node *en = [[e edgeNode] copy]; - [self setEdgeNode:en]; - [en release]; - - GraphElementData *d = [[e data] copy]; - [self setData:d]; - [d release]; - - [self setStyle:[e style]]; - [self setBend:[e bend]]; - [self setInAngle:[e inAngle]]; - [self setOutAngle:[e outAngle]]; - [self setBendMode:[e bendMode]]; - [self setWeight:[e weight]]; - - dirty = YES; // cached data will be recomputed lazily, rather than copied -} - -- (NSRect)boundingRect { - [self updateControls]; - NSRect bound = NSRectAround4Points(head, tail, cp1, cp2); - if ([self style] != nil) { - switch ([[self style] decorationStyle]) { - case ED_Arrow: - bound = NSRectWithPoint(bound, [self midTan]); - case ED_Tick: - bound = NSRectWithPoint(bound, [self leftNormal]); - bound = NSRectWithPoint(bound, [self rightNormal]); - case ED_None: - break; - } - if ([[self style] headStyle] != AH_None) { - bound = NSRectWithPoint(bound, [self leftHeadNormal]); - bound = NSRectWithPoint(bound, [self rightHeadNormal]); - } - if ([[self style] tailStyle] != AH_None) { - bound = NSRectWithPoint(bound, [self leftTailNormal]); - bound = NSRectWithPoint(bound, [self rightTailNormal]); - } - } - return bound; -} - -- (void) adjustWeight:(float)handle_dist withCourseness:(float)wcourseness { - float base_dist = NSDistanceBetweenPoints (src, targ); - if (base_dist == 0.0f) { - base_dist = 1.0f; - } - - [self setWeight:roundToNearest(wcourseness, handle_dist / base_dist)]; -} - -- (float) angleOf:(NSPoint)point relativeTo:(NSPoint)base { - float dx = point.x - base.x; - float dy = point.y - base.y; - return radiansToDegrees (good_atan(dx, dy)); -} - -- (void) moveCp1To:(NSPoint)point withWeightCourseness:(float)wc andBendCourseness:(int)bc forceLinkControlPoints:(BOOL)link { - [self updateControls]; - [self adjustWeight:NSDistanceBetweenPoints (point, src) withCourseness:wc]; - - float control_angle = [self angleOf:point relativeTo:src]; - if (bendMode == EdgeBendModeBasic) { - float base_angle = [self angleOf:targ relativeTo:src]; - int b = (int)roundToNearest (bc, base_angle - control_angle); - [self setBend:b]; - } else { - int angle = (int)roundToNearest (bc, control_angle); - if (link) { - [self setInAngle:(inAngle + angle - outAngle)]; - } - [self setOutAngle:angle]; - } -} - -- (void) moveCp1To:(NSPoint)point { - [self moveCp1To:point withWeightCourseness:0.0f andBendCourseness:0 forceLinkControlPoints:NO]; -} - -- (void) moveCp2To:(NSPoint)point withWeightCourseness:(float)wc andBendCourseness:(int)bc forceLinkControlPoints:(BOOL)link { - [self updateControls]; - - if (![self isSelfLoop]) { - [self adjustWeight:NSDistanceBetweenPoints (point, targ) withCourseness:wc]; - } - - float control_angle = [self angleOf:point relativeTo:targ]; - if (bendMode == EdgeBendModeBasic) { - float base_angle = [self angleOf:src relativeTo:targ]; - int b = (int)roundToNearest (bc, control_angle - base_angle); - [self setBend:b]; - } else { - int angle = (int)roundToNearest (bc, control_angle); - if (link) { - [self setOutAngle:(outAngle + angle - inAngle)]; - } - [self setInAngle: angle]; - } -} - -- (void) moveCp2To:(NSPoint)point { - [self moveCp2To:point withWeightCourseness:0.0f andBendCourseness:0 forceLinkControlPoints:NO]; -} - -- (void)reverse { - Node *n; - float f; - - n = source; - source = target; - target = n; - - f = inAngle; - inAngle = outAngle; - outAngle = f; - - [self setBend:-bend]; - - dirty = YES; -} - -- (void)dealloc { - [source removeObserver:self - forKeyPath:@"style"]; - [target removeObserver:self - forKeyPath:@"style"]; - [source release]; - [target release]; - [data release]; - [sourceAnchor release]; - [targetAnchor release]; - [super dealloc]; -} - -- (id)copyWithZone:(NSZone*)zone { - Edge *cp = [[Edge allocWithZone:zone] init]; - [cp setSource:[self source]]; - [cp setTarget:[self target]]; - [cp setPropertiesFromEdge:self]; - return cp; -} - -+ (Edge*)edge { - return [[[Edge alloc] init] autorelease]; -} - -+ (Edge*)edgeWithSource:(Node*)s andTarget:(Node*)t { - return [[[Edge alloc] initWithSource:s andTarget:t] autorelease]; -} - -@end - -// vi:ft=objc:ts=4:noet:sts=4:sw=4 diff --git a/tikzit/src/common/EdgeStyle.h b/tikzit/src/common/EdgeStyle.h deleted file mode 100644 index a51f129..0000000 --- a/tikzit/src/common/EdgeStyle.h +++ /dev/null @@ -1,71 +0,0 @@ -// -// EdgeStyle.h -// TikZiT -// -// Copyright 2011 Aleks Kissinger. All rights reserved. -// -// -// This file is part of TikZiT. -// -// TikZiT is free software: you can redistribute it and/or modify -// it under the terms of the GNU General Public License as published by -// the Free Software Foundation, either version 3 of the License, or -// (at your option) any later version. -// -// TikZiT is distributed in the hope that it will be useful, -// but WITHOUT ANY WARRANTY; without even the implied warranty of -// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -// GNU General Public License for more details. -// -// You should have received a copy of the GNU General Public License -// along with TikZiT. If not, see <http://www.gnu.org/licenses/>. -// - -#import <Foundation/Foundation.h> -#import "PropertyHolder.h" -#import "ColorRGB.h" - -typedef enum { - AH_None = 0, - AH_Plain = 1, - AH_Latex = 2 -} ArrowHeadStyle; - -typedef enum { - ED_None = 0, - ED_Arrow = 1, - ED_Tick = 2 -} EdgeDectorationStyle; - -@interface EdgeStyle : PropertyHolder <NSCopying> { - ArrowHeadStyle headStyle, tailStyle; - EdgeDectorationStyle decorationStyle; - float thickness; - ColorRGB *colorRGB; - NSString *name; - NSString *category; -} - -/*! - @property colorRGB - @brief The color to render the line in - */ -@property (copy) ColorRGB *colorRGB; - -@property (copy) NSString *name; -@property (copy) NSString *category; -@property (assign) ArrowHeadStyle headStyle; -@property (assign) ArrowHeadStyle tailStyle; -@property (assign) EdgeDectorationStyle decorationStyle; -@property (assign) float thickness; - -@property (readonly) NSString *tikz; - -- (id)init; -- (id)initWithName:(NSString*)nm; -+ (EdgeStyle*)defaultEdgeStyleWithName:(NSString*)nm; -- (void) updateFromStyle:(EdgeStyle*)style; - -@end - -// vi:ft=objc:noet:ts=4:sts=4:sw=4 diff --git a/tikzit/src/common/EdgeStyle.m b/tikzit/src/common/EdgeStyle.m deleted file mode 100644 index 15fbff8..0000000 --- a/tikzit/src/common/EdgeStyle.m +++ /dev/null @@ -1,206 +0,0 @@ -// -// EdgeStyle.m -// TikZiT -// -// Copyright 2011 Aleks Kissinger. All rights reserved. -// -// -// This file is part of TikZiT. -// -// TikZiT is free software: you can redistribute it and/or modify -// it under the terms of the GNU General Public License as published by -// the Free Software Foundation, either version 3 of the License, or -// (at your option) any later version. -// -// TikZiT is distributed in the hope that it will be useful, -// but WITHOUT ANY WARRANTY; without even the implied warranty of -// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -// GNU General Public License for more details. -// -// You should have received a copy of the GNU General Public License -// along with TikZiT. If not, see <http://www.gnu.org/licenses/>. -// - -#import "EdgeStyle.h" - -@implementation EdgeStyle - -+ (void)initialize { - [self setKeys:[NSArray arrayWithObjects: - @"tailStyle", - @"headStyle", - @"decorationStyle", - @"thickness", - @"colorRGB.red", - @"colorRGB.blue", - @"colorRGB.green", - @"name", - nil] - triggerChangeNotificationsForDependentKey:@"tikz"]; - [self setKeys:[NSArray arrayWithObjects: - @"colorRGB.name", - nil] - triggerChangeNotificationsForDependentKey:@"colorIsKnown"]; -} - -- (id)initWithName:(NSString*)nm { - self = [super initWithNotificationName:@"EdgeStylePropertyChanged"]; - - if (self != nil) { - headStyle = AH_None; - tailStyle = AH_None; - decorationStyle = ED_None; - colorRGB = [[ColorRGB alloc] initWithRed:0 green:0 blue:0]; - name = nm; - category = nil; - thickness = 1.0f; - } - - return self; -} - -- (id)init { - self = [self initWithName:@"new"]; - return self; -} - -- (id)copyWithZone:(NSZone*)zone { - EdgeStyle *style = [[EdgeStyle allocWithZone:zone] init]; - [style setName:[self name]]; - [style setCategory:[self category]]; - [style setHeadStyle:[self headStyle]]; - [style setTailStyle:[self tailStyle]]; - [style setDecorationStyle:[self decorationStyle]]; - [style setThickness:[self thickness]]; - [style setColorRGB:[self colorRGB]]; - return style; -} - -- (void)dealloc { - [name release]; - [category release]; - [colorRGB release]; - [super dealloc]; -} - -- (void) updateFromStyle:(EdgeStyle*)style { - [self setName:[style name]]; - [self setCategory:[style category]]; - [self setHeadStyle:[style headStyle]]; - [self setTailStyle:[style tailStyle]]; - [self setDecorationStyle:[style decorationStyle]]; - [self setThickness:[style thickness]]; - [self setColorRGB:[style colorRGB]]; -} - -+ (EdgeStyle*)defaultEdgeStyleWithName:(NSString*)nm { - return [[[EdgeStyle alloc] initWithName:nm] autorelease]; -} - -- (NSString*)name { return name; } -- (void)setName:(NSString *)s { - if (name != s) { - NSString *oldValue = name; - name = [s copy]; - [self postPropertyChanged:@"name" oldValue:oldValue]; - [oldValue release]; - } -} - -- (ArrowHeadStyle)headStyle { return headStyle; } -- (void)setHeadStyle:(ArrowHeadStyle)s { - ArrowHeadStyle oldValue = headStyle; - headStyle = s; - [self postPropertyChanged:@"headStyle" oldValue:[NSNumber numberWithInt:oldValue]]; -} - -- (ArrowHeadStyle)tailStyle { return tailStyle; } -- (void)setTailStyle:(ArrowHeadStyle)s { - ArrowHeadStyle oldValue = tailStyle; - tailStyle = s; - [self postPropertyChanged:@"tailStyle" oldValue:[NSNumber numberWithInt:oldValue]]; -} - -- (EdgeDectorationStyle)decorationStyle { return decorationStyle; } -- (void)setDecorationStyle:(EdgeDectorationStyle)s { - EdgeDectorationStyle oldValue = decorationStyle; - decorationStyle = s; - [self postPropertyChanged:@"decorationStyle" oldValue:[NSNumber numberWithInt:oldValue]]; -} -- (float)thickness { return thickness; } -- (void)setThickness:(float)s { - float oldValue = thickness; - thickness = s; - [self postPropertyChanged:@"thickness" oldValue:[NSNumber numberWithFloat:oldValue]]; -} - -- (NSString*)category { - return category; -} - -- (void)setCategory:(NSString *)s { - if (category != s) { - NSString *oldValue = category; - category = [s copy]; - [self postPropertyChanged:@"category" oldValue:oldValue]; - [oldValue release]; - } -} - -- (ColorRGB*)colorRGB { - return colorRGB; -} - -- (void)setColorRGB:(ColorRGB*)c { - if (colorRGB != c) { - ColorRGB *oldValue = colorRGB; - colorRGB = [c copy]; - [self postPropertyChanged:@"colorRGB" oldValue:oldValue]; - [oldValue release]; - } -} - -- (NSString*)tikz { - NSMutableString *buf = [NSMutableString stringWithFormat:@"\\tikzstyle{%@}=[", name]; - - NSString *colorName = [colorRGB name]; - if (colorName == nil) - colorName = [colorRGB hexName]; - - if (tailStyle == AH_Plain) - [buf appendString:@"<"]; - else if (tailStyle == AH_Latex) - [buf appendString:@"latex"]; - - [buf appendString:@"-"]; - - if (headStyle == AH_Plain) - [buf appendString:@">"]; - else if (headStyle == AH_Latex) - [buf appendString:@"latex"]; - - if(colorName != nil){ - [buf appendString:@",draw="]; - [buf appendString:colorName]; - } - - if (decorationStyle != ED_None) { - [buf appendString:@",postaction={decorate},decoration={markings,mark="]; - if (decorationStyle == ED_Arrow) - [buf appendString:@"at position .5 with {\\arrow{>}}"]; - else if (decorationStyle == ED_Tick) - [buf appendString:@"at position .5 with {\\draw (0,-0.1) -- (0,0.1);}"]; - [buf appendString:@"}"]; - } - - if (thickness != 1.0f) { - [buf appendFormat:@",line width=%.3f", thickness]; - } - - [buf appendString:@"]"]; - return buf; -} - -@end - -// vi:ft=objc:ts=4:noet:sts=4:sw=4 diff --git a/tikzit/src/common/Graph.h b/tikzit/src/common/Graph.h deleted file mode 100644 index 1f98858..0000000 --- a/tikzit/src/common/Graph.h +++ /dev/null @@ -1,401 +0,0 @@ -// -// Graph.h -// TikZiT -// -// Copyright 2010 Aleks Kissinger. All rights reserved. -// -// -// This file is part of TikZiT. -// -// TikZiT is free software: you can redistribute it and/or modify -// it under the terms of the GNU General Public License as published by -// the Free Software Foundation, either version 3 of the License, or -// (at your option) any later version. -// -// TikZiT is distributed in the hope that it will be useful, -// but WITHOUT ANY WARRANTY; without even the implied warranty of -// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -// GNU General Public License for more details. -// -// You should have received a copy of the GNU General Public License -// along with TikZiT. If not, see <http://www.gnu.org/licenses/>. -// - - -/*! - - @mainpage TikZiT - TikZiT is a GUI application for drawing, editing, and parsing TikZ - diagrams. Common code is in src/common, and plaform-specific code is - in src/{osx,linux}. - - */ - - -#import "Node.h" -#import "Edge.h" -#import "GraphChange.h" -#import "Transformer.h" - -/*! - @class Graph - @brief Store a graph, output to TikZ. - @details All of the methods that change a graph return an object of type GraphChange. - Graph changes can be re-done by calling applyGraphChange. They can be undone - by calling applyGraphChange on [change inverse]. - */ -@interface Graph : NSObject <NSCopying> { - NSRecursiveLock *graphLock; - BOOL dirty; // keep track of when inEdges and outEdges need an update - NSMutableArray *nodes; - NSMutableArray *edges; - - NSMapTable *inEdges; - NSMapTable *outEdges; - - GraphElementData *data; - NSRect boundingBox; -} - -/*! - @property data - @brief Data associated with the graph. - */ -@property (copy) GraphElementData *data; - -// KVC methods -- (void) insertObject:(GraphElementProperty*)gep - inDataAtIndex:(NSUInteger)index; -- (void) removeObjectFromDataAtIndex:(NSUInteger)index; -- (void) replaceObjectInDataAtIndex:(NSUInteger)index - withObject:(GraphElementProperty*)gep; - -/*! - @property nodes - @brief The set of nodes. - @details The node set is cached internally, so no need to lock - the graph when enumerating. - */ -@property (readonly) NSArray *nodes; - -/*! - @property edges - @brief The set of edges. - @details The edge set is cached internally, so no need to lock - the graph when enumerating. - */ -@property (readonly) NSArray *edges; - -/*! - @property boundingBox - @brief The bounding box of a graph - @details Optional data containing the bounding box, set with - \path [use as bounding box] .... - */ -@property (assign) NSRect boundingBox; - -/*! - @property hasBoundingBox - @brief Returns true if this graph has a bounding box. - */ -@property (readonly) BOOL hasBoundingBox; - - -/*! - @brief Computes graph bounds. - @result Graph bounds. - */ -- (NSRect)bounds; - -/*! - @brief Returns the set of edges incident to the given node set. - @param nds a set of nodes. - @result A set of incident edges. - */ -- (NSSet*)incidentEdgesForNodes:(NSSet*)nds; - -/*! - @brief Returns the set of in-edges for this node. - @param nd a node. - @result A set of edges. -*/ -- (NSSet*)inEdgesForNode:(Node*)nd; - -/*! - @brief Returns the set of out-edges for this node. - @param nd a node. - @result A set of edges. -*/ -- (NSSet*)outEdgesForNode:(Node*)nd; - -/*! - @brief Gives a copy of the full subgraph with the given nodes. - @param nds a set of nodes. - @result A subgraph. - */ -- (Graph*)copyOfSubgraphWithNodes:(NSSet*)nds; - -/*! - @brief Gives a copy of the full subgraph with the given nodes. - @param nds a set of nodes. - @param zone an allocation zone - @result A subgraph. - */ -- (Graph*)copyOfSubgraphWithNodes:(NSSet*)nds zone:(NSZone*)zone; - -/*! - @brief Gives a set of edge-arrays that partition all of the edges in the graph. - @result An NSet of NSArrays of edges. - */ -- (NSSet*)pathCover; - -/*! - @brief Adds a node. - @param node - @result A <tt>GraphChange</tt> recording this action. - */ -- (GraphChange*)addNode:(Node*)node; - -/*! - @brief Removes a node. - @param node - @result A <tt>GraphChange</tt> recording this action. - */ -- (GraphChange*)removeNode:(Node*)node; - -/*! - @brief Removes a set of nodes. - @param nds a set of nodes - @result A <tt>GraphChange</tt> recording this action. - */ -- (GraphChange*)removeNodes:(NSSet *)nds; - -/*! - @brief Adds an edge. - @param edge - @result A <tt>GraphChange</tt> recording this action. - */ -- (GraphChange*)addEdge:(Edge*)edge; - -/*! - @brief Removed an edge. - @param edge - @result A <tt>GraphChange</tt> recording this action. - */ -- (GraphChange*)removeEdge:(Edge*)edge; - -/*! - @brief Removes a set of edges. - @param es a set of edges. - @result A <tt>GraphChange</tt> recording this action. - */ -- (GraphChange*)removeEdges:(NSSet *)es; - -/*! - @brief Convenience function, intializes an edge with the given - source and target and adds it. - @param source the source of the edge. - @param target the target of the edge. - @result A <tt>GraphChange</tt> recording this action. - */ -- (GraphChange*)addEdgeFrom:(Node*)source to:(Node*)target; - -/*! - @brief Return the z-index for a given node (lower is farther back). - @param node a node in the graph - @result An <tt>int</tt> - */ -- (int)indexOfNode:(Node*)node; - -/*! - @brief Set the z-index for a given node (lower is farther back). - @param idx a new z-index - @param node a node in the graph - */ -- (void)setIndex:(int)idx ofNode:(Node*)node; - -/*! - @brief Bring set of nodes forward by one. - @param nodeSet a set of nodes - */ -- (GraphChange*)bringNodesForward:(NSSet*)nodeSet; - -/*! - @brief Bring set of nodes to the front. - @param nodeSet a set of nodes - */ -- (GraphChange*)bringNodesToFront:(NSSet*)nodeSet; - -/*! - @brief Bring set of edges to the front. - @param edgeSet a set of edges - */ -- (GraphChange*)bringEdgesToFront:(NSSet*)edgeSet; - -/*! - @brief Bring set of edges forward by one. - @param edgeSet a set of edges - */ -- (GraphChange*)bringEdgesForward:(NSSet*)edgeSet; - -/*! - @brief Send set of nodes backward by one. - @param nodeSet a set of nodes - */ -- (GraphChange*)sendNodesBackward:(NSSet*)nodeSet; - -/*! - @brief Send set of edges backward by one. - @param edgeSet a set of edges - */ -- (GraphChange*)sendEdgesBackward:(NSSet*)edgeSet; - -/*! - @brief Send set of nodes to back. - @param nodeSet a set of nodes - */ -- (GraphChange*)sendNodesToBack:(NSSet*)nodeSet; - -/*! - @brief Send set of edges to back. - @param edgeSet a set of edges - */ -- (GraphChange*)sendEdgesToBack:(NSSet*)edgeSet; - - -/*! - @brief Transform every node in the graph to screen space. - @param t a transformer - */ -- (void)applyTransformer:(Transformer*)t; - -/*! - @brief Shift nodes by a given distance. - @param ns a set of nodes. - @param p an x and y distance, given as an NSPoint. - @result A <tt>GraphChange</tt> recording this action. - */ -- (GraphChange*)shiftNodes:(id<NSFastEnumeration>)ns byPoint:(NSPoint)p; - -/*! - @brief Reverse the given edges - @param es the edges to reverse - @result A <tt>GraphChange</tt> recording this action. - */ -- (GraphChange*)reverseEdges:(NSSet *)es; - -/*! - @brief Insert the given graph into this one. Used for copy - and paste. - @param g a graph. - @result A <tt>GraphChange</tt> recording this action. - */ -- (GraphChange*)insertGraph:(Graph*)g; - -/*! - @brief Flip the subgraph defined by the given node set - horizontally. - @param nds a set of nodes. - @result A <tt>GraphChange</tt> recording this action. - */ -- (GraphChange*)flipHorizontalNodes:(NSSet*)nds; - -/*! - @brief Flip the subgraph defined by the given node set - vertically. - @param nds a set of nodes. - @result A <tt>GraphChange</tt> recording this action. - */ -- (GraphChange*)flipVerticalNodes:(NSSet*)nds; - -/*! - @brief Apply a graph change. - @details An undo manager should maintain a stack of GraphChange - objects returned. To undo a GraphChange, call this method - with <tt>[change inverse]</tt> as is argument. - @param ch a graph change. - */ -- (void)applyGraphChange:(GraphChange*)ch; - -/*! - @brief The TikZ representation of this graph. - @details The TikZ representation of this graph. The TikZ code should - contain enough data to totally reconstruct the graph. - @result A string containing TikZ code. - */ -- (NSString*)tikz; - - -/*! - @brief Copy the node set and return a table of copies, whose - keys are the original nodes. This is used to save the state - of a set of nodes in a GraphChange. - @param nds a set of nodes. - @result A <tt>NSMapTable</tt> of node copies. - */ -+ (NSMapTable*)nodeTableForNodes:(NSSet*)nds; - -+ (NSMapTable*)nodeTableForNodes:(NSSet*)nds withZone:(NSZone*)zone; - -/*! - @brief Copy the edge set and return a table of copies, whose - keys are the original edges. This is used to save the state - of a set of edges in a GraphChange. - @param es a set of edges. - @result A <tt>NSMapTable</tt> of edge copies. - */ -+ (NSMapTable*)edgeTableForEdges:(NSSet*)es; - -+ (NSMapTable*)edgeTableForEdges:(NSSet*)es withZone:(NSZone*)zone; - -/*! - @brief Compute the bounds for a set of nodes. - @param nds an enumerable collection of nodes. - @result The bounds. - */ -+ (NSRect)boundsForNodes:(id<NSFastEnumeration>)nds; - -/*! - @brief Factory method for constructing graphs. - @result An empty graph. - */ -+ (Graph*)graph; - -/** - * Initialize an empty graph - */ -- (id)init; - -/** - * Constructs a graph from the given tikz code - * - * See TikzGraphAssembler for more information about the error argument. - */ -+ (Graph*)graphFromTikz:(NSString*)tikz error:(NSError**)e; - -/** - * Constructs a graph from the given tikz code - */ -+ (Graph*)graphFromTikz:(NSString*)tikz; - -/** - * Initialize an empty graph from the given tikz code - * - * Note that this may not return the same object it was called on, - * and will return nil if parsing failed. - * - * See TikzGraphAssembler for more information about the error argument. - */ -- (id)initFromTikz:(NSString*)tikz error:(NSError**)e; - -/** - * Initialize an empty graph from the given tikz code - * - * Note that this may not return the same object it was called on, - * and will return nil if parsing failed. - */ -- (id)initFromTikz:(NSString*)tikz; - -@end - -// vi:ft=objc:noet:ts=4:sts=4:sw=4 diff --git a/tikzit/src/common/Graph.m b/tikzit/src/common/Graph.m deleted file mode 100644 index 2a01bae..0000000 --- a/tikzit/src/common/Graph.m +++ /dev/null @@ -1,844 +0,0 @@ -// -// Graph.m -// TikZiT -// -// Copyright 2010 Aleks Kissinger. All rights reserved. -// -// -// This file is part of TikZiT. -// -// TikZiT is free software: you can redistribute it and/or modify -// it under the terms of the GNU General Public License as published by -// the Free Software Foundation, either version 3 of the License, or -// (at your option) any later version. -// -// TikZiT is distributed in the hope that it will be useful, -// but WITHOUT ANY WARRANTY; without even the implied warranty of -// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -// GNU General Public License for more details. -// -// You should have received a copy of the GNU General Public License -// along with TikZiT. If not, see <http://www.gnu.org/licenses/>. -// - -#import "Graph.h" -#import "TikzGraphAssembler.h" - -@implementation Graph - -- (id)init { - self = [super init]; - if (self != nil) { - data = [[GraphElementData alloc] init]; - boundingBox = NSMakeRect(0, 0, 0, 0); - graphLock = [[NSRecursiveLock alloc] init]; - nodes = [[NSMutableArray alloc] initWithCapacity:10]; - edges = [[NSMutableArray alloc] initWithCapacity:10]; - inEdges = nil; - outEdges = nil; - } - return self; -} - -- (id)initFromTikz:(NSString*)tikz error:(NSError**)e { - [self release]; - return [[TikzGraphAssembler parseTikz:tikz error:e] retain]; -} - -- (id)initFromTikz:(NSString*)tikz { - return [self initFromTikz:tikz error:NULL]; -} - -- (id) copyWithZone:(NSZone*)zone { - Graph *newGraph = [self copyOfSubgraphWithNodes:[NSSet setWithArray:nodes] zone:zone]; - [newGraph setData:[self data]]; - return newGraph; -} - -- (void)dealloc { - [graphLock lock]; - [inEdges release]; - [outEdges release]; - [edges release]; - [nodes release]; - [data release]; - [graphLock unlock]; - [graphLock release]; - - [super dealloc]; -} - -- (void)sync { - [graphLock lock]; - if (dirty) { - [inEdges release]; - [outEdges release]; - inEdges = [[NSMapTable alloc] initWithKeyOptions:NSMapTableStrongMemory valueOptions:NSMapTableStrongMemory capacity:10]; - outEdges = [[NSMapTable alloc] initWithKeyOptions:NSMapTableStrongMemory valueOptions:NSMapTableStrongMemory capacity:10]; - - NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init]; - - for (Edge *e in edges) { - NSMutableSet *ie = [inEdges objectForKey:[e target]]; - NSMutableSet *oe = [outEdges objectForKey:[e source]]; - - if (ie == nil) { - ie = [NSMutableSet setWithCapacity:4]; - [inEdges setObject:ie forKey:[e target]]; - } - - if (oe == nil) { - oe = [NSMutableSet setWithCapacity:4]; - [outEdges setObject:oe forKey:[e source]]; - } - - [ie addObject:e]; - [oe addObject:e]; - } - - [pool drain]; - - - dirty = NO; - } - [graphLock unlock]; -} - -@synthesize nodes; -@synthesize edges; - -@synthesize data; -- (void) insertObject:(GraphElementProperty*)gep - inDataAtIndex:(NSUInteger)index { - [data insertObject:gep atIndex:index]; -} -- (void) removeObjectFromDataAtIndex:(NSUInteger)index { - [data removeObjectAtIndex:index]; -} -- (void) replaceObjectInDataAtIndex:(NSUInteger)index - withObject:(GraphElementProperty*)gep { - [data replaceObjectAtIndex:index withObject:gep]; -} - -@synthesize boundingBox; - -- (NSRect)bounds { - [graphLock lock]; - NSRect b = [Graph boundsForNodes:nodes]; - [graphLock unlock]; - return b; -} - -- (BOOL)hasBoundingBox { - return !( - boundingBox.size.width == 0 && - boundingBox.size.height == 0 - ); -} - -- (NSSet*)inEdgesForNode:(Node*)nd { - [self sync]; - return [[[inEdges objectForKey:nd] retain] autorelease]; -} - -- (NSSet*)outEdgesForNode:(Node*)nd { - [self sync]; - return [[[outEdges objectForKey:nd] retain] autorelease]; -} - -- (NSSet*)incidentEdgesForNodes:(NSSet*)nds { - [self sync]; - - NSMutableSet *mset = [NSMutableSet setWithCapacity:10]; - for (Node *n in nds) { - [mset unionSet:[self inEdgesForNode:n]]; - [mset unionSet:[self outEdgesForNode:n]]; - } - - return mset; -} - -- (void)applyTransformer:(Transformer *)t { - [graphLock lock]; - for (Node *n in nodes) { - [n setPoint:[t toScreen:[n point]]]; - } - [graphLock unlock]; -} - -- (GraphChange*)addNode:(Node *)node{ - [graphLock lock]; - NSSet *addedNode; - - // addNode is a no-op if graph already contains node - if (![nodes containsObject:node]) { - [nodes addObject:node]; - dirty = YES; - addedNode = [NSSet setWithObject:node]; - } else { - addedNode = [NSSet set]; - } - [graphLock unlock]; - - return [GraphChange graphAdditionWithNodes:addedNode - edges:[NSSet set]]; -} - -- (GraphChange*)removeNode:(Node*)node { - [graphLock lock]; - NSMutableSet *affectedEdges = [NSMutableSet set]; - for (Edge *e in edges) { - if ([e source] == node || [e target] == node) { - [affectedEdges addObject:e]; - } - } - for (Edge *e in affectedEdges) { - [edges removeObject:e]; - } - [nodes removeObject:node]; - dirty = YES; - [graphLock unlock]; - - return [GraphChange graphDeletionWithNodes:[NSSet setWithObject:node] - edges:affectedEdges]; -} - -- (GraphChange*)removeNodes:(NSSet *)nds { - [graphLock lock]; - - Node *n; - Edge *e; - - NSMutableSet *affectedEdges = [NSMutableSet set]; - NSEnumerator *en = [edges objectEnumerator]; - while ((e = [en nextObject])) { - if ([nds containsObject:[e source]] || [nds containsObject:[e target]]) { - [affectedEdges addObject:e]; - } - } - - en = [affectedEdges objectEnumerator]; - while ((e = [en nextObject])) [edges removeObject:e]; - - en = [nds objectEnumerator]; - while ((n = [en nextObject])) [nodes removeObject:n]; - - dirty = YES; - [graphLock unlock]; - - return [GraphChange graphDeletionWithNodes:nds edges:affectedEdges]; -} - -- (GraphChange*)addEdge:(Edge*)edge { - [graphLock lock]; - NSSet *addedEdge; - - // addEdge is a no-op if graph already contains edge - if (![edges containsObject:edge]) { - [edges addObject:edge]; - dirty = YES; - addedEdge = [NSSet setWithObject:edge]; - } else { - addedEdge = [NSSet set]; - } - [graphLock unlock]; - - return [GraphChange graphAdditionWithNodes:[NSSet set] - edges:addedEdge]; -} - -- (GraphChange*)removeEdge:(Edge *)edge { - [graphLock lock]; - [edges removeObject:edge]; - dirty = YES; - [graphLock unlock]; - return [GraphChange graphDeletionWithNodes:[NSSet set] - edges:[NSSet setWithObject:edge]]; -} - -- (GraphChange*)removeEdges:(NSSet *)es { - [graphLock lock]; - - for (Edge *e in es) { - [edges removeObject:e]; - } - dirty = YES; - [graphLock unlock]; - return [GraphChange graphDeletionWithNodes:[NSSet set] edges:es]; -} - -- (GraphChange*)addEdgeFrom:(Node *)source to:(Node *)target { - return [self addEdge:[Edge edgeWithSource:source andTarget:target]]; -} - -- (GraphChange*)shiftNodes:(id<NSFastEnumeration>)ns byPoint:(NSPoint)p { - NSPoint newLoc; - NSMutableSet *nodeSet = [NSMutableSet setWithCapacity:5]; - for (Node *n in ns) { - newLoc = NSMakePoint([n point].x + p.x, [n point].y + p.y); - [n setPoint:newLoc]; - [nodeSet addObject:n]; - } - return [GraphChange shiftNodes:nodeSet byPoint:p]; -} - -- (GraphChange*)reverseEdges:(NSSet *)es { - [graphLock lock]; - for (Edge *e in es) { - [e reverse]; - } - dirty = YES; - [graphLock unlock]; - return [GraphChange reverseEdges:es]; -} - -- (int)indexOfNode:(Node *)node { - return [nodes indexOfObject:node]; -} - -- (void)setIndex:(int)idx ofNode:(Node *)node { - [graphLock lock]; - - if ([nodes containsObject:node]) { - [nodes removeObject:node]; - [nodes insertObject:node atIndex:idx]; - } - - [graphLock unlock]; -} - -- (int)indexOfEdge:(Edge *)edge { - return [edges indexOfObject:edge]; -} - -- (void)setIndex:(int)idx ofEdge:(Edge *)edge { - [graphLock lock]; - - if ([edges containsObject:edge]) { - [edges removeObject:edge]; - [edges insertObject:edge atIndex:idx]; - } - - [graphLock unlock]; -} - -- (GraphChange*)bringNodesForward:(NSSet*)nodeSet { - NSArray *oldOrder = [nodes copy]; - [graphLock lock]; - // start at the top of the array and work backwards - for (int i = [nodes count]-2; i >= 0; --i) { - if ( [nodeSet containsObject:[nodes objectAtIndex:i]] && - ![nodeSet containsObject:[nodes objectAtIndex:i+1]]) - { - [self setIndex:(i+1) ofNode:[nodes objectAtIndex:i]]; - } - } - GraphChange *change = [GraphChange nodeOrderChangeFrom:oldOrder to:nodes moved:nodeSet]; - [graphLock unlock]; - [oldOrder release]; - - return change; -} - -- (GraphChange*)bringNodesToFront:(NSSet*)nodeSet { - NSArray *oldOrder = [nodes copy]; - int i = 0, top = [nodes count]-1; - - while (i <= top) { - if ([nodeSet containsObject:[nodes objectAtIndex:i]]) { - [self setIndex:([nodes count]-1) ofNode:[nodes objectAtIndex:i]]; - --top; - } else { - ++i; - } - } - GraphChange *change = [GraphChange nodeOrderChangeFrom:oldOrder to:nodes moved:nodeSet]; - [oldOrder release]; - - return change; -} - -- (GraphChange*)bringEdgesForward:(NSSet*)edgeSet { - [graphLock lock]; - NSArray *oldOrder = [edges copy]; - // start at the top of the array and work backwards - for (int i = [edges count]-2; i >= 0; --i) { - if ( [edgeSet containsObject:[edges objectAtIndex:i]] && - ![edgeSet containsObject:[edges objectAtIndex:i+1]]) - { - [self setIndex:(i+1) ofEdge:[edges objectAtIndex:i]]; - } - } - GraphChange *change = [GraphChange edgeOrderChangeFrom:oldOrder to:edges moved:edgeSet]; - [graphLock unlock]; - [oldOrder release]; - - return change; -} - -- (GraphChange*)bringEdgesToFront:(NSSet*)edgeSet { - NSArray *oldOrder = [edges copy]; - int i = 0, top = [edges count]-1; - - while (i <= top) { - if ([edgeSet containsObject:[edges objectAtIndex:i]]) { - [self setIndex:([edges count]-1) ofEdge:[edges objectAtIndex:i]]; - --top; - } else { - ++i; - } - } - GraphChange *change = [GraphChange edgeOrderChangeFrom:oldOrder to:edges moved:edgeSet]; - [oldOrder release]; - - return change; -} - -- (GraphChange*)sendNodesBackward:(NSSet*)nodeSet { - [graphLock lock]; - NSArray *oldOrder = [nodes copy]; - // start at the top of the array and work backwards - for (int i = 1; i < [nodes count]; ++i) { - if ( [nodeSet containsObject:[nodes objectAtIndex:i]] && - ![nodeSet containsObject:[nodes objectAtIndex:i-1]]) - { - [self setIndex:(i-1) ofNode:[nodes objectAtIndex:i]]; - } - } - GraphChange *change = [GraphChange nodeOrderChangeFrom:oldOrder to:nodes moved:nodeSet]; - [graphLock unlock]; - [oldOrder release]; - - return change; -} - -- (GraphChange*)sendEdgesBackward:(NSSet*)edgeSet { - [graphLock lock]; - NSArray *oldOrder = [edges copy]; - // start at the top of the array and work backwards - for (int i = 1; i < [edges count]; ++i) { - if ( [edgeSet containsObject:[edges objectAtIndex:i]] && - ![edgeSet containsObject:[edges objectAtIndex:i-1]]) - { - [self setIndex:(i-1) ofEdge:[edges objectAtIndex:i]]; - } - } - GraphChange *change = [GraphChange edgeOrderChangeFrom:oldOrder to:edges moved:edgeSet]; - [graphLock unlock]; - [oldOrder release]; - - return change; -} - -- (GraphChange*)sendNodesToBack:(NSSet*)nodeSet { - NSArray *oldOrder = [nodes copy]; - int i = [nodes count]-1, bot = 0; - - while (i >= bot) { - if ([nodeSet containsObject:[nodes objectAtIndex:i]]) { - [self setIndex:0 ofNode:[nodes objectAtIndex:i]]; - ++bot; - } else { - --i; - } - } - GraphChange *change = [GraphChange nodeOrderChangeFrom:oldOrder to:nodes moved:nodeSet]; - [oldOrder release]; - - return change; -} - -- (GraphChange*)sendEdgesToBack:(NSSet*)edgeSet { - NSArray *oldOrder = [edges copy]; - int i = [edges count]-1, bot = 0; - - while (i >= bot) { - if ([edgeSet containsObject:[edges objectAtIndex:i]]) { - [self setIndex:0 ofEdge:[edges objectAtIndex:i]]; - ++bot; - } else { - --i; - } - } - GraphChange *change = [GraphChange edgeOrderChangeFrom:oldOrder to:edges moved:edgeSet]; - [oldOrder release]; - - return change; -} - -- (GraphChange*)insertGraph:(Graph*)g { - [graphLock lock]; - - for (Node *n in [g nodes]) { - [self addNode:n]; - } - - for (Edge *e in [g edges]) { - [self addEdge:e]; - } - - dirty = YES; - - [graphLock unlock]; - - - return [GraphChange graphAdditionWithNodes:[NSSet setWithArray:[g nodes]] edges:[NSSet setWithArray:[g edges]]]; -} - -- (void)flipNodes:(NSSet*)nds horizontal:(BOOL)horiz { - [graphLock lock]; - - NSRect bds = [Graph boundsForNodes:nds]; - float ctr; - if (horiz) ctr = bds.origin.x + (bds.size.width/2); - else ctr = bds.origin.y + (bds.size.height/2); - - Node *n; - NSPoint p; - NSEnumerator *en = [nds objectEnumerator]; - while ((n = [en nextObject])) { - p = [n point]; - if (horiz) p.x = 2 * ctr - p.x; - else p.y = 2 * ctr - p.y; - [n setPoint:p]; - } - - Edge *e; - en = [edges objectEnumerator]; - while ((e = [en nextObject])) { - if ([nds containsObject:[e source]] && - [nds containsObject:[e target]]) - { - if ([e bendMode] == EdgeBendModeInOut) { - if (horiz) { - if ([e inAngle] < 0) [e setInAngle:(-180 - [e inAngle])]; - else [e setInAngle:180 - [e inAngle]]; - - if ([e outAngle] < 0) [e setOutAngle:(-180 - [e outAngle])]; - else [e setOutAngle:180 - [e outAngle]]; - } else { - [e setInAngle:-[e inAngle]]; - [e setOutAngle:-[e outAngle]]; - } - } else { - [e setBend:-[e bend]]; - } - } - } - - [graphLock unlock]; -} - -- (GraphChange*)flipHorizontalNodes:(NSSet*)nds { - [self flipNodes:nds horizontal:YES]; - return [GraphChange flipNodes:nds horizontal:YES]; -} - -- (GraphChange*)flipVerticalNodes:(NSSet*)nds { - [self flipNodes:nds horizontal:NO]; - return [GraphChange flipNodes:nds horizontal:NO]; -} - -- (Graph*)copyOfSubgraphWithNodes:(NSSet*)nds { - return [self copyOfSubgraphWithNodes:nds zone:NSDefaultMallocZone()]; -} - -- (Graph*)copyOfSubgraphWithNodes:(NSSet*)nds zone:(NSZone*)zone { - [graphLock lock]; - - NSMapTable *newNds = [Graph nodeTableForNodes:nds withZone:zone]; - Graph* newGraph = [[Graph allocWithZone:zone] init]; - - for (Node *nd in [newNds objectEnumerator]) { - [newGraph addNode:nd]; - } - - for (Edge *e in edges) { - if ([nds containsObject:[e source]] && [nds containsObject:[e target]]) { - Edge *e1 = [e copyWithZone:zone]; - [e1 setSource:[newNds objectForKey:[e source]]]; - [e1 setTarget:[newNds objectForKey:[e target]]]; - [newGraph addEdge:e1]; - [e1 release]; // e1 belongs to newGraph - } - } - - [graphLock unlock]; - - return newGraph; -} - -- (NSSet*)pathCover { - [self sync]; - - NSMutableSet *cover = [NSMutableSet set]; - NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init]; - - NSMutableSet *remainingEdges = [NSMutableSet setWithArray:edges]; - - while ([remainingEdges count] != 0) { - NSMutableArray *path = [[NSMutableArray alloc] init]; - NSSet *succs; - Edge *succ; - NSEnumerator *en; - - Edge *e = [remainingEdges anyObject]; - - while (e!=nil) { - [path addObject:e]; - [remainingEdges removeObject:e]; - - succs = [self outEdgesForNode:[e target]]; - en = [succs objectEnumerator]; - e = nil; - - while ((succ = [en nextObject])) { - if ([remainingEdges containsObject:succ]) e = succ; - } - } - - [cover addObject:path]; - [path release]; - } - - [pool drain]; - return cover; -} - -- (void)applyGraphChange:(GraphChange*)ch { - [graphLock lock]; - switch ([ch changeType]) { - case GraphAddition: - for (Node *n in [[ch affectedNodes] objectEnumerator]) { - [nodes addObject:n]; - } - - for (Edge *e in [[ch affectedEdges] objectEnumerator]) { - [edges addObject:e]; - } - - break; - case GraphDeletion: - for (Edge *e in [[ch affectedEdges] objectEnumerator]) { - [edges removeObject:e]; - } - - for (Node *n in [[ch affectedNodes] objectEnumerator]) { - [nodes removeObject:n]; - } - - break; - case NodePropertyChange: - [[ch nodeRef] setPropertiesFromNode:[ch nwNode]]; - break; - case NodesPropertyChange: - for (Node *key in [[ch nwNodeTable] keyEnumerator]) { - [key setPropertiesFromNode:[[ch nwNodeTable] objectForKey:key]]; - } - break; - case EdgePropertyChange: - [[ch edgeRef] setPropertiesFromEdge:[ch nwEdge]]; - break; - case EdgesPropertyChange: - for (Edge *key in [[ch nwEdgeTable] keyEnumerator]) { - [key setPropertiesFromEdge:[[ch nwEdgeTable] objectForKey:key]]; - } - break; - case NodesShift: - for (Node *n in [[ch affectedNodes] objectEnumerator]) { - [n setPoint:NSMakePoint([n point].x + [ch shiftPoint].x, - [n point].y + [ch shiftPoint].y)]; - } - break; - case NodesFlip: - [self flipNodes:[ch affectedNodes] horizontal:[ch horizontal]]; - break; - case EdgesReverse: - for (Edge *e in [[ch affectedEdges] objectEnumerator]) { - [e reverse]; - } - break; - case BoundingBoxChange: - [self setBoundingBox:[ch nwBoundingBox]]; - break; - case GraphPropertyChange: - [data setArray:[ch nwGraphData]]; - break; - case NodeOrderChange: - [nodes setArray:[ch nwNodeOrder]]; - break; - case EdgeOrderChange: - [edges setArray:[ch nwEdgeOrder]]; - break; - } - - dirty = YES; - [graphLock unlock]; -} - -//- (void)undoGraphChange:(GraphChange*)ch { -// [self applyGraphChange:[GraphChange inverseGraphChange:ch]]; -//} - -- (NSString*)tikz { - [graphLock lock]; - - NSMutableString *code = [NSMutableString - stringWithFormat:@"\\begin{tikzpicture}%@\n", - [[self data] tikzList]]; - - if ([self hasBoundingBox]) { - [code appendFormat:@"\t\\path [use as bounding box] (%@,%@) rectangle (%@,%@);\n", - [NSNumber numberWithFloat:boundingBox.origin.x], - [NSNumber numberWithFloat:boundingBox.origin.y], - [NSNumber numberWithFloat:boundingBox.origin.x + boundingBox.size.width], - [NSNumber numberWithFloat:boundingBox.origin.y + boundingBox.size.height]]; - } - -// NSArray *sortedNodeList = [[nodes allObjects] -// sortedArrayUsingSelector:@selector(compareTo:)]; - //NSMutableDictionary *nodeNames = [NSMutableDictionary dictionary]; - - if ([nodes count] > 0) [code appendFormat:@"\t\\begin{pgfonlayer}{nodelayer}\n"]; - - int i = 0; - for (Node *n in nodes) { - [n updateData]; - [n setName:[NSString stringWithFormat:@"%d", i]]; - [code appendFormat:@"\t\t\\node %@ (%d) at (%@, %@) {%@};\n", - [[n data] tikzList], - i, - [NSNumber numberWithFloat:[n point].x], - [NSNumber numberWithFloat:[n point].y], - [n label] - ]; - i++; - } - - if ([nodes count] > 0) [code appendFormat:@"\t\\end{pgfonlayer}\n"]; - if ([edges count] > 0) [code appendFormat:@"\t\\begin{pgfonlayer}{edgelayer}\n"]; - - NSString *nodeStr; - for (Edge *e in edges) { - [e updateData]; - - if ([e hasEdgeNode]) { - nodeStr = [NSString stringWithFormat:@"node%@{%@} ", - [[[e edgeNode] data] tikzList], - [[e edgeNode] label] - ]; - } else { - nodeStr = @""; - } - - NSString *edata = [[e data] tikzList]; - - NSString *srcAnchor; - NSString *tgtAnchor; - - if ([[e source] style] == nil) { - srcAnchor = @".center"; - } else if ([[e sourceAnchor] isEqual:@""]) { - srcAnchor = @""; - } else { - srcAnchor = [NSString stringWithFormat:@".%@", [e sourceAnchor]]; - } - - if ([[e target] style] == nil) { - tgtAnchor = @".center"; - } else if ([[e targetAnchor] isEqual:@""]) { - tgtAnchor = @""; - } else { - tgtAnchor = [NSString stringWithFormat:@".%@", [e targetAnchor]]; - } - - [code appendFormat:@"\t\t\\draw%@ (%@%@) to %@(%@%@);\n", - ([edata isEqual:@""]) ? @"" : [NSString stringWithFormat:@" %@", edata], - [[e source] name], - srcAnchor, - nodeStr, - ([e source] == [e target]) ? @"" : [[e target] name], - tgtAnchor - ]; - } - - if ([edges count] > 0) [code appendFormat:@"\t\\end{pgfonlayer}\n"]; - - [code appendString:@"\\end{tikzpicture}"]; - - [graphLock unlock]; - - return code; -} - -+ (Graph*)graph { - return [[[self alloc] init] autorelease]; -} - -+ (Graph*)graphFromTikz:(NSString*)tikz error:(NSError**)e { - return [TikzGraphAssembler parseTikz:tikz error:e]; -} - -+ (Graph*)graphFromTikz:(NSString*)tikz { - return [self graphFromTikz:tikz error:NULL]; -} - -+ (NSMapTable*)nodeTableForNodes:(NSSet*)nds { - return [self nodeTableForNodes:nds withZone:NSDefaultMallocZone()]; -} - -+ (NSMapTable*)nodeTableForNodes:(NSSet*)nds withZone:(NSZone*)zone { - NSMapTable *tab = [[NSMapTable allocWithZone:zone] - initWithKeyOptions:NSMapTableStrongMemory - valueOptions:NSMapTableStrongMemory - capacity:[nds count]]; - for (Node *n in nds) { - Node *ncopy = [n copyWithZone:zone]; - [tab setObject:ncopy forKey:n]; - [ncopy release]; // tab should still retain ncopy. - } - return [tab autorelease]; -} - -+ (NSMapTable*)edgeTableForEdges:(NSSet*)es { - return [self edgeTableForEdges:es withZone:NSDefaultMallocZone()]; -} - -+ (NSMapTable*)edgeTableForEdges:(NSSet*)es withZone:(NSZone*)zone { - NSMapTable *tab = [[NSMapTable allocWithZone:zone] - initWithKeyOptions:NSMapTableStrongMemory - valueOptions:NSMapTableStrongMemory - capacity:[es count]]; - for (Edge *e in es) { - Edge *ecopy = [e copyWithZone:zone]; - [tab setObject:ecopy forKey:e]; - [ecopy release]; // tab should still retain ecopy. - } - return tab; -} - - -+ (NSRect)boundsForNodes:(id<NSFastEnumeration>)nds { - NSPoint tl, br; - NSPoint p; - BOOL hasPoints = NO; - for (Node *n in nds) { - p = [n point]; - if (!hasPoints) { - tl = p; - br = p; - hasPoints = YES; - } else { - if (p.x < tl.x) tl.x = p.x; - if (p.y > tl.y) tl.y = p.y; - if (p.x > br.x) br.x = p.x; - if (p.y < br.y) br.y = p.y; - } - } - - return (hasPoints) ? NSRectAroundPoints(tl, br) : NSMakeRect(0, 0, 0, 0); -} - -@end - -// vi:ft=objc:ts=4:noet:sts=4:sw=4 diff --git a/tikzit/src/common/GraphChange.h b/tikzit/src/common/GraphChange.h deleted file mode 100644 index 0e71a90..0000000 --- a/tikzit/src/common/GraphChange.h +++ /dev/null @@ -1,344 +0,0 @@ -// -// GraphChange.h -// TikZiT -// -// Copyright 2010 Aleks Kissinger. All rights reserved. -// -// -// This file is part of TikZiT. -// -// TikZiT is free software: you can redistribute it and/or modify -// it under the terms of the GNU General Public License as published by -// the Free Software Foundation, either version 3 of the License, or -// (at your option) any later version. -// -// TikZiT is distributed in the hope that it will be useful, -// but WITHOUT ANY WARRANTY; without even the implied warranty of -// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -// GNU General Public License for more details. -// -// You should have received a copy of the GNU General Public License -// along with TikZiT. If not, see <http://www.gnu.org/licenses/>. -// - -#import "Node.h" -#import "Edge.h" - -typedef enum { - GraphAddition, - GraphDeletion, - NodePropertyChange, - EdgePropertyChange, - NodesPropertyChange, - EdgesPropertyChange, - NodesShift, - NodesFlip, - EdgesReverse, - BoundingBoxChange, - GraphPropertyChange, - NodeOrderChange, - EdgeOrderChange -} ChangeType; - -/*! - @class GraphChange - @brief Store the data associated with a graph change. - @details All of the methods that change a graph return an object of type GraphChange. - Graph changes can be re-done by calling [graph applyGraphChange:]. They can be undone - by calling applyGraphChange on [change inverse]. This class has no public initializer, - so everything should be constructed by factory methods. - */ -@interface GraphChange : NSObject { - ChangeType changeType; - - // for addition, deletion, and shifts - NSSet *affectedNodes; - NSSet *affectedEdges; - NSPoint shiftPoint; - - // for flip - BOOL horizontal; - - // for property changes - Node *nodeRef; - Edge *edgeRef; - - Node *oldNode, *nwNode; - Edge *oldEdge, *nwEdge; - NSMapTable *oldNodeTable, *nwNodeTable; - NSMapTable *oldEdgeTable, *nwEdgeTable; - NSRect oldBoundingBox, nwBoundingBox; - GraphElementData *oldGraphData, *nwGraphData; - - NSArray *oldNodeOrder, *nwNodeOrder; - NSArray *oldEdgeOrder, *nwEdgeOrder; -} - -/*! - @property changeType - @brief Type of GraphChange. - */ -@property (assign) ChangeType changeType; - -/*! - @property shiftPoint - @brief A point storing a shifted distance. - */ -@property (assign) NSPoint shiftPoint; - -/*! - @property horizontal - @brief Flags whether nodes were flipped horizontally - */ -@property (assign) BOOL horizontal; - -/*! - @property affectedNodes - @brief A set of nodes affected by this change, may be undefined. - */ -@property (copy) NSSet *affectedNodes; - -/*! - @property affectedEdges - @brief A set of edges affected by this change, may be undefined. - */ -@property (copy) NSSet *affectedEdges; - -/*! - @property nodeRef - @brief A reference to a single node affected by this change, may be undefined. - */ -@property (retain) Node *nodeRef; - -/*! - @property oldNode - @brief A copy of the node pre-change. - */ -@property (copy) Node *oldNode; - -/*! - @property nwNode - @brief A copy of the node post-change. - */ -@property (copy) Node *nwNode; - -/*! - @property edgeRef - @brief A reference to a single edge affected by this change, may be undefined. - */ -@property (retain) Edge *edgeRef; - -/*! - @property oldEdge - @brief A copy of the edge pre-change. - */ -@property (copy) Edge *oldEdge; - -/*! - @property nwEdge - @brief A copy of the edge post-change. - */ -@property (copy) Edge *nwEdge; - -/*! - @property oldNodeTable - @brief A a table containing copies of a set of nodes pre-change. - */ -@property (retain) NSMapTable *oldNodeTable; - -/*! - @property nwNodeTable - @brief A a table containing copies of a set of nodes post-change. - */ -@property (retain) NSMapTable *nwNodeTable; - -/*! - @property oldEdgeTable - @brief A a table containing copies of a set of edges pre-change. - */ -@property (retain) NSMapTable *oldEdgeTable; - -/*! - @property nwEdgeTable - @brief A a table containing copies of a set of edges post-change. - */ -@property (retain) NSMapTable *nwEdgeTable; - -/*! - @property oldBoundingBox - @brief The old bounding box. - */ -@property (assign) NSRect oldBoundingBox; - -/*! - @property nwBoundingBox - @brief The new bounding box. - */ -@property (assign) NSRect nwBoundingBox; - -/*! - @property oldGraphData - @brief The old graph data. - */ -@property (copy) GraphElementData *oldGraphData; - -/*! - @property nwGraphData - @brief The new graph data. - */ -@property (copy) GraphElementData *nwGraphData; - -/*! - @property oldNodeOrder - @brief The old node list. - */ -@property (copy) NSArray *oldNodeOrder; - -/*! - @property nwNodeOrder - @brief The new node list. - */ -@property (copy) NSArray *nwNodeOrder; - -/*! - @property oldEdgeOrder - @brief The old edge list. - */ -@property (copy) NSArray *oldEdgeOrder; - -/*! - @property nwEdgeOrder - @brief The new edge list. - */ -@property (copy) NSArray *nwEdgeOrder; - -/*! - @brief Invert a GraphChange. - @details Invert a GraphChange. Calling [graph applyGraphChange:[[graph msg:...] invert]] - should leave the graph unchanged for any method of Graph that returns a - GraphChange. - @result The inverse of the current Graph Change. - */ -- (GraphChange*)invert; - -/*! - @brief Construct a graph addition. affectedNodes are the added nodes, - affectedEdges are the added edges. - @param ns a set of nodes. - @param es a set of edges. - @result A graph addition. - */ -+ (GraphChange*)graphAdditionWithNodes:(NSSet*)ns edges:(NSSet*)es; - -/*! - @brief Construct a graph deletion. affectedNodes are the deleted nodes, - affectedEdges are the deleted edges. - @param ns a set of nodes. - @param es a set of edges. - @result A graph deletion. - */ -+ (GraphChange*)graphDeletionWithNodes:(NSSet*)ns edges:(NSSet*)es; - -/*! - @brief Construct a property change of a single node. - @param nd the affected node. - @param old a copy of the node pre-change - @param nw a copy of the node post-change - @result A property change of a single node. - */ -+ (GraphChange*)propertyChangeOfNode:(Node*)nd fromOld:(Node*)old toNew:(Node*)nw; - -/*! - @brief Construct a property change of a single edge. - @param e the affected edge. - @param old a copy of the edge pre-change - @param nw a copy of the edge post-change - @result A property change of a single node. - */ -+ (GraphChange*)propertyChangeOfEdge:(Edge*)e fromOld:(Edge *)old toNew:(Edge *)nw; - -/*! - @brief Construct a property change of set of nodes. - @details Construct a property change of set of nodes. oldC and newC should be - constructed using the class method [Graph nodeTableForNodes:] before - and after the property change, respectively. The affected nodes are - keys(oldC) = keys(newC). - @param oldC a table of copies of nodes pre-change - @param newC a table of copies of nodes post-change - @result A property change of a set of nodes. - */ -+ (GraphChange*)propertyChangeOfNodesFromOldCopies:(NSMapTable*)oldC - toNewCopies:(NSMapTable*)newC; - -/*! - @brief Construct a property change of set of edges. - @details Construct a property change of set of edges. oldC and newC should be - constructed using the class method [Graph edgeTableForEdges:] before - and after the property change, respectively. The affected edges are - keys(oldC) = keys(newC). - @param oldC a table of copies of edges pre-change - @param newC a table of copies of edges post-change - @result A property change of a set of edges. - */ -+ (GraphChange*)propertyChangeOfEdgesFromOldCopies:(NSMapTable*)oldC - toNewCopies:(NSMapTable*)newC; - - -/*! - @brief Construct a shift of a set of nodes by a given point. - @param ns the affected nodes. - @param p a point storing (dx,dy) - @result A shift of a set of nodes. - */ -+ (GraphChange*)shiftNodes:(NSSet*)ns byPoint:(NSPoint)p; - -/*! - @brief Construct a horizontal or vertical flip of a set of nodes. - @param ns the affected nodes. - @param b flag for whether to flip horizontally - @result A flip of a set of nodes. - */ -+ (GraphChange*)flipNodes:(NSSet*)ns horizontal:(BOOL)b; - -/*! - @brief Construct a reversal of a set of edges. - @param es the affected edges. - @result A reverse of a set of edges. - */ -+ (GraphChange*)reverseEdges:(NSSet*)es; - -/*! - @brief Construct a bounding box change - @param oldBB the old bounding box - @param newBB the new bounding box - @result A bounding box change. - */ -+ (GraphChange*)changeBoundingBoxFrom:(NSRect)oldBB to:(NSRect)newBB; - -/*! - @brief Construct a graph property change - @param oldData the old graph data - @param newData the new graph data - @result A graph property change. - */ -+ (GraphChange*)propertyChangeOfGraphFrom:(GraphElementData*)oldData to:(GraphElementData*)newData; - -/*! - @brief Construct a node order change - @param old The old ordering - @param new The new ordering - @result A node order change - */ -+ (GraphChange*)nodeOrderChangeFrom:(NSArray*)old to:(NSArray*)new moved:(NSSet*)affected; - -/*! - @brief Construct an edge order change - @param old The old ordering - @param new The new ordering - @result A edge order change - */ -+ (GraphChange*)edgeOrderChangeFrom:(NSArray*)old to:(NSArray*)new moved:(NSSet*)affected; - -@end - -// vi:ft=objc:noet:ts=4:sts=4:sw=4 diff --git a/tikzit/src/common/GraphChange.m b/tikzit/src/common/GraphChange.m deleted file mode 100644 index 239ae23..0000000 --- a/tikzit/src/common/GraphChange.m +++ /dev/null @@ -1,252 +0,0 @@ -// -// GraphChange.m -// TikZiT -// -// Copyright 2010 Aleks Kissinger. All rights reserved. -// -// -// This file is part of TikZiT. -// -// TikZiT is free software: you can redistribute it and/or modify -// it under the terms of the GNU General Public License as published by -// the Free Software Foundation, either version 3 of the License, or -// (at your option) any later version. -// -// TikZiT is distributed in the hope that it will be useful, -// but WITHOUT ANY WARRANTY; without even the implied warranty of -// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -// GNU General Public License for more details. -// -// You should have received a copy of the GNU General Public License -// along with TikZiT. If not, see <http://www.gnu.org/licenses/>. -// - - -// GraphChange : store the data associated to a single, undo-able change -// to a graph. An undo manager should maintain a stack of such changes -// and undo/redo them on request using [graph applyGraphChange:...]. - -#import "GraphChange.h" - - -@implementation GraphChange - -- (id)init { - return [super init]; -} - -- (void)dealloc { - [affectedNodes release]; - [affectedEdges release]; - [nodeRef release]; - [edgeRef release]; - [oldNode release]; - [nwNode release]; - [oldEdge release]; - [nwEdge release]; - [oldNodeTable release]; - [nwNodeTable release]; - [oldEdgeTable release]; - [nwEdgeTable release]; - [oldGraphData release]; - [nwGraphData release]; - [oldNodeOrder release]; - [nwNodeOrder release]; - [oldEdgeOrder release]; - [nwEdgeOrder release]; - - [super dealloc]; -} - -@synthesize changeType; -@synthesize shiftPoint, horizontal; -@synthesize affectedEdges, affectedNodes; -@synthesize edgeRef, nodeRef; -@synthesize nwNode, oldNode; -@synthesize nwEdge, oldEdge; -@synthesize oldNodeTable, nwNodeTable; -@synthesize oldEdgeTable, nwEdgeTable; -@synthesize oldBoundingBox, nwBoundingBox; -@synthesize oldGraphData, nwGraphData; -@synthesize oldNodeOrder, nwNodeOrder; -@synthesize oldEdgeOrder, nwEdgeOrder; - -- (GraphChange*)invert { - GraphChange *inverse = [[GraphChange alloc] init]; - [inverse setChangeType:[self changeType]]; - switch ([self changeType]) { - case GraphAddition: - [inverse setChangeType:GraphDeletion]; - inverse->affectedNodes = [affectedNodes retain]; - inverse->affectedEdges = [affectedEdges retain]; - break; - case GraphDeletion: - [inverse setChangeType:GraphAddition]; - inverse->affectedNodes = [affectedNodes retain]; - inverse->affectedEdges = [affectedEdges retain]; - break; - case NodePropertyChange: - inverse->nodeRef = [nodeRef retain]; - inverse->oldNode = [nwNode retain]; - inverse->nwNode = [oldNode retain]; - break; - case NodesPropertyChange: - inverse->oldNodeTable = [nwNodeTable retain]; - inverse->nwNodeTable = [oldNodeTable retain]; - break; - case EdgePropertyChange: - inverse->edgeRef = [edgeRef retain]; - inverse->oldEdge = [nwEdge retain]; - inverse->nwEdge = [oldEdge retain]; - break; - case EdgesPropertyChange: - inverse->oldEdgeTable = [nwEdgeTable retain]; - inverse->nwEdgeTable = [oldEdgeTable retain]; - break; - case NodesShift: - inverse->affectedNodes = [affectedNodes retain]; - [inverse setShiftPoint:NSMakePoint(-[self shiftPoint].x, - -[self shiftPoint].y)]; - break; - case NodesFlip: - inverse->affectedNodes = [affectedNodes retain]; - [inverse setHorizontal:[self horizontal]]; - break; - case EdgesReverse: - inverse->affectedEdges = [affectedEdges retain]; - break; - case BoundingBoxChange: - inverse->oldBoundingBox = nwBoundingBox; - inverse->nwBoundingBox = oldBoundingBox; - break; - case GraphPropertyChange: - inverse->oldGraphData = [nwGraphData retain]; - inverse->nwGraphData = [oldGraphData retain]; - break; - case NodeOrderChange: - inverse->affectedNodes = [affectedNodes retain]; - inverse->oldNodeOrder = [nwNodeOrder retain]; - inverse->nwNodeOrder = [oldNodeOrder retain]; - break; - case EdgeOrderChange: - inverse->affectedEdges = [affectedEdges retain]; - inverse->oldEdgeOrder = [nwEdgeOrder retain]; - inverse->nwEdgeOrder = [oldEdgeOrder retain]; - break; - } - - return [inverse autorelease]; -} - -+ (GraphChange*)graphAdditionWithNodes:(NSSet *)ns edges:(NSSet *)es { - GraphChange *gc = [[GraphChange alloc] init]; - [gc setChangeType:GraphAddition]; - [gc setAffectedNodes:ns]; - [gc setAffectedEdges:es]; - return [gc autorelease]; -} - -+ (GraphChange*)graphDeletionWithNodes:(NSSet *)ns edges:(NSSet *)es { - GraphChange *gc = [[GraphChange alloc] init]; - [gc setChangeType:GraphDeletion]; - [gc setAffectedNodes:ns]; - [gc setAffectedEdges:es]; - return [gc autorelease]; -} - -+ (GraphChange*)propertyChangeOfNode:(Node*)nd fromOld:(Node*)old toNew:(Node*)nw { - GraphChange *gc = [[GraphChange alloc] init]; - [gc setChangeType:NodePropertyChange]; - [gc setNodeRef:nd]; - [gc setOldNode:old]; - [gc setNwNode:nw]; - return [gc autorelease]; -} - -+ (GraphChange*)propertyChangeOfNodesFromOldCopies:(NSMapTable*)oldC - toNewCopies:(NSMapTable*)newC { - GraphChange *gc = [[GraphChange alloc] init]; - [gc setChangeType:NodesPropertyChange]; - [gc setOldNodeTable:oldC]; - [gc setNwNodeTable:newC]; - return [gc autorelease]; -} - -+ (GraphChange*)propertyChangeOfEdge:(Edge*)e fromOld:(Edge *)old toNew:(Edge *)nw { - GraphChange *gc = [[GraphChange alloc] init]; - [gc setChangeType:EdgePropertyChange]; - [gc setEdgeRef:e]; - [gc setOldEdge:old]; - [gc setNwEdge:nw]; - return [gc autorelease]; -} - -+ (GraphChange*)propertyChangeOfEdgesFromOldCopies:(NSMapTable*)oldC - toNewCopies:(NSMapTable*)newC { - GraphChange *gc = [[GraphChange alloc] init]; - [gc setChangeType:EdgesPropertyChange]; - [gc setOldEdgeTable:oldC]; - [gc setNwEdgeTable:newC]; - return [gc autorelease]; -} - -+ (GraphChange*)shiftNodes:(NSSet*)ns byPoint:(NSPoint)p { - GraphChange *gc = [[GraphChange alloc] init]; - [gc setChangeType:NodesShift]; - [gc setAffectedNodes:ns]; - [gc setShiftPoint:p]; - return [gc autorelease]; -} - -+ (GraphChange*)flipNodes:(NSSet*)ns horizontal:(BOOL)b { - GraphChange *gc = [[GraphChange alloc] init]; - [gc setChangeType:NodesFlip]; - [gc setAffectedNodes:ns]; - [gc setHorizontal:b]; - return [gc autorelease]; -} - -+ (GraphChange*)reverseEdges:(NSSet*)es { - GraphChange *gc = [[GraphChange alloc] init]; - [gc setChangeType:EdgesReverse]; - [gc setAffectedEdges:es]; - return [gc autorelease]; -} - -+ (GraphChange*)changeBoundingBoxFrom:(NSRect)oldBB to:(NSRect)newBB { - GraphChange *gc = [[GraphChange alloc] init]; - [gc setChangeType:BoundingBoxChange]; - [gc setOldBoundingBox:oldBB]; - [gc setNwBoundingBox:newBB]; - return [gc autorelease]; -} - -+ (GraphChange*)propertyChangeOfGraphFrom:(GraphElementData*)oldData to:(GraphElementData*)newData { - GraphChange *gc = [[GraphChange alloc] init]; - [gc setChangeType:GraphPropertyChange]; - [gc setOldGraphData:oldData]; - [gc setNwGraphData:newData]; - return [gc autorelease]; -} - -+ (GraphChange*)nodeOrderChangeFrom:(NSArray*)old to:(NSArray*)new moved:(NSSet*)affected { - GraphChange *gc = [[GraphChange alloc] init]; - [gc setChangeType:NodeOrderChange]; - [gc setAffectedNodes:affected]; - [gc setOldNodeOrder:old]; - [gc setNwNodeOrder:new]; - return [gc autorelease]; -} - -+ (GraphChange*)edgeOrderChangeFrom:(NSArray*)old to:(NSArray*)new moved:(NSSet*)affected { - GraphChange *gc = [[GraphChange alloc] init]; - [gc setChangeType:EdgeOrderChange]; - [gc setAffectedEdges:affected]; - [gc setOldEdgeOrder:old]; - [gc setNwEdgeOrder:new]; - return [gc autorelease]; -} - -@end - -// vi:ft=objc:ts=4:noet:sts=4:sw=4 diff --git a/tikzit/src/common/GraphElementData.h b/tikzit/src/common/GraphElementData.h deleted file mode 100644 index a65e6df..0000000 --- a/tikzit/src/common/GraphElementData.h +++ /dev/null @@ -1,94 +0,0 @@ -// -// GraphElementData.h -// TikZiT -// -// Copyright 2010 Aleks Kissinger. All rights reserved. -// -// -// This file is part of TikZiT. -// -// TikZiT is free software: you can redistribute it and/or modify -// it under the terms of the GNU General Public License as published by -// the Free Software Foundation, either version 3 of the License, or -// (at your option) any later version. -// -// TikZiT is distributed in the hope that it will be useful, -// but WITHOUT ANY WARRANTY; without even the implied warranty of -// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -// GNU General Public License for more details. -// -// You should have received a copy of the GNU General Public License -// along with TikZiT. If not, see <http://www.gnu.org/licenses/>. -// - - -#import <Foundation/Foundation.h> - -/*! - @class GraphElementData - @brief Store extra data associated with a graph, node, or edge. - @details Store the extra (style, ...) data associated with - a graph, node, or edge. This data is stored as a mutable - array of properties. It also implements hash-like accessors, - but care should be taken using these, as the list can contain - multiple occurrences of the same key. - - Convention: Getters and setters act on the *first* occurrence - of the key. 'Unsetters' remove *all* occurrences. - */ -@interface GraphElementData : NSMutableArray { - NSMutableArray *properties; -} - -- (id)init; -+ (id)data; - -/*! - @brief Set the given value for the *first* property matching this key. Add a - new property if it doesn't already exist. - @param val the value to set - @param key the key for this property - */ -- (void)setProperty:(NSString*)val forKey:(NSString*)key; - -/*! - @brief Remove *all* occurences of the property with the given key. - @param key - */ -- (void)unsetProperty:(NSString*)key; - -/*! - @brief Return the value of the *first* occurrence of the given key. - @param key - */ -- (NSString*)propertyForKey:(NSString*)key; - -/*! - @brief Add the given atom to the list, if it's not already present. - @param atom - */ -- (void)setAtom:(NSString*)atom; - -/*! - @brief Remove *all* occurrences of the given atom. - @param atom - */ -- (void)unsetAtom:(NSString*)atom; - -/*! - @brief Returns YES if the list contains at least one occurrence of - the given atom. - @param atom - @result A boolean value. - */ -- (BOOL)isAtomSet:(NSString*)atom; - -/*! - @brief Returns a TikZ-friendly string containing all of the properties. - @result A string. - */ -- (NSString*)tikzList; - -@end - -// vi:ft=objc:noet:ts=4:sts=4:sw=4 diff --git a/tikzit/src/common/GraphElementData.m b/tikzit/src/common/GraphElementData.m deleted file mode 100644 index 0750296..0000000 --- a/tikzit/src/common/GraphElementData.m +++ /dev/null @@ -1,151 +0,0 @@ -// -// GraphElementData.m -// TikZiT -// -// Copyright 2010 Aleks Kissinger. All rights reserved. -// -// -// This file is part of TikZiT. -// -// TikZiT is free software: you can redistribute it and/or modify -// it under the terms of the GNU General Public License as published by -// the Free Software Foundation, either version 3 of the License, or -// (at your option) any later version. -// -// TikZiT is distributed in the hope that it will be useful, -// but WITHOUT ANY WARRANTY; without even the implied warranty of -// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -// GNU General Public License for more details. -// -// You should have received a copy of the GNU General Public License -// along with TikZiT. If not, see <http://www.gnu.org/licenses/>. -// - -#import "GraphElementData.h" -#import "GraphElementProperty.h" - - -@implementation GraphElementData - -+ (id)data { - return [[[self alloc] init] autorelease]; -} - -- (id)init { - self = [super init]; - if (self) { - properties = [[NSMutableArray alloc] init]; - } - return self; -} - -// all of the array messages delegate to 'properties' - -- (NSUInteger)count { return [properties count]; } -- (id)objectAtIndex:(NSUInteger)index { - return [properties objectAtIndex:index]; -} -- (NSArray*)objectsAtIndexes:(NSIndexSet*)indexes { - return [properties objectsAtIndexes:indexes]; -} -- (void) getObjects:(id*)buffer range:(NSRange)range { - [properties getObjects:buffer range:range]; -} -- (void)insertObject:(id)anObject atIndex:(NSUInteger)index { - [properties insertObject:anObject atIndex:index]; -} -- (void)removeObjectAtIndex:(NSUInteger)index { - [properties removeObjectAtIndex:index]; -} -- (void)addObject:(id)anObject { - [properties addObject:anObject]; -} -- (void)removeLastObject { - [properties removeLastObject]; -} -- (void)replaceObjectAtIndex:(NSUInteger)index withObject:(id)anObject { - [properties replaceObjectAtIndex:index withObject:anObject]; -} -- (NSUInteger)countByEnumeratingWithState:(NSFastEnumerationState *)state - objects:(id *)stackbuf - count:(NSUInteger)len { - return [properties countByEnumeratingWithState:state objects:stackbuf count:len]; -} - -- (void)setProperty:(NSString*)val forKey:(NSString*)key { - GraphElementProperty *m = [[GraphElementProperty alloc] initWithKeyMatching:key]; - NSInteger idx = [properties indexOfObject:m]; - [m release]; - - GraphElementProperty *p; - if (idx == NSNotFound) { - p = [[GraphElementProperty alloc] initWithPropertyValue:val forKey:key]; - [properties addObject:p]; - [p release]; - } else { - p = [properties objectAtIndex:idx]; - [p setValue:val]; - } -} - -- (void)unsetProperty:(NSString*)key { - GraphElementProperty *m = [[GraphElementProperty alloc] initWithKeyMatching:key]; - [properties removeObject:m]; - [m release]; -} - -- (NSString*)propertyForKey:(NSString*)key { - GraphElementProperty *m = [[GraphElementProperty alloc] initWithKeyMatching:key]; - NSInteger idx = [properties indexOfObject:m]; - [m release]; - - if (idx == NSNotFound) { - return nil; - }else { - GraphElementProperty *p = [properties objectAtIndex:idx]; - return [p value]; - } -} - -- (void)setAtom:(NSString*)atom { - GraphElementProperty *a = [[GraphElementProperty alloc] initWithAtomName:atom]; - if (![properties containsObject:a]) [properties addObject:a]; - [a release]; -} - -- (void)unsetAtom:(NSString*)atom { - GraphElementProperty *a = [[GraphElementProperty alloc] initWithAtomName:atom]; - [properties removeObject:a]; - [a release]; -} - -- (BOOL)isAtomSet:(NSString*)atom { - GraphElementProperty *a = [[GraphElementProperty alloc] initWithAtomName:atom]; - BOOL set = [properties containsObject:a]; - [a release]; - return set; -} - -- (NSString*)tikzList { - NSString *s = [properties componentsJoinedByString:@", "]; - return ([s isEqualToString:@""]) ? @"" : [NSString stringWithFormat:@"[%@]", s]; -} - -- (id)copyWithZone:(NSZone *)zone { - GraphElementData *cp = [[GraphElementData allocWithZone:zone] init]; - for (GraphElementProperty *p in properties) { - GraphElementProperty *p2 = [p copy]; - [cp addObject:p2]; - [p2 release]; - } - return cp; -} - -- (void)dealloc { - [properties release]; - [super dealloc]; -} - -@end - -// vi:ft=objc:ts=4:noet:sts=4:sw=4 diff --git a/tikzit/src/common/GraphElementProperty.h b/tikzit/src/common/GraphElementProperty.h deleted file mode 100644 index 057cdbb..0000000 --- a/tikzit/src/common/GraphElementProperty.h +++ /dev/null @@ -1,88 +0,0 @@ -// -// GraphElementProperty.h -// TikZiT -// -// Copyright 2010 Aleks Kissinger. All rights reserved. -// -// -// This file is part of TikZiT. -// -// TikZiT is free software: you can redistribute it and/or modify -// it under the terms of the GNU General Public License as published by -// the Free Software Foundation, either version 3 of the License, or -// (at your option) any later version. -// -// TikZiT is distributed in the hope that it will be useful, -// but WITHOUT ANY WARRANTY; without even the implied warranty of -// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -// GNU General Public License for more details. -// -// You should have received a copy of the GNU General Public License -// along with TikZiT. If not, see <http://www.gnu.org/licenses/>. -// - -#import <Foundation/Foundation.h> - -/*! - @class GraphElementProperty - @brief A property. I.e. a single entry in a node's/edge's/graph's - GraphElementData table. - */ -@interface GraphElementProperty : NSObject<NSCopying> { - NSString *key; - NSString *value; - BOOL isAtom; - BOOL isKeyMatch; -} - -@property (copy) NSString *key; -@property (copy) NSString *value; -@property (readonly) BOOL isAtom; -@property (readonly) BOOL isKeyMatch; - -/*! - @brief Initialize a new key-matching object. - @param k a key to match - @result A key-matching object. - */ -- (id)initWithKeyMatching:(NSString*)k; -+ (id)keyMatching:(NSString*)k; - -/*! - @brief Initialize a new atomic property. - @param n the atom's name - @result An atom. - */ -- (id)initWithAtomName:(NSString*)n; -+ (id)atom:(NSString*)n; - -/*! - @brief Initialize a new property. - @param v the property's value - @param k the associated key - @result A property. - */ -- (id)initWithPropertyValue:(NSString*)v forKey:(NSString*)k; -+ (id)property:(NSString*)k withValue:(NSString*)v; - -/*! - @brief A matching function for properties. - @details Two properties match iff their keys match and one of the following: - (a) they are both atomic, (b) one is a key-matching and one is a non-atomic - property, or (c) they are both non-atomic and their values match. - @param object another GraphElementProperty - @result A boolean. - */ -- (BOOL)matches:(GraphElementProperty*)object; - -/*! - @brief An alias for <tt>matches:</tt>. This allows one to use built-in methods that - filter on <tt>isEqual:</tt> for <tt>NSObject</tt>s. - @param object another GraphElementProperty - @result A boolean. - */ -- (BOOL)isEqual:(id)object; - -@end - -// vi:ft=objc:noet:ts=4:sts=4:sw=4 diff --git a/tikzit/src/common/GraphElementProperty.m b/tikzit/src/common/GraphElementProperty.m deleted file mode 100644 index 3cf6632..0000000 --- a/tikzit/src/common/GraphElementProperty.m +++ /dev/null @@ -1,146 +0,0 @@ -// -// -// GraphElementProperty.m -// TikZiT -// -// Copyright 2010 Aleks Kissinger. All rights reserved. -// -// -// This file is part of TikZiT. -// -// TikZiT is free software: you can redistribute it and/or modify -// it under the terms of the GNU General Public License as published by -// the Free Software Foundation, either version 3 of the License, or -// (at your option) any later version. -// -// TikZiT is distributed in the hope that it will be useful, -// but WITHOUT ANY WARRANTY; without even the implied warranty of -// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -// GNU General Public License for more details. -// -// You should have received a copy of the GNU General Public License -// along with TikZiT. If not, see <http://www.gnu.org/licenses/>. -// - -#import "GraphElementProperty.h" -#import "NSString+Tikz.h" - -@implementation GraphElementProperty - -+ (id)atom:(NSString*)n { - return [[[self alloc] initWithAtomName:n] autorelease]; -} -+ (id)property:(NSString*)k withValue:(NSString*)v { - return [[[self alloc] initWithPropertyValue:v forKey:k] autorelease]; -} -+ (id)keyMatching:(NSString*)k { - return [[[self alloc] initWithKeyMatching:k] autorelease]; -} - -- (id)initWithAtomName:(NSString*)n { - self = [super init]; - if (self) { - [self setKey:n]; - isAtom = YES; - } - return self; -} - -- (id)initWithPropertyValue:(NSString*)v forKey:(NSString*)k { - self = [super init]; - if (self) { - [self setKey:k]; - [self setValue:v]; - } - return self; -} - -- (id)initWithKeyMatching:(NSString*)k { - self = [super init]; - if (self) { - [self setKey:k]; - isKeyMatch = YES; - } - return self; -} - -- (void) dealloc { - [key release]; - [value release]; - [super dealloc]; -} - -- (void)setValue:(NSString *)v { - if (value != v) { - [value release]; - value = [v copy]; - } -} - -- (NSString*)value { - if (isAtom) { - return @"(atom)"; - } else { - return value; - } -} - - -- (void)setKey:(NSString *)k { - if (key != k) { - [key release]; - key = [k copy]; - } - if (key == nil) - key = @""; // don't allow nil keys -} - -- (NSString*)key { - return key; -} - -- (BOOL)isAtom { return isAtom; } -- (BOOL)isKeyMatch { return isKeyMatch; } - -- (BOOL)matches:(GraphElementProperty*)object { - // properties and atoms are taken to be incomparable - if ([self isAtom] != [object isAtom]) return NO; - - // only compare keys if (a) we are both atoms, (b) i am a key match, or (c) object is a key match - if (([self isAtom] && [object isAtom]) || [self isKeyMatch] || [object isKeyMatch]) { - return [[self key] isEqual:[object key]]; - } - - // otherwise compare key and value - return [[self key] isEqual:[object key]] && [[self value] isEqual:[object value]]; -} - -- (BOOL)isEqual:(id)object { - return [self matches:object]; -} - -- (id)copyWithZone:(NSZone*)zone { - if (isAtom) { - return [[GraphElementProperty allocWithZone:zone] initWithAtomName:[self key]]; - } else if (isKeyMatch) { - return [[GraphElementProperty allocWithZone:zone] initWithKeyMatching:[self key]]; - } else { - return [[GraphElementProperty allocWithZone:zone] initWithPropertyValue:[self value] forKey:[self key]]; - } -} - -- (NSString*)description { - if ([self isAtom]) { - return [[self key] tikzEscapedString]; - } else if ([self isKeyMatch]) { - return [NSString stringWithFormat:@"%@=*", [[self key] tikzEscapedString]]; - } else { - return [NSString stringWithFormat:@"%@=%@", - [[self key] tikzEscapedString], - [[self value] tikzEscapedString]]; - } -} - -@end - -// vi:ft=objc:ts=4:noet:sts=4:sw=4 diff --git a/tikzit/src/common/Grid.h b/tikzit/src/common/Grid.h deleted file mode 100644 index b267536..0000000 --- a/tikzit/src/common/Grid.h +++ /dev/null @@ -1,110 +0,0 @@ -/* - * Copyright 2011 Alex Merry <dev@randomguy3.me.uk> - * - * 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 the Free Software Foundation; either version 2 of - * the License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see <http://www.gnu.org/licenses/>. - */ - -#import <Foundation/Foundation.h> -#import "RenderContext.h" -#import "Transformer.h" - -/*! - * Provides a grid, which can be use for snapping points - * - * The grid is divided into cells, and each cell is further subdivided. - * These subdivisions are the snap points for the grid. - */ -@interface Grid: NSObject <NSCopying> { - Transformer *transformer; - float spacing; - int cellSubdivisions; -} - -/*! - * The number of times to subdivide the edge of each cell - * - * Each cell will be divided into cellSubdivisions^2 squares. - */ -@property (assign) int cellSubdivisions; - -/*! - * The cell spacing - * - * Each cell will be @p cellSpacing wide and @p cellSpacing high. - */ -@property (assign) float cellSpacing; - - -/*! - * Create a new grid object. - * - * @param sp the cell spacing - this will be the width and height of each cell - * @param subs the number of cell subdivisions; the cell will end up being - * divided into subs*subs squares that are each sp/subs wide and high - * @param t the transformer to be used when snapping screen points - */ -+ (Grid*) gridWithSpacing:(float)sp subdivisions:(int)subs transformer:(Transformer*)t; -/*! - * Initialize a grid object. - * - * @param sp the cell spacing - this will be the width and height of each cell - * @param subs the number of cell subdivisions; each cell will end up being - * divided into subs*subs squares that are each sp/subs wide and high - * @param t the transformer to be used when snapping screen points - */ -- (id) initWithSpacing:(float)sp subdivisions:(int)subs transformer:(Transformer*)t; - -/*! - * Snap a point in screen co-ordinates - * - * @param p the point to snap, in screen co-ordinates - * @result @p p aligned to the nearest corner of a cell subdivision - */ -- (NSPoint) snapScreenPoint:(NSPoint)p; -/*! - * Snap a point in base co-ordinates - * - * @param p the point to snap - * @result @p p aligned to the nearest corner of a cell subdivision - */ -- (NSPoint) snapPoint:(NSPoint)p; - -/** - * Renders the grid - * - * The grid is rendered across the entire surface (subject to the context's - * clip). - * - * The internal transformer is used to convert between graph co-ordinates - * and graphics co-ordinates. - * - * @param cr the context to render in - */ -- (void) renderGridInContext:(id<RenderContext>)cr; - -/** - * Renders the grid - * - * The grid is rendered across the entire surface (subject to the context's - * clip). - * - * @param cr the context to render in - * @param t a transformer that will be used to map graph co-ordinates - * to graphics co-ordinates - */ -- (void) renderGridInContext:(id<RenderContext>)cr transformer:(Transformer*)t; - -@end - -// vi:ft=objc:noet:ts=4:sts=4:sw=4 diff --git a/tikzit/src/common/Grid.m b/tikzit/src/common/Grid.m deleted file mode 100644 index f597a4a..0000000 --- a/tikzit/src/common/Grid.m +++ /dev/null @@ -1,186 +0,0 @@ -/* - * Copyright 2011 Alex Merry <dev@randomguy3.me.uk> - * Copyright 2010 Chris Heunen - * - * 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 the Free Software Foundation; either version 2 of - * the License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see <http://www.gnu.org/licenses/>. - */ - -#import "Grid.h" -#import "util.h" - -@implementation Grid - -+ (Grid*) gridWithSpacing:(float)sp subdivisions:(int)subs transformer:(Transformer*)t { - return [[[self alloc] initWithSpacing:sp subdivisions:subs transformer:t] autorelease]; -} - -- (id) initWithSpacing:(float)sp subdivisions:(int)subs transformer:(Transformer*)t { - self = [super init]; - - if (self) { - transformer = [t retain]; - spacing = sp; - cellSubdivisions = subs; - } - - return self; -} - -- (id) copyWithZone:(NSZone*)zone { - return [[Grid allocWithZone:zone] - initWithSpacing:spacing - subdivisions:cellSubdivisions - transformer:transformer]; -} - -- (void) dealloc { - [transformer release]; - [super dealloc]; -} - -- (int) cellSubdivisions { - return cellSubdivisions; -} - -- (void) setCellSubdivisions:(int)count { - cellSubdivisions = count; -} - -- (float) cellSpacing { - return spacing; -} - -- (void) setCellSpacing:(float)sp { - spacing = sp; -} - -- (NSPoint) snapScreenPoint:(NSPoint)point { - NSPoint gridPoint = [transformer fromScreen:point]; - return [transformer toScreen:[self snapPoint:gridPoint]]; -} - -- (NSPoint) snapPoint:(NSPoint)p { - const float snapDistance = spacing/(float)cellSubdivisions; - p.x = roundToNearest (snapDistance, p.x); - p.y = roundToNearest (snapDistance, p.y); - return p; -} - -- (void) _setupLinesForContext:(id<RenderContext>)context withSpacing:(float)offset omittingEvery:(int)omitEvery origin:(NSPoint)origin { - NSRect clip = [context clipBoundingBox]; - float clipx1 = clip.origin.x; - float clipx2 = clipx1 + clip.size.width; - float clipy1 = clip.origin.y; - float clipy2 = clipy1 + clip.size.height; - - // left of the Y axis, moving outwards - unsigned int count = 1; - float x = origin.x - offset; - while (x >= clipx1) { - if (omitEvery == 0 || (count % omitEvery != 0)) { - [context moveTo:NSMakePoint(x, clipy1)]; - [context lineTo:NSMakePoint(x, clipy2)]; - } - - x -= offset; - ++count; - } - // right of the Y axis, moving outwards - count = 1; - x = origin.x + offset; - while (x <= clipx2) { - if (omitEvery == 0 || (count % omitEvery != 0)) { - [context moveTo:NSMakePoint(x, clipy1)]; - [context lineTo:NSMakePoint(x, clipy2)]; - } - - x += offset; - ++count; - } - - // above the Y axis, moving outwards - count = 1; - float y = origin.y - offset; - while (y >= clipy1) { - if (omitEvery == 0 || (count % omitEvery != 0)) { - [context moveTo:NSMakePoint(clipx1, y)]; - [context lineTo:NSMakePoint(clipx2, y)]; - } - - y -= offset; - ++count; - } - // below the Y axis, moving outwards - count = 1; - y = origin.y + offset; - while (y <= clipy2) { - if (omitEvery == 0 || (count % omitEvery != 0)) { - [context moveTo:NSMakePoint(clipx1, y)]; - [context lineTo:NSMakePoint(clipx2, y)]; - } - - y += offset; - ++count; - } -} - -- (void) _renderSubdivisionsWithContext:(id<RenderContext>)context origin:(NSPoint)origin cellSize:(float)cellSize { - const float offset = cellSize / cellSubdivisions; - - [self _setupLinesForContext:context withSpacing:offset omittingEvery:cellSubdivisions origin:origin]; - - [context strokePathWithColor:MakeSolidRColor (0.9, 0.9, 1.0)]; -} - -- (void) _renderCellsWithContext:(id<RenderContext>)context origin:(NSPoint)origin cellSize:(float)cellSize { - [self _setupLinesForContext:context withSpacing:cellSize omittingEvery:0 origin:origin]; - - [context strokePathWithColor:MakeSolidRColor (0.8, 0.8, 0.9)]; -} - -- (void) _renderAxesWithContext:(id<RenderContext>)context origin:(NSPoint)origin { - NSRect clip = [context clipBoundingBox]; - - [context moveTo:NSMakePoint(origin.x, clip.origin.y)]; - [context lineTo:NSMakePoint(origin.x, clip.origin.y + clip.size.height)]; - [context moveTo:NSMakePoint(clip.origin.x, origin.y)]; - [context lineTo:NSMakePoint(clip.origin.x + clip.size.width, origin.y)]; - - [context strokePathWithColor:MakeSolidRColor (0.6, 0.6, 0.7)]; -} - -- (void) renderGridInContext:(id<RenderContext>)cr { - [self renderGridInContext:cr transformer:transformer]; -} - -- (void) renderGridInContext:(id<RenderContext>)context transformer:(Transformer*)t { - const NSPoint origin = [t toScreen:NSZeroPoint]; - const float cellSize = [t scaleToScreen:spacing]; - - [context saveState]; - - // common line settings - [context setLineWidth:1.0]; - [context setAntialiasMode:AntialiasDisabled]; - - [self _renderSubdivisionsWithContext:context origin:origin cellSize:cellSize]; - [self _renderCellsWithContext:context origin:origin cellSize:cellSize]; - [self _renderAxesWithContext:context origin:origin]; - - [context restoreState]; -} - -@end - -// vi:ft=objc:ts=4:noet:sts=4:sw=4 diff --git a/tikzit/src/common/NSError+Tikzit.h b/tikzit/src/common/NSError+Tikzit.h deleted file mode 100644 index 0f45fba..0000000 --- a/tikzit/src/common/NSError+Tikzit.h +++ /dev/null @@ -1,44 +0,0 @@ -/* - * Copyright 2011 Alex Merry <alex.merry@kdemail.net> - * - * 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 the Free Software Foundation; either version 2 of - * the License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see <http://www.gnu.org/licenses/>. - */ - -#import <Foundation/Foundation.h> - -NSString* const TZErrorDomain; - -enum { - TZ_ERR_OTHER = 1, - TZ_ERR_BADSTATE, - TZ_ERR_BADFORMAT, - TZ_ERR_IO, - TZ_ERR_TOOL_FAILED, - TZ_ERR_NOTDIRECTORY, - TZ_ERR_PARSE -}; - -NSString* const TZToolOutputErrorKey; - -@interface NSError(Tikzit) -+ (NSString*)tikzitErrorDomain; -+ (id) errorWithMessage:(NSString*)message code:(NSInteger)code cause:(NSError*)cause; -+ (id) errorWithMessage:(NSString*)message code:(NSInteger)code; -+ (id) errorWithLibcError:(NSInteger)errnum; -- (NSString*)toolOutput; -@end - -void logError (NSError *error, NSString *message); - -// vi:ft=objc:noet:ts=4:sts=4:sw=4 diff --git a/tikzit/src/common/NSError+Tikzit.m b/tikzit/src/common/NSError+Tikzit.m deleted file mode 100644 index 6b9404b..0000000 --- a/tikzit/src/common/NSError+Tikzit.m +++ /dev/null @@ -1,64 +0,0 @@ -/* - * Copyright 2011 Alex Merry <alex.merry@kdemail.net> - * - * 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 the Free Software Foundation; either version 2 of - * the License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see <http://www.gnu.org/licenses/>. - */ - -#import "NSError+Tikzit.h" - -NSString* const TZErrorDomain = @"tikzit"; - -NSString* const TZToolOutputErrorKey = @"tool-output"; - -@implementation NSError(Tikzit) -+ (NSString*)tikzitErrorDomain { - return TZErrorDomain; -} - -+ (id) errorWithMessage:(NSString*)message code:(NSInteger)code cause:(NSError*)cause { - NSMutableDictionary *errorDetail = [NSMutableDictionary dictionaryWithCapacity:2]; - [errorDetail setValue:message forKey:NSLocalizedDescriptionKey]; - if (cause) - [errorDetail setValue:cause forKey:NSUnderlyingErrorKey]; - return [self errorWithDomain:TZErrorDomain code:code userInfo:errorDetail]; -} - -+ (id) errorWithMessage:(NSString*)message code:(NSInteger)code { - NSMutableDictionary *errorDetail = [NSMutableDictionary dictionaryWithObject:message - forKey:NSLocalizedDescriptionKey]; - return [self errorWithDomain:TZErrorDomain code:code userInfo:errorDetail]; -} - -+ (id) errorWithLibcError:(NSInteger)errnum { - NSString *message = [NSString stringWithUTF8String:strerror(errnum)]; - NSMutableDictionary *errorDetail = [NSMutableDictionary dictionaryWithObject:message - forKey:NSLocalizedDescriptionKey]; - return [self errorWithDomain:NSPOSIXErrorDomain code:errnum userInfo:errorDetail]; -} - -- (NSString*)toolOutput { - return [[self userInfo] objectForKey:TZToolOutputErrorKey]; -} - -@end - -void logError (NSError *error, NSString *message) { - if (message == nil) { - NSLog (@"%@", [error localizedDescription]); - } else { - NSLog (@"%@: %@", message, [error localizedDescription]); - } -} - -// vi:ft=objc:ts=4:noet:sts=4:sw=4 diff --git a/tikzit/src/common/NSFileManager+Utils.h b/tikzit/src/common/NSFileManager+Utils.h deleted file mode 100644 index 1349919..0000000 --- a/tikzit/src/common/NSFileManager+Utils.h +++ /dev/null @@ -1,29 +0,0 @@ -// -// NSFileManager+Utils.h -// TikZiT -// -// Copyright 2010 Alex Merry -// -// This file is part of TikZiT. -// -// TikZiT is free software: you can redistribute it and/or modify -// it under the terms of the GNU General Public License as published by -// the Free Software Foundation, either version 3 of the License, or -// (at your option) any later version. -// -// TikZiT is distributed in the hope that it will be useful, -// but WITHOUT ANY WARRANTY; without even the implied warranty of -// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -// GNU General Public License for more details. -// -// You should have received a copy of the GNU General Public License -// along with TikZiT. If not, see <http://www.gnu.org/licenses/>. -// - -#import <Foundation/Foundation.h> - -@interface NSFileManager(Utils) -- (BOOL) ensureDirectoryExists:(NSString*)path error:(NSError**)error; -@end - -// vi:ft=objc:sts=4:sw=4:ts=4:noet diff --git a/tikzit/src/common/NSFileManager+Utils.m b/tikzit/src/common/NSFileManager+Utils.m deleted file mode 100644 index 87ede95..0000000 --- a/tikzit/src/common/NSFileManager+Utils.m +++ /dev/null @@ -1,46 +0,0 @@ -// -// NSFileManager+Utils.h -// TikZiT -// -// Copyright 2010 Alex Merry -// -// This file is part of TikZiT. -// -// TikZiT is free software: you can redistribute it and/or modify -// it under the terms of the GNU General Public License as published by -// the Free Software Foundation, either version 3 of the License, or -// (at your option) any later version. -// -// TikZiT is distributed in the hope that it will be useful, -// but WITHOUT ANY WARRANTY; without even the implied warranty of -// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -// GNU General Public License for more details. -// -// You should have received a copy of the GNU General Public License -// along with TikZiT. If not, see <http://www.gnu.org/licenses/>. -// - -#import <Foundation/Foundation.h> -#import "NSError+Tikzit.h" - -@implementation NSFileManager(Utils) -- (BOOL) ensureDirectoryExists:(NSString*)directory error:(NSError**)error { - BOOL isDirectory = NO; - if (![self fileExistsAtPath:directory isDirectory:&isDirectory]) { - if (![self createDirectoryAtPath:directory withIntermediateDirectories:YES attributes:nil error:error]) { - return NO; - } - } else if (!isDirectory) { - if (error) { - NSMutableDictionary *errorDetail = [NSMutableDictionary dictionary]; - [errorDetail setValue:@"Directory is a file" forKey:NSLocalizedDescriptionKey]; - [errorDetail setValue:directory forKey:NSFilePathErrorKey]; - *error = [NSError errorWithDomain:TZErrorDomain code:TZ_ERR_NOTDIRECTORY userInfo:errorDetail]; - } - return NO; - } - return YES; -} -@end - -// vi:ft=objc:sts=4:sw=4:ts=4:noet diff --git a/tikzit/src/common/NSString+LatexConstants.h b/tikzit/src/common/NSString+LatexConstants.h deleted file mode 100644 index f4b5236..0000000 --- a/tikzit/src/common/NSString+LatexConstants.h +++ /dev/null @@ -1,33 +0,0 @@ -// -// NSString+LatexConstants.h -// TikZiT -// -// Copyright 2010 Aleks Kissinger. All rights reserved. -// -// -// This file is part of TikZiT. -// -// TikZiT is free software: you can redistribute it and/or modify -// it under the terms of the GNU General Public License as published by -// the Free Software Foundation, either version 3 of the License, or -// (at your option) any later version. -// -// TikZiT is distributed in the hope that it will be useful, -// but WITHOUT ANY WARRANTY; without even the implied warranty of -// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -// GNU General Public License for more details. -// -// You should have received a copy of the GNU General Public License -// along with TikZiT. If not, see <http://www.gnu.org/licenses/>. -// - -#import <Foundation/Foundation.h> - - -@interface NSString(LatexConstants) - -- (NSString*)stringByExpandingLatexConstants; - -@end - -// vi:ft=objc:noet:ts=4:sts=4:sw=4 diff --git a/tikzit/src/common/NSString+LatexConstants.m b/tikzit/src/common/NSString+LatexConstants.m deleted file mode 100644 index bd598b7..0000000 --- a/tikzit/src/common/NSString+LatexConstants.m +++ /dev/null @@ -1,208 +0,0 @@ -// -// NSString+LatexConstants.m -// TikZiT -// -// Copyright 2010 Aleks Kissinger. All rights reserved. -// -// -// This file is part of TikZiT. -// -// TikZiT is free software: you can redistribute it and/or modify -// it under the terms of the GNU General Public License as published by -// the Free Software Foundation, either version 3 of the License, or -// (at your option) any later version. -// -// TikZiT is distributed in the hope that it will be useful, -// but WITHOUT ANY WARRANTY; without even the implied warranty of -// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -// GNU General Public License for more details. -// -// You should have received a copy of the GNU General Public License -// along with TikZiT. If not, see <http://www.gnu.org/licenses/>. -// - -#import "NSString+LatexConstants.h" - -// can't use sizeof() in non-fragile ABI (eg: clang) -#define texConstantCount 63 -static NSString *texConstantNames[texConstantCount] = { - @"alpha", - @"beta", - @"gamma", - @"delta", - @"epsilon", - @"zeta", - @"eta", - @"theta", - @"iota", - @"kappa", - @"lambda", - @"mu", - @"nu", - @"xi", - @"pi", - @"rho", - @"sigma", - @"tau", - @"upsilon", - @"phi", - @"chi", - @"psi", - @"omega", - @"Gamma", - @"Delta", - @"Theta", - @"Lambda", - @"Xi", - @"Pi", - @"Sigma", - @"Upsilon", - @"Phi", - @"Psi", - @"Omega", - - @"pm", - @"to", - @"Rightarrow", - @"Leftrightarrow", - @"forall", - @"partial", - @"exists", - @"emptyset", - @"nabla", - @"in", - @"notin", - @"prod", - @"sum", - @"surd", - @"infty", - @"wedge", - @"vee", - @"cap", - @"cup", - @"int", - @"approx", - @"neq", - @"equiv", - @"leq", - @"geq", - @"subset", - @"supset", - @"cdot", - @"ldots" -}; - -static char * texConstantCodes[texConstantCount] = { - "\u03b1","\u03b2","\u03b3","\u03b4","\u03b5","\u03b6","\u03b7", - "\u03b8","\u03b9","\u03ba","\u03bb","\u03bc","\u03bd","\u03be", - "\u03c0","\u03c1","\u03c3","\u03c4","\u03c5","\u03c6","\u03c7", - "\u03c8","\u03c9","\u0393","\u0394","\u0398","\u039b","\u039e", - "\u03a0","\u03a3","\u03a5","\u03a6","\u03a8","\u03a9", - - "\u00b1","\u2192","\u21d2","\u21d4","\u2200","\u2202","\u2203", - "\u2205","\u2207","\u2208","\u2209","\u220f","\u2211","\u221a", - "\u221e","\u2227","\u2228","\u2229","\u222a","\u222b","\u2248", - "\u2260","\u2261","\u2264","\u2265","\u2282","\u2283","\u22c5", - "\u2026" -}; - -#define texModifierCount 10 -static NSString *texModifierNames[texModifierCount] = { - @"tiny", - @"scriptsize", - @"footnotesize", - @"small", - @"normalsize", - @"large", - @"Large", - @"LARGE", - @"huge", - @"Huge" -}; - -static NSDictionary *texConstants = nil; -static NSSet *texModifiers = nil; - -@implementation NSString(LatexConstants) - -- (NSString*)stringByExpandingLatexConstants { - - if (texConstants == nil) { - NSMutableDictionary *constants = [[NSMutableDictionary alloc] initWithCapacity:texConstantCount]; - for (int i = 0; i < texConstantCount; ++i) { - [constants setObject:[NSString stringWithUTF8String:texConstantCodes[i]] forKey:texConstantNames[i]]; - } - texConstants = constants; - } - if (texModifiers == nil) { - texModifiers = [[NSSet alloc] initWithObjects:texModifierNames count:texModifierCount]; - } - - NSMutableString *buf = [[NSMutableString alloc] initWithCapacity:[self length]]; - NSMutableString *wordBuf = [[NSMutableString alloc] initWithCapacity:10]; - - unichar c_a = [@"a" characterAtIndex:0]; - unichar c_z = [@"z" characterAtIndex:0]; - unichar c_A = [@"A" characterAtIndex:0]; - unichar c_Z = [@"Z" characterAtIndex:0]; - - int state = 0; - // a tiny little DFA to replace \\([\w*]) with unicode of $1 - unichar c; - NSString *code; - int i; - for (i = 0; i<[self length]; ++i) { - c = [self characterAtIndex:i]; - switch (state) { - case 0: - if (c=='\\') { - state = 1; - } else if (c!='$') { - [buf appendFormat:@"%C", c]; - } - break; - case 1: - if ((c>=c_a && c<=c_z) || (c>=c_A && c<=c_Z)) { - [wordBuf appendFormat:@"%C", c]; - } else { - code = [texConstants objectForKey:wordBuf]; - if (code != nil) { - [buf appendString:code]; - } else if (![texModifiers containsObject:wordBuf]) { - [buf appendFormat:@"\\%@", wordBuf]; - } - - [wordBuf setString:@""]; - if (c=='\\') { - state = 1; - } else { - if (c!='$') { - [buf appendFormat:@"%C", c]; - } - state = 0; - } - - } - break; - } - } - - if (state == 1) { - code = [texConstants objectForKey:wordBuf]; - if (code != nil) { - [buf appendString:code]; - } else if (![texModifiers containsObject:wordBuf]) { - [buf appendFormat:@"\\%@", wordBuf]; - } - } - - NSString *ret = [buf copy]; - [buf release]; - [wordBuf release]; - - return [ret autorelease]; -} - -@end - -// vi:ft=objc:ts=4:noet:sts=4:sw=4 diff --git a/tikzit/src/common/NSString+Tikz.h b/tikzit/src/common/NSString+Tikz.h deleted file mode 100644 index ea6ea40..0000000 --- a/tikzit/src/common/NSString+Tikz.h +++ /dev/null @@ -1,26 +0,0 @@ -/* - * Copyright 2013 Alex Merry <alex.merry@kdemail.net> - * - * 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 the Free Software Foundation; either version 2 of - * the License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see <http://www.gnu.org/licenses/>. - */ - -#import <Foundation/Foundation.h> - -@interface NSString (Tikz) - - (NSString*) tikzEscapedString; - - (BOOL) isValidTikzPropertyNameOrValue; - - (BOOL) isValidAnchor; -@end - -// vi:ft=objc:noet:ts=4:sts=4:sw=4 diff --git a/tikzit/src/common/NSString+Tikz.m b/tikzit/src/common/NSString+Tikz.m deleted file mode 100644 index 520ffd3..0000000 --- a/tikzit/src/common/NSString+Tikz.m +++ /dev/null @@ -1,63 +0,0 @@ -/* - * Copyright 2013 Alex Merry <alex.merry@kdemail.net> - * - * 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 the Free Software Foundation; either version 2 of - * the License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see <http://www.gnu.org/licenses/>. - */ - -#import "NSString+Tikz.h" -#import "TikzGraphAssembler.h" - -@implementation NSString (Tikz) - -- (NSString*) tikzEscapedString { - static NSCharacterSet *avoid = nil; - if (avoid == nil) - avoid = [[[NSCharacterSet characterSetWithCharactersInString:@"abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ<>-'0123456789. "] invertedSet] retain]; - - if ([self rangeOfCharacterFromSet:avoid].length > 0) { - return [NSString stringWithFormat:@"{%@}", self]; - } else { - return [[self retain] autorelease]; - } -} - -- (BOOL) isValidTikzPropertyNameOrValue { - NSUInteger length = [self length]; - unsigned int brace_depth = 0; - unsigned int escape = 0; - for (NSUInteger i = 0; i < length; ++i) { - unichar c = [self characterAtIndex:i]; - - if (escape) { - escape = 0; - } else if (c == '\\') { - escape = 1; - } else if (c == '{') { - brace_depth++; - } else if (c == '}') { - if (brace_depth == 0) - return NO; - brace_depth--; - } - } - return !escape && brace_depth == 0; -} - -- (BOOL) isValidAnchor { - return [TikzGraphAssembler validateTikzEdgeAnchor:self]; -} - -@end - -// vi:ft=objc:noet:ts=4:sts=4:sw=4 diff --git a/tikzit/src/common/Node.h b/tikzit/src/common/Node.h deleted file mode 100644 index 1e580ce..0000000 --- a/tikzit/src/common/Node.h +++ /dev/null @@ -1,181 +0,0 @@ -// -// Node.h -// TikZiT -// -// Copyright 2010 Aleks Kissinger. All rights reserved. -// -// -// This file is part of TikZiT. -// -// TikZiT is free software: you can redistribute it and/or modify -// it under the terms of the GNU General Public License as published by -// the Free Software Foundation, either version 3 of the License, or -// (at your option) any later version. -// -// TikZiT is distributed in the hope that it will be useful, -// but WITHOUT ANY WARRANTY; without even the implied warranty of -// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -// GNU General Public License for more details. -// -// You should have received a copy of the GNU General Public License -// along with TikZiT. If not, see <http://www.gnu.org/licenses/>. -// - - -// Node : store the data associated with a node. - -#import <Foundation/Foundation.h> - -#import "NodeStyle.h" -#import "GraphElementData.h" - -@class GraphElementProperty; -@class Shape; -@class Transformer; - -/*! - @class Node - @brief A graph node, with associated location and style data. - */ -@interface Node : NSObject<NSCopying> { - NSPoint point; - NodeStyle *style; - NSString *name; - NSString *label; - GraphElementData *data; -} - -/*! - @property shape - @brief The shape to use - @detail This is a convenience property that resolves the shape name - from the style, and uses a circle if there is no style. - - This property is NOT KVO-compliant - */ -@property (readonly) Shape *shape; - -/*! - @property point - @brief The point where this node is located. - */ -@property (assign) NSPoint point; - -/*! - @property style - @brief The style of this node. - */ -@property (retain) NodeStyle *style; - -/*! - @property name - @brief The name of this node. This is a temporary name and may change between - successive TikZ outputs. - */ -@property (copy) NSString *name; - -/*! - @property label - @brief The latex label that appears on this node. - */ -@property (copy) NSString *label; - -/*! - @property data - @brief Associated extra data. - */ -@property (copy) GraphElementData *data; - -// KVC methods -- (void) insertObject:(GraphElementProperty*)gep - inDataAtIndex:(NSUInteger)index; -- (void) removeObjectFromDataAtIndex:(NSUInteger)index; -- (void) replaceObjectInDataAtIndex:(NSUInteger)index - withObject:(GraphElementProperty*)gep; - -/*! - @brief Initialize a new node with the given point. - @param p a point. - @result A node. - */ -- (id)initWithPoint:(NSPoint)p; - -/*! - @brief Initialize a new node at (0,0). - @result A node. - */ -- (id)init; - -/*! - @brief Composes the shape transformer with another transformer - @param t The transform to apply before the shape transform - @result A transformer that first maps according to t, then according - to -shapeTransformer. - */ -- (Transformer*) shapeTransformerFromTransformer:(Transformer*)t; - -/*! - @brief A transformer that may be used to convert the shape to the - right position and scale - */ -- (Transformer*) shapeTransformer; - -/*! - @brief The bounding rect in the given co-ordinate system - @detail This is the bounding rect of the shape (after being - suitably translated and scaled). The label is not - considered. - @param shapeTrans The mapping from graph co-ordinates to the required - co-ordinates - @result The bounding rectangle - */ -- (NSRect) boundsUsingShapeTransform:(Transformer*)shapeTrans; - -/*! - @brief The bounding rect in graph co-ordinates - @detail This is the bounding rect of the shape (after being suitably - translated and scaled). The label is not considered. - */ -- (NSRect) boundingRect; - -/*! - @brief Try to attach a style of the correct name from the given style list. - @param styles an array of styles. - @result YES if successfully attached, NO otherwise. - */ -- (BOOL)attachStyleFromTable:(NSArray*)styles; - -/*! - @brief Set node properties from <tt>GraphElementData</tt>. - */ -- (void)updateData; - -/*! - @brief Set properties of this node to match the given node. - @param nd a node to mimic. - */ -- (void)setPropertiesFromNode:(Node *)nd; - -/*! - @brief Compare a node to another node using a lex ordering on coordinates. - @param nd another node. - @result A comparison result. - */ -- (NSComparisonResult)compareTo:(id)nd; - -/*! - @brief Factory method to construct a node with the given point. - @param p a point. - @result A node. - */ -+ (Node*)nodeWithPoint:(NSPoint)p; - -/*! - @brief Factory method to construct a node at (0,0). - @result A node. - */ -+ (Node*)node; - -@end - -// vi:ft=objc:noet:ts=4:sts=4:sw=4 diff --git a/tikzit/src/common/Node.m b/tikzit/src/common/Node.m deleted file mode 100644 index 8c64b6b..0000000 --- a/tikzit/src/common/Node.m +++ /dev/null @@ -1,192 +0,0 @@ -// -// Node.m -// TikZiT -// -// Copyright 2010 Aleks Kissinger. All rights reserved. -// -// -// This file is part of TikZiT. -// -// TikZiT is free software: you can redistribute it and/or modify -// it under the terms of the GNU General Public License as published by -// the Free Software Foundation, either version 3 of the License, or -// (at your option) any later version. -// -// TikZiT is distributed in the hope that it will be useful, -// but WITHOUT ANY WARRANTY; without even the implied warranty of -// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -// GNU General Public License for more details. -// -// You should have received a copy of the GNU General Public License -// along with TikZiT. If not, see <http://www.gnu.org/licenses/>. -// - -#import "Node.h" - -#import "Shape.h" - - -@implementation Node - -- (id)initWithPoint:(NSPoint)p { - self = [super init]; - if (self) { - data = [[GraphElementData alloc] init]; - style = nil; - label = @""; - point = p; - } - return self; -} - -- (id)init { - return [self initWithPoint:NSMakePoint(0.0f, 0.0f)]; -} - -- (id)copyWithZone:(NSZone*)z { - Node *cp = [[Node allocWithZone:z] init]; - [cp setPropertiesFromNode:self]; - return cp; -} - -- (void)dealloc { - [name release]; - [style release]; - [data release]; - [label release]; - [super dealloc]; -} - -- (Shape*) shape { - if (style) { - return [Shape shapeForName:[style shapeName]]; - } else { - return nil; - } -} - -- (Transformer*) shapeTransformerFromTransformer:(Transformer*)t { - // we take a copy to keep the reflection attributes - Transformer *transformer = [[t copy] autorelease]; - NSPoint screenPos = [t toScreen:point]; - [transformer setOrigin:screenPos]; - float scale = [t scale]; - if (style) { - scale *= [style scale]; - } - [transformer setScale:scale]; - return transformer; -} - -- (Transformer*) shapeTransformer { - float scale = 1.0f; - if (style) { - scale = [style scale]; - } - return [Transformer transformerWithOrigin:point andScale:scale]; -} - -- (NSRect) boundsUsingShapeTransform:(Transformer*)shapeTrans { - //if (style) { - return [shapeTrans rectToScreen:[[self shape] boundingRect]]; - /*} else { - NSRect r = NSZeroRect; - r.origin = [shapeTrans toScreen:[self point]]; - return r; - }*/ -} - -- (NSRect) boundingRect { - return [self boundsUsingShapeTransform:[self shapeTransformer]]; -} - -- (BOOL)attachStyleFromTable:(NSArray*)styles { - NSString *style_name = [[[data propertyForKey:@"style"] retain] autorelease]; - - [self setStyle:nil]; - - // 'none' is a reserved style - if (style_name == nil || [style_name isEqualToString:@"none"]) return YES; - - for (NodeStyle *s in styles) { - if ([[s name] compare:style_name]==NSOrderedSame) { - [self setStyle:s]; - return YES; - } - } - - // if we didn't find a style, fill in a default one - [self setStyle:[NodeStyle defaultNodeStyleWithName:style_name]]; - return NO; -} - -- (void)updateData { - if (style == nil) { - [data setProperty:@"none" forKey:@"style"]; - } else { - [data setProperty:[style name] forKey:@"style"]; - } -} - -- (void)setPropertiesFromNode:(Node*)nd { - [self setPoint:[nd point]]; - [self setStyle:[nd style]]; - [self setName:[nd name]]; - [self setData:[nd data]]; - [self setLabel:[nd label]]; -} - -+ (Node*)nodeWithPoint:(NSPoint)p { - return [[[Node alloc] initWithPoint:p] autorelease]; -} - -+ (Node*)node { - return [[[Node alloc] init] autorelease]; -} - - -// perform a lexicographic ordering (-y, x) on coordinates. -- (NSComparisonResult)compareTo:(id)nd { - Node *node = (Node*)nd; - if (point.y > [node point].y) return NSOrderedAscending; - else if (point.y < [node point].y) return NSOrderedDescending; - else { - if (point.x < [node point].x) return NSOrderedAscending; - else if (point.x > [node point].x) return NSOrderedDescending; - else return NSOrderedSame; - } -} - -@synthesize name; -@synthesize label; -@synthesize point; - -@synthesize data; -- (void) insertObject:(GraphElementProperty*)gep - inDataAtIndex:(NSUInteger)index { - [data insertObject:gep atIndex:index]; -} -- (void) removeObjectFromDataAtIndex:(NSUInteger)index { - [data removeObjectAtIndex:index]; -} -- (void) replaceObjectInDataAtIndex:(NSUInteger)index - withObject:(GraphElementProperty*)gep { - [data replaceObjectAtIndex:index withObject:gep]; -} - -- (NodeStyle*)style { - return style; -} - -- (void)setStyle:(NodeStyle *)st { - if (style != st) { - NodeStyle *oldStyle = style; - style = [st retain]; - [oldStyle release]; - } - [self updateData]; -} - -@end - -// vi:ft=objc:ts=4:noet:sts=4:sw=4 diff --git a/tikzit/src/common/NodeStyle.h b/tikzit/src/common/NodeStyle.h deleted file mode 100644 index 034f95d..0000000 --- a/tikzit/src/common/NodeStyle.h +++ /dev/null @@ -1,125 +0,0 @@ -// -// NodeStyle.h -// TikZiT -// -// Copyright 2010 Aleks Kissinger. All rights reserved. -// -// -// This file is part of TikZiT. -// -// TikZiT is free software: you can redistribute it and/or modify -// it under the terms of the GNU General Public License as published by -// the Free Software Foundation, either version 3 of the License, or -// (at your option) any later version. -// -// TikZiT is distributed in the hope that it will be useful, -// but WITHOUT ANY WARRANTY; without even the implied warranty of -// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -// GNU General Public License for more details. -// -// You should have received a copy of the GNU General Public License -// along with TikZiT. If not, see <http://www.gnu.org/licenses/>. -// - -#import "util.h" -#import "ColorRGB.h" -#import "PropertyHolder.h" - -/*! - @class NodeStyle - @brief Store node style information. - @details Store node style information. These properties affect how a node - is displayed in TikZiT. Colors are stored in the ColorRGB struct - to avoid any Cocoa dependency. These styles should be persistant, - which should be implemented in a platform-specific category. For - OS X, this is NodeStyle+Coder. - */ -@interface NodeStyle : PropertyHolder <NSCopying> { - int strokeThickness; - float scale; - ColorRGB *strokeColorRGB; - ColorRGB *fillColorRGB; - NSString *name; - NSString *shapeName; - NSString *category; -} - -/*! - @property strokeThickness - @brief Thickness of the stroke. - */ -@property (assign) int strokeThickness; - -/*! - @property scale - @brief Overall scale of the shape. Defaults to 1.0. - */ -@property (assign) float scale; - - -/*! - @property strokeColorRGB - @brief The stroke color used to render the node - */ -@property (copy) ColorRGB *strokeColorRGB; - -/*! - @property fillColorRGB - @brief The fill color used to render the node - */ -@property (copy) ColorRGB *fillColorRGB; - -/*! - @property name - @brief Style name. - @details Style name. This is the only thing that affects how the node - will look when the latex code is rendered. - */ -@property (copy) NSString *name; - -/*! - @property shapeName - @brief The name of the shape that will be drawn in TikZiT. - */ -@property (copy) NSString *shapeName; - -/*! - @property category - @brief ??? - */ -@property (copy) NSString *category; - -@property (readonly) NSString *tikz; -@property (readonly) BOOL strokeColorIsKnown; -@property (readonly) BOOL fillColorIsKnown; - -+ (int) defaultStrokeThickness; - -/*! - @brief Designated initializer. Construct a blank style with name 'new'. - @result A default style. - */ -- (id)init; - -/*! - @brief Create a named style. - @param nm the style name. - @result A <tt>NodeStyle</tt> with the given name. - */ -- (id)initWithName:(NSString *)nm; - -/*! - @brief Factory method for initWithName: - @param nm the style name. - @result A <tt>NodeStyle</tt> with the given name. - */ -+ (NodeStyle*)defaultNodeStyleWithName:(NSString *)nm; - -/*! - * Make this style the same as the given one - */ -- (void) updateFromStyle:(NodeStyle*)style; - -@end - -// vi:ft=objc:noet:ts=4:sts=4:sw=4 diff --git a/tikzit/src/common/NodeStyle.m b/tikzit/src/common/NodeStyle.m deleted file mode 100644 index f81d7eb..0000000 --- a/tikzit/src/common/NodeStyle.m +++ /dev/null @@ -1,226 +0,0 @@ -// -// NodeStyle.m -// TikZiT -// -// Copyright 2010 Aleks Kissinger. All rights reserved. -// -// -// This file is part of TikZiT. -// -// TikZiT is free software: you can redistribute it and/or modify -// it under the terms of the GNU General Public License as published by -// the Free Software Foundation, either version 3 of the License, or -// (at your option) any later version. -// -// TikZiT is distributed in the hope that it will be useful, -// but WITHOUT ANY WARRANTY; without even the implied warranty of -// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -// GNU General Public License for more details. -// -// You should have received a copy of the GNU General Public License -// along with TikZiT. If not, see <http://www.gnu.org/licenses/>. -// - -#import "NodeStyle.h" -#import "Shape.h" -#import "ShapeNames.h" - -@implementation NodeStyle - -+ (void)initialize { - [self setKeys:[NSArray arrayWithObjects: - @"fillColorRGB.red", - @"fillColorRGB.blue", - @"fillColorRGB.green", - @"strokeColorRGB.red", - @"strokeColorRGB.blue", - @"strokeColorRGB.green", - @"strokeThickness", - @"shapeName", - @"name", - nil] - triggerChangeNotificationsForDependentKey:@"tikz"]; - [self setKeys:[NSArray arrayWithObjects: - @"fillColorRGB.name", - nil] - triggerChangeNotificationsForDependentKey:@"fillColorIsKnown"]; - [self setKeys:[NSArray arrayWithObjects: - @"strokeColorRGB.name", - nil] - triggerChangeNotificationsForDependentKey:@"strokeColorIsKnown"]; -} - -+ (int) defaultStrokeThickness { return 1; } - -- (id)initWithName:(NSString*)nm { - self = [super initWithNotificationName:@"NodeStylePropertyChanged"]; - if (self != nil) { - strokeThickness = [NodeStyle defaultStrokeThickness]; - scale = 1.0f; - strokeColorRGB = [[ColorRGB alloc] initWithRed:0 green:0 blue:0]; - fillColorRGB = [[ColorRGB alloc] initWithRed:255 green:255 blue:255]; - - name = nm; - category = nil; - shapeName = SHAPE_CIRCLE; - } - return self; -} - -- (id)init { - self = [self initWithName:@"new"]; - return self; -} - -- (id)copyWithZone:(NSZone*)zone { - NodeStyle *style = [[NodeStyle allocWithZone:zone] init]; - - [style setStrokeThickness:[self strokeThickness]]; - [style setScale:[self scale]]; - [style setStrokeColorRGB:[self strokeColorRGB]]; - [style setFillColorRGB:[self fillColorRGB]]; - [style setName:[self name]]; - [style setShapeName:[self shapeName]]; - [style setCategory:[self category]]; - - return style; -} - -- (void)dealloc { - [name release]; - [category release]; - [shapeName release]; - [strokeColorRGB release]; - [fillColorRGB release]; - [super dealloc]; -} - -- (void) updateFromStyle:(NodeStyle*)style { - [self setStrokeThickness:[style strokeThickness]]; - [self setScale:[style scale]]; - [self setStrokeColorRGB:[style strokeColorRGB]]; - [self setFillColorRGB:[style fillColorRGB]]; - [self setName:[style name]]; - [self setShapeName:[style shapeName]]; - [self setCategory:[style category]]; -} - -+ (NodeStyle*)defaultNodeStyleWithName:(NSString*)nm { - return [[[NodeStyle alloc] initWithName:nm] autorelease]; -} - -- (NSString*)name { - return name; -} - -- (void)setName:(NSString *)s { - if (name != s) { - NSString *oldValue = name; - name = [s copy]; - [self postPropertyChanged:@"name" oldValue:oldValue]; - [oldValue release]; - } -} - -- (NSString*)shapeName { - return shapeName; -} - -- (void)setShapeName:(NSString *)s { - if (shapeName != s) { - NSString *oldValue = shapeName; - shapeName = [s copy]; - [self postPropertyChanged:@"shapeName" oldValue:oldValue]; - [oldValue release]; - } -} - -- (NSString*)category { - return category; -} - -- (void)setCategory:(NSString *)s { - if (category != s) { - NSString *oldValue = category; - category = [s copy]; - [self postPropertyChanged:@"category" oldValue:oldValue]; - [oldValue release]; - } -} - -- (int)strokeThickness { return strokeThickness; } -- (void)setStrokeThickness:(int)i { - int oldValue = strokeThickness; - strokeThickness = i; - [self postPropertyChanged:@"strokeThickness" oldValue:[NSNumber numberWithInt:oldValue]]; -} - -- (float)scale { return scale; } -- (void)setScale:(float)s { - float oldValue = scale; - scale = s; - [self postPropertyChanged:@"scale" oldValue:[NSNumber numberWithFloat:oldValue]]; -} - -- (ColorRGB*)strokeColorRGB { - return strokeColorRGB; -} - -- (void)setStrokeColorRGB:(ColorRGB*)c { - if (strokeColorRGB != c) { - ColorRGB *oldValue = strokeColorRGB; - strokeColorRGB = [c copy]; - [self postPropertyChanged:@"strokeColorRGB" oldValue:oldValue]; - [oldValue release]; - } -} - -- (ColorRGB*)fillColorRGB { - return fillColorRGB; -} - -- (void)setFillColorRGB:(ColorRGB*)c { - if (fillColorRGB != c) { - ColorRGB *oldValue = fillColorRGB; - fillColorRGB = [c copy]; - [self postPropertyChanged:@"fillColorRGB" oldValue:oldValue]; - [oldValue release]; - } -} - -- (NSString*)tikz { - NSString *fillName = [fillColorRGB name]; - NSString *strokeName = [strokeColorRGB name]; - NSString *stroke = @""; - if (strokeThickness != 1) { - stroke = [NSString stringWithFormat:@",line width=%@ pt", - [NSNumber numberWithFloat:(float)strokeThickness * 0.4f]]; - } - - // If the colors are unknown, fall back on hexnames. These should be defined as colors - // in the Preambles class. - if (fillName == nil) fillName = [fillColorRGB hexName]; - if (strokeName == nil) strokeName = [strokeColorRGB hexName]; - - NSString *shapeDesc = [[Shape shapeForName:shapeName] styleTikz]; - if (shapeDesc == nil) shapeDesc = shapeName; - - return [NSString stringWithFormat:@"\\tikzstyle{%@}=[%@,fill=%@,draw=%@%@]", - name, - shapeDesc, - fillName, - strokeName, - stroke]; -} - -- (BOOL)strokeColorIsKnown { - return ([strokeColorRGB name] != nil); -} - -- (BOOL)fillColorIsKnown { - return ([fillColorRGB name] != nil); -} - -@end - -// vi:ft=objc:ts=4:noet:sts=4:sw=4 diff --git a/tikzit/src/common/PickSupport.h b/tikzit/src/common/PickSupport.h deleted file mode 100644 index 0749649..0000000 --- a/tikzit/src/common/PickSupport.h +++ /dev/null @@ -1,164 +0,0 @@ -// -// PickSupport.h -// TikZiT -// -// Copyright 2010 Aleks Kissinger. All rights reserved. -// -// -// This file is part of TikZiT. -// -// TikZiT is free software: you can redistribute it and/or modify -// it under the terms of the GNU General Public License as published by -// the Free Software Foundation, either version 3 of the License, or -// (at your option) any later version. -// -// TikZiT is distributed in the hope that it will be useful, -// but WITHOUT ANY WARRANTY; without even the implied warranty of -// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -// GNU General Public License for more details. -// -// You should have received a copy of the GNU General Public License -// along with TikZiT. If not, see <http://www.gnu.org/licenses/>. -// - - -#import <Foundation/Foundation.h> -#import "Node.h" -#import "Edge.h" - -/*! - @class PickSupport - @brief Maintain the selection state of nodes and edges. - @detail In addition to the notifications listed for specific methods, - whenever the node selection changes, a "NodeSelectionChanged" - signal is emitted, and whenever the edge selection changes, - an "EdgeSelectionChanged" signal is emitted. - */ -@interface PickSupport : NSObject { - NSMutableSet *selectedNodes; - NSMutableSet *selectedEdges; -} - -/*! - @property selectedNodes - @brief A set of selected nodes. - */ -@property (readonly) NSSet *selectedNodes; - -// KVC methods -- (void)addSelectedNodesObject:(Node*)node; -- (void)addSelectedNodes:(NSSet*)nodes; -- (void)removeSelectedNodesObject:(Node*)node; -- (void)removeSelectedNodes:(NSSet*)nodes; - -/*! - @property selectedEdges - @brief A set of selected edges. - */ -@property (readonly) NSSet *selectedEdges; - -// KVC methods -- (void)addSelectedEdgesObject:(Edge*)edge; -- (void)addSelectedEdges:(NSSet*)edges; -- (void)removeSelectedEdgesObject:(Edge*)edge; -- (void)removeSelectedEdges:(NSSet*)edges; - -/*! - @brief Check if a node is selected. - @param nd a node. - @result YES if nd is selected. - */ -- (BOOL)isNodeSelected:(Node*)nd; - -/*! - @brief Check if an edge is selected. - @param e an edge. - @result YES if e is selected. - */ -- (BOOL)isEdgeSelected:(Edge*)e; - -/*! - @brief Select a node. - @details Sends the "NodeSelected" notification if the node was not - already selected, with @p nd as "node" in the userInfo - @param nd a node. - */ -- (void)selectNode:(Node*)nd; - -/*! - @brief Deselect a node. - @details Sends the "NodeDeselected" notification if the node was - selected, with @p nd as "node" in the userInfo - @param nd a node. - */ -- (void)deselectNode:(Node*)nd; - -/*! - @brief Select an edge. - @details Sends the "EdgeSelected" notification if the node was not - already selected, with @p e as "edge" in the userInfo - @param e an edge. - */ -- (void)selectEdge:(Edge*)e; - -/*! - @brief Deselect an edge. - @details Sends the "EdgeDeselected" notification if the node was - selected, with @p e as "edge" in the userInfo - @param e an edge. - */ -- (void)deselectEdge:(Edge*)e; - -/*! - @brief Toggle the selected state of the given node. - @details Sends the "NodeSelected" or "NodeDeselected" notification as - appropriate, with @p nd as "node" in the userInfo - @param nd a node. - */ -- (void)toggleNodeSelected:(Node*)nd; - -/*! - @brief Select all nodes in the given set. - @details Sends the "NodeSelectionReplaced" notification if this - caused the selection to change. - - Equivalent to selectAllNodes:nodes replacingSelection:YES - @param nodes a set of nodes. - */ -- (void)selectAllNodes:(NSSet*)nodes; - -/*! - @brief Select all nodes in the given set. - @details Sends the "NodeSelectionReplaced" notification if this - caused the selection to change. - - If replace is NO, @p nodes will be added to the existing - selection, otherwise it will replace the existing selection. - @param nodes a set of nodes. - @param replace whether to replace the existing selection - */ -- (void)selectAllNodes:(NSSet*)nodes replacingSelection:(BOOL)replace; - -/*! - @brief Deselect all nodes. - @details Sends the "NodeSelectionReplaced" notification if there - were any nodes previously selected - */ -- (void)deselectAllNodes; - -/*! - @brief Deselect all edges. - @details Sends the "EdgeSelectionReplaced" notification if there - were any edges previously selected - */ -- (void)deselectAllEdges; - -/*! - @brief Factory method for getting a new <tt>PickSupport</tt> object. - @result An empty <tt>PickSupport</tt>. - */ -+ (PickSupport*)pickSupport; - -@end - -// vi:ft=objc:noet:ts=4:sts=4:sw=4 diff --git a/tikzit/src/common/PickSupport.m b/tikzit/src/common/PickSupport.m deleted file mode 100644 index 6470214..0000000 --- a/tikzit/src/common/PickSupport.m +++ /dev/null @@ -1,219 +0,0 @@ -// -// PickSupport.m -// TikZiT -// -// Copyright 2010 Aleks Kissinger. All rights reserved. -// -// -// This file is part of TikZiT. -// -// TikZiT is free software: you can redistribute it and/or modify -// it under the terms of the GNU General Public License as published by -// the Free Software Foundation, either version 3 of the License, or -// (at your option) any later version. -// -// TikZiT is distributed in the hope that it will be useful, -// but WITHOUT ANY WARRANTY; without even the implied warranty of -// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -// GNU General Public License for more details. -// -// You should have received a copy of the GNU General Public License -// along with TikZiT. If not, see <http://www.gnu.org/licenses/>. -// - -#import "PickSupport.h" - - -@implementation PickSupport - -- (void) postNodeSelectionChanged { - [[NSNotificationCenter defaultCenter] - postNotificationName:@"NodeSelectionChanged" - object:self]; -} - -- (void) postEdgeSelectionChanged { - [[NSNotificationCenter defaultCenter] - postNotificationName:@"EdgeSelectionChanged" - object:self]; -} - -- (id) init { - self = [super init]; - - if (self) { - selectedNodes = [[NSMutableSet set] retain]; - selectedEdges = [[NSMutableSet set] retain]; - } - - return self; -} - -+ (PickSupport*)pickSupport { - return [[[PickSupport alloc] init] autorelease]; -} - -@synthesize selectedNodes; -- (void)addSelectedNodesObject:(Node*)node { - return [self selectNode:node]; -} -- (void)addSelectedNodes:(NSSet*)nodes { - return [self selectAllNodes:nodes replacingSelection:NO]; -} -- (void)removeSelectedNodesObject:(Node*)node { - return [self deselectNode:node]; -} -- (void)removeSelectedNodes:(NSSet*)nodes { - if ([selectedNodes count] > 0) { - [selectedNodes minusSet:nodes]; - [[NSNotificationCenter defaultCenter] - postNotificationName:@"NodeSelectionReplaced" - object:self]; - [self postNodeSelectionChanged]; - } -} - -@synthesize selectedEdges; -- (void)addSelectedEdgesObject:(Edge*)edge { - return [self selectEdge:edge]; -} -- (void)addSelectedEdges:(NSSet*)edges { - if (selectedEdges == edges) { - return; - } - if ([edges count] == 0) { - return; - } - - [selectedEdges unionSet:edges]; - [[NSNotificationCenter defaultCenter] - postNotificationName:@"EdgeSelectionReplaced" - object:self]; - [self postEdgeSelectionChanged]; -} -- (void)removeSelectedEdgesObject:(Edge*)edge { - return [self deselectEdge:edge]; -} -- (void)removeSelectedEdges:(NSSet*)edges { - if ([selectedEdges count] > 0 && [edges count] > 0) { - [selectedEdges minusSet:edges]; - [[NSNotificationCenter defaultCenter] - postNotificationName:@"EdgeSelectionReplaced" - object:self]; - [self postEdgeSelectionChanged]; - } -} - -- (BOOL)isNodeSelected:(Node*)nd { - return [selectedNodes containsObject:nd]; -} - -- (BOOL)isEdgeSelected:(Edge*)e { - return [selectedEdges containsObject:e]; -} - -- (void)selectNode:(Node*)nd { - if (nd != nil && ![selectedNodes member:nd]) { - [selectedNodes addObject:nd]; - [[NSNotificationCenter defaultCenter] - postNotificationName:@"NodeSelected" - object:self - userInfo:[NSDictionary dictionaryWithObject:nd forKey:@"node"]]; - [self postNodeSelectionChanged]; - } -} - -- (void)deselectNode:(Node*)nd { - if (nd != nil && [selectedNodes member:nd]) { - [selectedNodes removeObject:nd]; - [[NSNotificationCenter defaultCenter] - postNotificationName:@"NodeDeselected" - object:self - userInfo:[NSDictionary dictionaryWithObject:nd forKey:@"node"]]; - [self postNodeSelectionChanged]; - } -} - -- (void)selectEdge:(Edge*)e { - if (e != nil && ![selectedEdges member:e]) { - [selectedEdges addObject:e]; - [[NSNotificationCenter defaultCenter] - postNotificationName:@"EdgeSelected" - object:self - userInfo:[NSDictionary dictionaryWithObject:e forKey:@"edge"]]; - [self postEdgeSelectionChanged]; - } -} - -- (void)deselectEdge:(Edge*)e { - if (e != nil && [selectedEdges member:e]) { - [selectedEdges removeObject:e]; - [[NSNotificationCenter defaultCenter] - postNotificationName:@"EdgeDeselected" - object:self - userInfo:[NSDictionary dictionaryWithObject:e forKey:@"edge"]]; - [self postEdgeSelectionChanged]; - } -} - -- (void)toggleNodeSelected:(Node*)nd { - if ([self isNodeSelected:nd]) - [self deselectNode:nd]; - else - [self selectNode:nd]; -} - -- (void)selectAllNodes:(NSSet*)nodes { - [self selectAllNodes:nodes replacingSelection:YES]; -} - -- (void)selectAllNodes:(NSSet*)nodes replacingSelection:(BOOL)replace { - if (selectedNodes == nodes) { - return; - } - if (!replace && [nodes count] == 0) { - return; - } - - if (replace) { - [selectedNodes release]; - selectedNodes = [nodes mutableCopy]; - } else { - [selectedNodes unionSet:nodes]; - } - [[NSNotificationCenter defaultCenter] - postNotificationName:@"NodeSelectionReplaced" - object:self]; - [self postNodeSelectionChanged]; -} - -- (void)deselectAllNodes { - if ([selectedNodes count] > 0) { - [selectedNodes removeAllObjects]; - [[NSNotificationCenter defaultCenter] - postNotificationName:@"NodeSelectionReplaced" - object:self]; - [self postNodeSelectionChanged]; - } -} - -- (void)deselectAllEdges { - if ([selectedEdges count] > 0) { - [selectedEdges removeAllObjects]; - [[NSNotificationCenter defaultCenter] - postNotificationName:@"EdgeSelectionReplaced" - object:self]; - [self postEdgeSelectionChanged]; - } -} - -- (void)dealloc { - [selectedNodes release]; - [selectedEdges release]; - - [super dealloc]; -} - -@end - -// vi:ft=objc:ts=4:noet:sts=4:sw=4 diff --git a/tikzit/src/common/Preambles.h b/tikzit/src/common/Preambles.h deleted file mode 100644 index 95081c4..0000000 --- a/tikzit/src/common/Preambles.h +++ /dev/null @@ -1,68 +0,0 @@ -// -// Preambles.h -// TikZiT -// -// Copyright 2010 Aleks Kissinger. All rights reserved. -// Copyright 2011 Alex Merry. All rights reserved. -// -// -// This file is part of TikZiT. -// -// TikZiT is free software: you can redistribute it and/or modify -// it under the terms of the GNU General Public License as published by -// the Free Software Foundation, either version 3 of the License, or -// (at your option) any later version. -// -// TikZiT is distributed in the hope that it will be useful, -// but WITHOUT ANY WARRANTY; without even the implied warranty of -// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -// GNU General Public License for more details. -// -// You should have received a copy of the GNU General Public License -// along with TikZiT. If not, see <http://www.gnu.org/licenses/>. -// - -#import <Foundation/Foundation.h> -#import "StyleManager.h" - -@interface Preambles : NSObject { - NSMutableDictionary *preambleDict; - NSString *selectedPreambleName; - NSArray *styles; - NSArray *edges; - StyleManager *styleManager; -} - -@property (copy) NSString *selectedPreambleName; -@property (retain) NSString *currentPreamble; -@property (retain) StyleManager *styleManager; -@property (readonly) NSMutableDictionary *preambleDict; - -+ (Preambles*)preambles; -- (id)init; -- (void)setStyles:(NSArray*)sty; -- (void)setEdges:(NSArray*)edg; - -- (NSString*)preambleForName:(NSString*)name; -- (BOOL)setPreamble:(NSString*)content forName:(NSString*)name; - -- (NSString*)addPreamble; -- (NSString*)addPreambleWithNameBase:(NSString*)name; - -- (BOOL)renamePreambleFrom:(NSString*)old to:(NSString*)new; -- (BOOL)removePreamble:(NSString*)name; - -- (NSEnumerator*)customPreambleNameEnumerator; - -- (void)removeAllPreambles; - -- (BOOL)selectedPreambleIsDefault; - -- (NSString*)styleDefinitions; -- (NSString*)defaultPreamble; -- (NSString*)defaultPreambleName; -- (NSString*)currentPostamble; - -@end - -// vi:ft=objc:noet:ts=4:sts=4:sw=4 diff --git a/tikzit/src/common/Preambles.m b/tikzit/src/common/Preambles.m deleted file mode 100644 index d6d18e9..0000000 --- a/tikzit/src/common/Preambles.m +++ /dev/null @@ -1,267 +0,0 @@ -// -// Preambles.m -// TikZiT -// -// Copyright 2010 Aleks Kissinger. All rights reserved. -// -// -// This file is part of TikZiT. -// -// TikZiT is free software: you can redistribute it and/or modify -// it under the terms of the GNU General Public License as published by -// the Free Software Foundation, either version 3 of the License, or -// (at your option) any later version. -// -// TikZiT is distributed in the hope that it will be useful, -// but WITHOUT ANY WARRANTY; without even the implied warranty of -// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -// GNU General Public License for more details. -// -// You should have received a copy of the GNU General Public License -// along with TikZiT. If not, see <http://www.gnu.org/licenses/>. -// - -#import "Preambles.h" -#import "NodeStyle.h" -#import "EdgeStyle.h" - -static NSString *PREAMBLE_HEAD = -@"\\documentclass{article}\n" -@"\\usepackage[svgnames]{xcolor}\n" -@"\\usepackage{tikz}\n" -@"\\usetikzlibrary{decorations.markings}\n" -@"\\usetikzlibrary{shapes.geometric}\n" -@"\\pagestyle{empty}\n" -@"\n" -@"\\pgfdeclarelayer{edgelayer}\n" -@"\\pgfdeclarelayer{nodelayer}\n" -@"\\pgfsetlayers{edgelayer,nodelayer,main}\n" -@"\n" -@"\\tikzstyle{none}=[inner sep=0pt]\n"; - -static NSString *PREAMBLE_TAIL = -@"\n" -@"\\usepackage[graphics,tightpage,active]{preview}\n" -@"\\PreviewEnvironment{tikzpicture}\n" -@"\\newlength{\\imagewidth}\n" -@"\\newlength{\\imagescale}\n" -@"\n" -@"\\begin{document}\n"; - -static NSString *POSTAMBLE = -@"\n" -@"\\end{document}\n"; - -@implementation Preambles - -+ (Preambles*)preambles { - return [[[self alloc] init] autorelease]; -} - -- (id)init { - self = [super init]; - if (self) { - selectedPreambleName = @"default"; - preambleDict = [[NSMutableDictionary alloc] initWithCapacity:1]; - [preambleDict setObject:[self defaultPreamble] forKey:@"custom"]; - styles = nil; - edges = nil; - styleManager = nil; - } - return self; -} - -- (NSString*)preambleForName:(NSString*)name { - if ([name isEqualToString:@"default"]) - return [self defaultPreamble]; - else - return [preambleDict objectForKey:name]; -} - -- (BOOL)setPreamble:(NSString*)content forName:(NSString*)name { - if ([name isEqualToString:@"default"]) - return NO; - [preambleDict setObject:content forKey:name]; - return YES; -} - -- (void)removeAllPreambles { - [preambleDict removeAllObjects]; -} - -- (NSEnumerator*)customPreambleNameEnumerator { - return [preambleDict keyEnumerator]; -} - -- (void)setStyles:(NSArray*)sty { - [sty retain]; - [styles release]; - styles = sty; -} - -- (void)setEdges:(NSArray*)edg { - [edg retain]; - [edges release]; - edges = edg; -} - -- (NSString*)styleDefinitions { - if (styleManager != nil) { - [self setStyles:[styleManager nodeStyles]]; - } - NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init]; - NSMutableString *buf = [NSMutableString string]; - NSMutableString *colbuf = [NSMutableString string]; - NSMutableSet *colors = [NSMutableSet setWithCapacity:2*[styles count]]; - for (NodeStyle *st in styles) { - [buf appendFormat:@"%@\n", [st tikz]]; - ColorRGB *fill = [st fillColorRGB]; - ColorRGB *stroke = [st strokeColorRGB]; - if ([fill name] == nil && ![colors containsObject:fill]) { - [colors addObject:fill]; - [colbuf appendFormat:@"\\definecolor{%@}{rgb}{%.3f,%.3f,%.3f}\n", - [fill hexName], [fill redFloat], [fill greenFloat], [fill blueFloat]]; - } - - if ([stroke name] == nil && ![colors containsObject:stroke]) { - [colors addObject:stroke]; - [colbuf appendFormat:@"\\definecolor{%@}{rgb}{%.3f,%.3f,%.3f}\n", - [stroke hexName], [stroke redFloat], [stroke greenFloat], [stroke blueFloat]]; - } - } - - if (styleManager != nil) { - [self setEdges:[styleManager edgeStyles]]; - } - - [buf appendString:@"\n"]; - for (EdgeStyle *st in edges) { - [buf appendFormat:@"%@\n", [st tikz]]; - ColorRGB *color = [st colorRGB]; - if (color != nil && [color name] == nil && ![colors containsObject:color]) { - [colors addObject:color]; - [colbuf appendFormat:@"\\definecolor{%@}{rgb}{%.3f,%.3f,%.3f}\n", - [color hexName], [color redFloat], [color greenFloat], [color blueFloat]]; - } - } - - NSString *defs = [[NSString alloc] initWithFormat:@"%@\n%@", colbuf, buf]; - - [pool drain]; - return [defs autorelease]; -} - -- (NSString*)defaultPreamble { - return [NSString stringWithFormat:@"%@%@%@", - PREAMBLE_HEAD, [self styleDefinitions], PREAMBLE_TAIL]; -} - -- (BOOL)selectedPreambleIsDefault { - return [selectedPreambleName isEqualToString:@"default"]; -} - -- (NSString*)selectedPreambleName { return selectedPreambleName; } -- (void)setSelectedPreambleName:(NSString *)sel { - if (sel != selectedPreambleName) { - [selectedPreambleName release]; - selectedPreambleName = [sel copy]; - } -} - -- (NSString*)currentPreamble { - NSString *pre = [self preambleForName:selectedPreambleName]; - return (pre == nil) ? [self defaultPreamble] : pre; -} - -- (void)setCurrentPreamble:(NSString*)str { - if (![selectedPreambleName isEqualToString:@"default"]) - [preambleDict setObject:str forKey:selectedPreambleName]; -} - -- (StyleManager*)styleManager { - return styleManager; -} - -- (void)setStyleManager:(StyleManager *)manager { - [manager retain]; - [styleManager release]; - styleManager = manager; -} - -- (NSString*)currentPostamble { - return POSTAMBLE; -} - -- (NSMutableDictionary*)preambleDict { - return preambleDict; -} - -- (NSString*)defaultPreambleName { - return @"default"; -} - -- (NSString*)addPreamble { - return [self addPreambleWithNameBase:@"new preamble"]; -} - -- (NSString*)addPreambleWithNameBase:(NSString*)base { - if ([preambleDict objectForKey:base] == nil) { - [self setPreamble:[self defaultPreamble] forName:base]; - return base; - } - int i = 0; - NSString *tryName = nil; - do { - ++i; - tryName = [NSString stringWithFormat:@"%@ %d", base, i]; - } while ([preambleDict objectForKey:tryName] != nil); - - [self setPreamble:[self defaultPreamble] forName:tryName]; - return tryName; -} - -- (BOOL)renamePreambleFrom:(NSString*)old to:(NSString*)new { - if ([old isEqualToString:@"default"]) - return NO; - if ([new isEqualToString:@"default"]) - return NO; - if ([old isEqualToString:new]) - return YES; - BOOL isSelected = NO; - if ([old isEqualToString:selectedPreambleName]) { - [self setSelectedPreambleName:nil]; - isSelected = YES; - } - NSString *preamble = [preambleDict objectForKey:old]; - [preamble retain]; - [preambleDict removeObjectForKey:old]; - [preambleDict setObject:preamble forKey:new]; - [preamble release]; - if (isSelected) { - [self setSelectedPreambleName:new]; - } - return YES; -} - -- (BOOL)removePreamble:(NSString*)name { - if ([name isEqualToString:@"default"]) - return NO; - // "name" may be held only by being the selected preamble... - [name retain]; - if ([name isEqualToString:selectedPreambleName]) - [self setSelectedPreambleName:nil]; - [preambleDict removeObjectForKey:name]; - [name release]; - return YES; -} - -- (void)dealloc { - [selectedPreambleName release]; - [styles release]; - [styleManager release]; - [super dealloc]; -} - -@end - -// vi:ft=objc:ts=4:noet:sts=4:sw=4 diff --git a/tikzit/src/common/PropertyHolder.h b/tikzit/src/common/PropertyHolder.h deleted file mode 100644 index ba1d825..0000000 --- a/tikzit/src/common/PropertyHolder.h +++ /dev/null @@ -1,36 +0,0 @@ -// -// PropertyHolder.h -// TikZiT -// -// Copyright 2011 Aleks Kissinger. All rights reserved. -// -// -// This file is part of TikZiT. -// -// TikZiT is free software: you can redistribute it and/or modify -// it under the terms of the GNU General Public License as published by -// the Free Software Foundation, either version 3 of the License, or -// (at your option) any later version. -// -// TikZiT is distributed in the hope that it will be useful, -// but WITHOUT ANY WARRANTY; without even the implied warranty of -// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -// GNU General Public License for more details. -// -// You should have received a copy of the GNU General Public License -// along with TikZiT. If not, see <http://www.gnu.org/licenses/>. -// - -#import <Foundation/Foundation.h> - -@interface PropertyHolder : NSObject { - NSString *notificationName; -} - -- (id)initWithNotificationName:(NSString*)name; -- (void) postPropertyChanged:(NSString*)property oldValue:(id)value; -- (void) postPropertyChanged:(NSString*)property; - -@end - -// vi:ft=objc:noet:ts=4:sts=4:sw=4 diff --git a/tikzit/src/common/PropertyHolder.m b/tikzit/src/common/PropertyHolder.m deleted file mode 100644 index 2b3442f..0000000 --- a/tikzit/src/common/PropertyHolder.m +++ /dev/null @@ -1,72 +0,0 @@ -// -// PropertyHolder.m -// TikZiT -// -// Copyright 2011 Aleks Kissinger. All rights reserved. -// -// -// This file is part of TikZiT. -// -// TikZiT is free software: you can redistribute it and/or modify -// it under the terms of the GNU General Public License as published by -// the Free Software Foundation, either version 3 of the License, or -// (at your option) any later version. -// -// TikZiT is distributed in the hope that it will be useful, -// but WITHOUT ANY WARRANTY; without even the implied warranty of -// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -// GNU General Public License for more details. -// -// You should have received a copy of the GNU General Public License -// along with TikZiT. If not, see <http://www.gnu.org/licenses/>. -// - -#import "PropertyHolder.h" - -@implementation PropertyHolder - - -- (id)init { - self = [super init]; - if (self) { - notificationName = @"UnknownPropertyChanged"; - } - return self; -} - -- (id)initWithNotificationName:(NSString*)n { - self = [super init]; - if (self) { - notificationName = [n copy]; - } - return self; -} - -- (void)postPropertyChanged:(NSString*)property oldValue:(id)value { - NSDictionary *userInfo; - if (value != nil) { - userInfo = [NSDictionary dictionaryWithObjectsAndKeys: - property, @"propertyName", - value, @"oldValue", - nil]; - } else { - userInfo = [NSDictionary dictionaryWithObject:property - forKey:@"propertyName"]; - } - [[NSNotificationCenter defaultCenter] postNotificationName:notificationName - object:self - userInfo:userInfo]; -} - -- (void)postPropertyChanged:(NSString*)property { - [self postPropertyChanged:property oldValue:nil]; -} - -- (void)dealloc { - [notificationName release]; - [super dealloc]; -} - -@end - -// vi:ft=objc:ts=4:et:sts=4:sw=4 diff --git a/tikzit/src/common/RColor.h b/tikzit/src/common/RColor.h deleted file mode 100644 index 7f22547..0000000 --- a/tikzit/src/common/RColor.h +++ /dev/null @@ -1,50 +0,0 @@ -/* - * Copyright 2011 Alex Merry <alex.merry@kdemail.net> - * - * 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 the Free Software Foundation; either version 2 of - * the License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see <http://www.gnu.org/licenses/>. - */ - -#import <Foundation/Foundation.h> - -#ifndef CGFloat -#define CGFloat float -#endif - -/** - * A lightweight color structure used by RenderContext - * - * This is mainly to avoid the overhead of ColorRGB when - * rendering things not based on a NodeStyle - * - * All values range from 0.0f to 1.0f. - */ -typedef struct { - CGFloat red; - CGFloat green; - CGFloat blue; - CGFloat alpha; -} -RColor; - -/** Solid white */ -static const RColor WhiteRColor __attribute__((unused)) = {1.0, 1.0, 1.0, 1.0}; -/** Solid black */ -static const RColor BlackRColor __attribute__((unused)) = {0.0, 0.0, 0.0, 1.0}; - -/** Create a color with alpha set to 1.0 */ -RColor MakeSolidRColor (CGFloat red, CGFloat green, CGFloat blue); -/** Create a color */ -RColor MakeRColor (CGFloat red, CGFloat green, CGFloat blue, CGFloat alpha); - -// vi:ft=objc:noet:ts=4:sts=4:sw=4 diff --git a/tikzit/src/common/RColor.m b/tikzit/src/common/RColor.m deleted file mode 100644 index 49914fe..0000000 --- a/tikzit/src/common/RColor.m +++ /dev/null @@ -1,33 +0,0 @@ -/* - * Copyright 2011 Alex Merry <alex.merry@kdemail.net> - * - * 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 the Free Software Foundation; either version 2 of - * the License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see <http://www.gnu.org/licenses/>. - */ - -#import "RColor.h" - -RColor MakeSolidRColor (CGFloat red, CGFloat green, CGFloat blue) { - return MakeRColor (red, green, blue, 1.0); -} - -RColor MakeRColor (CGFloat red, CGFloat green, CGFloat blue, CGFloat alpha) { - RColor color; - color.red = red; - color.green = green; - color.blue = blue; - color.alpha = alpha; - return color; -} - -// vi:ft=objc:ts=4:noet:sts=4:sw=4 diff --git a/tikzit/src/common/RectangleShape.h b/tikzit/src/common/RectangleShape.h deleted file mode 100644 index 3fa0f31..0000000 --- a/tikzit/src/common/RectangleShape.h +++ /dev/null @@ -1,33 +0,0 @@ -// -// RectangleShape.h -// TikZiT -// -// Copyright 2011 Aleks Kissinger. All rights reserved. -// -// -// This file is part of TikZiT. -// -// TikZiT is free software: you can redistribute it and/or modify -// it under the terms of the GNU General Public License as published by -// the Free Software Foundation, either version 3 of the License, or -// (at your option) any later version. -// -// TikZiT is distributed in the hope that it will be useful, -// but WITHOUT ANY WARRANTY; without even the implied warranty of -// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -// GNU General Public License for more details. -// -// You should have received a copy of the GNU General Public License -// along with TikZiT. If not, see <http://www.gnu.org/licenses/>. -// - -#import <Foundation/Foundation.h> -#import "Shape.h" - - -@interface RectangleShape : Shape { -} - -@end - -// vi:ft=objc:noet:ts=4:sts=4:sw=4 diff --git a/tikzit/src/common/RectangleShape.m b/tikzit/src/common/RectangleShape.m deleted file mode 100644 index db9c803..0000000 --- a/tikzit/src/common/RectangleShape.m +++ /dev/null @@ -1,57 +0,0 @@ -// -// RectangleShape.m -// TikZiT -// -// Copyright 2011 Aleks Kissinger. All rights reserved. -// -// -// This file is part of TikZiT. -// -// TikZiT is free software: you can redistribute it and/or modify -// it under the terms of the GNU General Public License as published by -// the Free Software Foundation, either version 3 of the License, or -// (at your option) any later version. -// -// TikZiT is distributed in the hope that it will be useful, -// but WITHOUT ANY WARRANTY; without even the implied warranty of -// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -// GNU General Public License for more details. -// -// You should have received a copy of the GNU General Public License -// along with TikZiT. If not, see <http://www.gnu.org/licenses/>. -// - -#import "RectangleShape.h" -#import "Node.h" -#import "Edge.h" - -@implementation RectangleShape - -- (id)init { - self = [super init]; - if (self) { - Node *n0,*n1,*n2,*n3; - float sz = 0.2f; - - n0 = [Node nodeWithPoint:NSMakePoint(-sz, sz)]; - n1 = [Node nodeWithPoint:NSMakePoint( sz, sz)]; - n2 = [Node nodeWithPoint:NSMakePoint( sz,-sz)]; - n3 = [Node nodeWithPoint:NSMakePoint(-sz,-sz)]; - - Edge *e0,*e1,*e2,*e3; - - e0 = [Edge edgeWithSource:n0 andTarget:n1]; - e1 = [Edge edgeWithSource:n1 andTarget:n2]; - e2 = [Edge edgeWithSource:n2 andTarget:n3]; - e3 = [Edge edgeWithSource:n3 andTarget:n0]; - - paths = [[NSSet alloc] initWithObjects:[NSArray arrayWithObjects:e0,e1,e2,e3,nil],nil]; - - styleTikz = @"rectangle"; - } - return self; -} - -@end - -// vi:ft=objc:ts=4:noet:sts=4:sw=4 diff --git a/tikzit/src/common/RegularPolyShape.h b/tikzit/src/common/RegularPolyShape.h deleted file mode 100644 index 1fd8f1e..0000000 --- a/tikzit/src/common/RegularPolyShape.h +++ /dev/null @@ -1,50 +0,0 @@ -// -// RegularPolyShape.h -// TikZiT -// -// Copyright 2011 Aleks Kissinger. All rights reserved. -// -// -// This file is part of TikZiT. -// -// TikZiT is free software: you can redistribute it and/or modify -// it under the terms of the GNU General Public License as published by -// the Free Software Foundation, either version 3 of the License, or -// (at your option) any later version. -// -// TikZiT is distributed in the hope that it will be useful, -// but WITHOUT ANY WARRANTY; without even the implied warranty of -// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -// GNU General Public License for more details. -// -// You should have received a copy of the GNU General Public License -// along with TikZiT. If not, see <http://www.gnu.org/licenses/>. -// - -#import <Foundation/Foundation.h> -#import "Shape.h" - -/** - * A regular polygon - * - * Matches the "regular polygon" shape in the shapes.geometric - * PGF/TikZ library. - */ -@interface RegularPolyShape : Shape { -} - -/** - * Initialise a regular polygon - * - * A rotation of 0 will produce a polygon with one - * edge flat along the bottom (just like PGF/TikZ - * does it). - * - * @param sides the number of sides the polygon should have - * @param rotation the rotation of the polygon, in degrees - */ -- (id)initWithSides:(int)sides rotation:(int)rotation; - -@end - -// vi:ft=objc:noet:ts=4:sts=4:sw=4 diff --git a/tikzit/src/common/RegularPolyShape.m b/tikzit/src/common/RegularPolyShape.m deleted file mode 100644 index 3555115..0000000 --- a/tikzit/src/common/RegularPolyShape.m +++ /dev/null @@ -1,76 +0,0 @@ -// -// RegularPolyShape.m -// TikZiT -// -// Copyright 2011 Aleks Kissinger -// Copyright 2012 Alex Merry -// All rights reserved. -// -// This file is part of TikZiT. -// -// TikZiT is free software: you can redistribute it and/or modify -// it under the terms of the GNU General Public License as published by -// the Free Software Foundation, either version 3 of the License, or -// (at your option) any later version. -// -// TikZiT is distributed in the hope that it will be useful, -// but WITHOUT ANY WARRANTY; without even the implied warranty of -// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -// GNU General Public License for more details. -// -// You should have received a copy of the GNU General Public License -// along with TikZiT. If not, see <http://www.gnu.org/licenses/>. -// - -#import "RegularPolyShape.h" -#import "Node.h" -#import "Edge.h" -#import "util.h" - -@implementation RegularPolyShape - -- (id)initWithSides:(int)sides rotation:(int)rotation { - self = [super init]; - if (self == nil) - return nil; - - // TikZ draws regular polygons using a radius inscribed - // _inside_ the shape (touching middles of edges), not - // outside (touching points) - const float innerRadius = 0.2f; - - NSMutableArray *nodes = [NSMutableArray arrayWithCapacity:sides]; - NSMutableArray *edges = [NSMutableArray arrayWithCapacity:sides]; - - float dtheta = (M_PI * 2.0f) / ((float)sides); - float theta = (dtheta/2.0f) - (M_PI / 2.0f); - theta += degreesToRadians(rotation); - // radius of the outer circle - float radius = ABS(innerRadius / cos(dtheta)); - - for (int i = 0; i < sides; ++i) { - NSPoint p; - p.x = radius * cos(theta); - p.y = radius * sin(theta); - - [nodes addObject:[Node nodeWithPoint:p]]; - theta += dtheta; - } - - for (int i = 0; i < sides; ++i) { - [edges addObject:[Edge edgeWithSource:[nodes objectAtIndex:i] - andTarget:[nodes objectAtIndex:(i+1)%sides]]]; - } - - paths = [[NSSet alloc] initWithObjects:edges,nil]; - - styleTikz = [[NSString alloc] initWithFormat: - @"regular polygon,regular polygon sides=%d,shape border rotate=%d", - sides, rotation]; - - return self; -} - -@end - -// vi:ft=objc:ts=4:noet:sts=4:sw=4 diff --git a/tikzit/src/common/RenderContext.h b/tikzit/src/common/RenderContext.h deleted file mode 100644 index 8633944..0000000 --- a/tikzit/src/common/RenderContext.h +++ /dev/null @@ -1,156 +0,0 @@ -/* - * Copyright 2011 Alex Merry <alex.merry@kdemail.net> - * - * 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 the Free Software Foundation; either version 2 of - * the License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see <http://www.gnu.org/licenses/>. - */ - -#import <Foundation/Foundation.h> -#import "RColor.h" - -typedef enum { - AntialiasDisabled, - AntialiasDefault -} AntialiasMode; - -// encapsulates a CTLine on OSX and -// a PangoLayout in GTK+ -@protocol TextLayout -@property (readonly) NSSize size; -@property (readonly) NSString *text; -- (void) showTextAt:(NSPoint)topLeft withColor:(RColor)color; -@end - -@protocol RenderContext -- (void) saveState; -- (void) restoreState; - -- (NSRect) clipBoundingBox; -- (BOOL) strokeIncludesPoint:(NSPoint)p; -- (BOOL) fillIncludesPoint:(NSPoint)p; -- (id<TextLayout>) layoutText:(NSString*)text withSize:(CGFloat)fontSize; - -// this may not affect text rendering -- (void) setAntialiasMode:(AntialiasMode)mode; -- (void) setLineWidth:(CGFloat)width; -// setting to 0 will unset the dash -- (void) setLineDash:(CGFloat)dashLength; - -/** - * Clear the current path, including all subpaths - */ -- (void) startPath; -/** - * Close the current subpath - */ -- (void) closeSubPath; -/** - * Start a new subpath, and set the current point. - * - * The point will be the current point and the starting point - * for the subpath. - */ -- (void) moveTo:(NSPoint)p; -/** - * Add a cubic bezier curve to the current subpath. - * - * The curve will start at the current point, terminate at end and - * be defined by cp1 and cp2. - */ -- (void) curveTo:(NSPoint)end withCp1:(NSPoint)cp1 andCp2:(NSPoint)cp2; -/** - * Add a straight line to the current subpath. - * - * The line will start at the current point, and terminate at end. - */ -- (void) lineTo:(NSPoint)end; -/** - * Add a new rectangular subpath. - * - * The current point is undefined after this call. - */ -- (void) rect:(NSRect)rect; -/** - * Add a new circular subpath. - * - * The current point is undefined after this call. - */ -- (void) circleAt:(NSPoint)c withRadius:(CGFloat)r; - -/** - * Paint along the current path. - * - * The current line width and dash style will be used, - * and the colour is given by color. - * - * The path will be cleared by this call, as though - * startPath had been called. - */ -- (void) strokePathWithColor:(RColor)color; -/** - * Paint inside the current path. - * - * The fill colour is given by color. - * - * The path will be cleared by this call, as though - * startPath had been called. - */ -- (void) fillPathWithColor:(RColor)color; -/** - * Paint along and inside the current path. - * - * The current line width and dash style will be used, - * and the colour is given by color. - * - * The path will be cleared by this call, as though - * startPath had been called. - * - * Note that the fill and stroke may overlap, although - * the stroke is always painted on top, so this is only - * relevant when the stroke colour has an alpha channel - * other than 1.0f. - */ -- (void) strokePathWithColor:(RColor)scolor - andFillWithColor:(RColor)fcolor; -/** - * Paint along and inside the current path using an alpha channel. - * - * The current line width and dash style will be used, - * and the colour is given by color. - * - * The path will be cleared by this call, as though - * startPath had been called. - * - * Note that the fill and stroke may overlap, although - * the stroke is always painted on top, so this is only - * relevant when the stroke colour has an alpha channel - * other than 1.0f. - */ -- (void) strokePathWithColor:(RColor)scolor - andFillWithColor:(RColor)fcolor - usingAlpha:(CGFloat)alpha; -/** - * Set the clip to the current path. - * - * The path will be cleared by this call, as though - * startPath had been called. - */ -- (void) clipToPath; - -/** - * Paint everywhere within the clip. - */ -- (void) paintWithColor:(RColor)color; -@end - -// vi:ft=objc:noet:ts=4:sts=4:sw=4 diff --git a/tikzit/src/common/Shape.h b/tikzit/src/common/Shape.h deleted file mode 100644 index b401a87..0000000 --- a/tikzit/src/common/Shape.h +++ /dev/null @@ -1,49 +0,0 @@ -// -// Shape.h -// TikZiT -// -// Copyright 2011 Aleks Kissinger. All rights reserved. -// -// -// This file is part of TikZiT. -// -// TikZiT is free software: you can redistribute it and/or modify -// it under the terms of the GNU General Public License as published by -// the Free Software Foundation, either version 3 of the License, or -// (at your option) any later version. -// -// TikZiT is distributed in the hope that it will be useful, -// but WITHOUT ANY WARRANTY; without even the implied warranty of -// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -// GNU General Public License for more details. -// -// You should have received a copy of the GNU General Public License -// along with TikZiT. If not, see <http://www.gnu.org/licenses/>. -// - -#import <Foundation/Foundation.h> -#import "Transformer.h" - -@interface Shape : NSObject <NSCopying> { - NSSet *paths; - NSRect boundingRect; // cache - NSString *styleTikz; -} - -@property (retain) NSSet *paths; -@property (readonly) NSRect boundingRect; -/** - * The tikz code to use in style properties for this shape - * - * This can return nil, in which case the shape name should be used - */ -@property (retain) NSString *styleTikz; - -- (id)init; -+ (void)refreshShapeDictionary; -+ (NSDictionary*)shapeDictionary; -+ (Shape*)shapeForName:(NSString*)shapeName; - -@end - -// vi:ft=objc:noet:ts=4:sts=4:sw=4 diff --git a/tikzit/src/common/Shape.m b/tikzit/src/common/Shape.m deleted file mode 100644 index e86b122..0000000 --- a/tikzit/src/common/Shape.m +++ /dev/null @@ -1,151 +0,0 @@ -// -// Shape.m -// TikZiT -// -// Copyright 2011 Aleks Kissinger. All rights reserved. -// -// -// This file is part of TikZiT. -// -// TikZiT is free software: you can redistribute it and/or modify -// it under the terms of the GNU General Public License as published by -// the Free Software Foundation, either version 3 of the License, or -// (at your option) any later version. -// -// TikZiT is distributed in the hope that it will be useful, -// but WITHOUT ANY WARRANTY; without even the implied warranty of -// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -// GNU General Public License for more details. -// -// You should have received a copy of the GNU General Public License -// along with TikZiT. If not, see <http://www.gnu.org/licenses/>. -// - -#import "Shape.h" - -#import "Edge.h" -#import "SupportDir.h" -#import "ShapeNames.h" - -#import "CircleShape.h" -#import "DiamondShape.h" -#import "RectangleShape.h" -#import "RegularPolyShape.h" -#import "TikzShape.h" - -#import "util.h" - -@implementation Shape - -- (void)calcBoundingRect { - boundingRect = NSZeroRect; - - if (paths == nil) - return; - - for (NSArray *arr in paths) { - for (Edge *e in arr) { - boundingRect = NSUnionRect(boundingRect, [e boundingRect]); - } - } -} - -- (id)init { - self = [super init]; - if (self) { - paths = nil; - } - return self; -} - -- (NSSet*)paths {return paths;} -- (void)setPaths:(NSSet *)p { - if (paths != p) { - [paths release]; - paths = [p retain]; - [self calcBoundingRect]; - } -} - -- (NSRect)boundingRect { return boundingRect; } - -@synthesize styleTikz; - -- (id)copyWithZone:(NSZone*)zone { - Shape *cp = [[[self class] allocWithZone:zone] init]; - [cp setPaths:paths]; - [cp setStyleTikz:styleTikz]; - return cp; -} - -- (void)dealloc { - [paths release]; - [styleTikz release]; - [super dealloc]; -} - -NSDictionary *shapeDictionary = nil; - -+ (void)addShapesInDir:(NSString*)shapeDir to:(NSMutableDictionary*)shapeDict { - NSFileManager *fileManager = [NSFileManager defaultManager]; - NSArray *files = [fileManager directoryContentsAtPath:shapeDir]; - - if (files != nil) { - NSString *nm; - for (NSString *f in files) { - if ([f hasSuffix:@".tikz"]) { - nm = [f substringToIndex:[f length]-5]; - TikzShape *sh = - [[TikzShape alloc] initWithTikzFile: - [shapeDir stringByAppendingPathComponent:f]]; - if (sh != nil) { - [shapeDict setObject:sh forKey:nm]; - [sh release]; - } - } - } - } -} - -+ (void)refreshShapeDictionary { - Shape *shapes[5] = { - [[CircleShape alloc] init], - [[RectangleShape alloc] init], - [[DiamondShape alloc] init], - [[RegularPolyShape alloc] initWithSides:3 rotation:0], - [[RegularPolyShape alloc] initWithSides:3 rotation:180]}; - NSMutableDictionary *shapeDict = [[NSMutableDictionary alloc] initWithObjectsAndKeys: - shapes[0], SHAPE_CIRCLE, - shapes[1], SHAPE_RECTANGLE, - shapes[2], SHAPE_DIAMOND, - shapes[3], SHAPE_UP_TRIANGLE, - shapes[4], SHAPE_DOWN_TRIANGLE, - nil]; - for (int i = 0; i<5; ++i) [shapes[i] release]; - - NSString *systemShapeDir = [[SupportDir systemSupportDir] stringByAppendingPathComponent:@"shapes"]; - NSString *userShapeDir = [[SupportDir userSupportDir] stringByAppendingPathComponent:@"shapes"]; - - [Shape addShapesInDir:systemShapeDir to:shapeDict]; - [Shape addShapesInDir:userShapeDir to:shapeDict]; - - shapeDictionary = shapeDict; - - [[NSNotificationCenter defaultCenter] - postNotificationName:@"ShapeDictionaryReplaced" - object:self]; -} - -+ (NSDictionary*)shapeDictionary { - if (shapeDictionary == nil) [Shape refreshShapeDictionary]; - return shapeDictionary; -} - -+ (Shape*)shapeForName:(NSString*)shapeName { - Shape *s = [[[Shape shapeDictionary] objectForKey:shapeName] copy]; - return [s autorelease]; -} - -@end - -// vi:ft=objc:ts=4:noet:sts=4:sw=4 diff --git a/tikzit/src/common/ShapeNames.h b/tikzit/src/common/ShapeNames.h deleted file mode 100644 index 66ecfb1..0000000 --- a/tikzit/src/common/ShapeNames.h +++ /dev/null @@ -1,27 +0,0 @@ -// -// ShapeNames.h -// TikZiT -// -// Copyright 2011 Aleks Kissinger. All rights reserved. -// -// -// This file is part of TikZiT. -// -// TikZiT is free software: you can redistribute it and/or modify -// it under the terms of the GNU General Public License as published by -// the Free Software Foundation, either version 3 of the License, or -// (at your option) any later version. -// -// TikZiT is distributed in the hope that it will be useful, -// but WITHOUT ANY WARRANTY; without even the implied warranty of -// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -// GNU General Public License for more details. -// - -#define SHAPE_CIRCLE @"circle" -#define SHAPE_RECTANGLE @"rectangle" -#define SHAPE_UP_TRIANGLE @"up triangle" -#define SHAPE_DOWN_TRIANGLE @"down triangle" -#define SHAPE_DIAMOND @"diamond" - -// vi:ft=objc:noet:ts=4:sts=4:sw=4 diff --git a/tikzit/src/common/StyleManager.h b/tikzit/src/common/StyleManager.h deleted file mode 100644 index bc920e7..0000000 --- a/tikzit/src/common/StyleManager.h +++ /dev/null @@ -1,49 +0,0 @@ -/* - * Copyright 2011 Alex Merry <dev@randomguy3.me.uk> - * - * 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 the Free Software Foundation; either version 2 of - * the License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see <http://www.gnu.org/licenses/>. - */ - -#import <Foundation/Foundation.h> -#import "NodeStyle.h" -#import "EdgeStyle.h" - -@interface StyleManager: NSObject <NSCopying> { - NSMutableArray *nodeStyles; - NSMutableArray *edgeStyles; -} - -+ (StyleManager*) manager; -- (id) init; - -@property (readonly) NSArray *nodeStyles; -@property (readonly) NSArray *edgeStyles; - -// only for use by loading code -- (void) _setNodeStyles:(NSMutableArray*)styles; -- (void) _setEdgeStyles:(NSMutableArray*)styles; - -- (NodeStyle*) nodeStyleForName:(NSString*)name; -- (EdgeStyle*) edgeStyleForName:(NSString*)name; - -- (void) addNodeStyle:(NodeStyle*)style; -- (void) removeNodeStyle:(NodeStyle*)style; -- (void) addEdgeStyle:(EdgeStyle*)style; -- (void) removeEdgeStyle:(EdgeStyle*)style; - -- (void) updateFromManager:(StyleManager*)manager; - -@end - -// vi:ft=objc:noet:ts=4:sts=4:sw=4 diff --git a/tikzit/src/common/StyleManager.m b/tikzit/src/common/StyleManager.m deleted file mode 100644 index ae0d488..0000000 --- a/tikzit/src/common/StyleManager.m +++ /dev/null @@ -1,341 +0,0 @@ -/* - * Copyright 2011 Alex Merry <dev@randomguy3.me.uk> - * - * 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 the Free Software Foundation; either version 2 of - * the License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see <http://www.gnu.org/licenses/>. - */ - -#import "StyleManager.h" - -@implementation StyleManager - -- (void) nodeStylePropertyChanged:(NSNotification*)n { - if ([[[n userInfo] objectForKey:@"propertyName"] isEqual:@"name"]) { - NSDictionary *userInfo; - userInfo = [NSDictionary dictionaryWithObjectsAndKeys: - [n object], @"style", - [[n userInfo] objectForKey:@"oldValue"], @"oldName", - nil]; - [[NSNotificationCenter defaultCenter] postNotificationName:@"NodeStyleRenamed" - object:self - userInfo:userInfo]; - } -} - -- (void) ignoreAllNodeStyles { - [[NSNotificationCenter defaultCenter] - removeObserver:self - name:@"NodeStylePropertyChanged" - object:nil]; -} - -- (void) ignoreNodeStyle:(NodeStyle*)style { - [[NSNotificationCenter defaultCenter] - removeObserver:self - name:@"NodeStylePropertyChanged" - object:style]; -} - -- (void) listenToNodeStyle:(NodeStyle*)style { - [[NSNotificationCenter defaultCenter] - addObserver:self - selector:@selector(nodeStylePropertyChanged:) - name:@"NodeStylePropertyChanged" - object:style]; -} - -- (void) edgeStylePropertyChanged:(NSNotification*)n { - if ([[[n userInfo] objectForKey:@"propertyName"] isEqual:@"name"]) { - NSDictionary *userInfo; - userInfo = [NSDictionary dictionaryWithObjectsAndKeys: - [n object], @"style", - [[n userInfo] objectForKey:@"oldValue"], @"oldName", - nil]; - [[NSNotificationCenter defaultCenter] postNotificationName:@"EdgeStyleRenamed" - object:self - userInfo:userInfo]; - } -} - -- (void) ignoreAllEdgeStyles { - [[NSNotificationCenter defaultCenter] - removeObserver:self - name:@"EdgeStylePropertyChanged" - object:nil]; -} - -- (void) ignoreEdgeStyle:(EdgeStyle*)style { - [[NSNotificationCenter defaultCenter] - removeObserver:self - name:@"EdgeStylePropertyChanged" - object:style]; -} - -- (void) listenToEdgeStyle:(EdgeStyle*)style { - [[NSNotificationCenter defaultCenter] - addObserver:self - selector:@selector(edgeStylePropertyChanged:) - name:@"EdgeStylePropertyChanged" - object:style]; -} - -+ (StyleManager*) manager { - return [[[self alloc] init] autorelease]; -} - -- (id) init { - self = [super init]; - - if (self) { - // we lazily load the default styles, since they may not be needed - nodeStyles = nil; - edgeStyles = nil; - } - - return self; -} - -- (void) dealloc { - [[NSNotificationCenter defaultCenter] removeObserver:self]; - - [nodeStyles release]; - [edgeStyles release]; - - [super dealloc]; -} - -- (void) loadDefaultEdgeStyles { - [edgeStyles release]; - edgeStyles = [[NSMutableArray alloc] initWithCapacity:3]; - - EdgeStyle *simple = [EdgeStyle defaultEdgeStyleWithName:@"simple"]; - [simple setThickness:2.0f]; - [self listenToEdgeStyle:simple]; - - EdgeStyle *arrow = [EdgeStyle defaultEdgeStyleWithName:@"arrow"]; - [arrow setThickness:2.0f]; - [arrow setDecorationStyle:ED_Arrow]; - [self listenToEdgeStyle:arrow]; - - EdgeStyle *tick = [EdgeStyle defaultEdgeStyleWithName:@"tick"]; - [tick setThickness:2.0f]; - [tick setDecorationStyle:ED_Tick]; - [self listenToEdgeStyle:tick]; - - [edgeStyles addObject:simple]; - [edgeStyles addObject:arrow]; - [edgeStyles addObject:tick]; -} - -- (void) loadDefaultNodeStyles { - [nodeStyles release]; - nodeStyles = [[NSMutableArray alloc] initWithCapacity:3]; - - NodeStyle *rn = [NodeStyle defaultNodeStyleWithName:@"rn"]; - [rn setStrokeThickness:2]; - [rn setStrokeColorRGB:[ColorRGB colorWithFloatRed:0 green:0 blue:0]]; - [rn setFillColorRGB:[ColorRGB colorWithFloatRed:1 green:0 blue:0]]; - [self listenToNodeStyle:rn]; - - NodeStyle *gn = [NodeStyle defaultNodeStyleWithName:@"gn"]; - [gn setStrokeThickness:2]; - [gn setStrokeColorRGB:[ColorRGB colorWithFloatRed:0 green:0 blue:0]]; - [gn setFillColorRGB:[ColorRGB colorWithFloatRed:0 green:1 blue:0]]; - [self listenToNodeStyle:gn]; - - NodeStyle *yn = [NodeStyle defaultNodeStyleWithName:@"yn"]; - [yn setStrokeThickness:2]; - [yn setStrokeColorRGB:[ColorRGB colorWithFloatRed:0 green:0 blue:0]]; - [yn setFillColorRGB:[ColorRGB colorWithFloatRed:1 green:1 blue:0]]; - [self listenToNodeStyle:yn]; - - [nodeStyles addObject:rn]; - [nodeStyles addObject:gn]; - [nodeStyles addObject:yn]; -} - -- (void) postNodeStyleAdded:(NodeStyle*)style { - [[NSNotificationCenter defaultCenter] postNotificationName:@"NodeStyleAdded" - object:self - userInfo:[NSDictionary dictionaryWithObject:style forKey:@"style"]]; -} - -- (void) postNodeStyleRemoved:(NodeStyle*)style { - [[NSNotificationCenter defaultCenter] postNotificationName:@"NodeStyleRemoved" - object:self - userInfo:[NSDictionary dictionaryWithObject:style forKey:@"style"]]; -} - -- (void) postEdgeStyleAdded:(EdgeStyle*)style { - [[NSNotificationCenter defaultCenter] postNotificationName:@"EdgeStyleAdded" - object:self - userInfo:[NSDictionary dictionaryWithObject:style forKey:@"style"]]; -} - -- (void) postEdgeStyleRemoved:(EdgeStyle*)style { - [[NSNotificationCenter defaultCenter] postNotificationName:@"EdgeStyleRemoved" - object:self - userInfo:[NSDictionary dictionaryWithObject:style forKey:@"style"]]; -} - -- (void) postNodeStylesReplaced { - [[NSNotificationCenter defaultCenter] postNotificationName:@"NodeStylesReplaced" object:self]; -} - -- (void) postEdgeStylesReplaced { - [[NSNotificationCenter defaultCenter] postNotificationName:@"EdgeStylesReplaced" object:self]; -} - -- (NSArray*) nodeStyles { - if (nodeStyles == nil) { - [self loadDefaultNodeStyles]; - } - return nodeStyles; -} - -- (NSArray*) edgeStyles { - if (edgeStyles == nil) { - [self loadDefaultEdgeStyles]; - } - return edgeStyles; -} - -- (void) _setNodeStyles:(NSMutableArray*)styles { - [self ignoreAllNodeStyles]; - [nodeStyles release]; - [styles retain]; - nodeStyles = styles; - for (NodeStyle *style in styles) { - [self listenToNodeStyle:style]; - } - [self postNodeStylesReplaced]; -} - -- (void) _setEdgeStyles:(NSMutableArray*)styles { - [self ignoreAllEdgeStyles]; - [edgeStyles release]; - [styles retain]; - edgeStyles = styles; - for (EdgeStyle *style in styles) { - [self listenToEdgeStyle:style]; - } - [self postEdgeStylesReplaced]; -} - -- (NodeStyle*) nodeStyleForName:(NSString*)name { - for (NodeStyle *s in nodeStyles) { - if ([[s name] isEqualToString:name]) { - return s; - } - } - - return nil; -} - -- (void) addNodeStyle:(NodeStyle*)style { - if (nodeStyles == nil) { - [self loadDefaultNodeStyles]; - } - [nodeStyles addObject:style]; - [self listenToNodeStyle:style]; - [self postNodeStyleAdded:style]; -} - -- (void) removeNodeStyle:(NodeStyle*)style { - if (nodeStyles == nil) { - [self loadDefaultNodeStyles]; - } - - [self ignoreNodeStyle:style]; - [style retain]; - [nodeStyles removeObject:style]; - [self postNodeStyleRemoved:style]; - [style release]; -} - -- (EdgeStyle*) edgeStyleForName:(NSString*)name { - for (EdgeStyle *s in edgeStyles) { - if ([[s name] isEqualToString:name]) { - return s; - } - } - - return nil; -} - -- (void) addEdgeStyle:(EdgeStyle*)style { - if (edgeStyles == nil) { - [self loadDefaultEdgeStyles]; - } - [edgeStyles addObject:style]; - [self listenToEdgeStyle:style]; - [self postEdgeStyleAdded:style]; -} - -- (void) removeEdgeStyle:(EdgeStyle*)style { - if (edgeStyles == nil) { - [self loadDefaultEdgeStyles]; - } - - [self ignoreEdgeStyle:style]; - [style retain]; - [edgeStyles removeObject:style]; - [self postEdgeStyleRemoved:style]; - [style release]; -} - -- (void) updateFromManager:(StyleManager*)m { - NSMutableArray *ns = [NSMutableArray arrayWithCapacity:[[m nodeStyles] count]]; - for (NodeStyle *style in [m nodeStyles]) { - NodeStyle *currentStyle = [self nodeStyleForName:[style name]]; - if (currentStyle != nil) { - [currentStyle updateFromStyle:style]; - [ns addObject:currentStyle]; - } else { - [ns addObject:[[style copy] autorelease]]; - } - } - NSMutableArray *es = [NSMutableArray arrayWithCapacity:[[m edgeStyles] count]]; - for (EdgeStyle *style in [m edgeStyles]) { - EdgeStyle *currentStyle = [self edgeStyleForName:[style name]]; - if (currentStyle != nil) { - [currentStyle updateFromStyle:style]; - [es addObject:currentStyle]; - } else { - [es addObject:[[style copy] autorelease]]; - } - } - [self _setNodeStyles:ns]; - [self _setEdgeStyles:es]; -} - -- (id) copyWithZone:(NSZone*)zone { - StyleManager *m = [[StyleManager allocWithZone:zone] init]; - - NSMutableArray *ns = [NSMutableArray arrayWithCapacity:[nodeStyles count]]; - for (NodeStyle *style in nodeStyles) { - [ns addObject:[[style copyWithZone:zone] autorelease]]; - } - NSMutableArray *es = [NSMutableArray arrayWithCapacity:[edgeStyles count]]; - for (EdgeStyle *style in edgeStyles) { - [es addObject:[[style copyWithZone:zone] autorelease]]; - } - [m _setNodeStyles:ns]; - [m _setEdgeStyles:es]; - - return m; -} - -@end - -// vi:ft=objc:ts=4:noet:sts=4:sw=4 diff --git a/tikzit/src/common/SupportDir.h b/tikzit/src/common/SupportDir.h deleted file mode 100644 index 30ccbcb..0000000 --- a/tikzit/src/common/SupportDir.h +++ /dev/null @@ -1,36 +0,0 @@ -// -// SupportDir.h -// TikZiT -// -// Copyright 2011 Aleks Kissinger. All rights reserved. -// -// -// This file is part of TikZiT. -// -// TikZiT is free software: you can redistribute it and/or modify -// it under the terms of the GNU General Public License as published by -// the Free Software Foundation, either version 3 of the License, or -// (at your option) any later version. -// -// TikZiT is distributed in the hope that it will be useful, -// but WITHOUT ANY WARRANTY; without even the implied warranty of -// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -// GNU General Public License for more details. -// -// You should have received a copy of the GNU General Public License -// along with TikZiT. If not, see <http://www.gnu.org/licenses/>. -// - -#import <Foundation/Foundation.h> - - -@interface SupportDir : NSObject { -} - -+ (void)createUserSupportDir; -+ (NSString*)userSupportDir; -+ (NSString*)systemSupportDir; - -@end - -// vi:ft=objc:noet:ts=4:sts=4:sw=4 diff --git a/tikzit/src/common/SupportDir.m b/tikzit/src/common/SupportDir.m deleted file mode 100644 index 22fed1b..0000000 --- a/tikzit/src/common/SupportDir.m +++ /dev/null @@ -1,65 +0,0 @@ -// -// SupportDir.m -// TikZiT -// -// Copyright 2011 Aleks Kissinger. All rights reserved. -// -// -// This file is part of TikZiT. -// -// TikZiT is free software: you can redistribute it and/or modify -// it under the terms of the GNU General Public License as published by -// the Free Software Foundation, either version 3 of the License, or -// (at your option) any later version. -// -// TikZiT is distributed in the hope that it will be useful, -// but WITHOUT ANY WARRANTY; without even the implied warranty of -// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -// GNU General Public License for more details. -// -// You should have received a copy of the GNU General Public License -// along with TikZiT. If not, see <http://www.gnu.org/licenses/>. -// - -#import "SupportDir.h" - -#ifndef __APPLE__ -#import <glib.h> -#import "stat.h" -#endif - -@implementation SupportDir - -+ (NSString*)userSupportDir { -#ifdef __APPLE__ - return [[NSSearchPathForDirectoriesInDomains(NSApplicationSupportDirectory,NSUserDomainMask,YES) - objectAtIndex:0] stringByAppendingPathComponent:@"TikZiT"]; -#else - return [NSString stringWithFormat:@"%s/tikzit", g_get_user_config_dir ()]; -#endif -} - -+ (NSString*)systemSupportDir { -#ifdef __APPLE__ - return [[NSBundle mainBundle] resourcePath]; -#else - return @TIKZITSHAREDIR; -#endif -} - -+ (void)createUserSupportDir { -#ifdef __APPLE__ - NSFileManager *fileManager = [NSFileManager defaultManager]; - [fileManager createDirectoryAtPath:[SupportDir userSupportDir] - withIntermediateDirectories:YES - attributes:nil - error:NULL]; -#else - // NSFileManager is slightly dodgy on Windows - g_mkdir_with_parents ([[SupportDir userSupportDir] UTF8String], S_IRUSR | S_IWUSR | S_IXUSR); -#endif -} - -@end - -// vi:ft=objc:ts=4:noet:sts=4:sw=4 diff --git a/tikzit/src/common/TikzGraphAssembler+Parser.h b/tikzit/src/common/TikzGraphAssembler+Parser.h deleted file mode 100644 index 55fa901..0000000 --- a/tikzit/src/common/TikzGraphAssembler+Parser.h +++ /dev/null @@ -1,39 +0,0 @@ -/* - * Copyright 2013 Alex Merry <dev@randomguy3.me.uk> - * - * 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 the Free Software Foundation; either version 2 of - * the License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see <http://www.gnu.org/licenses/>. - */ - -/** - * TikzGraphAssember+Parser.h - * - * This file exposes some TikzGraphAssembler functions - * that are only of use to the parser. - */ - -#import "TikzGraphAssembler.h" - -@interface TikzGraphAssembler (Parser) -- (Graph*) graph; -/** Store a node so that it can be looked up by name later */ -- (void) addNodeToMap:(Node*)n; -/** Get a previously-stored node by name */ -- (Node*) nodeWithName:(NSString*)name; -- (void) reportError:(const char *)message atLocation:(YYLTYPE*)yylloc; -- (void*) scanner; -@end - -#define YY_EXTRA_TYPE TikzGraphAssembler * - -// vi:ft=objc:noet:ts=4:sts=4:sw=4 diff --git a/tikzit/src/common/TikzGraphAssembler.h b/tikzit/src/common/TikzGraphAssembler.h deleted file mode 100644 index 3403969..0000000 --- a/tikzit/src/common/TikzGraphAssembler.h +++ /dev/null @@ -1,115 +0,0 @@ -// -// TikzGraphAssembler.h -// TikZiT -// -// Copyright 2010 Aleks Kissinger. All rights reserved. -// -// -// This file is part of TikZiT. -// -// TikZiT is free software: you can redistribute it and/or modify -// it under the terms of the GNU General Public License as published by -// the Free Software Foundation, either version 3 of the License, or -// (at your option) any later version. -// -// TikZiT is distributed in the hope that it will be useful, -// but WITHOUT ANY WARRANTY; without even the implied warranty of -// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -// GNU General Public License for more details. -// -// You should have received a copy of the GNU General Public License -// along with TikZiT. If not, see <http://www.gnu.org/licenses/>. -// - -#import <Foundation/Foundation.h> -#import "Graph.h" - -/** - * Parses (a subset of) tikz code and produces the corresponding Graph - * - * A note on errors: - * If parsing fails and a non-NULL error argument is given, it will be - * populated with an error with domain TZErrorDomain and code TZ_ERR_PARSE - * (see NSError+Tikzit.h). - * - * This will have a description set, typically something like - * "syntax error, unexpected [, expecting (" - * It may also have the following keys (it will have all or none of these), - * where numbers are stored using NSNumber: - * - startLine: the line (starting at 1) containing the first character - * of the bad token - * - startColumn: the column (starting at 1; tabs count for 1) of the first - * character of the bad token - * - endLine: the line (starting at 1) containing the last character - * of the bad token - * - endColumn: the column (starting at 1; tabs count for 1) of the last - * character of the bad token - * - syntaxString: an excerpt of the input string (typically the contents - * from startLine to endLine) providing some context - * - tokenOffset: the character offset (starting at 0) of the bad token - * within syntaxString - * - tokenLength: the character length (including newlines) of the bad token - * within syntaxString - */ -@interface TikzGraphAssembler : NSObject { - const char *tikzStr; - Graph *graph; - void *scanner; - NSMutableDictionary *nodeMap; - NSError *lastError; -} - -/** - * Parse tikz and place the result in gr - * - * Note that the graph must be empty; this might be used from an init - * method, for example, although don't forget that you can return a - * different object in init methods, providing you get the allocation - * right. - * - * @param tikz the tikz string to parse - * @param gr the graph to store the result in (must be empty, non-nil) - * @param e a location to store an error if parsing fails (may be NULL) - * @return YES if parsing succeeded, NO otherwise - */ -+ (BOOL) parseTikz:(NSString*)tikz forGraph:(Graph*)gr error:(NSError**)e; -/** - * Overload for -[parseTikz:forGraph:error:] with the error set to NULL - */ -+ (BOOL) parseTikz:(NSString*)tikz forGraph:(Graph*)gr; -/** - * Parse tikz - * - * @param tikz the tikz string to parse - * @param e a location to store an error if parsing fails (may be NULL) - * @return a Graph object if parsing succeeded, nil otherwise - */ -+ (Graph*) parseTikz:(NSString*)tikz error:(NSError**)e; -/** - * Overload for -[parseTikz:error:] with the error set to NULL - */ -+ (Graph*) parseTikz:(NSString*)tikz; -/** - * Validate a property string or value - * - * Wraps the string in "{" and "}" and checks it lexes completely; in other - * words, makes sure that "{" and "}" are balanced (ignoring escaped versions). - * @param tikz the string to validate - * @return YES if the string can be used as a property name or value, NO - * otherwise - */ -+ (BOOL)validateTikzPropertyNameOrValue:(NSString*)tikz; - -/** - * Validate an edge anchor - * - * Checks that the given string will successfully lex if used as an anchor for - * and edge - * @param tikz the string to validate - * @return YES if the string can be used as an edge anchor, NO otherwise - */ -+ (BOOL)validateTikzEdgeAnchor:(NSString*)tikz; - -@end - -// vi:ft=objc:noet:ts=4:sts=4:sw=4 diff --git a/tikzit/src/common/TikzGraphAssembler.m b/tikzit/src/common/TikzGraphAssembler.m deleted file mode 100644 index 2dd8d50..0000000 --- a/tikzit/src/common/TikzGraphAssembler.m +++ /dev/null @@ -1,284 +0,0 @@ -// -// TikzGraphAssembler.m -// TikZiT -// -// Copyright 2010 Aleks Kissinger. All rights reserved. -// -// -// This file is part of TikZiT. -// -// TikZiT is free software: you can redistribute it and/or modify -// it under the terms of the GNU General Public License as published by -// the Free Software Foundation, either version 3 of the License, or -// (at your option) any later version. -// -// TikZiT is distributed in the hope that it will be useful, -// but WITHOUT ANY WARRANTY; without even the implied warranty of -// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -// GNU General Public License for more details. -// -// You should have received a copy of the GNU General Public License -// along with TikZiT. If not, see <http://www.gnu.org/licenses/>. -// - -#import "TikzGraphAssembler.h" -#import "tikzparser.h" -#import "TikzGraphAssembler+Parser.h" -#import "tikzlexer.h" -#import "NSError+Tikzit.h" - -@implementation TikzGraphAssembler - -- (id)init { - [self release]; - return nil; -} - -- (id)initWithGraph:(Graph*)g { - self = [super init]; - if (self) { - graph = [g retain]; - nodeMap = [[NSMutableDictionary alloc] init]; - yylex_init (&scanner); - yyset_extra(self, scanner); - } - return self; -} - -- (void)dealloc { - [graph release]; - [nodeMap release]; - [lastError release]; - yylex_destroy (scanner); - [super dealloc]; -} - -- (BOOL) parseTikz:(NSString*)t error:(NSError**)error { - NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init]; - - tikzStr = [t UTF8String]; - yy_scan_string(tikzStr, scanner); - int result = yyparse(self); - tikzStr = NULL; - - [pool drain]; - - if (result == 0) { - return YES; - } else { - if (error) { - if (lastError) { - *error = [[lastError retain] autorelease]; - } else if (result == 1) { - *error = [NSError errorWithMessage:@"Syntax error" - code:TZ_ERR_PARSE]; - } else if (result == 2) { - *error = [NSError errorWithMessage:@"Insufficient memory" - code:TZ_ERR_PARSE]; - } else { - *error = [NSError errorWithMessage:@"Unknown error" - code:TZ_ERR_PARSE]; - } - } - return NO; - } -} - -+ (BOOL) parseTikz:(NSString*)tikz forGraph:(Graph*)gr { - return [self parseTikz:tikz forGraph:gr error:NULL]; -} -+ (Graph*) parseTikz:(NSString*)tikz error:(NSError**)e { - Graph *gr = [[Graph alloc] init]; - if ([self parseTikz:tikz forGraph:gr error:e]) { - return [gr autorelease]; - } else { - [gr release]; - return nil; - } -} -+ (Graph*) parseTikz:(NSString*)tikz { - return [self parseTikz:tikz error:NULL]; -} - -+ (BOOL) parseTikz:(NSString*)tikz forGraph:(Graph*)gr error:(NSError**)error { - if([tikz length] == 0) { - // empty string -> empty graph - return YES; - } - - TikzGraphAssembler *assembler = [[self alloc] initWithGraph:gr]; - BOOL success = [assembler parseTikz:tikz error:error]; - [assembler release]; - return success; -} - -+ (BOOL)validateTikzPropertyNameOrValue:(NSString*)tikz { - BOOL valid; - - NSString * testTikz = [NSString stringWithFormat: @"{%@}", tikz]; - - void *scanner; - yylex_init (&scanner); - yyset_extra(nil, scanner); - yy_scan_string([testTikz UTF8String], scanner); - YYSTYPE lval; - YYLTYPE lloc; - int result = yylex(&lval, &lloc, scanner); - valid = (result == DELIMITEDSTRING) && - (yyget_leng(scanner) == [testTikz length]); - yylex_destroy(scanner); - - return valid; -} - -+ (BOOL)validateTikzEdgeAnchor:(NSString*)tikz { - if ([tikz length] == 0) - return YES; - - BOOL valid = YES; - - NSString * testTikz = [NSString stringWithFormat: @"(1.%@)", tikz]; - - void *scanner; - yylex_init (&scanner); - yyset_extra(nil, scanner); - yy_scan_string([testTikz UTF8String], scanner); - YYSTYPE lval; - YYLTYPE lloc; - valid = valid && (yylex(&lval, &lloc, scanner) == LEFTPARENTHESIS); - valid = valid && (yylex(&lval, &lloc, scanner) == REFSTRING); - valid = valid && (yylex(&lval, &lloc, scanner) == FULLSTOP); - valid = valid && (yylex(&lval, &lloc, scanner) == REFSTRING); - valid = valid && (yylex(&lval, &lloc, scanner) == RIGHTPARENTHESIS); - valid = valid && (lloc.last_column == [testTikz length]); - yylex_destroy(scanner); - - return valid; -} - -@end - -@implementation TikzGraphAssembler (Parser) -- (Graph*)graph { return graph; } - -- (void)addNodeToMap:(Node*)n { - [nodeMap setObject:n forKey:[n name]]; -} - -- (Node*)nodeWithName:(NSString*)name { - return [nodeMap objectForKey:name]; -} - -- (void) setLastError:(NSError*)error { - [error retain]; - [lastError release]; - lastError = error; -} - -- (void) reportError:(const char *)message atLocation:(YYLTYPE*)yylloc { - NSString *nsmsg = [NSString stringWithUTF8String:message]; - - const char *first_line_start = find_start_of_nth_line ( - tikzStr, yylloc->first_line - 1); - const char *last_line_start = find_start_of_nth_line ( - first_line_start, yylloc->last_line - yylloc->first_line); - const char *last_line_end = last_line_start; - while (*last_line_end && *last_line_end != '\n') { - // points to just after end of last line - ++last_line_end; - } - - size_t context_len = last_line_end - first_line_start; - size_t token_offset = yylloc->first_column - 1; - size_t token_len = ((last_line_start - first_line_start) + yylloc->last_column) - token_offset; - - if (token_offset + token_len > context_len) { - // error position state is corrupted - NSLog(@"Got bad error state for error \"%s\": start(%i,%i), end(%i,%i)", - message, - yylloc->first_line, - yylloc->first_column, - yylloc->last_line, - yylloc->last_column); - [self setLastError:[NSError errorWithMessage:nsmsg - code:TZ_ERR_PARSE]]; - } else { - char *context = malloc (context_len + 1); - strncpy (context, first_line_start, context_len); - *(context + context_len) = '\0'; - - NSDictionary *userInfo = - [NSDictionary dictionaryWithObjectsAndKeys: - nsmsg, - NSLocalizedDescriptionKey, - [NSNumber numberWithInt:yylloc->first_line], - @"startLine", - [NSNumber numberWithInt:yylloc->first_column], - @"startColumn", - [NSNumber numberWithInt:yylloc->last_line], - @"endLine", - [NSNumber numberWithInt:yylloc->last_column], - @"endColumn", - [NSString stringWithUTF8String:context], - @"syntaxString", - [NSNumber numberWithInt:token_offset], - @"tokenStart", - [NSNumber numberWithInt:token_len], - @"tokenLength", - nil]; - [self setLastError: - [NSError errorWithDomain:TZErrorDomain - code:TZ_ERR_PARSE - userInfo:userInfo]]; - - // we can now freely edit context string - // we only bother printing out the first line - if (yylloc->last_line > yylloc->first_line) { - char *nlp = strchr(context, '\n'); - if (nlp) { - *nlp = '\0'; - context_len = nlp - context; - NSAssert2(token_offset < context_len, @"token_offset (%lu) < context_len (%lu)", token_offset, context_len); - if (token_offset + token_len > context_len) { - token_len = context_len - token_offset; - } - } else { - NSLog(@"Didn't find any newlines in context string!"); - } - } - size_t token_col_offset = 0; - size_t token_col_len = 0; - for (int i = 0; i < token_offset; ++i) { - if (*(context + i) == '\t') - token_col_offset += 8; - else - ++token_col_offset; - } - for (int i = token_offset; i < token_offset + token_len; ++i) { - if (*(context + i) == '\t') - token_col_len += 8; - else - ++token_col_len; - } - NSString *pointerLinePadding = - [@"" stringByPaddingToLength:token_col_offset - withString:@" " - startingAtIndex:0]; - NSString *pointerLineCarets = - [@"" stringByPaddingToLength:token_col_len - withString:@"^" - startingAtIndex:0]; - NSLog(@"Parse error on line %i, starting at %i: %s\n%s\n%@%@", - yylloc->first_line, - yylloc->first_column, - message, - context, - pointerLinePadding, - pointerLineCarets); - free (context); - } -} -- (void*) scanner { return scanner; } -@end - -// vi:ft=objc:ts=4:noet:sts=4:sw=4 diff --git a/tikzit/src/common/TikzShape.h b/tikzit/src/common/TikzShape.h deleted file mode 100644 index 1ccf658..0000000 --- a/tikzit/src/common/TikzShape.h +++ /dev/null @@ -1,34 +0,0 @@ -// -// TikzShape.h -// TikZiT -// -// Copyright 2011 Aleks Kissinger. All rights reserved. -// -// -// This file is part of TikZiT. -// -// TikZiT is free software: you can redistribute it and/or modify -// it under the terms of the GNU General Public License as published by -// the Free Software Foundation, either version 3 of the License, or -// (at your option) any later version. -// -// TikZiT is distributed in the hope that it will be useful, -// but WITHOUT ANY WARRANTY; without even the implied warranty of -// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -// GNU General Public License for more details. -// -// You should have received a copy of the GNU General Public License -// along with TikZiT. If not, see <http://www.gnu.org/licenses/>. -// - -#import <Foundation/Foundation.h> -#import "Shape.h" - -@interface TikzShape : Shape { -} - -- (id)initWithTikzFile:(NSString*)file; - -@end - -// vi:ft=objc:noet:ts=4:sts=4:sw=4 diff --git a/tikzit/src/common/TikzShape.m b/tikzit/src/common/TikzShape.m deleted file mode 100644 index 9735371..0000000 --- a/tikzit/src/common/TikzShape.m +++ /dev/null @@ -1,62 +0,0 @@ -// -// TikzShape.m -// TikZiT -// -// Copyright 2011 Aleks Kissinger. All rights reserved. -// -// -// This file is part of TikZiT. -// -// TikZiT is free software: you can redistribute it and/or modify -// it under the terms of the GNU General Public License as published by -// the Free Software Foundation, either version 3 of the License, or -// (at your option) any later version. -// -// TikZiT is distributed in the hope that it will be useful, -// but WITHOUT ANY WARRANTY; without even the implied warranty of -// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -// GNU General Public License for more details. -// -// You should have received a copy of the GNU General Public License -// along with TikZiT. If not, see <http://www.gnu.org/licenses/>. -// - -#import "TikzShape.h" -#import "Graph.h" - -@implementation TikzShape - -- (id)initWithTikzFile:(NSString*)file { - self = [super init]; - if (self) { - NSString *tikz = [NSString stringWithContentsOfFile:file - encoding:NSUTF8StringEncoding - error:NULL]; - if (tikz == nil) return nil; - - Graph *graph = [Graph graphFromTikz:tikz]; - if (graph == nil) return nil; - - NSRect graphBounds = ([graph hasBoundingBox]) ? [graph boundingBox] : [graph bounds]; - - float sz = 0.5f; - - // the "screen" coordinate space fits in the shape bounds - Transformer *t = [Transformer transformer]; - float width_ratio = (2*sz) / graphBounds.size.width; - float height_ratio = (2*sz) / graphBounds.size.height; - [t setScale:MIN(width_ratio, height_ratio)]; - NSRect bds = [t rectToScreen:graphBounds]; - NSPoint shift = NSMakePoint(-NSMidX(bds), - -NSMidY(bds)); - [t setOrigin:shift]; - [graph applyTransformer:t]; - paths = [[graph pathCover] retain]; - } - return self; -} - - -@end - -// vi:ft=objc:ts=4:noet:sts=4:sw=4 diff --git a/tikzit/src/common/Transformer.h b/tikzit/src/common/Transformer.h deleted file mode 100644 index 1b0108a..0000000 --- a/tikzit/src/common/Transformer.h +++ /dev/null @@ -1,154 +0,0 @@ -// -// Transformer.h -// TikZiT -// -// Copyright 2010 Aleks Kissinger. All rights reserved. -// -// -// This file is part of TikZiT. -// -// TikZiT is free software: you can redistribute it and/or modify -// it under the terms of the GNU General Public License as published by -// the Free Software Foundation, either version 3 of the License, or -// (at your option) any later version. -// -// TikZiT is distributed in the hope that it will be useful, -// but WITHOUT ANY WARRANTY; without even the implied warranty of -// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -// GNU General Public License for more details. -// -// You should have received a copy of the GNU General Public License -// along with TikZiT. If not, see <http://www.gnu.org/licenses/>. -// - - -#import <Foundation/Foundation.h> - -extern float const PIXELS_PER_UNIT; - -/*! - @class Transformer - @brief Do affine coordinate transforms between an abstract co-ordinate - space (such as the graph's) and the screen's. - - This currently allows zooming and panning. - */ -@interface Transformer : NSObject <NSCopying> { - NSPoint origin; - float x_scale; - float y_scale; -} - -/*! - @brief The screen co-ordinate of the abstract space origin. - */ -@property (assign) NSPoint origin; - -/*! - @brief The scale (from abstract space to screen space) - @detail This is the size of a single unit (a distance of 1.0) - of the abstract space on the screen. - - Around 50 is a reasonable value. - */ -@property (assign) float scale; - -/*! - @brief Whether co-ordinates are flipped about the X axis - @detail TikZ considers X co-ordinates to run left to right, - which is not necessarily how the screen views - them. - */ -@property (assign,getter=isFlippedAboutXAxis) BOOL flippedAboutXAxis; - -/*! - @brief Whether co-ordinates are flipped about the Y axis - @detail TikZ considers Y co-ordinates to run up the page, - which is not necessarily how the screen views - them. - */ -@property (assign,getter=isFlippedAboutYAxis) BOOL flippedAboutYAxis; - -/*! - @brief Transform a point from screen space to abstract space. - @param p a point in screen space. - @result A point in abstract space. - */ -- (NSPoint)fromScreen:(NSPoint)p; - -/*! - @brief Transform a point from abstract space to screen space. - @param p a point in abstract space. - @result A point in screen space. - */ -- (NSPoint)toScreen:(NSPoint)p; - -/*! - @brief Scale a distance from screen space to abstract space. - @param dist a distance in screen space. - @result A distance in abstract space. - */ -- (float)scaleFromScreen:(float)dist; - -/*! - @brief Scale a distance from abstract space to screen space. - @param dist a distance in abstract space. - @result A distance in screen space. - */ -- (float)scaleToScreen:(float)dist; - -/*! - @brief Scale a rectangle from screen space to abstract space. - @param r a rectangle in screen space. - @result A rectangle in abstract space. - */ -- (NSRect)rectFromScreen:(NSRect)r; - -/*! - @brief Scale a rectangle from abstract space to screen space. - @param r a rectangle in abstract space. - @result A rectangle in screen space. - */ -- (NSRect)rectToScreen:(NSRect)r; - -/*! - @brief Factory method to get an identity transformer. - @result A transformer. - */ -+ (Transformer*)transformer; - -/*! - @brief Factory method to get a transformer identical to another - @result A transformer. - */ -+ (Transformer*)transformerWithTransformer:(Transformer*)t; - -/*! - @brief Factory method to get a transformer. - @param o The screen co-ordinate of the abstract space origin - @param scale The scale (from abstract space to screen space) - @result A transformer. - */ -+ (Transformer*)transformerWithOrigin:(NSPoint)o andScale:(float)scale; - -/*! - @brief Get a global 'actual size' transformer. - @result A transformer. - */ -+ (Transformer*)defaultTransformer; - -/*! - @brief A transformer set up from two bounding rects. - - graphRect is made as large as possible while still fitting into screenRect. - @result A transformer. - */ -+ (Transformer*)transformerToFit:(NSRect)graphRect intoScreenRect:(NSRect)screenRect flippedAboutXAxis:(BOOL)flipX flippedAboutYAxis:(BOOL)flipY; - -+ (Transformer*)transformerToFit:(NSRect)graphRect intoScreenRect:(NSRect)screenRect flippedAboutXAxis:(BOOL)flipX; -+ (Transformer*)transformerToFit:(NSRect)graphRect intoScreenRect:(NSRect)screenRect flippedAboutYAxis:(BOOL)flipY; -+ (Transformer*)transformerToFit:(NSRect)graphRect intoScreenRect:(NSRect)screenRect; - -@end - -// vi:ft=objc:noet:ts=4:sts=4:sw=4 diff --git a/tikzit/src/common/Transformer.m b/tikzit/src/common/Transformer.m deleted file mode 100644 index 403ae87..0000000 --- a/tikzit/src/common/Transformer.m +++ /dev/null @@ -1,223 +0,0 @@ -// -// Transformer.m -// TikZiT -// -// Copyright 2010 Aleks Kissinger. All rights reserved. -// -// -// This file is part of TikZiT. -// -// TikZiT is free software: you can redistribute it and/or modify -// it under the terms of the GNU General Public License as published by -// the Free Software Foundation, either version 3 of the License, or -// (at your option) any later version. -// -// TikZiT is distributed in the hope that it will be useful, -// but WITHOUT ANY WARRANTY; without even the implied warranty of -// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -// GNU General Public License for more details. -// -// You should have received a copy of the GNU General Public License -// along with TikZiT. If not, see <http://www.gnu.org/licenses/>. -// - -#import "Transformer.h" - -float const PIXELS_PER_UNIT = 50; - -@implementation Transformer - -+ (Transformer*)transformer { - return [[[Transformer alloc] init] autorelease]; -} - -+ (Transformer*)transformerWithTransformer:(Transformer*)t { - return [[t copy] autorelease]; -} - -+ (Transformer*)transformerWithOrigin:(NSPoint)o andScale:(float)scale { - Transformer *trans = [self transformer]; - [trans setOrigin:o]; - [trans setScale:scale]; - return trans; -} - -+ (Transformer*)transformerToFit:(NSRect)graphRect - intoScreenRect:(NSRect)screenRect { - return [self transformerToFit:graphRect - intoScreenRect:screenRect - flippedAboutXAxis:NO - flippedAboutYAxis:NO]; -} - -+ (Transformer*)transformerToFit:(NSRect)graphRect - intoScreenRect:(NSRect)screenRect - flippedAboutXAxis:(BOOL)flipX { - return [self transformerToFit:graphRect - intoScreenRect:screenRect - flippedAboutXAxis:flipX - flippedAboutYAxis:NO]; -} - -+ (Transformer*)transformerToFit:(NSRect)graphRect - intoScreenRect:(NSRect)screenRect - flippedAboutYAxis:(BOOL)flipY { - return [self transformerToFit:graphRect - intoScreenRect:screenRect - flippedAboutXAxis:NO - flippedAboutYAxis:flipY]; -} - -+ (Transformer*)transformerToFit:(NSRect)graphRect - intoScreenRect:(NSRect)screenRect - flippedAboutXAxis:(BOOL)flipAboutXAxis - flippedAboutYAxis:(BOOL)flipAboutYAxis { - - const float wscale = screenRect.size.width / graphRect.size.width; - const float hscale = screenRect.size.height / graphRect.size.height; - const float scale = (wscale < hscale) ? wscale : hscale; - const float xpad = (screenRect.size.width - (graphRect.size.width * scale)) / 2.0; - const float ypad = (screenRect.size.height - (graphRect.size.height * scale)) / 2.0; - - // if we are flipping, we need to calculate the origin from the opposite edge - const float gx = flipAboutYAxis ? -(graphRect.size.width + graphRect.origin.x) - : graphRect.origin.x; - const float gy = flipAboutXAxis ? -(graphRect.size.height + graphRect.origin.y) - : graphRect.origin.y; - const float origin_x = screenRect.origin.x - (gx * scale) + xpad; - const float origin_y = screenRect.origin.y - (gy * scale) + ypad; - - Transformer *trans = [self transformer]; - [trans setOrigin:NSMakePoint(origin_x, origin_y)]; - [trans setScale:scale]; - [trans setFlippedAboutXAxis:flipAboutXAxis]; - [trans setFlippedAboutYAxis:flipAboutYAxis]; - return trans; -} - -- (id) init { - self = [super init]; - - if (self) { - origin = NSZeroPoint; - x_scale = 1.0f; - y_scale = 1.0f; - } - - return self; -} - -- (id)copyWithZone:(NSZone *)zone { - Transformer *cp = [[[self class] allocWithZone:zone] init]; - if (cp) { - cp->origin = origin; - cp->x_scale = x_scale; - cp->y_scale = y_scale; - } - return cp; -} - -- (NSPoint)origin { return origin; } -- (void)setOrigin:(NSPoint)o { - origin = o; -} - -- (float)scale { return ABS(x_scale); } -- (void)setScale:(float)s { - x_scale = (x_scale < 0.0) ? -s : s; - y_scale = (y_scale < 0.0) ? -s : s; -} - -- (BOOL)isFlippedAboutXAxis { - return y_scale < 0.0; -} - -- (void)setFlippedAboutXAxis:(BOOL)flip { - if (flip != [self isFlippedAboutXAxis]) { - y_scale *= -1; - } -} - -- (BOOL)isFlippedAboutYAxis { - return x_scale < 0.0; -} - -- (void)setFlippedAboutYAxis:(BOOL)flip { - if (flip != [self isFlippedAboutYAxis]) { - x_scale *= -1; - } -} - -- (NSPoint)fromScreen:(NSPoint)p { - NSPoint trans; - trans.x = (p.x - origin.x) / x_scale; - trans.y = (p.y - origin.y) / y_scale; - return trans; -} - -- (NSPoint)toScreen:(NSPoint)p { - NSPoint trans; - trans.x = (p.x * x_scale) + origin.x; - trans.y = (p.y * y_scale) + origin.y; - return trans; -} - -- (float)scaleFromScreen:(float)dist { - return dist / ABS(x_scale); -} - -- (float)scaleToScreen:(float)dist { - return dist * ABS(x_scale); -} - -- (NSRect)rectFromScreen:(NSRect)r { - NSRect r1; - r1.origin = [self fromScreen:r.origin]; - r1.size.width = [self scaleFromScreen:r.size.width]; - r1.size.height = [self scaleFromScreen:r.size.height]; - // if we're flipped, the origin will be at a different corner - if ([self isFlippedAboutYAxis]) { - r1.origin.x -= r1.size.width; - } - if ([self isFlippedAboutXAxis]) { - r1.origin.y -= r1.size.height; - } - return r1; -} - -- (NSRect)rectToScreen:(NSRect)r { - NSPoint o = r.origin; - // if we're flipped, the origin will be at a different corner - if ([self isFlippedAboutYAxis]) { - o.x = NSMaxX(r); - } - if ([self isFlippedAboutXAxis]) { - o.y = NSMaxY(r); - } - NSRect r1; - r1.origin = [self toScreen:o]; - r1.size.width = [self scaleToScreen:r.size.width]; - r1.size.height = [self scaleToScreen:r.size.height]; - return r1; -} - -- (BOOL)isEqual:(id)object { - Transformer *t = (Transformer*)object; - return ([t origin].x == [self origin].x && - [t origin].y == [self origin].y && - [t scale] == [self scale]); -} - -Transformer *defaultTransformer = nil; - -+ (Transformer*)defaultTransformer { - if (defaultTransformer == nil) { - defaultTransformer = [[Transformer alloc] init]; - [defaultTransformer setScale:PIXELS_PER_UNIT]; - } - return defaultTransformer; -} - -@end - -// vi:ft=objc:ts=4:noet:sts=4:sw=4 diff --git a/tikzit/src/common/test/Makefile b/tikzit/src/common/test/Makefile deleted file mode 100644 index d158d16..0000000 --- a/tikzit/src/common/test/Makefile +++ /dev/null @@ -1,14 +0,0 @@ -OBJC = gcc -MMD -MP -DSTAND_ALONE -DGNUSTEP -DGNUSTEP_BASE_LIBRARY=1 -DGNU_RUNTIME=1 -DGNUSTEP_BASE_LIBRARY=1 -fno-strict-aliasing -fPIC -Wall -DGSWARN -DGSDIAGNOSE -Wno-import -O0 -g -pipe -Wall -Wp,-D_FORTIFY_SOURCE=2 -fexceptions -fstack-protector --param=ssp-buffer-size=4 -m64 -mtune=generic -fgnu-runtime -fconstant-string-class=NSConstantString -I. -I.. -I/users/alemer/GNUstep/Library/Headers -std=c99 -D_GNU_SOURCE -rdynamic -fgnu-runtime -L/users/alemer/GNUstep/Library/Libraries -L/usr/local/lib64 -L/usr/lib64 -lgnustep-base -lpthread -lobjc -lm - -maths_test_objects = test.m maths.m ../util.m -color_test_objects = test.m color.m ../ColorRGB.m ../util.m ../BasicMapTable.m ../RColor.m - -test: maths-test color-test - ./maths-test - ./color-test - -maths-test: $(maths_test_objects) - $(OBJC) $(maths_test_objects) -o $@ - -color-test: $(color_test_objects) - $(OBJC) $(color_test_objects) -o $@ diff --git a/tikzit/src/common/test/color.m b/tikzit/src/common/test/color.m deleted file mode 100644 index 48a6ff4..0000000 --- a/tikzit/src/common/test/color.m +++ /dev/null @@ -1,80 +0,0 @@ -// -// color.m -// TikZiT -// -// Copyright 2010 Aleks Kissinger. All rights reserved. -// -// -// This file is part of TikZiT. -// -// TikZiT is free software: you can redistribute it and/or modify -// it under the terms of the GNU General Public License as published by -// the Free Software Foundation, either version 3 of the License, or -// (at your option) any later version. -// -// TikZiT is distributed in the hope that it will be useful, -// but WITHOUT ANY WARRANTY; without even the implied warranty of -// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -// GNU General Public License for more details. -// -// You should have received a copy of the GNU General Public License -// along with TikZiT. If not, see <http://www.gnu.org/licenses/>. -// -#import "test/test.h" -#import "ColorRGB.h" - -#ifdef STAND_ALONE -void runTests() { -#else -void testColor() { -#endif - NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init]; - startTestBlock(@"color"); - - ColorRGB *red = [ColorRGB colorWithRed:255 green:0 blue:0]; - ColorRGB *lime = [ColorRGB colorWithRed:0 green:255 blue:0]; - ColorRGB *green = [ColorRGB colorWithRed:0 green:128 blue:0]; - TEST(@"Recognised red", - [red name] != nil && - [[red name] isEqualToString:@"Red"]); - TEST(@"Recognised lime", - [lime name] != nil && - [[lime name] isEqualToString:@"Lime"]); - TEST(@"Recognised green", - [green name] != nil && - [[green name] isEqualToString:@"Green"]); - - ColorRGB *floatRed = [ColorRGB colorWithFloatRed:1.0f green:0.0f blue:0.0f]; - ColorRGB *floatLime = [ColorRGB colorWithFloatRed:0.0f green:1.0f blue:0.0f]; - ColorRGB *floatGreen = [ColorRGB colorWithFloatRed:0.0f green:0.5f blue:0.0f]; - - TEST(@"Float red equal to int red", [floatRed isEqual:red]); - TEST(@"Float lime equal to int lime", [floatLime isEqual:lime]); - TEST(@"Float green equal to int green", [floatGreen isEqual:green]); - - TEST(@"Recognised float red", - [floatRed name] != nil && - [[floatRed name] isEqualToString:@"Red"]); - - TEST(@"Recognised float lime", - [floatLime name] != nil && - [[floatLime name] isEqualToString:@"Lime"]); - - TEST(@"Recognised float green", - [floatGreen name] != nil && - [[floatGreen name] isEqualToString:@"Green"]); - - [floatRed setRedFloat:0.99f]; - TEST(@"Nudged red, not recognised now", [floatRed name] == nil); - [floatRed setToClosestHashed]; - TEST(@"Set to closest hashed, reconised again", - [floatRed name] != nil && - [[floatRed name] isEqualToString:@"Red"]); - - TEST(@"Red has correct hex (ff0000)", [[red hexName] isEqualToString:@"hexcolor0xff0000"]); - TEST(@"Lime has correct hex (00ff00)", [[lime hexName] isEqualToString:@"hexcolor0x00ff00"]); - TEST(@"Green has correct hex (008000)", [[green hexName] isEqualToString:@"hexcolor0x008000"]); - - endTestBlock(@"color"); - [pool drain]; -} diff --git a/tikzit/src/common/test/common.m b/tikzit/src/common/test/common.m deleted file mode 100644 index c9ac980..0000000 --- a/tikzit/src/common/test/common.m +++ /dev/null @@ -1,34 +0,0 @@ -// -// common.m -// TikZiT -// -// Copyright 2010 Aleks Kissinger. All rights reserved. -// -// -// This file is part of TikZiT. -// -// TikZiT is free software: you can redistribute it and/or modify -// it under the terms of the GNU General Public License as published by -// the Free Software Foundation, either version 3 of the License, or -// (at your option) any later version. -// -// TikZiT is distributed in the hope that it will be useful, -// but WITHOUT ANY WARRANTY; without even the implied warranty of -// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -// GNU General Public License for more details. -// -// You should have received a copy of the GNU General Public License -// along with TikZiT. If not, see <http://www.gnu.org/licenses/>. -// -#import "test/test.h" -void testParser(); -void testColor(); -void testMaths(); - -void testCommon() { - startTestBlock(@"common"); - testParser(); - testColor(); - testMaths(); - endTestBlock(@"common"); -} diff --git a/tikzit/src/common/test/maths.m b/tikzit/src/common/test/maths.m deleted file mode 100644 index a11e58e..0000000 --- a/tikzit/src/common/test/maths.m +++ /dev/null @@ -1,562 +0,0 @@ -// -// TikZiT -// -// Copyright 2011 Alex Merry -// -// This file is part of TikZiT. -// -// TikZiT is free software: you can redistribute it and/or modify -// it under the terms of the GNU General Public License as published by -// the Free Software Foundation, either version 3 of the License, or -// (at your option) any later version. -// -// TikZiT is distributed in the hope that it will be useful, -// but WITHOUT ANY WARRANTY; without even the implied warranty of -// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -// GNU General Public License for more details. -// -// You should have received a copy of the GNU General Public License -// along with TikZiT. If not, see <http://www.gnu.org/licenses/>. -// - -#import "../util.h" - -#import "test.h" - -void testRectAroundPoints() { - NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init]; - startTestBlock(@"NSRectAroundPoints"); - - NSRect rect = NSRectAroundPoints (NSZeroPoint, NSZeroPoint); - assertRectsEqual (@"(0,0) and (0,0)", rect, NSZeroRect); - - rect = NSRectAroundPoints (NSZeroPoint, NSMakePoint (1.0f, 1.0f)); - assertRectsEqual (@"(0,0) and (1,1)", rect, NSMakeRect (0.0f, 0.0f, 1.0f, 1.0f)); - - rect = NSRectAroundPoints (NSMakePoint (-1.0f, 1.0f), NSMakePoint (1.0f, -1.0f)); - assertRectsEqual (@"(-1,1) and (1,-1)", rect, NSMakeRect (-1.0f, -1.0f, 2.0f, 2.0f)); - - endTestBlock(@"NSRectAroundPoints"); - [pool drain]; -} - -void testRectAroundPointsWithPadding() { - NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init]; - startTestBlock(@"NSRectAroundPointsWithPadding"); - - NSRect rect = NSRectAroundPointsWithPadding (NSZeroPoint, NSZeroPoint, 0.0f); - assertRectsEqual (@"(0,0) and (0,0); 0 padding", rect, NSZeroRect); - - rect = NSRectAroundPointsWithPadding (NSZeroPoint, NSZeroPoint, 0.2f); - assertRectsEqual (@"(0,0) and (0,0); 0.2 padding", rect, NSMakeRect (-0.2f, -0.2f, 0.4f, 0.4f)); - - rect = NSRectAroundPointsWithPadding (NSZeroPoint, NSMakePoint (1.0f, 1.0f), -0.2f); - assertRectsEqual (@"(0,0) and (1,1); -0.2 padding", rect, NSMakeRect (0.2f, 0.2f, 0.6f, 0.6f)); - - endTestBlock(@"NSRectAroundPointsWithPadding"); - [pool drain]; -} - -void testGoodAtan() { - NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init]; - startTestBlock(@"good_atan"); - - assertFloatsEqual (@"0.0, 0.0", good_atan (0.0f, 0.0f), 0.0f); - assertFloatsEqual (@"0.0, 1.0", good_atan (0.0f, 1.0f), 0.5f * M_PI); - assertFloatsEqual (@"0.0, -1.0", good_atan (0.0f, -1.0f), 1.5f * M_PI); - assertFloatsEqual (@"1.0, 0.0", good_atan (1.0f, 0.0f), 0.0f); - assertFloatsEqual (@"1.0, 0.1", good_atan (1.0f, 0.1f), 0.0996687f); - - endTestBlock(@"good_atan"); - [pool drain]; -} - -void testBezierInterpolate() { - NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init]; - startTestBlock(@"bezierInterpolate"); - - assertFloatsEqual (@"0.0, (0.0, 0.1, 0.2, 0.3)", bezierInterpolate (0.0f, 0.0f, 0.1f, 0.2f, 0.3f), 0.0f); - assertFloatsEqual (@"1.0, (0.0, 0.1, 0.2, 0.3)", bezierInterpolate (1.0f, 0.0f, 0.1f, 0.2f, 0.3f), 0.3f); - assertFloatsEqual (@"0.5, (0.0, 0.1, 0.2, 0.3)", bezierInterpolate (0.5f, 0.0f, 0.1f, 0.2f, 0.3f), 0.15f); - // FIXME: other tests - - endTestBlock(@"bezierInterpolate"); - [pool drain]; -} - -void testLineSegmentsIntersect() { - NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init]; - startTestBlock(@"lineSegmentsIntersect"); - - BOOL result = NO; - NSPoint intersection = NSMakePoint (-1.0f, -1.0f); - - result = lineSegmentsIntersect (NSMakePoint (-1.0f, -1.0f), NSMakePoint (1.0f, 1.0f), - NSMakePoint (-1.0f, 1.0f), NSMakePoint (1.0f, -1.0f), - &intersection); - TEST (@"Cross at zero: has intersection", result); - assertPointsEqual (@"Cross at zero: intersection value", intersection, NSZeroPoint); - - result = lineSegmentsIntersect (NSMakePoint (-1.0f, -1.0f), NSMakePoint (-0.5f, -0.5f), - NSMakePoint (-1.0f, 1.0f), NSMakePoint (1.0f, -1.0f), - &intersection); - TEST (@"Fail to cross at zero", !result); - - result = lineSegmentsIntersect (NSMakePoint (1.0f, 1.0f), NSMakePoint (1.0f, -1.0f), - NSMakePoint (0.0f, 0.0f), NSMakePoint (1.0f, 0.0f), - &intersection); - TEST (@"Touch at one: has intersection", result); - assertPointsEqual (@"Touch at one: intersection value", intersection, NSMakePoint (1.0f, 0.0f)); - - endTestBlock(@"lineSegmentsIntersect"); - [pool drain]; -} - -void testLineSegmentIntersectsRect() { - NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init]; - startTestBlock(@"lineSegmentIntersectsRect"); - - BOOL result = NO; - - result = lineSegmentIntersectsRect ( - NSMakePoint (-1.0f, -1.0f), - NSMakePoint (0.0f, 0.0f), - NSZeroRect); - TEST (@"Zero rect; line touches zero", result); - - result = lineSegmentIntersectsRect ( - NSMakePoint (-1.0f, -1.0f), - NSMakePoint (-0.1f, -0.1f), - NSZeroRect); - TEST (@"Zero rect; line short of zero", !result); - - NSRect rect = NSMakeRect (1.0f, 1.0f, 1.0f, 1.0f); - - result = lineSegmentIntersectsRect ( - NSMakePoint (0.0f, 0.0f), - NSMakePoint (3.0f, 1.0f), - rect); - TEST (@"Line underneath", !result); - - result = lineSegmentIntersectsRect ( - NSMakePoint (0.0f, 0.0f), - NSMakePoint (1.0f, 3.0f), - rect); - TEST (@"Line to left", !result); - - result = lineSegmentIntersectsRect ( - NSMakePoint (0.0f, 2.0f), - NSMakePoint (3.0f, 3.0f), - rect); - TEST (@"Line above", !result); - - result = lineSegmentIntersectsRect ( - NSMakePoint (2.0f, 0.0f), - NSMakePoint (3.0f, 3.0f), - rect); - TEST (@"Line to right", !result); - - result = lineSegmentIntersectsRect ( - NSMakePoint (0.0f, 0.0f), - NSMakePoint (0.9f, 0.9f), - rect); - TEST (@"Line short", !result); - - result = lineSegmentIntersectsRect ( - NSMakePoint (1.1f, 1.1f), - NSMakePoint (1.9f, 1.9f), - rect); - TEST (@"Line inside", result); - - result = lineSegmentIntersectsRect ( - NSMakePoint (0.0f, 1.5f), - NSMakePoint (3.0f, 1.5f), - rect); - TEST (@"Horizontal line through", result); - - result = lineSegmentIntersectsRect ( - NSMakePoint (1.5f, 0.0f), - NSMakePoint (1.5f, 3.0f), - rect); - TEST (@"Vertical line through", result); - - result = lineSegmentIntersectsRect ( - NSMakePoint (0.5f, 1.0f), - NSMakePoint (2.0f, 2.5f), - rect); - TEST (@"Cut top and left", result); - - result = lineSegmentIntersectsRect ( - NSMakePoint (2.0f, 0.5f), - NSMakePoint (0.5f, 2.0f), - rect); - TEST (@"Cut bottom and left", result); - - result = lineSegmentIntersectsRect ( - NSMakePoint (1.0f, 0.5f), - NSMakePoint (2.5f, 2.0f), - rect); - TEST (@"Cut bottom and right", result); - - result = lineSegmentIntersectsRect ( - NSMakePoint (0.0f, 1.0f), - NSMakePoint (2.0f, 3.0f), - rect); - TEST (@"Touch top left", result); - - result = lineSegmentIntersectsRect ( - NSMakePoint (1.0f, 0.0f), - NSMakePoint (3.0f, 2.0f), - rect); - TEST (@"Touch bottom right", result); - - result = lineSegmentIntersectsRect ( - NSMakePoint (1.0f, 0.0f), - NSMakePoint (1.0f, 3.0f), - rect); - TEST (@"Along left side", result); - - result = lineSegmentIntersectsRect ( - NSMakePoint (0.0f, 1.0f), - NSMakePoint (3.0f, 1.0f), - rect); - TEST (@"Along bottom side", result); - - endTestBlock(@"lineSegmentIntersectsRect"); - [pool drain]; -} - -struct line_bezier_test { - NSString *msg; - NSPoint lstart; - NSPoint lend; - NSPoint c0; - NSPoint c1; - NSPoint c2; - NSPoint c3; - BOOL expectedResult; - float expectedT; - NSPoint expectedIntersect; -}; - -static struct line_bezier_test line_bezier_tests[] = { - { - @"Outside box", - {0.0f, 0.0f}, - {1.0f, 0.0f}, - {0.0f, 1.0f}, - {0.0f, 2.0f}, - {1.0f, 2.0f}, - {1.0f, 1.0f}, - NO, - -1.0f, - {0.0f, 0.0f} - }, - { - @"Single intersect", - {100.0f, 20.0f}, - {195.0f, 255.0f}, - {93.0f, 163.0f}, - {40.0f, 30.0f}, - {270.0f, 115.0f}, - {219.0f, 178.0f}, - YES, - -0.4f, - {129.391693f, 92.705772f} - }, - { - @"Double intersect", - {100.0f, 20.0f}, - {195.0f, 255.0f}, - {93.0f, 163.0f}, - {40.0f, 30.0f}, - {270.0f, 115.0f}, - {154.0f, 212.0f}, - YES, - -0.909f, - {170.740646f,194.990021f} - }, - { - @"Near miss", - {100.0f, 20.0f}, - {195.0f, 255.0f}, - {93.0f, 163.0f}, - {40.0f, 30.0f}, - {176.0f, 100.0f}, - {154.0f, 212.0f}, - NO, - -1.0f, - {0.0f,0.0f} - } -}; -static unsigned int n_line_bezier_tests = sizeof (line_bezier_tests) / sizeof (line_bezier_tests[0]); - -void testLineSegmentIntersectsBezier() { - NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init]; - startTestBlock(@"lineSegmentIntersectsBezier"); - - for (unsigned int i = 0; i < n_line_bezier_tests; ++i) { - NSPoint intersect; - BOOL result = lineSegmentIntersectsBezier ( - line_bezier_tests[i].lstart, - line_bezier_tests[i].lend, - line_bezier_tests[i].c0, - line_bezier_tests[i].c1, - line_bezier_tests[i].c2, - line_bezier_tests[i].c3, - &intersect); - if (result) { - if (line_bezier_tests[i].expectedT < 0.0f) { - assertPointsEqual (line_bezier_tests[i].msg, intersect, line_bezier_tests[i].expectedIntersect); - } else { - assertPointsEqual (line_bezier_tests[i].msg, intersect, - bezierInterpolateFull (line_bezier_tests[i].expectedT, line_bezier_tests[i].c0, line_bezier_tests[i].c1, line_bezier_tests[i].c2, line_bezier_tests[i].c3)); - } - } else { - if (line_bezier_tests[i].expectedResult) - fail (line_bezier_tests[i].msg); - else - pass (line_bezier_tests[i].msg); - } - } - -BOOL lineSegmentIntersectsBezier (NSPoint lstart, NSPoint lend, NSPoint c0, NSPoint c1, NSPoint c2, NSPoint c3, NSPoint *result); - endTestBlock(@"lineSegmentIntersectsBezier"); - [pool drain]; -} - -struct exit_point_test { - NSString *msg; - NSPoint rayStart; - float angle; - NSRect rect; - NSPoint expected; -}; - -static struct exit_point_test exit_point_tests[] = { - { - @"0.0 rads", - {0.0f, 0.0f}, - 0.0f, - {{-1.0f, -1.0f}, {2.0f, 2.0f}}, - {1.0f, 0.0f} - }, - { - @"pi/2 rads", - {0.0f, 0.0f}, - M_PI / 2.0f, - {{-1.0f, -1.0f}, {2.0f, 2.0f}}, - {0.0f, 1.0f} - }, - { - @"-pi/2 rads", - {0.0f, 0.0f}, - -M_PI / 2.0f, - {{-1.0f, -1.0f}, {2.0f, 2.0f}}, - {0.0f, -1.0f} - }, - { - @"pi rads", - {0.0f, 0.0f}, - M_PI, - {{-1.0f, -1.0f}, {2.0f, 2.0f}}, - {-1.0f, 0.0f} - }, - { - @"-pi rads", - {0.0f, 0.0f}, - -M_PI, - {{-1.0f, -1.0f}, {2.0f, 2.0f}}, - {-1.0f, 0.0f} - }, - { - @"pi/4 rads", - {0.0f, 0.0f}, - M_PI / 4.0f, - {{-1.0f, -1.0f}, {2.0f, 2.0f}}, - {1.0f, 1.0f} - }, - { - @"3pi/4 rads", - {0.0f, 0.0f}, - (3.0f * M_PI) / 4.0f, - {{-1.0f, -1.0f}, {2.0f, 2.0f}}, - {-1.0f, 1.0f} - }, - { - @"-pi/4 rads", - {0.0f, 0.0f}, - -M_PI / 4.0f, - {{-1.0f, -1.0f}, {2.0f, 2.0f}}, - {1.0f, -1.0f} - }, - { - @"-3pi/4 rads", - {0.0f, 0.0f}, - (-3.0f * M_PI) / 4.0f, - {{-1.0f, -1.0f}, {2.0f, 2.0f}}, - {-1.0f, -1.0f} - }, - { - @"pi/8 rads", - {0.0f, 0.0f}, - M_PI / 8.0f, - {{-1.0f, -1.0f}, {2.0f, 2.0f}}, - {1.0f, 0.414213562373095f} - }, - { - @"3pi/8 rads", - {0.0f, 0.0f}, - 3.0f * M_PI / 8.0f, - {{-1.0f, -1.0f}, {2.0f, 2.0f}}, - {0.414213562373095f, 1.0f} - }, - { - @"-5pi/8 rads", - {0.0f, 0.0f}, - -5.0f * M_PI / 8.0f, - {{-1.0f, -1.0f}, {2.0f, 2.0f}}, - {-0.414213562373095f, -1.0f} - }, - { - @"-7pi/8 rads", - {0.0f, 0.0f}, - -7.0f * M_PI / 8.0f, - {{-1.0f, -1.0f}, {2.0f, 2.0f}}, - {-1.0f, -0.414213562373095f} - }, - { - @"pi/8 rads; origin (1,1)", - {1.0f, 1.0f}, - M_PI / 8.0f, - {{0.0f, 0.0f}, {2.0f, 2.0f}}, - {2.0f, 1.414213562373095f} - }, - { - @"7pi/8 rads; origin (-2,2)", - {-2.0f, 2.0f}, - 7.0f * M_PI / 8.0f, - {{-3.0f, 1.0f}, {2.0f, 2.0f}}, - {-3.0f, 2.414213562373095f} - }, - { - @"pi/8 rads; origin (1,1); SW of box", - {1.0f, 1.0f}, - M_PI / 8.0f, - {{1.0f, 1.0f}, {1.0f, 1.0f}}, - {2.0f, 1.414213562373095f} - }, - { - @"pi/8 rads; origin (1,1); SE of box", - {1.0f, 1.0f}, - M_PI / 8.0f, - {{0.0f, 1.0f}, {1.0f, 1.0f}}, - {1.0f, 1.0f} - }, - { - @"pi/8 rads; origin (1,1); NE of box", - {1.0f, 1.0f}, - M_PI / 8.0f, - {{0.0f, 1.0f}, {1.0f, 1.0f}}, - {1.0f, 1.0f} - }, - { - @"pi/8 rads; origin (1,1); NW of box", - {1.0f, 1.0f}, - M_PI / 8.0f, - {{1.0f, 0.0f}, {1.0f, 1.0f}}, - {1.0f, 1.0f} - }, - { - @"pi/8 rads; origin (1,1); N of box", - {1.0f, 1.0f}, - M_PI / 8.0f, - {{0.5f, 0.0f}, {1.0f, 1.0f}}, - {1.0f, 1.0f} - }, - { - @"7pi/8 rads; origin (1,1); N of box", - {1.0f, 1.0f}, - 7.0f * M_PI / 8.0f, - {{0.5f, 0.0f}, {1.0f, 1.0f}}, - {1.0f, 1.0f} - }, - { - @"-pi/8 rads; origin (1,1); S of box", - {1.0f, 1.0f}, - -M_PI / 8.0f, - {{0.5f, 1.0f}, {1.0f, 1.0f}}, - {1.0f, 1.0f} - }, - { - @"-pi/8 rads; origin (1,1); E of box", - {1.0f, 1.0f}, - -M_PI / 8.0f, - {{0.0f, 0.5f}, {1.0f, 1.0f}}, - {1.0f, 1.0f} - }, - { - @"-7pi/8 rads; origin (1,1); W of box", - {1.0f, 1.0f}, - -7.0f * M_PI / 8.0f, - {{1.0f, 0.5f}, {1.0f, 1.0f}}, - {1.0f, 1.0f} - }, - { - @"7pi/8 rads; origin (1,1); W of box", - {1.0f, 1.0f}, - 7.0f * M_PI / 8.0f, - {{1.0f, 0.5f}, {1.0f, 1.0f}}, - {1.0f, 1.0f} - }, - { - @"pi/8 rads; origin (1,1); leave through top", - {1.0f, 1.0f}, - M_PI / 8.0f, - {{0.9f, 0.1f}, {1.0f, 1.0f}}, - {1.2414213562373f, 1.1f} - }, - { - @"0 rads; origin (1,1); N of box", - {1.0f, 1.0f}, - 0.0f, - {{0.5f, 0.0f}, {1.0f, 1.0f}}, - {1.5f, 1.0f} - } -}; -static unsigned int n_exit_point_tests = sizeof (exit_point_tests) / sizeof (exit_point_tests[0]); - -void testFindExitPointOfRay() { - NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init]; - startTestBlock(@"findExitPointOfRay"); - - for (unsigned int i = 0; i < n_exit_point_tests; ++i) { - NSPoint exitPoint = findExitPointOfRay ( - exit_point_tests[i].rayStart, - exit_point_tests[i].angle, - exit_point_tests[i].rect); - assertPointsEqual (exit_point_tests[i].msg, exitPoint, exit_point_tests[i].expected); - } - - endTestBlock(@"findExitPointOfRay"); - [pool drain]; -} - -#ifdef STAND_ALONE -void runTests() { -#else -void testMaths() { -#endif - startTestBlock(@"maths"); - testRectAroundPoints(); - testRectAroundPointsWithPadding(); - testGoodAtan(); - testBezierInterpolate(); - testLineSegmentsIntersect(); - testLineSegmentIntersectsRect(); - testFindExitPointOfRay(); - testLineSegmentIntersectsBezier(); - endTestBlock(@"maths"); -} - -// vim:ft=objc:ts=4:sts=4:sw=4:noet diff --git a/tikzit/src/common/test/parser.m b/tikzit/src/common/test/parser.m deleted file mode 100644 index 3346acd..0000000 --- a/tikzit/src/common/test/parser.m +++ /dev/null @@ -1,86 +0,0 @@ -// -// parser.m -// TikZiT -// -// Copyright 2010 Aleks Kissinger. All rights reserved. -// -// -// This file is part of TikZiT. -// -// TikZiT is free software: you can redistribute it and/or modify -// it under the terms of the GNU General Public License as published by -// the Free Software Foundation, either version 3 of the License, or -// (at your option) any later version. -// -// TikZiT is distributed in the hope that it will be useful, -// but WITHOUT ANY WARRANTY; without even the implied warranty of -// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -// GNU General Public License for more details. -// -// You should have received a copy of the GNU General Public License -// along with TikZiT. If not, see <http://www.gnu.org/licenses/>. -// -#import "test/test.h" -#import "TikzGraphAssembler.h" - - -#ifdef STAND_ALONE -void runTests() { -#else -void testParser() { -#endif - NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init]; - startTestBlock(@"parser"); - - [TikzGraphAssembler setup]; - - NodeStyle *rn = [NodeStyle defaultNodeStyleWithName:@"rn"]; - NSArray *styles = [NSArray arrayWithObject:rn]; - - NSString *tikz = - @"\\begin{tikzpicture}[dotpic]" - @" \\begin{pgfonlayer}{foo}" //ignored - @" \\node [style=rn] (0) at (-2,3.4) {stuff{$\\alpha$ in here}};" - @" \\node (b) at (1,1) {};" - @" \\end{pgfonlayer}" //ignored - @" \\draw [bend right=20] (0) to node[tick]{-} (b.center);" - @"\\end{tikzpicture}"; - - TikzGraphAssembler *ga = [[TikzGraphAssembler alloc] init]; - TEST(@"Parsing TikZ", [ga parseTikz:tikz]); - - Graph *g = [ga graph]; - TEST(@"Graph is non-nil", g != nil); - TEST(@"Graph has correct number of nodes", [[g nodes] count]==2); - TEST(@"Graph has correct number of edges", [[g edges] count]==1); - - NSEnumerator *en = [[g nodes] objectEnumerator]; - Node *n; - Node *n1, *n2; - while ((n=[en nextObject])) { - [n attachStyleFromTable:styles]; - if ([n style] == rn) n1 = n; - else if ([n style] == nil) n2 = n; - } - - TEST(@"Styles attached correctly", n1!=nil && n2!=nil); - - TEST(@"Nodes labeled correctly", - [[n1 label] isEqualToString:@"stuff{$\\alpha$ in here}"] && - [[n2 label] isEqualToString:@""] - ); - - Edge *e1 = [[[g edges] objectEnumerator] nextObject]; - - TEST(@"Edge has edge node", [e1 edgeNode]!=nil); - TEST(@"Edge node labeled correctly", [[[e1 edgeNode] label] isEqualToString:@"-"]); -// NSString *sty = [[[[[e1 edgeNode] data] atoms] objectEnumerator] nextObject]; -// TEST(@"Edge node styled correctly", sty!=nil && [sty isEqualToString:@"tick"]); - - PUTS(@"Source anchor: %@",[e1 sourceAnchor]); - PUTS(@"Target anchor: %@",[e1 targetAnchor]); - - endTestBlock(@"parser"); - - [pool drain]; -} diff --git a/tikzit/src/common/test/test.h b/tikzit/src/common/test/test.h deleted file mode 100644 index 59dcdd4..0000000 --- a/tikzit/src/common/test/test.h +++ /dev/null @@ -1,57 +0,0 @@ -// -// test.h -// TikZiT -// -// Copyright 2010 Aleks Kissinger. All rights reserved. -// -// -// This file is part of TikZiT. -// -// TikZiT is free software: you can redistribute it and/or modify -// it under the terms of the GNU General Public License as published by -// the Free Software Foundation, either version 3 of the License, or -// (at your option) any later version. -// -// TikZiT is distributed in the hope that it will be useful, -// but WITHOUT ANY WARRANTY; without even the implied warranty of -// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -// GNU General Public License for more details. -// -// You should have received a copy of the GNU General Public License -// along with TikZiT. If not, see <http://www.gnu.org/licenses/>. -// -#import <Foundation/Foundation.h> - -@interface Allocator : NSObject -{} -@end - -BOOL fuzzyCompare (float f1, float f2); -BOOL fuzzyComparePoints (NSPoint p1, NSPoint p2); - -void setColorEnabled(BOOL b); - -void pass(NSString *msg); -void fail(NSString *msg); -void TEST(NSString *msg, BOOL test); -void assertRectsEqual (NSString *msg, NSRect val, NSRect exp); -void assertPointsEqual (NSString *msg, NSPoint val, NSPoint exp); -void assertFloatsEqual (NSString *msg, float val, float exp); - -void startTests(); -void endTests(); - -void startTestBlock(NSString *name); -void endTestBlock(NSString *name); - -#define PUTS(fmt, ...) { \ - NSString *_str = [[NSString alloc] initWithFormat:fmt, ##__VA_ARGS__]; \ - printf("%s\n", [_str UTF8String]); \ - [_str release]; } - -#define failFmt(fmt, ...) { \ - NSString *_fstr = [[NSString alloc] initWithFormat:fmt, ##__VA_ARGS__]; \ - fail(_fstr); \ - [_fstr release]; } - -// vim:ft=objc:ts=4:sts=4:sw=4:noet diff --git a/tikzit/src/common/test/test.m b/tikzit/src/common/test/test.m deleted file mode 100644 index 9afcd67..0000000 --- a/tikzit/src/common/test/test.m +++ /dev/null @@ -1,175 +0,0 @@ -// -// test.m -// TikZiT -// -// Copyright 2010 Aleks Kissinger. All rights reserved. -// -// -// This file is part of TikZiT. -// -// TikZiT is free software: you can redistribute it and/or modify -// it under the terms of the GNU General Public License as published by -// the Free Software Foundation, either version 3 of the License, or -// (at your option) any later version. -// -// TikZiT is distributed in the hope that it will be useful, -// but WITHOUT ANY WARRANTY; without even the implied warranty of -// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -// GNU General Public License for more details. -// -// You should have received a copy of the GNU General Public License -// along with TikZiT. If not, see <http://www.gnu.org/licenses/>. -// -#import "test/test.h" - -static int PASSES; -static int FAILS; - -static int ALLOC_INSTANCES = 0; - -static BOOL colorEnabled = YES; -static int depth = 0; - -static NSString *RED, *GREEN, *BLUE, *OFF; - -static NSString *indents[6] = - {@"", @" ", @" ", @" ", - @" ", @" "}; - -#define INDENT ((depth >= 6) ? indents[5] : indents[depth]) - - -@implementation Allocator - -+ (id)alloc { - ++ALLOC_INSTANCES; - return [super alloc]; -} - -- (void)dealloc { - --ALLOC_INSTANCES; - [super dealloc]; -} - -+ (Allocator*)allocator { - return [[[Allocator alloc] init] autorelease]; -} - -@end - -BOOL fuzzyCompare(float f1, float f2) { - return (ABS(f1 - f2) <= 0.00001f * MAX(1.0f,MIN(ABS(f1), ABS(f2)))); -} - -BOOL fuzzyComparePoints (NSPoint p1, NSPoint p2) { - return fuzzyCompare (p1.x, p2.x) && fuzzyCompare (p1.y, p2.y); -} - -void pass(NSString *msg) { - PUTS(@"%@[%@PASS%@] %@", INDENT, GREEN, OFF, msg); - ++PASSES; -} - -void fail(NSString *msg) { - PUTS(@"%@[%@FAIL%@] %@", INDENT, RED, OFF, msg); - ++FAILS; -} - -void TEST(NSString *msg, BOOL test) { - if (test) { - pass (msg); - } else { - fail (msg); - } -} - -void assertRectsEqual (NSString *msg, NSRect r1, NSRect r2) { - BOOL equal = fuzzyCompare (r1.origin.x, r2.origin.x) && - fuzzyCompare (r1.origin.y, r2.origin.y) && - fuzzyCompare (r1.size.width, r2.size.width) && - fuzzyCompare (r1.size.height, r2.size.height); - if (equal) { - pass (msg); - } else { - failFmt(@"%@ (expected (%f,%f:%fx%f) but got (%f,%f:%fx%f))", - msg, - r2.origin.x, r2.origin.y, r2.size.width, r2.size.height, - r1.origin.x, r1.origin.y, r1.size.width, r1.size.height); - } -} - -void assertPointsEqual (NSString *msg, NSPoint p1, NSPoint p2) { - BOOL equal = fuzzyCompare (p1.x, p2.x) && fuzzyCompare (p1.y, p2.y); - if (equal) { - pass (msg); - } else { - failFmt(@"%@ (expected (%f,%f) but got (%f,%f)", - msg, - p2.x, p2.y, - p1.x, p1.y); - } -} - -void assertFloatsEqual (NSString *msg, float f1, float f2) { - if (fuzzyCompare (f1, f2)) { - pass (msg); - } else { - failFmt(@"%@ (expected %f but got %f", msg, f2, f1); - } -} - -void startTests() { - PASSES = 0; - FAILS = 0; -} - -void endTests() { - PUTS(@"Done testing. %@%d%@ passed, %@%d%@ failed.", - GREEN, PASSES, OFF, - RED, FAILS, OFF); -} - -void startTestBlock(NSString *name) { - PUTS(@"%@Starting %@%@%@ tests.", INDENT, BLUE, name, OFF); - ++depth; -} - -void endTestBlock(NSString *name) { - --depth; - PUTS(@"%@Done with %@%@%@ tests.", INDENT, BLUE, name, OFF); -} - -void setColorEnabled(BOOL b) { - colorEnabled = b; - if (b) { - RED = @"\033[31;1m"; - GREEN = @"\033[32;1m"; - BLUE = @"\033[36;1m"; - OFF = @"\033[0m"; - } else { - RED = @""; - GREEN = @""; - BLUE = @""; - OFF = @""; - } -} - -#ifdef STAND_ALONE -void runTests(); - -int main() { - NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init]; - - setColorEnabled (NO); - startTests(); - - runTests(); - - endTests(); - - [pool drain]; - return 0; -} -#endif - -// vim:ft=objc:ts=4:sts=4:sw=4:noet diff --git a/tikzit/src/common/tikzlexer.lm b/tikzit/src/common/tikzlexer.lm deleted file mode 100644 index a0e5968..0000000 --- a/tikzit/src/common/tikzlexer.lm +++ /dev/null @@ -1,167 +0,0 @@ -%{ -/* - * Copyright 2010 Chris Heunen - * Copyright 2010-2013 Aleks Kissinger - * Copyright 2013 K. Johan Paulsson - * Copyright 2013 Alex Merry <dev@randomguy3.me.uk> - * - * 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 the Free Software Foundation; either version 2 of - * the License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see <http://www.gnu.org/licenses/>. - */ - -#import <Foundation/Foundation.h> -#import "tikzparser.h" - -#define YY_USER_ACTION \ - yylloc->first_line = yylloc->last_line; \ - yylloc->first_column = yylloc->last_column + 1; \ - yylloc->last_column = yylloc->first_column + yyleng - 1; - -%} - -%option reentrant bison-bridge bison-locations 8bit -%option nounput -%option yylineno -%option noyywrap -%option header-file="common/tikzlexer.h" - -%s props -%s xcoord -%s ycoord -%s noderef - -FLOAT \-?[0-9]*(\.[0-9]+)? - -%% - - /* whitespace is ignored, except for position counting; we don't - count formfeed and vtab as whitespace, because it's not obvious - how they should be dealt with and no-one actually uses them */ - - /* lex will take the longest-matching string */ -<INITIAL,xcoord,ycoord,props,noderef>\r\n|\r|\n { - yylloc->first_line += 1; - yylloc->last_line = yylloc->first_line; - yylloc->first_column = yylloc->last_column = 0; -} -<INITIAL,xcoord,ycoord,props,noderef>[\t ]+ { } - -\\begin\{tikzpicture\} { return BEGIN_TIKZPICTURE_CMD; } -\\end\{tikzpicture\} { return END_TIKZPICTURE_CMD; } -\\begin\{pgfonlayer\} { return BEGIN_PGFONLAYER_CMD; } -\\end\{pgfonlayer\} { return END_PGFONLAYER_CMD; } -\\draw { return DRAW_CMD; } -\\node { return NODE_CMD; } -\\path { return PATH_CMD; } -rectangle { return RECTANGLE; } -node { return NODE; } -at { return AT; } -to { return TO; } -; { return SEMICOLON; } - -\([ ]*{FLOAT}[ ]*,[ ]*{FLOAT}[ ]*\) { - yylloc->last_column = yylloc->first_column + 1; - yyless(1); - BEGIN(xcoord); -} -<xcoord>{FLOAT} { - yylval->pt.x=(float)strtod(yytext,NULL); - BEGIN(ycoord); -} -<ycoord>, { } -<ycoord>{FLOAT} { - yylval->pt.y=(float)strtod(yytext,NULL); -} -<ycoord>\) { - BEGIN(INITIAL); - return COORD; -} - - /* when we see "[", change parsing mode */ -\[ /*syntaxhlfix]*/ { - BEGIN(props); - return LEFTBRACKET; -} -<props>= { return EQUALS; } -<props>, { return COMMA; } - /* technically, it is possible to have newlines in the middle of - property names or values, but in practice this is unlikely and - screws up our line counting */ -<props>[^=,\{\] \t\n]([^=,\{\]\n]*[^=,\{\] \t\n])? { - yylval->nsstr=[NSString stringWithUTF8String:yytext]; - return PROPSTRING; -} -<props>\] { - BEGIN(INITIAL); - return RIGHTBRACKET; -} - -\( { - BEGIN(noderef); - return LEFTPARENTHESIS; -} -<noderef>\. { - return FULLSTOP; -} - /* we assume node names (and anchor names) never contain - newlines */ -<noderef>[^\.\{\)\n]+ { - yylval->nsstr=[NSString stringWithUTF8String:yytext]; - return REFSTRING; -} -<noderef>\) { - BEGIN(INITIAL); - return RIGHTPARENTHESIS; -} - -<INITIAL,props>\{ { - NSMutableString *buf = [NSMutableString string]; - unsigned int brace_depth = 1; - unsigned int escape = 0; - while (1) { - char c = input(yyscanner); - // eof reached before closing brace - if (c == '\0' || c == EOF) { - return UNCLOSED_DELIM_STR; - } - - yylloc->last_column += 1; - yyleng += 1; - if (escape) { - escape = 0; - } else if (c == '\\') { - escape = 1; - } else if (c == '{') { - brace_depth++; - } else if (c == '}') { - brace_depth--; - if (brace_depth == 0) break; - } else if (c == '\n') { - yylloc->last_line += 1; - yylloc->last_column = 0; - } - [buf appendFormat:@"%c", c]; - } - - yylval->nsstr = buf; - return DELIMITEDSTRING; -} - -\\begin { return UNKNOWN_BEGIN_CMD; } -\\end { return UNKNOWN_END_CMD; } -\\[a-zA-Z0-9]+ { return UNKNOWN_CMD; } -[a-zA-Z0-9]+ { return UNKNOWN_STR; } -<INITIAL,xcoord,ycoord,props,noderef>. { return UNKNOWN_STR; } - - /* vi:ft=lex:noet:ts=4:sts=4:sw=4: - */ diff --git a/tikzit/src/common/tikzparser.ym b/tikzit/src/common/tikzparser.ym deleted file mode 100644 index 794b06d..0000000 --- a/tikzit/src/common/tikzparser.ym +++ /dev/null @@ -1,210 +0,0 @@ -%{ -/* - * Copyright 2010 Chris Heunen - * Copyright 2010-2013 Aleks Kissinger - * Copyright 2013 K. Johan Paulsson - * Copyright 2013 Alex Merry <dev@randomguy3.me.uk> - * - * 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 the Free Software Foundation; either version 2 of - * the License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see <http://www.gnu.org/licenses/>. - */ - -#import "Edge.h" - -%} - -%code requires { -#import <Foundation/Foundation.h> -@class TikzGraphAssembler; -@class GraphElementData; -@class GraphElementProperty; -@class Node; -struct noderef { - Node *node; - NSString *anchor; -}; -} - -%defines "common/tikzparser.h" -%pure-parser -%locations -%parse-param {TikzGraphAssembler *assembler} -%error-verbose - -%union { - NSPoint pt; - NSString *nsstr; - GraphElementProperty *prop; - GraphElementData *data; - Node *node; - struct noderef noderef; -}; - -%{ -#import "TikzGraphAssembler+Parser.h" -#import "GraphElementData.h" -#import "GraphElementProperty.h" -#import "Node.h" -#import "tikzlexer.h" -#define YYLEX_PARAM [assembler scanner] -void yyerror(YYLTYPE *yylloc, TikzGraphAssembler *assembler, const char *str) { - [assembler reportError:str atLocation:yylloc]; -} -%} - -%initial-action { - yylloc.first_column = yylloc.last_column = 0; -}; - - -%token BEGIN_TIKZPICTURE_CMD "\\begin{tikzpicture}" -%token END_TIKZPICTURE_CMD "\\end{tikzpicture}" -%token BEGIN_PGFONLAYER_CMD "\\begin{pgfonlayer}" -%token END_PGFONLAYER_CMD "\\end{pgfonlayer}" -%token DRAW_CMD "\\draw" -%token NODE_CMD "\\node" -%token PATH_CMD "\\path" -%token RECTANGLE "rectangle" -%token NODE "node" -%token AT "at" -%token TO "to" -%token SEMICOLON ";" -%token COMMA "," - -%token LEFTPARENTHESIS "(" -%token RIGHTPARENTHESIS ")" -%token LEFTBRACKET "[" -%token RIGHTBRACKET "]" -%token FULLSTOP "." -%token EQUALS "=" -%token <pt> COORD "co-ordinate" -%token <nsstr> PROPSTRING "key/value string" -%token <nsstr> REFSTRING "string" -%token <nsstr> DELIMITEDSTRING "{-delimited string" - -%token UNKNOWN_BEGIN_CMD "unknown \\begin command" -%token UNKNOWN_END_CMD "unknown \\end command" -%token UNKNOWN_CMD "unknown latex command" -%token UNKNOWN_STR "unknown string" -%token UNCLOSED_DELIM_STR "unclosed {-delimited string" - -%type<nsstr> nodename -%type<nsstr> optanchor -%type<nsstr> val -%type<prop> property -%type<data> extraproperties -%type<data> properties -%type<data> optproperties -%type<node> optedgenode -%type<noderef> noderef -%type<noderef> optnoderef - -%% - -tikzpicture: "\\begin{tikzpicture}" optproperties tikzcmds "\\end{tikzpicture}" - { - if ($2) { - [[assembler graph] setData:$2]; - } - }; -tikzcmds: tikzcmds tikzcmd | ; -tikzcmd: node | edge | boundingbox | ignore; - -ignore: "\\begin{pgfonlayer}" DELIMITEDSTRING | "\\end{pgfonlayer}"; - -optproperties: - "[" properties "]" - { $$ = $2; } - | { $$ = nil; }; -properties: property extraproperties - { - [$2 addObject:$1]; - $$ = $2; - }; -extraproperties: - "," property extraproperties - { - [$3 addObject:$2]; - $$ = $3; - } - | { $$ = [GraphElementData data]; }; -property: - val "=" val - { $$ = [GraphElementProperty property:$1 withValue:$3]; } - | val - { $$ = [GraphElementProperty atom:$1]; }; -val: PROPSTRING { $$ = $1; } | DELIMITEDSTRING { $$ = $1; }; - -nodename: "(" REFSTRING ")" { $$ = $2; }; -node: "\\node" optproperties nodename "at" COORD DELIMITEDSTRING ";" - { - Node *node = [[Node alloc] init]; - if ($2) - [node setData:$2]; - [node setName:$3]; - [node setPoint:$5]; - [node setLabel:$6]; - [assembler addNodeToMap:node]; - [[assembler graph] addNode:node]; - [node release]; - }; - -optanchor: { $$ = nil; } | "." REFSTRING { $$ = $2; }; -noderef: "(" REFSTRING optanchor ")" - { - $$.node = [assembler nodeWithName:$2]; - $$.anchor = $3; - }; -optnoderef: - noderef { $$ = $1; } - | "(" ")" { $$.node = nil; $$.anchor = nil; } -optedgenode: - { $$ = nil; } - | "node" optproperties DELIMITEDSTRING - { - $$ = [Node node]; - if ($2) - [$$ setData:$2]; - [$$ setLabel:$3]; - } -edge: "\\draw" optproperties noderef "to" optedgenode optnoderef ";" - { - Edge *edge = [[Edge alloc] init]; - if ($2) - [edge setData:$2]; - [edge setSource:$3.node]; - [edge setSourceAnchor:$3.anchor]; - [edge setEdgeNode:$5]; - if ($6.node) { - [edge setTarget:$6.node]; - [edge setTargetAnchor:$6.anchor]; - } else { - [edge setTarget:$3.node]; - [edge setTargetAnchor:$3.anchor]; - } - [edge setAttributesFromData]; - [[assembler graph] addEdge:edge]; - [edge release]; - }; - -ignoreprop: val | val "=" val; -ignoreprops: ignoreprop ignoreprops | ; -optignoreprops: "[" ignoreprops "]"; -boundingbox: - "\\path" optignoreprops COORD "rectangle" COORD ";" - { - [[assembler graph] setBoundingBox:NSRectAroundPoints($3, $5)]; - }; - -/* vi:ft=yacc:noet:ts=4:sts=4:sw=4 -*/ diff --git a/tikzit/src/common/util.h b/tikzit/src/common/util.h deleted file mode 100644 index f527820..0000000 --- a/tikzit/src/common/util.h +++ /dev/null @@ -1,194 +0,0 @@ -// -// util.h -// TikZiT -// -// Copyright 2010 Aleks Kissinger. All rights reserved. -// -// -// This file is part of TikZiT. -// -// TikZiT is free software: you can redistribute it and/or modify -// it under the terms of the GNU General Public License as published by -// the Free Software Foundation, either version 3 of the License, or -// (at your option) any later version. -// -// TikZiT is distributed in the hope that it will be useful, -// but WITHOUT ANY WARRANTY; without even the implied warranty of -// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -// GNU General Public License for more details. -// - -#import <Foundation/Foundation.h> - -#include <math.h> - -#ifndef M_PI -#define M_PI 3.141592654 -#endif - -#ifndef MAX -#define MAX(a,b) (((a) > (b)) ? (a) : (b)) -#endif - -#ifndef MIN -#define MIN(a,b) (((a) < (b)) ? (a) : (b)) -#endif - -/*! - @brief Compute a bounding rectangle for two given points. - @param p1 a point. - @param p2 another point. - @result A bounding rectangle for p1 and p2. - */ -NSRect NSRectAroundPoints(NSPoint p1, NSPoint p2); - -/*! - @brief Compute a bounding rectangle for two given points. - @param rect the base rectangle - @param the point to ensure is included - @result A rectangle containing rect and p - */ -NSRect NSRectWithPoint(NSRect rect, NSPoint p); - -/*! - @brief Compute a bounding rectangle for two given points with a given padding. - @param p1 a point. - @param p2 another point. - @param padding a padding. - @result A bounding rectangle for p1 and p2 with padding. - */ -NSRect NSRectAroundPointsWithPadding(NSPoint p1, NSPoint p2, float padding); - -/*! - @brief Compute a bounding rectangle for four given points. - @result A bounding rectangle for p1, p2, p3 and p4. - */ -NSRect NSRectAround4Points(NSPoint p1, NSPoint p2, NSPoint p3, NSPoint p4); - -/*! - @brief Compute a bounding rectangle for four given points. - @param padding the amount to pad the rectangle - @result A bounding rectangle for p1, p2, p3 and p4 with padding - */ -NSRect NSRectAround4PointsWithPadding(NSPoint p1, NSPoint p2, NSPoint p3, NSPoint p4, float padding); - -/*! - @brief Find the distance between two points - @param p1 The first point - @param p2 The second point - @result The distance between p1 and p2 - */ -float NSDistanceBetweenPoints(NSPoint p1, NSPoint p2); - -/*! - @brief Compute the 'real' arctan for two points. Always succeeds and gives a good angle, - regardless of sign, zeroes, etc. - @param dx the x distance between points. - @param dy the y distance between points. - @result An angle in radians. - */ -float good_atan(float dx, float dy); - -/*! - @brief Interpolate along a bezier curve to the given distance. To find the x coord, - use the relavant x coordinates for c0-c3, and for y use the y's. - @param dist a distance from 0 to 1 spanning the whole curve. - @param c0 the x (resp. y) coordinate of the start point. - @param c1 the x (resp. y) coordinate of the first control point. - @param c2 the x (resp. y) coordinate of the second control point. - @param c3 the x (resp. y) coordinate of the end point. - @result The x (resp. y) coordinate of the point at 'dist'. - */ -float bezierInterpolate (float dist, float c0, float c1, float c2, float c3); - -/*! - @brief Interpolate along a bezier curve to the given distance. - @param dist a distance from 0 to 1 spanning the whole curve. - @param c0 the x start point. - @param c1 the x first control point. - @param c2 the x second control point. - @param c3 the x end point. - @result The point at 'dist'. - */ -NSPoint bezierInterpolateFull (float dist, NSPoint c0, NSPoint c1, NSPoint c2, NSPoint c3); - -/*! - * @brief Find whether two line segments intersect - * @param l1start The starting point of line segment 1 - * @param l1end The ending point of line segment 1 - * @param l2start The starting point of line segment 2 - * @param l2end The ending point of line segment 2 - * @param result A location to store the intersection point - * @result YES if they intersect, NO if they do not - */ -BOOL lineSegmentsIntersect (NSPoint l1start, NSPoint l1end, NSPoint l2start, NSPoint l2end, NSPoint *result); - -/*! - * @brief Find whether a line segment intersects a bezier curve - * @detail Always finds the intersection furthest along the line segment - * @param lstart The starting point of the line segment - * @param lend The ending point of the line segment - * @param c0 The starting point of the bezier curve - * @param c1 The first control point of the bezier curve - * @param c2 The second control point of the bezier curve - * @param c3 The ending point of the bezier curve - * @param result A location to store the intersection point - * @result YES if they intersect, NO if they do not - */ -BOOL lineSegmentIntersectsBezier (NSPoint lstart, NSPoint lend, NSPoint c0, NSPoint c1, NSPoint c2, NSPoint c3, NSPoint *result); - -/*! - * @brief Find whether a line segment enters a rectangle - * @param lineStart The starting point of the line segment - * @param lineEnd The ending point of the line segment - * @param rect The rectangle - * @result YES if they intersect, NO if they do not - */ -BOOL lineSegmentIntersectsRect (NSPoint lineStart, NSPoint lineEnd, NSRect rect); - -/*! - * @brief Find where a ray exits a rectangle - * @param rayStart The starting point of the ray; must be contained in rect - * @param angle_rads The angle of the ray, in radians - * @param rect The rectangle - * @result The point at which the ray leaves the rect - */ -NSPoint findExitPointOfRay (NSPoint rayStart, float angle_rads, NSRect rect); - -/*! - @brief Round val to nearest stepSize - @param stepSize the courseness - @param val a value to round - */ -float roundToNearest(float stepSize, float val); - -/*! - @brief Convert radians into degrees - */ -float radiansToDegrees(float radians); - -/*! - @brief Convert degrees into radians - */ -float degreesToRadians(float degrees); - -/*! - @brief Normalises an angle (in degrees) to fall between -179 and 180 - */ -int normaliseAngleDeg (int degrees); - -/*! - @brief Normalises an angle (in radians) to fall in the range (-pi,pi] - */ -float normaliseAngleRad (float rads); - -/*! - @brief Express a byte as alpha-only hex, with digits (0..16) -> (a..jA..F) - @param sh A number 0-255 - @result A string 'aa'-'FF' - */ -NSString *alphaHex(unsigned short sh); - -const char *find_start_of_nth_line (const char * string, int line); - -// vi:ft=objc:noet:ts=4:sts=4:sw=4 diff --git a/tikzit/src/common/util.m b/tikzit/src/common/util.m deleted file mode 100644 index aa21a67..0000000 --- a/tikzit/src/common/util.m +++ /dev/null @@ -1,380 +0,0 @@ -// -// util.m -// TikZiT -// -// Copyright 2010 Aleks Kissinger. All rights reserved. -// -// -// This file is part of TikZiT. -// -// TikZiT is free software: you can redistribute it and/or modify -// it under the terms of the GNU General Public License as published by -// the Free Software Foundation, either version 3 of the License, or -// (at your option) any later version. -// -// TikZiT is distributed in the hope that it will be useful, -// but WITHOUT ANY WARRANTY; without even the implied warranty of -// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -// GNU General Public License for more details. -// - -#import "util.h" -#import "math.h" - -static BOOL fuzzyCompare(float f1, float f2) { - return (ABS(f1 - f2) <= 0.00001f * MIN(ABS(f1), ABS(f2))); -} - -NSRect NSRectWithPoint(NSRect rect, NSPoint p) { - CGFloat minX = NSMinX(rect); - CGFloat maxX = NSMaxX(rect); - CGFloat minY = NSMinY(rect); - CGFloat maxY = NSMaxY(rect); - if (p.x < minX) { - minX = p.x; - } else if (p.x > maxX) { - maxX = p.x; - } - if (p.y < minY) { - minY = p.y; - } else if (p.y > maxY) { - maxY = p.y; - } - return NSMakeRect(minX, minY, maxX - minX, maxY - minY); -} - -NSRect NSRectAroundPointsWithPadding(NSPoint p1, NSPoint p2, float padding) { - return NSMakeRect(MIN(p1.x,p2.x)-padding, - MIN(p1.y,p2.y)-padding, - ABS(p2.x-p1.x)+(2.0f*padding), - ABS(p2.y-p1.y)+(2.0f*padding)); -} - -NSRect NSRectAroundPoints(NSPoint p1, NSPoint p2) { - return NSRectAroundPointsWithPadding(p1, p2, 0.0f); -} - -NSRect NSRectAround4PointsWithPadding(NSPoint p1, NSPoint p2, NSPoint p3, NSPoint p4, float padding) { - float leftMost = MIN(p1.x, p2.x); - leftMost = MIN(leftMost, p3.x); - leftMost = MIN(leftMost, p4.x); - float rightMost = MAX(p1.x, p2.x); - rightMost = MAX(rightMost, p3.x); - rightMost = MAX(rightMost, p4.x); - float topMost = MIN(p1.y, p2.y); - topMost = MIN(topMost, p3.y); - topMost = MIN(topMost, p4.y); - float bottomMost = MAX(p1.y, p2.y); - bottomMost = MAX(bottomMost, p3.y); - bottomMost = MAX(bottomMost, p4.y); - return NSMakeRect(leftMost-padding, - topMost-padding, - (rightMost - leftMost)+(2.0f*padding), - (bottomMost - topMost)+(2.0f*padding)); -} - -NSRect NSRectAround4Points(NSPoint p1, NSPoint p2, NSPoint p3, NSPoint p4) { - return NSRectAround4PointsWithPadding(p1, p2, p3, p4, 0.0f); -} - -float NSDistanceBetweenPoints(NSPoint p1, NSPoint p2) { - float dx = p2.x - p1.x; - float dy = p2.y - p1.y; - return sqrt(dx * dx + dy * dy); -} - -float good_atan(float dx, float dy) { - if (dx > 0) { - return atan(dy/dx); - } else if (dx < 0) { - return M_PI + atan(dy/dx); - } else { - if (dy > 0) return 0.5 * M_PI; - else if (dy < 0) return 1.5 * M_PI; - else return 0; - } -} - -// interpolate on a cubic bezier curve -float bezierInterpolate(float dist, float c0, float c1, float c2, float c3) { - float distp = 1 - dist; - return (distp*distp*distp) * c0 + - 3 * (distp*distp) * dist * c1 + - 3 * (dist*dist) * distp * c2 + - (dist*dist*dist) * c3; -} - -NSPoint bezierInterpolateFull (float dist, NSPoint c0, NSPoint c1, NSPoint c2, NSPoint c3) { - return NSMakePoint (bezierInterpolate (dist, c0.x, c1.x, c2.x, c3.x), - bezierInterpolate (dist, c0.y, c1.y, c2.y, c3.y)); -} - -static void lineCoeffsFromPoints(NSPoint p1, NSPoint p2, float *A, float *B, float *C) { - *A = p2.y - p1.y; - *B = p1.x - p2.x; - *C = (*A) * p1.x + (*B) * p1.y; -} - -static void lineCoeffsFromPointAndAngle(NSPoint p, float angle, float *A, float *B, float *C) { - *A = sin (angle); - *B = -cos (angle); - *C = (*A) * p.x + (*B) * p.y; -} - -static BOOL lineSegmentContainsPoint(NSPoint l1, NSPoint l2, float x, float y) { - float minX = MIN(l1.x, l2.x); - float maxX = MAX(l1.x, l2.x); - float minY = MIN(l1.y, l2.y); - float maxY = MAX(l1.y, l2.y); - return (x >= minX || fuzzyCompare (x, minX)) && - (x <= maxX || fuzzyCompare (x, maxX)) && - (y >= minY || fuzzyCompare (y, minY)) && - (y <= maxY || fuzzyCompare (y, maxY)); -} - -BOOL lineSegmentsIntersect(NSPoint l1start, NSPoint l1end, NSPoint l2start, NSPoint l2end, NSPoint *result) { - // Ax + By = C - float A1, B1, C1; - lineCoeffsFromPoints(l1start, l1end, &A1, &B1, &C1); - float A2, B2, C2; - lineCoeffsFromPoints(l2start, l2end, &A2, &B2, &C2); - - float det = A1*B2 - A2*B1; - if (det == 0.0f) { - // parallel - return NO; - } else { - float x = (B2*C1 - B1*C2)/det; - float y = (A1*C2 - A2*C1)/det; - - if (lineSegmentContainsPoint(l1start, l1end, x, y) && - lineSegmentContainsPoint(l2start, l2end, x, y)) { - if (result) { - (*result).x = x; - (*result).y = y; - } - return YES; - } - } - return NO; -} - -BOOL lineSegmentIntersectsBezier (NSPoint lstart, NSPoint lend, NSPoint c0, NSPoint c1, NSPoint c2, NSPoint c3, NSPoint *result) { - NSRect curveBounds = NSRectAround4Points(c0, c1, c2, c3); - if (!lineSegmentIntersectsRect(lstart, lend, curveBounds)) - return NO; - - const int divisions = 20; - const float chunkSize = 1.0f/(float)divisions; - float chunkStart = 0.0f; - BOOL found = NO; - - for (int i = 0; i < divisions; ++i) { - float chunkEnd = chunkStart + chunkSize; - - NSPoint p1 = bezierInterpolateFull (chunkStart, c0, c1, c2, c3); - NSPoint p2 = bezierInterpolateFull (chunkEnd, c0, c1, c2, c3); - - NSPoint p; - if (lineSegmentsIntersect (lstart, lend, p1, p2, &p)) { - lstart = p; - found = YES; - } - - chunkStart = chunkEnd; - } - if (found && result) { - *result = lstart; - } - return found; -} - -BOOL lineSegmentIntersectsRect(NSPoint lineStart, NSPoint lineEnd, NSRect rect) { - const float rectMaxX = NSMaxX(rect); - const float rectMinX = NSMinX(rect); - const float rectMaxY = NSMaxY(rect); - const float rectMinY = NSMinY(rect); - - // check if the segment is entirely to one side of the rect - if (lineStart.x > rectMaxX && lineEnd.x > rectMaxX) { - return NO; - } - if (lineStart.x < rectMinX && lineEnd.x < rectMinX) { - return NO; - } - if (lineStart.y > rectMaxY && lineEnd.y > rectMaxY) { - return NO; - } - if (lineStart.y < rectMinY && lineEnd.y < rectMinY) { - return NO; - } - - // Now check whether the (infinite) line intersects the rect - // (if it does, so does the segment, due to above checks) - - // Ax + By = C - float A, B, C; - lineCoeffsFromPoints(lineStart, lineEnd, &A, &B, &C); - - const float tlVal = A * rectMinX + B * rectMaxY - C; - const float trVal = A * rectMaxX + B * rectMaxY - C; - const float blVal = A * rectMinX + B * rectMinY - C; - const float brVal = A * rectMaxX + B * rectMinY - C; - - if (tlVal < 0 && trVal < 0 && blVal < 0 && brVal < 0) { - // rect below line - return NO; - } - if (tlVal > 0 && trVal > 0 && blVal > 0 && brVal > 0) { - // rect above line - return NO; - } - - return YES; -} - -NSPoint findExitPointOfRay (NSPoint p, float angle_rads, NSRect rect) { - const float rectMinX = NSMinX (rect); - const float rectMaxX = NSMaxX (rect); - const float rectMinY = NSMinY (rect); - const float rectMaxY = NSMaxY (rect); - - const float angle = normaliseAngleRad (angle_rads); - - // special case the edges - if (p.y == rectMaxY && angle > 0 && angle < M_PI) { - // along the top of the box - return p; - } - if (p.y == rectMinY && angle < 0 && angle > -M_PI) { - // along the bottom of the box - return p; - } - if (p.x == rectMaxX && angle > -M_PI/2.0f && angle < M_PI/2.0f) { - // along the right of the box - return p; - } - if (p.x == rectMinX && (angle > M_PI/2.0f || angle < -M_PI/2.0f)) { - // along the left of the box - return p; - } - - float A1, B1, C1; - lineCoeffsFromPointAndAngle(p, angle, &A1, &B1, &C1); - //NSLog(@"Ray is %fx + %fy = %f", A1, B1, C1); - - const float tlAngle = normaliseAngleRad (good_atan (rectMinX - p.x, rectMaxY - p.y)); - const float trAngle = normaliseAngleRad (good_atan (rectMaxX - p.x, rectMaxY - p.y)); - if (angle <= tlAngle && angle >= trAngle) { - // exit top - float A2, B2, C2; - lineCoeffsFromPoints(NSMakePoint (rectMinX, rectMaxY), - NSMakePoint (rectMaxX, rectMaxY), - &A2, &B2, &C2); - float det = A1*B2 - A2*B1; - NSCAssert(det != 0.0f, @"Parallel lines?"); - NSPoint intersect = NSMakePoint ((B2*C1 - B1*C2)/det, - (A1*C2 - A2*C1)/det); - return intersect; - } - - const float brAngle = normaliseAngleRad (good_atan (rectMaxX - p.x, rectMinY - p.y)); - if (angle <= trAngle && angle >= brAngle) { - // exit right - float A2, B2, C2; - lineCoeffsFromPoints(NSMakePoint (rectMaxX, rectMaxY), - NSMakePoint (rectMaxX, rectMinY), - &A2, &B2, &C2); - //NSLog(@"Edge is %fx + %fy = %f", A2, B2, C2); - float det = A1*B2 - A2*B1; - NSCAssert(det != 0.0f, @"Parallel lines?"); - NSPoint intersect = NSMakePoint ((B2*C1 - B1*C2)/det, - (A1*C2 - A2*C1)/det); - return intersect; - } - - const float blAngle = normaliseAngleRad (good_atan (rectMinX - p.x, rectMinY - p.y)); - if (angle <= brAngle && angle >= blAngle) { - // exit bottom - float A2, B2, C2; - lineCoeffsFromPoints(NSMakePoint (rectMaxX, rectMinY), - NSMakePoint (rectMinX, rectMinY), - &A2, &B2, &C2); - float det = A1*B2 - A2*B1; - NSCAssert(det != 0.0f, @"Parallel lines?"); - NSPoint intersect = NSMakePoint ((B2*C1 - B1*C2)/det, - (A1*C2 - A2*C1)/det); - return intersect; - } else { - // exit left - float A2, B2, C2; - lineCoeffsFromPoints(NSMakePoint (rectMinX, rectMaxY), - NSMakePoint (rectMinX, rectMinY), - &A2, &B2, &C2); - float det = A1*B2 - A2*B1; - NSCAssert(det != 0.0f, @"Parallel lines?"); - NSPoint intersect = NSMakePoint ((B2*C1 - B1*C2)/det, - (A1*C2 - A2*C1)/det); - return intersect; - } -} - -float roundToNearest(float stepSize, float val) { - if (stepSize==0.0f) return val; - else return round(val/stepSize)*stepSize; -} - -float radiansToDegrees (float radians) { - return (radians * 180.0f) / M_PI; -} - -float degreesToRadians(float degrees) { - return (degrees * M_PI) / 180.0f; -} - -int normaliseAngleDeg (int degrees) { - while (degrees > 180) { - degrees -= 360; - } - while (degrees <= -180) { - degrees += 360; - } - return degrees; -} - -float normaliseAngleRad (float rads) { - while (rads > M_PI) { - rads -= 2 * M_PI; - } - while (rads <= -M_PI) { - rads += 2 * M_PI; - } - return rads; -} - -static char ahex[] = -{'a','b','c','d','e','f','g','h','i','j', - 'A','B','C','D','E','F'}; - -NSString *alphaHex(unsigned short sh) { - if (sh > 255) return @"!!"; - return [NSString stringWithFormat:@"%c%c", ahex[sh/16], ahex[sh%16]]; -} - -const char *find_start_of_nth_line (const char * string, int line) { - int l = 0; - const char *lineStart = string; - while (*lineStart && l < line) { - while (*lineStart && *lineStart != '\n') { - ++lineStart; - } - if (*lineStart) { - ++l; - ++lineStart; - } - } - return lineStart; -} - - -// vi:ft=objc:noet:ts=4:sts=4:sw=4 diff --git a/tikzit/src/gtk/Application.h b/tikzit/src/gtk/Application.h deleted file mode 100644 index 1b48a79..0000000 --- a/tikzit/src/gtk/Application.h +++ /dev/null @@ -1,155 +0,0 @@ -/* - * Copyright 2012 Alex Merry <dev@randomguy3.me.uk> - * - * 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 the Free Software Foundation; either version 2 of - * the License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see <http://www.gnu.org/licenses/>. - */ - -#import "TZFoundation.h" -#import "InputDelegate.h" - -@class Application; -@class Configuration; -@class ContextWindow; -@class Preambles; -@class PreambleEditor; -@class PreviewWindow; -@class SettingsDialog; -@class StyleManager; -@class TikzDocument; -@class ToolBox; -@class Window; -@protocol Tool; - -extern Application* app; - -/** - * Manages the main application window - */ -@interface Application: NSObject { - // the main application configuration - Configuration *configFile; - // maintains the known (user-defined) styles - StyleManager *styleManager; - // maintains the preambles used for previews - Preambles *preambles; - // the last-accessed folders (for open and save dialogs) - NSString *lastOpenFolder; - NSString *lastSaveAsFolder; - - ToolBox *toolBox; - PreambleEditor *preambleWindow; - ContextWindow *contextWindow; - SettingsDialog *settingsDialog; - - // the open windows (array of Window*) - NSMutableArray *openWindows; - - // tools - id<Tool> activeTool; - NSArray *tools; -} - -/** - * The main application configuration file - */ -@property (readonly) Configuration *mainConfiguration; - -/** - * The app-wide style manager instance - */ -@property (readonly) StyleManager *styleManager; - -/** - * The app-wide preambles registry - */ -@property (readonly) Preambles *preambles; - -/** - * The tools - */ -@property (readonly) NSArray *tools; - -/** - * The currently-selected tool - */ -@property (assign) id<Tool> activeTool; - -/** - * The folder last actively chosen by a user for opening a file - */ -@property (copy) NSString *lastOpenFolder; - -/** - * The folder last actively chosen by a user for saving a file - */ -@property (copy) NSString *lastSaveAsFolder; - -/** - * The application instance. - */ -+ (Application*) app; - -/** - * Starts the application with a single window containing an empty file - */ -- (id) init; -/** - * Starts the application with the given files open - */ -- (id) initWithFiles:(NSArray*)files; - -/** - * Loads a new, empty document in a new window - */ -- (void) newWindow; -/** - * Loads an existing document from a file in a new window - * - * @param doc the document the new window should show - */ -- (void) newWindowWithDocument:(TikzDocument*)doc; -/** - * Quit the application, confirming with the user if there are - * changes to any open documents. - */ -- (void) quit; - -/** - * Show the dialog for editing preambles. - */ -- (void) presentPreamblesEditor; -/** - * Show the context-aware window - */ -- (void) presentContextWindow; -/** - * Show the settings dialog. - */ -- (void) presentSettingsDialog; - -/** - * Save the application configuration to permanent storage - * - * Should be called just before the application exits - */ -- (void) saveConfiguration; - -/** - * @result YES if key event was processed, NO otherwise - */ -- (BOOL) activateToolForKey:(unsigned int)keyVal withMask:(InputMask)mask; - -@end - -// vim:ft=objc:ts=8:et:sts=4:sw=4 diff --git a/tikzit/src/gtk/Application.m b/tikzit/src/gtk/Application.m deleted file mode 100644 index e9935bd..0000000 --- a/tikzit/src/gtk/Application.m +++ /dev/null @@ -1,377 +0,0 @@ -/* - * Copyright 2011-2012 Alex Merry <dev@randomguy3.me.uk> - * - * 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 the Free Software Foundation; either version 2 of - * the License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see <http://www.gnu.org/licenses/>. - */ - -#import "Application.h" - -#import "Configuration.h" -#import "EdgeStylesModel.h" -#import "NodeStylesModel.h" -#import "PreambleEditor.h" -#import "ContextWindow.h" -#import "Shape.h" -#import "SettingsDialog.h" -#import "StyleManager.h" -#import "StyleManager+Storage.h" -#import "SupportDir.h" -#import "TikzDocument.h" -#import "ToolBox.h" -#import "Window.h" - -#ifdef HAVE_POPPLER -#import "Preambles.h" -#import "Preambles+Storage.h" -#endif - -#import "BoundingBoxTool.h" -#import "CreateNodeTool.h" -#import "CreateEdgeTool.h" -#import "HandTool.h" -#import "SelectTool.h" - -// used for args to g_mkdir_with_parents -#import "stat.h" - -Application* app = nil; - -@interface Application (Notifications) -- (void) windowClosed:(NSNotification*)notification; -- (void) windowGainedFocus:(NSNotification*)notification; -- (void) selectedToolChanged:(NSNotification*)notification; -- (void) windowDocumentChanged:(NSNotification*)n; -@end - -@interface Application (Private) -- (void) setActiveWindow:(Window*)window; -@end - -@implementation Application - -@synthesize mainConfiguration=configFile; -@synthesize styleManager, preambles; -@synthesize lastOpenFolder, lastSaveAsFolder; -@synthesize tools; - -+ (Application*) app { - if (app == nil) { - [[[self alloc] init] release]; - } - return app; -} - -- (id) _initCommon { - if (app != nil) { - [self release]; - self = app; - return self; - } - self = [super init]; - - if (self) { - NSError *error = nil; - configFile = [[Configuration alloc] initWithName:@"tikzit" loadError:&error]; - if (error != nil) { - logError (error, @"WARNING: Failed to load configuration"); - } - - styleManager = [[StyleManager alloc] init]; - [styleManager loadStylesUsingConfigurationName:@"styles"]; // FIXME: error message? - NodeStylesModel *nsm = [NodeStylesModel modelWithStyleManager:styleManager]; - EdgeStylesModel *esm = [EdgeStylesModel modelWithStyleManager:styleManager]; - -#ifdef HAVE_POPPLER - NSString *preamblesDir = [[SupportDir userSupportDir] stringByAppendingPathComponent:@"preambles"]; - preambles = [[Preambles alloc] initFromDirectory:preamblesDir]; // FIXME: error message? - [preambles setStyleManager:styleManager]; - NSString *selectedPreamble = [configFile stringEntry:@"selectedPreamble" inGroup:@"Preambles"]; - if (selectedPreamble != nil) { - [preambles setSelectedPreambleName:selectedPreamble]; - } -#endif - - lastOpenFolder = [[configFile stringEntry:@"lastOpenFolder" inGroup:@"Paths"] retain]; - if (lastOpenFolder == nil) - lastOpenFolder = [[configFile stringEntry:@"lastFolder" inGroup:@"Paths"] retain]; - lastSaveAsFolder = [[configFile stringEntry:@"lastSaveAsFolder" inGroup:@"Paths"] retain]; - if (lastSaveAsFolder == nil) - lastSaveAsFolder = [[configFile stringEntry:@"lastFolder" inGroup:@"Paths"] retain]; - - openWindows = [[NSMutableArray alloc] init]; - - tools = [[NSArray alloc] initWithObjects: - [SelectTool tool], - [CreateNodeTool toolWithNodeStylesModel:nsm], - [CreateEdgeTool toolWithEdgeStylesModel:esm], - [BoundingBoxTool tool], - [HandTool tool], - nil]; - activeTool = [tools objectAtIndex:0]; - for (id<Tool> tool in tools) { - [tool loadConfiguration:configFile]; - } - - toolBox = [[ToolBox alloc] initWithTools:tools]; - [toolBox loadConfiguration:configFile]; - [toolBox setSelectedTool:activeTool]; - [[NSNotificationCenter defaultCenter] - addObserver:self - selector:@selector(selectedToolChanged:) - name:@"ToolSelectionChanged" - object:toolBox]; - [toolBox show]; - - contextWindow = [[ContextWindow alloc] initWithNodeStylesModel:nsm - andEdgeStylesModel:esm]; - [contextWindow loadConfiguration:configFile]; - - app = [self retain]; - } - - return self; -} - -- (id) init { - self = [self _initCommon]; - - if (self) { - [self newWindow]; - } - - return self; -} - -- (id) initWithFiles:(NSArray*)files { - self = [self _initCommon]; - - if (self) { - int fileOpenCount = 0; - for (NSString *file in files) { - NSError *error = nil; - TikzDocument *doc = [TikzDocument documentFromFile:file styleManager:styleManager error:&error]; - if (doc != nil) { - [self newWindowWithDocument:doc]; - ++fileOpenCount; - } else { - logError(error, @"WARNING: failed to open file"); - } - } - if (fileOpenCount == 0) { - [self newWindow]; - } - } - - return self; -} - -- (void) dealloc { - [[NSNotificationCenter defaultCenter] removeObserver:self]; - - [configFile release]; - [styleManager release]; - [preambles release]; - [lastOpenFolder release]; - [lastSaveAsFolder release]; - [preambleWindow release]; - [settingsDialog release]; - [openWindows release]; - [tools release]; - [activeTool release]; - [toolBox release]; - [contextWindow release]; - - [super dealloc]; -} - -- (id<Tool>) activeTool { return activeTool; } -- (void) setActiveTool:(id<Tool>)tool { - if (activeTool == tool) - return; - - activeTool = tool; - [toolBox setSelectedTool:tool]; - for (Window* window in openWindows) { - [window setActiveTool:tool]; - } -} - -- (BOOL) activateToolForKey:(unsigned int)keyVal withMask:(InputMask)mask { - // FIXME: cache the accel info, rather than reparsing it every time? - for (id<Tool> tool in tools) { - guint toolKey = 0; - GdkModifierType toolMod = 0; - gtk_accelerator_parse ([[tool shortcut] UTF8String], &toolKey, &toolMod); - if (toolKey != 0 && toolKey == keyVal && (int)mask == (int)toolMod) { - [self setActiveTool:tool]; - return YES; - } - } - return NO; -} - -- (void) _addWindow:(Window*)window { - [window setActiveTool:activeTool]; - [openWindows addObject:window]; - [[NSNotificationCenter defaultCenter] addObserver:self - selector:@selector(windowClosed:) - name:@"WindowClosed" - object:window]; - [[NSNotificationCenter defaultCenter] addObserver:self - selector:@selector(windowGainedFocus:) - name:@"WindowGainedFocus" - object:window]; - if ([window hasFocus]) { - [self setActiveWindow:window]; - } -} - -- (void) newWindow { - [self _addWindow:[Window window]]; -} - -- (void) newWindowWithDocument:(TikzDocument*)doc { - [self _addWindow:[Window windowWithDocument:doc]]; -} - -- (void) quit { - NSMutableArray *unsavedDocs = [NSMutableArray arrayWithCapacity:[openWindows count]]; - for (Window *window in openWindows) { - TikzDocument *doc = [window document]; - if ([doc hasUnsavedChanges]) { - [unsavedDocs addObject:doc]; - } - } - if ([unsavedDocs count] > 0) { - // FIXME: show a dialog - return; - } - gtk_main_quit(); -} - -- (void) presentPreamblesEditor { -#ifdef HAVE_POPPLER - if (preambleWindow == nil) { - preambleWindow = [[PreambleEditor alloc] initWithPreambles:preambles]; - //[preambleWindow setParentWindow:mainWindow]; - } - [preambleWindow present]; -#endif -} - -- (void) presentContextWindow { - [contextWindow present]; -} - -- (void) presentSettingsDialog { - if (settingsDialog == nil) { - settingsDialog = [[SettingsDialog alloc] initWithConfiguration:configFile - andStyleManager:styleManager]; - //[settingsDialog setParentWindow:mainWindow]; - } - [settingsDialog present]; -} - -- (Configuration*) mainConfiguration { - return configFile; -} - -- (void) saveConfiguration { - NSError *error = nil; - -#ifdef HAVE_POPPLER - if (preambles != nil) { - NSString *preamblesDir = [[SupportDir userSupportDir] stringByAppendingPathComponent:@"preambles"]; - // NSFileManager is slightly dodgy on Windows - g_mkdir_with_parents ([preamblesDir UTF8String], S_IRUSR | S_IWUSR | S_IXUSR); - [preambles storeToDirectory:preamblesDir]; - [configFile setStringEntry:@"selectedPreamble" inGroup:@"Preambles" value:[preambles selectedPreambleName]]; - } -#endif - - [styleManager saveStylesUsingConfigurationName:@"styles"]; - - for (id<Tool> tool in tools) { - [tool saveConfiguration:configFile]; - } - [toolBox saveConfiguration:configFile]; - - [contextWindow saveConfiguration:configFile]; - - if (lastOpenFolder != nil) { - [configFile setStringEntry:@"lastOpenFolder" inGroup:@"Paths" value:lastOpenFolder]; - } - if (lastSaveAsFolder != nil) { - [configFile setStringEntry:@"lastSaveAsFolder" inGroup:@"Paths" value:lastSaveAsFolder]; - } - - if (![configFile writeToStoreWithError:&error]) { - logError (error, @"Could not write config file"); - } -} - -@end - -@implementation Application (Notifications) -- (void) windowClosed:(NSNotification*)notification { - Window *window = [notification object]; - [openWindows removeObjectIdenticalTo:window]; - [[NSNotificationCenter defaultCenter] removeObserver:self - name:nil - object:window]; - if ([openWindows count] == 0) { - gtk_main_quit(); - } else { - [self setActiveWindow:[openWindows objectAtIndex:0]]; - } -} - -- (void) windowGainedFocus:(NSNotification*)notification { - Window *window = [notification object]; - [self setActiveWindow:window]; -} - -- (void) selectedToolChanged:(NSNotification*)n { - id<Tool> tool = [[n userInfo] objectForKey:@"tool"]; - if (tool != nil) - [self setActiveTool:tool]; - else - NSLog(@"nil tool!"); -} - -- (void) windowDocumentChanged:(NSNotification*)n { - [contextWindow setDocument:[[n userInfo] objectForKey:@"document"]]; -} -@end - -@implementation Application (Private) -- (void) setActiveWindow:(Window*)window { - [[NSNotificationCenter defaultCenter] removeObserver:self - name:@"DocumentChanged" - object:nil]; - - [contextWindow setDocument:[window document]]; - - [contextWindow attachToWindow:window]; - [toolBox attachToWindow:window]; - - [[NSNotificationCenter defaultCenter] - addObserver:self - selector:@selector(windowDocumentChanged:) - name:@"DocumentChanged" - object:window]; -} -@end - -// vim:ft=objc:ts=8:et:sts=4:sw=4:foldmethod=marker diff --git a/tikzit/src/gtk/BoundingBoxTool.h b/tikzit/src/gtk/BoundingBoxTool.h deleted file mode 100644 index f6498b0..0000000 --- a/tikzit/src/gtk/BoundingBoxTool.h +++ /dev/null @@ -1,45 +0,0 @@ -/* - * Copyright 2012 Alex Merry <alex.merry@kdemail.net> - * - * 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 the Free Software Foundation; either version 2 of - * the License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see <http://www.gnu.org/licenses/>. - */ - -#import "TZFoundation.h" -#import "Tool.h" - -typedef enum { - NoHandle, - EastHandle, - SouthEastHandle, - SouthHandle, - SouthWestHandle, - WestHandle, - NorthWestHandle, - NorthHandle, - NorthEastHandle -} ResizeHandle; - -@interface BoundingBoxTool : NSObject <Tool> { - GraphRenderer *renderer; - NSPoint dragOrigin; - ResizeHandle currentResizeHandle; - BOOL drawingNewBox; -} - -+ (id) tool; -- (id) init; -@end - - -// vim:ft=objc:ts=8:et:sts=4:sw=4 diff --git a/tikzit/src/gtk/BoundingBoxTool.m b/tikzit/src/gtk/BoundingBoxTool.m deleted file mode 100644 index 483705e..0000000 --- a/tikzit/src/gtk/BoundingBoxTool.m +++ /dev/null @@ -1,353 +0,0 @@ -/* - * Copyright 2011-2012 Alex Merry <alex.merry@kdemail.net> - * - * 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 the Free Software Foundation; either version 2 of - * the License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see <http://www.gnu.org/licenses/>. - */ - -#import "BoundingBoxTool.h" - -#import "GraphRenderer.h" -#import "TikzDocument.h" -#import "tzstockitems.h" - -static const float handle_size = 8.0; -float sideHandleTop(NSRect bbox) { - return (NSMinY(bbox) + NSMaxY(bbox) - handle_size)/2.0f; -} -float tbHandleLeft(NSRect bbox) { - return (NSMinX(bbox) + NSMaxX(bbox) - handle_size)/2.0f; -} - -@interface BoundingBoxTool (Private) -- (NSRect) screenBoundingBox; -- (ResizeHandle) boundingBoxResizeHandleAt:(NSPoint)p; -- (NSRect) boundingBoxResizeHandleRect:(ResizeHandle)handle; -- (void) setResizeCursorForHandle:(ResizeHandle)handle; -@end - -@implementation BoundingBoxTool -- (NSString*) name { return @"Bounding Box"; } -- (const gchar*) stockId { return TIKZIT_STOCK_BOUNDING_BOX; } -- (NSString*) helpText { return @"Set the bounding box"; } -- (NSString*) shortcut { return @"b"; } - -+ (id) tool { - return [[[self alloc] init] autorelease]; -} - -- (id) init { - self = [super init]; - - if (self) { - currentResizeHandle = NoHandle; - } - - return self; -} - -- (void) dealloc { - [[NSNotificationCenter defaultCenter] removeObserver:self]; - - [renderer release]; - - [super dealloc]; -} - -- (GraphRenderer*) activeRenderer { return renderer; } -- (void) setActiveRenderer:(GraphRenderer*)r { - if (r == renderer) - return; - - [[renderer surface] setCursor:NormalCursor]; - - [r retain]; - [renderer release]; - renderer = r; -} - -- (GtkWidget*) configurationWidget { return NULL; } - -- (void) mousePressAt:(NSPoint)pos withButton:(MouseButton)button andMask:(InputMask)mask { - if (button != LeftButton) - return; - - dragOrigin = pos; - currentResizeHandle = [self boundingBoxResizeHandleAt:pos]; - [[renderer document] startChangeBoundingBox]; - if (currentResizeHandle == NoHandle) { - drawingNewBox = YES; - [[[renderer document] graph] setBoundingBox:NSZeroRect]; - } else { - drawingNewBox = NO; - } - [renderer invalidateGraph]; -} - -- (void) mouseMoveTo:(NSPoint)pos withButtons:(MouseButton)buttons andMask:(InputMask)mask { - if (!(buttons & LeftButton)) { - ResizeHandle handle = [self boundingBoxResizeHandleAt:pos]; - [self setResizeCursorForHandle:handle]; - return; - } - - Transformer *transformer = [renderer transformer]; - Grid *grid = [renderer grid]; - Graph *graph = [[renderer document] graph]; - - if (currentResizeHandle == NoHandle) { - NSRect bbox = NSRectAroundPoints( - [grid snapScreenPoint:dragOrigin], - [grid snapScreenPoint:pos] - ); - [graph setBoundingBox:[transformer rectFromScreen:bbox]]; - } else { - NSRect bbox = [transformer rectToScreen:[graph boundingBox]]; - NSPoint p2 = [grid snapScreenPoint:pos]; - - if (currentResizeHandle == NorthWestHandle || - currentResizeHandle == NorthHandle || - currentResizeHandle == NorthEastHandle) { - - float dy = p2.y - NSMinY(bbox); - if (dy < bbox.size.height) { - bbox.origin.y += dy; - bbox.size.height -= dy; - } else { - bbox.origin.y = NSMaxY(bbox); - bbox.size.height = 0; - } - - } else if (currentResizeHandle == SouthWestHandle || - currentResizeHandle == SouthHandle || - currentResizeHandle == SouthEastHandle) { - - float dy = p2.y - NSMaxY(bbox); - if (-dy < bbox.size.height) { - bbox.size.height += dy; - } else { - bbox.size.height = 0; - } - } - - if (currentResizeHandle == NorthWestHandle || - currentResizeHandle == WestHandle || - currentResizeHandle == SouthWestHandle) { - - float dx = p2.x - NSMinX(bbox); - if (dx < bbox.size.width) { - bbox.origin.x += dx; - bbox.size.width -= dx; - } else { - bbox.origin.x = NSMaxX(bbox); - bbox.size.width = 0; - } - - } else if (currentResizeHandle == NorthEastHandle || - currentResizeHandle == EastHandle || - currentResizeHandle == SouthEastHandle) { - - float dx = p2.x - NSMaxX(bbox); - if (-dx < bbox.size.width) { - bbox.size.width += dx; - } else { - bbox.size.width = 0; - } - } - [graph setBoundingBox:[transformer rectFromScreen:bbox]]; - } - [[renderer document] changeBoundingBoxCheckPoint]; - [renderer invalidateGraph]; -} - -- (void) mouseReleaseAt:(NSPoint)pos withButton:(MouseButton)button andMask:(InputMask)mask { - if (button != LeftButton) - return; - - [[renderer document] endChangeBoundingBox]; - drawingNewBox = NO; - [renderer invalidateGraph]; -} - -- (void) renderWithContext:(id<RenderContext>)context onSurface:(id<Surface>)surface { - if (!drawingNewBox && [[[renderer document] graph] hasBoundingBox]) { - [context saveState]; - - [context setAntialiasMode:AntialiasDisabled]; - [context setLineWidth:1.0]; - - [context startPath]; - [context rect:[self boundingBoxResizeHandleRect:EastHandle]]; - [context rect:[self boundingBoxResizeHandleRect:SouthEastHandle]]; - [context rect:[self boundingBoxResizeHandleRect:SouthHandle]]; - [context rect:[self boundingBoxResizeHandleRect:SouthWestHandle]]; - [context rect:[self boundingBoxResizeHandleRect:WestHandle]]; - [context rect:[self boundingBoxResizeHandleRect:NorthWestHandle]]; - [context rect:[self boundingBoxResizeHandleRect:NorthHandle]]; - [context rect:[self boundingBoxResizeHandleRect:NorthEastHandle]]; - [context strokePathWithColor:MakeSolidRColor (0.5, 0.5, 0.5)]; - - [context restoreState]; - } -} -- (void) loadConfiguration:(Configuration*)config {} -- (void) saveConfiguration:(Configuration*)config {} -@end - -@implementation BoundingBoxTool (Private) -- (NSRect) screenBoundingBox { - Transformer *transformer = [[renderer surface] transformer]; - Graph *graph = [[renderer document] graph]; - return [transformer rectToScreen:[graph boundingBox]]; -} - -- (ResizeHandle) boundingBoxResizeHandleAt:(NSPoint)p { - NSRect bbox = [self screenBoundingBox]; - if (p.x >= NSMaxX(bbox)) { - if (p.x <= NSMaxX(bbox) + handle_size) { - if (p.y >= NSMaxY(bbox)) { - if (p.y <= NSMaxY(bbox) + handle_size) { - return SouthEastHandle; - } - } else if (p.y <= NSMinY(bbox)) { - if (p.y >= NSMinY(bbox) - handle_size) { - return NorthEastHandle; - } - } else { - float eastHandleTop = sideHandleTop(bbox); - if (p.y >= eastHandleTop && p.y <= (eastHandleTop + handle_size)) { - return EastHandle; - } - } - } - } else if (p.x <= NSMinX(bbox)) { - if (p.x >= NSMinX(bbox) - handle_size) { - if (p.y >= NSMaxY(bbox)) { - if (p.y <= NSMaxY(bbox) + handle_size) { - return SouthWestHandle; - } - } else if (p.y <= NSMinY(bbox)) { - if (p.y >= NSMinY(bbox) - handle_size) { - return NorthWestHandle; - } - } else { - float westHandleTop = sideHandleTop(bbox); - if (p.y >= westHandleTop && p.y <= (westHandleTop + handle_size)) { - return WestHandle; - } - } - } - } else if (p.y >= NSMaxY(bbox)) { - if (p.y <= NSMaxY(bbox) + handle_size) { - float southHandleLeft = tbHandleLeft(bbox); - if (p.x >= southHandleLeft && p.x <= (southHandleLeft + handle_size)) { - return SouthHandle; - } - } - } else if (p.y <= NSMinY(bbox)) { - if (p.y >= NSMinY(bbox) - handle_size) { - float northHandleLeft = tbHandleLeft(bbox); - if (p.x >= northHandleLeft && p.x <= (northHandleLeft + handle_size)) { - return NorthHandle; - } - } - } - return NoHandle; -} - -- (NSRect) boundingBoxResizeHandleRect:(ResizeHandle)handle { - Graph *graph = [[renderer document] graph]; - if (![graph hasBoundingBox]) { - return NSZeroRect; - } - NSRect bbox = [self screenBoundingBox]; - float x; - float y; - switch (handle) { - case NorthEastHandle: - case EastHandle: - case SouthEastHandle: - x = NSMaxX(bbox); - break; - case NorthWestHandle: - case WestHandle: - case SouthWestHandle: - x = NSMinX(bbox) - handle_size; - break; - case SouthHandle: - case NorthHandle: - x = tbHandleLeft(bbox); - break; - default: - return NSZeroRect; - } - switch (handle) { - case EastHandle: - case WestHandle: - y = sideHandleTop(bbox); - break; - case SouthEastHandle: - case SouthHandle: - case SouthWestHandle: - y = NSMaxY(bbox); - break; - case NorthEastHandle: - case NorthHandle: - case NorthWestHandle: - y = NSMinY(bbox) - handle_size; - break; - default: - return NSZeroRect; - } - return NSMakeRect(x, y, handle_size, handle_size); -} - -- (void) setResizeCursorForHandle:(ResizeHandle)handle { - if (handle != currentResizeHandle) { - currentResizeHandle = handle; - Cursor c = NormalCursor; - switch (handle) { - case EastHandle: - c = ResizeRightCursor; - break; - case SouthEastHandle: - c = ResizeBottomRightCursor; - break; - case SouthHandle: - c = ResizeBottomCursor; - break; - case SouthWestHandle: - c = ResizeBottomLeftCursor; - break; - case WestHandle: - c = ResizeLeftCursor; - break; - case NorthWestHandle: - c = ResizeTopLeftCursor; - break; - case NorthHandle: - c = ResizeTopCursor; - break; - case NorthEastHandle: - c = ResizeTopRightCursor; - break; - default: - c = NormalCursor; - break; - } - [[renderer surface] setCursor:c]; - } -} -@end - -// vim:ft=objc:ts=8:et:sts=4:sw=4 diff --git a/tikzit/src/gtk/CairoRenderContext.h b/tikzit/src/gtk/CairoRenderContext.h deleted file mode 100644 index ac9c5ee..0000000 --- a/tikzit/src/gtk/CairoRenderContext.h +++ /dev/null @@ -1,59 +0,0 @@ -/* - * Copyright 2011 Alex Merry <alex.merry@kdemail.net> - * - * 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 the Free Software Foundation; either version 2 of - * the License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see <http://www.gnu.org/licenses/>. - */ - -#import "TZFoundation.h" -#import "RenderContext.h" -#import "Transformer.h" -#import <cairo/cairo.h> -#import <pango/pango.h> -#import <gtk/gtk.h> - -@interface PangoTextLayout: NSObject<TextLayout> { - PangoLayout *layout; - cairo_t *context; -} - -+ (PangoTextLayout*) layoutForContext:(cairo_t*)cr withFontSize:(CGFloat)fontSize; -- (id) initWithContext:(cairo_t*)cr fontSize:(CGFloat)fontSize; -- (void) setText:(NSString*)text; - -@end - -@interface CairoRenderContext: NSObject<RenderContext> { - cairo_t *context; -} - -+ (CairoRenderContext*) contextForSurface:(cairo_surface_t*)surface; -- (id) initForSurface:(cairo_surface_t*)surface; - -+ (CairoRenderContext*) contextForWidget:(GtkWidget*)widget; -- (id) initForWidget:(GtkWidget*)widget; - -+ (CairoRenderContext*) contextForDrawable:(GdkDrawable*)d; -- (id) initForDrawable:(GdkDrawable*)d; - -+ (CairoRenderContext*) contextForPixbuf:(GdkPixbuf*)buf; -- (id) initForPixbuf:(GdkPixbuf*)buf; - -- (cairo_t*) cairoContext; -- (void) applyTransform:(Transformer*)transformer; - -- (void) clearSurface; - -@end - -// vim:ft=objc:ts=8:et:sts=4:sw=4 diff --git a/tikzit/src/gtk/CairoRenderContext.m b/tikzit/src/gtk/CairoRenderContext.m deleted file mode 100644 index 77e10b5..0000000 --- a/tikzit/src/gtk/CairoRenderContext.m +++ /dev/null @@ -1,344 +0,0 @@ -/* - * Copyright 2011 Alex Merry <alex.merry@kdemail.net> - * - * 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 the Free Software Foundation; either version 2 of - * the License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see <http://www.gnu.org/licenses/>. - */ - -#import "CairoRenderContext.h" - -#import "cairo_helpers.h" -#import "util.h" - -#import <pango/pangocairo.h> - -@implementation PangoTextLayout - -- (id) init { - [self release]; - return nil; -} - -+ (PangoTextLayout*) layoutForContext:(cairo_t*)cr withFontSize:(CGFloat)fontSize { - return [[[self alloc] initWithContext:cr fontSize:fontSize] autorelease]; -} - -- (id) initWithContext:(cairo_t*)cr fontSize:(CGFloat)fontSize { - self = [super init]; - - if (self) { - cairo_reference (cr); - context = cr; - layout = pango_cairo_create_layout (cr); - - PangoFontDescription *font_desc = pango_font_description_new (); - pango_font_description_set_family_static (font_desc, "Sans"); - pango_font_description_set_size (font_desc, pango_units_from_double (fontSize)); - pango_layout_set_font_description (layout, font_desc); - pango_font_description_free (font_desc); - } - - return self; -} - -- (void) setText:(NSString*)text { - pango_layout_set_text (layout, [text UTF8String], -1); -} - -- (NSSize) size { - int width, height; - pango_layout_get_size (layout, &width, &height); - return NSMakeSize (pango_units_to_double (width), pango_units_to_double (height)); -} - -- (NSString*) text { - return [NSString stringWithUTF8String:pango_layout_get_text (layout)]; -} - -- (void) showTextAt:(NSPoint)topLeft withColor:(RColor)color { - cairo_save (context); - - cairo_move_to(context, topLeft.x, topLeft.y); - cairo_set_source_rcolor (context, color); - pango_cairo_show_layout (context, layout); - - cairo_restore (context); -} - -- (void) dealloc { - if (layout) - g_object_unref (G_OBJECT (layout)); - if (context) - cairo_destroy (context); - - [super dealloc]; -} - -@end - -@implementation CairoRenderContext - -- (id) init { - [self release]; - return nil; -} - -+ (CairoRenderContext*) contextForSurface:(cairo_surface_t*)surface { - return [[[self alloc] initForSurface:surface] autorelease]; -} - -- (id) initForSurface:(cairo_surface_t*)surface { - self = [super init]; - - if (self) { - context = cairo_create (surface); - } - - return self; -} - -+ (CairoRenderContext*) contextForWidget:(GtkWidget*)widget { - return [[[self alloc] initForWidget:widget] autorelease]; -} - -- (id) initForWidget:(GtkWidget*)widget { - self = [super init]; - - if (self) { - GdkWindow *window = gtk_widget_get_window (widget); - if (window) { - context = gdk_cairo_create (window); - } else { - [self release]; - self = nil; - } - } - - return self; -} - -+ (CairoRenderContext*) contextForDrawable:(GdkDrawable*)d { - return [[[self alloc] initForDrawable:d] autorelease]; -} - -- (id) initForDrawable:(GdkDrawable*)d { - self = [super init]; - - if (self) { - context = gdk_cairo_create (d); - } - - return self; -} - -+ (CairoRenderContext*) contextForPixbuf:(GdkPixbuf*)pixbuf { - return [[[self alloc] initForPixbuf:pixbuf] autorelease]; -} - -- (id) initForPixbuf:(GdkPixbuf*)pixbuf { - self = [super init]; - - if (self) { - cairo_format_t format = -1; - - if (gdk_pixbuf_get_colorspace (pixbuf) != GDK_COLORSPACE_RGB) { - NSLog(@"Unsupported colorspace (must be RGB)"); - [self release]; - return nil; - } - if (gdk_pixbuf_get_bits_per_sample (pixbuf) != 8) { - NSLog(@"Unsupported bits per sample (must be 8)"); - [self release]; - return nil; - } - if (gdk_pixbuf_get_has_alpha (pixbuf)) { - if (gdk_pixbuf_get_n_channels (pixbuf) != 4) { - NSLog(@"Unsupported bits per sample (must be 4 for an image with alpha)"); - [self release]; - return nil; - } - format = CAIRO_FORMAT_ARGB32; - } else { - if (gdk_pixbuf_get_n_channels (pixbuf) != 3) { - NSLog(@"Unsupported bits per sample (must be 3 for an image without alpha)"); - [self release]; - return nil; - } - format = CAIRO_FORMAT_RGB24; - } - - cairo_surface_t *surface = cairo_image_surface_create_for_data( - gdk_pixbuf_get_pixels(pixbuf), - format, - gdk_pixbuf_get_width(pixbuf), - gdk_pixbuf_get_height(pixbuf), - gdk_pixbuf_get_rowstride(pixbuf)); - context = cairo_create (surface); - cairo_surface_destroy (surface); - } - - return self; -} - -- (cairo_t*) cairoContext { - return context; -} - -- (void) applyTransform:(Transformer*)transformer { - NSPoint origin = [transformer toScreen:NSZeroPoint]; - cairo_translate (context, origin.x, origin.y); - NSPoint scale = [transformer toScreen:NSMakePoint (1.0f, 1.0f)]; - scale.x -= origin.x; - scale.y -= origin.y; - cairo_scale (context, scale.x, scale.y); -} - -- (void) saveState { - cairo_save (context); -} - -- (void) restoreState { - cairo_restore (context); -} - -- (NSRect) clipBoundingBox { - double clipx1, clipx2, clipy1, clipy2; - cairo_clip_extents (context, &clipx1, &clipy1, &clipx2, &clipy2); - return NSMakeRect (clipx1, clipy1, clipx2-clipx1, clipy2-clipy1); -} - -- (BOOL) strokeIncludesPoint:(NSPoint)p { - return cairo_in_stroke (context, p.x, p.y); -} - -- (BOOL) fillIncludesPoint:(NSPoint)p { - return cairo_in_fill (context, p.x, p.y); -} - -- (id<TextLayout>) layoutText:(NSString*)text withSize:(CGFloat)fontSize { - PangoTextLayout *layout = [PangoTextLayout layoutForContext:context withFontSize:fontSize]; - [layout setText:text]; - return layout; -} - -- (void) setAntialiasMode:(AntialiasMode)mode { - if (mode == AntialiasDisabled) { - cairo_set_antialias (context, CAIRO_ANTIALIAS_NONE); - } else { - cairo_set_antialias (context, CAIRO_ANTIALIAS_DEFAULT); - } -} - -- (void) setLineWidth:(CGFloat)width { - cairo_set_line_width (context, width); -} - -- (void) setLineDash:(CGFloat)dashLength { - if (dashLength <= 0.0) { - cairo_set_dash (context, NULL, 0, 0); - } else { - double dashes[] = { dashLength }; - cairo_set_dash (context, dashes, 1, 0); - } -} - -// paths -- (void) startPath { - cairo_new_path (context); -} - -- (void) closeSubPath { - cairo_close_path (context); -} - -- (void) moveTo:(NSPoint)p { - cairo_move_to(context, p.x, p.y); -} - -- (void) curveTo:(NSPoint)end withCp1:(NSPoint)cp1 andCp2:(NSPoint)cp2 { - cairo_curve_to (context, cp1.x, cp1.y, cp2.x, cp2.y, end.x, end.y); -} - -- (void) lineTo:(NSPoint)end { - cairo_line_to (context, end.x, end.y); -} - -- (void) rect:(NSRect)rect { - cairo_rectangle (context, rect.origin.x, rect.origin.y, rect.size.width, rect.size.height); -} - -- (void) circleAt:(NSPoint)c withRadius:(CGFloat)r { - cairo_new_sub_path (context); - cairo_arc (context, c.x, c.y, r, 0, 2 * M_PI); -} - -- (void) strokePathWithColor:(RColor)color { - cairo_set_source_rcolor (context, color); - cairo_stroke (context); -} - -- (void) fillPathWithColor:(RColor)color { - cairo_set_source_rcolor (context, color); - cairo_fill (context); -} - -- (void) strokePathWithColor:(RColor)scolor - andFillWithColor:(RColor)fcolor { - cairo_set_source_rcolor (context, fcolor); - cairo_fill_preserve (context); - cairo_set_source_rcolor (context, scolor); - cairo_stroke (context); -} - -- (void) strokePathWithColor:(RColor)scolor - andFillWithColor:(RColor)fcolor - usingAlpha:(CGFloat)alpha { - cairo_push_group (context); - cairo_set_source_rcolor (context, fcolor); - cairo_fill_preserve (context); - cairo_set_source_rcolor (context, scolor); - cairo_stroke (context); - cairo_pop_group_to_source (context); - cairo_paint_with_alpha (context, alpha); -} - -- (void) clipToPath { - cairo_clip (context); -} - -- (void) paintWithColor:(RColor)color { - cairo_set_source_rcolor (context, color); - cairo_paint (context); -} - -- (void) clearSurface { - cairo_operator_t old_op = cairo_get_operator (context); - - cairo_set_operator (context, CAIRO_OPERATOR_SOURCE); - cairo_set_source_rgba (context, 0.0, 0.0, 0.0, 0.0); - cairo_paint (context); - - cairo_set_operator (context, old_op); -} - -- (void) dealloc { - if (context) { - cairo_destroy (context); - } - - [super dealloc]; -} - -@end - -// vim:ft=objc:ts=8:et:sts=4:sw=4 diff --git a/tikzit/src/gtk/ColorRGB+Gtk.h b/tikzit/src/gtk/ColorRGB+Gtk.h deleted file mode 100644 index 5cfb4d7..0000000 --- a/tikzit/src/gtk/ColorRGB+Gtk.h +++ /dev/null @@ -1,30 +0,0 @@ -/* - * Copyright 2011 Alex Merry <dev@randomguy3.me.uk> - * - * 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 the Free Software Foundation; either version 2 of - * the License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see <http://www.gnu.org/licenses/>. - */ - -#import "TZFoundation.h" -#import "ColorRGB.h" -#import <gdk/gdk.h> - -@interface ColorRGB (Gtk) - -+ (ColorRGB*) colorWithGdkColor:(GdkColor)color; -- (id) initWithGdkColor:(GdkColor)color; -- (GdkColor) gdkColor; - -@end - -// vim:ft=objc:ts=8:et:sts=4:sw=4 diff --git a/tikzit/src/gtk/ColorRGB+Gtk.m b/tikzit/src/gtk/ColorRGB+Gtk.m deleted file mode 100644 index be5dd56..0000000 --- a/tikzit/src/gtk/ColorRGB+Gtk.m +++ /dev/null @@ -1,46 +0,0 @@ -/* - * Copyright 2011 Alex Merry <dev@randomguy3.me.uk> - * Copyright 2010 Chris Heunen - * - * 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 the Free Software Foundation; either version 2 of - * the License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see <http://www.gnu.org/licenses/>. - */ - -#import "ColorRGB+Gtk.h" - -// 257 = 65535/255 -// GdkColor values run from 0 to 65535, not from 0 to 255 -#define GDK_FACTOR 257 - -@implementation ColorRGB (Gtk) - -+ (ColorRGB*) colorWithGdkColor:(GdkColor)color { - return [ColorRGB colorWithRed:color.red/GDK_FACTOR green:color.green/GDK_FACTOR blue:color.blue/GDK_FACTOR]; -} - -- (id) initWithGdkColor:(GdkColor)color { - return [self initWithRed:color.red/GDK_FACTOR green:color.green/GDK_FACTOR blue:color.blue/GDK_FACTOR]; -} - -- (GdkColor) gdkColor { - GdkColor color; - color.pixel = 0; - color.red = GDK_FACTOR * [self red]; - color.green = GDK_FACTOR * [self green]; - color.blue = GDK_FACTOR * [self blue]; - return color; -} - -@end - -// vim:ft=objc:ts=8:et:sts=4:sw=4 diff --git a/tikzit/src/gtk/ColorRGB+IntegerListStorage.h b/tikzit/src/gtk/ColorRGB+IntegerListStorage.h deleted file mode 100644 index 118eaee..0000000 --- a/tikzit/src/gtk/ColorRGB+IntegerListStorage.h +++ /dev/null @@ -1,32 +0,0 @@ -/* - * Copyright 2011 Alex Merry <dev@randomguy3.me.uk> - * - * 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 the Free Software Foundation; either version 2 of - * the License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see <http://www.gnu.org/licenses/>. - */ - -#import "TZFoundation.h" -#import "ColorRGB.h" - -/** - * Stores a ColorRGB as a list of short integers - */ -@interface ColorRGB (IntegerListStorage) - -+ (ColorRGB*) colorFromValueList:(NSArray*)values; -- (id) initFromValueList:(NSArray*)values; -- (NSArray*) valueList; - -@end - -// vim:ft=objc:ts=8:et:sts=4:sw=4 diff --git a/tikzit/src/gtk/ColorRGB+IntegerListStorage.m b/tikzit/src/gtk/ColorRGB+IntegerListStorage.m deleted file mode 100644 index 0103a3c..0000000 --- a/tikzit/src/gtk/ColorRGB+IntegerListStorage.m +++ /dev/null @@ -1,57 +0,0 @@ -/* - * Copyright 2011 Alex Merry <dev@randomguy3.me.uk> - * Copyright 2010 Chris Heunen - * - * 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 the Free Software Foundation; either version 2 of - * the License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see <http://www.gnu.org/licenses/>. - */ - -#import "ColorRGB+IntegerListStorage.h" - -@implementation ColorRGB (IntegerListStorage) - -+ (ColorRGB*) colorFromValueList:(NSArray*)values { - if ([values count] != 3) { - return nil; - } - - unsigned short redValue = [[values objectAtIndex:0] intValue]; - unsigned short greenValue = [[values objectAtIndex:1] intValue]; - unsigned short blueValue = [[values objectAtIndex:2] intValue]; - return [ColorRGB colorWithRed:redValue green:greenValue blue:blueValue]; -} - -- (id) initFromValueList:(NSArray*)values { - if ([values count] != 3) { - [self release]; - return nil; - } - - unsigned short redValue = [[values objectAtIndex:0] intValue]; - unsigned short greenValue = [[values objectAtIndex:1] intValue]; - unsigned short blueValue = [[values objectAtIndex:2] intValue]; - - return [self initWithRed:redValue green:greenValue blue:blueValue]; -} - -- (NSArray*) valueList { - NSMutableArray *array = [NSMutableArray arrayWithCapacity:3]; - [array addObject:[NSNumber numberWithInt:[self red]]]; - [array addObject:[NSNumber numberWithInt:[self green]]]; - [array addObject:[NSNumber numberWithInt:[self blue]]]; - return array; -} - -@end - -// vim:ft=objc:ts=8:et:sts=4:sw=4 diff --git a/tikzit/src/gtk/Configuration.h b/tikzit/src/gtk/Configuration.h deleted file mode 100644 index 6c68681..0000000 --- a/tikzit/src/gtk/Configuration.h +++ /dev/null @@ -1,447 +0,0 @@ -// -// Configuration.h -// TikZiT -// -// Copyright 2010 Alex Merry -// -// This file is part of TikZiT. -// -// TikZiT is free software: you can redistribute it and/or modify -// it under the terms of the GNU General Public License as published by -// the Free Software Foundation, either version 3 of the License, or -// (at your option) any later version. -// -// TikZiT is distributed in the hope that it will be useful, -// but WITHOUT ANY WARRANTY; without even the implied warranty of -// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -// GNU General Public License for more details. -// -// You should have received a copy of the GNU General Public License -// along with TikZiT. If not, see <http://www.gnu.org/licenses/>. -// - -#import "TZFoundation.h" - -/** - * Manages configuration information in a grouped key-value format. - */ -@interface Configuration : NSObject { - NSString *name; - GKeyFile *file; -} - -/** - * Check whether there is any existing configuration. - */ -+ (BOOL) configurationExistsWithName:(NSString*)name; -/** - * Create a blank configuration with the given name, without loading - * any existing configuration information. - * - * @param name the name of the configuration - */ -+ (Configuration*) emptyConfigurationWithName:(NSString*)name; -/** - * Load an existing configuration for the given name. - * - * If there was no existing configuration, or it could not be opened, - * an empty configuration will be returned. - * - * @param name the name of the configuration - */ -+ (Configuration*) configurationWithName:(NSString*)name; -/** - * Load an existing configuration for the given name. - * - * If there was no existing configuration, or it could not be opened, - * an empty configuration will be returned. - * - * @param name the name of the configuration - * @param error this will be set if the configuration exists, but could - * not be opened. - */ -+ (Configuration*) configurationWithName:(NSString*)name loadError:(NSError**)error; - -/** - * Initialise the configuration to be empty - * - * Does not attempt to load any existing configuration data. - * - * @param name the name of the configuration - */ -- (id) initEmptyWithName:(NSString*)name; -/** - * Initialise a configuration, loading it if it had previously been stored. - * - * If there was no existing configuration, or it could not be opened, - * an empty configuration will be returned. - * - * @param name the name of the configuration - */ -- (id) initWithName:(NSString*)name; -/** - * Initialise a configuration, loading it if it had previously been stored. - * - * If there was no existing configuration, or it could not be opened, - * an empty configuration will be returned. - * - * @param name the name of the configuration - * @param error this will be set if the configuration exists, but could - * not be opened. - */ -- (id) initWithName:(NSString*)name loadError:(NSError**)error; - -/** - * The name of the configuration. - * - * Configurations with different names are stored independently. - */ -- (NSString*) name; -/** - * Set the name of the configuration. - * - * This will affect the behaviour of [-writeToStore] - * - * Configurations with different names are stored independently. - */ -- (void) setName:(NSString*)name; - -/** - * Writes the configuration to the backing store. - * - * The location the configuration is written to is determined by the - * [-name] property. - * - * @result YES if the configuration was successfully written, NO otherwise - */ -- (BOOL) writeToStore; -/** - * Writes the configuration to the backing store. - * - * The location the configuration is written to is determined by the - * [-name] property. - * - * @param error this will be set if the configuration could not be written - * to the backing store - * @result YES if the configuration was successfully written, NO otherwise - */ -- (BOOL) writeToStoreWithError:(NSError**)error; - -/** - * Check whether a particular key exists within a group - * - * @param key the key to check for - * @param group the name of the group to look in - * @result YES if the key exists, NO otherwise - */ -- (BOOL) hasKey:(NSString*)key inGroup:(NSString*)group; -/** - * Check whether a particular group exists - * - * @param group the name of the group to check for - * @result YES if the group exists, NO otherwise - */ -- (BOOL) hasGroup:(NSString*)group; -/** - * List the groups in the configuration. - * - * @result a list of group names - */ -- (NSArray*) groups; - -/** - * Get the value associated with a key as a string - * - * This is only guaranteed to work if the value was stored as a string. - * - * @param key the key to fetch the data for - * @param group the name of the group to look in - * @result the value associated with key as a string, or nil - * if no string value was associated with key - */ -- (NSString*) stringEntry:(NSString*)key inGroup:(NSString*)group; -/** - * Get the value associated with a key as a string - * - * This is only guaranteed to work if the value was stored as a string. - * - * @param key the key to fetch the data for - * @param group the name of the group to look in - * @param def the value to return if no string value was associated with key - * @result the value associated with key as a string, or default - */ -- (NSString*) stringEntry:(NSString*)key inGroup:(NSString*)group withDefault:(NSString*)def; -/** - * Get the value associated with a key as a boolean - * - * This is only guaranteed to work if the value was stored as a boolean. - * - * @param key the key to fetch the data for - * @param group the name of the group to look in - * @result the value associated with key as a boolean, or NO - * if no boolean value was associated with key - */ -- (BOOL) booleanEntry:(NSString*)key inGroup:(NSString*)group; -/** - * Get the value associated with a key as a boolean - * - * This is only guaranteed to work if the value was stored as a boolean. - * - * @param key the key to fetch the data for - * @param group the name of the group to look in - * @param def the value to return if no boolean value was associated with key - * @result the value associated with key as a boolean, or def - */ -- (BOOL) booleanEntry:(NSString*)key inGroup:(NSString*)group withDefault:(BOOL)def; -/** - * Get the value associated with a key as a integer - * - * This is only guaranteed to work if the value was stored as a integer. - * - * @param key the key to fetch the data for - * @param group the name of the group to look in - * @result the value associated with key as a integer, or 0 - * if no integer value was associated with key - */ -- (int) integerEntry:(NSString*)key inGroup:(NSString*)group; -/** - * Get the value associated with a key as a integer - * - * This is only guaranteed to work if the value was stored as a integer. - * - * @param key the key to fetch the data for - * @param group the name of the group to look in - * @param def the value to return if no integer value was associated with key - * @result the value associated with key as a integer, or def - */ -- (int) integerEntry:(NSString*)key inGroup:(NSString*)group withDefault:(int)def; -/** - * Get the value associated with a key as a double - * - * This is only guaranteed to work if the value was stored as a double. - * - * @param key the key to fetch the data for - * @param group the name of the group to look in - * @result the value associated with key as a double, or 0 - * if no double value was associated with key - */ -- (double) doubleEntry:(NSString*)key inGroup:(NSString*)group; -/** - * Get the value associated with a key as a double - * - * This is only guaranteed to work if the value was stored as a double. - * - * @param key the key to fetch the data for - * @param group the name of the group to look in - * @param def the value to return if no double value was associated with key - * @result the value associated with key as a double, or def - */ -- (double) doubleEntry:(NSString*)key inGroup:(NSString*)group withDefault:(double)def; - -/** - * Get the value associated with a key as a list of strings - * - * This is only guaranteed to work if the value was stored as a - * list of strings. - * - * @param key the key to fetch the data for - * @param group the name of the group to look in - * @result the value associated with key as a list of strings, - * or nil if no list of strings was associated with key - */ -- (NSArray*) stringListEntry:(NSString*)key inGroup:(NSString*)group; -/** - * Get the value associated with a key as a list of strings - * - * This is only guaranteed to work if the value was stored as a - * list of strings. - * - * @param key the key to fetch the data for - * @param group the name of the group to look in - * @param def the value to return if no string list value was associated with key - * @result the value associated with key as a list of strings, or def - */ -- (NSArray*) stringListEntry:(NSString*)key inGroup:(NSString*)group withDefault:(NSArray*)def; -/** - * Get the value associated with a key as a list of booleans - * - * This is only guaranteed to work if the value was stored as a - * list of booleans. - * - * @param key the key to fetch the data for - * @param group the name of the group to look in - * @result the value associated with key as a list of NSNumber - * objects, containing boolean values, or nil - */ -- (NSArray*) booleanListEntry:(NSString*)key inGroup:(NSString*)group; -/** - * Get the value associated with a key as a list of booleans - * - * This is only guaranteed to work if the value was stored as a - * list of booleans. - * - * @param key the key to fetch the data for - * @param group the name of the group to look in - * @param def the value to return if no boolean list value was associated with key - * @result the value associated with key as a list of NSNumber - * objects, containing boolean values, or def - */ -- (NSArray*) booleanListEntry:(NSString*)key inGroup:(NSString*)group withDefault:(NSArray*)def; -/** - * Get the value associated with a key as a list of integers - * - * This is only guaranteed to work if the value was stored as a - * list of integers. - * - * @param key the key to fetch the data for - * @param group the name of the group to look in - * @result the value associated with key as a list of NSNumber - * objects, containing integer values, or nil - */ -- (NSArray*) integerListEntry:(NSString*)key inGroup:(NSString*)group; -/** - * Get the value associated with a key as a list of integers - * - * This is only guaranteed to work if the value was stored as a - * list of integers. - * - * @param key the key to fetch the data for - * @param group the name of the group to look in - * @param def the value to return if no integer list value was associated with key - * @result the value associated with key as a list of NSNumber - * objects, containing integer values, or def - */ -- (NSArray*) integerListEntry:(NSString*)key inGroup:(NSString*)group withDefault:(NSArray*)def; -/** - * Get the value associated with a key as a list of doubles - * - * This is only guaranteed to work if the value was stored as a - * list of doubles. - * - * @param key the key to fetch the data for - * @param group the name of the group to look in - * @result the value associated with key as a list of NSNumber - * objects, containing double values, or nil - */ -- (NSArray*) doubleListEntry:(NSString*)key inGroup:(NSString*)group; -/** - * Get the value associated with a key as a list of doubles - * - * This is only guaranteed to work if the value was stored as a - * list of doubles. - * - * @param key the key to fetch the data for - * @param group the name of the group to look in - * @param def the value to return if no double list value was associated with key - * @result the value associated with key as a list of NSNumber - * objects, containing double values, or def - */ -- (NSArray*) doubleListEntry:(NSString*)key inGroup:(NSString*)group withDefault:(NSArray*)def; - -/** - * Associate a string value with a key. - * - * Any previous value (of any type) with the same key and group will - * be overwritten. - * - * @param key the key to associate the value with - * @param group the group to store the association in - * @param value the value to store - */ -- (void) setStringEntry:(NSString*)key inGroup:(NSString*)group value:(NSString*)value; -/** - * Associate a boolean value with a key. - * - * Any previous value (of any type) with the same key and group will - * be overwritten. - * - * @param key the key to associate the value with - * @param group the group to store the association in - * @param value the value to store - */ -- (void) setBooleanEntry:(NSString*)key inGroup:(NSString*)group value:(BOOL)value; -/** - * Associate a integer value with a key. - * - * Any previous value (of any type) with the same key and group will - * be overwritten. - * - * @param key the key to associate the value with - * @param group the group to store the association in - * @param value the value to store - */ -- (void) setIntegerEntry:(NSString*)key inGroup:(NSString*)group value:(int)value; -/** - * Associate a double value with a key. - * - * Any previous value (of any type) with the same key and group will - * be overwritten. - * - * @param key the key to associate the value with - * @param group the group to store the association in - * @param value the value to store - */ -- (void) setDoubleEntry:(NSString*)key inGroup:(NSString*)group value:(double)value; - -/** - * Associate a list of string values with a key. - * - * Any previous value (of any type) with the same key and group will - * be overwritten. - * - * @param key the key to associate the list with - * @param group the group to store the association in - * @param value the list to store, as an array of strings - */ -- (void) setStringListEntry:(NSString*)key inGroup:(NSString*)group value:(NSArray*)value; -/** - * Associate a list of boolean values with a key. - * - * Any previous value (of any type) with the same key and group will - * be overwritten. - * - * @param key the key to associate the list with - * @param group the group to store the association in - * @param value the list to store, as an array of NSNumber objects - */ -- (void) setBooleanListEntry:(NSString*)key inGroup:(NSString*)group value:(NSArray*)value; -/** - * Associate a list of integer values with a key. - * - * Any previous value (of any type) with the same key and group will - * be overwritten. - * - * @param key the key to associate the list with - * @param group the group to store the association in - * @param value the list to store, as an array of NSNumber objects - */ -- (void) setIntegerListEntry:(NSString*)key inGroup:(NSString*)group value:(NSArray*)value; -/** - * Associate a list of double values with a key. - * - * Any previous value (of any type) with the same key and group will - * be overwritten. - * - * @param key the key to associate the list with - * @param group the group to store the association in - * @param value the list to store, as an array of NSNumber objects - */ -- (void) setDoubleListEntry:(NSString*)key inGroup:(NSString*)group value:(NSArray*)value; - -/** - * Remove a group from the configuration - * - * This will remove all the groups key-value associations. - */ -- (void) removeGroup:(NSString*)group; -/** - * Remove a key from the configuration - * - * @param key the key to remove - * @param group the group to remove it from - */ -- (void) removeKey:(NSString*)key inGroup:(NSString*)group; - -@end - -// vim:ft=objc:sts=4:sw=4:et diff --git a/tikzit/src/gtk/Configuration.m b/tikzit/src/gtk/Configuration.m deleted file mode 100644 index 4a3ed79..0000000 --- a/tikzit/src/gtk/Configuration.m +++ /dev/null @@ -1,450 +0,0 @@ -// -// Configuration.h -// TikZiT -// -// Copyright 2010 Alex Merry -// -// This file is part of TikZiT. -// -// TikZiT is free software: you can redistribute it and/or modify -// it under the terms of the GNU General Public License as published by -// the Free Software Foundation, either version 3 of the License, or -// (at your option) any later version. -// -// TikZiT is distributed in the hope that it will be useful, -// but WITHOUT ANY WARRANTY; without even the implied warranty of -// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -// GNU General Public License for more details. -// -// You should have received a copy of the GNU General Public License -// along with TikZiT. If not, see <http://www.gnu.org/licenses/>. -// - -#import "Configuration.h" -#import "SupportDir.h" - -@implementation Configuration - -+ (NSString*) _pathFromName:(NSString*)name { - return [NSString stringWithFormat:@"%@/%@.conf", [SupportDir userSupportDir], name]; -} - -+ (BOOL) configurationExistsWithName:(NSString*)name { - BOOL isDir; - BOOL exists = [[NSFileManager defaultManager] fileExistsAtPath:[self _pathFromName:name] isDirectory:&isDir]; - return exists && !isDir; -} - -+ (Configuration*) emptyConfigurationWithName:(NSString*)name - { return [[[self alloc] initEmptyWithName:name] autorelease]; } -+ (Configuration*) configurationWithName:(NSString*)name - { return [[[self alloc] initWithName:name] autorelease]; } -+ (Configuration*) configurationWithName:(NSString*)name loadError:(NSError**)error - { return [[[self alloc] initWithName:name loadError:error] autorelease]; } - -- (id) init -{ - [self release]; - return nil; -} - -- (id) initEmptyWithName:(NSString*)n -{ - self = [super init]; - if (self) { - name = [n retain]; - file = g_key_file_new (); - } - - return self; -} - -- (id) _initFromFile:(NSString*)path error:(NSError**)error -{ - self = [super init]; - if (self) { - file = g_key_file_new (); - - NSFileManager *manager = [NSFileManager defaultManager]; - if ([manager fileExistsAtPath:path]) { - gchar *filename = [path glibFilename]; - - GError *gerror = NULL; - g_key_file_load_from_file (file, - filename, - G_KEY_FILE_NONE, - &gerror); - g_free (filename); - - if (gerror) { - GErrorToNSError (gerror, error); - g_error_free (gerror); - } - } - } - - return self; -} - -- (id) initWithName:(NSString*)n { - return [self initWithName:n loadError:NULL]; -} - -- (id) initWithName:(NSString*)n loadError:(NSError**)error { - self = [self _initFromFile:[Configuration _pathFromName:n] error:error]; - - if (self) { - name = [n retain]; - } - - return self; -} - -- (BOOL) _ensureParentExists:(NSString*)path error:(NSError**)error { - NSString *directory = [path stringByDeletingLastPathComponent]; - return [[NSFileManager defaultManager] ensureDirectoryExists:directory error:error]; -} - -- (BOOL) _writeFileTo:(NSString*)path error:(NSError**)error -{ - if (![self _ensureParentExists:path error:error]) { - return NO; - } - - BOOL success = NO; - gsize length; - gchar *data = g_key_file_to_data (file, &length, NULL); // never reports an error - if (data && length) { - GError *gerror = NULL; - gchar* nativePath = [path glibFilename]; - success = g_file_set_contents (nativePath, data, length, &gerror) ? YES : NO; - g_free (data); - g_free (nativePath); - if (gerror) { - g_warning ("Failed to write file: %s\n", gerror->message); - GErrorToNSError (gerror, error); - g_error_free (gerror); - } - } else { - [[NSFileManager defaultManager] removeFileAtPath:path handler:nil]; - success = YES; - } - - return success; -} - -- (NSString*) name { - return name; -} - -- (void) setName:(NSString*)n { - [n retain]; - [name release]; - name = n; -} - -- (BOOL) writeToStore { - return [self writeToStoreWithError:NULL]; -} - -- (BOOL) writeToStoreWithError:(NSError**)error { - return [self _writeFileTo:[Configuration _pathFromName:name] error:error]; -} - -- (BOOL) hasKey:(NSString*)key inGroup:(NSString*)group -{ - gboolean result = g_key_file_has_key (file, [group UTF8String], [key UTF8String], NULL); - return result ? YES : NO; -} - -- (BOOL) hasGroup:(NSString*)group -{ - gboolean result = g_key_file_has_group (file, [group UTF8String]); - return result ? YES : NO; -} - -- (NSArray*) keys:(NSString*)group -{ - gsize length; - gchar **keys = g_key_file_get_keys (file, [group UTF8String], &length, NULL); - if (!keys) - length = 0; - - NSMutableArray *array = [NSMutableArray arrayWithCapacity:length]; - for (int i = 0; i < length; ++i) { - [array addObject:[NSString stringWithUTF8String:keys[i]]]; - } - g_strfreev (keys); - return array; -} - -- (NSArray*) groups -{ - gsize length; - gchar **groups = g_key_file_get_groups (file, &length); - NSMutableArray *array = [NSMutableArray arrayWithCapacity:length]; - for (int i = 0; i < length; ++i) { - [array addObject:[NSString stringWithUTF8String:groups[i]]]; - } - g_strfreev (groups); - return array; -} - -- (NSString*) stringEntry:(NSString*)key inGroup:(NSString*)group -{ - return [self stringEntry:key inGroup:group withDefault:nil]; -} - -- (NSString*) stringEntry:(NSString*)key inGroup:(NSString*)group withDefault:(NSString*)def -{ - NSString *result = def; - gchar *entry = g_key_file_get_string (file, [group UTF8String], [key UTF8String], NULL); - if (entry) { - result = [NSString stringWithUTF8String:entry]; - g_free (entry); - } - return result; -} - -- (BOOL) booleanEntry:(NSString*)key inGroup:(NSString*)group withDefault:(BOOL)def -{ - GError *error = NULL; - gboolean result = g_key_file_get_boolean (file, [group UTF8String], [key UTF8String], &error); - if (error != NULL) { - g_error_free (error); - return def; - } else { - return result ? YES : NO; - } -} - -- (BOOL) booleanEntry:(NSString*)key inGroup:(NSString*)group -{ - gboolean result = g_key_file_get_boolean (file, [group UTF8String], [key UTF8String], NULL); - return result ? YES : NO; -} - -- (int) integerEntry:(NSString*)key inGroup:(NSString*)group withDefault:(int)def -{ - GError *error = NULL; - int result = g_key_file_get_integer (file, [group UTF8String], [key UTF8String], &error); - if (error != NULL) { - g_error_free (error); - return def; - } else { - return result; - } -} - -- (int) integerEntry:(NSString*)key inGroup:(NSString*)group -{ - return g_key_file_get_integer (file, [group UTF8String], [key UTF8String], NULL); -} - -- (double) doubleEntry:(NSString*)key inGroup:(NSString*)group withDefault:(double)def -{ - GError *error = NULL; - double result = g_key_file_get_double (file, [group UTF8String], [key UTF8String], &error); - if (error != NULL) { - g_error_free (error); - return def; - } else { - return result; - } -} - -- (double) doubleEntry:(NSString*)key inGroup:(NSString*)group -{ - return g_key_file_get_double (file, [group UTF8String], [key UTF8String], NULL); -} - -- (NSArray*) stringListEntry:(NSString*)key inGroup:(NSString*)group -{ - return [self stringListEntry:key inGroup:group withDefault:nil]; -} - -- (NSArray*) stringListEntry:(NSString*)key inGroup:(NSString*)group withDefault:(NSArray*)def -{ - gsize length; - gchar **list = g_key_file_get_string_list (file, [group UTF8String], [key UTF8String], &length, NULL); - if (list) { - NSMutableArray *result = [NSMutableArray arrayWithCapacity:length]; - for (int i = 0; i < length; ++i) { - [result addObject:[NSString stringWithUTF8String:list[i]]]; - } - g_strfreev (list); - return result; - } else { - return def; - } -} - -- (NSArray*) booleanListEntry:(NSString*)key inGroup:(NSString*)group -{ - return [self booleanListEntry:key inGroup:group withDefault:nil]; -} - -- (NSArray*) booleanListEntry:(NSString*)key inGroup:(NSString*)group withDefault:(NSArray*)def -{ - gsize length; - gboolean *list = g_key_file_get_boolean_list (file, [group UTF8String], [key UTF8String], &length, NULL); - if (list) { - NSMutableArray *result = [NSMutableArray arrayWithCapacity:length]; - for (int i = 0; i < length; ++i) { - [result addObject:[NSNumber numberWithBool:list[i]]]; - } - g_free (list); - return result; - } else { - return def; - } -} - -- (NSArray*) integerListEntry:(NSString*)key inGroup:(NSString*)group -{ - return [self integerListEntry:key inGroup:group withDefault:nil]; -} - -- (NSArray*) integerListEntry:(NSString*)key inGroup:(NSString*)group withDefault:(NSArray*)def -{ - gsize length; - gint *list = g_key_file_get_integer_list (file, [group UTF8String], [key UTF8String], &length, NULL); - if (list) { - NSMutableArray *result = [NSMutableArray arrayWithCapacity:length]; - for (int i = 0; i < length; ++i) { - [result addObject:[NSNumber numberWithInt:list[i]]]; - } - g_free (list); - return result; - } else { - return def; - } -} - -- (NSArray*) doubleListEntry:(NSString*)key inGroup:(NSString*)group -{ - return [self doubleListEntry:key inGroup:group withDefault:nil]; -} - -- (NSArray*) doubleListEntry:(NSString*)key inGroup:(NSString*)group withDefault:(NSArray*)def -{ - gsize length; - double *list = g_key_file_get_double_list (file, [group UTF8String], [key UTF8String], &length, NULL); - if (list) { - NSMutableArray *result = [NSMutableArray arrayWithCapacity:length]; - for (int i = 0; i < length; ++i) { - [result addObject:[NSNumber numberWithDouble:list[i]]]; - } - g_free (list); - return result; - } else { - return def; - } -} - -- (void) setStringEntry:(NSString*)key inGroup:(NSString*)group value:(NSString*)value -{ - if (value == nil) { - [self removeKey:key inGroup:group]; - return; - } - g_key_file_set_string (file, [group UTF8String], [key UTF8String], [value UTF8String]); -} - -- (void) setBooleanEntry:(NSString*)key inGroup:(NSString*)group value:(BOOL)value; -{ - g_key_file_set_boolean (file, [group UTF8String], [key UTF8String], value); -} - -- (void) setIntegerEntry:(NSString*)key inGroup:(NSString*)group value:(int)value; -{ - g_key_file_set_integer (file, [group UTF8String], [key UTF8String], value); -} - -- (void) setDoubleEntry:(NSString*)key inGroup:(NSString*)group value:(double)value; -{ - g_key_file_set_double (file, [group UTF8String], [key UTF8String], value); -} - - -- (void) setStringListEntry:(NSString*)key inGroup:(NSString*)group value:(NSArray*)value -{ - if (value == nil) { - [self removeKey:key inGroup:group]; - return; - } - gsize length = [value count]; - const gchar * *list = g_new (const gchar *, length); - for (int i = 0; i < length; ++i) { - list[i] = [[value objectAtIndex:i] UTF8String]; - } - g_key_file_set_string_list (file, [group UTF8String], [key UTF8String], list, length); - g_free (list); -} - -- (void) setBooleanListEntry:(NSString*)key inGroup:(NSString*)group value:(NSArray*)value; -{ - if (value == nil) { - [self removeKey:key inGroup:group]; - return; - } - gsize length = [value count]; - gboolean *list = g_new (gboolean, length); - for (int i = 0; i < length; ++i) { - list[i] = [[value objectAtIndex:i] boolValue]; - } - g_key_file_set_boolean_list (file, [group UTF8String], [key UTF8String], list, length); - g_free (list); -} - -- (void) setIntegerListEntry:(NSString*)key inGroup:(NSString*)group value:(NSArray*)value; -{ - if (value == nil) { - [self removeKey:key inGroup:group]; - return; - } - gsize length = [value count]; - gint *list = g_new (gint, length); - for (int i = 0; i < length; ++i) { - list[i] = [[value objectAtIndex:i] intValue]; - } - g_key_file_set_integer_list (file, [group UTF8String], [key UTF8String], list, length); - g_free (list); -} - -- (void) setDoubleListEntry:(NSString*)key inGroup:(NSString*)group value:(NSArray*)value; -{ - if (value == nil) { - [self removeKey:key inGroup:group]; - return; - } - gsize length = [value count]; - gdouble *list = g_new (gdouble, length); - for (int i = 0; i < length; ++i) { - list[i] = [[value objectAtIndex:i] doubleValue]; - } - g_key_file_set_double_list (file, [group UTF8String], [key UTF8String], list, length); - g_free (list); -} - -- (void) removeGroup:(NSString*)group -{ - g_key_file_remove_group (file, [group UTF8String], NULL); -} - -- (void) removeKey:(NSString*)key inGroup:(NSString*)group; -{ - g_key_file_remove_key (file, [group UTF8String], [key UTF8String], NULL); -} - -- (void) dealloc -{ - [name release]; - g_key_file_free (file); - file = NULL; - [super dealloc]; -} - -@end - -// vim:ft=objc:sts=4:sw=4:et diff --git a/tikzit/src/gtk/ContextWindow.h b/tikzit/src/gtk/ContextWindow.h deleted file mode 100644 index fcad9df..0000000 --- a/tikzit/src/gtk/ContextWindow.h +++ /dev/null @@ -1,53 +0,0 @@ -/* - * Copyright 2011-2012 Alex Merry <dev@randomguy3.me.uk> - * - * 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 the Free Software Foundation; either version 2 of - * the License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see <http://www.gnu.org/licenses/>. - */ - -#import "TZFoundation.h" -#import <gtk/gtk.h> - -@class Configuration; -@class EdgeStylesModel; -@class NodeStylesModel; -@class PropertiesPane; -@class SelectionPane; -@class StyleManager; -@class TikzDocument; -@class Window; - -@interface ContextWindow: NSObject { - PropertiesPane *propsPane; - SelectionPane *selPane; - - GtkWidget *window; - GtkWidget *layout; -} - -@property (retain) TikzDocument *document; -@property (assign) BOOL visible; - -- (id) initWithStyleManager:(StyleManager*)mgr; -- (id) initWithNodeStylesModel:(NodeStylesModel*)nsm - andEdgeStylesModel:(EdgeStylesModel*)esm; - -- (void) present; -- (void) attachToWindow:(Window*)parent; - -- (void) loadConfiguration:(Configuration*)config; -- (void) saveConfiguration:(Configuration*)config; - -@end - -// vim:ft=objc:ts=8:et:sts=4:sw=4:foldmethod=marker diff --git a/tikzit/src/gtk/ContextWindow.m b/tikzit/src/gtk/ContextWindow.m deleted file mode 100644 index d8e9d20..0000000 --- a/tikzit/src/gtk/ContextWindow.m +++ /dev/null @@ -1,169 +0,0 @@ -/* - * Copyright 2011-2012 Alex Merry <dev@randomguy3.me.uk> - * - * 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 the Free Software Foundation; either version 2 of - * the License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see <http://www.gnu.org/licenses/>. - */ - -#import "ContextWindow.h" - -#import "Configuration.h" -#import "EdgeStylesModel.h" -#import "NodeStylesModel.h" -#import "PropertiesPane.h" -#import "SelectionPane.h" -#import "StyleManager.h" -#import "Window.h" - -#import "gtkhelpers.h" - -static gboolean props_window_delete_event_cb (GtkWidget *widget, GdkEvent *event, ContextWindow *window); - -@implementation ContextWindow - -- (id) init { - [self release]; - return nil; -} - -- (id) initWithStyleManager:(StyleManager*)sm { - return [self initWithNodeStylesModel:[NodeStylesModel modelWithStyleManager:sm] - andEdgeStylesModel:[EdgeStylesModel modelWithStyleManager:sm]]; -} - -- (id) initWithNodeStylesModel:(NodeStylesModel*)nsm - andEdgeStylesModel:(EdgeStylesModel*)esm { - self = [super init]; - - if (self) { - window = gtk_window_new (GTK_WINDOW_TOPLEVEL); - g_object_ref_sink (window); - gtk_window_set_title (GTK_WINDOW (window), "Context"); - gtk_window_set_role (GTK_WINDOW (window), "context"); - gtk_window_set_type_hint (GTK_WINDOW (window), - GDK_WINDOW_TYPE_HINT_UTILITY); - gtk_window_set_default_size (GTK_WINDOW (window), 200, 500); - g_signal_connect (G_OBJECT (window), - "delete-event", - G_CALLBACK (props_window_delete_event_cb), - self); - - layout = gtk_vbox_new (FALSE, 3); - g_object_ref_sink (layout); - gtk_widget_show (layout); - gtk_container_set_border_width (GTK_CONTAINER (layout), 6); - - gtk_container_add (GTK_CONTAINER (window), layout); - - propsPane = [[PropertiesPane alloc] init]; - gtk_box_pack_start (GTK_BOX (layout), [propsPane gtkWidget], - TRUE, TRUE, 0); - - GtkWidget *sep = gtk_hseparator_new (); - gtk_widget_show (sep); - gtk_box_pack_start (GTK_BOX (layout), sep, - FALSE, FALSE, 0); - - selPane = [[SelectionPane alloc] initWithNodeStylesModel:nsm - andEdgeStylesModel:esm]; - gtk_box_pack_start (GTK_BOX (layout), [selPane gtkWidget], - FALSE, FALSE, 0); - - // hack to position the context window somewhere sensible - // (upper right) - gtk_window_parse_geometry (GTK_WINDOW (window), "-0+0"); - } - - return self; -} - -- (void) dealloc { - [[NSNotificationCenter defaultCenter] removeObserver:self]; - - g_object_unref (layout); - g_object_unref (window); - - [propsPane release]; - - [super dealloc]; -} - -- (TikzDocument*) document { - return [propsPane document]; -} - -- (void) setDocument:(TikzDocument*)doc { - [propsPane setDocument:doc]; - [selPane setDocument:doc]; -} - -- (BOOL) visible { - return gtk_widget_get_visible (window); -} - -- (void) setVisible:(BOOL)visible { - gtk_widget_set_visible (window, visible); -} - -- (void) present { - gtk_window_present (GTK_WINDOW (window)); -} - -- (void) attachToWindow:(Window*)parent { - utility_window_attach (GTK_WINDOW (window), [parent gtkWindow]); -} - -- (void) loadConfiguration:(Configuration*)config { - [propsPane loadConfiguration:config]; - [selPane loadConfiguration:config]; - - if ([config hasGroup:@"ContextWindow"]) { - tz_restore_window (GTK_WINDOW (window), - [config integerEntry:@"x" inGroup:@"ContextWindow"], - [config integerEntry:@"y" inGroup:@"ContextWindow"], - [config integerEntry:@"w" inGroup:@"ContextWindow"], - [config integerEntry:@"h" inGroup:@"ContextWindow"]); - } - [self setVisible:[config booleanEntry:@"visible" - inGroup:@"ContextWindow" - withDefault:YES]]; -} - -- (void) saveConfiguration:(Configuration*)config { - gint x, y, w, h; - - gtk_window_get_position (GTK_WINDOW (window), &x, &y); - gtk_window_get_size (GTK_WINDOW (window), &w, &h); - - [config setIntegerEntry:@"x" inGroup:@"ContextWindow" value:x]; - [config setIntegerEntry:@"y" inGroup:@"ContextWindow" value:y]; - [config setIntegerEntry:@"w" inGroup:@"ContextWindow" value:w]; - [config setIntegerEntry:@"h" inGroup:@"ContextWindow" value:h]; - [config setBooleanEntry:@"visible" - inGroup:@"ContextWindow" - value:[self visible]]; - - [propsPane saveConfiguration:config]; - [selPane saveConfiguration:config]; -} - -@end - -static gboolean props_window_delete_event_cb (GtkWidget *widget, GdkEvent *event, ContextWindow *window) { - NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init]; - [window setVisible:NO]; - [pool drain]; - return TRUE; -} - -// vim:ft=objc:ts=8:et:sts=4:sw=4:foldmethod=marker diff --git a/tikzit/src/gtk/CreateEdgeTool.h b/tikzit/src/gtk/CreateEdgeTool.h deleted file mode 100644 index d33efce..0000000 --- a/tikzit/src/gtk/CreateEdgeTool.h +++ /dev/null @@ -1,45 +0,0 @@ -/* - * Copyright 2012 Alex Merry <alex.merry@kdemail.net> - * - * 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 the Free Software Foundation; either version 2 of - * the License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see <http://www.gnu.org/licenses/>. - */ - -#import "TZFoundation.h" -#import "Tool.h" - -@class EdgeStyle; -@class EdgeStylesModel; -@class EdgeStyleSelector; -@class Node; -@class StyleManager; - -@interface CreateEdgeTool : NSObject <Tool> { - GraphRenderer *renderer; - EdgeStyleSelector *stylePicker; - GtkWidget *configWidget; - Node *sourceNode; - NSPoint sourceNodeScreenPoint; - NSPoint halfEdgeEnd; -} - -@property (retain) EdgeStyle *activeStyle; - -+ (id) toolWithStyleManager:(StyleManager*)sm; -- (id) initWithStyleManager:(StyleManager*)sm; -+ (id) toolWithEdgeStylesModel:(EdgeStylesModel*)esm; -- (id) initWithEdgeStylesModel:(EdgeStylesModel*)esm; -@end - - -// vim:ft=objc:ts=8:et:sts=4:sw=4 diff --git a/tikzit/src/gtk/CreateEdgeTool.m b/tikzit/src/gtk/CreateEdgeTool.m deleted file mode 100644 index f3fb2c0..0000000 --- a/tikzit/src/gtk/CreateEdgeTool.m +++ /dev/null @@ -1,226 +0,0 @@ -/* - * Copyright 2011-2012 Alex Merry <alex.merry@kdemail.net> - * - * 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 the Free Software Foundation; either version 2 of - * the License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see <http://www.gnu.org/licenses/>. - */ - -#import "CreateEdgeTool.h" - -#import "Configuration.h" -#import "EdgeStyleSelector.h" -#import "EdgeStylesModel.h" -#import "GraphRenderer.h" -#import "TikzDocument.h" -#import "tzstockitems.h" - -static void clear_style_button_cb (GtkButton *widget, - EdgeStyleSelector *selector); - -@implementation CreateEdgeTool -- (NSString*) name { return @"Create Edge"; } -- (const gchar*) stockId { return TIKZIT_STOCK_CREATE_EDGE; } -- (NSString*) helpText { return @"Create new edges"; } -- (NSString*) shortcut { return @"e"; } -@synthesize activeRenderer=renderer; -@synthesize configurationWidget=configWidget; - -+ (id) toolWithStyleManager:(StyleManager*)sm { - return [[[self alloc] initWithStyleManager:sm] autorelease]; -} - -+ (id) toolWithEdgeStylesModel:(EdgeStylesModel*)esm { - return [[[self alloc] initWithEdgeStylesModel:esm] autorelease]; -} - -- (id) init { - [self release]; - return nil; -} - -- (id) initWithStyleManager:(StyleManager*)sm { - return [self initWithEdgeStylesModel:[EdgeStylesModel modelWithStyleManager:sm]]; -} - -- (id) initWithEdgeStylesModel:(EdgeStylesModel*)esm { - self = [super init]; - - if (self) { - stylePicker = [[EdgeStyleSelector alloc] initWithModel:esm]; - - configWidget = gtk_vbox_new (FALSE, 0); - g_object_ref_sink (configWidget); - - GtkWidget *label = gtk_label_new ("Edge style:"); - gtk_widget_show (label); - gtk_misc_set_alignment (GTK_MISC (label), 0.0, 0.5); - gtk_box_pack_start (GTK_BOX (configWidget), - label, - FALSE, - FALSE, - 0); - - GtkWidget *selWindow = gtk_scrolled_window_new (NULL, NULL); - gtk_widget_show (selWindow); - gtk_container_add (GTK_CONTAINER (selWindow), - [stylePicker widget]); - gtk_scrolled_window_set_policy (GTK_SCROLLED_WINDOW (selWindow), - GTK_POLICY_NEVER, - GTK_POLICY_AUTOMATIC); - gtk_widget_show ([stylePicker widget]); - - GtkWidget *selectorFrame = gtk_frame_new (NULL); - gtk_widget_show (selectorFrame); - gtk_box_pack_start (GTK_BOX (configWidget), - selectorFrame, - TRUE, - TRUE, - 0); - gtk_container_add (GTK_CONTAINER (selectorFrame), - selWindow); - - GtkWidget *button = gtk_button_new_with_label ("No style"); - gtk_widget_show (button); - gtk_box_pack_start (GTK_BOX (configWidget), - button, - FALSE, - FALSE, - 0); - g_signal_connect (G_OBJECT (button), - "clicked", - G_CALLBACK (clear_style_button_cb), - stylePicker); - } - - return self; -} - -- (void) dealloc { - [[NSNotificationCenter defaultCenter] removeObserver:self]; - - [renderer release]; - [stylePicker release]; - [sourceNode release]; - - g_object_unref (G_OBJECT (configWidget)); - - [super dealloc]; -} - -- (EdgeStyle*) activeStyle { - return [stylePicker selectedStyle]; -} - -- (void) setActiveStyle:(EdgeStyle*)style { - return [stylePicker setSelectedStyle:style]; -} - -- (void) invalidateHalfEdge { - NSRect invRect = NSRectAroundPoints(sourceNodeScreenPoint, halfEdgeEnd); - [renderer invalidateRect:NSInsetRect (invRect, -2.0f, -2.0f)]; -} - -- (void) mousePressAt:(NSPoint)pos withButton:(MouseButton)button andMask:(InputMask)mask { - if (button != LeftButton) - return; - - sourceNode = [renderer anyNodeAt:pos]; - if (sourceNode != nil) { - Transformer *transformer = [[renderer surface] transformer]; - sourceNodeScreenPoint = [transformer toScreen:[sourceNode point]]; - halfEdgeEnd = pos; - [renderer setNode:sourceNode highlighted:YES]; - } -} - -- (void) mouseMoveTo:(NSPoint)pos withButtons:(MouseButton)buttons andMask:(InputMask)mask { - if (!(buttons & LeftButton)) - return; - if (sourceNode == nil) - return; - - [self invalidateHalfEdge]; - - [renderer clearHighlightedNodes]; - [renderer setNode:sourceNode highlighted:YES]; - halfEdgeEnd = pos; - Node *targ = [renderer anyNodeAt:pos]; - if (targ != nil) { - [renderer setNode:targ highlighted:YES]; - } - - [self invalidateHalfEdge]; -} - -- (void) mouseReleaseAt:(NSPoint)pos withButton:(MouseButton)button andMask:(InputMask)mask { - if (button != LeftButton) - return; - if (sourceNode == nil) - return; - - [renderer clearHighlightedNodes]; - [self invalidateHalfEdge]; - - Node *targ = [renderer anyNodeAt:pos]; - if (targ != nil) { - Edge *edge = [Edge edgeWithSource:sourceNode andTarget:targ]; - [edge setStyle:[self activeStyle]]; - [[renderer document] addEdge:edge]; - [renderer invalidateEdge:edge]; - } - - sourceNode = nil; -} - -- (void) renderWithContext:(id<RenderContext>)context onSurface:(id<Surface>)surface { - if (sourceNode == nil) { - return; - } - [context saveState]; - - [context setLineWidth:1.0]; - [context startPath]; - [context moveTo:sourceNodeScreenPoint]; - [context lineTo:halfEdgeEnd]; - [context strokePathWithColor:MakeRColor (0, 0, 0, 0.5)]; - - [context restoreState]; -} - -- (StyleManager*) styleManager { - return [[stylePicker model] styleManager]; -} - -- (void) loadConfiguration:(Configuration*)config { - NSString *styleName = [config stringEntry:@"ActiveStyle" - inGroup:@"CreateEdgeTool" - withDefault:nil]; - [self setActiveStyle:[[self styleManager] edgeStyleForName:styleName]]; -} - -- (void) saveConfiguration:(Configuration*)config { - [config setStringEntry:@"ActiveStyle" - inGroup:@"CreateEdgeTool" - value:[[self activeStyle] name]]; -} -@end - -static void clear_style_button_cb (GtkButton *widget, - EdgeStyleSelector *selector) -{ - NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init]; - [selector setSelectedStyle:nil]; - [pool drain]; -} - -// vim:ft=objc:ts=8:et:sts=4:sw=4 diff --git a/tikzit/src/gtk/CreateNodeTool.h b/tikzit/src/gtk/CreateNodeTool.h deleted file mode 100644 index 94d6b31..0000000 --- a/tikzit/src/gtk/CreateNodeTool.h +++ /dev/null @@ -1,42 +0,0 @@ -/* - * Copyright 2012 Alex Merry <alex.merry@kdemail.net> - * - * 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 the Free Software Foundation; either version 2 of - * the License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see <http://www.gnu.org/licenses/>. - */ - -#import "TZFoundation.h" -#import <gtk/gtk.h> -#import "Tool.h" - -@class NodeStyle; -@class NodeStyleSelector; -@class NodeStylesModel; -@class StyleManager; - -@interface CreateNodeTool : NSObject <Tool> { - GraphRenderer *renderer; - NodeStyleSelector *stylePicker; - GtkWidget *configWidget; -} - -@property (retain) NodeStyle *activeStyle; - -+ (id) toolWithStyleManager:(StyleManager*)sm; -- (id) initWithStyleManager:(StyleManager*)sm; -+ (id) toolWithNodeStylesModel:(NodeStylesModel*)nsm; -- (id) initWithNodeStylesModel:(NodeStylesModel*)nsm; -@end - - -// vim:ft=objc:ts=8:et:sts=4:sw=4 diff --git a/tikzit/src/gtk/CreateNodeTool.m b/tikzit/src/gtk/CreateNodeTool.m deleted file mode 100644 index 77b24f0..0000000 --- a/tikzit/src/gtk/CreateNodeTool.m +++ /dev/null @@ -1,169 +0,0 @@ -/* - * Copyright 2011-2012 Alex Merry <alex.merry@kdemail.net> - * - * 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 the Free Software Foundation; either version 2 of - * the License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see <http://www.gnu.org/licenses/>. - */ - -#import "CreateNodeTool.h" - -#import "Configuration.h" -#import "GraphRenderer.h" -#import "NodeStyleSelector.h" -#import "NodeStylesModel.h" -#import "TikzDocument.h" -#import "tzstockitems.h" - -static void clear_style_button_cb (GtkButton *widget, - NodeStyleSelector *selector); - -@implementation CreateNodeTool -- (NSString*) name { return @"Create Node"; } -- (const gchar*) stockId { return TIKZIT_STOCK_CREATE_NODE; } -- (NSString*) helpText { return @"Create new nodes"; } -- (NSString*) shortcut { return @"n"; } -@synthesize activeRenderer=renderer; -@synthesize configurationWidget=configWidget; - -+ (id) toolWithStyleManager:(StyleManager*)sm { - return [[[self alloc] initWithStyleManager:sm] autorelease]; -} - -+ (id) toolWithNodeStylesModel:(NodeStylesModel*)nsm { - return [[[self alloc] initWithNodeStylesModel:nsm] autorelease]; -} - -- (id) init { - [self release]; - return nil; -} - -- (id) initWithStyleManager:(StyleManager*)sm { - return [self initWithNodeStylesModel:[NodeStylesModel modelWithStyleManager:sm]]; -} - -- (id) initWithNodeStylesModel:(NodeStylesModel*)nsm { - self = [super init]; - - if (self) { - stylePicker = [[NodeStyleSelector alloc] initWithModel:nsm]; - - configWidget = gtk_vbox_new (FALSE, 0); - g_object_ref_sink (configWidget); - - GtkWidget *label = gtk_label_new ("Node style:"); - gtk_widget_show (label); - gtk_misc_set_alignment (GTK_MISC (label), 0.0, 0.5); - gtk_box_pack_start (GTK_BOX (configWidget), - label, - FALSE, - FALSE, - 0); - - GtkWidget *selWindow = gtk_scrolled_window_new (NULL, NULL); - gtk_widget_show (selWindow); - gtk_container_add (GTK_CONTAINER (selWindow), - [stylePicker widget]); - gtk_scrolled_window_set_policy (GTK_SCROLLED_WINDOW (selWindow), - GTK_POLICY_AUTOMATIC, - GTK_POLICY_AUTOMATIC); - gtk_widget_show ([stylePicker widget]); - - GtkWidget *selectorFrame = gtk_frame_new (NULL); - gtk_widget_show (selectorFrame); - gtk_box_pack_start (GTK_BOX (configWidget), - selectorFrame, - TRUE, - TRUE, - 0); - gtk_container_add (GTK_CONTAINER (selectorFrame), - selWindow); - - GtkWidget *button = gtk_button_new_with_label ("No style"); - gtk_widget_show (button); - gtk_box_pack_start (GTK_BOX (configWidget), - button, - FALSE, - FALSE, - 0); - g_signal_connect (G_OBJECT (button), - "clicked", - G_CALLBACK (clear_style_button_cb), - stylePicker); - } - - return self; -} - -- (void) dealloc { - [[NSNotificationCenter defaultCenter] removeObserver:self]; - - [renderer release]; - [stylePicker release]; - - g_object_unref (G_OBJECT (configWidget)); - - [super dealloc]; -} - -- (NodeStyle*) activeStyle { - return [stylePicker selectedStyle]; -} - -- (void) setActiveStyle:(NodeStyle*)style { - return [stylePicker setSelectedStyle:style]; -} - -// FIXME: create node on press, and drag it around? -- (void) mousePressAt:(NSPoint)pos withButton:(MouseButton)button andMask:(InputMask)mask {} - -- (void) mouseReleaseAt:(NSPoint)pos withButton:(MouseButton)button andMask:(InputMask)mask { - if (button != LeftButton) - return; - - Transformer *transformer = [renderer transformer]; - NSPoint nodePoint = [transformer fromScreen:[[renderer grid] snapScreenPoint:pos]]; - Node *node = [Node nodeWithPoint:nodePoint]; - [node setStyle:[self activeStyle]]; - [[renderer document] addNode:node]; -} - -- (void) renderWithContext:(id<RenderContext>)context onSurface:(id<Surface>)surface {} - -- (StyleManager*) styleManager { - return [[stylePicker model] styleManager]; -} - -- (void) loadConfiguration:(Configuration*)config { - NSString *styleName = [config stringEntry:@"ActiveStyle" - inGroup:@"CreateNodeTool" - withDefault:nil]; - [self setActiveStyle:[[self styleManager] nodeStyleForName:styleName]]; -} - -- (void) saveConfiguration:(Configuration*)config { - [config setStringEntry:@"ActiveStyle" - inGroup:@"CreateNodeTool" - value:[[self activeStyle] name]]; -} -@end - -static void clear_style_button_cb (GtkButton *widget, - NodeStyleSelector *selector) -{ - NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init]; - [selector setSelectedStyle:nil]; - [pool drain]; -} - -// vim:ft=objc:ts=8:et:sts=4:sw=4 diff --git a/tikzit/src/gtk/DocumentContext.h b/tikzit/src/gtk/DocumentContext.h deleted file mode 100644 index e4c1065..0000000 --- a/tikzit/src/gtk/DocumentContext.h +++ /dev/null @@ -1,27 +0,0 @@ -/* - * Copyright 2012 Alex Merry <alex.merry@kdemail.net> - * - * 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 the Free Software Foundation; either version 2 of - * the License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see <http://www.gnu.org/licenses/>. - */ - -#import "TZFoundation.h" - -@class TikzDocument; - -@interface DocumentContext { - TikzDocument *document; - GraphRenderer *renderSurface; -} - -// vim:ft=objc:ts=8:et:sts=4:sw=4 diff --git a/tikzit/src/gtk/Edge+Render.h b/tikzit/src/gtk/Edge+Render.h deleted file mode 100644 index e88b28a..0000000 --- a/tikzit/src/gtk/Edge+Render.h +++ /dev/null @@ -1,34 +0,0 @@ -/* - * Copyright 2011 Alex Merry <dev@randomguy3.me.uk> - * - * 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 the Free Software Foundation; either version 2 of - * the License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see <http://www.gnu.org/licenses/>. - */ - -#import "TZFoundation.h" -#import "Edge.h" -#import "RenderContext.h" -#import "Surface.h" - -@interface Edge (Render) - -+ (float) controlPointRadius; -- (void) renderControlsInContext:(id<RenderContext>)context withTransformer:(Transformer*)transformer; -- (void) renderBasicEdgeInContext:(id<RenderContext>)context withTransformer:(Transformer*)t selected:(BOOL)selected; -- (void) renderToSurface:(id<Surface>)surface withContext:(id<RenderContext>)context selected:(BOOL)selected; -- (NSRect) renderedBoundsWithTransformer:(Transformer*)t whenSelected:(BOOL)selected; -- (BOOL) hitByPoint:(NSPoint)p onSurface:(id<Surface>)surface withFuzz:(float)fuzz; - -@end - -// vim:ft=objc:ts=8:et:sts=4:sw=4 diff --git a/tikzit/src/gtk/Edge+Render.m b/tikzit/src/gtk/Edge+Render.m deleted file mode 100644 index 3cc2a14..0000000 --- a/tikzit/src/gtk/Edge+Render.m +++ /dev/null @@ -1,267 +0,0 @@ -/* - * Copyright 2011 Alex Merry <dev@randomguy3.me.uk> - * Copyright 2010 Chris Heunen - * - * 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 the Free Software Foundation; either version 2 of - * the License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see <http://www.gnu.org/licenses/>. - */ - -#import "Edge+Render.h" -#import "Node+Render.h" -#import "../common/util.h" - -static const float edgeWidth = 2.0; -static const float cpRadius = 3.0; -static const float cpLineWidth = 1.0; - -@implementation Edge (Render) - -+ (float) controlPointRadius { - return cpRadius; -} - -- (float) controlDistance { - const float dx = (targ.x - src.x); - const float dy = (targ.y - src.y); - if (dx == 0 && dy == 0) { - return weight; - } else { - return NSDistanceBetweenPoints(src, targ) * weight; - } -} - -- (void) renderControlsInContext:(id<RenderContext>)context withTransformer:(Transformer*)transformer { - [context saveState]; - - [self updateControls]; - - NSPoint c_source = [transformer toScreen:src]; - NSPoint c_target = [transformer toScreen:targ]; - NSPoint c_mid = [transformer toScreen:mid]; - - const float dx = (c_target.x - c_source.x); - const float dy = (c_target.y - c_source.y); - - [context setLineWidth:cpLineWidth]; - RColor fillColor = MakeRColor (1.0, 1.0, 1.0, 0.5); - - // draw a circle at the mid point - [context startPath]; - [context circleAt:c_mid withRadius:cpRadius]; - [context strokePathWithColor:MakeSolidRColor(0, 0, 1) andFillWithColor:fillColor]; - - //[context setAntialiasMode:AntialiasDisabled]; - - // size of control circles - float c_dist = 0.0f; - if (dx == 0 && dy == 0) { - c_dist = [transformer scaleToScreen:weight]; - } else { - c_dist = NSDistanceBetweenPoints(c_source, c_target) * weight; - } - - // basic bend is blue, in-out is green - RColor controlTrackColor; - if ([self bendMode] == EdgeBendModeBasic) { - controlTrackColor = MakeRColor (0.0, 0.0, 1.0, 0.4); - } else { - controlTrackColor = MakeRColor (0.0, 0.7, 0.0, 0.4); - } - - [context startPath]; - [context circleAt:c_source withRadius:c_dist]; - if (dx != 0 || dy != 0) { - [context circleAt:c_target withRadius:c_dist]; - } - [context strokePathWithColor:controlTrackColor]; - - RColor handleColor = MakeRColor (1.0, 0.0, 1.0, 0.6); - if ([self bendMode] == EdgeBendModeBasic) { - if (bend % 45 != 0) { - handleColor = MakeRColor (0.0, 0.0, 0.1, 0.4); - } - } else if ([self bendMode] == EdgeBendModeInOut) { - if (outAngle % 45 != 0) { - handleColor = MakeRColor (0.0, 0.7, 0.0, 0.4); - } - } - - NSPoint c_cp1 = [transformer toScreen:cp1]; - [context moveTo:c_source]; - [context lineTo:c_cp1]; - [context circleAt:c_cp1 withRadius:cpRadius]; - [context strokePathWithColor:handleColor]; - - if ([self bendMode] == EdgeBendModeInOut) { - // recalculate color based on inAngle - if (inAngle % 45 == 0) { - handleColor = MakeRColor (1.0, 0.0, 1.0, 0.6); - } else { - handleColor = MakeRColor (0.0, 0.7, 0.0, 0.4); - } - } - - NSPoint c_cp2 = [transformer toScreen:cp2]; - [context moveTo:c_target]; - [context lineTo:c_cp2]; - [context circleAt:c_cp2 withRadius:cpRadius]; - [context strokePathWithColor:handleColor]; - - [context restoreState]; -} - -- (void) renderArrowStrokePathInContext:(id<RenderContext>)context withTransformer:(Transformer*)transformer color:(RColor)color { - - if ([self style] != nil) { - switch ([[self style] headStyle]) { - case AH_None: - break; - case AH_Plain: - [context startPath]; - [context moveTo:[transformer toScreen:[self leftHeadNormal]]]; - [context lineTo:[transformer toScreen:head]]; - [context lineTo:[transformer toScreen:[self rightHeadNormal]]]; - [context strokePathWithColor:color]; - break; - case AH_Latex: - [context startPath]; - [context moveTo:[transformer toScreen:[self leftHeadNormal]]]; - [context lineTo:[transformer toScreen:head]]; - [context lineTo:[transformer toScreen:[self rightHeadNormal]]]; - [context closeSubPath]; - [context strokePathWithColor:color andFillWithColor:color]; - break; - } - switch ([[self style] tailStyle]) { - case AH_None: - break; - case AH_Plain: - [context startPath]; - [context moveTo:[transformer toScreen:[self leftTailNormal]]]; - [context lineTo:[transformer toScreen:tail]]; - [context lineTo:[transformer toScreen:[self rightTailNormal]]]; - [context strokePathWithColor:color]; - break; - case AH_Latex: - [context startPath]; - [context moveTo:[transformer toScreen:[self leftTailNormal]]]; - [context lineTo:[transformer toScreen:tail]]; - [context lineTo:[transformer toScreen:[self rightTailNormal]]]; - [context closeSubPath]; - [context strokePathWithColor:color andFillWithColor:color]; - break; - } - } -} - -- (void) createStrokePathInContext:(id<RenderContext>)context withTransformer:(Transformer*)transformer { - NSPoint c_tail = [transformer toScreen:tail]; - NSPoint c_cp1 = [transformer toScreen:cp1]; - NSPoint c_cp2 = [transformer toScreen:cp2]; - NSPoint c_head = [transformer toScreen:head]; - - [context startPath]; - [context moveTo:c_tail]; - [context curveTo:c_head withCp1:c_cp1 andCp2:c_cp2]; - - if ([self style] != nil) { - // draw edge decoration - switch ([[self style] decorationStyle]) { - case ED_None: - break; - case ED_Tick: - [context moveTo:[transformer toScreen:[self leftNormal]]]; - [context lineTo:[transformer toScreen:[self rightNormal]]]; - break; - case ED_Arrow: - [context moveTo:[transformer toScreen:[self leftNormal]]]; - [context lineTo:[transformer toScreen:[self midTan]]]; - [context lineTo:[transformer toScreen:[self rightNormal]]]; - break; - } - - } -} - -- (RColor) color { - if (style) { - return [[style colorRGB] rColor]; - } else { - return BlackRColor; - } -} - -- (void) renderBasicEdgeInContext:(id<RenderContext>)context withTransformer:(Transformer*)t selected:(BOOL)selected { - [self updateControls]; - [context saveState]; - - const CGFloat lineWidth = style ? [style thickness] : edgeWidth; - [context setLineWidth:lineWidth]; - RColor color = [self color]; - if (selected) { - color.alpha = 0.5; - } - - [self createStrokePathInContext:context withTransformer:t]; - [context strokePathWithColor:color]; - - [self renderArrowStrokePathInContext:context withTransformer:t color:color]; - - [context restoreState]; -} - -- (void) renderToSurface:(id <Surface>)surface withContext:(id<RenderContext>)context selected:(BOOL)selected { - [self renderBasicEdgeInContext:context withTransformer:[surface transformer] selected:selected]; - - if (selected) { - [self renderControlsInContext:context withTransformer:[surface transformer]]; - } - - if ([self hasEdgeNode]) { - NSPoint labelPt = [[surface transformer] toScreen:[self mid]]; - [[self edgeNode] renderLabelAt:labelPt - withContext:context]; - } -} - -- (NSRect) renderedBoundsWithTransformer:(Transformer*)t whenSelected:(BOOL)selected { - if (selected) { - float c_dist = [self controlDistance] + cpRadius; // include handle - NSRect cp1circ = NSMakeRect (head.x - c_dist, head.y - c_dist, 2*c_dist, 2*c_dist); - NSRect cp2circ = NSMakeRect (tail.x - c_dist, tail.y - c_dist, 2*c_dist, 2*c_dist); - NSRect rect = NSUnionRect ([self boundingRect], NSUnionRect (cp1circ, cp2circ)); - return [t rectToScreen:rect]; - } else { - return [t rectToScreen:[self boundingRect]]; - } -} - -- (BOOL) hitByPoint:(NSPoint)p onSurface:(id<Surface>)surface withFuzz:(float)fuzz { - [self updateControls]; - - NSRect boundingRect = [[surface transformer] rectToScreen:[self boundingRect]]; - if (!NSPointInRect(p, NSInsetRect(boundingRect, -fuzz, -fuzz))) { - return NO; - } - - id<RenderContext> cr = [surface createRenderContext]; - - [cr setLineWidth:edgeWidth + 2 * fuzz]; - [self createStrokePathInContext:cr withTransformer:[surface transformer]]; - - return [cr strokeIncludesPoint:p]; -} - -@end - -// vim:ft=objc:ts=4:et:sts=4:sw=4 diff --git a/tikzit/src/gtk/EdgeStyle+Gtk.h b/tikzit/src/gtk/EdgeStyle+Gtk.h deleted file mode 100644 index 4323593..0000000 --- a/tikzit/src/gtk/EdgeStyle+Gtk.h +++ /dev/null @@ -1,29 +0,0 @@ -/* - * Copyright 2011 Alex Merry <dev@randomguy3.me.uk> - * - * 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 the Free Software Foundation; either version 2 of - * the License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see <http://www.gnu.org/licenses/>. - */ - -#import "TZFoundation.h" -#import "EdgeStyle.h" -#import <gtk/gtk.h> - -@interface EdgeStyle (Gtk) - -- (GdkColor) color; -- (void) setColor:(GdkColor)color; - -@end - -// vim:ft=objc:ts=8:et:sts=4:sw=4 diff --git a/tikzit/src/gtk/EdgeStyle+Gtk.m b/tikzit/src/gtk/EdgeStyle+Gtk.m deleted file mode 100644 index 886329e..0000000 --- a/tikzit/src/gtk/EdgeStyle+Gtk.m +++ /dev/null @@ -1,33 +0,0 @@ -/* - * Copyright 2011 Alex Merry <dev@randomguy3.me.uk> - * - * 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 the Free Software Foundation; either version 2 of - * the License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see <http://www.gnu.org/licenses/>. - */ - -#import "EdgeStyle+Gtk.h" -#import "ColorRGB+Gtk.h" - -@implementation EdgeStyle (Gtk) - -- (GdkColor) color { - return [[self colorRGB] gdkColor]; -} - -- (void) setColor:(GdkColor)color { - [self setColorRGB:[ColorRGB colorWithGdkColor:color]]; -} - -@end - -// vim:ft=objc:ts=8:et:sts=4:sw=4 diff --git a/tikzit/src/gtk/EdgeStyle+Storage.h b/tikzit/src/gtk/EdgeStyle+Storage.h deleted file mode 100644 index 74881f3..0000000 --- a/tikzit/src/gtk/EdgeStyle+Storage.h +++ /dev/null @@ -1,29 +0,0 @@ -/* - * Copyright 2011 Alex Merry <dev@randomguy3.me.uk> - * - * 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 the Free Software Foundation; either version 2 of - * the License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see <http://www.gnu.org/licenses/>. - */ - -#import "TZFoundation.h" -#import "EdgeStyle.h" -#import "Configuration.h" - -@interface EdgeStyle (Storage) - -- (id) initFromConfigurationGroup:(NSString*)groupName config:(Configuration*)configFile; -- (void) storeToConfigurationGroup:(NSString*)groupName config:(Configuration*)configFile; - -@end - -// vim:ft=objc:ts=8:et:sts=4:sw=4 diff --git a/tikzit/src/gtk/EdgeStyle+Storage.m b/tikzit/src/gtk/EdgeStyle+Storage.m deleted file mode 100644 index 45e2a20..0000000 --- a/tikzit/src/gtk/EdgeStyle+Storage.m +++ /dev/null @@ -1,55 +0,0 @@ -/* - * Copyright 2011 Alex Merry <dev@randomguy3.me.uk> - * - * 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 the Free Software Foundation; either version 2 of - * the License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see <http://www.gnu.org/licenses/>. - */ - -#import "EdgeStyle+Storage.h" -#import "ColorRGB+IntegerListStorage.h" - -@implementation EdgeStyle (Storage) - -- (id) initFromConfigurationGroup:(NSString*)groupName config:(Configuration*)configFile { - self = [self init]; - - if (self) { - [self setName:[configFile stringEntry:@"Name" inGroup:groupName withDefault:name]]; - [self setCategory:[configFile stringEntry:@"Category" inGroup:groupName withDefault:category]]; - headStyle = [configFile integerEntry:@"HeadStyle" inGroup:groupName withDefault:headStyle]; - tailStyle = [configFile integerEntry:@"TailStyle" inGroup:groupName withDefault:tailStyle]; - decorationStyle = [configFile integerEntry:@"DecorationStyle" inGroup:groupName withDefault:decorationStyle]; - thickness = [configFile doubleEntry:@"Thickness" inGroup:groupName withDefault:thickness]; - [self setColorRGB: - [ColorRGB colorFromValueList: - [configFile integerListEntry:@"Color" - inGroup:groupName - withDefault:[colorRGB valueList]]]]; - } - - return self; -} - -- (void) storeToConfigurationGroup:(NSString*)groupName config:(Configuration*)configFile { - [configFile setStringEntry:@"Name" inGroup:groupName value:name]; - [configFile setStringEntry:@"Category" inGroup:groupName value:category]; - [configFile setIntegerEntry:@"HeadStyle" inGroup:groupName value:headStyle]; - [configFile setIntegerEntry:@"TailStyle" inGroup:groupName value:tailStyle]; - [configFile setIntegerEntry:@"DecorationStyle" inGroup:groupName value:decorationStyle]; - [configFile setDoubleEntry:@"Thickness" inGroup:groupName value:thickness]; - [configFile setIntegerListEntry:@"Color" inGroup:groupName value:[[self colorRGB] valueList]]; -} - -@end - -// vim:ft=objc:ts=8:et:sts=4:sw=4 diff --git a/tikzit/src/gtk/EdgeStyleEditor.h b/tikzit/src/gtk/EdgeStyleEditor.h deleted file mode 100644 index 2224bbb..0000000 --- a/tikzit/src/gtk/EdgeStyleEditor.h +++ /dev/null @@ -1,45 +0,0 @@ -/* - * Copyright 2012 Alex Merry <dev@randomguy3.me.uk> - * - * 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 the Free Software Foundation; either version 2 of - * the License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see <http://www.gnu.org/licenses/>. - */ - -#import "TZFoundation.h" -#import <gtk/gtk.h> - -@class EdgeStyle; - -@interface EdgeStyleEditor: NSObject { - EdgeStyle *style; - GtkTable *table; - GtkEntry *nameEdit; - GtkComboBox *decorationCombo; - GtkComboBox *headArrowCombo; - GtkComboBox *tailArrowCombo; - GtkColorButton *colorButton; - GtkWidget *makeColorTexSafeButton; - GtkAdjustment *thicknessAdj; - BOOL blockSignals; -} - -@property (retain) EdgeStyle *style; -@property (readonly) GtkWidget *widget; - -- (id) init; - -- (void) selectNameField; - -@end - -// vim:ft=objc:ts=4:et:sts=4:sw=4:foldmethod=marker diff --git a/tikzit/src/gtk/EdgeStyleEditor.m b/tikzit/src/gtk/EdgeStyleEditor.m deleted file mode 100644 index c7ca8bd..0000000 --- a/tikzit/src/gtk/EdgeStyleEditor.m +++ /dev/null @@ -1,499 +0,0 @@ -/* - * Copyright 2012 Alex Merry <dev@randomguy3.me.uk> - * - * 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 the Free Software Foundation; either version 2 of - * the License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see <http://www.gnu.org/licenses/>. - */ - -#import "EdgeStyleEditor.h" - -#import "EdgeStyle.h" -#import "EdgeStyle+Gtk.h" -#import "Shape.h" - -#include <gdk-pixbuf/gdk-pixdata.h> - -#pragma GCC diagnostic push -#pragma GCC diagnostic ignored "-Wpointer-sign" -#import "edgedecdata.m" -#pragma GCC diagnostic pop - -// {{{ Data Types -enum { - DEC_NAME_COL = 0, - DEC_PREVIEW_COL, - DEC_VALUE_COL, - DEC_N_COLS -}; - -struct dec_info { - const gchar *name; - const GdkPixdata *pixdata; - int value; -}; -static struct dec_info ed_entries[] = { - { "None", &ED_none_pixdata, ED_None }, - { "Arrow", &ED_arrow_pixdata, ED_Arrow }, - { "Tick", &ED_tick_pixdata, ED_Tick } -}; -static guint n_ed_entries = G_N_ELEMENTS (ed_entries); -static struct dec_info ah_head_entries[] = { - { "None", &AH_none_pixdata, AH_None }, - { "Plain", &AH_plain_head_pixdata, AH_Plain }, - { "Latex", &AH_latex_head_pixdata, AH_Latex } -}; -static guint n_ah_head_entries = G_N_ELEMENTS (ah_head_entries); -static struct dec_info ah_tail_entries[] = { - { "None", &AH_none_pixdata, AH_None }, - { "Plain", &AH_plain_tail_pixdata, AH_Plain }, - { "Latex", &AH_latex_tail_pixdata, AH_Latex } -}; -static guint n_ah_tail_entries = G_N_ELEMENTS (ah_tail_entries); - -static const guint row_count = 6; - -// }}} -// {{{ Internal interfaces -// {{{ GTK+ Callbacks -static void style_name_edit_changed_cb (GtkEditable *widget, EdgeStyleEditor *editor); -static void decoration_combo_changed_cb (GtkComboBox *widget, EdgeStyleEditor *editor); -static void head_arrow_combo_changed_cb (GtkComboBox *widget, EdgeStyleEditor *editor); -static void tail_arrow_combo_changed_cb (GtkComboBox *widget, EdgeStyleEditor *editor); -static void thickness_adjustment_changed_cb (GtkAdjustment *widget, EdgeStyleEditor *editor); -static void color_changed_cb (GtkColorButton *widget, EdgeStyleEditor *editor); -static void make_color_safe_button_clicked_cb (GtkButton *widget, EdgeStyleEditor *editor); -// }}} -// {{{ Notifications - -@interface EdgeStyleEditor (Notifications) -- (void) nameChangedTo:(NSString*)value; -- (void) edgeDecorationChangedTo:(EdgeDectorationStyle)value; -- (void) headArrowChangedTo:(ArrowHeadStyle)value; -- (void) tailArrowChangedTo:(ArrowHeadStyle)value; -- (void) thicknessChangedTo:(double)value; -- (void) makeColorTexSafe; -- (void) colorChangedTo:(GdkColor)value; -@end - -// }}} -// {{{ Private - -@interface EdgeStyleEditor (Private) -- (void) load:(guint)count decorationStylesFrom:(struct dec_info*)info into:(GtkListStore*)list; -- (void) clearDecCombo:(GtkComboBox*)combo; -- (void) setDecCombo:(GtkComboBox*)combo toValue:(int)value; -@end - -// }}} -// }}} -// {{{ API - -@implementation EdgeStyleEditor - -- (void) _addWidget:(GtkWidget*)w withLabel:(gchar *)label atRow:(guint)row { - NSAssert(row < row_count, @"row_count is wrong!"); - - GtkWidget *l = gtk_label_new (label); - gtk_misc_set_alignment (GTK_MISC (l), 0, 0.5); - gtk_widget_show (l); - gtk_widget_show (w); - - gtk_table_attach (table, l, - 0, 1, row, row+1, // l, r, t, b - GTK_FILL, // x opts - GTK_FILL | GTK_EXPAND, // y opts - 5, // x padding - 0); // y padding - - gtk_table_attach (table, w, - 1, 2, row, row+1, // l, r, t, b - GTK_FILL | GTK_EXPAND, // x opts - GTK_FILL | GTK_EXPAND, // y opts - 0, // x padding - 0); // y padding -} - -- (GtkComboBox*) _createDecComboWithEntries:(struct dec_info*)entries count:(guint)n { - GtkListStore *store = gtk_list_store_new (DEC_N_COLS, G_TYPE_STRING, GDK_TYPE_PIXBUF, G_TYPE_INT); - [self load:n decorationStylesFrom:entries into:store]; - - GtkComboBox *combo = GTK_COMBO_BOX (gtk_combo_box_new_with_model (GTK_TREE_MODEL (store))); - g_object_unref (store); - GtkCellRenderer *cellRend = gtk_cell_renderer_pixbuf_new (); - gtk_cell_layout_pack_start (GTK_CELL_LAYOUT (combo), - cellRend, - TRUE); - gtk_cell_layout_add_attribute (GTK_CELL_LAYOUT (combo), cellRend, "pixbuf", DEC_PREVIEW_COL); - g_object_ref_sink (combo); - - return combo; -} - -- (GtkWidget*) _createMakeColorTexSafeButton { - GtkWidget *b = gtk_button_new (); - GtkWidget *icon = gtk_image_new_from_stock (GTK_STOCK_DIALOG_WARNING, GTK_ICON_SIZE_BUTTON); - gtk_widget_show (icon); - gtk_container_add (GTK_CONTAINER (b), icon); - NSString *ttip = @"The colour is not a predefined TeX colour.\nClick here to choose the nearest TeX-safe colour."; - gtk_widget_set_tooltip_text (b, [ttip UTF8String]); - return b; -} - -- (id) init { - self = [super init]; - - if (self != nil) { - style = nil; - table = GTK_TABLE (gtk_table_new (row_count, 2, FALSE)); - gtk_table_set_col_spacings (table, 6); - gtk_table_set_row_spacings (table, 6); - gtk_widget_set_sensitive (GTK_WIDGET (table), FALSE); - blockSignals = NO; - - /** - * Name - */ - nameEdit = GTK_ENTRY (gtk_entry_new ()); - g_object_ref_sink (nameEdit); - [self _addWidget:GTK_WIDGET (nameEdit) - withLabel:"Name" - atRow:0]; - g_signal_connect (G_OBJECT (nameEdit), - "changed", - G_CALLBACK (style_name_edit_changed_cb), - self); - - - /** - * Edge decoration style - */ - decorationCombo = [self _createDecComboWithEntries:ed_entries count:n_ed_entries]; - [self _addWidget:GTK_WIDGET (decorationCombo) - withLabel:"Decoration" - atRow:1]; - g_signal_connect (G_OBJECT (decorationCombo), - "changed", - G_CALLBACK (decoration_combo_changed_cb), - self); - - - /** - * Head arrow style - */ - headArrowCombo = [self _createDecComboWithEntries:ah_head_entries count:n_ah_head_entries]; - [self _addWidget:GTK_WIDGET (headArrowCombo) - withLabel:"Arrow head" - atRow:2]; - g_signal_connect (G_OBJECT (headArrowCombo), - "changed", - G_CALLBACK (head_arrow_combo_changed_cb), - self); - - - /** - * Tail arrow style - */ - tailArrowCombo = [self _createDecComboWithEntries:ah_tail_entries count:n_ah_tail_entries]; - [self _addWidget:GTK_WIDGET (tailArrowCombo) - withLabel:"Arrow tail" - atRow:3]; - g_signal_connect (G_OBJECT (tailArrowCombo), - "changed", - G_CALLBACK (tail_arrow_combo_changed_cb), - self); - - - /** - * Colour - */ - GtkWidget *colorBox = gtk_hbox_new (FALSE, 0); - [self _addWidget:colorBox - withLabel:"Colour" - atRow:4]; - colorButton = GTK_COLOR_BUTTON (gtk_color_button_new ()); - g_object_ref_sink (colorButton); - gtk_widget_show (GTK_WIDGET (colorButton)); - gtk_box_pack_start (GTK_BOX (colorBox), GTK_WIDGET (colorButton), - FALSE, FALSE, 0); - makeColorTexSafeButton = [self _createMakeColorTexSafeButton]; - g_object_ref_sink (makeColorTexSafeButton); - gtk_box_pack_start (GTK_BOX (colorBox), makeColorTexSafeButton, - FALSE, FALSE, 0); - g_signal_connect (G_OBJECT (colorButton), - "color-set", - G_CALLBACK (color_changed_cb), - self); - g_signal_connect (G_OBJECT (makeColorTexSafeButton), - "clicked", - G_CALLBACK (make_color_safe_button_clicked_cb), - self); - - - /** - * Thickness - */ - thicknessAdj = GTK_ADJUSTMENT (gtk_adjustment_new ( - 1.0, // value - 0.0, // lower - 50.0, // upper - 0.20, // step - 1.0, // page - 0.0)); // (irrelevant) - g_object_ref_sink (thicknessAdj); - GtkWidget *scaleSpin = gtk_spin_button_new (thicknessAdj, 0.0, 2); - [self _addWidget:scaleSpin - withLabel:"Thickness" - atRow:5]; - g_signal_connect (G_OBJECT (thicknessAdj), - "value-changed", - G_CALLBACK (thickness_adjustment_changed_cb), - self); - } - - return self; -} - -- (void) dealloc { - [[NSNotificationCenter defaultCenter] removeObserver:self]; - - g_object_unref (nameEdit); - g_object_unref (decorationCombo); - g_object_unref (colorButton); - g_object_unref (makeColorTexSafeButton); - g_object_unref (thicknessAdj); - g_object_unref (table); - [style release]; - - [super dealloc]; -} - -- (EdgeStyle*) style { - return style; -} - -- (void) setStyle:(EdgeStyle*)s { - blockSignals = YES; - EdgeStyle *oldStyle = style; - style = [s retain]; - - if (style != nil) { - gtk_widget_set_sensitive (GTK_WIDGET (table), TRUE); - - gtk_entry_set_text(nameEdit, [[style name] UTF8String]); - - [self setDecCombo:decorationCombo toValue:[style decorationStyle]]; - [self setDecCombo:headArrowCombo toValue:[style headStyle]]; - [self setDecCombo:tailArrowCombo toValue:[style tailStyle]]; - - GdkColor c = [style color]; - gtk_color_button_set_color(colorButton, &c); - gtk_widget_set_visible (makeColorTexSafeButton, ([[style colorRGB] name] == nil)); - - gtk_adjustment_set_value(thicknessAdj, [style thickness]); - } else { - gtk_entry_set_text(nameEdit, ""); - [self clearDecCombo:decorationCombo]; - [self clearDecCombo:headArrowCombo]; - [self clearDecCombo:tailArrowCombo]; - gtk_widget_set_visible (makeColorTexSafeButton, FALSE); - gtk_adjustment_set_value(thicknessAdj, 1.0); - gtk_widget_set_sensitive (GTK_WIDGET (table), FALSE); - } - - [oldStyle release]; - blockSignals = NO; -} - -- (GtkWidget*) widget { - return GTK_WIDGET (table); -} - -- (void) selectNameField { - gtk_widget_grab_focus (GTK_WIDGET (nameEdit)); - gtk_editable_select_region (GTK_EDITABLE (nameEdit), 0, -1); -} - -@end - -// }}} -// {{{ Notifications - -@implementation EdgeStyleEditor (Notifications) -- (void) nameChangedTo:(NSString*)value { - [style setName:value]; -} - -- (void) edgeDecorationChangedTo:(EdgeDectorationStyle)value { - [style setDecorationStyle:value]; -} - -- (void) headArrowChangedTo:(ArrowHeadStyle)value { - [style setHeadStyle:value]; -} - -- (void) tailArrowChangedTo:(ArrowHeadStyle)value { - [style setTailStyle:value]; -} - -- (void) thicknessChangedTo:(double)value { - [style setThickness:(float)value]; -} - -- (void) colorChangedTo:(GdkColor)value { - [style setColor:value]; - gtk_widget_set_visible (makeColorTexSafeButton, - [[style colorRGB] name] == nil); -} - -- (void) makeColorTexSafe { - if (style != nil) { - [[style colorRGB] setToClosestHashed]; - GdkColor color = [style color]; - gtk_color_button_set_color(colorButton, &color); - gtk_widget_set_visible (makeColorTexSafeButton, FALSE); - } -} -@end - -// }}} -// {{{ Private - -@implementation EdgeStyleEditor (Private) -- (BOOL) signalsBlocked { return blockSignals; } - -- (void) load:(guint)count decorationStylesFrom:(struct dec_info*)info into:(GtkListStore*)list { - GtkTreeIter iter; - - for (guint i = 0; i < count; ++i) { - GdkPixbuf *buf = gdk_pixbuf_from_pixdata (info[i].pixdata, FALSE, NULL); - gtk_list_store_append (list, &iter); - gtk_list_store_set (list, &iter, - DEC_NAME_COL, info[i].name, - DEC_PREVIEW_COL, buf, - DEC_VALUE_COL, info[i].value, - -1); - g_object_unref (buf); - } -} - -- (void) clearDecCombo:(GtkComboBox*)combo { - gtk_combo_box_set_active (combo, -1); -} - -- (void) setDecCombo:(GtkComboBox*)combo toValue:(int)value { - GtkTreeModel *model = gtk_combo_box_get_model (combo); - GtkTreeIter iter; - if (gtk_tree_model_get_iter_first (model, &iter)) { - do { - int rowValue; - gtk_tree_model_get (model, &iter, DEC_VALUE_COL, &rowValue, -1); - if (rowValue == value) { - gtk_combo_box_set_active_iter (combo, &iter); - return; - } - } while (gtk_tree_model_iter_next (model, &iter)); - } -} -@end - -// }}} -// {{{ GTK+ callbacks - -static void style_name_edit_changed_cb (GtkEditable *widget, EdgeStyleEditor *editor) { - if ([editor signalsBlocked]) - return; - - NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init]; - - const gchar *contents = gtk_entry_get_text (GTK_ENTRY (widget)); - [editor nameChangedTo:[NSString stringWithUTF8String:contents]]; - - [pool drain]; -} - -static void decoration_combo_changed_cb (GtkComboBox *widget, EdgeStyleEditor *editor) { - if ([editor signalsBlocked]) - return; - - NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init]; - - GtkTreeIter iter; - gtk_combo_box_get_active_iter (widget, &iter); - EdgeDectorationStyle dec = ED_None; - gtk_tree_model_get (gtk_combo_box_get_model (widget), &iter, DEC_VALUE_COL, &dec, -1); - [editor edgeDecorationChangedTo:dec]; - - [pool drain]; -} - -static void head_arrow_combo_changed_cb (GtkComboBox *widget, EdgeStyleEditor *editor) { - if ([editor signalsBlocked]) - return; - - NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init]; - - GtkTreeIter iter; - gtk_combo_box_get_active_iter (widget, &iter); - ArrowHeadStyle dec = AH_None; - gtk_tree_model_get (gtk_combo_box_get_model (widget), &iter, DEC_VALUE_COL, &dec, -1); - [editor headArrowChangedTo:dec]; - - [pool drain]; -} - -static void tail_arrow_combo_changed_cb (GtkComboBox *widget, EdgeStyleEditor *editor) { - if ([editor signalsBlocked]) - return; - - NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init]; - - GtkTreeIter iter; - gtk_combo_box_get_active_iter (widget, &iter); - ArrowHeadStyle dec = AH_None; - gtk_tree_model_get (gtk_combo_box_get_model (widget), &iter, DEC_VALUE_COL, &dec, -1); - [editor tailArrowChangedTo:dec]; - - [pool drain]; -} - -static void thickness_adjustment_changed_cb (GtkAdjustment *adj, EdgeStyleEditor *editor) { - NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init]; - [editor thicknessChangedTo:gtk_adjustment_get_value (adj)]; - [pool drain]; -} - -static void color_changed_cb (GtkColorButton *widget, EdgeStyleEditor *editor) { - if ([editor signalsBlocked]) - return; - - NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init]; - - GdkColor color; - gtk_color_button_get_color (widget, &color); - [editor colorChangedTo:color]; - - [pool drain]; -} - -static void make_color_safe_button_clicked_cb (GtkButton *widget, EdgeStyleEditor *editor) { - if ([editor signalsBlocked]) - return; - - NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init]; - [editor makeColorTexSafe]; - [pool drain]; -} - -// }}} - -// vim:ft=objc:ts=4:et:sts=4:sw=4:foldmethod=marker diff --git a/tikzit/src/gtk/EdgeStyleSelector.h b/tikzit/src/gtk/EdgeStyleSelector.h deleted file mode 100644 index 904bd93..0000000 --- a/tikzit/src/gtk/EdgeStyleSelector.h +++ /dev/null @@ -1,61 +0,0 @@ -/* - * Copyright 2012 Alex Merry <dev@randomguy3.me.uk> - * - * 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 the Free Software Foundation; either version 2 of - * the License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see <http://www.gnu.org/licenses/>. - */ - -#import "TZFoundation.h" -#import <gtk/gtk.h> - -@class EdgeStyle; -@class EdgeStylesModel; -@class StyleManager; - -@interface EdgeStyleSelector: NSObject { - EdgeStylesModel *model; - GtkTreeView *view; -} - -/*! - @property widget - @brief The GTK widget - */ -@property (readonly) GtkWidget *widget; - -/*! - @property model - @brief The model to use. - */ -@property (retain) EdgeStylesModel *model; - -/*! - @property selectedStyle - @brief The selected style. - - When this changes, a SelectedStyleChanged notification will be posted - */ -@property (assign) EdgeStyle *selectedStyle; - -/*! - * Initialise with a new model for the given style manager - */ -- (id) initWithStyleManager:(StyleManager*)m; -/*! - * Initialise with the given model - */ -- (id) initWithModel:(EdgeStylesModel*)model; - -@end - -// vim:ft=objc:ts=8:et:sts=4:sw=4:foldmethod=marker diff --git a/tikzit/src/gtk/EdgeStyleSelector.m b/tikzit/src/gtk/EdgeStyleSelector.m deleted file mode 100644 index 6a9db33..0000000 --- a/tikzit/src/gtk/EdgeStyleSelector.m +++ /dev/null @@ -1,143 +0,0 @@ -/* - * Copyright 2012 Alex Merry <dev@randomguy3.me.uk> - * - * 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 the Free Software Foundation; either version 2 of - * the License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see <http://www.gnu.org/licenses/>. - */ - -#import "EdgeStyleSelector.h" - -#import "EdgeStylesModel.h" - -// {{{ Internal interfaces -static void selection_changed_cb (GtkTreeSelection *sel, EdgeStyleSelector *mgr); -// }}} -// {{{ API - -@implementation EdgeStyleSelector - -- (id) init { - [self release]; - return nil; -} - -- (id) initWithStyleManager:(StyleManager*)m { - return [self initWithModel:[EdgeStylesModel modelWithStyleManager:m]]; -} -- (id) initWithModel:(EdgeStylesModel*)m { - self = [super init]; - - if (self) { - model = [m retain]; - - view = GTK_TREE_VIEW (gtk_tree_view_new_with_model ([m model])); - gtk_tree_view_set_headers_visible (view, FALSE); - g_object_ref (view); - - GtkCellRenderer *renderer; - GtkTreeViewColumn *column; - renderer = gtk_cell_renderer_pixbuf_new (); - column = gtk_tree_view_column_new_with_attributes ( - "Preview", - renderer, - "pixbuf", EDGE_STYLES_ICON_COL, - NULL); - gtk_tree_view_append_column (view, column); - gtk_tree_view_set_tooltip_column (view, EDGE_STYLES_NAME_COL); - - GtkTreeSelection *sel = gtk_tree_view_get_selection (view); - gtk_tree_selection_set_mode (sel, GTK_SELECTION_SINGLE); - - g_signal_connect (G_OBJECT (sel), - "changed", - G_CALLBACK (selection_changed_cb), - self); - } - - return self; -} - -- (void) dealloc { - [[NSNotificationCenter defaultCenter] removeObserver:self]; - - g_object_unref (view); - [model release]; - - [super dealloc]; -} - -- (EdgeStylesModel*) model { - return model; -} - -- (void) setModel:(EdgeStylesModel*)m { - if (m == model) - return; - - EdgeStylesModel *oldModel = model; - model = [m retain]; - gtk_tree_view_set_model (view, [model model]); - [oldModel release]; -} - -- (GtkWidget*) widget { - return GTK_WIDGET (view); -} - -- (EdgeStyle*) selectedStyle { - GtkTreeSelection *sel = gtk_tree_view_get_selection (view); - GtkTreeIter iter; - - if (!gtk_tree_selection_get_selected (sel, NULL, &iter)) { - return nil; - } - - EdgeStyle *style = nil; - gtk_tree_model_get ([model model], &iter, EDGE_STYLES_PTR_COL, &style, -1); - - return style; -} - -- (void) setSelectedStyle:(EdgeStyle*)style { - GtkTreeSelection *sel = gtk_tree_view_get_selection (view); - - if (style == nil) { - gtk_tree_selection_unselect_all (sel); - return; - } - - GtkTreePath *path = [model pathFromStyle:style]; - if (path) { - gtk_tree_selection_unselect_all (sel); - gtk_tree_selection_select_path (sel, path); - gtk_tree_path_free (path); - } -} -@end - -// }}} -// {{{ GTK+ callbacks - -static void selection_changed_cb (GtkTreeSelection *sel, EdgeStyleSelector *mgr) { - NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init]; - - [[NSNotificationCenter defaultCenter] - postNotificationName:@"SelectedStyleChanged" - object:mgr]; - - [pool drain]; -} -// }}} - -// vim:ft=objc:ts=8:et:sts=4:sw=4:foldmethod=marker - diff --git a/tikzit/src/gtk/EdgeStylesModel.h b/tikzit/src/gtk/EdgeStylesModel.h deleted file mode 100644 index 1166f92..0000000 --- a/tikzit/src/gtk/EdgeStylesModel.h +++ /dev/null @@ -1,62 +0,0 @@ -/* - * Copyright 2011-2012 Alex Merry <dev@randomguy3.me.uk> - * - * 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 the Free Software Foundation; either version 2 of - * the License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see <http://www.gnu.org/licenses/>. - */ - -#import "TZFoundation.h" -#import <gtk/gtk.h> - -@class EdgeStyle; -@class StyleManager; - -enum { - EDGE_STYLES_NAME_COL = 0, - EDGE_STYLES_ICON_COL, - EDGE_STYLES_PTR_COL, - EDGE_STYLES_N_COLS -}; - -@interface EdgeStylesModel: NSObject { - GtkListStore *store; - StyleManager *styleManager; -} - -/*! - @property model - @brief The GTK+ tree model - */ -@property (readonly) GtkTreeModel *model; - -/*! - @property manager - @brief The StyleManager to use. - */ -@property (retain) StyleManager *styleManager; - -/*! - * Initialise with the given style manager - */ -- (id) initWithStyleManager:(StyleManager*)m; - -+ (id) modelWithStyleManager:(StyleManager*)m; - -- (EdgeStyle*) styleFromPath:(GtkTreePath*)path; -- (GtkTreePath*) pathFromStyle:(EdgeStyle*)style; -- (EdgeStyle*) styleFromIter:(GtkTreeIter*)iter; -- (GtkTreeIter*) iterFromStyle:(EdgeStyle*)style; - -@end - -// vim:ft=objc:ts=8:et:sts=4:sw=4 diff --git a/tikzit/src/gtk/EdgeStylesModel.m b/tikzit/src/gtk/EdgeStylesModel.m deleted file mode 100644 index 2de57ed..0000000 --- a/tikzit/src/gtk/EdgeStylesModel.m +++ /dev/null @@ -1,367 +0,0 @@ -/* - * Copyright 2012 Alex Merry <dev@randomguy3.me.uk> - * - * 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 the Free Software Foundation; either version 2 of - * the License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see <http://www.gnu.org/licenses/>. - */ - -#import "EdgeStylesModel.h" - -#import "CairoRenderContext.h" -#import "Edge.h" -#import "Edge+Render.h" -#import "EdgeStyle.h" -#import "Node.h" -#import "StyleManager.h" - -#import "gtkhelpers.h" - -#import <gdk-pixbuf/gdk-pixbuf.h> - -// {{{ Internal interfaces - -@interface EdgeStylesModel (Notifications) -- (void) edgeStylesReplaced:(NSNotification*)notification; -- (void) edgeStyleAdded:(NSNotification*)notification; -- (void) edgeStyleRemoved:(NSNotification*)notification; -- (void) observeValueForKeyPath:(NSString*)keyPath - ofObject:(id)object - change:(NSDictionary*)change - context:(void*)context; -@end - -@interface EdgeStylesModel (Private) -- (cairo_surface_t*) createEdgeIconSurface; -- (GdkPixbuf*) pixbufOfEdgeInStyle:(EdgeStyle*)style; -- (GdkPixbuf*) pixbufOfEdgeInStyle:(EdgeStyle*)style usingSurface:(cairo_surface_t*)surface; -- (void) addEdgeStyle:(EdgeStyle*)style; -- (void) addEdgeStyle:(EdgeStyle*)style usingSurface:(cairo_surface_t*)surface; -- (void) observeEdgeStyle:(EdgeStyle*)style; -- (void) stopObservingEdgeStyle:(EdgeStyle*)style; -- (void) clearEdgeStylesModel; -- (void) reloadEdgeStyles; -@end - -// }}} -// {{{ API - -@implementation EdgeStylesModel - -+ (id) modelWithStyleManager:(StyleManager*)m { - return [[[self alloc] initWithStyleManager:m] autorelease]; -} - -- (id) init { - [self release]; - return nil; -} - -- (id) initWithStyleManager:(StyleManager*)m { - self = [super init]; - - if (self) { - store = gtk_list_store_new (EDGE_STYLES_N_COLS, - G_TYPE_STRING, - GDK_TYPE_PIXBUF, - G_TYPE_POINTER); - g_object_ref_sink (store); - - [self setStyleManager:m]; - } - - return self; -} - -- (void) dealloc { - [[NSNotificationCenter defaultCenter] removeObserver:self]; - - [self clearEdgeStylesModel]; - g_object_unref (store); - [styleManager release]; - - [super dealloc]; -} - -- (GtkTreeModel*) model { - return GTK_TREE_MODEL (store); -} - -- (StyleManager*) styleManager { - return styleManager; -} - -- (void) setStyleManager:(StyleManager*)m { - if (m == nil) { - [NSException raise:NSInvalidArgumentException format:@"Style manager cannot be nil"]; - } - [m retain]; - - [[NSNotificationCenter defaultCenter] removeObserver:self name:nil object:styleManager]; - [[NSNotificationCenter defaultCenter] addObserver:self - selector:@selector(edgeStylesReplaced:) - name:@"EdgeStylesReplaced" - object:m]; - [[NSNotificationCenter defaultCenter] addObserver:self - selector:@selector(edgeStyleAdded:) - name:@"EdgeStyleAdded" - object:m]; - [[NSNotificationCenter defaultCenter] addObserver:self - selector:@selector(edgeStyleRemoved:) - name:@"EdgeStyleRemoved" - object:m]; - - [styleManager release]; - styleManager = m; - - [self reloadEdgeStyles]; -} - -- (EdgeStyle*) styleFromPath:(GtkTreePath*)path { - GtkTreeIter iter; - gtk_tree_model_get_iter (GTK_TREE_MODEL (store), &iter, path); - EdgeStyle *style = nil; - gtk_tree_model_get (GTK_TREE_MODEL (store), &iter, EDGE_STYLES_PTR_COL, &style, -1); - return style; -} - -- (GtkTreePath*) pathFromStyle:(EdgeStyle*)style { - GtkTreeModel *m = GTK_TREE_MODEL (store); - GtkTreeIter row; - if (gtk_tree_model_get_iter_first (m, &row)) { - do { - EdgeStyle *rowStyle; - gtk_tree_model_get (m, &row, EDGE_STYLES_PTR_COL, &rowStyle, -1); - if (style == rowStyle) { - return gtk_tree_model_get_path (m, &row); - } - } while (gtk_tree_model_iter_next (m, &row)); - } - return NULL; -} - -- (EdgeStyle*) styleFromIter:(GtkTreeIter*)iter { - EdgeStyle *style = nil; - gtk_tree_model_get (GTK_TREE_MODEL (store), iter, EDGE_STYLES_PTR_COL, &style, -1); - return style; -} - -- (GtkTreeIter*) iterFromStyle:(EdgeStyle*)style { - GtkTreeModel *m = GTK_TREE_MODEL (store); - GtkTreeIter row; - if (gtk_tree_model_get_iter_first (m, &row)) { - do { - EdgeStyle *rowStyle; - gtk_tree_model_get (m, &row, EDGE_STYLES_PTR_COL, &rowStyle, -1); - if (style == rowStyle) { - return gtk_tree_iter_copy (&row); - } - } while (gtk_tree_model_iter_next (m, &row)); - } - return NULL; -} -@end - -// }}} -// {{{ Notifications - -@implementation EdgeStylesModel (Notifications) - -- (void) edgeStylesReplaced:(NSNotification*)notification { - [self reloadEdgeStyles]; -} - -- (void) edgeStyleAdded:(NSNotification*)notification { - [self addEdgeStyle:[[notification userInfo] objectForKey:@"style"]]; -} - -- (void) edgeStyleRemoved:(NSNotification*)notification { - EdgeStyle *style = [[notification userInfo] objectForKey:@"style"]; - - GtkTreeModel *model = GTK_TREE_MODEL (store); - GtkTreeIter row; - if (gtk_tree_model_get_iter_first (model, &row)) { - do { - EdgeStyle *rowStyle; - gtk_tree_model_get (model, &row, EDGE_STYLES_PTR_COL, &rowStyle, -1); - if (style == rowStyle) { - gtk_list_store_remove (store, &row); - [self stopObservingEdgeStyle:rowStyle]; - [rowStyle release]; - return; - } - } while (gtk_tree_model_iter_next (model, &row)); - } -} - -- (void) observeValueForKeyPath:(NSString*)keyPath - ofObject:(id)object - change:(NSDictionary*)change - context:(void*)context -{ - if ([object class] != [EdgeStyle class]) - return; - - EdgeStyle *style = object; - - GtkTreeModel *model = GTK_TREE_MODEL (store); - GtkTreeIter row; - if (gtk_tree_model_get_iter_first (model, &row)) { - do { - EdgeStyle *rowStyle; - gtk_tree_model_get (model, &row, EDGE_STYLES_PTR_COL, &rowStyle, -1); - if (style == rowStyle) { - if ([@"name" isEqual:keyPath]) { - gtk_list_store_set (store, &row, EDGE_STYLES_NAME_COL, [[style name] UTF8String], -1); - } else { - GdkPixbuf *pixbuf = [self pixbufOfEdgeInStyle:style]; - gtk_list_store_set (store, &row, EDGE_STYLES_ICON_COL, pixbuf, -1); - g_object_unref (pixbuf); - } - } - } while (gtk_tree_model_iter_next (model, &row)); - } -} -@end - -// }}} -// {{{ Private - -@implementation EdgeStylesModel (Private) -- (cairo_surface_t*) createEdgeIconSurface { - return cairo_image_surface_create (CAIRO_FORMAT_ARGB32, 48, 18); -} - -- (GdkPixbuf*) pixbufOfEdgeInStyle:(EdgeStyle*)style { - cairo_surface_t *surface = [self createEdgeIconSurface]; - GdkPixbuf *pixbuf = [self pixbufOfEdgeInStyle:style usingSurface:surface]; - cairo_surface_destroy (surface); - return pixbuf; -} - -- (GdkPixbuf*) pixbufOfEdgeInStyle:(EdgeStyle*)style usingSurface:(cairo_surface_t*)surface { - Transformer *transformer = [Transformer defaultTransformer]; - [transformer setFlippedAboutXAxis:YES]; - - int width = cairo_image_surface_get_width (surface); - int height = cairo_image_surface_get_height (surface); - NSRect pixbufBounds = NSMakeRect(0.0, 0.0, width, height); - NSRect graphBounds = [transformer rectFromScreen:pixbufBounds]; - - NSPoint start = NSMakePoint (NSMinX (graphBounds) + 0.1f, NSMidY (graphBounds)); - NSPoint end = NSMakePoint (NSMaxX (graphBounds) - 0.1f, NSMidY (graphBounds)); - Node *src = [Node nodeWithPoint:start]; - Node *tgt = [Node nodeWithPoint:end]; - Edge *e = [Edge edgeWithSource:src andTarget:tgt]; - [e setStyle:style]; - - CairoRenderContext *context = [[CairoRenderContext alloc] initForSurface:surface]; - [context clearSurface]; - [e renderBasicEdgeInContext:context withTransformer:transformer selected:NO]; - [context release]; - - return pixbuf_get_from_surface (surface); -} - -- (void) addEdgeStyle:(EdgeStyle*)style usingSurface:(cairo_surface_t*)surface { - GtkTreeIter iter; - gtk_list_store_append (store, &iter); - - GdkPixbuf *pixbuf = [self pixbufOfEdgeInStyle:style usingSurface:surface]; - gtk_list_store_set (store, &iter, - EDGE_STYLES_NAME_COL, [[style name] UTF8String], - EDGE_STYLES_ICON_COL, pixbuf, - EDGE_STYLES_PTR_COL, (gpointer)[style retain], - -1); - g_object_unref (pixbuf); - [self observeEdgeStyle:style]; -} - -- (void) addEdgeStyle:(EdgeStyle*)style { - cairo_surface_t *surface = [self createEdgeIconSurface]; - [self addEdgeStyle:style usingSurface:surface]; - cairo_surface_destroy (surface); -} - -- (void) observeEdgeStyle:(EdgeStyle*)style { - [style addObserver:self - forKeyPath:@"name" - options:NSKeyValueObservingOptionNew - context:NULL]; - [style addObserver:self - forKeyPath:@"thickness" - options:0 - context:NULL]; - [style addObserver:self - forKeyPath:@"headStyle" - options:0 - context:NULL]; - [style addObserver:self - forKeyPath:@"tailStyle" - options:0 - context:NULL]; - [style addObserver:self - forKeyPath:@"decorationStyle" - options:0 - context:NULL]; - [style addObserver:self - forKeyPath:@"colorRGB.red" - options:0 - context:NULL]; - [style addObserver:self - forKeyPath:@"colorRGB.green" - options:0 - context:NULL]; - [style addObserver:self - forKeyPath:@"colorRGB.blue" - options:0 - context:NULL]; -} - -- (void) stopObservingEdgeStyle:(EdgeStyle*)style { - [style removeObserver:self forKeyPath:@"name"]; - [style removeObserver:self forKeyPath:@"thickness"]; - [style removeObserver:self forKeyPath:@"headStyle"]; - [style removeObserver:self forKeyPath:@"tailStyle"]; - [style removeObserver:self forKeyPath:@"decorationStyle"]; - [style removeObserver:self forKeyPath:@"colorRGB.red"]; - [style removeObserver:self forKeyPath:@"colorRGB.green"]; - [style removeObserver:self forKeyPath:@"colorRGB.blue"]; -} - -- (void) clearEdgeStylesModel { - GtkTreeModel *model = GTK_TREE_MODEL (store); - GtkTreeIter row; - if (gtk_tree_model_get_iter_first (model, &row)) { - do { - EdgeStyle *rowStyle; - gtk_tree_model_get (model, &row, EDGE_STYLES_PTR_COL, &rowStyle, -1); - [self stopObservingEdgeStyle:rowStyle]; - [rowStyle release]; - } while (gtk_tree_model_iter_next (model, &row)); - } - gtk_list_store_clear (store); -} - -- (void) reloadEdgeStyles { - [self clearEdgeStylesModel]; - cairo_surface_t *surface = [self createEdgeIconSurface]; - for (EdgeStyle *style in [styleManager edgeStyles]) { - [self addEdgeStyle:style usingSurface:surface]; - } - cairo_surface_destroy (surface); -} -@end - -// }}} - -// vim:ft=objc:ts=8:et:sts=4:sw=4:foldmethod=marker diff --git a/tikzit/src/gtk/EdgeStylesPalette.h b/tikzit/src/gtk/EdgeStylesPalette.h deleted file mode 100644 index c0c6c4b..0000000 --- a/tikzit/src/gtk/EdgeStylesPalette.h +++ /dev/null @@ -1,43 +0,0 @@ -/* - * Copyright 2012 Alex Merry <dev@randomguy3.me.uk> - * - * 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 the Free Software Foundation; either version 2 of - * the License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see <http://www.gnu.org/licenses/>. - */ - -#import "TZFoundation.h" -#import <gtk/gtk.h> - -@class StyleManager; -@class EdgeStyleSelector; -@class EdgeStyleEditor; - -@interface EdgeStylesPalette: NSObject { - EdgeStyleSelector *selector; - EdgeStyleEditor *editor; - - GtkWidget *palette; - - GtkWidget *removeStyleButton; - GtkWidget *applyStyleButton; - GtkWidget *clearStyleButton; -} - -@property (retain) StyleManager *styleManager; -@property (readonly) GtkWidget *widget; - -- (id) initWithManager:(StyleManager*)m; - -@end - -// vim:ft=objc:ts=4:et:sts=4:sw=4:foldmethod=marker diff --git a/tikzit/src/gtk/EdgeStylesPalette.m b/tikzit/src/gtk/EdgeStylesPalette.m deleted file mode 100644 index 33264cf..0000000 --- a/tikzit/src/gtk/EdgeStylesPalette.m +++ /dev/null @@ -1,198 +0,0 @@ -/* - * Copyright 2012 Alex Merry <dev@randomguy3.me.uk> - * - * 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 the Free Software Foundation; either version 2 of - * the License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see <http://www.gnu.org/licenses/>. - */ - -#import "EdgeStylesPalette.h" - -#import "EdgeStylesModel.h" -#import "EdgeStyleSelector.h" -#import "EdgeStyleEditor.h" -#import "StyleManager.h" - -// {{{ Internal interfaces -// {{{ GTK+ Callbacks -static void add_style_button_cb (GtkButton *widget, EdgeStylesPalette *palette); -static void remove_style_button_cb (GtkButton *widget, EdgeStylesPalette *palette); -// }}} -// {{{ Notifications - -@interface EdgeStylesPalette (Notifications) -- (void) selectedStyleChanged:(NSNotification*)notification; -@end - -// }}} -// {{{ Private - -@interface EdgeStylesPalette (Private) -- (void) updateButtonState; -- (void) removeSelectedStyle; -- (void) addStyle; -@end - -// }}} -// }}} -// {{{ API - -@implementation EdgeStylesPalette - -@synthesize widget=palette; - -- (id) init { - [self release]; - return nil; -} - -- (id) initWithManager:(StyleManager*)m { - self = [super init]; - - if (self) { - selector = [[EdgeStyleSelector alloc] initWithStyleManager:m]; - editor = [[EdgeStyleEditor alloc] init]; - - palette = gtk_vbox_new (FALSE, 6); - gtk_container_set_border_width (GTK_CONTAINER (palette), 6); - g_object_ref_sink (palette); - - GtkWidget *mainBox = gtk_hbox_new (FALSE, 0); - gtk_box_pack_start (GTK_BOX (palette), mainBox, FALSE, FALSE, 0); - gtk_widget_show (mainBox); - - GtkWidget *selectorScroller = gtk_scrolled_window_new (NULL, NULL); - gtk_scrolled_window_set_policy (GTK_SCROLLED_WINDOW (selectorScroller), - GTK_POLICY_NEVER, - GTK_POLICY_AUTOMATIC); - GtkWidget *selectorFrame = gtk_frame_new (NULL); - gtk_container_add (GTK_CONTAINER (selectorScroller), [selector widget]); - gtk_container_add (GTK_CONTAINER (selectorFrame), selectorScroller); - gtk_box_pack_start (GTK_BOX (mainBox), selectorFrame, TRUE, TRUE, 0); - gtk_widget_show (selectorScroller); - gtk_widget_show (selectorFrame); - gtk_widget_show ([selector widget]); - - gtk_box_pack_start (GTK_BOX (mainBox), [editor widget], TRUE, TRUE, 0); - gtk_widget_show ([editor widget]); - - GtkBox *buttonBox = GTK_BOX (gtk_hbox_new(FALSE, 0)); - gtk_box_pack_start (GTK_BOX (palette), GTK_WIDGET (buttonBox), FALSE, FALSE, 0); - - GtkWidget *addStyleButton = gtk_button_new (); - gtk_widget_set_tooltip_text (addStyleButton, "Add a new style"); - GtkWidget *addIcon = gtk_image_new_from_stock (GTK_STOCK_ADD, GTK_ICON_SIZE_BUTTON); - gtk_container_add (GTK_CONTAINER (addStyleButton), addIcon); - gtk_box_pack_start (buttonBox, addStyleButton, FALSE, FALSE, 0); - g_signal_connect (G_OBJECT (addStyleButton), - "clicked", - G_CALLBACK (add_style_button_cb), - self); - - removeStyleButton = gtk_button_new (); - g_object_ref_sink (removeStyleButton); - gtk_widget_set_tooltip_text (removeStyleButton, "Delete selected style"); - GtkWidget *removeIcon = gtk_image_new_from_stock (GTK_STOCK_REMOVE, GTK_ICON_SIZE_BUTTON); - gtk_container_add (GTK_CONTAINER (removeStyleButton), removeIcon); - gtk_box_pack_start (buttonBox, removeStyleButton, FALSE, FALSE, 0); - g_signal_connect (G_OBJECT (removeStyleButton), - "clicked", - G_CALLBACK (remove_style_button_cb), - self); - - gtk_widget_show_all (GTK_WIDGET (buttonBox)); - - [[NSNotificationCenter defaultCenter] addObserver:self - selector:@selector(selectedStyleChanged:) - name:@"SelectedStyleChanged" - object:selector]; - - [self updateButtonState]; - } - - return self; -} - -- (StyleManager*) styleManager { - return [[selector model] styleManager]; -} - -- (void) setStyleManager:(StyleManager*)m { - [[selector model] setStyleManager:m]; -} - -- (void) dealloc { - [[NSNotificationCenter defaultCenter] removeObserver:self]; - - [editor release]; - [selector release]; - - g_object_unref (palette); - g_object_unref (removeStyleButton); - - [super dealloc]; -} - -@end - -// }}} -// {{{ Notifications - -@implementation EdgeStylesPalette (Notifications) -- (void) selectedStyleChanged:(NSNotification*)notification { - [editor setStyle:[selector selectedStyle]]; - [self updateButtonState]; -} -@end - -// }}} -// {{{ Private - -@implementation EdgeStylesPalette (Private) -- (void) updateButtonState { - gboolean hasStyleSelection = [selector selectedStyle] != nil; - gtk_widget_set_sensitive (removeStyleButton, hasStyleSelection); -} - -- (void) removeSelectedStyle { - EdgeStyle *style = [selector selectedStyle]; - if (style) - [[[selector model] styleManager] removeEdgeStyle:style]; -} - -- (void) addStyle { - EdgeStyle *newStyle = [EdgeStyle defaultEdgeStyleWithName:@"newstyle"]; - [[self styleManager] addEdgeStyle:newStyle]; - [selector setSelectedStyle:newStyle]; - [editor selectNameField]; -} - -@end - -// }}} -// {{{ GTK+ callbacks - -static void add_style_button_cb (GtkButton *widget, EdgeStylesPalette *palette) { - NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init]; - [palette addStyle]; - [pool drain]; -} - -static void remove_style_button_cb (GtkButton *widget, EdgeStylesPalette *palette) { - NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init]; - [palette removeSelectedStyle]; - [pool drain]; -} - -// }}} - -// vim:ft=objc:ts=8:et:sts=4:sw=4:foldmethod=marker diff --git a/tikzit/src/gtk/FileChooserDialog.h b/tikzit/src/gtk/FileChooserDialog.h deleted file mode 100644 index 80b03f5..0000000 --- a/tikzit/src/gtk/FileChooserDialog.h +++ /dev/null @@ -1,56 +0,0 @@ -/* - * Copyright 2011 Alex Merry <alex.merry@kdemail.net> - * - * 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 the Free Software Foundation; either version 2 of - * the License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see <http://www.gnu.org/licenses/>. - */ - -#import "TZFoundation.h" -#import <gtk/gtk.h> - -@interface FileChooserDialog: NSObject { - GtkFileChooser *dialog; -} - -+ (FileChooserDialog*) saveDialog; -+ (FileChooserDialog*) saveDialogWithParent:(GtkWindow*)parent; -+ (FileChooserDialog*) saveDialogWithTitle:(NSString*)title parent:(GtkWindow*)parent; -+ (FileChooserDialog*) openDialog; -+ (FileChooserDialog*) openDialogWithParent:(GtkWindow*)parent; -+ (FileChooserDialog*) openDialogWithTitle:(NSString*)title parent:(GtkWindow*)parent; - -- (id) initSaveDialog; -- (id) initSaveDialogWithParent:(GtkWindow*)parent; -- (id) initSaveDialogWithTitle:(NSString*)title parent:(GtkWindow*)parent; -- (id) initOpenDialog; -- (id) initOpenDialogWithParent:(GtkWindow*)parent; -- (id) initOpenDialogWithTitle:(NSString*)title parent:(GtkWindow*)parent; - -- (void) addStandardFilters; -- (void) addFileFilter:(NSString*)filterName withPattern:(NSString*)filePattern; -- (void) addFileFilter:(NSString*)filterName withPattern:(NSString*)filePattern setSelected:(BOOL)selected; - -- (void) setCurrentFolder:(NSString*)path; -- (NSString*) currentFolder; - -- (void) setSuggestedName:(NSString*)fileName; - -- (NSString*) filePath; - -- (BOOL) showDialog; - -- (void) destroy; - -@end - -// vim:ft=objc:ts=8:et:sts=4:sw=4 diff --git a/tikzit/src/gtk/FileChooserDialog.m b/tikzit/src/gtk/FileChooserDialog.m deleted file mode 100644 index 9498e4c..0000000 --- a/tikzit/src/gtk/FileChooserDialog.m +++ /dev/null @@ -1,152 +0,0 @@ -/* - * Copyright 2011 Alex Merry <alex.merry@kdemail.net> - * - * 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 the Free Software Foundation; either version 2 of - * the License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see <http://www.gnu.org/licenses/>. - */ - -#import "FileChooserDialog.h" - -@implementation FileChooserDialog: NSObject - -+ (FileChooserDialog*) saveDialog { return [[[self alloc] initSaveDialog] autorelease]; } -+ (FileChooserDialog*) saveDialogWithParent:(GtkWindow*)parent - { return [[[self alloc] initSaveDialogWithParent:parent] autorelease]; } -+ (FileChooserDialog*) saveDialogWithTitle:(NSString*)title parent:(GtkWindow*)parent - { return [[[self alloc] initSaveDialogWithTitle:title parent:parent] autorelease]; } -+ (FileChooserDialog*) openDialog { return [[[self alloc] initOpenDialog] autorelease]; } -+ (FileChooserDialog*) openDialogWithParent:(GtkWindow*)parent - { return [[[self alloc] initOpenDialogWithParent:parent] autorelease]; } -+ (FileChooserDialog*) openDialogWithTitle:(NSString*)title parent:(GtkWindow*)parent - { return [[[self alloc] initOpenDialogWithTitle:title parent:parent] autorelease]; } - -- (id) initSaveDialog { return [self initSaveDialogWithParent:NULL]; } -- (id) initSaveDialogWithParent:(GtkWindow*)parent - { return [self initSaveDialogWithTitle:@"Save file" parent:parent]; } -- (id) initSaveDialogWithTitle:(NSString*)title parent:(GtkWindow*)parent { - self = [super init]; - - if (self) { - dialog = GTK_FILE_CHOOSER (gtk_file_chooser_dialog_new ( - [title UTF8String], - parent, - GTK_FILE_CHOOSER_ACTION_SAVE, - GTK_STOCK_CANCEL, GTK_RESPONSE_CANCEL, - GTK_STOCK_SAVE, GTK_RESPONSE_ACCEPT, - NULL)); - gtk_file_chooser_set_do_overwrite_confirmation (dialog, TRUE); - } - - return self; -} - -- (id) initOpenDialog { return [self initOpenDialogWithParent:NULL]; } -- (id) initOpenDialogWithParent:(GtkWindow*)parent - { return [self initOpenDialogWithTitle:@"Open file" parent:parent]; } -- (id) initOpenDialogWithTitle:(NSString*)title parent:(GtkWindow*)parent { - self = [super init]; - - if (self) { - dialog = GTK_FILE_CHOOSER (gtk_file_chooser_dialog_new ( - [title UTF8String], - parent, - GTK_FILE_CHOOSER_ACTION_OPEN, - GTK_STOCK_CANCEL, GTK_RESPONSE_CANCEL, - GTK_STOCK_OPEN, GTK_RESPONSE_ACCEPT, - NULL)); - } - - return self; -} - -- (void) addStandardFilters { - GtkFileFilter *tikzfilter = gtk_file_filter_new(); - gtk_file_filter_set_name(tikzfilter, ".tikz files"); - gtk_file_filter_add_pattern(tikzfilter, "*.tikz"); - gtk_file_chooser_add_filter(dialog, tikzfilter); - GtkFileFilter *allfilter = gtk_file_filter_new(); - gtk_file_filter_set_name(allfilter, "all files"); - gtk_file_filter_add_pattern(allfilter, "*"); - gtk_file_chooser_add_filter(dialog, allfilter); - gtk_file_chooser_set_filter(dialog, tikzfilter); -} - -- (void) addFileFilter:(NSString*)filterName withPattern:(NSString*)filePattern { - [self addFileFilter:filterName withPattern:filePattern setSelected:NO]; -} - -- (void) addFileFilter:(NSString*)filterName withPattern:(NSString*)filePattern setSelected:(BOOL)selected { - GtkFileFilter *oldFilter = selected ? NULL : gtk_file_chooser_get_filter (dialog); - GtkFileFilter *filter = gtk_file_filter_new(); - gtk_file_filter_set_name(filter, [filterName UTF8String]); - gtk_file_filter_add_pattern(filter, [filePattern UTF8String]); - gtk_file_chooser_add_filter(dialog, filter); - if (selected) { - gtk_file_chooser_set_filter (dialog, filter); - } else if (oldFilter) { - gtk_file_chooser_set_filter (dialog, oldFilter); - } -} - -- (void) setCurrentFolder:(NSString*)path { - gchar *folder = [path glibFilename]; - if (folder) { - gtk_file_chooser_set_current_folder(dialog, folder); - g_free (folder); - } -} - -- (NSString*) currentFolder { - NSString *path = nil; - gchar *folder = gtk_file_chooser_get_current_folder(dialog); - if (folder) { - path = [NSString stringWithGlibFilename:folder]; - g_free (folder); - } - return path; -} - -- (void) setSuggestedName:(NSString*)fileName { - gtk_file_chooser_set_current_name (GTK_FILE_CHOOSER (dialog), [fileName UTF8String]); -} - -- (NSString*) filePath { - NSString *path = nil; - gchar *filename = gtk_file_chooser_get_filename (GTK_FILE_CHOOSER (dialog)); - if (filename) { - path = [NSString stringWithGlibFilename:filename]; - g_free (filename); - } - return path; -} - -- (BOOL) showDialog { - return (gtk_dialog_run (GTK_DIALOG (dialog)) == GTK_RESPONSE_ACCEPT) ? YES : NO; -} - -- (void) destroy { - gtk_widget_destroy (GTK_WIDGET (dialog)); - dialog = NULL; -} - -- (void) dealloc { - if (dialog) { - g_warning ("Failed to destroy file chooser dialog!\n"); - gtk_widget_destroy (GTK_WIDGET (dialog)); - } - [super dealloc]; -} - -@end - -// vim:ft=objc:ts=8:et:sts=4:sw=4 diff --git a/tikzit/src/gtk/GraphEditorPanel.h b/tikzit/src/gtk/GraphEditorPanel.h deleted file mode 100644 index 2b93259..0000000 --- a/tikzit/src/gtk/GraphEditorPanel.h +++ /dev/null @@ -1,53 +0,0 @@ -/* - * Copyright 2012 Alex Merry <alex.merry@kdemail.net> - * - * 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 the Free Software Foundation; either version 2 of - * the License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see <http://www.gnu.org/licenses/>. - */ - -#import "TZFoundation.h" -#import "Tool.h" -#import <gtk/gtk.h> - -@class GraphInputHandler; -@class GraphRenderer; -@class TikzDocument; -@class WidgetSurface; - -@protocol PreviewHandler <NSObject> -- (void) showPreview; -@end -@interface GraphEditorPanel : NSObject { - GraphRenderer *renderer; - WidgetSurface *surface; - GraphInputHandler *inputHandler; - id<PreviewHandler> previewHandler; - id<Tool> tool; -} -@property (retain) TikzDocument *document; -@property (readonly) GtkWidget *widget; -@property (retain) id<Tool> activeTool; -@property (assign) id<PreviewHandler> previewHandler; - -- (id) init; -- (id) initWithDocument:(TikzDocument*)document; -- (void) grabTool; -- (void) zoomInAboutPoint:(NSPoint)pos; -- (void) zoomOutAboutPoint:(NSPoint)pos; -- (void) zoomIn; -- (void) zoomOut; -- (void) zoomReset; - -@end - -// vim:ft=objc:ts=8:et:sts=4:sw=4 diff --git a/tikzit/src/gtk/GraphEditorPanel.m b/tikzit/src/gtk/GraphEditorPanel.m deleted file mode 100644 index c87e53e..0000000 --- a/tikzit/src/gtk/GraphEditorPanel.m +++ /dev/null @@ -1,211 +0,0 @@ -/* - * Copyright 2012 Alex Merry <alex.merry@kdemail.net> - * - * 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 the Free Software Foundation; either version 2 of - * the License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see <http://www.gnu.org/licenses/>. - */ - -#import "GraphEditorPanel.h" - -#import "Application.h" -#import "GraphRenderer.h" -#import "HandTool.h" -#import "InputDelegate.h" -#import "TikzDocument.h" -#import "WidgetSurface.h" - -#import <gdk/gdkkeysyms.h> - -@class GraphRenderer; -@class WidgetSurface; - -/** - * Mostly just a multiplexer - */ -@interface GraphInputHandler : NSObject<InputDelegate> { - GraphEditorPanel *panel; -} -- (id) initForPanel:(GraphEditorPanel*)p; -@end - -@implementation GraphEditorPanel - -@synthesize previewHandler; - -- (id) init { - return [self initWithDocument:nil]; -} -- (id) initWithDocument:(TikzDocument*)document { - self = [super init]; - if (self) { - surface = [[WidgetSurface alloc] init]; - [surface setDefaultScale:50.0f]; - [surface setKeepCentered:YES]; - [surface setCanFocus:YES]; - renderer = [[GraphRenderer alloc] initWithSurface:surface document:document]; - - inputHandler = [[GraphInputHandler alloc] initForPanel:self]; - [surface setInputDelegate:inputHandler]; - } - return self; -} - -- (void) dealloc { - [renderer release]; - [surface release]; - [inputHandler release]; - - [super dealloc]; -} - -- (TikzDocument*) document { - return [renderer document]; -} -- (void) setDocument:(TikzDocument*)doc { - [renderer setDocument:doc]; -} -- (GtkWidget*) widget { - return [surface widget]; -} -- (id<Tool>) activeTool { - return tool; -} -- (void) setActiveTool:(id<Tool>)t { - if (t == tool) - return; - - [[[renderer document] pickSupport] deselectAllNodes]; - [[[renderer document] pickSupport] deselectAllEdges]; - - BOOL hadOldTool = ([tool activeRenderer] == renderer); - - id oldTool = tool; - tool = [t retain]; - [oldTool release]; - - if (hadOldTool) { - [self grabTool]; - } -} - -- (BOOL) hasTool { - return [tool activeRenderer] == renderer; -} - -- (void) grabTool { - if ([tool activeRenderer] != renderer) { - [[tool activeRenderer] setPostRenderer:nil]; - [tool setActiveRenderer:renderer]; - } - [renderer setPostRenderer:tool]; -} - -- (void) zoomInAboutPoint:(NSPoint)pos { [surface zoomInAboutPoint:pos]; } -- (void) zoomOutAboutPoint:(NSPoint)pos { [surface zoomOutAboutPoint:pos]; } -- (void) zoomIn { [surface zoomIn]; } -- (void) zoomOut { [surface zoomOut]; } -- (void) zoomReset { [surface zoomReset]; } - -@end - -@implementation GraphInputHandler -- (id) initForPanel:(GraphEditorPanel*)p { - self = [super init]; - if (self) { - // NB: no retention! - panel = p; - } - return self; -} -- (id) init { - [self release]; - return nil; -} -- (void) dealloc { - [super dealloc]; -} - -// FIXME: use a local copy of HandTool to implement CTRL-dragging -- (void) mousePressAt:(NSPoint)pos withButton:(MouseButton)button andMask:(InputMask)mask { - [panel grabTool]; - id<Tool> tool = [panel activeTool]; - if ([tool respondsToSelector:@selector(mousePressAt:withButton:andMask:)]) { - [tool mousePressAt:pos withButton:button andMask:mask]; - } -} - -- (void) mouseDoubleClickAt:(NSPoint)pos withButton:(MouseButton)button andMask:(InputMask)mask { - [panel grabTool]; - id<Tool> tool = [panel activeTool]; - if ([tool respondsToSelector:@selector(mouseDoubleClickAt:withButton:andMask:)]) { - [tool mouseDoubleClickAt:pos withButton:button andMask:mask]; - } -} - -- (void) mouseReleaseAt:(NSPoint)pos withButton:(MouseButton)button andMask:(InputMask)mask { - if (![panel hasTool]) - return; - id<Tool> tool = [panel activeTool]; - if ([tool respondsToSelector:@selector(mouseReleaseAt:withButton:andMask:)]) { - [tool mouseReleaseAt:pos withButton:button andMask:mask]; - } -} - -- (void) mouseMoveTo:(NSPoint)pos withButtons:(MouseButton)buttons andMask:(InputMask)mask { - if (![panel hasTool]) - return; - id<Tool> tool = [panel activeTool]; - if ([tool respondsToSelector:@selector(mouseMoveTo:withButtons:andMask:)]) { - [tool mouseMoveTo:pos withButtons:buttons andMask:mask]; - } -} - -- (void) mouseScrolledAt:(NSPoint)pos inDirection:(ScrollDirection)dir withMask:(InputMask)mask { - id<Tool> tool = [panel activeTool]; - if (mask == ControlMask) { - if (dir == ScrollUp) { - [panel zoomInAboutPoint:pos]; - } else if (dir == ScrollDown) { - [panel zoomOutAboutPoint:pos]; - } - } else if ([panel hasTool] && [tool respondsToSelector:@selector(mouseScrolledAt:inDirection:withMask:)]) { - [tool mouseScrolledAt:pos inDirection:dir withMask:mask]; - } -} - -- (void) keyPressed:(unsigned int)keyVal withMask:(InputMask)mask { - if (keyVal == GDK_KEY_space && !mask) { - return; - } - if (![app activateToolForKey:keyVal withMask:mask]) { - id<Tool> tool = [panel activeTool]; - if ([panel hasTool] && [tool respondsToSelector:@selector(keyPressed:withMask:)]) { - [tool keyPressed:keyVal withMask:mask]; - } - } -} - -- (void) keyReleased:(unsigned int)keyVal withMask:(InputMask)mask { - if (keyVal == GDK_KEY_space && !mask) { - [[panel previewHandler] showPreview]; - } - if (![app activateToolForKey:keyVal withMask:mask]) { - id<Tool> tool = [panel activeTool]; - if ([panel hasTool] && [tool respondsToSelector:@selector(keyReleased:withMask:)]) { - [tool keyReleased:keyVal withMask:mask]; - } - } -} -@end - -// vim:ft=objc:ts=8:et:sts=4:sw=4 diff --git a/tikzit/src/gtk/GraphRenderer.h b/tikzit/src/gtk/GraphRenderer.h deleted file mode 100644 index 730d606..0000000 --- a/tikzit/src/gtk/GraphRenderer.h +++ /dev/null @@ -1,84 +0,0 @@ -/* - * Copyright 2011 Alex Merry <dev@randomguy3.me.uk> - * - * 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 the Free Software Foundation; either version 2 of - * the License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see <http://www.gnu.org/licenses/>. - */ - -#import "TZFoundation.h" -#import <gtk/gtk.h> - -// classes -#import "Graph.h" -#import "Grid.h" -#import "PickSupport.h" -#import "TikzDocument.h" - -// protocols -#import "Surface.h" - -@interface GraphRenderer: NSObject <RenderDelegate> { - TikzDocument *doc; - NSObject<Surface> *surface; - Grid *grid; - NSMutableSet *highlightedNodes; - id<RenderDelegate> postRenderer; -} - -@property (retain) id<RenderDelegate> postRenderer; - -- (id) initWithSurface:(NSObject <Surface> *)surface; -- (id) initWithSurface:(NSObject <Surface> *)surface document:(TikzDocument*)document; -- (void) renderWithContext:(id<RenderContext>)context; -- (void) invalidateRect:(NSRect)rect; -- (void) invalidateGraph; -- (void) invalidateNode:(Node*)node; -- (void) invalidateEdge:(Edge*)edge; -- (void) invalidateNodesHitBy:(NSPoint)point; -- (BOOL) point:(NSPoint)p hitsNode:(Node*)node; -- (BOOL) point:(NSPoint)p hitsEdge:(Edge*)edge withFuzz:(float)fuzz; -/** - * Finds a node at the given screen location. - * - * If there is more than one node at this point (because they overlap), - * an arbitrary one is returned. - */ -- (Node*) anyNodeAt:(NSPoint)p; -/** - * Finds an edge at the given screen location. - * - * If there is more than one edge at this point (because they overlap), - * an arbitrary one is returned. - * - * @param fuzz the fuzz for detecting edges: this will pick up - * edges that are close to the point - */ -- (Edge*) anyEdgeAt:(NSPoint)p withFuzz:(float)fuzz; - -- (id<Surface>) surface; -- (Transformer*) transformer; -- (Grid*) grid; -- (PickSupport*) pickSupport; - -- (Graph*) graph; - -- (TikzDocument*) document; -- (void) setDocument:(TikzDocument*)document; - -- (BOOL) isNodeHighlighted:(Node*)node; -- (void) setNode:(Node*)node highlighted:(BOOL)h; -- (void) clearHighlightedNodes; - -@end - -// vim:ft=objc:ts=8:et:sts=4:sw=4 diff --git a/tikzit/src/gtk/GraphRenderer.m b/tikzit/src/gtk/GraphRenderer.m deleted file mode 100644 index 278f245..0000000 --- a/tikzit/src/gtk/GraphRenderer.m +++ /dev/null @@ -1,465 +0,0 @@ -/* - * Copyright 2011 Alex Merry <alex.merry@kdemail.net> - * Copyright 2010 Chris Heunen - * - * 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 the Free Software Foundation; either version 2 of - * the License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see <http://www.gnu.org/licenses/>. - */ - -#import "GraphRenderer.h" -#import "Edge+Render.h" -#import "Node+Render.h" - -void graph_renderer_expose_event(GtkWidget *widget, GdkEventExpose *event); - -@interface GraphRenderer (Private) -- (enum NodeState) nodeState:(Node*)node; -- (void) renderBoundingBoxWithContext:(id<RenderContext>)context; -- (void) nodeNeedsRefreshing:(NSNotification*)notification; -- (void) edgeNeedsRefreshing:(NSNotification*)notification; -- (void) graphNeedsRefreshing:(NSNotification*)notification; -- (void) graphChanged:(NSNotification*)notification; -- (void) nodeStylePropertyChanged:(NSNotification*)notification; -- (void) edgeStylePropertyChanged:(NSNotification*)notification; -@end - -@implementation GraphRenderer - -- (id) initWithSurface:(NSObject <Surface> *)s { - self = [super init]; - - if (self) { - surface = [s retain]; - grid = [[Grid alloc] initWithSpacing:1.0f subdivisions:4 transformer:[s transformer]]; - highlightedNodes = [[NSMutableSet alloc] initWithCapacity:10]; - [surface setRenderDelegate:self]; - - [[NSNotificationCenter defaultCenter] addObserver:self - selector:@selector(nodeStylePropertyChanged:) - name:@"NodeStylePropertyChanged" - object:nil]; - [[NSNotificationCenter defaultCenter] addObserver:self - selector:@selector(edgeStylePropertyChanged:) - name:@"EdgeStylePropertyChanged" - object:nil]; - } - - return self; -} - -- (id) initWithSurface:(NSObject <Surface> *)s document:(TikzDocument*)document { - self = [self initWithSurface:s]; - - if (self) { - [self setDocument:document]; - } - - return self; -} - -- (void) dealloc { - [[NSNotificationCenter defaultCenter] removeObserver:self]; - [doc release]; - [grid release]; - [highlightedNodes release]; - [surface release]; - - [super dealloc]; -} - -- (id<RenderDelegate>) postRenderer { - return postRenderer; -} -- (void) setPostRenderer:(id<RenderDelegate>)r { - if (r == postRenderer) - return; - - [r retain]; - [postRenderer release]; - postRenderer = r; - - [self invalidateGraph]; -} - -- (void) renderWithContext:(id<RenderContext>)context onSurface:(id<Surface>)s { - [self renderWithContext:context]; - if ([s hasFocus]) { - [s renderFocus]; - } -} - -- (void) renderWithContext:(id<RenderContext>)context { - // blank surface - [context paintWithColor:WhiteRColor]; - - // draw grid - [grid renderGridInContext:context]; - - // draw edges - NSEnumerator *enumerator = [doc edgeEnumerator]; - Edge *edge; - while ((edge = [enumerator nextObject]) != nil) { - [edge renderToSurface:surface withContext:context selected:[doc isEdgeSelected:edge]]; - } - - // draw nodes - enumerator = [doc nodeEnumerator]; - Node *node; - while ((node = [enumerator nextObject]) != nil) { - [node renderToSurface:surface withContext:context state:[self nodeState:node]]; - } - - [self renderBoundingBoxWithContext:context]; - [postRenderer renderWithContext:context onSurface:surface]; -} - -- (void) invalidateGraph { - [surface invalidate]; -} - -- (void) invalidateRect:(NSRect)rect { - [surface invalidateRect:rect]; -} - -- (void) invalidateNodes:(NSSet*)nodes { - for (Node *node in nodes) { - [self invalidateNode:node]; - } -} - -- (void) invalidateEdges:(NSSet*)edges { - for (Edge *edge in edges) { - [self invalidateEdge:edge]; - } -} - -- (void) invalidateNode:(Node*)node { - if (node == nil) { - return; - } - NSRect nodeRect = [node renderBoundsWithLabelForSurface:surface]; - nodeRect = NSInsetRect (nodeRect, -2.0f, -2.0f); - [surface invalidateRect:nodeRect]; -} - -- (void) invalidateEdge:(Edge*)edge { - if (edge == nil) { - return; - } - BOOL selected = [doc isEdgeSelected:edge]; - NSRect edgeRect = [edge renderedBoundsWithTransformer:[surface transformer] whenSelected:selected]; - edgeRect = NSInsetRect (edgeRect, -2.0f, -2.0f); - [surface invalidateRect:edgeRect]; -} - -- (void) invalidateNodesHitBy:(NSPoint)point { - NSEnumerator *enumerator = [doc nodeEnumerator]; - Node *node = nil; - while ((node = [enumerator nextObject]) != nil) { - if ([self point:point hitsNode:node]) { - [self invalidateNode:node]; - } - } -} - -- (BOOL) point:(NSPoint)p hitsNode:(Node*)node { - return [node hitByPoint:p onSurface:surface]; -} - -- (BOOL) point:(NSPoint)p fuzzyHitsNode:(Node*)node { - NSRect bounds = [node renderBoundsForSurface:surface]; - return NSPointInRect(p, bounds); -} - -- (BOOL) point:(NSPoint)p hitsEdge:(Edge*)edge withFuzz:(float)fuzz { - return [edge hitByPoint:p onSurface:surface withFuzz:fuzz]; -} - -- (Node*) anyNodeAt:(NSPoint)p { - NSEnumerator *enumerator = [doc nodeEnumerator]; - Node *node; - while ((node = [enumerator nextObject]) != nil) { - if ([self point:p hitsNode:node]) { - return node; - } - } - return nil; -} - -- (Edge*) anyEdgeAt:(NSPoint)p withFuzz:(float)fuzz { - // FIXME: is there an efficient way to find the "nearest" edge - // if the fuzz is the reason we hit more than one? - NSEnumerator *enumerator = [doc edgeEnumerator]; - Edge *edge; - while ((edge = [enumerator nextObject]) != nil) { - if ([self point:p hitsEdge:edge withFuzz:fuzz]) { - return edge; - } - } - return nil; -} - -- (id<Surface>) surface { - return surface; -} - -- (Transformer*) transformer { - return [surface transformer]; -} - -- (Grid*) grid { - return grid; -} - -- (PickSupport*) pickSupport { - return [doc pickSupport]; -} - -- (Graph*) graph { - return [doc graph]; -} - -- (TikzDocument*) document { - return doc; -} - -- (void) setDocument:(TikzDocument*)document { - if (doc == document) { - return; - } - - if (doc != nil) { - [[NSNotificationCenter defaultCenter] removeObserver:self name:nil object:doc]; - [[NSNotificationCenter defaultCenter] removeObserver:self name:nil object:[doc pickSupport]]; - } - - [document retain]; - [doc release]; - doc = document; - - if (doc != nil) { - [[NSNotificationCenter defaultCenter] - addObserver:self - selector:@selector(graphNeedsRefreshing:) - name:@"GraphReplaced" object:doc]; - [[NSNotificationCenter defaultCenter] - addObserver:self - selector:@selector(graphChanged:) - name:@"GraphChanged" object:doc]; - [[NSNotificationCenter defaultCenter] - addObserver:self - selector:@selector(graphChanged:) - name:@"GraphBeingChanged" object:doc]; - [[NSNotificationCenter defaultCenter] - addObserver:self - selector:@selector(graphChanged:) - name:@"GraphChangeCancelled" object:doc]; - [[NSNotificationCenter defaultCenter] - addObserver:self - selector:@selector(nodeNeedsRefreshing:) - name:@"NodeSelected" object:[doc pickSupport]]; - [[NSNotificationCenter defaultCenter] - addObserver:self - selector:@selector(nodeNeedsRefreshing:) - name:@"NodeDeselected" object:[doc pickSupport]]; - [[NSNotificationCenter defaultCenter] - addObserver:self - selector:@selector(graphNeedsRefreshing:) - name:@"NodeSelectionReplaced" object:[doc pickSupport]]; - [[NSNotificationCenter defaultCenter] - addObserver:self - selector:@selector(edgeNeedsRefreshing:) - name:@"EdgeSelected" object:[doc pickSupport]]; - [[NSNotificationCenter defaultCenter] - addObserver:self - selector:@selector(edgeNeedsRefreshing:) - name:@"EdgeDeselected" object:[doc pickSupport]]; - [[NSNotificationCenter defaultCenter] - addObserver:self - selector:@selector(graphNeedsRefreshing:) - name:@"EdgeSelectionReplaced" object:[doc pickSupport]]; - } - [surface invalidate]; -} - -- (BOOL) isNodeHighlighted:(Node*)node { - return [highlightedNodes containsObject:node]; -} -- (void) setNode:(Node*)node highlighted:(BOOL)h { - if (h) { - if (![highlightedNodes containsObject:node]) { - [highlightedNodes addObject:node]; - [self invalidateNode:node]; - } - } else { - if ([highlightedNodes containsObject:node]) { - [highlightedNodes removeObject:node]; - [self invalidateNode:node]; - } - } -} -- (void) clearHighlightedNodes { - [self invalidateNodes:highlightedNodes]; - [highlightedNodes removeAllObjects]; -} - -@end - -@implementation GraphRenderer (Private) -- (enum NodeState) nodeState:(Node*)node { - if ([doc isNodeSelected:node]) { - return NodeSelected; - } else if ([self isNodeHighlighted:node]) { - return NodeHighlighted; - } else { - return NodeNormal; - } -} - -- (void) renderBoundingBoxWithContext:(id<RenderContext>)context { - if ([[self graph] hasBoundingBox]) { - [context saveState]; - - NSRect bbox = [[surface transformer] rectToScreen:[[self graph] boundingBox]]; - - [context setAntialiasMode:AntialiasDisabled]; - [context setLineWidth:1.0]; - [context startPath]; - [context rect:bbox]; - [context strokePathWithColor:MakeSolidRColor (1.0, 0.7, 0.5)]; - - [context restoreState]; - } -} - -- (void) nodeNeedsRefreshing:(NSNotification*)notification { - [self invalidateNode:[[notification userInfo] objectForKey:@"node"]]; -} - -- (void) edgeNeedsRefreshing:(NSNotification*)notification { - Edge *edge = [[notification userInfo] objectForKey:@"edge"]; - NSRect edgeRect = [edge renderedBoundsWithTransformer:[surface transformer] whenSelected:YES]; - edgeRect = NSInsetRect (edgeRect, -2, -2); - [surface invalidateRect:edgeRect]; -} - -- (void) graphNeedsRefreshing:(NSNotification*)notification { - [self invalidateGraph]; -} - -- (void) invalidateBentIncidentEdgesForNode:(Node*)nd { - for (Edge *e in [[self graph] inEdgesForNode:nd]) { - if (![e isStraight]) { - [self invalidateEdge:e]; - } - } - for (Edge *e in [[self graph] outEdgesForNode:nd]) { - if (![e isStraight]) { - [self invalidateEdge:e]; - } - } -} - -- (void) graphChanged:(NSNotification*)notification { - GraphChange *change = [[notification userInfo] objectForKey:@"change"]; - switch ([change changeType]) { - case GraphAddition: - case GraphDeletion: - [self invalidateNodes:[change affectedNodes]]; - [self invalidateEdges:[change affectedEdges]]; - break; - case NodePropertyChange: - if (!NSEqualPoints ([[change oldNode] point], [[change nwNode] point])) { - // if the node has moved, it may be affecting edges - [surface invalidate]; - } else if ([[change oldNode] style] != [[change nwNode] style]) { - // change in style means that edges may touch at a different point, - // but this only matters for bent edges - [self invalidateBentIncidentEdgesForNode:[change nodeRef]]; - // invalide both old and new (old node may be larger) - [self invalidateNode:[change oldNode]]; - [self invalidateNode:[change nwNode]]; - } else { - // invalide both old and new (old node may be larger) - [self invalidateNode:[change oldNode]]; - [self invalidateNode:[change nwNode]]; - } - break; - case EdgePropertyChange: - // invalide both old and new (old bend may increase bounds) - [self invalidateEdge:[change oldEdge]]; - [self invalidateEdge:[change nwEdge]]; - [self invalidateEdge:[change edgeRef]]; - break; - case NodesPropertyChange: - { - NSEnumerator *enumerator = [[change oldNodeTable] keyEnumerator]; - Node *node = nil; - while ((node = [enumerator nextObject]) != nil) { - NSPoint oldPos = [[[change oldNodeTable] objectForKey:node] point]; - NSPoint newPos = [[[change nwNodeTable] objectForKey:node] point]; - NodeStyle *oldStyle = [[[change oldNodeTable] objectForKey:node] style]; - NodeStyle *newStyle = [[[change nwNodeTable] objectForKey:node] style]; - if (!NSEqualPoints (oldPos, newPos)) { - [surface invalidate]; - break; - } else if (oldStyle != newStyle) { - [self invalidateBentIncidentEdgesForNode:node]; - [self invalidateNode:[[change oldNodeTable] objectForKey:node]]; - [self invalidateNode:[[change nwNodeTable] objectForKey:node]]; - } else { - [self invalidateNode:[[change oldNodeTable] objectForKey:node]]; - [self invalidateNode:[[change nwNodeTable] objectForKey:node]]; - } - } - } - break; - case NodesShift: - case NodesFlip: - case BoundingBoxChange: - [surface invalidate]; - break; - default: - // unknown change - [surface invalidate]; - break; - }; -} - -- (void) nodeStylePropertyChanged:(NSNotification*)notification { - if (![@"name" isEqual:[[notification userInfo] objectForKey:@"propertyName"]]) { - BOOL affected = NO; - for (Node *node in [[self graph] nodes]) { - if ([node style] == [notification object]) - affected = YES; - } - if (affected) - [surface invalidate]; - } -} - -- (void) edgeStylePropertyChanged:(NSNotification*)notification { - if (![@"name" isEqual:[[notification userInfo] objectForKey:@"propertyName"]]) { - BOOL affected = NO; - for (Edge *edge in [[self graph] edges]) { - if ([edge style] == [notification object]) - affected = YES; - } - if (affected) - [surface invalidate]; - } -} - -@end - -// vim:ft=objc:ts=8:et:sts=4:sw=4 diff --git a/tikzit/src/gtk/HandTool.h b/tikzit/src/gtk/HandTool.h deleted file mode 100644 index c96de36..0000000 --- a/tikzit/src/gtk/HandTool.h +++ /dev/null @@ -1,33 +0,0 @@ -/* - * Copyright 2012 Alex Merry <alex.merry@kdemail.net> - * - * 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 the Free Software Foundation; either version 2 of - * the License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see <http://www.gnu.org/licenses/>. - */ - -#import "TZFoundation.h" -#import "Tool.h" - -@interface HandTool : NSObject <Tool> { - GraphRenderer *renderer; - NSPoint dragOrigin; - NSPoint oldGraphOrigin; -} - - -+ (id) tool; -- (id) init; -@end - - -// vim:ft=objc:ts=8:et:sts=4:sw=4 diff --git a/tikzit/src/gtk/HandTool.m b/tikzit/src/gtk/HandTool.m deleted file mode 100644 index c3a0fb4..0000000 --- a/tikzit/src/gtk/HandTool.m +++ /dev/null @@ -1,75 +0,0 @@ -/* - * Copyright 2011-2012 Alex Merry <alex.merry@kdemail.net> - * - * 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 the Free Software Foundation; either version 2 of - * the License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see <http://www.gnu.org/licenses/>. - */ - -#import "HandTool.h" - -#import "GraphRenderer.h" -#import "TikzDocument.h" -#import "tzstockitems.h" - -@implementation HandTool -- (NSString*) name { return @"Drag"; } -- (const gchar*) stockId { return TIKZIT_STOCK_DRAG; } -- (NSString*) helpText { return @"Move the diagram to view different parts"; } -- (NSString*) shortcut { return @"m"; } -@synthesize activeRenderer=renderer; - -+ (id) tool { - return [[[self alloc] init] autorelease]; -} - -- (id) init { - return [super init]; -} - -- (void) dealloc { - [[NSNotificationCenter defaultCenter] removeObserver:self]; - - [renderer release]; - - [super dealloc]; -} - -- (GtkWidget*) configurationWidget { return NULL; } - -- (void) mousePressAt:(NSPoint)pos withButton:(MouseButton)button andMask:(InputMask)mask { - if (button != LeftButton) - return; - - dragOrigin = pos; - oldGraphOrigin = [[renderer transformer] origin]; -} - -- (void) mouseMoveTo:(NSPoint)pos withButtons:(MouseButton)buttons andMask:(InputMask)mask { - if (!(buttons & LeftButton)) - return; - - NSPoint newGraphOrigin = oldGraphOrigin; - newGraphOrigin.x += pos.x - dragOrigin.x; - newGraphOrigin.y += pos.y - dragOrigin.y; - [[renderer transformer] setOrigin:newGraphOrigin]; - [renderer invalidateGraph]; -} - -- (void) mouseReleaseAt:(NSPoint)pos withButton:(MouseButton)button andMask:(InputMask)mask {} - -- (void) renderWithContext:(id<RenderContext>)context onSurface:(id<Surface>)surface {} -- (void) loadConfiguration:(Configuration*)config {} -- (void) saveConfiguration:(Configuration*)config {} -@end - -// vim:ft=objc:ts=8:et:sts=4:sw=4 diff --git a/tikzit/src/gtk/InputDelegate.h b/tikzit/src/gtk/InputDelegate.h deleted file mode 100644 index 9f9b426..0000000 --- a/tikzit/src/gtk/InputDelegate.h +++ /dev/null @@ -1,77 +0,0 @@ -/* - * Copyright 2011 Alex Merry <alex.merry@kdemail.net> - * - * 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 the Free Software Foundation; either version 2 of - * the License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see <http://www.gnu.org/licenses/>. - */ - -#import "TZFoundation.h" - -typedef enum { - LeftButton = 1, - MiddleButton = 2, - RightButton = 3, - Button4 = 4, - Button5 = 5 -} MouseButton; - -typedef enum { - ShiftMask = 1, - ControlMask = 2, - MetaMask = 4 -} InputMask; - -typedef enum { - ScrollUp = 1, - ScrollDown = 2, - ScrollLeft = 3, - ScrollRight = 4, -} ScrollDirection; - -@protocol InputDelegate <NSObject> -@optional -/** - * A mouse button was pressed. - */ -- (void) mousePressAt:(NSPoint)pos withButton:(MouseButton)button andMask:(InputMask)mask; -/** - * A mouse button was released. - */ -- (void) mouseReleaseAt:(NSPoint)pos withButton:(MouseButton)button andMask:(InputMask)mask; -/** - * A mouse button was double-clicked. - * - * Note that mouseDown and mouseUp events will still be delivered. - * This will be triggered between the second mouseDown and the second - * mouseUp. - */ -- (void) mouseDoubleClickAt:(NSPoint)pos withButton:(MouseButton)button andMask:(InputMask)mask; -/** - * The mouse was moved - */ -- (void) mouseMoveTo:(NSPoint)pos withButtons:(MouseButton)button andMask:(InputMask)mask; -/** - * The mouse was scrolled - */ -- (void) mouseScrolledAt:(NSPoint)pos inDirection:(ScrollDirection)dir withMask:(InputMask)mask; -/** - * A key was pressed - */ -- (void) keyPressed:(unsigned int)keyVal withMask:(InputMask)mask; -/** - * A key was released - */ -- (void) keyReleased:(unsigned int)keyVal withMask:(InputMask)mask; -@end - -// vim:ft=objc:ts=8:et:sts=4:sw=4 diff --git a/tikzit/src/gtk/Menu.h b/tikzit/src/gtk/Menu.h deleted file mode 100644 index e0f78d4..0000000 --- a/tikzit/src/gtk/Menu.h +++ /dev/null @@ -1,86 +0,0 @@ -/* - * Copyright 2011 Alex Merry <alex.merry@kdemail.net> - * - * 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 the Free Software Foundation; either version 2 of - * the License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see <http://www.gnu.org/licenses/>. - */ - -#import "TZFoundation.h" -#import <gtk/gtk.h> - -@class Window; -@class PickSupport; - -/** - * Manages the menu - */ -@interface Menu: NSObject { - GtkWidget *menubar; - GtkActionGroup *appActions; - GtkActionGroup *windowActions; - GtkAction *undoAction; // no ref - GtkAction *redoAction; // no ref - GtkAction *pasteAction; // no ref - GtkAction **nodeSelBasedActions; - guint nodeSelBasedActionCount; - GtkAction **edgeSelBasedActions; - guint edgeSelBasedActionCount; - GtkAction **selBasedActions; - guint selBasedActionCount; -} - -/** - * The menubar widget, to be inserted into the window - */ -@property (readonly) GtkWidget *menubar; - -/** - * Constructs the menu for @p window - * - * @param window the window that will be acted upon - */ -- (id) initForWindow:(Window*)window; - -/** - * Enables or disables the undo action - */ -- (void) setUndoActionEnabled:(BOOL)enabled; -/** - * Sets the text that describes what action will be undone - * - * @param detail a text description of the action, or nil - */ -- (void) setUndoActionDetail:(NSString*)detail; -/** - * Enables or disables the redo action - */ -- (void) setRedoActionEnabled:(BOOL)enabled; -/** - * Sets the text that describes what action will be redone - * - * @param detail a text description of the action, or nil - */ -- (void) setRedoActionDetail:(NSString*)detail; - -/** - * Gets the paste action - */ -- (GtkAction*) pasteAction; - -/** - * Enables or disables the actions that act on a selection - */ -- (void) notifySelectionChanged:(PickSupport*)pickSupport; -@end - -// vim:ft=objc:ts=8:et:sts=4:sw=4 diff --git a/tikzit/src/gtk/Menu.m b/tikzit/src/gtk/Menu.m deleted file mode 100644 index 04c9c31..0000000 --- a/tikzit/src/gtk/Menu.m +++ /dev/null @@ -1,737 +0,0 @@ -/* - * Copyright 2011 Alex Merry <alex.merry@kdemail.net> - * - * Stuff stolen from glade-window.c in Glade: - * Copyright (C) 2001 Ximian, Inc. - * Copyright (C) 2007 Vincent Geddes. - * - * 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 the Free Software Foundation; either version 2 of - * the License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see <http://www.gnu.org/licenses/>. - */ - -#import "Menu.h" - -#import "Application.h" -#import "Window.h" -#import "Configuration.h" -#import "PickSupport.h" -#import "Shape.h" -#import "Tool.h" -#import "TikzDocument.h" - -#import <glib.h> -#ifdef _ -#undef _ -#endif -#import <glib/gi18n.h> -#import <gtk/gtk.h> - -#import "gtkhelpers.h" - -#import "logo.h" - -// {{{ Application actions -static void new_cb (GtkAction *action, Application *appl) { - NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init]; - [appl newWindow]; - [pool drain]; -} - -static void refresh_shapes_cb (GtkAction *action, Application *appl) { - NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init]; - [Shape refreshShapeDictionary]; - [pool drain]; -} - -static void show_preferences_cb (GtkAction *action, Application *appl) { - NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init]; - [appl presentSettingsDialog]; - [pool drain]; -} - -#ifdef HAVE_POPPLER -static void show_preamble_cb (GtkAction *action, Application *appl) { - NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init]; - [appl presentPreamblesEditor]; - [pool drain]; -} -#endif - -static void show_context_window_cb (GtkAction *action, Application *appl) { - NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init]; - [appl presentContextWindow]; - [pool drain]; -} - -static void quit_cb (GtkAction *action, Application *appl) { - NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init]; - [appl quit]; - [pool drain]; -} - -static void help_cb (GtkAction *action, Application *appl) { - GError *gerror = NULL; - gtk_show_uri (NULL, "http://tikzit.sourceforge.net/manual.html", GDK_CURRENT_TIME, &gerror); - if (gerror != NULL) { - NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init]; - logGError (gerror, @"Could not show help"); - [pool drain]; - } -} - -static void about_cb (GtkAction *action, Application *appl) { - static const gchar * const authors[] = - { "Aleks Kissinger <aleks0@gmail.com>", - "Chris Heunen <chrisheunen@gmail.com>", - "Alex Merry <dev@randomguy3.me.uk>", - NULL }; - - static const gchar license[] = - N_("TikZiT is free software; you can redistribute it and/or modify " - "it under the terms of the GNU General Public License as " - "published by the Free Software Foundation; either version 2 of the " - "License, or (at your option) any later version." - "\n\n" - "TikZiT is distributed in the hope that it will be useful, " - "but WITHOUT ANY WARRANTY; without even the implied warranty of " - "MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the " - "GNU General Public License for more details." - "\n\n" - "You should have received a copy of the GNU General Public License " - "along with TikZiT; if not, write to the Free Software " - "Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, " - "MA 02110-1301, USA."); - - static const gchar copyright[] = - "Copyright \xc2\xa9 2010-2011 Aleks Kissinger, Chris Heunen and Alex Merry."; - - GdkPixbuf *logo = get_logo (LOGO_SIZE_128); - gtk_show_about_dialog (NULL, - "program-name", PACKAGE_NAME, - "logo", logo, - "authors", authors, - "translator-credits", _("translator-credits"), - "comments", _("A graph manipulation program for pgf/tikz graphs"), - "license", _(license), - "wrap-license", TRUE, - "copyright", copyright, - "version", PACKAGE_VERSION, - "website", "http://tikzit.sourceforge.net", - NULL); - g_object_unref (logo); -} - -static GtkActionEntry app_action_entries[] = { - /* - Fields: - * action name - * stock id or name of icon for action - * label for action (mark for translation with N_) - * accelerator (as understood by gtk_accelerator_parse()) - * tooltip (mark for translation with N_) - * callback - */ - { "New", GTK_STOCK_NEW, NULL, "<control>N", - N_("Create a new graph"), G_CALLBACK (new_cb) }, - - { "RefreshShapes", NULL, N_("_Refresh shapes"), NULL, - N_(""), G_CALLBACK (refresh_shapes_cb) }, - - { "Quit", GTK_STOCK_QUIT, NULL, "<control>Q", - N_("Quit the program"), G_CALLBACK (quit_cb) }, - - { "Tool", NULL, N_("_Tool") }, - - { "ShowPreferences", GTK_STOCK_PREFERENCES, N_("Configure TikZiT..."), NULL, - N_("Edit the TikZiT configuration"), G_CALLBACK (show_preferences_cb) }, - -#ifdef HAVE_POPPLER - { "ShowPreamble", NULL, N_("_Edit Preambles..."), NULL, - N_("Edit the preambles used to generate the preview"), G_CALLBACK (show_preamble_cb) }, -#endif - - { "ShowContextWindow", NULL, N_("_Context Window"), NULL, - N_("Show the contextual tools window"), G_CALLBACK (show_context_window_cb) }, - - /* HelpMenu */ - { "HelpManual", GTK_STOCK_HELP, N_("_Online manual"), "F1", - N_("TikZiT manual (online)"), G_CALLBACK (help_cb) }, - - { "About", GTK_STOCK_ABOUT, NULL, NULL, - N_("About this application"), G_CALLBACK (about_cb) }, -}; -static guint n_app_action_entries = G_N_ELEMENTS (app_action_entries); -// }}} -// {{{ Window actions - -static void open_cb (GtkAction *action, Window *window) { - NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init]; - [window openFile]; - [pool drain]; -} - -static void close_cb (GtkAction *action, Window *window) { - NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init]; - [window close]; - [pool drain]; -} - -static void save_cb (GtkAction *action, Window *window) { - NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init]; - [window saveActiveDocument]; - [pool drain]; -} - -static void save_as_cb (GtkAction *action, Window *window) { - NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init]; - [window saveActiveDocumentAs]; - [pool drain]; -} - -static void save_as_shape_cb (GtkAction *action, Window *window) { - NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init]; - [window saveActiveDocumentAsShape]; - [pool drain]; -} - -static void undo_cb (GtkAction *action, Window *window) { - NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init]; - - TikzDocument *document = [window document]; - if ([document canUndo]) { - [document undo]; - } else { - g_warning ("Can't undo!\n"); - gtk_action_set_sensitive (action, FALSE); - } - - [pool drain]; -} - -static void redo_cb (GtkAction *action, Window *window) { - NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init]; - - TikzDocument *document = [window document]; - if ([document canRedo]) { - [document redo]; - } else { - g_warning ("Can't redo!\n"); - gtk_action_set_sensitive (action, FALSE); - } - - [pool drain]; -} - -static void cut_cb (GtkAction *action, Window *window) { - NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init]; - [window selectionCutToClipboard]; - [pool drain]; -} - -static void copy_cb (GtkAction *action, Window *window) { - NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init]; - [window selectionCopyToClipboard]; - [pool drain]; -} - -static void paste_cb (GtkAction *action, Window *window) { - NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init]; - [window pasteFromClipboard]; - [pool drain]; -} - -static void delete_cb (GtkAction *action, Window *window) { - NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init]; - [[window document] removeSelected]; - [pool drain]; -} - -static void select_all_cb (GtkAction *action, Window *window) { - NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init]; - TikzDocument *document = [window document]; - [[document pickSupport] selectAllNodes:[NSSet setWithArray:[[document graph] nodes]]]; - [pool drain]; -} - -static void deselect_all_cb (GtkAction *action, Window *window) { - NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init]; - TikzDocument *document = [window document]; - [[document pickSupport] deselectAllNodes]; - [[document pickSupport] deselectAllEdges]; - [pool drain]; -} - -static void flip_horiz_cb (GtkAction *action, Window *window) { - NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init]; - [[window document] flipSelectedNodesHorizontally]; - [pool drain]; -} - -static void flip_vert_cb (GtkAction *action, Window *window) { - NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init]; - [[window document] flipSelectedNodesVertically]; - [pool drain]; -} - -static void reverse_edges_cb (GtkAction *action, Window *window) { - NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init]; - [[window document] reverseSelectedEdges]; - [pool drain]; -} - -static void bring_forward_cb (GtkAction *action, Window *window) { - NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init]; - [[window document] bringSelectionForward]; - [pool drain]; -} - -static void send_backward_cb (GtkAction *action, Window *window) { - NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init]; - [[window document] sendSelectionBackward]; - [pool drain]; -} - -static void bring_to_front_cb (GtkAction *action, Window *window) { - NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init]; - [[window document] bringSelectionToFront]; - [pool drain]; -} - -static void send_to_back_cb (GtkAction *action, Window *window) { - NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init]; - [[window document] sendSelectionToBack]; - [pool drain]; -} - -#ifdef HAVE_POPPLER -static void show_preview_cb (GtkAction *action, Window *window) { - NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init]; - [window presentPreview]; - [pool drain]; -} -#endif - -static void zoom_in_cb (GtkAction *action, Window *window) { - NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init]; - [window zoomIn]; - [pool drain]; -} - -static void zoom_out_cb (GtkAction *action, Window *window) { - NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init]; - [window zoomOut]; - [pool drain]; -} - -static void zoom_reset_cb (GtkAction *action, Window *window) { - NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init]; - [window zoomReset]; - [pool drain]; -} - -static void recent_chooser_item_activated_cb (GtkRecentChooser *chooser, Window *window) { - NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init]; - - gchar *uri, *path; - GError *error = NULL; - - uri = gtk_recent_chooser_get_current_uri (chooser); - - path = g_filename_from_uri (uri, NULL, NULL); - if (error) { - g_warning ("Could not convert uri \"%s\" to a local path: %s", uri, error->message); - g_error_free (error); - return; - } - - [window openFileAtPath:[NSString stringWithGlibFilename:path]]; - - g_free (uri); - g_free (path); - - [pool drain]; -} - - -static GtkActionEntry window_action_entries[] = { - /* - Fields: - * action name - * stock id or name of icon for action - * label for action (mark for translation with N_) - * accelerator (as understood by gtk_accelerator_parse()) - * tooltip (mark for translation with N_) - * callback - */ - { "FileMenu", NULL, N_("_File") }, - { "EditMenu", NULL, N_("_Edit") }, - { "ViewMenu", NULL, N_("_View") }, - { "HelpMenu", NULL, N_("_Help") }, - - { "Arrange", NULL, N_("_Arrange") }, - { "Zoom", NULL, N_("_Zoom") }, - - { "Open", GTK_STOCK_OPEN, N_("_Open\342\200\246") ,"<control>O", - N_("Open a graph"), G_CALLBACK (open_cb) }, - - { "Close", GTK_STOCK_CLOSE, NULL, "<control>W", - N_("Close the current graph"), G_CALLBACK (close_cb) }, - - { "ZoomIn", GTK_STOCK_ZOOM_IN, NULL, "<control>plus", - NULL, G_CALLBACK (zoom_in_cb) }, - - { "ZoomOut", GTK_STOCK_ZOOM_OUT, NULL, "<control>minus", - NULL, G_CALLBACK (zoom_out_cb) }, - - { "ZoomReset", GTK_STOCK_ZOOM_100, N_("_Reset zoom"), "<control>0", - NULL, G_CALLBACK (zoom_reset_cb) }, - - { "Save", GTK_STOCK_SAVE, NULL, "<control>S", - N_("Save the current graph"), G_CALLBACK (save_cb) }, - - { "SaveAs", GTK_STOCK_SAVE_AS, N_("Save _As\342\200\246"), NULL, - N_("Save the current graph with a different name"), G_CALLBACK (save_as_cb) }, - - { "SaveAsShape", NULL, N_("Save As S_hape\342\200\246"), NULL, - N_("Save the current graph as a shape for use in styles"), G_CALLBACK (save_as_shape_cb) }, - - { "Undo", GTK_STOCK_UNDO, NULL, "<control>Z", - N_("Undo the last action"), G_CALLBACK (undo_cb) }, - - { "Redo", GTK_STOCK_REDO, NULL, "<shift><control>Z", - N_("Redo the last action"), G_CALLBACK (redo_cb) }, - - { "Cut", GTK_STOCK_CUT, NULL, NULL, - N_("Cut the selection"), G_CALLBACK (cut_cb) }, - - { "Copy", GTK_STOCK_COPY, NULL, NULL, - N_("Copy the selection"), G_CALLBACK (copy_cb) }, - - { "Paste", GTK_STOCK_PASTE, NULL, NULL, - N_("Paste the clipboard"), G_CALLBACK (paste_cb) }, - - { "Delete", GTK_STOCK_DELETE, NULL, "Delete", - N_("Delete the selection"), G_CALLBACK (delete_cb) }, - - { "SelectAll", GTK_STOCK_SELECT_ALL, NULL, "<control>A", - N_("Select all nodes on the graph"), G_CALLBACK (select_all_cb) }, - - { "DeselectAll", NULL, N_("D_eselect all"), "<shift><control>A", - N_("Deselect everything"), G_CALLBACK (deselect_all_cb) }, - - { "FlipHoriz", NULL, N_("Flip nodes _horizonally"), NULL, - N_("Flip the selected nodes horizontally"), G_CALLBACK (flip_horiz_cb) }, - - { "FlipVert", NULL, N_("Flip nodes _vertically"), NULL, - N_("Flip the selected nodes vertically"), G_CALLBACK (flip_vert_cb) }, - - { "ReverseEdges", NULL, N_("Rever_se edges"), NULL, - N_("Reverse the selected edges"), G_CALLBACK (reverse_edges_cb) }, - - { "SendToBack", NULL, N_("Send to _back"), NULL, - N_("Send the selected nodes and edges to the back of the graph"), G_CALLBACK (send_to_back_cb) }, - - { "SendBackward", NULL, N_("Send b_ackward"), NULL, - N_("Send the selected nodes and edges backward"), G_CALLBACK (send_backward_cb) }, - - { "BringForward", NULL, N_("Bring f_orward"), NULL, - N_("Bring the selected nodes and edges forward"), G_CALLBACK (bring_forward_cb) }, - - { "BringToFront", NULL, N_("Bring to _front"), NULL, - N_("Bring the selected nodes and edges to the front of the graph"), G_CALLBACK (bring_to_front_cb) }, - - /* ViewMenu */ -#ifdef HAVE_POPPLER - { "ShowPreview", NULL, N_("_Preview"), "<control>L", - N_("See the graph as it will look when rendered in LaTeX"), G_CALLBACK (show_preview_cb) }, -#endif -}; -static guint n_window_action_entries = G_N_ELEMENTS (window_action_entries); - -// }}} -// {{{ UI XML - -static const gchar ui_info[] = -"<ui>" -" <menubar name='MenuBar'>" -" <menu action='FileMenu'>" -" <menuitem action='New'/>" -" <menuitem action='Open'/>" -" <menuitem action='OpenRecent'/>" -" <separator/>" -" <menuitem action='Save'/>" -" <menuitem action='SaveAs'/>" -" <separator/>" -" <menuitem action='SaveAsShape'/>" -" <menuitem action='RefreshShapes'/>" -" <separator/>" -" <menuitem action='Close'/>" -" <menuitem action='Quit'/>" -" </menu>" -" <menu action='EditMenu'>" -" <menu action='Tool'>" -" </menu>" -" <separator/>" -" <menuitem action='Undo'/>" -" <menuitem action='Redo'/>" -" <separator/>" -" <menuitem action='Cut'/>" -" <menuitem action='Copy'/>" -" <menuitem action='Paste'/>" -" <menuitem action='Delete'/>" -" <separator/>" -" <menuitem action='SelectAll'/>" -" <menuitem action='DeselectAll'/>" -" <separator/>" -" <menuitem action='FlipVert'/>" -" <menuitem action='FlipHoriz'/>" -" <menuitem action='ReverseEdges'/>" -" <separator/>" -" <menu action='Arrange'>" -" <menuitem action='SendToBack'/>" -" <menuitem action='SendBackward'/>" -" <menuitem action='BringForward'/>" -" <menuitem action='BringToFront'/>" -" </menu>" -" <separator/>" -" <menuitem action='ShowPreferences'/>" -" </menu>" -" <menu action='ViewMenu'>" -" <menuitem action='ShowContextWindow'/>" -#ifdef HAVE_POPPLER -" <menuitem action='ShowPreamble'/>" -" <menuitem action='ShowPreview'/>" -#endif -" <menu action='Zoom'>" -" <menuitem action='ZoomIn'/>" -" <menuitem action='ZoomOut'/>" -" <menuitem action='ZoomReset'/>" -" </menu>" -" </menu>" -" <menu action='HelpMenu'>" -" <menuitem action='HelpManual'/>" -" <separator/>" -" <menuitem action='About'/>" -" </menu>" -" </menubar>" -/* -" <toolbar name='ToolBar'>" -" <toolitem action='New'/>" -" <toolitem action='Open'/>" -" <toolitem action='Save'/>" -" <separator/>" -" <toolitem action='Cut'/>" -" <toolitem action='Copy'/>" -" <toolitem action='Paste'/>" -" <separator/>" -" <toolitem action='SelectMode'/>" -" <toolitem action='CreateNodeMode'/>" -" <toolitem action='DrawEdgeMode'/>" -" <toolitem action='BoundingBoxMode'/>" -" <toolitem action='HandMode'/>" -" </toolbar>" -*/ -"</ui>"; - - - -// }}} -// {{{ Helper methods - -static void configure_recent_chooser (GtkRecentChooser *chooser) -{ - gtk_recent_chooser_set_local_only (chooser, TRUE); - gtk_recent_chooser_set_show_icons (chooser, FALSE); - gtk_recent_chooser_set_sort_type (chooser, GTK_RECENT_SORT_MRU); - - GtkRecentFilter *filter = gtk_recent_filter_new (); - gtk_recent_filter_add_application (filter, g_get_application_name()); - gtk_recent_chooser_set_filter (chooser, filter); -} - -static void tool_cb (GtkAction *action, id<Tool> tool) { - NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init]; - [app setActiveTool:tool]; - [pool drain]; -} - - - -// }}} -// {{{ API - -@implementation Menu - -- (id) init { - [self release]; - return nil; -} - -- (id) initForWindow:(Window*)window { - self = [super init]; - if (!self) { - return nil; - } - - GError *error = NULL; - - appActions = gtk_action_group_new ("TZApp"); - //gtk_action_group_set_translation_domain (actions, GETTEXT_PACKAGE); - gtk_action_group_add_actions (appActions, - app_action_entries, - n_app_action_entries, - app); - for (id<Tool> tool in [app tools]) { - NSString *tooltip = [NSString stringWithFormat: - @"%@: %@ (%@)", [tool name], [tool helpText], [tool shortcut]]; - GtkAction *action = gtk_action_new ( - [[tool name] UTF8String], - [[tool name] UTF8String], - [tooltip UTF8String], - [tool stockId]); - gtk_action_group_add_action_with_accel ( - appActions, - action, - NULL); - g_signal_connect ( - G_OBJECT (action), - "activate", - G_CALLBACK (tool_cb), - tool); - g_object_unref (action); - } - - windowActions = gtk_action_group_new ("TZWindow"); - //gtk_action_group_set_translation_domain (windowActions, GETTEXT_PACKAGE); - - gtk_action_group_add_actions (windowActions, - window_action_entries, - n_window_action_entries, - window); - - GtkAction *action = gtk_recent_action_new ("OpenRecent", N_("Open _Recent"), NULL, NULL); - g_signal_connect (G_OBJECT (action), - "item-activated", - G_CALLBACK (recent_chooser_item_activated_cb), - window); - configure_recent_chooser (GTK_RECENT_CHOOSER (action)); - gtk_action_group_add_action_with_accel (windowActions, action, NULL); - g_object_unref (action); - - /* Save refs to actions that will need to be updated */ - undoAction = gtk_action_group_get_action (windowActions, "Undo"); - redoAction = gtk_action_group_get_action (windowActions, "Redo"); - pasteAction = gtk_action_group_get_action (windowActions, "Paste"); - - nodeSelBasedActionCount = 4; - nodeSelBasedActions = g_new (GtkAction*, nodeSelBasedActionCount); - nodeSelBasedActions[0] = gtk_action_group_get_action (windowActions, "Cut"); - nodeSelBasedActions[1] = gtk_action_group_get_action (windowActions, "Copy"); - nodeSelBasedActions[2] = gtk_action_group_get_action (windowActions, "FlipHoriz"); - nodeSelBasedActions[3] = gtk_action_group_get_action (windowActions, "FlipVert"); - edgeSelBasedActionCount = 1; - edgeSelBasedActions = g_new (GtkAction*, edgeSelBasedActionCount); - edgeSelBasedActions[0] = gtk_action_group_get_action (windowActions, "ReverseEdges"); - selBasedActionCount = 2; - selBasedActions = g_new (GtkAction*, selBasedActionCount); - selBasedActions[0] = gtk_action_group_get_action (windowActions, "Delete"); - selBasedActions[1] = gtk_action_group_get_action (windowActions, "DeselectAll"); - - - GtkUIManager *ui = gtk_ui_manager_new (); - gtk_ui_manager_insert_action_group (ui, windowActions, 0); - gtk_ui_manager_insert_action_group (ui, appActions, 1); - gtk_window_add_accel_group ([window gtkWindow], gtk_ui_manager_get_accel_group (ui)); - if (!gtk_ui_manager_add_ui_from_string (ui, ui_info, -1, &error)) - { - g_message ("Building menus failed: %s", error->message); - g_error_free (error); - g_object_unref (ui); - [self release]; - return nil; - } - guint tool_merge_id = gtk_ui_manager_new_merge_id (ui); - for (id<Tool> tool in [app tools]) { - gtk_ui_manager_add_ui (ui, - tool_merge_id, - "/ui/MenuBar/EditMenu/Tool", - [[tool name] UTF8String], - [[tool name] UTF8String], - GTK_UI_MANAGER_AUTO, - FALSE); - } - menubar = gtk_ui_manager_get_widget (ui, "/MenuBar"); - g_object_ref_sink (menubar); - g_object_unref (ui); - - return self; -} - -- (void) dealloc { - g_free (nodeSelBasedActions); - g_free (edgeSelBasedActions); - g_free (selBasedActions); - g_object_unref (menubar); - g_object_unref (appActions); - g_object_unref (windowActions); - - [super dealloc]; -} - -@synthesize menubar; - -- (void) setUndoActionEnabled:(BOOL)enabled { - gtk_action_set_sensitive (undoAction, enabled); -} - -- (void) setUndoActionDetail:(NSString*)detail { - gtk_action_set_detailed_label (undoAction, "_Undo", [detail UTF8String]); -} - -- (void) setRedoActionEnabled:(BOOL)enabled { - gtk_action_set_sensitive (redoAction, enabled); -} - -- (void) setRedoActionDetail:(NSString*)detail { - gtk_action_set_detailed_label (redoAction, "_Redo", [detail UTF8String]); -} - -- (GtkAction*) pasteAction { - return pasteAction; -} - -- (void) notifySelectionChanged:(PickSupport*)pickSupport { - BOOL hasSelectedNodes = [[pickSupport selectedNodes] count] > 0; - BOOL hasSelectedEdges = [[pickSupport selectedEdges] count] > 0; - for (int i = 0; i < nodeSelBasedActionCount; ++i) { - if (nodeSelBasedActions[i]) { - gtk_action_set_sensitive (nodeSelBasedActions[i], hasSelectedNodes); - } - } - for (int i = 0; i < edgeSelBasedActionCount; ++i) { - if (edgeSelBasedActions[i]) { - gtk_action_set_sensitive (edgeSelBasedActions[i], hasSelectedEdges); - } - } - for (int i = 0; i < selBasedActionCount; ++i) { - if (selBasedActions[i]) { - gtk_action_set_sensitive (selBasedActions[i], hasSelectedNodes || hasSelectedEdges); - } - } -} - -@end - -// }}} - -// vim:ft=objc:ts=8:et:sts=4:sw=4:foldmethod=marker diff --git a/tikzit/src/gtk/NSError+Glib.h b/tikzit/src/gtk/NSError+Glib.h deleted file mode 100644 index 137977e..0000000 --- a/tikzit/src/gtk/NSError+Glib.h +++ /dev/null @@ -1,28 +0,0 @@ -/* - * Copyright 2011 Alex Merry <alex.merry@kdemail.net> - * - * 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 the Free Software Foundation; either version 2 of - * the License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see <http://www.gnu.org/licenses/>. - */ - -#import <Foundation/Foundation.h> -#import <glib.h> - -@interface NSError(Glib) -+ (id) errorWithGError:(GError*)gerror; -@end - -void GErrorToNSError(GError *errorIn, NSError **errorOut); -void logGError (GError *error, NSString *message); - -// vim:ft=objc:ts=8:et:sts=4:sw=4 diff --git a/tikzit/src/gtk/NSError+Glib.m b/tikzit/src/gtk/NSError+Glib.m deleted file mode 100644 index f466d9e..0000000 --- a/tikzit/src/gtk/NSError+Glib.m +++ /dev/null @@ -1,50 +0,0 @@ -/* - * Copyright 2011 Alex Merry <alex.merry@kdemail.net> - * - * 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 the Free Software Foundation; either version 2 of - * the License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see <http://www.gnu.org/licenses/>. - */ - -#import "NSError+Glib.h" -#import "TZFoundation.h" - -@implementation NSError(Glib) -+ (id) errorWithGError:(GError*)gerror { - if (!gerror) - return nil; - - NSString *message = [NSString stringWithUTF8String:gerror->message]; - NSString *domain = [NSString stringWithUTF8String:g_quark_to_string(gerror->domain)]; - - NSMutableDictionary *errorDetail = [NSMutableDictionary dictionaryWithObject:message - forKey:NSLocalizedDescriptionKey]; - return [self errorWithDomain:domain code:gerror->code userInfo:errorDetail]; -} -@end - -void GErrorToNSError(GError *errorIn, NSError **errorOut) -{ - if (errorOut && errorIn) { - *errorOut = [NSError errorWithGError:errorIn]; - } -} - -void logGError (GError *error, NSString *message) { - if (message == nil) { - NSLog (@"%s", error->message); - } else { - NSLog (@"%@: %s", message, error->message); - } -} - -// vim:ft=objc:ts=8:et:sts=4:sw=4 diff --git a/tikzit/src/gtk/NSFileManager+Glib.h b/tikzit/src/gtk/NSFileManager+Glib.h deleted file mode 100644 index cb49fcb..0000000 --- a/tikzit/src/gtk/NSFileManager+Glib.h +++ /dev/null @@ -1,31 +0,0 @@ -/* - * Copyright 2011 Alex Merry <alex.merry@kdemail.net> - * - * 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 the Free Software Foundation; either version 2 of - * the License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see <http://www.gnu.org/licenses/>. - */ - -#import <Foundation/Foundation.h> - -@interface NSFileManager(Glib) -/** - * Creates a directory in the system temp directory - */ -- (NSString*) createTempDirectoryWithError:(NSError**)error; -/** - * Creates a directory in the system temp directory - */ -- (NSString*) createTempDirectory; -@end - -// vim:ft=objc:ts=8:et:sts=4:sw=4 diff --git a/tikzit/src/gtk/NSFileManager+Glib.m b/tikzit/src/gtk/NSFileManager+Glib.m deleted file mode 100644 index b3e9de6..0000000 --- a/tikzit/src/gtk/NSFileManager+Glib.m +++ /dev/null @@ -1,55 +0,0 @@ -/* - * Copyright 2011 Alex Merry <alex.merry@kdemail.net> - * - * 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 the Free Software Foundation; either version 2 of - * the License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see <http://www.gnu.org/licenses/>. - */ - -#import "NSFileManager+Glib.h" -#import "TZFoundation.h" -#import "mkdtemp.h" - -@implementation NSFileManager(Glib) - -- (NSString*) createTempDirectoryWithError:(NSError**)error { - NSString *result = nil; -#if GLIB_CHECK_VERSION (2, 30, 0) - GError *gerror = NULL; - gchar *dir = g_dir_make_tmp ("tikzitXXXXXX", &gerror); - GErrorToNSError (gerror, error); - if (dir) - result = [NSString stringWithGlibFilename:dir]; - g_free (dir); -#else -//#if (!GLIB_CHECK_VERSION (2, 26, 0)) -#define g_mkdtemp mkdtemp -//#endif - gchar *dir = g_build_filename (g_get_tmp_dir(), "tikzitXXXXXX", NULL); - gchar *rdir = g_mkdtemp (dir); - if (rdir) { - result = [NSString stringWithGlibFilename:dir]; - } else if (error) { - *error = [NSError errorWithLibcError:errno]; - } - g_free (dir); -#endif - return result; -} - -- (NSString*) createTempDirectory { - return [self createTempDirectoryWithError:NULL]; -} - -@end - -// vim:ft=objc:ts=8:et:sts=4:sw=4 diff --git a/tikzit/src/gtk/NSString+Glib.h b/tikzit/src/gtk/NSString+Glib.h deleted file mode 100644 index ac59833..0000000 --- a/tikzit/src/gtk/NSString+Glib.h +++ /dev/null @@ -1,50 +0,0 @@ -/* - * Copyright 2011 Alex Merry <alex.merry@kdemail.net> - * - * 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 the Free Software Foundation; either version 2 of - * the License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see <http://www.gnu.org/licenses/>. - */ - -#import <Foundation/Foundation.h> -#import <glib.h> - -@interface NSString(Glib) -/** - * Initialise a string with a string in the GLib filename encoding - */ -- (id) initWithGlibFilename:(const gchar *)filename; -/** - * Create a string from a string in the GLib filename encoding - */ -+ (id) stringWithGlibFilename:(const gchar *)filename; -/** - * Get a copy of the string in GLib filename encoding. - * - * This will need to be freed with g_free. - */ -- (gchar*)glibFilename; -/** - * Get a copy of the string as a GLib URI - * - * This will need to be freed with g_free. - */ -- (gchar*)glibUriWithError:(NSError**)error; -/** - * Get a copy of the string as a GLib URI - * - * This will need to be freed with g_free. - */ -- (gchar*)glibUri; -@end - -// vim:ft=objc:ts=8:et:sts=4:sw=4 diff --git a/tikzit/src/gtk/NSString+Glib.m b/tikzit/src/gtk/NSString+Glib.m deleted file mode 100644 index b6dc765..0000000 --- a/tikzit/src/gtk/NSString+Glib.m +++ /dev/null @@ -1,96 +0,0 @@ -/* - * Copyright 2011 Alex Merry <alex.merry@kdemail.net> - * - * 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 the Free Software Foundation; either version 2 of - * the License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see <http://www.gnu.org/licenses/>. - */ - -#import "NSString+Glib.h" -#import "TZFoundation.h" - -@implementation NSString(Glib) -+ (id) stringWithGlibFilename:(const gchar *)filename { - return [[[self alloc] initWithGlibFilename:filename] autorelease]; -} - -- (id) initWithGlibFilename:(const gchar *)filename { - if (self == nil) { - return nil; - } - - if (filename == NULL) { - [self release]; - return nil; - } - - GError *error = NULL; - gchar *utf8file = g_filename_to_utf8 (filename, -1, NULL, NULL, &error); - if (utf8file == NULL) { - if (error) - logGError (error, @"Failed to convert a GLib filename to UTF8"); - [self release]; - return nil; - } - - self = [self initWithUTF8String:utf8file]; - g_free (utf8file); - - return self; -} - -- (gchar*)glibFilenameWithError:(NSError**)error { - GError *gerror = NULL; - gchar *result = g_filename_from_utf8 ([self UTF8String], -1, NULL, NULL, &gerror); - GErrorToNSError (gerror, error); - if (gerror) { - logGError (gerror, @"Failed to convert a UTF8 string to a GLib filename"); - } - return result; -} - -- (gchar*)glibFilename { - return [self glibFilenameWithError:NULL]; -} - -- (gchar*)glibUriWithError:(NSError**)error { - gchar *filepath; - gchar *uri; - NSError *cause = nil; - - filepath = [self glibFilenameWithError:&cause]; - if (!filepath) { - if (error) { - NSString *message = [NSString stringWithFormat:@"Could not convert \"%@\" to the GLib filename encoding", self]; - *error = [NSError errorWithMessage:message code:TZ_ERR_OTHER cause:cause]; - } - return NULL; - } - - GError *gerror = NULL; - GError **gerrorptr = error ? &gerror : NULL; - uri = g_filename_to_uri (filepath, NULL, gerrorptr); - if (!uri && error) { - NSString *message = [NSString stringWithFormat:@"Could not convert \"%@\" to a GLib URI", self]; - *error = [NSError errorWithMessage:message code:TZ_ERR_BADFORMAT cause:[NSError errorWithGError:gerror]]; - } - g_free (filepath); - return uri; -} - -- (gchar*)glibUri { - return [self glibUriWithError:NULL]; -} - -@end - -// vim:ft=objc:ts=8:et:sts=4:sw=4 diff --git a/tikzit/src/gtk/Node+Render.h b/tikzit/src/gtk/Node+Render.h deleted file mode 100644 index 60d2573..0000000 --- a/tikzit/src/gtk/Node+Render.h +++ /dev/null @@ -1,44 +0,0 @@ -/* - * Copyright 2011 Alex Merry <dev@randomguy3.me.uk> - * - * 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 the Free Software Foundation; either version 2 of - * the License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see <http://www.gnu.org/licenses/>. - */ - -#import "TZFoundation.h" -#import "Node.h" -#import "RenderContext.h" -#import "Surface.h" - -enum NodeState { - NodeNormal, - NodeSelected, - NodeHighlighted -}; - -@interface Node(Render) - -- (Transformer*) shapeTransformerForSurface:(id<Surface>)surface; -// the total rendered bounds, excluding label -- (NSRect) renderBoundsForSurface:(id<Surface>)surface; -- (NSRect) renderBoundsWithLabelForSurface:(id<Surface>)surface; -- (NSString*) renderedLabel; -- (NSSize) renderedLabelSizeInContext:(id<RenderContext>)context; -- (void) renderLabelToSurface:(id<Surface>)surface withContext:(id<RenderContext>)context; -- (void) renderLabelAt:(NSPoint)point withContext:(id<RenderContext>)context; -- (void) renderToSurface:(id<Surface>)surface withContext:(id<RenderContext>)context state:(enum NodeState)state; -- (BOOL) hitByPoint:(NSPoint)p onSurface:(id<Surface>)surface; - -@end - -// vim:ft=objc:ts=8:et:sts=4:sw=4 diff --git a/tikzit/src/gtk/Node+Render.m b/tikzit/src/gtk/Node+Render.m deleted file mode 100644 index 907d818..0000000 --- a/tikzit/src/gtk/Node+Render.m +++ /dev/null @@ -1,188 +0,0 @@ -/* - * Copyright 2011 Alex Merry <dev@randomguy3.me.uk> - * Copyright 2010 Chris Heunen - * - * 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 the Free Software Foundation; either version 2 of - * the License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see <http://www.gnu.org/licenses/>. - */ - -#import "Node+Render.h" -#import "Shape.h" -#import "Shape+Render.h" -#import "ShapeNames.h" - -#define MAX_LABEL_LENGTH 10 -#define LABEL_PADDING_X 2 -#define LABEL_PADDING_Y 2 - -@implementation Node (Render) - -- (Shape*) shapeToRender { - if (style) { - return [Shape shapeForName:[style shapeName]]; - } else { - return [Shape shapeForName:SHAPE_CIRCLE]; - } -} - -- (Transformer*) shapeTransformerForSurface:(id<Surface>)surface { - return [self shapeTransformerFromTransformer:[surface transformer]]; -} - -- (NSRect) renderBoundsUsingShapeTransform:(Transformer*)shapeTrans { - float strokeThickness = style ? [style strokeThickness] : [NodeStyle defaultStrokeThickness]; - NSRect screenBounds = [shapeTrans rectToScreen:[[self shapeToRender] boundingRect]]; - screenBounds = NSInsetRect(screenBounds, -strokeThickness, -strokeThickness); - return screenBounds; -} - -- (NSRect) renderBoundsForSurface:(id<Surface>)surface { - return [self renderBoundsUsingShapeTransform:[self shapeTransformerForSurface:surface]]; -} - -- (NSRect) renderBoundsWithLabelForSurface:(id<Surface>)surface { - NSRect nodeBounds = [self renderBoundsForSurface:surface]; - NSRect labelRect = NSZeroRect; - if (![label isEqual:@""]) { - id<RenderContext> cr = [surface createRenderContext]; - labelRect.size = [self renderedLabelSizeInContext:cr]; - NSPoint nodePos = [[surface transformer] toScreen:point]; - labelRect.origin.x = nodePos.x - (labelRect.size.width / 2); - labelRect.origin.y = nodePos.y - (labelRect.size.height / 2); - } - return NSUnionRect(nodeBounds, labelRect); -} - -- (RColor) strokeColor { - if (style) { - return [[style strokeColorRGB] rColor]; - } else { - return MakeRColor (0.4, 0.4, 0.7, 0.8); - } -} - -- (RColor) fillColor { - if (style) { - return [[style fillColorRGB] rColor]; - } else { - return MakeRColor (0.4, 0.4, 0.7, 0.3); - } -} - -- (NSString*) renderedLabel { - NSString *r_label = [label stringByExpandingLatexConstants]; - if ([r_label length] > MAX_LABEL_LENGTH) { - r_label = [[[r_label substringToIndex:MAX_LABEL_LENGTH-1] stringByTrimmingSpaces] stringByAppendingString:@"..."]; - } else { - r_label = [r_label stringByTrimmingSpaces]; - } - return r_label; -} - -- (NSSize) renderedLabelSizeInContext:(id<RenderContext>)context { - NSSize result = {0, 0}; - if (![label isEqual:@""]) { - NSString *r_label = [self renderedLabel]; - - id<TextLayout> layout = [context layoutText:r_label withSize:9]; - - result = [layout size]; - result.width += LABEL_PADDING_X; - result.height += LABEL_PADDING_Y; - } - return result; -} - -- (void) renderLabelToSurface:(id <Surface>)surface withContext:(id<RenderContext>)context { - [self renderLabelAt:[[surface transformer] toScreen:point] withContext:context]; -} - -- (void) renderLabelAt:(NSPoint)p withContext:(id<RenderContext>)context { - // draw latex code overlayed on node - if (![label isEqual:@""]) { - [context saveState]; - - NSString *r_label = [self renderedLabel]; - id<TextLayout> layout = [context layoutText:r_label withSize:9]; - - NSSize labelSize = [layout size]; - - NSRect textBounds = NSMakeRect (p.x - labelSize.width/2, - p.y - labelSize.height/2, - labelSize.width, - labelSize.height); - NSRect backRect = NSInsetRect (textBounds, -LABEL_PADDING_X, -LABEL_PADDING_Y); - - [context startPath]; - [context setLineWidth:1.0]; - [context rect:backRect]; - RColor fColor = MakeRColor (1.0, 1.0, 0.5, 0.7); - RColor sColor = MakeRColor (0.5, 0.0, 0.0, 0.7); - [context strokePathWithColor:sColor andFillWithColor:fColor]; - - [layout showTextAt:textBounds.origin withColor:BlackRColor]; - - [context restoreState]; - } -} - -- (void) renderToSurface:(id <Surface>)surface withContext:(id<RenderContext>)context state:(enum NodeState)state { - Transformer *shapeTrans = [self shapeTransformerForSurface:surface]; - float strokeThickness = style ? [style strokeThickness] : [NodeStyle defaultStrokeThickness]; - - [context saveState]; - - [[self shapeToRender] drawPathWithTransform:shapeTrans andContext:context]; - - [context setLineWidth:strokeThickness]; - if (!style) { - [context setLineDash:3.0]; - } - [context strokePathWithColor:[self strokeColor] andFillWithColor:[self fillColor]]; - - if (state != NodeNormal) { - [context setLineWidth:strokeThickness + 4.0]; - [context setLineDash:0.0]; - float alpha = 0.0f; - if (state == NodeSelected) - alpha = 0.5f; - else if (state == NodeHighlighted) - alpha = 0.25f; - RColor selectionColor = MakeSolidRColor(0.61f, 0.735f, 1.0f); - - [[self shapeToRender] drawPathWithTransform:shapeTrans andContext:context]; - [context strokePathWithColor:selectionColor andFillWithColor:selectionColor usingAlpha:alpha]; - } - - [context restoreState]; - [self renderLabelToSurface:surface withContext:context]; -} - -- (BOOL) hitByPoint:(NSPoint)p onSurface:(id<Surface>)surface { - Transformer *shapeTrans = [self shapeTransformerForSurface:surface]; - - NSRect screenBounds = [self renderBoundsUsingShapeTransform:shapeTrans]; - if (!NSPointInRect(p, screenBounds)) { - return NO; - } - - float strokeThickness = style ? [style strokeThickness] : [NodeStyle defaultStrokeThickness]; - id<RenderContext> ctx = [surface createRenderContext]; - [ctx setLineWidth:strokeThickness]; - [[self shapeToRender] drawPathWithTransform:shapeTrans andContext:ctx]; - return [ctx strokeIncludesPoint:p] || [ctx fillIncludesPoint:p]; -} - -@end - -// vim:ft=objc:ts=8:et:sts=4:sw=4 diff --git a/tikzit/src/gtk/NodeStyle+Gtk.h b/tikzit/src/gtk/NodeStyle+Gtk.h deleted file mode 100644 index 4fa5edd..0000000 --- a/tikzit/src/gtk/NodeStyle+Gtk.h +++ /dev/null @@ -1,31 +0,0 @@ -/* - * Copyright 2011 Alex Merry <dev@randomguy3.me.uk> - * - * 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 the Free Software Foundation; either version 2 of - * the License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see <http://www.gnu.org/licenses/>. - */ - -#import "TZFoundation.h" -#import "NodeStyle.h" -#import <gtk/gtk.h> - -@interface NodeStyle (Gtk) - -- (GdkColor) strokeColor; -- (void) setStrokeColor:(GdkColor)color; -- (GdkColor) fillColor; -- (void) setFillColor:(GdkColor)color; - -@end - -// vim:ft=objc:ts=8:et:sts=4:sw=4 diff --git a/tikzit/src/gtk/NodeStyle+Gtk.m b/tikzit/src/gtk/NodeStyle+Gtk.m deleted file mode 100644 index 1954def..0000000 --- a/tikzit/src/gtk/NodeStyle+Gtk.m +++ /dev/null @@ -1,41 +0,0 @@ -/* - * Copyright 2011 Alex Merry <dev@randomguy3.me.uk> - * - * 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 the Free Software Foundation; either version 2 of - * the License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see <http://www.gnu.org/licenses/>. - */ - -#import "NodeStyle+Gtk.h" -#import "ColorRGB+Gtk.h" - -@implementation NodeStyle (Gtk) - -- (GdkColor) strokeColor { - return [[self strokeColorRGB] gdkColor]; -} - -- (void) setStrokeColor:(GdkColor)color { - [self setStrokeColorRGB:[ColorRGB colorWithGdkColor:color]]; -} - -- (GdkColor) fillColor { - return [[self fillColorRGB] gdkColor]; -} - -- (void) setFillColor:(GdkColor)color { - [self setFillColorRGB:[ColorRGB colorWithGdkColor:color]]; -} - -@end - -// vim:ft=objc:ts=8:et:sts=4:sw=4 diff --git a/tikzit/src/gtk/NodeStyle+Render.h b/tikzit/src/gtk/NodeStyle+Render.h deleted file mode 100644 index 00edd27..0000000 --- a/tikzit/src/gtk/NodeStyle+Render.h +++ /dev/null @@ -1,30 +0,0 @@ -/* - * Copyright 2011 Alex Merry <dev@randomguy3.me.uk> - * - * 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 the Free Software Foundation; either version 2 of - * the License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see <http://www.gnu.org/licenses/>. - */ - -#import "TZFoundation.h" -#import "NodeStyle.h" -#import "RenderContext.h" -#import "Surface.h" - -@interface NodeStyle (Render) - -- (void) renderToSurface:(id<Surface>)surface withContext:(id<RenderContext>)context at:(NSPoint)p; -- (BOOL) hitByPoint:(NSPoint)p onSurface:(id<Surface>)surface; - -@end - -// vim:ft=objc:ts=8:et:sts=4:sw=4 diff --git a/tikzit/src/gtk/NodeStyle+Storage.h b/tikzit/src/gtk/NodeStyle+Storage.h deleted file mode 100644 index 7649414..0000000 --- a/tikzit/src/gtk/NodeStyle+Storage.h +++ /dev/null @@ -1,29 +0,0 @@ -/* - * Copyright 2011 Alex Merry <dev@randomguy3.me.uk> - * - * 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 the Free Software Foundation; either version 2 of - * the License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see <http://www.gnu.org/licenses/>. - */ - -#import "TZFoundation.h" -#import "NodeStyle.h" -#import "Configuration.h" - -@interface NodeStyle (Storage) - -- (id) initFromConfigurationGroup:(NSString*)groupName config:(Configuration*)configFile; -- (void) storeToConfigurationGroup:(NSString*)groupName config:(Configuration*)configFile; - -@end - -// vim:ft=objc:ts=8:et:sts=4:sw=4 diff --git a/tikzit/src/gtk/NodeStyle+Storage.m b/tikzit/src/gtk/NodeStyle+Storage.m deleted file mode 100644 index 088b062..0000000 --- a/tikzit/src/gtk/NodeStyle+Storage.m +++ /dev/null @@ -1,62 +0,0 @@ -/* - * Copyright 2011 Alex Merry <dev@randomguy3.me.uk> - * Copyright 2010 Chris Heunen - * - * 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 the Free Software Foundation; either version 2 of - * the License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see <http://www.gnu.org/licenses/>. - */ - -#import "NodeStyle+Storage.h" -#import "ColorRGB+IntegerListStorage.h" - -@implementation NodeStyle (Storage) - -- (id) initFromConfigurationGroup:(NSString*)groupName config:(Configuration*)configFile { - self = [self init]; - - if (self) { - [self setName:[configFile stringEntry:@"Name" inGroup:groupName withDefault:name]]; - [self setCategory:[configFile stringEntry:@"Category" inGroup:groupName withDefault:category]]; - [self setShapeName:[configFile stringEntry:@"ShapeName" inGroup:groupName withDefault:shapeName]]; - [self setScale:[configFile doubleEntry:@"Scale" inGroup:groupName withDefault:scale]]; - [self setStrokeThickness:[configFile integerEntry:@"StrokeThickness" - inGroup:groupName - withDefault:strokeThickness]]; - [self setStrokeColorRGB: - [ColorRGB colorFromValueList: - [configFile integerListEntry:@"StrokeColor" - inGroup:groupName - withDefault:[strokeColorRGB valueList]]]]; - [self setFillColorRGB: - [ColorRGB colorFromValueList: - [configFile integerListEntry:@"FillColor" - inGroup:groupName - withDefault:[fillColorRGB valueList]]]]; - } - - return self; -} - -- (void) storeToConfigurationGroup:(NSString*)groupName config:(Configuration*)configFile { - [configFile setStringEntry:@"Name" inGroup:groupName value:[self name]]; - [configFile setStringEntry:@"Category" inGroup:groupName value:[self category]]; - [configFile setStringEntry:@"ShapeName" inGroup:groupName value:[self shapeName]]; - [configFile setDoubleEntry:@"Scale" inGroup:groupName value:[self scale]]; - [configFile setIntegerEntry:@"StrokeThickness" inGroup:groupName value:[self strokeThickness]]; - [configFile setIntegerListEntry:@"StrokeColor" inGroup:groupName value:[[self strokeColorRGB] valueList]]; - [configFile setIntegerListEntry:@"FillColor" inGroup:groupName value:[[self fillColorRGB] valueList]]; -} - -@end - -// vim:ft=objc:ts=8:et:sts=4:sw=4 diff --git a/tikzit/src/gtk/NodeStyleEditor.h b/tikzit/src/gtk/NodeStyleEditor.h deleted file mode 100644 index b45c992..0000000 --- a/tikzit/src/gtk/NodeStyleEditor.h +++ /dev/null @@ -1,45 +0,0 @@ -/* - * Copyright 2011 Alex Merry <dev@randomguy3.me.uk> - * - * 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 the Free Software Foundation; either version 2 of - * the License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see <http://www.gnu.org/licenses/>. - */ - -#import "TZFoundation.h" -#import <gtk/gtk.h> - -@class NodeStyle; - -@interface NodeStyleEditor: NSObject { - NodeStyle *style; - GtkTable *table; - GtkEntry *nameEdit; - GtkComboBox *shapeNameCombo; - GtkColorButton *strokeColorButton; - GtkWidget *makeStrokeTexSafeButton; - GtkColorButton *fillColorButton; - GtkWidget *makeFillTexSafeButton; - GtkAdjustment *scaleAdj; - BOOL blockSignals; -} - -@property (retain) NodeStyle *style; -@property (readonly) GtkWidget *widget; - -- (id) init; - -- (void) selectNameField; - -@end - -// vim:ft=objc:ts=4:et:sts=4:sw=4:foldmethod=marker diff --git a/tikzit/src/gtk/NodeStyleEditor.m b/tikzit/src/gtk/NodeStyleEditor.m deleted file mode 100644 index fcf4147..0000000 --- a/tikzit/src/gtk/NodeStyleEditor.m +++ /dev/null @@ -1,477 +0,0 @@ -/* - * Copyright 2011 Alex Merry <dev@randomguy3.me.uk> - * - * 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 the Free Software Foundation; either version 2 of - * the License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see <http://www.gnu.org/licenses/>. - */ - -#import "NodeStyleEditor.h" -#import "NodeStyle.h" -#import "NodeStyle+Gtk.h" -#import "Shape.h" - -static const guint row_count = 5; - -// {{{ Internal interfaces -// {{{ GTK+ Callbacks -static void style_name_edit_changed_cb (GtkEditable *widget, NodeStyleEditor *editor); -static void style_shape_combo_changed_cb (GtkComboBox *widget, NodeStyleEditor *editor); -static void stroke_color_changed_cb (GtkColorButton *widget, NodeStyleEditor *editor); -static void fill_color_changed_cb (GtkColorButton *widget, NodeStyleEditor *editor); -static void make_stroke_safe_button_clicked_cb (GtkButton *widget, NodeStyleEditor *editor); -static void make_fill_safe_button_clicked_cb (GtkButton *widget, NodeStyleEditor *editor); -static void scale_adjustment_changed_cb (GtkAdjustment *widget, NodeStyleEditor *editor); -// }}} -// {{{ Notifications - -@interface NodeStyleEditor (Notifications) -- (void) shapeDictionaryReplaced:(NSNotification*)n; -- (void) nameChangedTo:(NSString*)value; -- (void) shapeNameChangedTo:(NSString*)value; -- (void) strokeColorChangedTo:(GdkColor)value; -- (void) makeStrokeColorTexSafe; -- (void) fillColorChangedTo:(GdkColor)value; -- (void) makeFillColorTexSafe; -- (void) scaleChangedTo:(double)value; -@end - -// }}} -// {{{ Private - -@interface NodeStyleEditor (Private) -- (void) loadShapeNames; -- (void) setActiveShapeName:(NSString*)name; -@end - -// }}} -// }}} -// {{{ API - -@implementation NodeStyleEditor - -- (void) _addWidget:(GtkWidget*)w withLabel:(gchar *)label atRow:(guint)row { - NSAssert(row < row_count, @"row_count is wrong!"); - - GtkWidget *l = gtk_label_new (label); - gtk_misc_set_alignment (GTK_MISC (l), 0, 0.5); - gtk_widget_show (l); - gtk_widget_show (w); - - gtk_table_attach (table, l, - 0, 1, row, row+1, // l, r, t, b - GTK_FILL, // x opts - GTK_FILL | GTK_EXPAND, // y opts - 5, // x padding - 0); // y padding - - gtk_table_attach (table, w, - 1, 2, row, row+1, // l, r, t, b - GTK_FILL | GTK_EXPAND, // x opts - GTK_FILL | GTK_EXPAND, // y opts - 0, // x padding - 0); // y padding -} - -- (GtkWidget*) _createMakeColorTexSafeButton:(NSString*)type { - GtkWidget *b = gtk_button_new (); - GtkWidget *icon = gtk_image_new_from_stock (GTK_STOCK_DIALOG_WARNING, GTK_ICON_SIZE_BUTTON); - gtk_widget_show (icon); - gtk_container_add (GTK_CONTAINER (b), icon); - NSString *ttip = [NSString stringWithFormat:@"The %@ colour is not a predefined TeX colour.\nClick here to choose the nearest TeX-safe colour.", type]; - gtk_widget_set_tooltip_text (b, [ttip UTF8String]); - return b; -} - -- (id) init { - self = [super init]; - - if (self != nil) { - style = nil; - table = GTK_TABLE (gtk_table_new (row_count, 2, FALSE)); - gtk_table_set_col_spacings (table, 6); - gtk_table_set_row_spacings (table, 6); - gtk_widget_set_sensitive (GTK_WIDGET (table), FALSE); - blockSignals = NO; - - /** - * Name - */ - nameEdit = GTK_ENTRY (gtk_entry_new ()); - g_object_ref_sink (nameEdit); - [self _addWidget:GTK_WIDGET (nameEdit) - withLabel:"Name" - atRow:0]; - g_signal_connect (G_OBJECT (nameEdit), - "changed", - G_CALLBACK (style_name_edit_changed_cb), - self); - - - /** - * Shape - */ - GtkListStore *store = gtk_list_store_new (1, G_TYPE_STRING); - shapeNameCombo = GTK_COMBO_BOX (gtk_combo_box_new_with_model (GTK_TREE_MODEL (store))); - GtkCellRenderer *cellRend = gtk_cell_renderer_text_new (); - gtk_cell_layout_pack_start (GTK_CELL_LAYOUT (shapeNameCombo), - cellRend, - TRUE); - gtk_cell_layout_add_attribute (GTK_CELL_LAYOUT (shapeNameCombo), cellRend, "text", 0); - g_object_ref_sink (shapeNameCombo); - [self _addWidget:GTK_WIDGET (shapeNameCombo) - withLabel:"Shape" - atRow:1]; - g_signal_connect (G_OBJECT (shapeNameCombo), - "changed", - G_CALLBACK (style_shape_combo_changed_cb), - self); - - - /** - * Stroke colour - */ - GtkWidget *strokeBox = gtk_hbox_new (FALSE, 0); - [self _addWidget:strokeBox - withLabel:"Stroke colour" - atRow:2]; - strokeColorButton = GTK_COLOR_BUTTON (gtk_color_button_new ()); - g_object_ref_sink (strokeColorButton); - gtk_widget_show (GTK_WIDGET (strokeColorButton)); - gtk_box_pack_start (GTK_BOX (strokeBox), GTK_WIDGET (strokeColorButton), - FALSE, FALSE, 0); - makeStrokeTexSafeButton = [self _createMakeColorTexSafeButton:@"stroke"]; - g_object_ref_sink (makeStrokeTexSafeButton); - gtk_box_pack_start (GTK_BOX (strokeBox), makeStrokeTexSafeButton, - FALSE, FALSE, 0); - g_signal_connect (G_OBJECT (strokeColorButton), - "color-set", - G_CALLBACK (stroke_color_changed_cb), - self); - g_signal_connect (G_OBJECT (makeStrokeTexSafeButton), - "clicked", - G_CALLBACK (make_stroke_safe_button_clicked_cb), - self); - - - /** - * Fill colour - */ - GtkWidget *fillBox = gtk_hbox_new (FALSE, 0); - [self _addWidget:fillBox - withLabel:"Fill colour" - atRow:3]; - fillColorButton = GTK_COLOR_BUTTON (gtk_color_button_new ()); - g_object_ref_sink (fillColorButton); - gtk_widget_show (GTK_WIDGET (fillColorButton)); - gtk_box_pack_start (GTK_BOX (fillBox), GTK_WIDGET (fillColorButton), - FALSE, FALSE, 0); - makeFillTexSafeButton = [self _createMakeColorTexSafeButton:@"fill"]; - g_object_ref_sink (makeFillTexSafeButton); - gtk_box_pack_start (GTK_BOX (fillBox), makeFillTexSafeButton, - FALSE, FALSE, 0); - g_signal_connect (G_OBJECT (fillColorButton), - "color-set", - G_CALLBACK (fill_color_changed_cb), - self); - g_signal_connect (G_OBJECT (makeFillTexSafeButton), - "clicked", - G_CALLBACK (make_fill_safe_button_clicked_cb), - self); - - - /** - * Scale - */ - scaleAdj = GTK_ADJUSTMENT (gtk_adjustment_new ( - 1.0, // value - 0.0, // lower - 50.0, // upper - 0.20, // step - 1.0, // page - 0.0)); // (irrelevant) - g_object_ref_sink (scaleAdj); - GtkWidget *scaleSpin = gtk_spin_button_new (scaleAdj, 0.0, 2); - [self _addWidget:scaleSpin - withLabel:"Scale" - atRow:4]; - g_signal_connect (G_OBJECT (scaleAdj), - "value-changed", - G_CALLBACK (scale_adjustment_changed_cb), - self); - - [self loadShapeNames]; - [[NSNotificationCenter defaultCenter] addObserver:self - selector:@selector(shapeDictionaryReplaced:) - name:@"ShapeDictionaryReplaced" - object:[Shape class]]; - } - - return self; -} - -- (void) dealloc { - [[NSNotificationCenter defaultCenter] removeObserver:self]; - - g_object_unref (nameEdit); - g_object_unref (shapeNameCombo); - g_object_unref (strokeColorButton); - g_object_unref (makeStrokeTexSafeButton); - g_object_unref (fillColorButton); - g_object_unref (makeFillTexSafeButton); - g_object_unref (scaleAdj); - g_object_unref (table); - [style release]; - - [super dealloc]; -} - -- (NodeStyle*) style { - return style; -} - -- (void) setStyle:(NodeStyle*)s { - blockSignals = YES; - NodeStyle *oldStyle = style; - style = [s retain]; - - if (style != nil) { - gtk_widget_set_sensitive (GTK_WIDGET (table), TRUE); - - gtk_entry_set_text(nameEdit, [[style name] UTF8String]); - - [self setActiveShapeName:[style shapeName]]; - - GdkColor c = [style strokeColor]; - gtk_color_button_set_color(strokeColorButton, &c); - - gtk_widget_set_visible (makeStrokeTexSafeButton, ([[style strokeColorRGB] name] == nil)); - - c = [style fillColor]; - gtk_color_button_set_color(fillColorButton, &c); - - gtk_widget_set_visible (makeFillTexSafeButton, ([[style fillColorRGB] name] == nil)); - - gtk_adjustment_set_value(scaleAdj, [style scale]); - } else { - gtk_entry_set_text(nameEdit, ""); - [self setActiveShapeName:nil]; - gtk_widget_set_visible (makeStrokeTexSafeButton, FALSE); - gtk_widget_set_visible (makeFillTexSafeButton, FALSE); - gtk_adjustment_set_value(scaleAdj, 1.0); - gtk_widget_set_sensitive (GTK_WIDGET (table), FALSE); - } - - [oldStyle release]; - blockSignals = NO; -} - -- (GtkWidget*) widget { - return GTK_WIDGET (table); -} - -- (void) selectNameField { - gtk_widget_grab_focus (GTK_WIDGET (nameEdit)); - gtk_editable_select_region (GTK_EDITABLE (nameEdit), 0, -1); -} - -@end - -// }}} -// {{{ Notifications - -@implementation NodeStyleEditor (Notifications) -- (void) shapeDictionaryReplaced:(NSNotification*)n { - blockSignals = YES; - - [self loadShapeNames]; - [self setActiveShapeName:[style shapeName]]; - - blockSignals = NO; -} - -- (void) nameChangedTo:(NSString*)value { - [style setName:value]; -} - -- (void) shapeNameChangedTo:(NSString*)value { - [style setShapeName:value]; -} - -- (void) strokeColorChangedTo:(GdkColor)value { - [style setStrokeColor:value]; - gtk_widget_set_visible (makeStrokeTexSafeButton, - [[style strokeColorRGB] name] == nil); -} - -- (void) makeStrokeColorTexSafe { - if (style != nil) { - [[style strokeColorRGB] setToClosestHashed]; - GdkColor color = [style strokeColor]; - gtk_color_button_set_color(strokeColorButton, &color); - gtk_widget_set_visible (makeStrokeTexSafeButton, FALSE); - } -} - -- (void) fillColorChangedTo:(GdkColor)value { - [style setFillColor:value]; - gtk_widget_set_visible (makeFillTexSafeButton, - [[style fillColorRGB] name] == nil); -} - -- (void) makeFillColorTexSafe { - if (style != nil) { - [[style fillColorRGB] setToClosestHashed]; - GdkColor color = [style fillColor]; - gtk_color_button_set_color(fillColorButton, &color); - gtk_widget_set_visible (makeFillTexSafeButton, FALSE); - } -} - -- (void) scaleChangedTo:(double)value { - [style setScale:value]; -} -@end - -// }}} -// {{{ Private - -@implementation NodeStyleEditor (Private) -- (BOOL) signalsBlocked { return blockSignals; } - -- (void) loadShapeNames { - blockSignals = YES; - - gtk_combo_box_set_active (shapeNameCombo, -1); - - GtkListStore *list = GTK_LIST_STORE (gtk_combo_box_get_model (shapeNameCombo)); - gtk_list_store_clear (list); - - NSEnumerator *en = [[Shape shapeDictionary] keyEnumerator]; - NSString *shapeName; - GtkTreeIter iter; - while ((shapeName = [en nextObject]) != nil) { - gtk_list_store_append (list, &iter); - gtk_list_store_set (list, &iter, 0, [shapeName UTF8String], -1); - } - - blockSignals = NO; -} - -- (void) setActiveShapeName:(NSString*)name { - if (name == nil) { - gtk_combo_box_set_active (shapeNameCombo, -1); - return; - } - const gchar *shapeName = [name UTF8String]; - - GtkTreeModel *model = gtk_combo_box_get_model (shapeNameCombo); - GtkTreeIter iter; - if (gtk_tree_model_get_iter_first (model, &iter)) { - do { - gchar *rowShapeName; - gtk_tree_model_get (model, &iter, 0, &rowShapeName, -1); - if (g_strcmp0 (shapeName, rowShapeName) == 0) { - gtk_combo_box_set_active_iter (shapeNameCombo, &iter); - g_free (rowShapeName); - return; - } - g_free (rowShapeName); - } while (gtk_tree_model_iter_next (model, &iter)); - } -} -@end - -// }}} -// {{{ GTK+ callbacks - -static void style_name_edit_changed_cb (GtkEditable *widget, NodeStyleEditor *editor) { - if ([editor signalsBlocked]) - return; - - NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init]; - - const gchar *contents = gtk_entry_get_text (GTK_ENTRY (widget)); - [editor nameChangedTo:[NSString stringWithUTF8String:contents]]; - - [pool drain]; -} - -static void style_shape_combo_changed_cb (GtkComboBox *widget, NodeStyleEditor *editor) { - if ([editor signalsBlocked]) - return; - - NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init]; - - GtkTreeIter iter; - gtk_combo_box_get_active_iter (widget, &iter); - gchar *shapeName = NULL; - gtk_tree_model_get (gtk_combo_box_get_model (widget), &iter, 0, &shapeName, -1); - [editor shapeNameChangedTo:[NSString stringWithUTF8String:shapeName]]; - g_free (shapeName); - - [pool drain]; -} - -static void stroke_color_changed_cb (GtkColorButton *widget, NodeStyleEditor *editor) { - if ([editor signalsBlocked]) - return; - - NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init]; - - GdkColor color; - gtk_color_button_get_color (widget, &color); - [editor strokeColorChangedTo:color]; - - [pool drain]; -} - -static void fill_color_changed_cb (GtkColorButton *widget, NodeStyleEditor *editor) { - if ([editor signalsBlocked]) - return; - - NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init]; - - GdkColor color; - gtk_color_button_get_color (widget, &color); - [editor fillColorChangedTo:color]; - - [pool drain]; -} - -static void make_stroke_safe_button_clicked_cb (GtkButton *widget, NodeStyleEditor *editor) { - if ([editor signalsBlocked]) - return; - - NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init]; - [editor makeStrokeColorTexSafe]; - [pool drain]; -} - -static void make_fill_safe_button_clicked_cb (GtkButton *widget, NodeStyleEditor *editor) { - if ([editor signalsBlocked]) - return; - - NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init]; - [editor makeFillColorTexSafe]; - [pool drain]; -} - -static void scale_adjustment_changed_cb (GtkAdjustment *adj, NodeStyleEditor *editor) { - NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init]; - [editor scaleChangedTo:gtk_adjustment_get_value (adj)]; - [pool drain]; -} - -// }}} - -// vim:ft=objc:ts=4:et:sts=4:sw=4:foldmethod=marker diff --git a/tikzit/src/gtk/NodeStyleSelector.h b/tikzit/src/gtk/NodeStyleSelector.h deleted file mode 100644 index a699dc8..0000000 --- a/tikzit/src/gtk/NodeStyleSelector.h +++ /dev/null @@ -1,61 +0,0 @@ -/* - * Copyright 2011 Alex Merry <dev@randomguy3.me.uk> - * - * 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 the Free Software Foundation; either version 2 of - * the License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see <http://www.gnu.org/licenses/>. - */ - -#import "TZFoundation.h" -#import <gtk/gtk.h> - -@class NodeStyle; -@class NodeStylesModel; -@class StyleManager; - -@interface NodeStyleSelector: NSObject { - NodeStylesModel *model; - GtkIconView *view; -} - -/*! - @property widget - @brief The GTK widget - */ -@property (readonly) GtkWidget *widget; - -/*! - @property model - @brief The model to use. - */ -@property (retain) NodeStylesModel *model; - -/*! - @property selectedStyle - @brief The selected style. - - When this changes, a SelectedStyleChanged notification will be posted - */ -@property (assign) NodeStyle *selectedStyle; - -/*! - * Initialise with a new model for the given style manager - */ -- (id) initWithStyleManager:(StyleManager*)manager; -/*! - * Initialise with the given model - */ -- (id) initWithModel:(NodeStylesModel*)model; - -@end - -// vim:ft=objc:ts=8:et:sts=4:sw=4 diff --git a/tikzit/src/gtk/NodeStyleSelector.m b/tikzit/src/gtk/NodeStyleSelector.m deleted file mode 100644 index 14cdc75..0000000 --- a/tikzit/src/gtk/NodeStyleSelector.m +++ /dev/null @@ -1,135 +0,0 @@ -/* - * Copyright 2011-2012 Alex Merry <dev@randomguy3.me.uk> - * - * 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 the Free Software Foundation; either version 2 of - * the License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see <http://www.gnu.org/licenses/>. - */ - -#import "NodeStyleSelector.h" - -#import "NodeStylesModel.h" - -// {{{ Internal interfaces -static void selection_changed_cb (GtkIconView *widget, NodeStyleSelector *mgr); -// }}} -// {{{ API - -@implementation NodeStyleSelector - -- (id) init { - [self release]; - return nil; -} - -- (id) initWithStyleManager:(StyleManager*)m { - return [self initWithModel:[NodeStylesModel modelWithStyleManager:m]]; -} -- (id) initWithModel:(NodeStylesModel*)m { - self = [super init]; - - if (self) { - model = [m retain]; - - view = GTK_ICON_VIEW (gtk_icon_view_new ()); - g_object_ref_sink (view); - - gtk_icon_view_set_model (view, [model model]); - gtk_icon_view_set_pixbuf_column (view, NODE_STYLES_ICON_COL); - gtk_icon_view_set_tooltip_column (view, NODE_STYLES_NAME_COL); - gtk_icon_view_set_selection_mode (view, GTK_SELECTION_SINGLE); - - g_signal_connect (G_OBJECT (view), - "selection-changed", - G_CALLBACK (selection_changed_cb), - self); - } - - return self; -} - -- (void) dealloc { - [[NSNotificationCenter defaultCenter] removeObserver:self]; - - g_object_unref (view); - [model release]; - - [super dealloc]; -} - -- (NodeStylesModel*) model { - return model; -} - -- (void) setModel:(NodeStylesModel*)m { - if (m == model) - return; - - NodeStylesModel *oldModel = model; - model = [m retain]; - gtk_icon_view_set_model (view, [model model]); - [oldModel release]; -} - -- (GtkWidget*) widget { - return GTK_WIDGET (view); -} - -- (NodeStyle*) selectedStyle { - GList *list = gtk_icon_view_get_selected_items (view); - if (!list) { - return nil; - } - if (list->next != NULL) { - NSLog(@"Multiple selected items in NodeStyleSelector!"); - } - - GtkTreePath *path = (GtkTreePath*) list->data; - NodeStyle *style = [model styleFromPath:path]; - - g_list_foreach (list, (GFunc)gtk_tree_path_free, NULL); - g_list_free (list); - - return style; -} - -- (void) setSelectedStyle:(NodeStyle*)style { - if (style == nil) { - gtk_icon_view_unselect_all (view); - return; - } - - GtkTreePath *path = [model pathFromStyle:style]; - if (path) { - gtk_icon_view_unselect_all (view); - gtk_icon_view_select_path (view, path); - gtk_tree_path_free (path); - } -} - -@end - -// }}} -// {{{ GTK+ callbacks - -static void selection_changed_cb (GtkIconView *view, NodeStyleSelector *mgr) { - NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init]; - - [[NSNotificationCenter defaultCenter] - postNotificationName:@"SelectedStyleChanged" - object:mgr]; - - [pool drain]; -} -// }}} - -// vim:ft=objc:ts=8:et:sts=4:sw=4:foldmethod=marker diff --git a/tikzit/src/gtk/NodeStylesModel.h b/tikzit/src/gtk/NodeStylesModel.h deleted file mode 100644 index a048560..0000000 --- a/tikzit/src/gtk/NodeStylesModel.h +++ /dev/null @@ -1,62 +0,0 @@ -/* - * Copyright 2011-2012 Alex Merry <dev@randomguy3.me.uk> - * - * 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 the Free Software Foundation; either version 2 of - * the License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see <http://www.gnu.org/licenses/>. - */ - -#import "TZFoundation.h" -#import <gtk/gtk.h> - -@class NodeStyle; -@class StyleManager; - -enum { - NODE_STYLES_NAME_COL = 0, - NODE_STYLES_ICON_COL, - NODE_STYLES_PTR_COL, - NODE_STYLES_N_COLS -}; - -@interface NodeStylesModel: NSObject { - GtkListStore *store; - StyleManager *styleManager; -} - -/*! - @property model - @brief The GTK+ tree model - */ -@property (readonly) GtkTreeModel *model; - -/*! - @property manager - @brief The StyleManager to use. - */ -@property (retain) StyleManager *styleManager; - -/*! - * Initialise with the given style manager - */ -- (id) initWithStyleManager:(StyleManager*)m; - -+ (id) modelWithStyleManager:(StyleManager*)m; - -- (NodeStyle*) styleFromPath:(GtkTreePath*)path; -- (GtkTreePath*) pathFromStyle:(NodeStyle*)style; -- (NodeStyle*) styleFromIter:(GtkTreeIter*)iter; -- (GtkTreeIter*) iterFromStyle:(NodeStyle*)style; - -@end - -// vim:ft=objc:ts=8:et:sts=4:sw=4 diff --git a/tikzit/src/gtk/NodeStylesModel.m b/tikzit/src/gtk/NodeStylesModel.m deleted file mode 100644 index 3cc5771..0000000 --- a/tikzit/src/gtk/NodeStylesModel.m +++ /dev/null @@ -1,381 +0,0 @@ -/* - * Copyright 2011-2012 Alex Merry <dev@randomguy3.me.uk> - * - * 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 the Free Software Foundation; either version 2 of - * the License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see <http://www.gnu.org/licenses/>. - */ - -#import "NodeStylesModel.h" - -#import "CairoRenderContext.h" -#import "NodeStyle.h" -#import "Shape.h" -#import "Shape+Render.h" -#import "ShapeNames.h" -#import "StyleManager.h" - -#import "gtkhelpers.h" - -#import <gdk-pixbuf/gdk-pixbuf.h> - -// {{{ Internal interfaces - -@interface NodeStylesModel (Notifications) -- (void) nodeStylesReplaced:(NSNotification*)notification; -- (void) nodeStyleAdded:(NSNotification*)notification; -- (void) nodeStyleRemoved:(NSNotification*)notification; -- (void) shapeDictionaryReplaced:(NSNotification*)n; -- (void) observeValueForKeyPath:(NSString*)keyPath - ofObject:(id)object - change:(NSDictionary*)change - context:(void*)context; -@end - -@interface NodeStylesModel (Private) -- (cairo_surface_t*) createNodeIconSurface; -- (GdkPixbuf*) pixbufOfNodeInStyle:(NodeStyle*)style; -- (GdkPixbuf*) pixbufOfNodeInStyle:(NodeStyle*)style usingSurface:(cairo_surface_t*)surface; -- (void) addNodeStyle:(NodeStyle*)style; -- (void) addNodeStyle:(NodeStyle*)style usingSurface:(cairo_surface_t*)surface; -- (void) observeNodeStyle:(NodeStyle*)style; -- (void) stopObservingNodeStyle:(NodeStyle*)style; -- (void) clearNodeStylesModel; -- (void) reloadNodeStyles; -@end - -// }}} -// {{{ API - -@implementation NodeStylesModel - -+ (id) modelWithStyleManager:(StyleManager*)m { - return [[[self alloc] initWithStyleManager:m] autorelease]; -} - -- (id) init { - [self release]; - return nil; -} - -- (id) initWithStyleManager:(StyleManager*)m { - self = [super init]; - - if (self) { - store = gtk_list_store_new (NODE_STYLES_N_COLS, - G_TYPE_STRING, - GDK_TYPE_PIXBUF, - G_TYPE_POINTER); - g_object_ref_sink (store); - - [self setStyleManager:m]; - - [[NSNotificationCenter defaultCenter] addObserver:self - selector:@selector(shapeDictionaryReplaced:) - name:@"ShapeDictionaryReplaced" - object:[Shape class]]; - } - - return self; -} - -- (void) dealloc { - [[NSNotificationCenter defaultCenter] removeObserver:self]; - - [self clearNodeStylesModel]; - g_object_unref (store); - [styleManager release]; - - [super dealloc]; -} - -- (StyleManager*) styleManager { - return styleManager; -} - -- (void) setStyleManager:(StyleManager*)m { - if (m == nil) { - [NSException raise:NSInvalidArgumentException format:@"Style manager cannot be nil"]; - } - [m retain]; - - [[NSNotificationCenter defaultCenter] removeObserver:self name:nil object:styleManager]; - [[NSNotificationCenter defaultCenter] addObserver:self - selector:@selector(nodeStylesReplaced:) - name:@"NodeStylesReplaced" - object:m]; - [[NSNotificationCenter defaultCenter] addObserver:self - selector:@selector(nodeStyleAdded:) - name:@"NodeStyleAdded" - object:m]; - [[NSNotificationCenter defaultCenter] addObserver:self - selector:@selector(nodeStyleRemoved:) - name:@"NodeStyleRemoved" - object:m]; - - [styleManager release]; - styleManager = m; - - [self reloadNodeStyles]; -} - -- (GtkTreeModel*) model { - return GTK_TREE_MODEL (store); -} - -- (NodeStyle*) styleFromPath:(GtkTreePath*)path { - GtkTreeIter iter; - gtk_tree_model_get_iter (GTK_TREE_MODEL (store), &iter, path); - NodeStyle *style = nil; - gtk_tree_model_get (GTK_TREE_MODEL (store), &iter, NODE_STYLES_PTR_COL, &style, -1); - return style; -} - -- (GtkTreePath*) pathFromStyle:(NodeStyle*)style { - GtkTreeModel *m = GTK_TREE_MODEL (store); - GtkTreeIter row; - if (gtk_tree_model_get_iter_first (m, &row)) { - do { - NodeStyle *rowStyle; - gtk_tree_model_get (m, &row, NODE_STYLES_PTR_COL, &rowStyle, -1); - if (style == rowStyle) { - return gtk_tree_model_get_path (m, &row); - } - } while (gtk_tree_model_iter_next (m, &row)); - } - return NULL; -} - -- (NodeStyle*) styleFromIter:(GtkTreeIter*)iter { - NodeStyle *style = nil; - gtk_tree_model_get (GTK_TREE_MODEL (store), iter, NODE_STYLES_PTR_COL, &style, -1); - return style; -} - -- (GtkTreeIter*) iterFromStyle:(NodeStyle*)style { - GtkTreeModel *m = GTK_TREE_MODEL (store); - GtkTreeIter row; - if (gtk_tree_model_get_iter_first (m, &row)) { - do { - NodeStyle *rowStyle; - gtk_tree_model_get (m, &row, NODE_STYLES_PTR_COL, &rowStyle, -1); - if (style == rowStyle) { - return gtk_tree_iter_copy (&row); - } - } while (gtk_tree_model_iter_next (m, &row)); - } - return NULL; -} -@end - -// }}} -// {{{ Notifications - -@implementation NodeStylesModel (Notifications) - -- (void) nodeStylesReplaced:(NSNotification*)notification { - [self reloadNodeStyles]; -} - -- (void) nodeStyleAdded:(NSNotification*)notification { - [self addNodeStyle:[[notification userInfo] objectForKey:@"style"]]; -} - -- (void) nodeStyleRemoved:(NSNotification*)notification { - NodeStyle *style = [[notification userInfo] objectForKey:@"style"]; - - GtkTreeModel *model = GTK_TREE_MODEL (store); - GtkTreeIter row; - if (gtk_tree_model_get_iter_first (model, &row)) { - do { - NodeStyle *rowStyle; - gtk_tree_model_get (model, &row, NODE_STYLES_PTR_COL, &rowStyle, -1); - if (style == rowStyle) { - gtk_list_store_remove (store, &row); - [self stopObservingNodeStyle:rowStyle]; - [rowStyle release]; - return; - } - } while (gtk_tree_model_iter_next (model, &row)); - } -} - -- (void) observeValueForKeyPath:(NSString*)keyPath - ofObject:(id)object - change:(NSDictionary*)change - context:(void*)context -{ - if ([object class] == [NodeStyle class]) { - NodeStyle *style = object; - - GtkTreeModel *model = GTK_TREE_MODEL (store); - GtkTreeIter row; - if (gtk_tree_model_get_iter_first (model, &row)) { - do { - NodeStyle *rowStyle; - gtk_tree_model_get (model, &row, NODE_STYLES_PTR_COL, &rowStyle, -1); - if (style == rowStyle) { - if ([@"name" isEqual:keyPath]) { - gtk_list_store_set (store, &row, NODE_STYLES_NAME_COL, [[style name] UTF8String], -1); - } else { - GdkPixbuf *pixbuf = [self pixbufOfNodeInStyle:style]; - gtk_list_store_set (store, &row, NODE_STYLES_ICON_COL, pixbuf, -1); - g_object_unref (pixbuf); - } - } - } while (gtk_tree_model_iter_next (model, &row)); - } - } -} - -- (void) shapeDictionaryReplaced:(NSNotification*)n { - [self reloadNodeStyles]; -} -@end - -// }}} -// {{{ Private - -@implementation NodeStylesModel (Private) -- (cairo_surface_t*) createNodeIconSurface { - return cairo_image_surface_create (CAIRO_FORMAT_ARGB32, 24, 24); -} - -- (GdkPixbuf*) pixbufOfNodeInStyle:(NodeStyle*)style { - cairo_surface_t *surface = [self createNodeIconSurface]; - GdkPixbuf *pixbuf = [self pixbufOfNodeInStyle:style usingSurface:surface]; - cairo_surface_destroy (surface); - return pixbuf; -} - -- (GdkPixbuf*) pixbufOfNodeInStyle:(NodeStyle*)style usingSurface:(cairo_surface_t*)surface { - Shape *shape = [Shape shapeForName:[style shapeName]]; - - int width = cairo_image_surface_get_width (surface); - int height = cairo_image_surface_get_height (surface); - NSRect pixbufBounds = NSMakeRect(0.0, 0.0, width, height); - const CGFloat lineWidth = [style strokeThickness]; - Transformer *shapeTrans = [Transformer transformerToFit:[shape boundingRect] - intoScreenRect:NSInsetRect(pixbufBounds, lineWidth, lineWidth) - flippedAboutXAxis:YES]; - if ([style scale] < 1.0) - [shapeTrans setScale:[style scale] * [shapeTrans scale]]; - - CairoRenderContext *context = [[CairoRenderContext alloc] initForSurface:surface]; - [context clearSurface]; - [shape drawPathWithTransform:shapeTrans andContext:context]; - [context setLineWidth:lineWidth]; - [context strokePathWithColor:[[style strokeColorRGB] rColor] - andFillWithColor:[[style fillColorRGB] rColor]]; - [context release]; - - return pixbuf_get_from_surface (surface); -} - -- (void) addNodeStyle:(NodeStyle*)style usingSurface:(cairo_surface_t*)surface { - GtkTreeIter iter; - gtk_list_store_append (store, &iter); - - GdkPixbuf *pixbuf = [self pixbufOfNodeInStyle:style usingSurface:surface]; - gtk_list_store_set (store, &iter, - NODE_STYLES_NAME_COL, [[style name] UTF8String], - NODE_STYLES_ICON_COL, pixbuf, - NODE_STYLES_PTR_COL, (gpointer)[style retain], - -1); - g_object_unref (pixbuf); - [self observeNodeStyle:style]; -} - -- (void) addNodeStyle:(NodeStyle*)style { - cairo_surface_t *surface = [self createNodeIconSurface]; - [self addNodeStyle:style usingSurface:surface]; - cairo_surface_destroy (surface); -} - -- (void) observeNodeStyle:(NodeStyle*)style { - [style addObserver:self - forKeyPath:@"name" - options:NSKeyValueObservingOptionNew - context:NULL]; - [style addObserver:self - forKeyPath:@"strokeThickness" - options:0 - context:NULL]; - [style addObserver:self - forKeyPath:@"strokeColorRGB.red" - options:0 - context:NULL]; - [style addObserver:self - forKeyPath:@"strokeColorRGB.green" - options:0 - context:NULL]; - [style addObserver:self - forKeyPath:@"strokeColorRGB.blue" - options:0 - context:NULL]; - [style addObserver:self - forKeyPath:@"fillColorRGB.red" - options:0 - context:NULL]; - [style addObserver:self - forKeyPath:@"fillColorRGB.green" - options:0 - context:NULL]; - [style addObserver:self - forKeyPath:@"fillColorRGB.blue" - options:0 - context:NULL]; - [style addObserver:self - forKeyPath:@"shapeName" - options:0 - context:NULL]; -} - -- (void) stopObservingNodeStyle:(NodeStyle*)style { - [style removeObserver:self forKeyPath:@"name"]; - [style removeObserver:self forKeyPath:@"strokeThickness"]; - [style removeObserver:self forKeyPath:@"strokeColorRGB.red"]; - [style removeObserver:self forKeyPath:@"strokeColorRGB.green"]; - [style removeObserver:self forKeyPath:@"strokeColorRGB.blue"]; - [style removeObserver:self forKeyPath:@"fillColorRGB.red"]; - [style removeObserver:self forKeyPath:@"fillColorRGB.green"]; - [style removeObserver:self forKeyPath:@"fillColorRGB.blue"]; - [style removeObserver:self forKeyPath:@"shapeName"]; -} - -- (void) clearNodeStylesModel { - GtkTreeModel *model = GTK_TREE_MODEL (store); - GtkTreeIter row; - if (gtk_tree_model_get_iter_first (model, &row)) { - do { - NodeStyle *rowStyle; - gtk_tree_model_get (model, &row, NODE_STYLES_PTR_COL, &rowStyle, -1); - [self stopObservingNodeStyle:rowStyle]; - [rowStyle release]; - } while (gtk_tree_model_iter_next (model, &row)); - } - gtk_list_store_clear (store); -} - -- (void) reloadNodeStyles { - [self clearNodeStylesModel]; - cairo_surface_t *surface = [self createNodeIconSurface]; - for (NodeStyle *style in [styleManager nodeStyles]) { - [self addNodeStyle:style usingSurface:surface]; - } - cairo_surface_destroy (surface); -} -@end - -// }}} - -// vim:ft=objc:ts=8:et:sts=4:sw=4:foldmethod=marker diff --git a/tikzit/src/gtk/NodeStylesPalette.h b/tikzit/src/gtk/NodeStylesPalette.h deleted file mode 100644 index ac712ea..0000000 --- a/tikzit/src/gtk/NodeStylesPalette.h +++ /dev/null @@ -1,43 +0,0 @@ -/* - * Copyright 2011 Alex Merry <dev@randomguy3.me.uk> - * - * 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 the Free Software Foundation; either version 2 of - * the License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see <http://www.gnu.org/licenses/>. - */ - -#import "TZFoundation.h" -#import <gtk/gtk.h> - -@class StyleManager; -@class NodeStyleSelector; -@class NodeStyleEditor; - -@interface NodeStylesPalette: NSObject { - NodeStyleSelector *selector; - NodeStyleEditor *editor; - - GtkWidget *palette; - - GtkWidget *removeStyleButton; - GtkWidget *applyStyleButton; - GtkWidget *clearStyleButton; -} - -@property (retain) StyleManager *styleManager; -@property (readonly) GtkWidget *widget; - -- (id) initWithManager:(StyleManager*)m; - -@end - -// vim:ft=objc:ts=4:et:sts=4:sw=4:foldmethod=marker diff --git a/tikzit/src/gtk/NodeStylesPalette.m b/tikzit/src/gtk/NodeStylesPalette.m deleted file mode 100644 index e28edbb..0000000 --- a/tikzit/src/gtk/NodeStylesPalette.m +++ /dev/null @@ -1,197 +0,0 @@ -/* - * Copyright 2011 Alex Merry <dev@randomguy3.me.uk> - * - * 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 the Free Software Foundation; either version 2 of - * the License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see <http://www.gnu.org/licenses/>. - */ - -#import "NodeStylesPalette.h" - -#import "NodeStyleSelector.h" -#import "NodeStyleEditor.h" -#import "NodeStylesModel.h" -#import "StyleManager.h" - -// {{{ Internal interfaces -// {{{ GTK+ Callbacks -static void add_style_button_cb (GtkButton *widget, NodeStylesPalette *palette); -static void remove_style_button_cb (GtkButton *widget, NodeStylesPalette *palette); -// }}} -// {{{ Notifications - -@interface NodeStylesPalette (Notifications) -- (void) selectedStyleChanged:(NSNotification*)notification; -@end - -// }}} -// {{{ Private - -@interface NodeStylesPalette (Private) -- (void) updateButtonState; -- (void) removeSelectedStyle; -- (void) addStyle; -@end - -// }}} -// }}} -// {{{ API - -@implementation NodeStylesPalette - -@synthesize widget=palette; - -- (id) init { - [self release]; - return nil; -} - -- (id) initWithManager:(StyleManager*)m { - self = [super init]; - - if (self) { - selector = [[NodeStyleSelector alloc] initWithStyleManager:m]; - editor = [[NodeStyleEditor alloc] init]; - - palette = gtk_vbox_new (FALSE, 6); - gtk_container_set_border_width (GTK_CONTAINER (palette), 6); - g_object_ref_sink (palette); - - GtkWidget *mainBox = gtk_hbox_new (FALSE, 0); - gtk_box_pack_start (GTK_BOX (palette), mainBox, FALSE, FALSE, 0); - gtk_widget_show (mainBox); - - GtkWidget *selectorScroller = gtk_scrolled_window_new (NULL, NULL); - gtk_scrolled_window_set_policy (GTK_SCROLLED_WINDOW (selectorScroller), - GTK_POLICY_AUTOMATIC, - GTK_POLICY_AUTOMATIC); - GtkWidget *selectorFrame = gtk_frame_new (NULL); - gtk_container_add (GTK_CONTAINER (selectorScroller), [selector widget]); - gtk_container_add (GTK_CONTAINER (selectorFrame), selectorScroller); - gtk_box_pack_start (GTK_BOX (mainBox), selectorFrame, TRUE, TRUE, 0); - gtk_widget_show (selectorScroller); - gtk_widget_show (selectorFrame); - gtk_widget_show ([selector widget]); - - gtk_box_pack_start (GTK_BOX (mainBox), [editor widget], TRUE, TRUE, 0); - gtk_widget_show ([editor widget]); - - GtkBox *buttonBox = GTK_BOX (gtk_hbox_new(FALSE, 0)); - gtk_box_pack_start (GTK_BOX (palette), GTK_WIDGET (buttonBox), FALSE, FALSE, 0); - - GtkWidget *addStyleButton = gtk_button_new (); - gtk_widget_set_tooltip_text (addStyleButton, "Add a new style"); - GtkWidget *addIcon = gtk_image_new_from_stock (GTK_STOCK_ADD, GTK_ICON_SIZE_BUTTON); - gtk_container_add (GTK_CONTAINER (addStyleButton), addIcon); - gtk_box_pack_start (buttonBox, addStyleButton, FALSE, FALSE, 0); - g_signal_connect (G_OBJECT (addStyleButton), - "clicked", - G_CALLBACK (add_style_button_cb), - self); - - removeStyleButton = gtk_button_new (); - g_object_ref_sink (removeStyleButton); - gtk_widget_set_tooltip_text (removeStyleButton, "Delete selected style"); - GtkWidget *removeIcon = gtk_image_new_from_stock (GTK_STOCK_REMOVE, GTK_ICON_SIZE_BUTTON); - gtk_container_add (GTK_CONTAINER (removeStyleButton), removeIcon); - gtk_box_pack_start (buttonBox, removeStyleButton, FALSE, FALSE, 0); - g_signal_connect (G_OBJECT (removeStyleButton), - "clicked", - G_CALLBACK (remove_style_button_cb), - self); - - gtk_widget_show_all (GTK_WIDGET (buttonBox)); - - [[NSNotificationCenter defaultCenter] addObserver:self - selector:@selector(selectedStyleChanged:) - name:@"SelectedStyleChanged" - object:selector]; - - [self updateButtonState]; - } - - return self; -} - -- (StyleManager*) styleManager { - return [[selector model] styleManager]; -} - -- (void) setStyleManager:(StyleManager*)m { - [[selector model] setStyleManager:m]; -} - -- (void) dealloc { - [[NSNotificationCenter defaultCenter] removeObserver:self]; - [editor release]; - [selector release]; - g_object_unref (palette); - g_object_unref (removeStyleButton); - - [super dealloc]; -} - -@end - -// }}} -// {{{ Notifications - -@implementation NodeStylesPalette (Notifications) -- (void) selectedStyleChanged:(NSNotification*)notification { - [editor setStyle:[selector selectedStyle]]; - [self updateButtonState]; -} -@end - -// }}} -// {{{ Private - -@implementation NodeStylesPalette (Private) -- (void) updateButtonState { - gboolean hasStyleSelection = [selector selectedStyle] != nil; - - gtk_widget_set_sensitive (removeStyleButton, hasStyleSelection); -} - -- (void) removeSelectedStyle { - NodeStyle *style = [selector selectedStyle]; - if (style) - [[[selector model] styleManager] removeNodeStyle:style]; -} - -- (void) addStyle { - NodeStyle *newStyle = [NodeStyle defaultNodeStyleWithName:@"newstyle"]; - [[self styleManager] addNodeStyle:newStyle]; - [selector setSelectedStyle:newStyle]; - [editor selectNameField]; -} - -@end - -// }}} -// {{{ GTK+ callbacks - -static void add_style_button_cb (GtkButton *widget, NodeStylesPalette *palette) { - NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init]; - [palette addStyle]; - [pool drain]; -} - -static void remove_style_button_cb (GtkButton *widget, NodeStylesPalette *palette) { - NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init]; - [palette removeSelectedStyle]; - [pool drain]; -} - -// }}} - -// vim:ft=objc:ts=8:et:sts=4:sw=4:foldmethod=marker diff --git a/tikzit/src/gtk/PreambleEditor.h b/tikzit/src/gtk/PreambleEditor.h deleted file mode 100644 index f181446..0000000 --- a/tikzit/src/gtk/PreambleEditor.h +++ /dev/null @@ -1,51 +0,0 @@ -/* - * Copyright 2011 Alex Merry <dev@randomguy3.me.uk> - * - * 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 the Free Software Foundation; either version 2 of - * the License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see <http://www.gnu.org/licenses/>. - */ - -#import "TZFoundation.h" -#import <gtk/gtk.h> - -@class Preambles; - -@interface PreambleEditor: NSObject { - Preambles *preambles; - - // we don't keep any refs, as we control - // the top window - GtkWindow *parentWindow; - GtkWindow *window; - GtkListStore *preambleListStore; - GtkTreeView *preambleSelector; - GtkTextView *preambleView; - BOOL blockSignals; - BOOL adding; -} - -- (id) initWithPreambles:(Preambles*)p; - -- (void) setParentWindow:(GtkWindow*)parent; - -- (Preambles*) preambles; - -- (void) present; -- (void) show; -- (void) hide; -- (BOOL) isVisible; -- (void) setVisible:(BOOL)visible; - -@end - -// vim:ft=objc:ts=8:et:sts=4:sw=4:foldmethod=marker diff --git a/tikzit/src/gtk/PreambleEditor.m b/tikzit/src/gtk/PreambleEditor.m deleted file mode 100644 index d1f72ee..0000000 --- a/tikzit/src/gtk/PreambleEditor.m +++ /dev/null @@ -1,568 +0,0 @@ -/* - * Copyright 2011 Alex Merry <dev@randomguy3.me.uk> - * - * 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 the Free Software Foundation; either version 2 of - * the License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see <http://www.gnu.org/licenses/>. - */ - -#import "PreambleEditor.h" - -#import "Application.h" -#import "Preambles.h" -#import <gdk/gdk.h> - -enum { - NAME_COLUMN, - IS_CUSTOM_COLUMN, - N_COLUMNS -}; - -// {{{ Internal interfaces -// {{{ Signals -static gboolean window_delete_event_cb (GtkWidget *widget, - GdkEvent *event, - PreambleEditor *editor); -static gboolean window_focus_out_event_cb (GtkWidget *widget, - GdkEvent *event, - PreambleEditor *editor); -static void close_button_clicked_cb (GtkButton *widget, PreambleEditor *editor); -static void add_button_clicked_cb (GtkButton *widget, PreambleEditor *editor); -static void remove_button_clicked_cb (GtkButton *widget, PreambleEditor *editor); -/* -static void undo_button_clicked_cb (GtkButton *widget, PreambleEditor *editor); -static void redo_button_clicked_cb (GtkButton *widget, PreambleEditor *editor); -*/ -static void preamble_name_edited_cb (GtkCellRendererText *renderer, - gchar *path, - gchar *new_text, - PreambleEditor *editor); -static void preamble_selection_changed_cb (GtkTreeSelection *treeselection, - PreambleEditor *editor); -// }}} - -@interface PreambleEditor (Private) -- (void) loadUi; -- (void) save; -- (void) revert; -- (void) update; -- (void) fillListStore; -- (BOOL) isDefaultPreambleSelected; -- (NSString*) selectedPreambleName; -- (void) addPreamble; -- (void) deletePreamble; -- (void) renamePreambleAtPath:(gchar*)path to:(gchar*)newValue; -- (void) nodeStylePropertyChanged:(NSNotification*)notification; -- (void) edgeStylePropertyChanged:(NSNotification*)notification; -@end - -// }}} -// {{{ API - -@implementation PreambleEditor - -- (id) init { - [self release]; - return nil; -} - -- (id) initWithPreambles:(Preambles*)p { - self = [super init]; - - if (self) { - preambles = [p retain]; - parentWindow = NULL; - window = NULL; - preambleView = NULL; - preambleSelector = NULL; - blockSignals = NO; - adding = NO; - [[NSNotificationCenter defaultCenter] addObserver:self - selector:@selector(nodeStylePropertyChanged:) - name:@"NodeStylePropertyChanged" - object:nil]; - [[NSNotificationCenter defaultCenter] addObserver:self - selector:@selector(edgeStylePropertyChanged:) - name:@"EdgeStylePropertyChanged" - object:nil]; - } - - return self; -} - -- (Preambles*) preambles { - return preambles; -} - -- (void) setParentWindow:(GtkWindow*)parent { - GtkWindow *oldParent = parentWindow; - - if (parentWindow) - g_object_ref (parentWindow); - parentWindow = parent; - if (oldParent) - g_object_unref (oldParent); - - if (window) { - gtk_window_set_transient_for (window, parentWindow); - } -} - -- (void) present { - [self loadUi]; - gtk_window_present (GTK_WINDOW (window)); - [self revert]; -} - -- (void) show { - [self loadUi]; - gtk_widget_show (GTK_WIDGET (window)); - [self revert]; -} - -- (void) hide { - if (!window) { - return; - } - [self save]; - gtk_widget_hide (GTK_WIDGET (window)); -} - -- (BOOL) isVisible { - if (!window) { - return NO; - } - gboolean visible; - g_object_get (G_OBJECT (window), "visible", &visible, NULL); - return visible ? YES : NO; -} - -- (void) setVisible:(BOOL)visible { - if (visible) { - [self show]; - } else { - [self hide]; - } -} - -- (void) dealloc { - [preambles release]; - preambles = nil; - if (window) { - gtk_widget_destroy (GTK_WIDGET (window)); - window = NULL; - } - if (parentWindow) { - g_object_ref (parentWindow); - } - - [super dealloc]; -} - -@end - -// }}} -// {{{ Private - -@implementation PreambleEditor (Private) -- (GtkWidget*) createPreambleList { - preambleListStore = gtk_list_store_new (N_COLUMNS, G_TYPE_STRING, G_TYPE_BOOLEAN); - preambleSelector = GTK_TREE_VIEW (gtk_tree_view_new_with_model ( - GTK_TREE_MODEL (preambleListStore))); - gtk_widget_set_size_request (GTK_WIDGET (preambleSelector), 150, -1); - gtk_tree_view_set_headers_visible (preambleSelector, FALSE); - - GtkCellRenderer *renderer; - GtkTreeViewColumn *column; - - renderer = gtk_cell_renderer_text_new (); - column = gtk_tree_view_column_new_with_attributes ("Preamble", - renderer, - "text", NAME_COLUMN, - "editable", IS_CUSTOM_COLUMN, - NULL); - gtk_tree_view_append_column (preambleSelector, column); - g_signal_connect (G_OBJECT (renderer), - "edited", - G_CALLBACK (preamble_name_edited_cb), - self); - - GtkWidget *listScroller = gtk_scrolled_window_new (NULL, NULL); - gtk_scrolled_window_set_policy (GTK_SCROLLED_WINDOW (listScroller), - GTK_POLICY_AUTOMATIC, - GTK_POLICY_AUTOMATIC); - gtk_container_add (GTK_CONTAINER (listScroller), - GTK_WIDGET (preambleSelector)); - - [self fillListStore]; - - GtkTreeSelection *sel = gtk_tree_view_get_selection (preambleSelector); - gtk_tree_selection_set_mode (sel, GTK_SELECTION_BROWSE); - g_signal_connect (G_OBJECT (sel), - "changed", - G_CALLBACK (preamble_selection_changed_cb), - self); - - return listScroller; -} - -- (void) loadUi { - if (window) { - return; - } - - window = GTK_WINDOW (gtk_window_new (GTK_WINDOW_TOPLEVEL)); - gtk_window_set_title (window, "Preamble editor"); - gtk_window_set_position (window, GTK_WIN_POS_CENTER_ON_PARENT); - gtk_window_set_default_size (window, 600, 400); - gtk_window_set_type_hint (window, GDK_WINDOW_TYPE_HINT_DIALOG); - if (parentWindow) { - gtk_window_set_transient_for (window, parentWindow); - } - GdkEventMask mask; - g_object_get (G_OBJECT (window), "events", &mask, NULL); - mask |= GDK_FOCUS_CHANGE_MASK; - g_object_set (G_OBJECT (window), "events", mask, NULL); - g_signal_connect (window, - "delete-event", - G_CALLBACK (window_delete_event_cb), - self); - g_signal_connect (window, - "focus-out-event", - G_CALLBACK (window_focus_out_event_cb), - self); - - GtkWidget *mainBox = gtk_vbox_new (FALSE, 18); - gtk_container_set_border_width (GTK_CONTAINER (mainBox), 12); - gtk_container_add (GTK_CONTAINER (window), mainBox); - - GtkPaned *paned = GTK_PANED (gtk_hpaned_new ()); - gtk_box_pack_start (GTK_BOX (mainBox), - GTK_WIDGET (paned), - TRUE, TRUE, 0); - - GtkWidget *listWidget = [self createPreambleList]; - GtkWidget *listFrame = gtk_frame_new (NULL); - gtk_container_add (GTK_CONTAINER (listFrame), listWidget); - - GtkBox *listBox = GTK_BOX (gtk_vbox_new (FALSE, 6)); - gtk_box_pack_start (listBox, listFrame, TRUE, TRUE, 0); - - GtkContainer *listButtonBox = GTK_CONTAINER (gtk_hbox_new (FALSE, 6)); - gtk_box_pack_start (listBox, GTK_WIDGET (listButtonBox), FALSE, TRUE, 0); - GtkWidget *addButton = gtk_button_new_from_stock (GTK_STOCK_ADD); - g_signal_connect (addButton, - "clicked", - G_CALLBACK (add_button_clicked_cb), - self); - gtk_container_add (listButtonBox, addButton); - GtkWidget *removeButton = gtk_button_new_from_stock (GTK_STOCK_REMOVE); - g_signal_connect (removeButton, - "clicked", - G_CALLBACK (remove_button_clicked_cb), - self); - gtk_container_add (listButtonBox, removeButton); - - gtk_paned_pack1 (paned, GTK_WIDGET (listBox), FALSE, TRUE); - - preambleView = GTK_TEXT_VIEW (gtk_text_view_new ()); - gtk_text_view_set_left_margin (preambleView, 3); - gtk_text_view_set_right_margin (preambleView, 3); - GtkWidget *scroller = gtk_scrolled_window_new (NULL, NULL); - gtk_scrolled_window_set_policy (GTK_SCROLLED_WINDOW (scroller), - GTK_POLICY_AUTOMATIC, // horiz - GTK_POLICY_ALWAYS); // vert - gtk_container_add (GTK_CONTAINER (scroller), GTK_WIDGET (preambleView)); - GtkWidget *editorFrame = gtk_frame_new (NULL); - gtk_container_add (GTK_CONTAINER (editorFrame), scroller); - gtk_paned_pack2 (paned, editorFrame, TRUE, TRUE); - - GtkContainer *buttonBox = GTK_CONTAINER (gtk_hbutton_box_new ()); - gtk_box_set_spacing (GTK_BOX (buttonBox), 6); - gtk_button_box_set_layout (GTK_BUTTON_BOX (buttonBox), GTK_BUTTONBOX_END); - gtk_box_pack_start (GTK_BOX (mainBox), - GTK_WIDGET (buttonBox), - FALSE, TRUE, 0); - GtkWidget *closeButton = gtk_button_new_from_stock (GTK_STOCK_CLOSE); - gtk_container_add (buttonBox, closeButton); - g_signal_connect (closeButton, - "clicked", - G_CALLBACK (close_button_clicked_cb), - self); - /* - GtkWidget *undoButton = gtk_button_new_from_stock (GTK_STOCK_UNDO); - gtk_container_add (buttonBox, undoButton); - gtk_button_box_set_child_secondary (GTK_BUTTON_BOX (buttonBox), - undoButton, - TRUE); - g_signal_connect (undoButton, - "clicked", - G_CALLBACK (undo_button_clicked_cb), - self); - GtkWidget *redoButton = gtk_button_new_from_stock (GTK_STOCK_REDO); - gtk_container_add (buttonBox, redoButton); - gtk_button_box_set_child_secondary (GTK_BUTTON_BOX (buttonBox), - redoButton, - TRUE); - g_signal_connect (redoButton, - "clicked", - G_CALLBACK (redo_button_clicked_cb), - self); - */ - [self revert]; - - gtk_widget_show_all (mainBox); -} - -- (void) save { - if (!preambleView) - return; - if ([self isDefaultPreambleSelected]) - return; - GtkTextIter start,end; - GtkTextBuffer *preambleBuffer = gtk_text_view_get_buffer (preambleView); - gtk_text_buffer_get_bounds(preambleBuffer, &start, &end); - gchar *text = gtk_text_buffer_get_text(preambleBuffer, &start, &end, FALSE); - NSString *preamble = [NSString stringWithUTF8String:text]; - g_free (text); - [preambles setCurrentPreamble:preamble]; - [app saveConfiguration]; -} - -- (void) revert { - if (!preambleView) - return; - GtkTextBuffer *preambleBuffer = gtk_text_view_get_buffer (preambleView); - gtk_text_buffer_set_text (preambleBuffer, [[preambles currentPreamble] UTF8String], -1); - gtk_text_view_set_editable (preambleView, ![self isDefaultPreambleSelected]); -} - -- (void) update { - if (!blockSignals) { - [self save]; - } - GtkTreeSelection *sel = gtk_tree_view_get_selection (preambleSelector); - GtkTreeIter row; - GtkTreeModel *model; - if (gtk_tree_selection_get_selected (sel, &model, &row)) { - gchar *name; - gtk_tree_model_get (model, &row, NAME_COLUMN, &name, -1); - NSString *preambleName = [NSString stringWithUTF8String:name]; - [preambles setSelectedPreambleName:preambleName]; - g_free (name); - } - [self revert]; -} - -- (void) fillListStore { - blockSignals = YES; - - GtkTreeIter row; - gtk_list_store_clear (preambleListStore); - - gtk_list_store_append (preambleListStore, &row); - gtk_list_store_set (preambleListStore, &row, - NAME_COLUMN, [[preambles defaultPreambleName] UTF8String], - IS_CUSTOM_COLUMN, FALSE, - -1); - GtkTreeSelection *sel = gtk_tree_view_get_selection (preambleSelector); - if ([self isDefaultPreambleSelected]) { - gtk_tree_selection_select_iter (sel, &row); - } - - NSEnumerator *en = [preambles customPreambleNameEnumerator]; - NSString *preambleName; - while ((preambleName = [en nextObject])) { - gtk_list_store_append (preambleListStore, &row); - gtk_list_store_set (preambleListStore, &row, - NAME_COLUMN, [preambleName UTF8String], - IS_CUSTOM_COLUMN, TRUE, - -1); - if ([preambleName isEqualToString:[self selectedPreambleName]]) { - gtk_tree_selection_select_iter (sel, &row); - } - } - - blockSignals = NO; -} - -- (BOOL) isDefaultPreambleSelected { - return [preambles selectedPreambleIsDefault]; -} - -- (NSString*) selectedPreambleName { - return [preambles selectedPreambleName]; -} - -- (void) addPreamble { - NSString *newName = [preambles addPreamble]; - - GtkTreeIter row; - gtk_list_store_append (preambleListStore, &row); - gtk_list_store_set (preambleListStore, &row, - NAME_COLUMN, [newName UTF8String], - IS_CUSTOM_COLUMN, TRUE, - -1); - - GtkTreeSelection *sel = gtk_tree_view_get_selection (preambleSelector); - gtk_tree_selection_select_iter (sel, &row); -} - -- (void) deletePreamble { - if ([self isDefaultPreambleSelected]) - return; - - NSString *name = [self selectedPreambleName]; - - GtkTreeIter row; - GtkTreeModel *model = GTK_TREE_MODEL (preambleListStore); - - gtk_tree_model_get_iter_first (model, &row); - // ignore first; it is the default one - gboolean found = FALSE; - while (!found && gtk_tree_model_iter_next (model, &row)) { - gchar *candidate; - gtk_tree_model_get (model, &row, NAME_COLUMN, &candidate, -1); - if (g_strcmp0 (candidate, [name UTF8String]) == 0) { - found = TRUE; - } - g_free (candidate); - } - - if (!found) - return; - - if (![preambles removePreamble:name]) - return; - - blockSignals = YES; - - gboolean had_next = gtk_list_store_remove (preambleListStore, &row); - if (!had_next) { - // select the last item - gint length = gtk_tree_model_iter_n_children (model, NULL); - gtk_tree_model_iter_nth_child (model, &row, NULL, length - 1); - } - - GtkTreeSelection *sel = gtk_tree_view_get_selection (preambleSelector); - gtk_tree_selection_select_iter (sel, &row); - - [self revert]; - - blockSignals = NO; -} - -- (void) renamePreambleAtPath:(gchar*)path to:(gchar*)newValue { - NSString *newName = [NSString stringWithUTF8String:newValue]; - - GtkTreeIter row; - GtkTreeModel *model = GTK_TREE_MODEL (preambleListStore); - - if (!gtk_tree_model_get_iter_from_string (model, &row, path)) - return; - - gchar *oldValue; - gtk_tree_model_get (model, &row, NAME_COLUMN, &oldValue, -1); - - NSString* oldName = [NSString stringWithUTF8String:oldValue]; - if ([preambles renamePreambleFrom:oldName to:newName]) { - gtk_list_store_set (preambleListStore, &row, - NAME_COLUMN, newValue, - -1); - } -} - -- (void) nodeStylePropertyChanged:(NSNotification*)notification { - if ([self isDefaultPreambleSelected]) { - [self revert]; - } -} - -- (void) edgeStylePropertyChanged:(NSNotification*)notification { - if ([self isDefaultPreambleSelected]) { - [self revert]; - } -} -@end - -// }}} -// {{{ GTK+ callbacks - -static gboolean window_delete_event_cb (GtkWidget *widget, - GdkEvent *event, - PreambleEditor *editor) { - NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init]; - [editor hide]; - [pool drain]; - return TRUE; // we dealt with this event -} - -static gboolean window_focus_out_event_cb (GtkWidget *widget, - GdkEvent *event, - PreambleEditor *editor) { - NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init]; - [editor save]; - [pool drain]; - return FALSE; -} - -static void close_button_clicked_cb (GtkButton *widget, PreambleEditor *editor) { - NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init]; - [editor hide]; - [pool drain]; -} - -static void add_button_clicked_cb (GtkButton *widget, PreambleEditor *editor) { - NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init]; - [editor addPreamble]; - [pool drain]; -} - -static void remove_button_clicked_cb (GtkButton *widget, PreambleEditor *editor) { - NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init]; - [editor deletePreamble]; - [pool drain]; -} - -/* -static void undo_button_clicked_cb (GtkButton *widget, PreambleEditor *editor) { - NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init]; - NSLog(@"Undo"); - [pool drain]; -} - -static void redo_button_clicked_cb (GtkButton *widget, PreambleEditor *editor) { - NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init]; - NSLog(@"Redo"); - [pool drain]; -} -*/ - -static void preamble_name_edited_cb (GtkCellRendererText *renderer, - gchar *path, - gchar *new_text, - PreambleEditor *editor) { - NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init]; - [editor renamePreambleAtPath:path to:new_text]; - [pool drain]; -} - -static void preamble_selection_changed_cb (GtkTreeSelection *treeselection, - PreambleEditor *editor) { - NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init]; - [editor update]; - [pool drain]; -} - -// }}} - -// vim:ft=objc:ts=4:et:sts=4:sw=4:foldmethod=marker diff --git a/tikzit/src/gtk/Preambles+Storage.h b/tikzit/src/gtk/Preambles+Storage.h deleted file mode 100644 index 76f56cc..0000000 --- a/tikzit/src/gtk/Preambles+Storage.h +++ /dev/null @@ -1,29 +0,0 @@ -/* - * Copyright 2011 Alex Merry <dev@randomguy3.me.uk> - * - * 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 the Free Software Foundation; either version 2 of - * the License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see <http://www.gnu.org/licenses/>. - */ - -#import "Preambles.h" - -@interface Preambles (Storage) - -+ (Preambles*) preamblesFromDirectory:(NSString*)directory; -- (id) initFromDirectory:(NSString*)directory; -- (void) loadFromDirectory:(NSString*)directory; -- (void) storeToDirectory:(NSString*)directory; - -@end - -// vim:ft=objc:ts=8:et:sts=4:sw=4 diff --git a/tikzit/src/gtk/Preambles+Storage.m b/tikzit/src/gtk/Preambles+Storage.m deleted file mode 100644 index bd3ea03..0000000 --- a/tikzit/src/gtk/Preambles+Storage.m +++ /dev/null @@ -1,84 +0,0 @@ -/* - * Copyright 2011 Alex Merry <dev@randomguy3.me.uk> - * - * 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 the Free Software Foundation; either version 2 of - * the License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see <http://www.gnu.org/licenses/>. - */ - -#import "Preambles+Storage.h" - -static NSString *ext = @"preamble"; - -@implementation Preambles (Storage) - -+ (Preambles*) preamblesFromDirectory:(NSString*)directory { - return [[[self alloc] initFromDirectory:directory] autorelease]; -} - -- (id) initFromDirectory:(NSString*)directory { - BOOL isDir = NO; - if ([[NSFileManager defaultManager] fileExistsAtPath:directory isDirectory:&isDir] && isDir) { - self = [super init]; - - if (self) { - selectedPreambleName = @"default"; - preambleDict = nil; - [self loadFromDirectory:directory]; - } - } else { - self = [self init]; - } - - return self; -} - -- (void) loadFromDirectory:(NSString*)directory { - preambleDict = [[NSMutableDictionary alloc] initWithCapacity:1]; - NSDirectoryEnumerator *en = [[NSFileManager defaultManager] enumeratorAtPath:directory]; - NSString *filename; - while ((filename = [en nextObject]) != nil) { - if ([filename hasSuffix:ext] && [[en fileAttributes] fileType] == NSFileTypeRegular) { - NSString *path = [directory stringByAppendingPathComponent:filename]; - NSString *contents = [NSString stringWithContentsOfFile:path]; - if (contents) { - [preambleDict setObject:contents forKey:[filename stringByDeletingPathExtension]]; - } - } - } -} - -- (void) storeToDirectory:(NSString*)directory { - NSDirectoryEnumerator *den = [[NSFileManager defaultManager] enumeratorAtPath:directory]; - NSString *filename; - while ((filename = [den nextObject]) != nil) { - if ([filename hasSuffix:ext] && [[den fileAttributes] fileType] == NSFileTypeRegular) { - NSString *path = [directory stringByAppendingPathComponent:filename]; - NSString *entry = [filename stringByDeletingPathExtension]; - if ([preambleDict objectForKey:entry] == nil) { - [[NSFileManager defaultManager] removeFileAtPath:path handler:nil]; - } - } - } - - NSEnumerator *en = [self customPreambleNameEnumerator]; - NSString *entry; - while ((entry = [en nextObject]) != nil) { - NSString *path = [directory stringByAppendingPathComponent:[entry stringByAppendingPathExtension:ext]]; - NSString *contents = [preambleDict objectForKey:entry]; - [contents writeToFile:path atomically:YES]; - } -} - -@end - -// vim:ft=objc:ts=8:et:sts=4:sw=4 diff --git a/tikzit/src/gtk/PreviewRenderer.h b/tikzit/src/gtk/PreviewRenderer.h deleted file mode 100644 index d691722..0000000 --- a/tikzit/src/gtk/PreviewRenderer.h +++ /dev/null @@ -1,48 +0,0 @@ -/* - * Copyright 2011 Alex Merry <dev@randomguy3.me.uk> - * - * 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 the Free Software Foundation; either version 2 of - * the License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see <http://www.gnu.org/licenses/>. - */ - -#import "TZFoundation.h" -#import <poppler.h> - -#import "Surface.h" - -@class Configuration; -@class Preambles; -@class TikzDocument; - -@interface PreviewRenderer: NSObject<RenderDelegate> { - Configuration *config; - Preambles *preambles; - TikzDocument *document; - PopplerDocument *pdfDocument; - PopplerPage *pdfPage; -} - -@property (readonly) Preambles *preambles; -@property (retain) TikzDocument *document; -@property (readonly) double height; -@property (readonly) double width; - -- (id) initWithPreambles:(Preambles*)p config:(Configuration*)c; - -- (BOOL) updateWithError:(NSError**)error; -- (BOOL) update; -- (BOOL) isValid; - -@end - -// vim:ft=objc:ts=8:et:sts=4:sw=4 diff --git a/tikzit/src/gtk/PreviewRenderer.m b/tikzit/src/gtk/PreviewRenderer.m deleted file mode 100644 index 26293b5..0000000 --- a/tikzit/src/gtk/PreviewRenderer.m +++ /dev/null @@ -1,253 +0,0 @@ -/* - * Copyright 2011 Alex Merry <dev@randomguy3.me.uk> - * - * 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 the Free Software Foundation; either version 2 of - * the License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see <http://www.gnu.org/licenses/>. - */ - -#import "PreviewRenderer.h" - -#import "CairoRenderContext.h" -#import "Configuration.h" -#import "Preambles.h" -#import "TikzDocument.h" - -@implementation PreviewRenderer - -@synthesize preambles, document; - -- (id) init { - [self release]; - return nil; -} - -- (id) initWithPreambles:(Preambles*)p config:(Configuration*)c { - self = [super init]; - - if (self) { - document = nil; - config = [c retain]; - preambles = [p retain]; - pdfDocument = NULL; - pdfPage = NULL; - } - - return self; -} - -- (void) dealloc { - [document release]; - [config release]; - [preambles release]; - - if (pdfDocument) { - g_object_unref (pdfDocument); - pdfDocument = NULL; - } - if (pdfPage) { - g_object_unref (pdfPage); - pdfPage = NULL; - } - - [super dealloc]; -} - -- (BOOL) update { - NSError *error = nil; - BOOL result = [self updateWithError:&error]; - if (error) { - logError (error, @"Could not update preview"); - if ([error code] == TZ_ERR_TOOL_FAILED) { - NSLog (@"Output: %@", [[error userInfo] objectForKey:TZToolOutputErrorKey]); - } - } - return result; -} - -- (BOOL) updateWithError:(NSError**)error { - if (document == nil) { - if (error) { - *error = [NSError errorWithMessage:@"No document given" code:TZ_ERR_BADSTATE]; - } - if (pdfDocument) { - g_object_unref (pdfDocument); - pdfDocument = NULL; - } - if (pdfPage) { - g_object_unref (pdfPage); - pdfPage = NULL; - } - return NO; - } - - NSString *tex = [NSString stringWithFormat:@"%@%@%@", - [preambles currentPreamble], - [document tikz], - [preambles currentPostamble]]; - - NSString *tempDir = [[NSFileManager defaultManager] createTempDirectoryWithError:error]; - if (!tempDir) { - if (error) { - *error = [NSError errorWithMessage:@"Could not create temporary directory" code:TZ_ERR_IO cause:*error]; - } - return NO; - } - - // write tex code to temporary file - NSString *texFile = [NSString stringWithFormat:@"%@/tikzit.tex", tempDir]; - NSString *pdfFile = [NSString stringWithFormat:@"file://%@/tikzit.pdf", tempDir]; - [tex writeToFile:texFile atomically:YES]; - - NSTask *latexTask = [[NSTask alloc] init]; - [latexTask setCurrentDirectoryPath:tempDir]; - - // GNUStep is clever enough to use PATH - NSString *path = [config stringEntry:@"pdflatex" - inGroup:@"Previews" - withDefault:@"pdflatex"]; - [latexTask setLaunchPath:path]; - - NSArray *args = [NSArray arrayWithObjects: - @"-fmt=latex", - @"-output-format=pdf", - @"-interaction=nonstopmode", - @"-halt-on-error", - texFile, - nil]; - [latexTask setArguments:args]; - - NSPipe *pout = [NSPipe pipe]; - [latexTask setStandardOutput:pout]; - - NSFileHandle *latexOut = [pout fileHandleForReading]; - - BOOL success = NO; - - NS_DURING { - [latexTask launch]; - [latexTask waitUntilExit]; - } NS_HANDLER { - NSLog(@"Failed to run '%@'; error was: %@", path, [localException reason]); - (void)localException; - if (error) { - NSString *desc = [NSString stringWithFormat:@"Failed to run '%@'", path]; - NSMutableDictionary *errorDetail = [NSMutableDictionary dictionaryWithCapacity:2]; - [errorDetail setValue:desc forKey:NSLocalizedDescriptionKey]; - *error = [NSError errorWithDomain:TZErrorDomain code:TZ_ERR_IO userInfo:errorDetail]; - } - - // remove all temporary files - [[NSFileManager defaultManager] removeFileAtPath:tempDir handler:NULL]; - [latexTask release]; - - return NO; - } NS_ENDHANDLER - - if ([latexTask terminationStatus] != 0) { - if (error) { - NSData *data = [latexOut readDataToEndOfFile]; - NSString *str = [[NSString alloc] initWithData:data - encoding:NSUTF8StringEncoding]; - NSMutableDictionary *errorDetail = [NSMutableDictionary dictionaryWithCapacity:2]; - [errorDetail setValue:@"Generating a PDF file with pdflatex failed" forKey:NSLocalizedDescriptionKey]; - [errorDetail setValue:str forKey:TZToolOutputErrorKey]; - *error = [NSError errorWithDomain:TZErrorDomain code:TZ_ERR_TOOL_FAILED userInfo:errorDetail]; - [str release]; - } - } else { - // load pdf document - GError* gerror = NULL; - pdfDocument = poppler_document_new_from_file([pdfFile UTF8String], NULL, &gerror); - if (!pdfDocument) { - if (error) { - *error = [NSError errorWithMessage:[NSString stringWithFormat:@"Could not load PDF document", pdfFile] - code:TZ_ERR_IO - cause:[NSError errorWithGError:gerror]]; - } - g_error_free(gerror); - } else { - pdfPage = poppler_document_get_page(pdfDocument, 0); - if(!pdfPage) { - if (error) { - *error = [NSError errorWithMessage:@"Could not open first page of PDF document" - code:TZ_ERR_OTHER]; - } - g_object_unref(pdfDocument); - } else { - success = YES; - } - } - } - - // remove all temporary files - [[NSFileManager defaultManager] removeFileAtPath:tempDir handler:NULL]; - [latexTask release]; - - return success; -} - -- (BOOL) isValid { - return pdfPage ? YES : NO; -} - -- (double) width { - double w = 0.0; - if (pdfPage) - poppler_page_get_size(pdfPage, &w, NULL); - return w; -} - -- (double) height { - double h = 0.0; - if (pdfPage) - poppler_page_get_size(pdfPage, NULL, &h); - return h; -} - -- (void) renderWithContext:(id<RenderContext>)c onSurface:(id<Surface>)surface { - if (document != nil && pdfPage) { - CairoRenderContext *context = (CairoRenderContext*)c; - - double w = 0.0; - double h = 0.0; - poppler_page_get_size(pdfPage, &w, &h); - if (w==0) w = 1.0; - if (h==0) h = 1.0; - - double scale = ([surface height] / h) * 0.95; - if (w * scale > [surface width]) scale = [surface width] / w; - [[surface transformer] setScale:scale]; - - NSPoint origin; - w *= scale; - h *= scale; - origin.x = ([surface width] - w) / 2; - origin.y = ([surface height] - h) / 2; - - [[surface transformer] setOrigin:origin]; - - [context saveState]; - [context applyTransform:[surface transformer]]; - - // white-out - [context paintWithColor:WhiteRColor]; - - poppler_page_render (pdfPage, [context cairoContext]); - - [context restoreState]; - } -} - -@end - -// vim:ft=objc:ts=8:et:sts=4:sw=4 diff --git a/tikzit/src/gtk/PreviewWindow.h b/tikzit/src/gtk/PreviewWindow.h deleted file mode 100644 index 8bcd3e5..0000000 --- a/tikzit/src/gtk/PreviewWindow.h +++ /dev/null @@ -1,51 +0,0 @@ -/* - * Copyright 2011 Alex Merry <dev@randomguy3.me.uk> - * - * 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 the Free Software Foundation; either version 2 of - * the License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see <http://www.gnu.org/licenses/>. - */ - -#import "TZFoundation.h" -#import <gtk/gtk.h> - -@class Configuration; -@class Preambles; -@class PreviewRenderer; -@class TikzDocument; -@class WidgetSurface; - -@interface PreviewWindow: NSObject { - PreviewRenderer *previewer; - GtkWindow *window; - WidgetSurface *surface; - GtkWindow *parent; -} - -- (id) initWithPreambles:(Preambles*)p config:(Configuration*)c; - -- (void) setParentWindow:(GtkWindow*)parent; - -- (TikzDocument*) document; -- (void) setDocument:(TikzDocument*)doc; - -- (BOOL) update; - -- (void) present; -- (void) show; -- (void) hide; -- (BOOL) isVisible; -- (void) setVisible:(BOOL)visible; - -@end - -// vim:ft=objc:ts=8:et:sts=4:sw=4 diff --git a/tikzit/src/gtk/PreviewWindow.m b/tikzit/src/gtk/PreviewWindow.m deleted file mode 100644 index fc0e7a3..0000000 --- a/tikzit/src/gtk/PreviewWindow.m +++ /dev/null @@ -1,195 +0,0 @@ -/* - * Copyright 2011 Alex Merry <dev@randomguy3.me.uk> - * - * 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 the Free Software Foundation; either version 2 of - * the License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see <http://www.gnu.org/licenses/>. - */ - -#import "PreviewWindow.h" - -#import "Preambles.h" -#import "PreviewRenderer.h" -#import "TikzDocument.h" -#import "WidgetSurface.h" - -#import "gtkhelpers.h" - -@interface PreviewWindow (Private) -- (BOOL) updateOrShowError; -- (void) updateDefaultSize; -@end - -// {{{ API - -@implementation PreviewWindow - -- (id) init { - [self release]; - return nil; -} - -- (id) initWithPreambles:(Preambles*)p config:(Configuration*)c { - self = [super init]; - - if (self) { - parent = NULL; - previewer = [[PreviewRenderer alloc] initWithPreambles:p config:c]; - - window = GTK_WINDOW (gtk_window_new (GTK_WINDOW_TOPLEVEL)); - gtk_window_set_title (window, "Preview"); - gtk_window_set_resizable (window, TRUE); - gtk_window_set_default_size (window, 150.0, 150.0); - g_signal_connect (G_OBJECT (window), - "delete-event", - G_CALLBACK (gtk_widget_hide_on_delete), - NULL); - - GtkWidget *pdfArea = gtk_drawing_area_new (); - gtk_container_add (GTK_CONTAINER (window), pdfArea); - gtk_widget_show (pdfArea); - surface = [[WidgetSurface alloc] initWithWidget:pdfArea]; - [surface setRenderDelegate:previewer]; - Transformer *t = [surface transformer]; - [t setFlippedAboutXAxis:![t isFlippedAboutXAxis]]; - } - - return self; -} - -- (void) setParentWindow:(GtkWindow*)p { - parent = p; - gtk_window_set_transient_for (window, p); - if (p != NULL) { - gtk_window_set_position (window, GTK_WIN_POS_CENTER_ON_PARENT); - } -} - -- (TikzDocument*) document { - return [previewer document]; -} - -- (void) setDocument:(TikzDocument*)doc { - [previewer setDocument:doc]; -} - -- (void) present { - if ([self updateOrShowError]) { - [self updateDefaultSize]; - gtk_window_present (GTK_WINDOW (window)); - [surface invalidate]; - } -} - -- (BOOL) update { - if ([self updateOrShowError]) { - [self updateDefaultSize]; - return YES; - } - - return NO; -} - -- (void) show { - if ([self updateOrShowError]) { - [self updateDefaultSize]; - gtk_widget_show (GTK_WIDGET (window)); - [surface invalidate]; - } -} - -- (void) hide { - gtk_widget_hide (GTK_WIDGET (window)); -} - -- (BOOL) isVisible { - gboolean visible; - g_object_get (G_OBJECT (window), "visible", &visible, NULL); - return visible ? YES : NO; -} - -- (void) setVisible:(BOOL)visible { - if (visible) { - [self show]; - } else { - [self hide]; - } -} - -- (void) dealloc { - gtk_widget_destroy (GTK_WIDGET (window)); - [previewer release]; - [surface release]; - - [super dealloc]; -} - -@end -// }}} - -@implementation PreviewWindow (Private) -- (BOOL) updateOrShowError { - NSError *error = nil; - if (![previewer updateWithError:&error]) { - GtkWindow *dparent = gtk_widget_get_visible (GTK_WIDGET (window)) - ? window - : parent; - GtkWidget *dialog = gtk_message_dialog_new (dparent, - GTK_DIALOG_DESTROY_WITH_PARENT, - GTK_MESSAGE_ERROR, - GTK_BUTTONS_CLOSE, - "Failed to generate the preview: %s", - [[error localizedDescription] UTF8String]); -#if GTK_CHECK_VERSION(2,22,0) - if ([error code] == TZ_ERR_TOOL_FAILED) { - GtkBox *box = GTK_BOX (gtk_message_dialog_get_message_area (GTK_MESSAGE_DIALOG (dialog))); - GtkWidget *label = gtk_label_new ("pdflatex said:"); - gtk_misc_set_alignment (GTK_MISC (label), 0, 0.5f); - gtk_widget_show (label); - gtk_box_pack_start (box, label, FALSE, TRUE, 0); - - GtkWidget *view = gtk_text_view_new (); - GtkTextBuffer *buffer = gtk_text_view_get_buffer (GTK_TEXT_VIEW (view)); - gtk_text_buffer_set_text (buffer, [[error toolOutput] UTF8String], -1); - gtk_text_view_set_editable (GTK_TEXT_VIEW (view), FALSE); - gtk_widget_show (view); - GtkWidget *scrolledView = gtk_scrolled_window_new (NULL, NULL); - gtk_scrolled_window_set_policy (GTK_SCROLLED_WINDOW (scrolledView), - GTK_POLICY_NEVER, // horiz - GTK_POLICY_ALWAYS); // vert - gtk_widget_set_size_request (scrolledView, -1, 120); - gtk_container_add (GTK_CONTAINER (scrolledView), view); - gtk_widget_show (scrolledView); - gtk_box_pack_start (box, scrolledView, TRUE, TRUE, 0); - } -#endif // GTK+ 2.22.0 - gtk_dialog_run (GTK_DIALOG (dialog)); - gtk_widget_destroy (dialog); - return NO; - } - return YES; -} - -- (void) updateDefaultSize { - double width = 150; - double height = 150; - if ([previewer isValid]) { - double pWidth = [previewer width]; - double pHeight = [previewer height]; - width = (width < pWidth + 4) ? pWidth + 4 : width; - height = (height < pHeight + 4) ? pHeight + 4 : height; - } - gtk_window_set_default_size (window, width, height); -} -@end - -// vim:ft=objc:ts=8:et:sts=4:sw=4 diff --git a/tikzit/src/gtk/PropertiesPane.h b/tikzit/src/gtk/PropertiesPane.h deleted file mode 100644 index c76efae..0000000 --- a/tikzit/src/gtk/PropertiesPane.h +++ /dev/null @@ -1,69 +0,0 @@ -/* - * Copyright 2011-2012 Alex Merry <dev@randomguy3.me.uk> - * - * 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 the Free Software Foundation; either version 2 of - * the License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see <http://www.gnu.org/licenses/>. - */ - -#import "TZFoundation.h" -#import <gtk/gtk.h> - -@class Configuration; -@class EdgePropertyDelegate; -@class EdgeStylesModel; -@class GraphPropertyDelegate; -@class NodePropertyDelegate; -@class NodeStylesModel; -@class PropertyListEditor; -@class StyleManager; -@class TikzDocument; - -@interface PropertiesPane: NSObject { - TikzDocument *document; - BOOL blockUpdates; - - PropertyListEditor *graphProps; - PropertyListEditor *nodeProps; - PropertyListEditor *edgeProps; - PropertyListEditor *edgeNodeProps; - - GraphPropertyDelegate *graphPropDelegate; - NodePropertyDelegate *nodePropDelegate; - EdgePropertyDelegate *edgePropDelegate; - - GtkWidget *layout; - - GtkWidget *currentPropsWidget; // no ref! - - GtkWidget *graphPropsWidget; - GtkWidget *nodePropsWidget; - GtkWidget *edgePropsWidget; - - GtkEntry *nodeLabelEntry; - GtkToggleButton *edgeNodeToggle; - GtkWidget *edgeNodePropsWidget; - GtkEntry *edgeNodeLabelEntry; - GtkEntry *edgeSourceAnchorEntry; - GtkEntry *edgeTargetAnchorEntry; -} - -@property (retain) TikzDocument *document; -@property (assign) BOOL visible; -@property (readonly) GtkWidget *gtkWidget; - -- (void) loadConfiguration:(Configuration*)config; -- (void) saveConfiguration:(Configuration*)config; - -@end - -// vim:ft=objc:ts=8:et:sts=4:sw=4:foldmethod=marker diff --git a/tikzit/src/gtk/PropertiesPane.m b/tikzit/src/gtk/PropertiesPane.m deleted file mode 100644 index ba43298..0000000 --- a/tikzit/src/gtk/PropertiesPane.m +++ /dev/null @@ -1,763 +0,0 @@ -/* - * Copyright 2011-2012 Alex Merry <dev@randomguy3.me.uk> - * - * 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 the Free Software Foundation; either version 2 of - * the License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see <http://www.gnu.org/licenses/>. - */ - -#import "PropertiesPane.h" - -#import "GraphElementProperty.h" -#import "PropertyListEditor.h" -#import "TikzDocument.h" - -#import "gtkhelpers.h" - -// {{{ Internal interfaces -// {{{ GTK+ helpers -static GtkWidget *createLabelledEntry (const gchar *labelText, GtkEntry **entry); -static GtkWidget *createPropsPaneWithLabelEntry (PropertyListEditor *props, GtkEntry **labelEntry); -static GtkWidget *createBoldLabel (const gchar *text); -// }}} -// {{{ GTK+ callbacks -static void node_label_changed_cb (GtkEditable *widget, PropertiesPane *pane); -static void edge_node_label_changed_cb (GtkEditable *widget, PropertiesPane *pane); -static void edge_node_toggled_cb (GtkToggleButton *widget, PropertiesPane *pane); -static void edge_source_anchor_changed_cb (GtkEditable *widget, PropertiesPane *pane); -static void edge_target_anchor_changed_cb (GtkEditable *widget, PropertiesPane *pane); -// }}} - -@interface PropertiesPane (Notifications) -- (void) nodeSelectionChanged:(NSNotification*)n; -- (void) edgeSelectionChanged:(NSNotification*)n; -- (void) graphChanged:(NSNotification*)n; -- (void) nodeLabelEdited:(NSString*)newValue; -- (void) edgeNodeLabelEdited:(NSString*)newValue; -- (void) edgeNodeToggled:(BOOL)newValue; -- (BOOL) edgeSourceAnchorEdited:(NSString*)newValue; -- (BOOL) edgeTargetAnchorEdited:(NSString*)newValue; -@end - -@interface PropertiesPane (Private) -- (void) _updatePane; -- (void) _setDisplayedWidget:(GtkWidget*)widget; -@end - -// {{{ Delegates - -@interface GraphPropertyDelegate : NSObject<PropertyChangeDelegate> { - TikzDocument *doc; -} -- (void) setDocument:(TikzDocument*)d; -@end - -@interface NodePropertyDelegate : NSObject<PropertyChangeDelegate> { - TikzDocument *doc; - Node *node; -} -- (void) setDocument:(TikzDocument*)d; -- (void) setNode:(Node*)n; -@end - -@interface EdgePropertyDelegate : NSObject<PropertyChangeDelegate> { - TikzDocument *doc; - Edge *edge; -} -- (void) setDocument:(TikzDocument*)d; -- (void) setEdge:(Edge*)e; -@end - -// }}} - -// }}} -// {{{ API - -@implementation PropertiesPane - -- (id) init { - self = [super init]; - - if (self) { - document = nil; - blockUpdates = NO; - - graphProps = [[PropertyListEditor alloc] init]; - graphPropDelegate = [[GraphPropertyDelegate alloc] init]; - [graphProps setDelegate:graphPropDelegate]; - - nodeProps = [[PropertyListEditor alloc] init]; - nodePropDelegate = [[NodePropertyDelegate alloc] init]; - [nodeProps setDelegate:nodePropDelegate]; - - edgeProps = [[PropertyListEditor alloc] init]; - edgePropDelegate = [[EdgePropertyDelegate alloc] init]; - [edgeProps setDelegate:edgePropDelegate]; - - edgeNodeProps = [[PropertyListEditor alloc] init]; - [edgeNodeProps setDelegate:edgePropDelegate]; - - layout = gtk_vbox_new (FALSE, 0); - g_object_ref_sink (layout); - gtk_widget_show (layout); - - /* - * Graph properties - */ - graphPropsWidget = gtk_vbox_new (FALSE, 6); - g_object_ref_sink (graphPropsWidget); - gtk_widget_show (graphPropsWidget); - - GtkWidget *label = createBoldLabel ("Graph properties"); - gtk_widget_show (label); - gtk_box_pack_start (GTK_BOX (graphPropsWidget), - label, - FALSE, FALSE, 0); - - gtk_widget_show ([graphProps widget]); - gtk_box_pack_start (GTK_BOX (graphPropsWidget), - [graphProps widget], - TRUE, TRUE, 0); - - gtk_box_pack_start (GTK_BOX (layout), - graphPropsWidget, - TRUE, TRUE, 0); - - - /* - * Node properties - */ - nodePropsWidget = gtk_vbox_new (FALSE, 6); - g_object_ref_sink (nodePropsWidget); - gtk_box_pack_start (GTK_BOX (layout), - nodePropsWidget, - TRUE, TRUE, 0); - - label = createBoldLabel ("Node properties"); - gtk_widget_show (label); - gtk_box_pack_start (GTK_BOX (nodePropsWidget), - label, - FALSE, FALSE, 0); - - GtkWidget *labelWidget = createLabelledEntry ("Label", &nodeLabelEntry); - gtk_widget_show (labelWidget); - gtk_box_pack_start (GTK_BOX (nodePropsWidget), - labelWidget, - FALSE, FALSE, 0); - - gtk_widget_show ([nodeProps widget]); - gtk_box_pack_start (GTK_BOX (nodePropsWidget), - [nodeProps widget], - TRUE, TRUE, 0); - - g_signal_connect (G_OBJECT (nodeLabelEntry), - "changed", - G_CALLBACK (node_label_changed_cb), - self); - - /* - * Edge properties - */ - edgePropsWidget = gtk_vbox_new (FALSE, 6); - g_object_ref_sink (edgePropsWidget); - gtk_box_pack_start (GTK_BOX (layout), - edgePropsWidget, - TRUE, TRUE, 0); - - label = createBoldLabel ("Edge properties"); - gtk_widget_show (label); - gtk_box_pack_start (GTK_BOX (edgePropsWidget), - label, - FALSE, FALSE, 0); - - gtk_widget_show ([edgeProps widget]); - gtk_box_pack_start (GTK_BOX (edgePropsWidget), - [edgeProps widget], - TRUE, TRUE, 0); - - GtkWidget *split = gtk_hseparator_new (); - gtk_widget_show (split); - gtk_box_pack_start (GTK_BOX (edgePropsWidget), - split, - FALSE, FALSE, 0); - - GtkWidget *anchorTable = gtk_table_new (2, 2, FALSE); - - label = gtk_label_new ("Source anchor:"); - gtk_table_attach_defaults (GTK_TABLE (anchorTable), label, - 0, 1, 0, 1); - edgeSourceAnchorEntry = GTK_ENTRY (gtk_entry_new ()); - g_object_ref_sink (edgeSourceAnchorEntry); - gtk_table_attach_defaults (GTK_TABLE (anchorTable), - GTK_WIDGET (edgeSourceAnchorEntry), - 1, 2, 0, 1); - g_signal_connect (G_OBJECT (edgeSourceAnchorEntry), - "changed", - G_CALLBACK (edge_source_anchor_changed_cb), - self); - - label = gtk_label_new ("Target anchor:"); - gtk_table_attach_defaults (GTK_TABLE (anchorTable), label, - 0, 1, 1, 2); - edgeTargetAnchorEntry = GTK_ENTRY (gtk_entry_new ()); - g_object_ref_sink (edgeTargetAnchorEntry); - gtk_table_attach_defaults (GTK_TABLE (anchorTable), - GTK_WIDGET (edgeTargetAnchorEntry), - 1, 2, 1, 2); - g_signal_connect (G_OBJECT (edgeTargetAnchorEntry), - "changed", - G_CALLBACK (edge_target_anchor_changed_cb), - self); - - gtk_widget_show_all (anchorTable); - gtk_box_pack_start (GTK_BOX (edgePropsWidget), - anchorTable, - FALSE, FALSE, 0); - - split = gtk_hseparator_new (); - gtk_widget_show (split); - gtk_box_pack_start (GTK_BOX (edgePropsWidget), - split, - FALSE, FALSE, 0); - - edgeNodeToggle = GTK_TOGGLE_BUTTON (gtk_check_button_new_with_label ("Child node")); - g_object_ref_sink (edgeNodeToggle); - gtk_widget_show (GTK_WIDGET (edgeNodeToggle)); - gtk_box_pack_start (GTK_BOX (edgePropsWidget), - GTK_WIDGET (edgeNodeToggle), - FALSE, FALSE, 0); - g_signal_connect (G_OBJECT (GTK_WIDGET (edgeNodeToggle)), - "toggled", - G_CALLBACK (edge_node_toggled_cb), - self); - - edgeNodePropsWidget = createPropsPaneWithLabelEntry(edgeNodeProps, &edgeNodeLabelEntry); - g_object_ref_sink (edgeNodePropsWidget); - g_object_ref_sink (edgeNodeLabelEntry); - gtk_box_pack_start (GTK_BOX (edgePropsWidget), - edgeNodePropsWidget, - TRUE, TRUE, 0); - g_signal_connect (G_OBJECT (edgeNodeLabelEntry), - "changed", - G_CALLBACK (edge_node_label_changed_cb), - self); - - /* - * Misc setup - */ - - [self _setDisplayedWidget:graphPropsWidget]; - } - - return self; -} - -- (void) dealloc { - [[NSNotificationCenter defaultCenter] removeObserver:self]; - - g_object_unref (graphPropsWidget); - g_object_unref (nodePropsWidget); - g_object_unref (edgePropsWidget); - - g_object_unref (nodeLabelEntry); - g_object_unref (edgeNodeToggle); - g_object_unref (edgeNodePropsWidget); - g_object_unref (edgeNodeLabelEntry); - g_object_unref (edgeSourceAnchorEntry); - g_object_unref (edgeTargetAnchorEntry); - - g_object_unref (layout); - - [graphProps release]; - [nodeProps release]; - [edgeProps release]; - [edgeNodeProps release]; - - [graphPropDelegate release]; - [nodePropDelegate release]; - [edgePropDelegate release]; - - [document release]; - - [super dealloc]; -} - -- (TikzDocument*) document { - return document; -} - -- (void) setDocument:(TikzDocument*)doc { - if (document != nil) { - [[NSNotificationCenter defaultCenter] removeObserver:self name:nil object:document]; - [[NSNotificationCenter defaultCenter] removeObserver:self name:nil object:[document pickSupport]]; - } - - [doc retain]; - [document release]; - document = doc; - - [graphPropDelegate setDocument:doc]; - [nodePropDelegate setDocument:doc]; - [edgePropDelegate setDocument:doc]; - - if (doc != nil) { - [[NSNotificationCenter defaultCenter] addObserver:self - selector:@selector(nodeSelectionChanged:) - name:@"NodeSelectionChanged" object:[doc pickSupport]]; - [[NSNotificationCenter defaultCenter] addObserver:self - selector:@selector(edgeSelectionChanged:) - name:@"EdgeSelectionChanged" object:[doc pickSupport]]; - [[NSNotificationCenter defaultCenter] addObserver:self - selector:@selector(graphChanged:) - name:@"TikzChanged" object:doc]; - } - - [self _updatePane]; -} - -- (BOOL) visible { - return gtk_widget_get_visible (layout); -} - -- (void) setVisible:(BOOL)visible { - gtk_widget_set_visible (layout, visible); -} - -- (GtkWidget*) gtkWidget { - return layout; -} - -- (void) loadConfiguration:(Configuration*)config { -} - -- (void) saveConfiguration:(Configuration*)config { -} - -@end -// }}} -// {{{ Notifications - -@implementation PropertiesPane (Notifications) - -- (void) nodeSelectionChanged:(NSNotification*)n { - [self _updatePane]; -} - -- (void) edgeSelectionChanged:(NSNotification*)n { - [self _updatePane]; -} - -- (void) graphChanged:(NSNotification*)n { - [self _updatePane]; -} - -- (void) nodeLabelEdited:(NSString*)newValue { - if (blockUpdates) - return; - - NSSet *sel = [[document pickSupport] selectedNodes]; - if ([sel count] != 1) { - NSLog(@"Expected single node selected; got %lu", [sel count]); - return; - } - - if ([newValue isValidTikzPropertyNameOrValue]) { - Node *node = [sel anyObject]; - [document startModifyNode:node]; - [node setLabel:newValue]; - [document endModifyNode]; - } else { - widget_set_error (GTK_WIDGET (nodeLabelEntry)); - } -} - -- (void) edgeNodeLabelEdited:(NSString*)newValue { - if (blockUpdates) - return; - - NSSet *sel = [[document pickSupport] selectedEdges]; - if ([sel count] != 1) { - NSLog(@"Expected single edge selected; got %lu", [sel count]); - return; - } - - Edge *edge = [sel anyObject]; - if (![edge hasEdgeNode]) { - NSLog(@"Expected edge with edge node"); - return; - } - - if ([newValue isValidTikzPropertyNameOrValue]) { - [document startModifyEdge:edge]; - [[edge edgeNode] setLabel:newValue]; - [document endModifyEdge]; - } else { - widget_set_error (GTK_WIDGET (edgeNodeLabelEntry)); - } -} - -- (void) edgeNodeToggled:(BOOL)newValue { - if (blockUpdates) - return; - - NSSet *sel = [[document pickSupport] selectedEdges]; - if ([sel count] != 1) { - NSLog(@"Expected single edge selected; got %lu", [sel count]); - return; - } - - Edge *edge = [sel anyObject]; - - [document startModifyEdge:edge]; - [edge setHasEdgeNode:newValue]; - [document endModifyEdge]; -} - -- (BOOL) edgeSourceAnchorEdited:(NSString*)newValue { - if (blockUpdates) - return YES; - - NSSet *sel = [[document pickSupport] selectedEdges]; - if ([sel count] != 1) { - NSLog(@"Expected single edge selected; got %lu", [sel count]); - return YES; - } - - Edge *edge = [sel anyObject]; - if ([newValue isValidAnchor]) { - [document startModifyEdge:edge]; - [edge setSourceAnchor:newValue]; - [document endModifyEdge]; - return YES; - } else { - return NO; - } -} - -- (BOOL) edgeTargetAnchorEdited:(NSString*)newValue { - if (blockUpdates) - return YES; - - NSSet *sel = [[document pickSupport] selectedEdges]; - if ([sel count] != 1) { - NSLog(@"Expected single edge selected; got %lu", [sel count]); - return YES; - } - - Edge *edge = [sel anyObject]; - if ([newValue isValidAnchor]) { - [document startModifyEdge:edge]; - [edge setTargetAnchor:newValue]; - [document endModifyEdge]; - return YES; - } else { - return NO; - } -} - -@end -// }}} -// {{{ Private - -@implementation PropertiesPane (Private) - -- (void) _setDisplayedWidget:(GtkWidget*)widget { - if (currentPropsWidget != widget) { - if (currentPropsWidget) - gtk_widget_hide (currentPropsWidget); - currentPropsWidget = widget; - if (widget) - gtk_widget_show (widget); - } -} - -- (void) _updatePane { - blockUpdates = YES; - - BOOL editGraphProps = YES; - GraphElementData *data = [[document graph] data]; - [graphProps setData:data]; - - NSSet *nodeSel = [[document pickSupport] selectedNodes]; - if ([nodeSel count] == 1) { - Node *n = [nodeSel anyObject]; - [nodePropDelegate setNode:n]; - [nodeProps setData:[n data]]; - gtk_entry_set_text (nodeLabelEntry, [[n label] UTF8String]); - widget_clear_error (GTK_WIDGET (nodeLabelEntry)); - [self _setDisplayedWidget:nodePropsWidget]; - editGraphProps = NO; - } else { - [nodePropDelegate setNode:nil]; - [nodeProps setData:nil]; - gtk_entry_set_text (nodeLabelEntry, ""); - - NSSet *edgeSel = [[document pickSupport] selectedEdges]; - if ([edgeSel count] == 1) { - Edge *e = [edgeSel anyObject]; - [edgePropDelegate setEdge:e]; - [edgeProps setData:[e data]]; - gtk_entry_set_text (edgeSourceAnchorEntry, - [[e sourceAnchor] UTF8String]); - gtk_entry_set_text (edgeTargetAnchorEntry, - [[e targetAnchor] UTF8String]); - widget_clear_error (GTK_WIDGET (edgeSourceAnchorEntry)); - widget_clear_error (GTK_WIDGET (edgeTargetAnchorEntry)); - widget_clear_error (GTK_WIDGET (edgeNodeLabelEntry)); - if ([e hasEdgeNode]) { - gtk_toggle_button_set_active (edgeNodeToggle, TRUE); - gtk_widget_show (edgeNodePropsWidget); - gtk_entry_set_text (edgeNodeLabelEntry, [[[e edgeNode] label] UTF8String]); - [edgeNodeProps setData:[[e edgeNode] data]]; - gtk_widget_set_sensitive (edgeNodePropsWidget, TRUE); - } else { - gtk_toggle_button_set_active (edgeNodeToggle, FALSE); - gtk_widget_hide (edgeNodePropsWidget); - gtk_entry_set_text (edgeNodeLabelEntry, ""); - [edgeNodeProps setData:nil]; - gtk_widget_set_sensitive (edgeNodePropsWidget, FALSE); - } - [self _setDisplayedWidget:edgePropsWidget]; - editGraphProps = NO; - } else { - [edgePropDelegate setEdge:nil]; - [edgeProps setData:nil]; - [edgeNodeProps setData:nil]; - gtk_entry_set_text (edgeNodeLabelEntry, ""); - } - } - - if (editGraphProps) { - [self _setDisplayedWidget:graphPropsWidget]; - } - - blockUpdates = NO; -} - -@end - -// }}} -// {{{ Delegates - -@implementation GraphPropertyDelegate -- (id) init { - self = [super init]; - if (self) { - doc = nil; - } - return self; -} -- (void) dealloc { - // doc is not retained - [super dealloc]; -} -- (void) setDocument:(TikzDocument*)d { - doc = d; -} -- (BOOL)startEdit { - if ([doc graph] != nil) { - [doc startChangeGraphProperties]; - return YES; - } - return NO; -} -- (void)endEdit { - [doc endChangeGraphProperties]; -} -- (void)cancelEdit { - [doc cancelChangeGraphProperties]; -} -@end - -@implementation NodePropertyDelegate -- (id) init { - self = [super init]; - if (self) { - doc = nil; - node = nil; - } - return self; -} -- (void) dealloc { - // doc,node not retained - [super dealloc]; -} -- (void) setDocument:(TikzDocument*)d { - doc = d; - node = nil; -} -- (void) setNode:(Node*)n { - node = n; -} -- (BOOL)startEdit { - if (node != nil) { - [doc startModifyNode:node]; - return YES; - } - return NO; -} -- (void)endEdit { - [doc endModifyNode]; -} -- (void)cancelEdit { - [doc cancelModifyNode]; -} -@end - -@implementation EdgePropertyDelegate -- (id) init { - self = [super init]; - if (self) { - doc = nil; - edge = nil; - } - return self; -} -- (void) dealloc { - // doc,edge not retained - [super dealloc]; -} -- (void) setDocument:(TikzDocument*)d { - doc = d; - edge = nil; -} -- (void) setEdge:(Edge*)e { - edge = e; -} -- (BOOL)startEdit { - if (edge != nil) { - [doc startModifyEdge:edge]; - return YES; - } - return NO; -} -- (void)endEdit { - [doc endModifyEdge]; -} -- (void)cancelEdit { - [doc cancelModifyEdge]; -} -@end - -// }}} -// {{{ GTK+ helpers - -static GtkWidget *createLabelledEntry (const gchar *labelText, GtkEntry **entry) { - GtkBox *box = GTK_BOX (gtk_hbox_new (FALSE, 0)); - GtkWidget *label = gtk_label_new (labelText); - gtk_widget_show (label); - GtkWidget *entryWidget = gtk_entry_new (); - gtk_widget_show (entryWidget); - // container widget expand fill pad - gtk_box_pack_start (box, label, FALSE, TRUE, 5); - gtk_box_pack_start (box, entryWidget, TRUE, TRUE, 0); - if (entry) - *entry = GTK_ENTRY (entryWidget); - return GTK_WIDGET (box); -} - -static GtkWidget *createPropsPaneWithLabelEntry (PropertyListEditor *props, GtkEntry **labelEntry) { - GtkBox *box = GTK_BOX (gtk_vbox_new (FALSE, 6)); - - GtkWidget *labelWidget = createLabelledEntry ("Label", labelEntry); - gtk_widget_show (labelWidget); - // box widget expand fill pad - gtk_box_pack_start (box, labelWidget, FALSE, FALSE, 0); - gtk_box_pack_start (box, [props widget], TRUE, TRUE, 0); - gtk_widget_show ([props widget]); - return GTK_WIDGET (box); -} - -static GtkWidget *createBoldLabel (const gchar *text) { - GtkWidget *label = gtk_label_new (text); - label_set_bold (GTK_LABEL (label)); - return label; -} - -// }}} -// {{{ GTK+ callbacks - -static void node_label_changed_cb (GtkEditable *editable, PropertiesPane *pane) { - if (!gtk_widget_is_sensitive (GTK_WIDGET (editable))) { - // clearly wasn't the user editing - return; - } - - NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init]; - - NSString *newValue = gtk_editable_get_string (editable, 0, -1); - [pane nodeLabelEdited:newValue]; - - [pool drain]; -} - -static void edge_node_label_changed_cb (GtkEditable *editable, PropertiesPane *pane) { - if (!gtk_widget_is_sensitive (GTK_WIDGET (editable))) { - // clearly wasn't the user editing - return; - } - - NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init]; - - NSString *newValue = gtk_editable_get_string (editable, 0, -1); - [pane edgeNodeLabelEdited:newValue]; - - [pool drain]; -} - -static void edge_node_toggled_cb (GtkToggleButton *toggle, PropertiesPane *pane) { - if (!gtk_widget_is_sensitive (GTK_WIDGET (toggle))) { - // clearly wasn't the user editing - return; - } - - NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init]; - - gboolean newValue = gtk_toggle_button_get_active (toggle); - [pane edgeNodeToggled:newValue]; - - [pool drain]; -} - -static void edge_source_anchor_changed_cb (GtkEditable *editable, PropertiesPane *pane) { - if (!gtk_widget_is_sensitive (GTK_WIDGET (editable))) { - // clearly wasn't the user editing - return; - } - - NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init]; - - NSString *newValue = gtk_editable_get_string (editable, 0, -1); - if (![pane edgeSourceAnchorEdited:newValue]) - widget_set_error (GTK_WIDGET (editable)); - - [pool drain]; -} - -static void edge_target_anchor_changed_cb (GtkEditable *editable, PropertiesPane *pane) { - if (!gtk_widget_is_sensitive (GTK_WIDGET (editable))) { - // clearly wasn't the user editing - return; - } - - NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init]; - - NSString *newValue = gtk_editable_get_string (editable, 0, -1); - if (![pane edgeTargetAnchorEdited:newValue]) - widget_set_error (GTK_WIDGET (editable)); - - [pool drain]; -} - -// }}} - -// vim:ft=objc:ts=8:et:sts=4:sw=4:foldmethod=marker diff --git a/tikzit/src/gtk/PropertyListEditor.h b/tikzit/src/gtk/PropertyListEditor.h deleted file mode 100644 index 2d3166a..0000000 --- a/tikzit/src/gtk/PropertyListEditor.h +++ /dev/null @@ -1,65 +0,0 @@ -/* - * Copyright 2011 Alex Merry <dev@randomguy3.me.uk> - * - * 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 the Free Software Foundation; either version 2 of - * the License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see <http://www.gnu.org/licenses/>. - */ - -#import "TZFoundation.h" -#import <gtk/gtk.h> -#import "GraphElementData.h" -#import "GraphElementProperty.h" - -@protocol PropertyChangeDelegate -@optional -- (BOOL)startEdit; -- (void)endEdit; -- (void)cancelEdit; -@end - -@interface PropertyListEditor: NSObject { - GraphElementData *data; - NSObject<PropertyChangeDelegate> *delegate; - - GtkListStore *list; - GtkWidget *view; - GtkWidget *widget; - GtkWidget *removeButton; -} - -/*! - @property widget - @brief The widget displaying the editable list - */ -@property (readonly) GtkWidget *widget; - -/*! - @property data - @brief The GraphElementData that should be reflected in the list - */ -@property (retain) GraphElementData *data; - -/*! - @property delegate - @brief A delegate for dealing with property changes - */ -@property (retain) NSObject<PropertyChangeDelegate> *delegate; - -/*! - * Reload the properties from the data store - */ -- (void) reloadProperties; - -@end - -// vim:ft=objc:ts=8:et:sts=4:sw=4 diff --git a/tikzit/src/gtk/PropertyListEditor.m b/tikzit/src/gtk/PropertyListEditor.m deleted file mode 100644 index 9760618..0000000 --- a/tikzit/src/gtk/PropertyListEditor.m +++ /dev/null @@ -1,501 +0,0 @@ -/* - * Copyright 2011 Alex Merry <dev@randomguy3.me.uk> - * - * 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 the Free Software Foundation; either version 2 of - * the License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see <http://www.gnu.org/licenses/>. - */ - -#import "PropertyListEditor.h" -#import "gtkhelpers.h" - -// {{{ Constants - -enum { - PLM_NAME_COL = 0, - PLM_VALUE_COL, - PLM_IS_PROPERTY_COL, - PLM_PROPERTY_COL, - PLM_N_COLS -}; - -// }}} -// {{{ Internal interfaces -// {{{ Signals - -static void value_edited_cb (GtkCellRendererText *renderer, - gchar *path, - gchar *new_text, - PropertyListEditor *editor); -static void name_edited_cb (GtkCellRendererText *renderer, - gchar *path, - gchar *new_text, - PropertyListEditor *editor); -static void add_prop_clicked_cb (GtkButton *button, - PropertyListEditor *editor); -static void add_atom_clicked_cb (GtkButton *button, - PropertyListEditor *editor); -static void remove_clicked_cb (GtkButton *button, - PropertyListEditor *editor); -static void text_editing_started (GtkCellRenderer *cell, - GtkCellEditable *editable, - const gchar *path, - PropertyListEditor *editor); -static void text_changed_cb (GtkEditable *editable, - PropertyListEditor *pane); -static void selection_changed_cb (GtkTreeSelection *selection, - PropertyListEditor *pane); - -// }}} -// {{{ Private - -@interface PropertyListEditor (Private) -- (void) updatePath:(gchar*)path withValue:(NSString*)newText; -- (void) updatePath:(gchar*)path withName:(NSString*)newText; -- (void) addProperty; -- (void) addAtom; -- (void) removeSelected; -- (void) selectionCountChanged:(int)newSelectionCount; -- (void) clearStore; -@end - -// }}} -// }}} -// {{{ API - -@implementation PropertyListEditor - -- (id) init { - self = [super init]; - - if (self) { - list = gtk_list_store_new (PLM_N_COLS, - G_TYPE_STRING, - G_TYPE_STRING, - G_TYPE_BOOLEAN, - G_TYPE_POINTER); - g_object_ref_sink (G_OBJECT (list)); - view = gtk_tree_view_new_with_model (GTK_TREE_MODEL (list)); - g_object_ref_sink (G_OBJECT (view)); - GtkWidget *scrolledview = gtk_scrolled_window_new (NULL, NULL); - gtk_scrolled_window_set_policy (GTK_SCROLLED_WINDOW (scrolledview), - GTK_POLICY_AUTOMATIC, - GTK_POLICY_AUTOMATIC); - gtk_container_add (GTK_CONTAINER (scrolledview), view); - gtk_widget_set_size_request (view, -1, 150); - data = nil; - delegate = nil; - - GtkCellRenderer *renderer; - GtkTreeViewColumn *column; - - renderer = gtk_cell_renderer_text_new (); - g_object_set (G_OBJECT (renderer), - "editable", TRUE, - NULL); - column = gtk_tree_view_column_new_with_attributes ("Key/Atom", - renderer, - "text", PLM_NAME_COL, - NULL); - gtk_tree_view_append_column (GTK_TREE_VIEW (view), column); - g_signal_connect (G_OBJECT (renderer), - "editing-started", - G_CALLBACK (text_editing_started), - self); - g_signal_connect (G_OBJECT (renderer), - "edited", - G_CALLBACK (name_edited_cb), - self); - - renderer = gtk_cell_renderer_text_new (); - column = gtk_tree_view_column_new_with_attributes ("Value", - renderer, - "text", PLM_VALUE_COL, - "editable", PLM_IS_PROPERTY_COL, - "sensitive", PLM_IS_PROPERTY_COL, - NULL); - gtk_tree_view_append_column (GTK_TREE_VIEW (view), column); - g_signal_connect (G_OBJECT (renderer), - "edited", - G_CALLBACK (value_edited_cb), - self); - - widget = gtk_vbox_new (FALSE, 0); - gtk_box_set_spacing (GTK_BOX (widget), 6); - g_object_ref_sink (G_OBJECT (widget)); - - GtkWidget *listFrame = gtk_frame_new (NULL); - gtk_container_add (GTK_CONTAINER (listFrame), scrolledview); - gtk_widget_show (listFrame); - gtk_container_add (GTK_CONTAINER (widget), listFrame); - - GtkBox *buttonBox = GTK_BOX (gtk_hbox_new(FALSE, 0)); - gtk_box_pack_start (GTK_BOX (widget), GTK_WIDGET (buttonBox), FALSE, FALSE, 0); - - GtkWidget *addPropButton = gtk_button_new (); - //gtk_widget_set_size_request (addPropButton, 27, 27); - gtk_widget_set_tooltip_text (addPropButton, "Add property"); - GtkWidget *addPropContents = gtk_hbox_new(FALSE, 0); - GtkWidget *addPropIcon = gtk_image_new_from_stock (GTK_STOCK_ADD, GTK_ICON_SIZE_BUTTON); - gtk_container_add (GTK_CONTAINER (addPropContents), addPropIcon); - gtk_container_add (GTK_CONTAINER (addPropContents), gtk_label_new ("P")); - gtk_container_add (GTK_CONTAINER (addPropButton), addPropContents); - gtk_box_pack_start (buttonBox, addPropButton, FALSE, FALSE, 0); - g_signal_connect (G_OBJECT (addPropButton), - "clicked", - G_CALLBACK (add_prop_clicked_cb), - self); - - GtkWidget *addAtomButton = gtk_button_new (); - //gtk_widget_set_size_request (addAtomButton, 27, 27); - gtk_widget_set_tooltip_text (addAtomButton, "Add atom"); - GtkWidget *addAtomContents = gtk_hbox_new(FALSE, 0); - GtkWidget *addAtomIcon = gtk_image_new_from_stock (GTK_STOCK_ADD, GTK_ICON_SIZE_BUTTON); - gtk_container_add (GTK_CONTAINER (addAtomContents), addAtomIcon); - gtk_container_add (GTK_CONTAINER (addAtomContents), gtk_label_new ("A")); - gtk_container_add (GTK_CONTAINER (addAtomButton), addAtomContents); - gtk_box_pack_start (buttonBox, addAtomButton, FALSE, FALSE, 0); - g_signal_connect (G_OBJECT (addAtomButton), - "clicked", - G_CALLBACK (add_atom_clicked_cb), - self); - - removeButton = gtk_button_new (); - g_object_ref_sink (G_OBJECT (removeButton)); - gtk_widget_set_sensitive (removeButton, FALSE); - //gtk_widget_set_size_request (removeButton, 27, 27); - gtk_widget_set_tooltip_text (removeButton, "Remove selected"); - GtkWidget *removeIcon = gtk_image_new_from_stock (GTK_STOCK_REMOVE, GTK_ICON_SIZE_BUTTON); - gtk_container_add (GTK_CONTAINER (removeButton), removeIcon); - gtk_box_pack_start (buttonBox, removeButton, FALSE, FALSE, 0); - g_signal_connect (G_OBJECT (removeButton), - "clicked", - G_CALLBACK (remove_clicked_cb), - self); - - GtkTreeSelection *selection = gtk_tree_view_get_selection (GTK_TREE_VIEW (view)); - g_signal_connect (G_OBJECT (selection), - "changed", - G_CALLBACK (selection_changed_cb), - self); - - gtk_widget_show_all (GTK_WIDGET (buttonBox)); - gtk_widget_show_all (scrolledview); - - gtk_widget_set_sensitive (widget, FALSE); - } - - return self; -} - -- (void) dealloc { - [self clearStore]; - - [data release]; - [delegate release]; - - g_object_unref (list); - g_object_unref (view); - g_object_unref (widget); - g_object_unref (removeButton); - - [super dealloc]; -} - -@synthesize widget, delegate; - -- (GraphElementData*) data { return data; } -- (void) setData:(GraphElementData*)d { - [d retain]; - [data release]; - data = d; - [self reloadProperties]; - gtk_widget_set_sensitive (widget, data != nil); -} - -- (void) reloadProperties { - [self clearStore]; - int pos = 0; - for (GraphElementProperty *p in data) { - GtkTreeIter iter; - [p retain]; - gtk_list_store_insert_with_values (list, &iter, pos, - PLM_NAME_COL, [[p key] UTF8String], - PLM_VALUE_COL, [[p value] UTF8String], - PLM_IS_PROPERTY_COL, ![p isAtom], - PLM_PROPERTY_COL, (void *)p, - -1); - ++pos; - } -} - -@end - -// }}} -// {{{ Private - -@implementation PropertyListEditor (Private) -- (void) updatePath:(gchar*)pathStr withValue:(NSString*)newText { - if (![newText isValidTikzPropertyNameOrValue]) - return; - - GtkTreeIter iter; - GtkTreePath *path = gtk_tree_path_new_from_string (pathStr); - - if (!gtk_tree_model_get_iter (GTK_TREE_MODEL (list), &iter, path)) { - gtk_tree_path_free (path); - return; - } - - void *propPtr; - gtk_tree_model_get (GTK_TREE_MODEL (list), &iter, - PLM_PROPERTY_COL, &propPtr, - -1); - GraphElementProperty *prop = (GraphElementProperty*)propPtr; - - if (![prop isAtom]) { - if (![delegate respondsToSelector:@selector(startEdit)] || [delegate startEdit]) { - [prop setValue:newText]; - gtk_list_store_set (list, &iter, - PLM_VALUE_COL, [newText UTF8String], - -1); - [delegate endEdit]; - } - } - - gtk_tree_path_free (path); -} - -- (void) updatePath:(gchar*)pathStr withName:(NSString*)newText { - if (![newText isValidTikzPropertyNameOrValue]) - return; - - GtkTreeIter iter; - GtkTreePath *path = gtk_tree_path_new_from_string (pathStr); - - if (!gtk_tree_model_get_iter (GTK_TREE_MODEL (list), &iter, path)) { - gtk_tree_path_free (path); - return; - } - - void *propPtr; - gtk_tree_model_get (GTK_TREE_MODEL (list), &iter, - PLM_PROPERTY_COL, &propPtr, - -1); - GraphElementProperty *prop = (GraphElementProperty*)propPtr; - - if (![delegate respondsToSelector:@selector(startEdit)] || [delegate startEdit]) { - if ([newText isEqualToString:@""]) { - [data removeObjectIdenticalTo:prop]; - gtk_list_store_remove (list, &iter); - [prop release]; - } else { - [prop setKey:newText]; - gtk_list_store_set (list, &iter, - PLM_NAME_COL, [newText UTF8String], - -1); - } - [delegate endEdit]; - } - - gtk_tree_path_free (path); -} - -- (void) addProperty { - GtkTreeIter iter; - GraphElementProperty *p = [[GraphElementProperty alloc] initWithPropertyValue:@"" forKey:@"new property"]; - if (![delegate respondsToSelector:@selector(startEdit)] || [delegate startEdit]) { - [data addObject:p]; - gint pos = [data count] - 1; - gtk_list_store_insert_with_values (list, &iter, pos, - PLM_NAME_COL, "new property", - PLM_VALUE_COL, "", - PLM_IS_PROPERTY_COL, TRUE, - PLM_PROPERTY_COL, (void *)p, - -1); - [delegate endEdit]; - } else { - [p release]; - } -} - -- (void) addAtom { - GtkTreeIter iter; - GraphElementProperty *p = [[GraphElementProperty alloc] initWithAtomName:@"new atom"]; - if (![delegate respondsToSelector:@selector(startEdit)] || [delegate startEdit]) { - [data addObject:p]; - gint pos = [data count] - 1; - gtk_list_store_insert_with_values (list, &iter, pos, - PLM_NAME_COL, "new atom", - PLM_VALUE_COL, [[p value] UTF8String], - PLM_IS_PROPERTY_COL, FALSE, - PLM_PROPERTY_COL, (void *)p, - -1); - [delegate endEdit]; - } else { - [p release]; - } -} - -- (void) removeSelected { - GtkTreeSelection *selection = gtk_tree_view_get_selection (GTK_TREE_VIEW (view)); - GList *selPaths = gtk_tree_selection_get_selected_rows (selection, NULL); - GList *selIters = NULL; - - // Convert to iters, as GtkListStore has persistent iters - GList *curr = selPaths; - while (curr != NULL) { - GtkTreeIter iter; - gtk_tree_model_get_iter (GTK_TREE_MODEL (list), - &iter, - (GtkTreePath*)curr->data); - selIters = g_list_prepend (selIters, gtk_tree_iter_copy (&iter)); - curr = g_list_next (curr); - } - - // remove all iters - curr = selIters; - while (curr != NULL) { - GtkTreeIter *iter = (GtkTreeIter*)curr->data; - void *propPtr; - gtk_tree_model_get (GTK_TREE_MODEL (list), iter, - PLM_PROPERTY_COL, &propPtr, - -1); - GraphElementProperty *prop = (GraphElementProperty*)propPtr; - if (![delegate respondsToSelector:@selector(startEdit)] || [delegate startEdit]) { - [data removeObjectIdenticalTo:prop]; - gtk_list_store_remove (list, iter); - [prop release]; - [delegate endEdit]; - } - curr = g_list_next (curr); - } - - g_list_foreach (selIters, (GFunc) gtk_tree_iter_free, NULL); - g_list_free (selIters); - g_list_foreach (selPaths, (GFunc) gtk_tree_path_free, NULL); - g_list_free (selPaths); -} - -- (void) selectionCountChanged:(int)count { - gtk_widget_set_sensitive (removeButton, count > 0); -} - -- (void) clearStore { - GtkTreeIter iter; - if (gtk_tree_model_get_iter_first (GTK_TREE_MODEL (list), &iter)) { - do { - void *prop; - gtk_tree_model_get (GTK_TREE_MODEL (list), &iter, - PLM_PROPERTY_COL, &prop, - -1); - [(id)prop release]; - } while (gtk_tree_model_iter_next (GTK_TREE_MODEL (list), &iter)); - gtk_list_store_clear (list); - } -} -@end - -// }}} -// {{{ GTK+ callbacks - -static void value_edited_cb (GtkCellRendererText *renderer, - gchar *path, - gchar *new_text, - PropertyListEditor *editor) -{ - NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init]; - [editor updatePath:path withValue:[NSString stringWithUTF8String:new_text]]; - [pool drain]; -} - -static void name_edited_cb (GtkCellRendererText *renderer, - gchar *path, - gchar *new_text, - PropertyListEditor *editor) -{ - NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init]; - [editor updatePath:path withName:[NSString stringWithUTF8String:new_text]]; - [pool drain]; -} - -static void add_prop_clicked_cb (GtkButton *button, - PropertyListEditor *editor) -{ - NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init]; - [editor addProperty]; - [pool drain]; -} - -static void add_atom_clicked_cb (GtkButton *button, - PropertyListEditor *editor) -{ - NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init]; - [editor addAtom]; - [pool drain]; -} - -static void remove_clicked_cb (GtkButton *button, - PropertyListEditor *editor) -{ - NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init]; - [editor removeSelected]; - [pool drain]; -} - -static void text_editing_started (GtkCellRenderer *cell, - GtkCellEditable *editable, - const gchar *path, - PropertyListEditor *editor) -{ - NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init]; - - if (GTK_IS_EDITABLE (editable) && GTK_IS_WIDGET (editable)) { - g_signal_handlers_disconnect_by_func (G_OBJECT (editable), - G_CALLBACK (text_changed_cb), - editor); - widget_clear_error (GTK_WIDGET (editable)); - g_signal_connect (G_OBJECT (editable), - "changed", - G_CALLBACK (text_changed_cb), - editor); - } - - [pool drain]; -} - -static void text_changed_cb (GtkEditable *editable, PropertyListEditor *pane) -{ - NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init]; - - NSString *newValue = gtk_editable_get_string (editable, 0, -1); - if (![newValue isValidTikzPropertyNameOrValue]) { - widget_set_error (GTK_WIDGET (editable)); - } else { - widget_clear_error (GTK_WIDGET (editable)); - } - - [pool drain]; -} - -static void selection_changed_cb (GtkTreeSelection *selection, - PropertyListEditor *pane) -{ - NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init]; - int selcount = gtk_tree_selection_count_selected_rows (selection); - [pane selectionCountChanged:selcount]; - [pool drain]; -} - -// }}} - -// vim:ft=objc:ts=8:et:sts=4:sw=4:foldmethod=marker diff --git a/tikzit/src/gtk/RecentManager.h b/tikzit/src/gtk/RecentManager.h deleted file mode 100644 index e2c2793..0000000 --- a/tikzit/src/gtk/RecentManager.h +++ /dev/null @@ -1,30 +0,0 @@ -/* - * Copyright 2011 Alex Merry <alex.merry@kdemail.net> - * - * 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 the Free Software Foundation; either version 2 of - * the License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see <http://www.gnu.org/licenses/>. - */ - -#import "TZFoundation.h" - -@interface RecentManager: NSObject { -} - -+ (RecentManager*) defaultManager; - -- (void)addRecentFile:(NSString*)path; -- (void)removeRecentFile:(NSString*)path; - -@end - -// vim:ft=objc:ts=8:et:sts=4:sw=4 diff --git a/tikzit/src/gtk/RecentManager.m b/tikzit/src/gtk/RecentManager.m deleted file mode 100644 index c6074c6..0000000 --- a/tikzit/src/gtk/RecentManager.m +++ /dev/null @@ -1,74 +0,0 @@ -/* - * Copyright 2011 Alex Merry <alex.merry@kdemail.net> - * - * 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 the Free Software Foundation; either version 2 of - * the License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see <http://www.gnu.org/licenses/>. - */ - -#import "RecentManager.h" -#import <gtk/gtk.h> - -static RecentManager *defMan = nil; - -@implementation RecentManager -- (id) init { - self = [super init]; - return self; -} - -+ (RecentManager*) defaultManager { - if (defMan == nil) { - defMan = [[self alloc] init]; - } - return defMan; -} - -- (void)addRecentFile:(NSString*)path { - NSError *error = nil; - gchar *uri = [path glibUriWithError:&error]; - if (error) { - logError (error, @"Could not add recent file"); - return; - } - - GtkRecentData recent_data; - recent_data.display_name = NULL; - recent_data.description = NULL; - recent_data.mime_type = "text/x-tikz"; - recent_data.app_name = (gchar *) g_get_application_name (); - recent_data.app_exec = g_strjoin (" ", g_get_prgname (), "%u", NULL); - recent_data.groups = NULL; - recent_data.is_private = FALSE; - - gtk_recent_manager_add_full (gtk_recent_manager_get_default(), uri, &recent_data); - - g_free (uri); - g_free (recent_data.app_exec); -} - -- (void)removeRecentFile:(NSString*)path { - NSError *error = nil; - gchar *uri = [path glibUriWithError:&error]; - if (error) { - logError (error, @"Could not remove recent file"); - return; - } - - gtk_recent_manager_remove_item (gtk_recent_manager_get_default(), uri, NULL); - - g_free (uri); -} - -@end - -// vim:ft=objc:ts=8:et:sts=4:sw=4 diff --git a/tikzit/src/gtk/SelectTool.h b/tikzit/src/gtk/SelectTool.h deleted file mode 100644 index 65f511a..0000000 --- a/tikzit/src/gtk/SelectTool.h +++ /dev/null @@ -1,63 +0,0 @@ -/* - * Copyright 2012 Alex Merry <alex.merry@kdemail.net> - * - * 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 the Free Software Foundation; either version 2 of - * the License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see <http://www.gnu.org/licenses/>. - */ - -#import "TZFoundation.h" -#import "Tool.h" - -@class Edge; -@class Node; - -// FIXME: replace this with delegates -typedef enum { - QuietState, - SelectBoxState, - ToggleSelectState, - MoveSelectedNodesState, - DragEdgeControlPoint1, - DragEdgeControlPoint2 -} SelectToolState; - -typedef enum { - DragSelectsNodes = 1, - DragSelectsEdges = 2, - DragSelectsBoth = DragSelectsNodes | DragSelectsEdges -} DragSelectMode; - -@interface SelectTool : NSObject <Tool> { - GraphRenderer *renderer; - SelectToolState state; - float edgeFuzz; - DragSelectMode dragSelectMode; - NSPoint dragOrigin; - Node *leaderNode; - NSPoint oldLeaderPos; - Edge *modifyEdge; - NSRect selectionBox; - NSMutableSet *selectionBoxContents; - - GtkWidget *configWidget; - GSList *dragSelectModeButtons; -} - -@property (assign) float edgeFuzz; -@property (assign) DragSelectMode dragSelectMode; - -- (id) init; -+ (id) tool; -@end - -// vim:ft=objc:ts=8:et:sts=4:sw=4 diff --git a/tikzit/src/gtk/SelectTool.m b/tikzit/src/gtk/SelectTool.m deleted file mode 100644 index c821162..0000000 --- a/tikzit/src/gtk/SelectTool.m +++ /dev/null @@ -1,590 +0,0 @@ -/* - * Copyright 2012 Alex Merry <alex.merry@kdemail.net> - * - * 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 the Free Software Foundation; either version 2 of - * the License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see <http://www.gnu.org/licenses/>. - */ - -#import "SelectTool.h" - -#import "Configuration.h" -#import "Edge+Render.h" -#import "GraphRenderer.h" -#import "TikzDocument.h" -#import "tzstockitems.h" - -#import <gdk/gdkkeysyms.h> - -#define DRAG_SELECT_MODE_KEY "tikzit-drag-select-mode" - -static const InputMask unionSelectMask = ShiftMask; - -static void drag_select_mode_cb (GtkToggleButton *button, SelectTool *tool); - -@interface SelectTool (Private) -- (TikzDocument*) doc; -- (void) shiftNodesByMovingLeader:(Node*)leader to:(NSPoint)to; -- (void) deselectAllNodes; -- (void) deselectAllEdges; -- (void) deselectAll; -- (BOOL) circleWithCenter:(NSPoint)c andRadius:(float)r containsPoint:(NSPoint)p; -- (void) lookForControlPointAt:(NSPoint)pos; -- (void) setSelectionBox:(NSRect)box; -- (void) clearSelectionBox; -- (BOOL) selectionBoxContainsNode:(Node*)node; -@end - -@implementation SelectTool -- (NSString*) name { return @"Select"; } -- (const gchar*) stockId { return TIKZIT_STOCK_SELECT; } -- (NSString*) helpText { return @"Select, move and edit nodes and edges"; } -- (NSString*) shortcut { return @"s"; } -@synthesize configurationWidget=configWidget; -@synthesize edgeFuzz; - -+ (id) tool { - return [[[self alloc] init] autorelease]; -} - -- (id) init { - self = [super init]; - - if (self) { - state = QuietState; - edgeFuzz = 3.0f; - dragSelectMode = DragSelectsNodes; - - configWidget = gtk_vbox_new (FALSE, 0); - g_object_ref_sink (configWidget); - - GtkWidget *label = gtk_label_new ("Drag selects:"); - gtk_misc_set_alignment (GTK_MISC (label), 0.0, 0.5); - gtk_box_pack_start (GTK_BOX (configWidget), - label, - FALSE, - FALSE, - 0); - - GtkWidget *nodeOpt = gtk_radio_button_new_with_label (NULL, "nodes (N)"); - g_object_set_data (G_OBJECT (nodeOpt), - DRAG_SELECT_MODE_KEY, - (gpointer)DragSelectsNodes); - gtk_box_pack_start (GTK_BOX (configWidget), - nodeOpt, - FALSE, - FALSE, - 0); - g_signal_connect (G_OBJECT (nodeOpt), - "toggled", - G_CALLBACK (drag_select_mode_cb), - self); - - GtkWidget *edgeOpt = gtk_radio_button_new_with_label ( - gtk_radio_button_get_group (GTK_RADIO_BUTTON (nodeOpt)), - "edges (E)"); - g_object_set_data (G_OBJECT (edgeOpt), - DRAG_SELECT_MODE_KEY, - (gpointer)DragSelectsEdges); - gtk_box_pack_start (GTK_BOX (configWidget), - edgeOpt, - FALSE, - FALSE, - 0); - g_signal_connect (G_OBJECT (edgeOpt), - "toggled", - G_CALLBACK (drag_select_mode_cb), - self); - - GtkWidget *bothOpt = gtk_radio_button_new_with_label ( - gtk_radio_button_get_group (GTK_RADIO_BUTTON (edgeOpt)), - "both (B)"); - g_object_set_data (G_OBJECT (bothOpt), - DRAG_SELECT_MODE_KEY, - (gpointer)DragSelectsBoth); - gtk_box_pack_start (GTK_BOX (configWidget), - bothOpt, - FALSE, - FALSE, - 0); - g_signal_connect (G_OBJECT (bothOpt), - "toggled", - G_CALLBACK (drag_select_mode_cb), - self); - dragSelectModeButtons = gtk_radio_button_get_group (GTK_RADIO_BUTTON (bothOpt)); - - gtk_widget_show_all (configWidget); - } - - return self; -} - -- (void) dealloc { - [[NSNotificationCenter defaultCenter] removeObserver:self]; - - [renderer release]; - [leaderNode release]; - [modifyEdge release]; - - g_object_unref (G_OBJECT (configWidget)); - - [super dealloc]; -} - -- (DragSelectMode) dragSelectMode { - return dragSelectMode; -} - -- (void) setDragSelectMode:(DragSelectMode)mode { - if (dragSelectMode == mode) - return; - - dragSelectMode = mode; - - GSList *entry = dragSelectModeButtons; - while (entry) { - GtkToggleButton *button = GTK_TOGGLE_BUTTON (entry->data); - DragSelectMode buttonMode = - (DragSelectMode) g_object_get_data ( - G_OBJECT (button), - DRAG_SELECT_MODE_KEY); - if (buttonMode == dragSelectMode) { - gtk_toggle_button_set_active (button, TRUE); - break; - } - - entry = g_slist_next (entry); - } -} - -- (GraphRenderer*) activeRenderer { return renderer; } -- (void) setActiveRenderer:(GraphRenderer*)r { - if (r == renderer) - return; - - [r retain]; - [renderer release]; - renderer = r; - - state = QuietState; -} - -- (void) mousePressAt:(NSPoint)pos withButton:(MouseButton)button andMask:(InputMask)mask { - if (button != LeftButton) - return; - - dragOrigin = pos; - - // we should already be in a quiet state, but no harm in making sure - state = QuietState; - - modifyEdge = nil; - [self lookForControlPointAt:pos]; - - if (modifyEdge == nil) { - // we didn't find a control point - - BOOL unionSelect = (mask & unionSelectMask); - - leaderNode = [renderer anyNodeAt:pos]; - // if we hit a node, deselect other nodes (if Shift is up) and go to move mode - if (leaderNode != nil) { - BOOL alreadySelected = [[self doc] isNodeSelected:leaderNode]; - if (!unionSelect && !alreadySelected) { - [self deselectAll]; - } - if (unionSelect && alreadySelected) { - state = ToggleSelectState; - } else { - [[[self doc] pickSupport] selectNode:leaderNode]; - state = MoveSelectedNodesState; - oldLeaderPos = [leaderNode point]; - [[self doc] startShiftNodes:[[[self doc] pickSupport] selectedNodes]]; - } - } - - // if mouse did not hit a node, check if mouse hit an edge - if (leaderNode == nil) { - Edge *edge = [renderer anyEdgeAt:pos withFuzz:edgeFuzz]; - if (edge != nil) { - BOOL alreadySelected = [[self doc] isEdgeSelected:edge]; - if (!unionSelect) { - [self deselectAll]; - } - if (unionSelect && alreadySelected) { - [[[self doc] pickSupport] deselectEdge:edge]; - } else { - [[[self doc] pickSupport] selectEdge:edge]; - } - } else { - // if mouse did not hit anything, put us in box mode - if (!unionSelect) { - [self deselectAll]; - } - [renderer clearHighlightedNodes]; - state = SelectBoxState; - } - } - } -} - -- (void) mouseMoveTo:(NSPoint)pos withButtons:(MouseButton)buttons andMask:(InputMask)mask { - if (!(buttons & LeftButton)) - return; - - Transformer *transformer = [renderer transformer]; - - if (state == ToggleSelectState) { - state = MoveSelectedNodesState; - oldLeaderPos = [leaderNode point]; - [[self doc] startShiftNodes:[[[self doc] pickSupport] selectedNodes]]; - } - - if (state == SelectBoxState) { - [self setSelectionBox:NSRectAroundPoints(dragOrigin, pos)]; - - NSEnumerator *enumerator = [[self doc] nodeEnumerator]; - Node *node; - while ((node = [enumerator nextObject]) != nil) { - NSPoint nodePos = [transformer toScreen:[node point]]; - if (NSPointInRect(nodePos, selectionBox)) { - [renderer setNode:node highlighted:YES]; - } else { - [renderer setNode:node highlighted:NO]; - } - } - } else if (state == MoveSelectedNodesState) { - if (leaderNode != nil) { - [self shiftNodesByMovingLeader:leaderNode to:pos]; - NSPoint shiftSoFar; - shiftSoFar.x = [leaderNode point].x - oldLeaderPos.x; - shiftSoFar.y = [leaderNode point].y - oldLeaderPos.y; - [[self doc] shiftNodesUpdate:shiftSoFar]; - } - } else if (state == DragEdgeControlPoint1 || state == DragEdgeControlPoint2) { - // invalidate once before we start changing it: we may be shrinking - // the control circles - [[self doc] modifyEdgeCheckPoint]; - if (state == DragEdgeControlPoint1) { - [modifyEdge moveCp1To:[transformer fromScreen:pos] - withWeightCourseness:0.1f - andBendCourseness:15 - forceLinkControlPoints:(mask & ControlMask)]; - } else { - [modifyEdge moveCp2To:[transformer fromScreen:pos] - withWeightCourseness:0.1f - andBendCourseness:15 - forceLinkControlPoints:(mask & ControlMask)]; - } - [[self doc] modifyEdgeCheckPoint]; - } -} - -- (void) mouseReleaseAt:(NSPoint)pos withButton:(MouseButton)button andMask:(InputMask)mask { - if (button != LeftButton) - return; - - if (state == SelectBoxState) { - PickSupport *ps = [[self doc] pickSupport]; - Transformer *transformer = [renderer transformer]; - - if (!(mask & unionSelectMask)) { - [ps deselectAllNodes]; - [ps deselectAllEdges]; - } - - Graph *graph = [[self doc] graph]; - if (dragSelectMode & DragSelectsNodes) { - for (Node *node in [graph nodes]) { - NSPoint nodePos = [transformer toScreen:[node point]]; - if (NSPointInRect(nodePos, selectionBox)) { - [ps selectNode:node]; - } - } - } - if (dragSelectMode & DragSelectsEdges) { - for (Edge *edge in [graph edges]) { - NSPoint edgePos = [transformer toScreen:[edge mid]]; - if (NSPointInRect(edgePos, selectionBox)) { - [ps selectEdge:edge]; - } - } - } - - [self clearSelectionBox]; - } else if (state == ToggleSelectState) { - [[[self doc] pickSupport] deselectNode:leaderNode]; - leaderNode = nil; - } else if (state == MoveSelectedNodesState) { - if (NSEqualPoints (oldLeaderPos, [leaderNode point])) { - [[self doc] cancelShiftNodes]; - } else { - [[self doc] endShiftNodes]; - } - leaderNode = nil; - } else if (state == DragEdgeControlPoint1 || state == DragEdgeControlPoint2) { - // FIXME: check if there was any real change - [[self doc] endModifyEdge]; - } -} - -- (void) mouseDoubleClickAt:(NSPoint)pos withButton:(MouseButton)button andMask:(InputMask)mask { - if (button != LeftButton) - return; - - if (state != QuietState) { - return; - } - // convert bend mode on edge under mouse cursor - Edge *edge = [renderer anyEdgeAt:pos withFuzz:edgeFuzz]; - if (edge != nil) { - [[self doc] startModifyEdge:edge]; - if ([edge bendMode]==EdgeBendModeBasic) { - [edge convertBendToAngles]; - [edge setBendMode:EdgeBendModeInOut]; - } else { - [edge setBendMode:EdgeBendModeBasic]; - } - [[self doc] endModifyEdge]; - - [self deselectAllEdges]; - [[[self doc] pickSupport] selectEdge:edge]; - } -} - -- (void) keyPressed:(unsigned int)keyVal withMask:(InputMask)mask { - if (keyVal == GDK_KEY_N && mask == ShiftMask) { - [self setDragSelectMode:DragSelectsNodes]; - } else if (keyVal == GDK_KEY_E && mask == ShiftMask) { - [self setDragSelectMode:DragSelectsEdges]; - } else if (keyVal == GDK_KEY_B && mask == ShiftMask) { - [self setDragSelectMode:DragSelectsBoth]; - } else if (keyVal == GDK_KEY_D && (!mask || mask == ShiftMask)) { - PickSupport *ps = [[self doc] pickSupport]; - for (Node* node in [ps selectedNodes]) { - NSRect b = [node boundingRect]; - NSLog(@"%@ @ (%f,%f) {style=%@, label=%@, data=%@, bounds=(%f,%f),(%fx%f)}", - [node name], - [node point].x, - [node point].y, - [[node style] name], - [node label], - [[node data] tikzList], - b.origin.x, b.origin.y, b.size.width, b.size.height); - } - for (Edge* edge in [ps selectedEdges]) { - NSRect b = [edge boundingRect]; - NSLog(@"%@:%@->%@:%@ {\n" - @" style=%@, data=%@,\n" - @" bend=%d, weight=%f, inAngle=%d, outAngle=%d, bendMode=%d,\n" - @" head=(%f,%f), headTan=(%f,%f) leftHeadNormal=(%f,%f), rightHeadNormal=(%f,%f),\n" - @" cp1=(%f,%f),\n" - @" mid=(%f,%f), midTan=(%f,%f), leftNormal=(%f,%f), rightNormal=(%f,%f)\n" - @" cp2=(%f,%f),\n" - @" tail=(%f,%f), tailTan=(%f,%f), leftTailNormal=(%f,%f), rightTailNormal=(%f,%f),\n" - @" isSelfLoop=%s, isStraight=%s,\n" - @" bounds=(%f,%f),(%fx%f)\n" - @"}", - [[edge source] name], - [edge sourceAnchor], - [[edge target] name], - [edge targetAnchor], - [[edge style] name], - [[edge data] tikzList], - [edge bend], - [edge weight], - [edge inAngle], - [edge outAngle], - [edge bendMode], - [edge head].x, - [edge head].y, - [edge headTan].x, - [edge headTan].y, - [edge leftHeadNormal].x, - [edge leftHeadNormal].y, - [edge rightHeadNormal].x, - [edge rightHeadNormal].y, - [edge cp1].x, - [edge cp1].y, - [edge mid].x, - [edge mid].y, - [edge midTan].x, - [edge midTan].y, - [edge leftNormal].x, - [edge leftNormal].y, - [edge rightNormal].x, - [edge rightNormal].y, - [edge cp2].x, - [edge cp2].y, - [edge tail].x, - [edge tail].y, - [edge tailTan].x, - [edge tailTan].y, - [edge leftTailNormal].x, - [edge leftTailNormal].y, - [edge rightTailNormal].x, - [edge rightTailNormal].y, - [edge isSelfLoop] ? "yes" : "no", - [edge isStraight] ? "yes" : "no", - b.origin.x, b.origin.y, b.size.width, b.size.height); - } - } -} - -- (void) renderWithContext:(id<RenderContext>)context onSurface:(id<Surface>)surface { - if (!NSIsEmptyRect (selectionBox)) { - [context saveState]; - - [context setAntialiasMode:AntialiasDisabled]; - [context setLineWidth:1.0]; - [context startPath]; - [context rect:selectionBox]; - RColor fColor = MakeRColor (0.8, 0.8, 0.8, 0.2); - RColor sColor = MakeSolidRColor (0.6, 0.6, 0.6); - [context strokePathWithColor:sColor andFillWithColor:fColor]; - - [context restoreState]; - } -} - -- (void) loadConfiguration:(Configuration*)config { - NSString *mode = [config stringEntry:@"Drag select mode" - inGroup:@"SelectTool"]; - if ([mode isEqualToString:@"nodes"]) { - [self setDragSelectMode:DragSelectsNodes]; - } else if ([mode isEqualToString:@"edges"]) { - [self setDragSelectMode:DragSelectsEdges]; - } else if ([mode isEqualToString:@"both"]) { - [self setDragSelectMode:DragSelectsBoth]; - } -} - -- (void) saveConfiguration:(Configuration*)config { - switch (dragSelectMode) { - case DragSelectsNodes: - [config setStringEntry:@"Drag select mode" - inGroup:@"SelectTool" - value:@"nodes"]; - break; - case DragSelectsEdges: - [config setStringEntry:@"Drag select mode" - inGroup:@"SelectTool" - value:@"edges"]; - break; - case DragSelectsBoth: - [config setStringEntry:@"Drag select mode" - inGroup:@"SelectTool" - value:@"both"]; - break; - } -} - -@end - -@implementation SelectTool (Private) -- (TikzDocument*) doc { - return [renderer document]; -} - -- (void) shiftNodesByMovingLeader:(Node*)leader to:(NSPoint)to { - Transformer *transformer = [renderer transformer]; - - NSPoint from = [transformer toScreen:[leader point]]; - //to = [[renderer grid] snapScreenPoint:to]; - float dx = to.x - from.x; - float dy = to.y - from.y; - - for (Node *node in [[[self doc] pickSupport] selectedNodes]) { - NSPoint p = [transformer toScreen:[node point]]; - p.x += dx; - p.y += dy; - p = [[renderer grid] snapScreenPoint:p]; - [node setPoint:[transformer fromScreen:p]]; - } -} - -- (void) deselectAllNodes { - [[[self doc] pickSupport] deselectAllNodes]; -} - -- (void) deselectAllEdges { - [[[self doc] pickSupport] deselectAllEdges]; -} - -- (void) deselectAll { - [[[self doc] pickSupport] deselectAllNodes]; - [[[self doc] pickSupport] deselectAllEdges]; -} - -- (BOOL) circleWithCenter:(NSPoint)c andRadius:(float)r containsPoint:(NSPoint)p { - return (NSDistanceBetweenPoints(c, p) <= r); -} - -- (void) lookForControlPointAt:(NSPoint)pos { - const float cpr = [Edge controlPointRadius]; - for (Edge *e in [[[self doc] pickSupport] selectedEdges]) { - NSPoint cp1 = [[renderer transformer] toScreen:[e cp1]]; - if ([self circleWithCenter:cp1 andRadius:cpr containsPoint:pos]) { - state = DragEdgeControlPoint1; - modifyEdge = e; - [[self doc] startModifyEdge:e]; - return; - } - NSPoint cp2 = [[renderer transformer] toScreen:[e cp2]]; - if ([self circleWithCenter:cp2 andRadius:cpr containsPoint:pos]) { - state = DragEdgeControlPoint2; - modifyEdge = e; - [[self doc] startModifyEdge:e]; - return; - } - } -} - -- (void) setSelectionBox:(NSRect)box { - NSRect invRect = NSUnionRect (selectionBox, box); - selectionBox = box; - [renderer invalidateRect:NSInsetRect (invRect, -2, -2)]; -} - -- (void) clearSelectionBox { - NSRect oldRect = selectionBox; - - NSRect emptyRect; - selectionBox = emptyRect; - - [renderer invalidateRect:NSInsetRect (oldRect, -2, -2)]; - [renderer clearHighlightedNodes]; -} - -- (BOOL) selectionBoxContainsNode:(Node*)node { - if (!NSIsEmptyRect (selectionBox)) - return NO; - - Transformer *transf = [[renderer surface] transformer]; - NSPoint screenPt = [transf toScreen:[node point]]; - return NSPointInRect(screenPt, selectionBox); -} -@end - -static void drag_select_mode_cb (GtkToggleButton *button, SelectTool *tool) { - if (gtk_toggle_button_get_active (button)) { - NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init]; - DragSelectMode buttonMode = - (DragSelectMode) g_object_get_data ( - G_OBJECT (button), - DRAG_SELECT_MODE_KEY); - [tool setDragSelectMode:buttonMode]; - [pool drain]; - } -} - -// vim:ft=objc:ts=8:et:sts=4:sw=4 diff --git a/tikzit/src/gtk/SelectionPane.h b/tikzit/src/gtk/SelectionPane.h deleted file mode 100644 index 57a766a..0000000 --- a/tikzit/src/gtk/SelectionPane.h +++ /dev/null @@ -1,56 +0,0 @@ -/* - * Copyright 2011-2012 Alex Merry <dev@randomguy3.me.uk> - * - * 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 the Free Software Foundation; either version 2 of - * the License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see <http://www.gnu.org/licenses/>. - */ - -#import "TZFoundation.h" -#import <gtk/gtk.h> - -@class Configuration; -@class EdgeStylesModel; -@class NodeStylesModel; -@class StyleManager; -@class TikzDocument; - -@interface SelectionPane: NSObject { - TikzDocument *document; - - NodeStylesModel *nodeStylesModel; - EdgeStylesModel *edgeStylesModel; - - GtkWidget *layout; - - GtkWidget *nodeStyleCombo; - GtkWidget *applyNodeStyleButton; - GtkWidget *clearNodeStyleButton; - GtkWidget *edgeStyleCombo; - GtkWidget *applyEdgeStyleButton; - GtkWidget *clearEdgeStyleButton; -} - -@property (retain) TikzDocument *document; -@property (assign) BOOL visible; -@property (readonly) GtkWidget *gtkWidget; - -- (id) initWithStyleManager:(StyleManager*)mgr; -- (id) initWithNodeStylesModel:(NodeStylesModel*)nsm - andEdgeStylesModel:(EdgeStylesModel*)esm; - -- (void) loadConfiguration:(Configuration*)config; -- (void) saveConfiguration:(Configuration*)config; - -@end - -// vim:ft=objc:ts=8:et:sts=4:sw=4:foldmethod=marker diff --git a/tikzit/src/gtk/SelectionPane.m b/tikzit/src/gtk/SelectionPane.m deleted file mode 100644 index 2931258..0000000 --- a/tikzit/src/gtk/SelectionPane.m +++ /dev/null @@ -1,432 +0,0 @@ -/* - * Copyright 2011-2012 Alex Merry <dev@randomguy3.me.uk> - * - * 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 the Free Software Foundation; either version 2 of - * the License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see <http://www.gnu.org/licenses/>. - */ - -#import "SelectionPane.h" - -#import "Configuration.h" -#import "EdgeStylesModel.h" -#import "NodeStylesModel.h" -#import "TikzDocument.h" - -#import "gtkhelpers.h" - -// {{{ Internal interfaces - -static void node_style_changed_cb (GtkComboBox *widget, SelectionPane *pane); -static void apply_node_style_button_cb (GtkButton *widget, SelectionPane *pane); -static void clear_node_style_button_cb (GtkButton *widget, SelectionPane *pane); -static void edge_style_changed_cb (GtkComboBox *widget, SelectionPane *pane); -static void apply_edge_style_button_cb (GtkButton *widget, SelectionPane *pane); -static void clear_edge_style_button_cb (GtkButton *widget, SelectionPane *pane); - -static void setup_style_cell_layout (GtkCellLayout *cell_layout, gint pixbuf_col, gint name_col); - -@interface SelectionPane (Notifications) -- (void) nodeSelectionChanged:(NSNotification*)n; -- (void) edgeSelectionChanged:(NSNotification*)n; -@end - -@interface SelectionPane (Private) -- (void) _updateNodeStyleButtons; -- (void) _updateEdgeStyleButtons; -- (NodeStyle*) _selectedNodeStyle; -- (EdgeStyle*) _selectedEdgeStyle; -- (void) _applyNodeStyle; -- (void) _clearNodeStyle; -- (void) _applyEdgeStyle; -- (void) _clearEdgeStyle; -@end - -// }}} -// {{{ API - -@implementation SelectionPane - -- (id) init { - [self release]; - return nil; -} - -- (id) initWithStyleManager:(StyleManager*)sm { - return [self initWithNodeStylesModel:[NodeStylesModel modelWithStyleManager:sm] - andEdgeStylesModel:[EdgeStylesModel modelWithStyleManager:sm]]; -} - -- (id) initWithNodeStylesModel:(NodeStylesModel*)nsm - andEdgeStylesModel:(EdgeStylesModel*)esm { - self = [super init]; - - if (self) { - nodeStylesModel = [nsm retain]; - edgeStylesModel = [esm retain]; - - layout = gtk_vbox_new (FALSE, 0); - g_object_ref_sink (layout); - gtk_widget_show (layout); - - GtkWidget *label = gtk_label_new ("Selection"); - label_set_bold (GTK_LABEL (label)); - gtk_widget_show (label); - gtk_box_pack_start (GTK_BOX (layout), label, - FALSE, FALSE, 0); - - GtkWidget *lvl1_box = gtk_vbox_new (FALSE, 0); - gtk_box_pack_start (GTK_BOX (layout), lvl1_box, - FALSE, FALSE, 3); - - nodeStyleCombo = gtk_combo_box_new_with_model ([nodeStylesModel model]); - g_object_ref_sink (nodeStyleCombo); - setup_style_cell_layout (GTK_CELL_LAYOUT (nodeStyleCombo), - NODE_STYLES_ICON_COL, - NODE_STYLES_NAME_COL); - g_signal_connect (G_OBJECT (nodeStyleCombo), - "changed", - G_CALLBACK (node_style_changed_cb), - self); - gtk_box_pack_start (GTK_BOX (lvl1_box), nodeStyleCombo, - FALSE, FALSE, 0); - - GtkWidget *lvl2_box = gtk_hbox_new (FALSE, 0); - gtk_box_pack_start (GTK_BOX (lvl1_box), lvl2_box, - FALSE, FALSE, 0); - - applyNodeStyleButton = gtk_button_new_with_label ("Apply"); - g_object_ref_sink (applyNodeStyleButton); - gtk_widget_set_tooltip_text (applyNodeStyleButton, "Apply style to selected nodes"); - gtk_widget_set_sensitive (applyNodeStyleButton, FALSE); - g_signal_connect (G_OBJECT (applyNodeStyleButton), - "clicked", - G_CALLBACK (apply_node_style_button_cb), - self); - gtk_box_pack_start (GTK_BOX (lvl2_box), applyNodeStyleButton, - FALSE, FALSE, 0); - - clearNodeStyleButton = gtk_button_new_with_label ("Clear"); - g_object_ref_sink (clearNodeStyleButton); - gtk_widget_set_tooltip_text (clearNodeStyleButton, "Clear style from selected nodes"); - gtk_widget_set_sensitive (clearNodeStyleButton, FALSE); - g_signal_connect (G_OBJECT (clearNodeStyleButton), - "clicked", - G_CALLBACK (clear_node_style_button_cb), - self); - gtk_box_pack_start (GTK_BOX (lvl2_box), clearNodeStyleButton, - FALSE, FALSE, 0); - - lvl1_box = gtk_vbox_new (FALSE, 0); - gtk_box_pack_start (GTK_BOX (layout), lvl1_box, - FALSE, FALSE, 3); - - edgeStyleCombo = gtk_combo_box_new_with_model ([edgeStylesModel model]); - g_object_ref_sink (edgeStyleCombo); - setup_style_cell_layout (GTK_CELL_LAYOUT (edgeStyleCombo), - EDGE_STYLES_ICON_COL, - EDGE_STYLES_NAME_COL); - g_signal_connect (G_OBJECT (edgeStyleCombo), - "changed", - G_CALLBACK (edge_style_changed_cb), - self); - gtk_box_pack_start (GTK_BOX (lvl1_box), edgeStyleCombo, - FALSE, FALSE, 0); - - lvl2_box = gtk_hbox_new (FALSE, 0); - gtk_box_pack_start (GTK_BOX (lvl1_box), lvl2_box, - FALSE, FALSE, 0); - - applyEdgeStyleButton = gtk_button_new_with_label ("Apply"); - g_object_ref_sink (applyEdgeStyleButton); - gtk_widget_set_tooltip_text (applyEdgeStyleButton, "Apply style to selected edges"); - gtk_widget_set_sensitive (applyEdgeStyleButton, FALSE); - g_signal_connect (G_OBJECT (applyEdgeStyleButton), - "clicked", - G_CALLBACK (apply_edge_style_button_cb), - self); - gtk_box_pack_start (GTK_BOX (lvl2_box), applyEdgeStyleButton, - FALSE, FALSE, 0); - - clearEdgeStyleButton = gtk_button_new_with_label ("Clear"); - g_object_ref_sink (clearEdgeStyleButton); - gtk_widget_set_tooltip_text (clearEdgeStyleButton, "Clear style from selected edges"); - gtk_widget_set_sensitive (clearEdgeStyleButton, FALSE); - g_signal_connect (G_OBJECT (clearEdgeStyleButton), - "clicked", - G_CALLBACK (clear_edge_style_button_cb), - self); - gtk_box_pack_start (GTK_BOX (lvl2_box), clearEdgeStyleButton, - FALSE, FALSE, 0); - - gtk_widget_show_all (layout); - } - - return self; -} - -- (void) dealloc { - [[NSNotificationCenter defaultCenter] removeObserver:self]; - - g_object_unref (nodeStyleCombo); - g_object_unref (applyNodeStyleButton); - g_object_unref (clearNodeStyleButton); - g_object_unref (edgeStyleCombo); - g_object_unref (applyEdgeStyleButton); - g_object_unref (clearEdgeStyleButton); - - g_object_unref (layout); - - [nodeStylesModel release]; - [edgeStylesModel release]; - - [document release]; - - [super dealloc]; -} - -- (TikzDocument*) document { - return document; -} - -- (void) setDocument:(TikzDocument*)doc { - if (document != nil) { - [[NSNotificationCenter defaultCenter] - removeObserver:self - name:nil - object:[document pickSupport]]; - } - - [doc retain]; - [document release]; - document = doc; - - if (doc != nil) { - [[NSNotificationCenter defaultCenter] addObserver:self - selector:@selector(nodeSelectionChanged:) - name:@"NodeSelectionChanged" object:[doc pickSupport]]; - [[NSNotificationCenter defaultCenter] addObserver:self - selector:@selector(edgeSelectionChanged:) - name:@"EdgeSelectionChanged" object:[doc pickSupport]]; - } - - [self _updateNodeStyleButtons]; - [self _updateEdgeStyleButtons]; -} - -- (BOOL) visible { - return gtk_widget_get_visible (layout); -} - -- (void) setVisible:(BOOL)visible { - gtk_widget_set_visible (layout, visible); -} - -- (GtkWidget*) gtkWidget { - return layout; -} - -- (void) loadConfiguration:(Configuration*)config { - NSString *nodeStyleName = [config stringEntry:@"SelectedNodeStyle" - inGroup:@"SelectionPane" - withDefault:nil]; - NodeStyle *nodeStyle = [[nodeStylesModel styleManager] nodeStyleForName:nodeStyleName]; - if (nodeStyle == nil) { - gtk_combo_box_set_active (GTK_COMBO_BOX (nodeStyleCombo), -1); - } else { - GtkTreeIter *iter = [nodeStylesModel iterFromStyle:nodeStyle]; - if (iter) { - gtk_combo_box_set_active_iter (GTK_COMBO_BOX (nodeStyleCombo), iter); - gtk_tree_iter_free (iter); - } - } - - NSString *edgeStyleName = [config stringEntry:@"SelectedEdgeStyle" - inGroup:@"SelectionPane" - withDefault:nil]; - EdgeStyle *edgeStyle = [[edgeStylesModel styleManager] edgeStyleForName:edgeStyleName]; - if (edgeStyle == nil) { - gtk_combo_box_set_active (GTK_COMBO_BOX (edgeStyleCombo), -1); - } else { - GtkTreeIter *iter = [edgeStylesModel iterFromStyle:edgeStyle]; - if (iter) { - gtk_combo_box_set_active_iter (GTK_COMBO_BOX (edgeStyleCombo), iter); - gtk_tree_iter_free (iter); - } - } -} - -- (void) saveConfiguration:(Configuration*)config { - [config setStringEntry:@"SelectedNodeStyle" - inGroup:@"SelectionPane" - value:[[self _selectedNodeStyle] name]]; - [config setStringEntry:@"SelectedEdgeStyle" - inGroup:@"SelectionPane" - value:[[self _selectedEdgeStyle] name]]; -} - -@end - -// }}} -// {{{ Notifications - -@implementation SelectionPane (Notifications) -- (void) nodeSelectionChanged:(NSNotification*)n { - [self _updateNodeStyleButtons]; -} - -- (void) edgeSelectionChanged:(NSNotification*)n { - [self _updateEdgeStyleButtons]; -} -@end - -// }}} -// {{{ Private - -@implementation SelectionPane (Private) -- (void) _updateNodeStyleButtons { - gboolean hasNodeSelection = [[[document pickSupport] selectedNodes] count] > 0; - - gtk_widget_set_sensitive (applyNodeStyleButton, - hasNodeSelection && [self _selectedNodeStyle] != nil); - gtk_widget_set_sensitive (clearNodeStyleButton, hasNodeSelection); -} - -- (void) _updateEdgeStyleButtons { - gboolean hasEdgeSelection = [[[document pickSupport] selectedEdges] count] > 0; - - gtk_widget_set_sensitive (applyEdgeStyleButton, - hasEdgeSelection && [self _selectedEdgeStyle] != nil); - gtk_widget_set_sensitive (clearEdgeStyleButton, hasEdgeSelection); -} - -- (NodeStyle*) _selectedNodeStyle { - GtkTreeIter iter; - if (gtk_combo_box_get_active_iter (GTK_COMBO_BOX (nodeStyleCombo), &iter)) { - return [nodeStylesModel styleFromIter:&iter]; - } else { - return nil; - } -} - -- (EdgeStyle*) _selectedEdgeStyle { - GtkTreeIter iter; - if (gtk_combo_box_get_active_iter (GTK_COMBO_BOX (edgeStyleCombo), &iter)) { - return [edgeStylesModel styleFromIter:&iter]; - } else { - return nil; - } -} - -- (void) _applyNodeStyle { - [document startModifyNodes:[[document pickSupport] selectedNodes]]; - - NodeStyle *style = [self _selectedNodeStyle]; - for (Node *node in [[document pickSupport] selectedNodes]) { - [node setStyle:style]; - } - - [document endModifyNodes]; -} - -- (void) _clearNodeStyle { - [document startModifyNodes:[[document pickSupport] selectedNodes]]; - - for (Node *node in [[document pickSupport] selectedNodes]) { - [node setStyle:nil]; - } - - [document endModifyNodes]; -} - -- (void) _applyEdgeStyle { - [document startModifyEdges:[[document pickSupport] selectedEdges]]; - - EdgeStyle *style = [self _selectedEdgeStyle]; - for (Edge *edge in [[document pickSupport] selectedEdges]) { - [edge setStyle:style]; - } - - [document endModifyEdges]; -} - -- (void) _clearEdgeStyle { - [document startModifyEdges:[[document pickSupport] selectedEdges]]; - - for (Edge *edge in [[document pickSupport] selectedEdges]) { - [edge setStyle:nil]; - } - - [document endModifyEdges]; -} -@end - -// }}} -// {{{ GTK+ callbacks - -static void node_style_changed_cb (GtkComboBox *widget, SelectionPane *pane) { - NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init]; - [pane _updateNodeStyleButtons]; - [pool drain]; -} - -static void apply_node_style_button_cb (GtkButton *widget, SelectionPane *pane) { - NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init]; - [pane _applyNodeStyle]; - [pool drain]; -} - -static void clear_node_style_button_cb (GtkButton *widget, SelectionPane *pane) { - NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init]; - [pane _clearNodeStyle]; - [pool drain]; -} - -static void edge_style_changed_cb (GtkComboBox *widget, SelectionPane *pane) { - NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init]; - [pane _updateEdgeStyleButtons]; - [pool drain]; -} - -static void apply_edge_style_button_cb (GtkButton *widget, SelectionPane *pane) { - NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init]; - [pane _applyEdgeStyle]; - [pool drain]; -} - -static void clear_edge_style_button_cb (GtkButton *widget, SelectionPane *pane) { - NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init]; - [pane _clearEdgeStyle]; - [pool drain]; -} - -// }}} -// -static void setup_style_cell_layout (GtkCellLayout *cell_layout, gint pixbuf_col, gint name_col) { - gtk_cell_layout_clear (cell_layout); - GtkCellRenderer *pixbuf_renderer = gtk_cell_renderer_pixbuf_new (); - gtk_cell_layout_pack_start (cell_layout, pixbuf_renderer, FALSE); - gtk_cell_layout_set_attributes ( - cell_layout, - pixbuf_renderer, - "pixbuf", pixbuf_col, - NULL); - GtkCellRenderer *text_renderer = gtk_cell_renderer_text_new (); - gtk_cell_layout_pack_start (cell_layout, text_renderer, FALSE); - gtk_cell_layout_set_attributes ( - cell_layout, - text_renderer, - "text", name_col, - NULL); -} - -// vim:ft=objc:ts=8:et:sts=4:sw=4:foldmethod=marker diff --git a/tikzit/src/gtk/SettingsDialog.h b/tikzit/src/gtk/SettingsDialog.h deleted file mode 100644 index 0f687b3..0000000 --- a/tikzit/src/gtk/SettingsDialog.h +++ /dev/null @@ -1,54 +0,0 @@ -/* - * Copyright 2012 Alex Merry <dev@randomguy3.me.uk> - * - * 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 the Free Software Foundation; either version 2 of - * the License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see <http://www.gnu.org/licenses/>. - */ - -#import "TZFoundation.h" -#import <gtk/gtk.h> - -@class Configuration; -@class EdgeStylesPalette; -@class NodeStylesPalette; -@class StyleManager; - -@interface SettingsDialog: NSObject { - Configuration *configuration; - StyleManager *styleManager; - StyleManager *tempStyleManager; - NodeStylesPalette *nodePalette; - EdgeStylesPalette *edgePalette; - - GtkWindow *parentWindow; - GtkWindow *window; - - // we don't keep any refs, as we control - // the top window - GtkEntry *pdflatexPathEntry; -} - -@property (retain) Configuration *configuration; -@property (retain) StyleManager *styleManager; -@property (assign) GtkWindow *parentWindow; -@property (assign,getter=isVisible) BOOL visible; - -- (id) initWithConfiguration:(Configuration*)c andStyleManager:(StyleManager*)m; - -- (void) present; -- (void) show; -- (void) hide; - -@end - -// vim:ft=objc:ts=8:et:sts=4:sw=4:foldmethod=marker diff --git a/tikzit/src/gtk/SettingsDialog.m b/tikzit/src/gtk/SettingsDialog.m deleted file mode 100644 index bdb5db6..0000000 --- a/tikzit/src/gtk/SettingsDialog.m +++ /dev/null @@ -1,328 +0,0 @@ -/* - * Copyright 2012 Alex Merry <dev@randomguy3.me.uk> - * - * 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 the Free Software Foundation; either version 2 of - * the License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see <http://www.gnu.org/licenses/>. - */ - -#import "SettingsDialog.h" - -#import "Application.h" -#import "Configuration.h" -#import "EdgeStylesPalette.h" -#import "NodeStylesPalette.h" -#import "StyleManager.h" - -// {{{ Internal interfaces -// {{{ Signals -static gboolean window_delete_event_cb (GtkWidget *widget, - GdkEvent *event, - SettingsDialog *dialog); -static void ok_button_clicked_cb (GtkButton *widget, SettingsDialog *dialog); -static void cancel_button_clicked_cb (GtkButton *widget, SettingsDialog *dialog); -// }}} - -@interface SettingsDialog (Private) -- (void) loadUi; -- (void) save; -- (void) revert; -@end - -// }}} -// {{{ API - -@implementation SettingsDialog - -- (id) init { - [self release]; - return nil; -} - -- (id) initWithConfiguration:(Configuration*)c andStyleManager:(StyleManager*)m { - self = [super init]; - - if (self) { - configuration = [c retain]; - styleManager = [m retain]; - tempStyleManager = [m copy]; - } - - return self; -} - -- (void) dealloc { - if (window) { - gtk_widget_destroy (GTK_WIDGET (window)); - } - if (parentWindow) { - g_object_unref (parentWindow); - } - - [configuration release]; - [tempStyleManager release]; - [styleManager release]; - [nodePalette release]; - [edgePalette release]; - - [super dealloc]; -} - -- (Configuration*) configuration { - return configuration; -} - -- (void) setConfiguration:(Configuration*)c { - [c retain]; - [configuration release]; - configuration = c; - [self revert]; -} - -- (StyleManager*) styleManager { - return styleManager; -} - -- (void) setStyleManager:(StyleManager*)m { - [m retain]; - [styleManager release]; - styleManager = m; -} - -- (GtkWindow*) parentWindow { - return parentWindow; -} - -- (void) setParentWindow:(GtkWindow*)parent { - GtkWindow *oldParent = parentWindow; - - if (parent) - g_object_ref (parent); - parentWindow = parent; - if (oldParent) - g_object_unref (oldParent); - - if (window) { - gtk_window_set_transient_for (window, parentWindow); - } -} - -- (void) present { - [self loadUi]; - [self revert]; - gtk_window_present (GTK_WINDOW (window)); -} - -- (void) show { - [self loadUi]; - [self revert]; - gtk_widget_show (GTK_WIDGET (window)); -} - -- (void) hide { - if (!window) { - return; - } - gtk_widget_hide (GTK_WIDGET (window)); -} - -- (BOOL) isVisible { - if (!window) { - return NO; - } - gboolean visible; - g_object_get (G_OBJECT (window), "visible", &visible, NULL); - return visible ? YES : NO; -} - -- (void) setVisible:(BOOL)visible { - if (visible) { - [self show]; - } else { - [self hide]; - } -} - -@end - -// }}} -// {{{ Private - -@implementation SettingsDialog (Private) -- (void) loadUi { - if (window) { - return; - } - - nodePalette = [[NodeStylesPalette alloc] initWithManager:tempStyleManager]; - edgePalette = [[EdgeStylesPalette alloc] initWithManager:tempStyleManager]; - - window = GTK_WINDOW (gtk_window_new (GTK_WINDOW_TOPLEVEL)); - gtk_window_set_default_size (window, 570, -1); - gtk_window_set_title (window, "TikZiT Configuration"); - gtk_window_set_modal (window, TRUE); - gtk_window_set_position (window, GTK_WIN_POS_CENTER_ON_PARENT); - gtk_window_set_type_hint (window, GDK_WINDOW_TYPE_HINT_DIALOG); - if (parentWindow) { - gtk_window_set_transient_for (window, parentWindow); - } - g_signal_connect (window, - "delete-event", - G_CALLBACK (window_delete_event_cb), - self); - - GtkWidget *mainBox = gtk_vbox_new (FALSE, 18); - gtk_container_set_border_width (GTK_CONTAINER (mainBox), 12); - gtk_container_add (GTK_CONTAINER (window), mainBox); - gtk_widget_show (mainBox); - -#ifdef HAVE_POPPLER - /* - * Path for pdflatex - */ - - GtkWidget *pdflatexFrame = gtk_frame_new ("Previews"); - gtk_box_pack_start (GTK_BOX (mainBox), pdflatexFrame, TRUE, TRUE, 0); - - GtkBox *pdflatexBox = GTK_BOX (gtk_hbox_new (FALSE, 6)); - gtk_container_add (GTK_CONTAINER (pdflatexFrame), GTK_WIDGET (pdflatexBox)); - gtk_container_set_border_width (GTK_CONTAINER (pdflatexBox), 6); - - GtkWidget *pdflatexLabel = gtk_label_new ("Path to pdflatex:"); - gtk_misc_set_alignment (GTK_MISC (pdflatexLabel), 0, 0.5); - gtk_box_pack_start (pdflatexBox, - pdflatexLabel, - FALSE, TRUE, 0); - - pdflatexPathEntry = GTK_ENTRY (gtk_entry_new ()); - gtk_box_pack_start (pdflatexBox, - GTK_WIDGET (pdflatexPathEntry), - TRUE, TRUE, 0); - - gtk_widget_show_all (pdflatexFrame); -#else - pdflatexPathEntry = NULL; -#endif - - /* - * Node styles - */ - GtkWidget *nodeStylesFrame = gtk_frame_new ("Node Styles"); - gtk_widget_show (nodeStylesFrame); - gtk_box_pack_start (GTK_BOX (mainBox), nodeStylesFrame, TRUE, TRUE, 0); - gtk_container_add (GTK_CONTAINER (nodeStylesFrame), - GTK_WIDGET ([nodePalette widget])); - gtk_widget_show ([nodePalette widget]); - - - /* - * Edge styles - */ - GtkWidget *edgeStylesFrame = gtk_frame_new ("Edge Styles"); - gtk_widget_show (edgeStylesFrame); - gtk_box_pack_start (GTK_BOX (mainBox), edgeStylesFrame, TRUE, TRUE, 0); - gtk_container_add (GTK_CONTAINER (edgeStylesFrame), - GTK_WIDGET ([edgePalette widget])); - gtk_widget_show ([edgePalette widget]); - - - /* - * Bottom buttons - */ - - GtkContainer *buttonBox = GTK_CONTAINER (gtk_hbutton_box_new ()); - gtk_box_set_spacing (GTK_BOX (buttonBox), 6); - gtk_button_box_set_layout (GTK_BUTTON_BOX (buttonBox), GTK_BUTTONBOX_END); - gtk_box_pack_start (GTK_BOX (mainBox), - GTK_WIDGET (buttonBox), - FALSE, TRUE, 0); - - GtkWidget *okButton = gtk_button_new_from_stock (GTK_STOCK_OK); - gtk_container_add (buttonBox, okButton); - g_signal_connect (okButton, - "clicked", - G_CALLBACK (ok_button_clicked_cb), - self); - - GtkWidget *cancelButton = gtk_button_new_from_stock (GTK_STOCK_CANCEL); - gtk_container_add (buttonBox, cancelButton); - g_signal_connect (cancelButton, - "clicked", - G_CALLBACK (cancel_button_clicked_cb), - self); - - gtk_widget_show_all (GTK_WIDGET (buttonBox)); - - [self revert]; -} - -- (void) save { - if (!window) - return; - -#ifdef HAVE_POPPLER - const gchar *path = gtk_entry_get_text (pdflatexPathEntry); - if (path && *path) { - [configuration setStringEntry:@"pdflatex" - inGroup:@"Previews" - value:[NSString stringWithUTF8String:path]]; - } -#endif - - [styleManager updateFromManager:tempStyleManager]; - - [app saveConfiguration]; -} - -- (void) revert { - if (!window) - return; - -#ifdef HAVE_POPPLER - NSString *path = [configuration stringEntry:@"pdflatex" - inGroup:@"Previews" - withDefault:@"pdflatex"]; - gtk_entry_set_text (pdflatexPathEntry, [path UTF8String]); -#endif - - [tempStyleManager updateFromManager:styleManager]; -} -@end - -// }}} -// {{{ GTK+ callbacks - -static gboolean window_delete_event_cb (GtkWidget *widget, - GdkEvent *event, - SettingsDialog *dialog) { - NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init]; - [dialog hide]; - [pool drain]; - return TRUE; // we dealt with this event -} - -static void ok_button_clicked_cb (GtkButton *widget, SettingsDialog *dialog) { - NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init]; - [dialog save]; - [dialog hide]; - [pool drain]; -} - -static void cancel_button_clicked_cb (GtkButton *widget, SettingsDialog *dialog) { - NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init]; - [dialog hide]; - [pool drain]; -} - -// }}} - -// vim:ft=objc:ts=4:et:sts=4:sw=4:foldmethod=marker diff --git a/tikzit/src/gtk/Shape+Render.h b/tikzit/src/gtk/Shape+Render.h deleted file mode 100644 index a744c77..0000000 --- a/tikzit/src/gtk/Shape+Render.h +++ /dev/null @@ -1,29 +0,0 @@ -/* - * Copyright 2011 Alex Merry <dev@randomguy3.me.uk> - * - * 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 the Free Software Foundation; either version 2 of - * the License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see <http://www.gnu.org/licenses/>. - */ - -#import "TZFoundation.h" -#import "Shape.h" -#import "RenderContext.h" -#import "Surface.h" - -@interface Shape (Render) - -- (void) drawPathWithTransform:(Transformer*)transform andContext:(id<RenderContext>)context; - -@end - -// vim:ft=objc:ts=8:et:sts=4:sw=4 diff --git a/tikzit/src/gtk/Shape+Render.m b/tikzit/src/gtk/Shape+Render.m deleted file mode 100644 index 924bb24..0000000 --- a/tikzit/src/gtk/Shape+Render.m +++ /dev/null @@ -1,57 +0,0 @@ -/* - * Copyright 2011 Alex Merry <dev@randomguy3.me.uk> - * - * 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 the Free Software Foundation; either version 2 of - * the License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see <http://www.gnu.org/licenses/>. - */ - -#import "Shape+Render.h" - -#import "Edge.h" - -// we use cairo for finding the bounding box etc. -#import <cairo/cairo.h> - -@implementation Shape (Render) - -- (void) drawPathWithTransform:(Transformer*)transform andContext:(id<RenderContext>)context { - [context startPath]; - - for (NSArray *arr in [self paths]) { - BOOL fst = YES; - NSPoint p, cp1, cp2; - - for (Edge *e in arr) { - if (fst) { - fst = NO; - p = [transform toScreen:[[e source] point]]; - [context moveTo:p]; - } - - p = [transform toScreen:[[e target] point]]; - if ([e isStraight]) { - [context lineTo:p]; - } else { - cp1 = [transform toScreen:[e cp1]]; - cp2 = [transform toScreen:[e cp2]]; - [context curveTo:p withCp1:cp1 andCp2:cp2]; - } - } - - [context closeSubPath]; - } -} - -@end - -// vim:ft=objc:ts=8:et:sts=4:sw=4 diff --git a/tikzit/src/gtk/StyleManager+Storage.h b/tikzit/src/gtk/StyleManager+Storage.h deleted file mode 100644 index 1727786..0000000 --- a/tikzit/src/gtk/StyleManager+Storage.h +++ /dev/null @@ -1,26 +0,0 @@ -/* - * Copyright 2011 Alex Merry <dev@randomguy3.me.uk> - * - * 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 the Free Software Foundation; either version 2 of - * the License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see <http://www.gnu.org/licenses/>. - */ - -#import "TZFoundation.h" -#import "StyleManager.h" - -@interface StyleManager (Storage) -- (void) loadStylesUsingConfigurationName:(NSString*)name; -- (void) saveStylesUsingConfigurationName:(NSString*)name; -@end - -// vim:ft=objc:ts=8:et:sts=4:sw=4 diff --git a/tikzit/src/gtk/StyleManager+Storage.m b/tikzit/src/gtk/StyleManager+Storage.m deleted file mode 100644 index f4c8232..0000000 --- a/tikzit/src/gtk/StyleManager+Storage.m +++ /dev/null @@ -1,82 +0,0 @@ -/* - * Copyright 2011 Alex Merry <dev@randomguy3.me.uk> - * - * 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 the Free Software Foundation; either version 2 of - * the License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see <http://www.gnu.org/licenses/>. - */ - -#import "StyleManager+Storage.h" -#import "Configuration.h" -#import "NodeStyle+Storage.h" -#import "EdgeStyle+Storage.h" - -static NSString *nodeStyleGroupPrefix = @"Style "; -static NSString *edgeStyleGroupPrefix = @"EdgeStyle "; - -@implementation StyleManager (Storage) - -- (void) loadStylesUsingConfigurationName:(NSString*)name { - if (![Configuration configurationExistsWithName:name]) { - NSLog(@"No styles config found"); - return; - } - NSError *error = nil; - Configuration *stylesConfig = [Configuration configurationWithName:name loadError:&error]; - if (error != nil) { - logError (error, @"Could not load styles configuration"); - // stick with the default config - return; - } - NSArray *groups = [stylesConfig groups]; - NSMutableArray *ns = [NSMutableArray arrayWithCapacity:[groups count]]; - NSMutableArray *es = [NSMutableArray arrayWithCapacity:[groups count]]; - - for (NSString *groupName in groups) { - if ([groupName hasPrefix:nodeStyleGroupPrefix]) { - NodeStyle *style = [[NodeStyle alloc] initFromConfigurationGroup:groupName config:stylesConfig]; - [ns addObject:style]; - } else if ([groupName hasPrefix:edgeStyleGroupPrefix]) { - EdgeStyle *style = [[EdgeStyle alloc] initFromConfigurationGroup:groupName config:stylesConfig]; - [es addObject:style]; - } - } - - [self _setNodeStyles:ns]; - [self _setEdgeStyles:es]; -} - -- (void) saveStylesUsingConfigurationName:(NSString*)name { - NSError *error = nil; - Configuration *stylesConfig = [Configuration emptyConfigurationWithName:name]; - NSArray *ns = [self nodeStyles]; - NSArray *es = [self edgeStyles]; - NSUInteger length = [ns count]; - for (int i = 0; i < length; ++i) { - NodeStyle *style = [ns objectAtIndex:i]; - NSString *groupName = [NSString stringWithFormat:@"%@%d", nodeStyleGroupPrefix, i]; - [style storeToConfigurationGroup:groupName config:stylesConfig]; - } - length = [es count]; - for (int i = 0; i < length; ++i) { - EdgeStyle *style = [es objectAtIndex:i]; - NSString *groupName = [NSString stringWithFormat:@"%@%d", edgeStyleGroupPrefix, i]; - [style storeToConfigurationGroup:groupName config:stylesConfig]; - } - if (![stylesConfig writeToStoreWithError:&error]) { - logError (error, @"Could not write styles configuration"); - } -} - -@end - -// vim:ft=objc:ts=8:et:sts=4:sw=4 diff --git a/tikzit/src/gtk/Surface.h b/tikzit/src/gtk/Surface.h deleted file mode 100644 index db4288e..0000000 --- a/tikzit/src/gtk/Surface.h +++ /dev/null @@ -1,107 +0,0 @@ -/* - * Copyright 2011 Alex Merry <dev@randomguy3.me.uk> - * - * 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 the Free Software Foundation; either version 2 of - * the License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see <http://www.gnu.org/licenses/>. - */ - -#import "TZFoundation.h" -#import "RenderContext.h" -#import "Transformer.h" - -typedef enum { - NormalCursor, - ResizeRightCursor, - ResizeBottomRightCursor, - ResizeBottomCursor, - ResizeBottomLeftCursor, - ResizeLeftCursor, - ResizeTopLeftCursor, - ResizeTopCursor, - ResizeTopRightCursor -} Cursor; - -@protocol Surface; - -@protocol RenderDelegate <NSObject> -- (void) renderWithContext:(id<RenderContext>)context onSurface:(id<Surface>)surface; -@end - -/** - * Represents a surface that can be rendered to - * - * This protocol should be implemented by drawing surfaces. It - * provides geometry information and methods to invalidate - * regions of the surface, triggering a redraw. - * - * The surface should send a "SurfaceSizeChanged" notification - * when the width or height changes. - */ -@protocol Surface <NSObject> - -/** - * The width of the surface, in surface units - * - * The surface should send a "SurfaceSizeChanged" notification - * when this property changes. - */ -@property (readonly) int width; -/** - * The height of the surface, in surface units - * - * The surface should send a "SurfaceSizeChanged" notification - * when this property changes. - */ -@property (readonly) int height; -/** - * The transformer that converts between graph units and surface units - */ -@property (readonly) Transformer *transformer; -/** - * The render delegate. - * - * This will be used to redraw (parts of) the surface when necessary. - */ -@property (assign) id<RenderDelegate> renderDelegate; - -/** - * Create a render context for the surface. - */ -- (id<RenderContext>) createRenderContext; -/** - * Invalidate a portion of the surface. - * - * This will request that part of the surface be redrawn. - */ -- (void) invalidateRect:(NSRect)rect; -/** - * Invalidate the whole surface. - * - * This will request that the whole surface be redrawn. - */ -- (void) invalidate; - -- (void) zoomIn; -- (void) zoomOut; -- (void) zoomReset; -- (void) zoomInAboutPoint:(NSPoint)p; -- (void) zoomOutAboutPoint:(NSPoint)p; -- (void) zoomResetAboutPoint:(NSPoint)p; - -- (void) setCursor:(Cursor)c; - -- (BOOL) hasFocus; -- (void) renderFocus; -@end - -// vim:ft=objc:ts=8:et:sts=4:sw=4 diff --git a/tikzit/src/gtk/TZFoundation.h b/tikzit/src/gtk/TZFoundation.h deleted file mode 100644 index f275004..0000000 --- a/tikzit/src/gtk/TZFoundation.h +++ /dev/null @@ -1,29 +0,0 @@ -/* - * Copyright 2011 Alex Merry <alex.merry@kdemail.net> - * - * 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 the Free Software Foundation; either version 2 of - * the License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see <http://www.gnu.org/licenses/>. - */ - -#import <Foundation/Foundation.h> -#import <glib.h> - -#import "NSError+Glib.h" -#import "NSError+Tikzit.h" -#import "NSFileManager+Glib.h" -#import "NSFileManager+Utils.h" -#import "NSString+Glib.h" -#import "NSString+LatexConstants.h" -#import "NSString+Tikz.h" - -// vim:ft=objc:ts=8:et:sts=4:sw=4 diff --git a/tikzit/src/gtk/TikzDocument.h b/tikzit/src/gtk/TikzDocument.h deleted file mode 100644 index 5d15d13..0000000 --- a/tikzit/src/gtk/TikzDocument.h +++ /dev/null @@ -1,149 +0,0 @@ -// -// TikzDocument.h -// TikZiT -// -// Copyright 2010 Chris Heunen -// Copyright 2010 Alex Merry -// -// This file is part of TikZiT. -// -// TikZiT is free software: you can redistribute it and/or modify -// it under the terms of the GNU General Public License as published by -// the Free Software Foundation, either version 3 of the License, or -// (at your option) any later version. -// -// TikZiT is distributed in the hope that it will be useful, -// but WITHOUT ANY WARRANTY; without even the implied warranty of -// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -// GNU General Public License for more details. -// -// You should have received a copy of the GNU General Public License -// along with TikZiT. If not, see <http://www.gnu.org/licenses/>. -// - -#import "TZFoundation.h" -#import <Graph.h> -#import "PickSupport.h" -#import "StyleManager.h" - -@interface TikzDocument : NSObject { - StyleManager *styleManager; - Graph *graph; - PickSupport *pickSupport; - NSUndoManager *undoManager; - NSString *tikz; - NSString *path; - NSSet *nodesetBeingModified; - NSMapTable *nodesetBeingModifiedOldCopy; - NSSet *edgesetBeingModified; - NSMapTable *edgesetBeingModifiedOldCopy; - NSPoint currentNodeShift; - Node *nodeBeingModified; - Node *nodeBeingModifiedOldCopy; - Edge *edgeBeingModified; - Edge *edgeBeingModifiedOldCopy; - NSRect oldGraphBounds; - GraphElementData *oldGraphData; - BOOL hasChanges; -} - -+ (TikzDocument*) documentWithStyleManager:(StyleManager*)manager; -+ (TikzDocument*) documentWithGraph:(Graph*)g styleManager:(StyleManager*)manager; -+ (TikzDocument*) documentWithTikz:(NSString*)t styleManager:(StyleManager*)manager error:(NSError**)error; -+ (TikzDocument*) documentFromFile:(NSString*)path styleManager:(StyleManager*)manager error:(NSError**)error; - -- (id) initWithStyleManager:(StyleManager*)manager; -- (id) initWithGraph:(Graph*)g styleManager:(StyleManager*)manager; -- (id) initWithTikz:(NSString*)t styleManager:(StyleManager*)manager error:(NSError**)error; -- (id) initFromFile:(NSString*)path styleManager:(StyleManager*)manager error:(NSError**)error; - -@property (readonly) Graph *graph; -@property (readonly) PickSupport *pickSupport; -@property (readonly) NSString *path; -@property (readonly) NSString *name; -@property (readonly) NSString *suggestedFileName; -@property (readonly) BOOL hasUnsavedChanges; -@property (retain) StyleManager *styleManager; -@property (readonly) NSString *tikz; -@property (readonly) BOOL canUndo; -@property (readonly) BOOL canRedo; -@property (readonly) NSString *undoName; -@property (readonly) NSString *redoName; - -- (BOOL) updateTikz:(NSString*)t error:(NSError**)error; - -- (Graph*) selectionCut; -- (Graph*) selectionCopy; -- (void) paste:(Graph*)graph; -- (void) pasteFromTikz:(NSString*)tikz; - -// some convenience methods: -- (BOOL) isNodeSelected:(Node*)node; -- (BOOL) isEdgeSelected:(Edge*)edge; -- (NSEnumerator*) nodeEnumerator; -- (NSEnumerator*) edgeEnumerator; - -- (void) undo; -- (void) redo; - -- (void) startUndoGroup; -- (void) nameAndEndUndoGroup:(NSString*)nm; -- (void) endUndoGroup; - -- (void) startModifyNode:(Node*)node; -- (void) modifyNodeCheckPoint; -- (void) endModifyNode; -- (void) cancelModifyNode; - -- (void) startModifyNodes:(NSSet*)nodes; -- (void) modifyNodesCheckPoint; -- (void) endModifyNodes; -- (void) cancelModifyNodes; - -- (void) startShiftNodes:(NSSet*)nodes; -- (void) shiftNodesUpdate:(NSPoint)shiftChange; -- (void) endShiftNodes; -- (void) cancelShiftNodes; - -- (void) startModifyEdge:(Edge*)edge; -- (void) modifyEdgeCheckPoint; -- (void) endModifyEdge; -- (void) cancelModifyEdge; - -- (void) startModifyEdges:(NSSet*)edges; -- (void) modifyEdgesCheckPoint; -- (void) endModifyEdges; -- (void) cancelModifyEdges; - -- (void) startChangeBoundingBox; -- (void) changeBoundingBoxCheckPoint; -- (void) endChangeBoundingBox; -- (void) cancelChangeBoundingBox; - -- (void) startChangeGraphProperties; -- (void) changeGraphPropertiesCheckPoint; -- (void) endChangeGraphProperties; -- (void) cancelChangeGraphProperties; - -- (void) removeSelected; -- (void) addNode:(Node*)node; -- (void) removeNode:(Node*)node; -- (void) addEdge:(Edge*)edge; -- (void) removeEdge:(Edge*)edge; -- (void) shiftSelectedNodesByPoint:(NSPoint)offset; -- (void) insertGraph:(Graph*)g; -- (void) flipSelectedNodesHorizontally; -- (void) flipSelectedNodesVertically; -- (void) reverseSelectedEdges; -- (void) bringSelectionForward; -- (void) bringSelectionToFront; -- (void) sendSelectionBackward; -- (void) sendSelectionToBack; - -- (BOOL) saveCopyToPath: (NSString*)path error: (NSError**)error; -- (BOOL) saveToPath: (NSString*)path error: (NSError**)error; -- (BOOL) save: (NSError**)error; - -@end - -// vim:ft=objc:sts=4:sw=4:et diff --git a/tikzit/src/gtk/TikzDocument.m b/tikzit/src/gtk/TikzDocument.m deleted file mode 100644 index 6e013b1..0000000 --- a/tikzit/src/gtk/TikzDocument.m +++ /dev/null @@ -1,913 +0,0 @@ -// -// TikzDocument.h -// TikZiT -// -// Copyright 2010 Chris Heunen -// Copyright 2010 Alex Merry -// -// This file is part of TikZiT. -// -// TikZiT is free software: you can redistribute it and/or modify -// it under the terms of the GNU General Public License as published by -// the Free Software Foundation, either version 3 of the License, or -// (at your option) any later version. -// -// TikZiT is distributed in the hope that it will be useful, -// but WITHOUT ANY WARRANTY; without even the implied warranty of -// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -// GNU General Public License for more details. -// -// You should have received a copy of the GNU General Public License -// along with TikZiT. If not, see <http://www.gnu.org/licenses/>. -// - -#import "TikzDocument.h" - -@interface TikzDocument (Private) -- (void) styleRenamed:(NSNotification*)n; - -- (void) setPath:(NSString*)path; -- (void) setGraph:(Graph*)g; - -- (void) registerUndoForChange:(GraphChange*)change; -- (void) registerUndoGroupForChange:(GraphChange*)change withName:(NSString*)name; -- (void) undoGraphChange:(GraphChange*)change; -- (void) completedGraphChange:(GraphChange*)change withName:(NSString*)name; -- (void) attachStylesToGraph:(Graph*)g; - -- (void) regenerateTikz; -@end - -@implementation TikzDocument - -+ (TikzDocument*) documentWithStyleManager:(StyleManager*)manager -{ - return [[[TikzDocument alloc] initWithStyleManager:manager] autorelease]; -} - -+ (TikzDocument*) documentWithGraph:(Graph*)g - styleManager:(StyleManager*)manager -{ - return [[[TikzDocument alloc] initWithGraph:g - styleManager:manager] autorelease]; -} - -+ (TikzDocument*) documentWithTikz:(NSString*)t - styleManager:(StyleManager*)manager - error:(NSError**)error -{ - return [[[TikzDocument alloc] initWithTikz:t - styleManager:manager - error:error] autorelease]; -} - -+ (TikzDocument*) documentFromFile:(NSString*)pth - styleManager:(StyleManager*)manager - error:(NSError**)error -{ - return [[[TikzDocument alloc] initFromFile:pth - styleManager:manager - error:error] autorelease]; -} - - -- (id) initWithStyleManager:(StyleManager*)manager { - self = [self initWithGraph:[Graph graph] styleManager:manager]; - return self; -} - -- (id) initWithGraph:(Graph*)g styleManager:(StyleManager*)manager { - self = [super init]; - - if (self) { - graph = nil; - styleManager = [manager retain]; - pickSupport = [[PickSupport alloc] init]; - undoManager = [[NSUndoManager alloc] init]; - [undoManager setGroupsByEvent:NO]; - tikz = nil; - path = nil; - nodesetBeingModified = nil; - nodesetBeingModifiedOldCopy = nil; - nodeBeingModified = nil; - nodeBeingModifiedOldCopy = nil; - edgeBeingModified = nil; - edgeBeingModifiedOldCopy = nil; - - [undoManager disableUndoRegistration]; - [self setGraph:g]; - [undoManager enableUndoRegistration]; - - hasChanges = NO; - - [[NSNotificationCenter defaultCenter] - addObserver:self - selector:@selector(styleRenamed:) - name:@"NodeStyleRenamed" - object:styleManager]; - [[NSNotificationCenter defaultCenter] - addObserver:self - selector:@selector(styleRenamed:) - name:@"EdgeStyleRenamed" - object:styleManager]; - } - - return self; -} - -- (id) initWithTikz:(NSString*)t - styleManager:(StyleManager*)manager - error:(NSError**)error -{ - self = [self initWithStyleManager:manager]; - - if (self) { - [undoManager disableUndoRegistration]; - BOOL success = [self updateTikz:t error:error]; - if (!success) { - [self release]; - return nil; - } - [undoManager enableUndoRegistration]; - hasChanges = NO; - } - - return self; -} - -- (id) initFromFile:(NSString*)pth - styleManager:(StyleManager*)manager - error:(NSError**)error -{ - NSStringEncoding enc; // we can't pass in NULL here... - NSString *t = [NSString stringWithContentsOfFile:pth - usedEncoding:&enc error:error]; - if (t == nil) { - [self release]; - return nil; - } - - self = [self initWithTikz:t styleManager:manager error:error]; - - if (self) { - [self setPath:pth]; - } - return self; -} - -- (void) dealloc { - [[NSNotificationCenter defaultCenter] removeObserver:self]; - - [styleManager release]; - [graph release]; - [pickSupport release]; - [undoManager release]; - [tikz release]; - [path release]; - [nodesetBeingModified release]; - [nodesetBeingModifiedOldCopy release]; - [nodeBeingModified release]; - [nodeBeingModifiedOldCopy release]; - [edgeBeingModified release]; - [edgeBeingModifiedOldCopy release]; - [oldGraphData release]; - [super dealloc]; -} - -@synthesize graph, pickSupport, path; - -- (NSString*) name { - if (path) { - return [[NSFileManager defaultManager] displayNameAtPath: path]; - } else { - return @"Untitled"; - } -} - -- (NSString*) suggestedFileName { - if (path) { - return [path lastPathComponent]; - } else { - return @"untitled.tikz"; - } -} - -- (BOOL) hasUnsavedChanges { - return hasChanges; -} - -- (StyleManager*) styleManager { - return styleManager; -} - -- (void) setStyleManager:(StyleManager*)manager { - StyleManager *oldManager = styleManager; - [[NSNotificationCenter defaultCenter] - removeObserver:self - name:nil - object:oldManager]; - - styleManager = [manager retain]; - - [[NSNotificationCenter defaultCenter] - addObserver:self - selector:@selector(styleRenamed:) - name:@"NodeStyleRenamed" - object:styleManager]; - [[NSNotificationCenter defaultCenter] - addObserver:self - selector:@selector(styleRenamed:) - name:@"EdgeStyleRenamed" - object:styleManager]; - - [self attachStylesToGraph:graph]; - [oldManager release]; -} - -- (void) postGraphReplaced { - [[NSNotificationCenter defaultCenter] postNotificationName:@"GraphReplaced" object:self]; -} - -- (void) postGraphChange:(GraphChange*)change { - NSDictionary *info = [NSDictionary dictionaryWithObject:change forKey:@"change"]; - [[NSNotificationCenter defaultCenter] postNotificationName:@"GraphChanged" object:self userInfo:info]; -} - -- (void) postIncompleteGraphChange:(GraphChange*)change { - NSDictionary *info = [NSDictionary dictionaryWithObject:change forKey:@"change"]; - [[NSNotificationCenter defaultCenter] postNotificationName:@"GraphBeingChanged" object:self userInfo:info]; -} - -- (void) postCancelledGraphChange:(GraphChange*)change { - NSDictionary *info = [NSDictionary dictionaryWithObject:change forKey:@"change"]; - [[NSNotificationCenter defaultCenter] postNotificationName:@"GraphChangeCancelled" object:self userInfo:info]; -} - -- (void) postTikzChanged { - [[NSNotificationCenter defaultCenter] postNotificationName:@"TikzChanged" object:self]; -} - -- (void) postUndoStackChanged { - [[NSNotificationCenter defaultCenter] postNotificationName:@"UndoStackChanged" object:self]; -} - -- (NSString*) tikz { - return tikz; -} - -- (BOOL) updateTikz:(NSString*)t error:(NSError**)error { - if (t == nil) { - t = [NSString string]; - } - if (t == tikz || [t isEqual:tikz]) { - return YES; - } - - Graph *g = [Graph graphFromTikz:t error:error]; - if (g) { - // updateTikz actually generates a graph from the tikz, - // and generates the final tikz from that - [self startUndoGroup]; - [self setGraph:g]; - [self nameAndEndUndoGroup:@"Update tikz"]; - return YES; - } - - return NO; -} - -- (Graph*) selectionCut { - Graph *selection = [self selectionCopy]; - [self startUndoGroup]; - [self removeSelected]; - [self nameAndEndUndoGroup:@"Cut"]; - return selection; -} - -- (Graph*) selectionCopy { - return [[graph copyOfSubgraphWithNodes:[pickSupport selectedNodes]] autorelease]; -} - -- (void) paste:(Graph*)g { - if (g == nil || [[g nodes] count] == 0) { - // nothing to paste - return; - } - - // place to the right of the existing graph - NSRect bounds = [graph bounds]; - NSRect gBounds = [g bounds]; - float dx = NSMaxX (bounds) - gBounds.origin.x + 0.5f; - [g shiftNodes:[g nodes] byPoint:NSMakePoint (dx, 0)]; - - GraphChange *change = [graph insertGraph:g]; - [self completedGraphChange:change withName:@"Paste"]; - - // select everything from the clipboard - [pickSupport deselectAllEdges]; - [pickSupport selectAllNodes:[NSSet setWithArray:[g nodes]] replacingSelection:YES]; -} - -- (void) pasteFromTikz:(NSString*)t { - Graph *clipboard = [Graph graphFromTikz:t]; - if (clipboard) { - [self attachStylesToGraph:clipboard]; - [self paste:clipboard]; - } -} - -- (BOOL) isNodeSelected:(Node*)node { - return [pickSupport isNodeSelected:node]; -} - -- (BOOL) isEdgeSelected:(Edge*)edge { - return [pickSupport isEdgeSelected:edge]; -} - -- (NSEnumerator*) nodeEnumerator { - return [[graph nodes] objectEnumerator]; -} - -- (NSEnumerator*) edgeEnumerator { - return [[graph edges] objectEnumerator]; -} - -- (BOOL) canUndo { - return [undoManager canUndo]; -} - -- (void) undo { - [undoManager undo]; - [self postUndoStackChanged]; -} - -- (BOOL) canRedo { - return [undoManager canRedo]; -} - -- (void) redo { - [undoManager redo]; - [self postUndoStackChanged]; -} - -- (NSString*) undoName { - return [undoManager undoActionName]; -} - -- (NSString*) redoName { - return [undoManager redoActionName]; -} - -- (void) startUndoGroup { - [undoManager beginUndoGrouping]; -} - -- (void) nameAndEndUndoGroup:(NSString*)nm { - [undoManager setActionName:nm]; - [undoManager endUndoGrouping]; - [self postUndoStackChanged]; -} - -- (void) endUndoGroup { - [undoManager endUndoGrouping]; - [self postUndoStackChanged]; -} - -- (void) startModifyNode:(Node*)node { - if (nodeBeingModified != nil) { - [NSException raise:@"NSInternalInconsistencyException" format:@"Already modifying a node"]; - } - nodeBeingModified = [node retain]; - nodeBeingModifiedOldCopy = [node copy]; -} - -- (void) modifyNodeCheckPoint { - [self regenerateTikz]; - GraphChange *change = [GraphChange propertyChangeOfNode:nodeBeingModified - fromOld:nodeBeingModifiedOldCopy - toNew:[[nodeBeingModified copy] autorelease]]; - [self postIncompleteGraphChange:change]; -} - -- (void) _finishModifySequence:(GraphChange*)change withName:(NSString*)chName cancelled:(BOOL)cancelled { - if (cancelled) { - change = [change invert]; - [graph applyGraphChange:change]; - [self regenerateTikz]; - [self postCancelledGraphChange:change]; - } else { - [self registerUndoGroupForChange:change withName:chName]; - [self regenerateTikz]; - [self postGraphChange:change]; - } -} - -- (void) _finishModifyNodeCancelled:(BOOL)cancelled { - if (nodeBeingModified == nil) { - [NSException raise:@"NSInternalInconsistencyException" format:@"Not modifying a node"]; - } - - GraphChange *change = [GraphChange propertyChangeOfNode:nodeBeingModified - fromOld:nodeBeingModifiedOldCopy - toNew:[[nodeBeingModified copy] autorelease]]; - [self _finishModifySequence:change withName:@"Modify node" cancelled:cancelled]; - - [nodeBeingModified release]; - nodeBeingModified = nil; - [nodeBeingModifiedOldCopy release]; - nodeBeingModifiedOldCopy = nil; -} - -- (void) endModifyNode { [self _finishModifyNodeCancelled:NO]; } -- (void) cancelModifyNode { [self _finishModifyNodeCancelled:YES]; } - -- (void) startModifyNodes:(NSSet*)nodes { - if (nodesetBeingModified != nil) { - [NSException raise:@"NSInternalInconsistencyException" format:@"Already modifying a node set"]; - } - - nodesetBeingModified = [nodes copy]; - nodesetBeingModifiedOldCopy = [[Graph nodeTableForNodes:nodes] retain]; -} - -- (void) modifyNodesCheckPoint { - [self regenerateTikz]; - GraphChange *change = [GraphChange propertyChangeOfNodesFromOldCopies:nodesetBeingModifiedOldCopy - toNewCopies:[Graph nodeTableForNodes:nodesetBeingModified]]; - [self postIncompleteGraphChange:change]; -} - -- (void) _finishModifyNodes:(BOOL)cancelled { - if (nodesetBeingModified == nil) { - [NSException raise:@"NSInternalInconsistencyException" format:@"Not modifying a node set"]; - } - - GraphChange *change = [GraphChange propertyChangeOfNodesFromOldCopies:nodesetBeingModifiedOldCopy - toNewCopies:[Graph nodeTableForNodes:nodesetBeingModified]]; - [self _finishModifySequence:change withName:@"Modify nodes" cancelled:cancelled]; - - [nodesetBeingModified release]; - nodesetBeingModified = nil; - [nodesetBeingModifiedOldCopy release]; - nodesetBeingModifiedOldCopy = nil; -} - -- (void) endModifyNodes { [self _finishModifyNodes:NO]; } -- (void) cancelModifyNodes { [self _finishModifyNodes:YES]; } - -- (void) startShiftNodes:(NSSet*)nodes { - if (nodesetBeingModified != nil) { - [NSException raise:@"NSInternalInconsistencyException" format:@"Already modifying a node set"]; - } - - nodesetBeingModified = [nodes copy]; - currentNodeShift = NSZeroPoint; -} - -- (void) shiftNodesUpdate:(NSPoint)currentShift { - if (nodesetBeingModified == nil) { - [NSException raise:@"NSInternalInconsistencyException" format:@"Not modifying a node set"]; - } - - currentNodeShift = currentShift; - [self regenerateTikz]; - GraphChange *change = [GraphChange shiftNodes:nodesetBeingModified - byPoint:currentNodeShift]; - [self postIncompleteGraphChange:change]; -} - -- (void) _finishShiftNodesCancelled:(BOOL)cancelled { - if (nodesetBeingModified == nil) { - [NSException raise:@"NSInternalInconsistencyException" format:@"Not modifying a node set"]; - } - - if (!NSEqualPoints (currentNodeShift, NSZeroPoint)) { - GraphChange *change = [GraphChange shiftNodes:nodesetBeingModified - byPoint:currentNodeShift]; - [self _finishModifySequence:change withName:@"Move nodes" cancelled:cancelled]; - } - - [nodesetBeingModified release]; - nodesetBeingModified = nil; -} - -- (void) endShiftNodes { [self _finishShiftNodesCancelled:NO]; } -- (void) cancelShiftNodes { [self _finishShiftNodesCancelled:YES]; } - -- (void) startModifyEdge:(Edge*)edge { - if (edgeBeingModified != nil) { - [NSException raise:@"NSInternalInconsistencyException" format:@"Already modifying an edge"]; - } - edgeBeingModified = [edge retain]; - edgeBeingModifiedOldCopy = [edge copy]; -} - -- (void) modifyEdgeCheckPoint { - [self regenerateTikz]; - GraphChange *change = [GraphChange propertyChangeOfEdge:edgeBeingModified - fromOld:edgeBeingModifiedOldCopy - toNew:[[edgeBeingModified copy] autorelease]]; - [self postIncompleteGraphChange:change]; -} - -- (void) _finishModifyEdgeCancelled:(BOOL)cancelled { - if (edgeBeingModified == nil) { - [NSException raise:@"NSInternalInconsistencyException" format:@"Not modifying an edge"]; - } - - GraphChange *change = [GraphChange propertyChangeOfEdge:edgeBeingModified - fromOld:edgeBeingModifiedOldCopy - toNew:[[edgeBeingModified copy] autorelease]]; - [self _finishModifySequence:change withName:@"Modify edge" cancelled:cancelled]; - - [edgeBeingModified release]; - edgeBeingModified = nil; - [edgeBeingModifiedOldCopy release]; - edgeBeingModifiedOldCopy = nil; -} - -- (void) endModifyEdge { [self _finishModifyEdgeCancelled:NO]; } -- (void) cancelModifyEdge { [self _finishModifyEdgeCancelled:YES]; } - -- (void) startModifyEdges:(NSSet*)edges { - if (edgesetBeingModified != nil) { - [NSException raise:@"NSInternalInconsistencyException" format:@"Already modifying an edge set"]; - } - - edgesetBeingModified = [edges copy]; - edgesetBeingModifiedOldCopy = [[Graph edgeTableForEdges:edges] retain]; -} - -- (void) modifyEdgesCheckPoint { - [self regenerateTikz]; - GraphChange *change = [GraphChange propertyChangeOfEdgesFromOldCopies:edgesetBeingModifiedOldCopy - toNewCopies:[Graph edgeTableForEdges:edgesetBeingModified]]; - [self postIncompleteGraphChange:change]; -} - -- (void) _finishModifyEdgesCancelled:(BOOL)cancelled { - if (edgesetBeingModified == nil) { - [NSException raise:@"NSInternalInconsistencyException" format:@"Not modifying an edge"]; - } - - GraphChange *change = [GraphChange propertyChangeOfEdgesFromOldCopies:edgesetBeingModifiedOldCopy - toNewCopies:[Graph edgeTableForEdges:edgesetBeingModified]]; - [self _finishModifySequence:change withName:@"Modify edges" cancelled:cancelled]; - - [edgesetBeingModified release]; - edgesetBeingModified = nil; - [edgesetBeingModifiedOldCopy release]; - edgesetBeingModifiedOldCopy = nil; -} - -- (void) endModifyEdges { [self _finishModifyEdgesCancelled:NO]; } -- (void) cancelModifyEdges { [self _finishModifyEdgesCancelled:YES]; } - -- (void) startChangeBoundingBox { - oldGraphBounds = [graph boundingBox]; -} - -- (void) changeBoundingBoxCheckPoint { - [self regenerateTikz]; - GraphChange *change = [GraphChange changeBoundingBoxFrom:oldGraphBounds - to:[graph boundingBox]]; - [self postIncompleteGraphChange:change]; -} - -- (void) _finishChangeBoundingBoxCancelled:(BOOL)cancelled { - GraphChange *change = [GraphChange changeBoundingBoxFrom:oldGraphBounds - to:[graph boundingBox]]; - [self _finishModifySequence:change withName:@"Set bounding box" cancelled:cancelled]; -} -- (void) endChangeBoundingBox { [self _finishChangeBoundingBoxCancelled:NO]; } -- (void) cancelChangeBoundingBox { [self _finishChangeBoundingBoxCancelled:YES]; } - -- (void) startChangeGraphProperties { - oldGraphData = [[graph data] copy]; -} - -- (void) changeGraphPropertiesCheckPoint { - [self regenerateTikz]; - GraphChange *change = [GraphChange propertyChangeOfGraphFrom:oldGraphData - to:[graph data]]; - [self postIncompleteGraphChange:change]; -} - -- (void) _finishChangeGraphPropertiesCancelled:(BOOL)cancelled { - GraphChange *change = [GraphChange propertyChangeOfGraphFrom:oldGraphData - to:[graph data]]; - [self _finishModifySequence:change withName:@"Change graph properties" cancelled:cancelled]; - [oldGraphData release]; - oldGraphData = nil; -} -- (void) endChangeGraphProperties { [self _finishChangeGraphPropertiesCancelled:NO]; } -- (void) cancelChangeGraphProperties { [self _finishChangeGraphPropertiesCancelled:YES]; } - -- (void) removeSelected { - NSUInteger selEdges = [[pickSupport selectedEdges] count]; - NSUInteger selNodes = [[pickSupport selectedNodes] count]; - - if (selEdges == 0 && selNodes == 0) { - return; - } - - NSString *actionName = @"Remove selection"; - - [self startUndoGroup]; - if (selEdges > 0) { - GraphChange *change = [graph removeEdges:[pickSupport selectedEdges]]; - [self registerUndoForChange:change]; - [pickSupport deselectAllEdges]; - [self postGraphChange:change]; - } else { - actionName = (selNodes == 1 ? @"Remove node" : @"Remove nodes"); - } - if (selNodes > 0) { - GraphChange *change = [graph removeNodes:[pickSupport selectedNodes]]; - [self registerUndoForChange:change]; - [pickSupport deselectAllNodes]; - [self postGraphChange:change]; - } else { - actionName = (selEdges == 1 ? @"Remove edge" : @"Remove edges"); - } - [self nameAndEndUndoGroup:actionName]; - [self regenerateTikz]; -} - -- (void) addNode:(Node*)node { - GraphChange *change = [graph addNode:node]; - [self completedGraphChange:change withName:@"Add node"]; -} - -- (void) removeNode:(Node*)node { - [pickSupport deselectNode:node]; - GraphChange *change = [graph removeNode:node]; - [self completedGraphChange:change withName:@"Remove node"]; -} - -- (void) addEdge:(Edge*)edge { - GraphChange *change = [graph addEdge:edge]; - [self completedGraphChange:change withName:@"Add edge"]; -} - -- (void) removeEdge:(Edge*)edge { - [pickSupport deselectEdge:edge]; - GraphChange *change = [graph removeEdge:edge]; - [self completedGraphChange:change withName:@"Remove edge"]; -} - -- (void) shiftSelectedNodesByPoint:(NSPoint)offset { - if ([[pickSupport selectedNodes] count] > 0) { - GraphChange *change = [graph shiftNodes:[pickSupport selectedNodes] byPoint:offset]; - [self completedGraphChange:change withName:@"Move nodes"]; - } -} - -- (void) insertGraph:(Graph*)g { - GraphChange *change = [graph insertGraph:g]; - [self completedGraphChange:change withName:@"Insert graph"]; -} - -- (void) flipSelectedNodesHorizontally { - if ([[pickSupport selectedNodes] count] > 0) { - GraphChange *change = [graph flipHorizontalNodes:[pickSupport selectedNodes]]; - [self completedGraphChange:change withName:@"Flip nodes horizontally"]; - } -} - -- (void) flipSelectedNodesVertically { - if ([[pickSupport selectedNodes] count] > 0) { - GraphChange *change = [graph flipVerticalNodes:[pickSupport selectedNodes]]; - [self completedGraphChange:change withName:@"Flip nodes vertically"]; - } -} - -- (void) reverseSelectedEdges { - if ([[pickSupport selectedEdges] count] > 0) { - GraphChange *change = [graph reverseEdges:[pickSupport selectedEdges]]; - [self completedGraphChange:change withName:@"Reverse edges"]; - } -} - -- (void) bringSelectionForward { - BOOL hasNodeSelection = [[pickSupport selectedNodes] count] > 0; - BOOL hasEdgeSelection = [[pickSupport selectedEdges] count] > 0; - if (!hasNodeSelection && !hasEdgeSelection) - return; - - [self startUndoGroup]; - GraphChange *nodeChange; - GraphChange *edgeChange; - if (hasNodeSelection) { - nodeChange = [graph bringNodesForward:[pickSupport selectedNodes]]; - [self registerUndoForChange:nodeChange]; - } - if (hasEdgeSelection) { - edgeChange = [graph bringEdgesForward:[pickSupport selectedEdges]]; - [self registerUndoForChange:edgeChange]; - } - [self nameAndEndUndoGroup:@"Bring forward"]; - [self regenerateTikz]; - if (hasNodeSelection) - [self postGraphChange:nodeChange]; - if (hasEdgeSelection) - [self postGraphChange:edgeChange]; -} - -- (void) bringSelectionToFront { - BOOL hasNodeSelection = [[pickSupport selectedNodes] count] > 0; - BOOL hasEdgeSelection = [[pickSupport selectedEdges] count] > 0; - if (!hasNodeSelection && !hasEdgeSelection) - return; - - [self startUndoGroup]; - GraphChange *nodeChange; - GraphChange *edgeChange; - if (hasNodeSelection) { - nodeChange = [graph bringNodesToFront:[pickSupport selectedNodes]]; - [self registerUndoForChange:nodeChange]; - } - if (hasEdgeSelection) { - edgeChange = [graph bringEdgesToFront:[pickSupport selectedEdges]]; - [self registerUndoForChange:edgeChange]; - } - [self nameAndEndUndoGroup:@"Bring to front"]; - [self regenerateTikz]; - if (hasNodeSelection) - [self postGraphChange:nodeChange]; - if (hasEdgeSelection) - [self postGraphChange:edgeChange]; -} - -- (void) sendSelectionBackward { - BOOL hasNodeSelection = [[pickSupport selectedNodes] count] > 0; - BOOL hasEdgeSelection = [[pickSupport selectedEdges] count] > 0; - if (!hasNodeSelection && !hasEdgeSelection) - return; - - [self startUndoGroup]; - GraphChange *nodeChange; - GraphChange *edgeChange; - if (hasNodeSelection) { - nodeChange = [graph sendNodesBackward:[pickSupport selectedNodes]]; - [self registerUndoForChange:nodeChange]; - } - if (hasEdgeSelection) { - edgeChange = [graph sendNodesBackward:[pickSupport selectedEdges]]; - [self registerUndoForChange:edgeChange]; - } - [self nameAndEndUndoGroup:@"Send backward"]; - [self regenerateTikz]; - if (hasNodeSelection) - [self postGraphChange:nodeChange]; - if (hasEdgeSelection) - [self postGraphChange:edgeChange]; -} - -- (void) sendSelectionToBack { - BOOL hasNodeSelection = [[pickSupport selectedNodes] count] > 0; - BOOL hasEdgeSelection = [[pickSupport selectedEdges] count] > 0; - if (!hasNodeSelection && !hasEdgeSelection) - return; - - [self startUndoGroup]; - GraphChange *nodeChange; - GraphChange *edgeChange; - if (hasNodeSelection) { - nodeChange = [graph sendNodesToBack:[pickSupport selectedNodes]]; - [self registerUndoForChange:nodeChange]; - } - if (hasEdgeSelection) { - edgeChange = [graph sendNodesToBack:[pickSupport selectedEdges]]; - [self registerUndoForChange:edgeChange]; - } - [self nameAndEndUndoGroup:@"Send to back"]; - [self regenerateTikz]; - if (hasNodeSelection) - [self postGraphChange:nodeChange]; - if (hasEdgeSelection) - [self postGraphChange:edgeChange]; -} - -- (BOOL) saveCopyToPath: (NSString*)p error: (NSError**)error { - if (!p) { - [NSException raise:@"No document path" format:@"No path given"]; - } - // we use glib for writing the file, because GNUStep sucks in this regard - // (older versions don't have -[NSString writeToFile:atomically:encoding:error:]) - GError *gerror = NULL; - gchar *filename = [p glibFilename]; - BOOL success = g_file_set_contents (filename, [tikz UTF8String], -1, &gerror) ? YES : NO; - if (gerror) { - GErrorToNSError (gerror, error); - g_error_free (gerror); - } - g_free (filename); - return success; -} - -- (BOOL) saveToPath: (NSString*)p error: (NSError**)error { - BOOL success = [self saveCopyToPath:p error:error]; - if (success) { - [self setPath:p]; - hasChanges = NO; - } - return success; -} - -- (BOOL) save: (NSError**)error { - if (!path) { - [NSException raise:@"No document path" format:@"Tried to save a document when there was no path"]; - } - return [self saveToPath:path error:error]; -} - -@end - -@implementation TikzDocument (Private) -- (void) styleRenamed:(NSNotification*)n { - [self regenerateTikz]; -} - -- (void) setPath:(NSString*)p { - [p retain]; - [path release]; - path = p; -} - -- (void) setGraph:(Graph*)g { - if (g == nil) { - g = [Graph graph]; - } - if (g == graph) { - return; - } - - [pickSupport deselectAllNodes]; - [pickSupport deselectAllEdges]; - - [self startUndoGroup]; - [undoManager registerUndoWithTarget:self selector:@selector(setGraph:) object:graph]; - [g retain]; - [graph release]; - graph = g; - - [self attachStylesToGraph:graph]; - - [self regenerateTikz]; - [self postGraphReplaced]; - [self nameAndEndUndoGroup:@"Replace graph"]; -} - -- (void) registerUndoForChange:(GraphChange*)change { - [undoManager registerUndoWithTarget:self - selector:@selector(undoGraphChange:) - object:change]; -} - -- (void) registerUndoGroupForChange:(GraphChange*)change withName:(NSString*)nm { - [self startUndoGroup]; - [self registerUndoForChange:change]; - [self nameAndEndUndoGroup:nm]; -} - -- (void) undoGraphChange:(GraphChange*)change { - GraphChange *inverse = [change invert]; - [graph applyGraphChange:inverse]; - [self startUndoGroup]; - [undoManager registerUndoWithTarget:self - selector:@selector(undoGraphChange:) - object:inverse]; - [self endUndoGroup]; - [self regenerateTikz]; - [self postGraphChange:change]; -} - -- (void) completedGraphChange:(GraphChange*)change withName:(NSString*)name { - if (change == nil) { - NSLog(@"No graph change given for change %@", name); - return; - } - [self registerUndoGroupForChange:change withName:name]; - [self regenerateTikz]; - [self postGraphChange:change]; -} - -- (void) attachStylesToGraph:(Graph*)g { - for (Node *n in [g nodes]) { - [n attachStyleFromTable:[styleManager nodeStyles]]; - } - for (Edge *e in [g edges]) { - [e attachStyleFromTable:[styleManager edgeStyles]]; - } -} - -- (void) regenerateTikz { - [tikz release]; - tikz = [[graph tikz] retain]; - hasChanges = YES; - [self postTikzChanged]; -} -@end - -// vim:ft=objc:sts=4:sw=4:et diff --git a/tikzit/src/gtk/Tool.h b/tikzit/src/gtk/Tool.h deleted file mode 100644 index 22c983e..0000000 --- a/tikzit/src/gtk/Tool.h +++ /dev/null @@ -1,41 +0,0 @@ -/* - * Copyright 2012 Alex Merry <alex.merry@kdemail.net> - * - * 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 the Free Software Foundation; either version 2 of - * the License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see <http://www.gnu.org/licenses/>. - */ - -#import "TZFoundation.h" -#import "InputDelegate.h" -#import "Surface.h" - -#import <gtk/gtk.h> -#import <gdk-pixbuf/gdk-pixdata.h> - -@class Configuration; -@class GraphRenderer; -@protocol InputDelegate; -@protocol RenderDelegate; - -@protocol Tool <RenderDelegate,InputDelegate> -@property (readonly) NSString *name; -@property (readonly) const gchar *stockId; -@property (readonly) NSString *helpText; -@property (readonly) NSString *shortcut; -@property (retain) GraphRenderer *activeRenderer; -@property (readonly) GtkWidget *configurationWidget; -- (void) loadConfiguration:(Configuration*)config; -- (void) saveConfiguration:(Configuration*)config; -@end - -// vim:ft=objc:ts=8:et:sts=4:sw=4 diff --git a/tikzit/src/gtk/ToolBox.h b/tikzit/src/gtk/ToolBox.h deleted file mode 100644 index 60074c1..0000000 --- a/tikzit/src/gtk/ToolBox.h +++ /dev/null @@ -1,45 +0,0 @@ -/* - * Copyright 2012 Alex Merry <dev@randomguy3.me.uk> - * - * 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 the Free Software Foundation; either version 2 of - * the License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see <http://www.gnu.org/licenses/>. - */ - -#import "TZFoundation.h" -#import <gtk/gtk.h> - -@class Configuration; -@class Window; -@protocol Tool; - -@interface ToolBox : NSObject { - GtkWidget *window; - GtkToolItemGroup *toolGroup; - GtkWidget *titleLabel; - GtkWidget *configWidgetContainer; - GtkWidget *configWidget; -} - -@property (assign) id<Tool> selectedTool; - -- (id) initWithTools:(NSArray*)tools; - -- (void) show; -- (void) present; -- (void) attachToWindow:(Window*)parent; - -- (void) loadConfiguration:(Configuration*)config; -- (void) saveConfiguration:(Configuration*)config; -@end - -// vim:ft=objc:ts=8:et:sts=4:sw=4 diff --git a/tikzit/src/gtk/ToolBox.m b/tikzit/src/gtk/ToolBox.m deleted file mode 100644 index c6d2ccf..0000000 --- a/tikzit/src/gtk/ToolBox.m +++ /dev/null @@ -1,280 +0,0 @@ -/* - * Copyright 2012 Alex Merry <dev@randomguy3.me.uk> - * - * 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 the Free Software Foundation; either version 2 of - * the License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see <http://www.gnu.org/licenses/>. - */ - -#import "ToolBox.h" - -#import "Application.h" -#import "Configuration.h" -#import "Tool.h" -#import "Window.h" - -#import "gtkhelpers.h" -#import "tztoolpalette.h" - -static void tool_button_toggled_cb (GtkWidget *widget, ToolBox *toolBox); - -#define TOOL_DATA_KEY "tikzit-tool" - -@implementation ToolBox - -- (id) init { - [self release]; - return nil; -} - -- (id) initWithTools:(NSArray*)tools { - self = [super init]; - - if (self) { - window = gtk_window_new (GTK_WINDOW_TOPLEVEL); - g_object_ref_sink (window); - gtk_window_set_title (GTK_WINDOW (window), "Toolbox"); - gtk_window_set_role (GTK_WINDOW (window), "toolbox"); - gtk_window_set_type_hint (GTK_WINDOW (window), - GDK_WINDOW_TYPE_HINT_UTILITY); - gtk_window_set_deletable (GTK_WINDOW (window), FALSE); - - GtkWidget *mainLayout = gtk_vbox_new (FALSE, 5); - gtk_widget_show (mainLayout); - gtk_container_add (GTK_CONTAINER (window), mainLayout); - - GtkWidget *toolPalette = tz_tool_palette_new (); - gtk_widget_show (toolPalette); - gtk_box_pack_start (GTK_BOX (mainLayout), - toolPalette, - FALSE, - FALSE, - 0); - gtk_tool_palette_set_style (GTK_TOOL_PALETTE (toolPalette), - GTK_TOOLBAR_ICONS); - - toolGroup = GTK_TOOL_ITEM_GROUP (gtk_tool_item_group_new ("Tools")); - g_object_ref_sink (G_OBJECT (toolGroup)); - gtk_tool_item_group_set_label_widget ( - toolGroup, - NULL); - gtk_container_add (GTK_CONTAINER (toolPalette), GTK_WIDGET (toolGroup)); - gtk_widget_show (GTK_WIDGET (toolGroup)); - - GSList *item_group = NULL; - for (id<Tool> tool in tools) { - NSString *tooltip = [NSString stringWithFormat: - @"%@: %@ (%@)", - [tool name], [tool helpText], [tool shortcut]]; - GtkToolItem *item = gtk_radio_tool_button_new_from_stock ( - item_group, - [tool stockId]); - gtk_tool_item_set_tooltip_text (item, [tooltip UTF8String]); - item_group = gtk_radio_tool_button_get_group ( - GTK_RADIO_TOOL_BUTTON (item)); - gtk_tool_item_group_insert ( - toolGroup, - item, - -1); - gtk_widget_show (GTK_WIDGET (item)); - g_object_set_data_full ( - G_OBJECT(item), - TOOL_DATA_KEY, - [tool retain], - release_obj); - - g_signal_connect (item, "toggled", - G_CALLBACK (tool_button_toggled_cb), - self); - } - - GtkWidget *sep = gtk_hseparator_new (); - gtk_widget_show (sep); - gtk_box_pack_start (GTK_BOX (mainLayout), - sep, - FALSE, - FALSE, - 0); - - titleLabel = gtk_label_new (""); - g_object_ref_sink (titleLabel); - gtk_widget_show (titleLabel); - - PangoAttrList *attrs = pango_attr_list_new (); - pango_attr_list_insert (attrs, - pango_attr_weight_new (PANGO_WEIGHT_SEMIBOLD)); - gtk_label_set_attributes (GTK_LABEL (titleLabel), attrs); - pango_attr_list_unref (attrs); - - gtk_box_pack_start (GTK_BOX (mainLayout), - titleLabel, - FALSE, - FALSE, - 0); - - configWidgetContainer = gtk_alignment_new (0.5, 0.5, 1.0, 1.0); - g_object_ref_sink (configWidgetContainer); - gtk_widget_show (configWidgetContainer); - gtk_box_pack_start (GTK_BOX (mainLayout), - configWidgetContainer, - TRUE, - TRUE, - 0); - gtk_alignment_set_padding (GTK_ALIGNMENT (configWidgetContainer), - 5, 5, 5, 5); - - gint button_width; - gint button_height; - - if (tz_tool_palette_get_button_size (TZ_TOOL_PALETTE (toolPalette), - &button_width, &button_height)) - { - GdkGeometry geometry; - - geometry.min_width = 2 * button_width; - geometry.min_height = -1; - geometry.base_width = button_width; - geometry.base_height = 0; - geometry.width_inc = button_width; - geometry.height_inc = 1; - - gtk_window_set_geometry_hints (GTK_WINDOW (window), - NULL, - &geometry, - GDK_HINT_MIN_SIZE | - GDK_HINT_BASE_SIZE | - GDK_HINT_RESIZE_INC | - GDK_HINT_USER_POS); - } - gtk_window_set_default_size (GTK_WINDOW (window), button_width * 5, 500); - - // hack to position the toolbox window somewhere sensible - // (upper left) - gtk_window_parse_geometry (GTK_WINDOW (window), "+0+0"); - } - - return self; -} - -- (void) dealloc { - if (window) { - g_object_unref (G_OBJECT (toolGroup)); - g_object_unref (G_OBJECT (titleLabel)); - g_object_unref (G_OBJECT (configWidgetContainer)); - if (configWidget) - g_object_unref (G_OBJECT (configWidget)); - gtk_widget_destroy (window); - g_object_unref (G_OBJECT (window)); - } - - [super dealloc]; -} - -- (id<Tool>) selectedTool { - guint count = gtk_tool_item_group_get_n_items (toolGroup); - for (guint i = 0; i < count; ++i) { - GtkToolItem *item = gtk_tool_item_group_get_nth_item (toolGroup, i); - if (gtk_toggle_tool_button_get_active (GTK_TOGGLE_TOOL_BUTTON (item))) { - return (id)g_object_get_data (G_OBJECT (item), TOOL_DATA_KEY); - } - } - return nil; -} - -- (void) _setToolWidget:(GtkWidget*)widget { - if (configWidget) { - gtk_widget_hide (configWidget); - gtk_container_remove (GTK_CONTAINER (configWidgetContainer), - configWidget); - g_object_unref (configWidget); - } - configWidget = widget; - if (configWidget) { - g_object_ref (configWidget); - gtk_container_add (GTK_CONTAINER (configWidgetContainer), - configWidget); - gtk_widget_show (configWidget); - } -} - -- (void) setSelectedTool:(id<Tool>)tool { - guint count = gtk_tool_item_group_get_n_items (toolGroup); - for (guint i = 0; i < count; ++i) { - GtkToolItem *item = gtk_tool_item_group_get_nth_item (toolGroup, i); - id<Tool> data = (id)g_object_get_data (G_OBJECT (item), TOOL_DATA_KEY); - if (data == tool) { - gtk_toggle_tool_button_set_active ( - GTK_TOGGLE_TOOL_BUTTON (item), - TRUE); - break; - } - } - gtk_label_set_label (GTK_LABEL (titleLabel), - [[tool name] UTF8String]); - [self _setToolWidget:[tool configurationWidget]]; -} - -- (void) show { - gtk_widget_show (window); -} - -- (void) present { - gtk_window_present (GTK_WINDOW (window)); -} - -- (void) attachToWindow:(Window*)parent { - utility_window_attach (GTK_WINDOW (window), [parent gtkWindow]); -} - -- (void) loadConfiguration:(Configuration*)config { - if ([config hasGroup:@"ToolBox"]) { - tz_restore_window (GTK_WINDOW (window), - [config integerEntry:@"x" inGroup:@"ToolBox"], - [config integerEntry:@"y" inGroup:@"ToolBox"], - [config integerEntry:@"w" inGroup:@"ToolBox"], - [config integerEntry:@"h" inGroup:@"ToolBox"]); - } -} - -- (void) saveConfiguration:(Configuration*)config { - gint x, y, w, h; - - gtk_window_get_position (GTK_WINDOW (window), &x, &y); - gtk_window_get_size (GTK_WINDOW (window), &w, &h); - - [config setIntegerEntry:@"x" inGroup:@"ToolBox" value:x]; - [config setIntegerEntry:@"y" inGroup:@"ToolBox" value:y]; - [config setIntegerEntry:@"w" inGroup:@"ToolBox" value:w]; - [config setIntegerEntry:@"h" inGroup:@"ToolBox" value:h]; -} - -@end - -static void tool_button_toggled_cb (GtkWidget *widget, ToolBox *toolBox) { - if (gtk_toggle_tool_button_get_active (GTK_TOGGLE_TOOL_BUTTON (widget))) { - NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init]; - - id<Tool> tool = (id)g_object_get_data (G_OBJECT(widget), TOOL_DATA_KEY); - [app setActiveTool:tool]; - NSDictionary *userInfo = [NSDictionary - dictionaryWithObject:tool - forKey:@"tool"]; - [[NSNotificationCenter defaultCenter] - postNotificationName:@"ToolSelectionChanged" - object:toolBox - userInfo:userInfo]; - - [pool drain]; - } -} - -// vim:ft=objc:ts=8:et:sts=4:sw=4 diff --git a/tikzit/src/gtk/WidgetSurface.h b/tikzit/src/gtk/WidgetSurface.h deleted file mode 100644 index 667749f..0000000 --- a/tikzit/src/gtk/WidgetSurface.h +++ /dev/null @@ -1,54 +0,0 @@ -/* - * Copyright 2011 Alex Merry <dev@randomguy3.me.uk> - * - * 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 the Free Software Foundation; either version 2 of - * the License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see <http://www.gnu.org/licenses/>. - */ - -#import "TZFoundation.h" -#import <gtk/gtk.h> -#import <InputDelegate.h> -#import <Surface.h> - -/** - * Provides a surface for rendering to a widget. - */ -@interface WidgetSurface: NSObject <Surface> { - GtkWidget *widget; - Transformer *transformer; - id <RenderDelegate> renderDelegate; - id <InputDelegate> inputDelegate; - BOOL keepCentered; - BOOL buttonPressesRequired; - CGFloat defaultScale; - NSSize lastKnownSize; -} - -@property (assign) BOOL canFocus; -@property (assign) BOOL keepCentered; -@property (assign) CGFloat defaultScale; - -- (id) initWithWidget:(GtkWidget*)widget; -- (GtkWidget*) widget; - -- (id<InputDelegate>) inputDelegate; -- (void) setInputDelegate:(id<InputDelegate>)delegate; - -/** - * Set the minimum size that this widget wants - */ -- (void) setSizeRequestWidth:(double)width height:(double)height; - -@end - -// vim:ft=objc:ts=8:et:sts=4:sw=4 diff --git a/tikzit/src/gtk/WidgetSurface.m b/tikzit/src/gtk/WidgetSurface.m deleted file mode 100644 index 680cf90..0000000 --- a/tikzit/src/gtk/WidgetSurface.m +++ /dev/null @@ -1,603 +0,0 @@ -/* - * Copyright 2011 Alex Merry <dev@randomguy3.me.uk> - * - * 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 the Free Software Foundation; either version 2 of - * the License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see <http://www.gnu.org/licenses/>. - */ - -#import "WidgetSurface.h" -#import "gtkhelpers.h" -#import "InputDelegate.h" -#import "CairoRenderContext.h" - -// {{{ Internal interfaces -// {{{ GTK+ callbacks -static gboolean configure_event_cb (GtkWidget *widget, GdkEventConfigure *event, WidgetSurface *surface); -static void realize_cb (GtkWidget *widget, WidgetSurface *surface); -static gboolean expose_event_cb (GtkWidget *widget, GdkEventExpose *event, WidgetSurface *surface); -static gboolean button_press_event_cb (GtkWidget *widget, GdkEventButton *event, WidgetSurface *surface); -static gboolean button_release_event_cb (GtkWidget *widget, GdkEventButton *event, WidgetSurface *surface); -static gboolean motion_notify_event_cb (GtkWidget *widget, GdkEventMotion *event, WidgetSurface *surface); -static gboolean key_press_event_cb (GtkWidget *widget, GdkEventKey *event, WidgetSurface *surface); -static gboolean key_release_event_cb (GtkWidget *widget, GdkEventKey *event, WidgetSurface *surface); -static gboolean scroll_event_cb (GtkWidget *widget, GdkEventScroll *event, WidgetSurface *surface); -// }}} - -@interface WidgetSurface (Private) -- (void) updateTransformer; -- (void) widgetSizeChanged:(NSNotification*)notification; -- (void) handleExposeEvent:(GdkEventExpose*)event; -- (void) updateLastKnownSize; -- (void) zoomTo:(CGFloat)scale aboutPoint:(NSPoint)p; -- (void) zoomTo:(CGFloat)scale; -- (void) addToEventMask:(GdkEventMask)values; -- (void) removeFromEventMask:(GdkEventMask)values; -@end -// }}} -// {{{ API -@implementation WidgetSurface - -- (id) init { - return [self initWithWidget:gtk_drawing_area_new ()]; -} - -- (id) initWithWidget:(GtkWidget*)w { - self = [super init]; - - if (self) { - widget = w; - g_object_ref_sink (G_OBJECT (widget)); - defaultScale = 1.0f; - transformer = [[Transformer alloc] init]; - [transformer setFlippedAboutXAxis:YES]; - [self updateLastKnownSize]; - g_object_set (G_OBJECT (widget), "events", GDK_STRUCTURE_MASK, NULL); - g_signal_connect (widget, "expose-event", G_CALLBACK (expose_event_cb), self); - g_signal_connect (widget, "configure-event", G_CALLBACK (configure_event_cb), self); - g_signal_connect (widget, "realize", G_CALLBACK (realize_cb), self); - g_signal_connect (widget, "button-press-event", G_CALLBACK (button_press_event_cb), self); - g_signal_connect (widget, "button-release-event", G_CALLBACK (button_release_event_cb), self); - g_signal_connect (widget, "motion-notify-event", G_CALLBACK (motion_notify_event_cb), self); - g_signal_connect (widget, "key-press-event", G_CALLBACK (key_press_event_cb), self); - g_signal_connect (widget, "key-release-event", G_CALLBACK (key_release_event_cb), self); - g_signal_connect (widget, "scroll-event", G_CALLBACK (scroll_event_cb), self); - [[NSNotificationCenter defaultCenter] addObserver:self - selector:@selector(widgetSizeChanged:) - name:@"SurfaceSizeChanged" - object:self]; - if ([self canFocus]) { - [self addToEventMask:GDK_BUTTON_PRESS_MASK]; - } else { - [self removeFromEventMask:GDK_BUTTON_PRESS_MASK]; - } - } - - return self; -} - -- (void) dealloc { - [[NSNotificationCenter defaultCenter] removeObserver:self]; - [transformer release]; - g_object_unref (G_OBJECT (widget)); - - [super dealloc]; -} - -- (void) invalidateRect:(NSRect)rect { - if (!NSIsEmptyRect (rect)) { - GdkWindow *window = gtk_widget_get_window (widget); - if (window) { - GdkRectangle g_rect = gdk_rectangle_from_ns_rect (rect); - gdk_window_invalidate_rect (window, &g_rect, TRUE); - } - } -} - -- (void) invalidate { - GdkWindow *window = gtk_widget_get_window (widget); - if (window) { - GdkRegion *visible = gdk_drawable_get_visible_region (GDK_DRAWABLE (window)); - gdk_window_invalidate_region (window, visible, TRUE); - gdk_region_destroy (visible); - } -} - -- (id<RenderContext>) createRenderContext { - return [CairoRenderContext contextForWidget:widget]; -} - -- (int) width { - int width = 0; - GdkWindow *window = gtk_widget_get_window (widget); - if (window) { - gdk_drawable_get_size (window, &width, NULL); - } - return width; -} - -- (int) height { - int height = 0; - GdkWindow *window = gtk_widget_get_window (widget); - if (window) { - gdk_drawable_get_size (window, NULL, &height); - } - return height; -} - -- (void) setSizeRequestWidth:(double)width height:(double)height { - gtk_widget_set_size_request (widget, width, height); -} - -- (Transformer*) transformer { - return transformer; -} - -- (GtkWidget*) widget { - return widget; -} - -- (void) setRenderDelegate:(id <RenderDelegate>)delegate { - // NB: no retention! - renderDelegate = delegate; - if (renderDelegate == nil) { - [self removeFromEventMask:GDK_EXPOSURE_MASK]; - } else { - [self addToEventMask:GDK_EXPOSURE_MASK]; - } -} - -- (id<InputDelegate>) inputDelegate { - return inputDelegate; -} - -- (void) setInputDelegate:(id<InputDelegate>)delegate { - if (delegate == inputDelegate) { - return; - } - buttonPressesRequired = NO; - if (inputDelegate != nil) { - [self removeFromEventMask:GDK_POINTER_MOTION_MASK - | GDK_BUTTON_PRESS_MASK - | GDK_BUTTON_RELEASE_MASK - | GDK_KEY_PRESS_MASK - | GDK_KEY_RELEASE_MASK]; - } - inputDelegate = delegate; - if (delegate != nil) { - GdkEventMask mask = 0; - if ([delegate respondsToSelector:@selector(mousePressAt:withButton:andMask:)]) { - buttonPressesRequired = YES; - mask |= GDK_BUTTON_PRESS_MASK; - } - if ([delegate respondsToSelector:@selector(mouseReleaseAt:withButton:andMask:)]) { - mask |= GDK_BUTTON_RELEASE_MASK; - } - if ([delegate respondsToSelector:@selector(mouseDoubleClickAt:withButton:andMask:)]) { - buttonPressesRequired = YES; - mask |= GDK_BUTTON_PRESS_MASK; - } - if ([delegate respondsToSelector:@selector(mouseMoveTo:withButtons:andMask:)]) { - mask |= GDK_POINTER_MOTION_MASK; - } - if ([delegate respondsToSelector:@selector(keyPressed:withMask:)]) { - mask |= GDK_KEY_PRESS_MASK; - } - if ([delegate respondsToSelector:@selector(keyReleased:withMask:)]) { - mask |= GDK_KEY_RELEASE_MASK; - } - [self addToEventMask:mask]; - } -} - -- (id <RenderDelegate>) renderDelegate { - return renderDelegate; -} - -- (void) setKeepCentered:(BOOL)centered { - keepCentered = centered; - [self updateTransformer]; -} - -- (BOOL) keepCentered { - return keepCentered; -} - -- (BOOL) canFocus { - return gtk_widget_get_can_focus (widget); -} - -- (void) setCanFocus:(BOOL)focus { - gtk_widget_set_can_focus (widget, focus); - if (focus) { - [self addToEventMask:GDK_BUTTON_PRESS_MASK]; - } else if (!buttonPressesRequired) { - [self removeFromEventMask:GDK_BUTTON_PRESS_MASK]; - } -} - -- (BOOL) hasFocus { - return gtk_widget_has_focus (widget); -} - -- (void) renderFocus { - GdkWindow *window = gtk_widget_get_window (widget); - if (window) { - int width = 0; - int height = 0; - gdk_drawable_get_size (window, &width, &height); - gtk_paint_focus (gtk_widget_get_style (widget), - window, - GTK_STATE_NORMAL, - NULL, - widget, - NULL, - 0, - 0, - width, - height - ); - } -} - -- (CGFloat) defaultScale { - return defaultScale; -} - -- (void) setDefaultScale:(CGFloat)newDefault { - if (defaultScale != newDefault) { - CGFloat oldDefault = defaultScale; - defaultScale = newDefault; - - CGFloat scale = [transformer scale]; - scale *= (newDefault / oldDefault); - [transformer setScale:scale]; - [self invalidate]; - } -} - -- (void) zoomIn { - CGFloat scale = [transformer scale]; - scale *= 1.2f; - [self zoomTo:scale]; -} - -- (void) zoomOut { - CGFloat scale = [transformer scale]; - scale /= 1.2f; - [self zoomTo:scale]; -} - -- (void) zoomReset { - [self zoomTo:defaultScale]; -} - -- (void) zoomInAboutPoint:(NSPoint)p { - CGFloat scale = [transformer scale]; - scale *= 1.2f; - [self zoomTo:scale aboutPoint:p]; -} - -- (void) zoomOutAboutPoint:(NSPoint)p { - CGFloat scale = [transformer scale]; - scale /= 1.2f; - [self zoomTo:scale aboutPoint:p]; -} - -- (void) zoomResetAboutPoint:(NSPoint)p { - [self zoomTo:defaultScale aboutPoint:p]; -} - -- (void) setCursor:(Cursor)c { - GdkWindow *window = gtk_widget_get_window (widget); - GdkCursor *cursor = NULL; - switch (c) { - case ResizeRightCursor: - cursor = gdk_cursor_new (GDK_RIGHT_SIDE); - break; - case ResizeBottomRightCursor: - cursor = gdk_cursor_new (GDK_BOTTOM_RIGHT_CORNER); - break; - case ResizeBottomCursor: - cursor = gdk_cursor_new (GDK_BOTTOM_SIDE); - break; - case ResizeBottomLeftCursor: - cursor = gdk_cursor_new (GDK_BOTTOM_LEFT_CORNER); - break; - case ResizeLeftCursor: - cursor = gdk_cursor_new (GDK_LEFT_SIDE); - break; - case ResizeTopLeftCursor: - cursor = gdk_cursor_new (GDK_TOP_LEFT_CORNER); - break; - case ResizeTopCursor: - cursor = gdk_cursor_new (GDK_TOP_SIDE); - break; - case ResizeTopRightCursor: - cursor = gdk_cursor_new (GDK_TOP_RIGHT_CORNER); - break; - default: break; - } - gdk_window_set_cursor (window, cursor); - if (cursor != NULL) { - gdk_cursor_unref (cursor); - } -} - -@end -// }}} -// {{{ Private -@implementation WidgetSurface (Private) -- (void) widgetSizeChanged:(NSNotification*)notification { - [self updateTransformer]; - [self updateLastKnownSize]; -} - -- (void) updateTransformer { - if (keepCentered) { - GdkWindow *window = gtk_widget_get_window (widget); - if (window) { - int width = 0; - int height = 0; - gdk_drawable_get_size (window, &width, &height); - NSPoint origin; - if (lastKnownSize.width < 1 || lastKnownSize.height < 1) { - origin.x = (float)width / 2.0f; - origin.y = (float)height / 2.0f; - } else { - origin = [transformer origin]; - origin.x += ((float)width - lastKnownSize.width) / 2.0f; - origin.y += ((float)height - lastKnownSize.height) / 2.0f; - } - [transformer setOrigin:origin]; - } - } -} - -- (void) handleExposeEvent:(GdkEventExpose*)event { - if (renderDelegate != nil) { - NSRect area = gdk_rectangle_to_ns_rect (event->area); - - id<RenderContext> context = [CairoRenderContext contextForWidget:widget]; - [context rect:area]; - [context clipToPath]; - [renderDelegate renderWithContext:context onSurface:self]; - } -} - -- (void) updateLastKnownSize { - GdkWindow *window = gtk_widget_get_window (widget); - if (window) { - int width = 0; - int height = 0; - gdk_drawable_get_size (window, &width, &height); - lastKnownSize.width = (float)width; - lastKnownSize.height = (float)height; - } else { - lastKnownSize = NSZeroSize; - } -} - -- (void) zoomTo:(CGFloat)scale aboutPoint:(NSPoint)p { - NSPoint graphP = [transformer fromScreen:p]; - - [transformer setScale:scale]; - - NSPoint newP = [transformer toScreen:graphP]; - NSPoint origin = [transformer origin]; - origin.x += p.x - newP.x; - origin.y += p.y - newP.y; - [transformer setOrigin:origin]; - - [self invalidate]; -} - -- (void) zoomTo:(CGFloat)scale { - NSPoint centre = NSMakePoint (lastKnownSize.width/2.0f, lastKnownSize.height/2.0f); - [self zoomTo:scale aboutPoint:centre]; -} - -- (void) addToEventMask:(GdkEventMask)values { - GdkEventMask mask; - g_object_get (G_OBJECT (widget), "events", &mask, NULL); - mask |= values; - g_object_set (G_OBJECT (widget), "events", mask, NULL); -} - -- (void) removeFromEventMask:(GdkEventMask)values { - GdkEventMask mask; - g_object_get (G_OBJECT (widget), "events", &mask, NULL); - mask ^= values; - if (buttonPressesRequired || [self canFocus]) { - mask |= GDK_BUTTON_PRESS_MASK; - } - g_object_set (G_OBJECT (widget), "events", mask, NULL); -} - -@end -// }}} -// {{{ GTK+ callbacks -static gboolean configure_event_cb(GtkWidget *widget, GdkEventConfigure *event, WidgetSurface *surface) { - NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init]; - [[NSNotificationCenter defaultCenter] postNotificationName:@"SurfaceSizeChanged" object:surface]; - [pool drain]; - return FALSE; -} - -static void realize_cb (GtkWidget *widget, WidgetSurface *surface) { - NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init]; - [surface updateTransformer]; - [pool drain]; -} - -static gboolean expose_event_cb(GtkWidget *widget, GdkEventExpose *event, WidgetSurface *surface) { - NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init]; - [surface handleExposeEvent:event]; - [pool drain]; - return FALSE; -} - -InputMask mask_from_gdk_modifier_state (GdkModifierType state) { - InputMask mask = 0; - if (state & GDK_SHIFT_MASK) { - mask |= ShiftMask; - } - if (state & GDK_CONTROL_MASK) { - mask |= ControlMask; - } - if (state & GDK_META_MASK) { - mask |= MetaMask; - } - return mask; -} - -ScrollDirection scroll_dir_from_gdk_scroll_dir (GdkScrollDirection dir) { - switch (dir) { - case GDK_SCROLL_UP: return ScrollUp; - case GDK_SCROLL_DOWN: return ScrollDown; - case GDK_SCROLL_LEFT: return ScrollLeft; - case GDK_SCROLL_RIGHT: return ScrollRight; - default: NSLog(@"Invalid scroll direction %i", (int)dir); return ScrollDown; - } -} - -MouseButton buttons_from_gdk_modifier_state (GdkModifierType state) { - MouseButton buttons = 0; - if (state & GDK_BUTTON1_MASK) { - buttons |= LeftButton; - } - if (state & GDK_BUTTON2_MASK) { - buttons |= MiddleButton; - } - if (state & GDK_BUTTON3_MASK) { - buttons |= RightButton; - } - if (state & GDK_BUTTON4_MASK) { - buttons |= Button4; - } - if (state & GDK_BUTTON5_MASK) { - buttons |= Button5; - } - return buttons; -} - -static gboolean button_press_event_cb(GtkWidget *widget, GdkEventButton *event, WidgetSurface *surface) { - NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init]; - - if ([surface canFocus]) { - if (!gtk_widget_has_focus (widget)) { - gtk_widget_grab_focus (widget); - } - } - - id<InputDelegate> delegate = [surface inputDelegate]; - if (delegate != nil) { - NSPoint pos = NSMakePoint (event->x, event->y); - MouseButton button = (MouseButton)event->button; - InputMask mask = mask_from_gdk_modifier_state (event->state); - if (event->type == GDK_BUTTON_PRESS && [delegate respondsToSelector:@selector(mousePressAt:withButton:andMask:)]) { - [delegate mousePressAt:pos withButton:button andMask:mask]; - } - if (event->type == GDK_2BUTTON_PRESS && [delegate respondsToSelector:@selector(mouseDoubleClickAt:withButton:andMask:)]) { - [delegate mouseDoubleClickAt:pos withButton:button andMask:mask]; - } - } - - [pool drain]; - return FALSE; -} - -static gboolean button_release_event_cb(GtkWidget *widget, GdkEventButton *event, WidgetSurface *surface) { - NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init]; - - id<InputDelegate> delegate = [surface inputDelegate]; - if (delegate != nil) { - if ([delegate respondsToSelector:@selector(mouseReleaseAt:withButton:andMask:)]) { - NSPoint pos = NSMakePoint (event->x, event->y); - MouseButton button = (MouseButton)event->button; - InputMask mask = mask_from_gdk_modifier_state (event->state); - [delegate mouseReleaseAt:pos withButton:button andMask:mask]; - } - } - - [pool drain]; - return FALSE; -} - -static gboolean motion_notify_event_cb(GtkWidget *widget, GdkEventMotion *event, WidgetSurface *surface) { - NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init]; - - id<InputDelegate> delegate = [surface inputDelegate]; - if (delegate != nil) { - if ([delegate respondsToSelector:@selector(mouseMoveTo:withButtons:andMask:)]) { - NSPoint pos = NSMakePoint (event->x, event->y); - MouseButton buttons = buttons_from_gdk_modifier_state (event->state); - InputMask mask = mask_from_gdk_modifier_state (event->state); - [delegate mouseMoveTo:pos withButtons:buttons andMask:mask]; - } - } - - [pool drain]; - return FALSE; -} - -static gboolean key_press_event_cb(GtkWidget *widget, GdkEventKey *event, WidgetSurface *surface) { - NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init]; - - id<InputDelegate> delegate = [surface inputDelegate]; - if (delegate != nil) { - if ([delegate respondsToSelector:@selector(keyPressed:withMask:)]) { - InputMask mask = mask_from_gdk_modifier_state (event->state); - [delegate keyPressed:event->keyval withMask:mask]; - } - } - - [pool drain]; - return FALSE; -} - -static gboolean key_release_event_cb(GtkWidget *widget, GdkEventKey *event, WidgetSurface *surface) { - NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init]; - - id<InputDelegate> delegate = [surface inputDelegate]; - if (delegate != nil) { - if ([delegate respondsToSelector:@selector(keyReleased:withMask:)]) { - InputMask mask = mask_from_gdk_modifier_state (event->state); - [delegate keyReleased:event->keyval withMask:mask]; - } - } - - [pool drain]; - return FALSE; -} - -static gboolean scroll_event_cb (GtkWidget *widget, GdkEventScroll *event, WidgetSurface *surface) { - NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init]; - - id<InputDelegate> delegate = [surface inputDelegate]; - if (delegate != nil) { - if ([delegate respondsToSelector:@selector(mouseScrolledAt:inDirection:withMask:)]) { - NSPoint pos = NSMakePoint (event->x, event->y); - InputMask mask = mask_from_gdk_modifier_state (event->state); - ScrollDirection dir = scroll_dir_from_gdk_scroll_dir (event->direction); - [delegate mouseScrolledAt:pos - inDirection:dir - withMask:mask]; - } - } - - [pool drain]; - return FALSE; -} -// }}} - -// vim:ft=objc:ts=8:et:sts=4:sw=4:foldmethod=marker diff --git a/tikzit/src/gtk/Window.h b/tikzit/src/gtk/Window.h deleted file mode 100644 index a3ce8a4..0000000 --- a/tikzit/src/gtk/Window.h +++ /dev/null @@ -1,182 +0,0 @@ -/* - * Copyright 2011-2012 Alex Merry <dev@randomguy3.me.uk> - * - * 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 the Free Software Foundation; either version 2 of - * the License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see <http://www.gnu.org/licenses/>. - */ - -#import "TZFoundation.h" -#import <gtk/gtk.h> - -@class GraphEditorPanel; -@class Menu; -@class PropertyPane; -@class Preambles; -@class PreambleEditor; -@class PreviewWindow; -@class SettingsDialog; -@class StyleManager; -@class StylesPane; -@class TikzDocument; -@protocol Tool; - -/** - * Manages a document window - */ -@interface Window: NSObject { - // GTK+ widgets - GtkWindow *window; - GtkTextBuffer *tikzBuffer; - GtkStatusbar *statusBar; - GtkPaned *tikzPaneSplitter; - GtkWidget *tikzPane; - - gulong clipboard_handler_id; - GtkTextTag *errorHighlightTag; // owned by tikzBuffer - - // Classes that manage parts of the window - Menu *menu; - GraphEditorPanel *graphPanel; - - PreviewWindow *previewWindow; - - // state variables - BOOL suppressTikzUpdates; - BOOL hasParseError; - - // the document displayed by the window - TikzDocument *document; -} - -/** - * The document displayed by the window - */ -@property (retain) TikzDocument *document; -@property (readonly) BOOL hasFocus; -@property (readonly) GtkWindow *gtkWindow; - -/** - * Create a window with an empty document - */ -- (id) init; -+ (id) window; - -/** - * Create a window with the given document - */ -- (id) initWithDocument:(TikzDocument*)doc; -+ (id) windowWithDocument:(TikzDocument*)doc; - -/** - * Present the window to the user - */ -- (void) present; - -/** - * Open a file, asking the user which file to open - */ -- (void) openFile; -/** - * Open a file - */ -- (BOOL) openFileAtPath:(NSString*)path; -/** - * Save the active document to the path it was opened from - * or last saved to, or ask the user where to save it. - */ -- (BOOL) saveActiveDocument; -/** - * Save the active document, asking the user where to save it. - */ -- (BOOL) saveActiveDocumentAs; -/** - * Save the active document as a shape, asking the user what to name it. - */ -- (void) saveActiveDocumentAsShape; - -/** - * Close the window. - * - * May terminate the application if this is the last window. - * - * Will ask for user confirmation if the document is not saved. - */ -- (void) close; - -/** - * Cut the current selection to the clipboard. - */ -- (void) selectionCutToClipboard; -/** - * Copy the current selection to the clipboard. - */ -- (void) selectionCopyToClipboard; -/** - * Paste from the clipboard to the appropriate place. - */ -- (void) pasteFromClipboard; - -/** - * The GTK+ window that this class manages. - */ -- (GtkWindow*) gtkWindow; -/** - * The menu for the window. - */ -- (Menu*) menu; - -/** - * Present an error to the user - * - * @param error the error to present - */ -- (void) presentError:(NSError*)error; -/** - * Present an error to the user - * - * @param error the error to present - * @param message a message to display with the error - */ -- (void) presentError:(NSError*)error withMessage:(NSString*)message; -/** - * Present an error to the user - * - * @param error the error to present - */ -- (void) presentGError:(GError*)error; -/** - * Present an error to the user - * - * @param error the error to present - * @param message a message to display with the error - */ -- (void) presentGError:(GError*)error withMessage:(NSString*)message; - -- (void) setActiveTool:(id<Tool>)tool; - -- (void) zoomIn; -- (void) zoomOut; -- (void) zoomReset; - -/** - * Show or update the preview window. - */ -- (void) presentPreview; -/** - * Show or update the preview window without it grabbing focus - */ -- (void) updatePreview; - -@end - -// vim:ft=objc:ts=8:et:sts=4:sw=4 diff --git a/tikzit/src/gtk/Window.m b/tikzit/src/gtk/Window.m deleted file mode 100644 index 7cb1e65..0000000 --- a/tikzit/src/gtk/Window.m +++ /dev/null @@ -1,975 +0,0 @@ -/* - * Copyright 2011-2012 Alex Merry <dev@randomguy3.me.uk> - * - * 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 the Free Software Foundation; either version 2 of - * the License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see <http://www.gnu.org/licenses/>. - */ - -#import "Window.h" - -#import <gtk/gtk.h> -#import "gtkhelpers.h" -#import "clipboard.h" - -#import "Application.h" -#import "Configuration.h" -#import "FileChooserDialog.h" -#import "GraphEditorPanel.h" -#import "Menu.h" -#import "RecentManager.h" -#import "Shape.h" -#import "SupportDir.h" -#import "TikzDocument.h" - -#ifdef HAVE_POPPLER -#import "PreviewWindow.h" -#endif - -enum { - GraphInfoStatus, - ParseStatus -}; - -// {{{ Internal interfaces -// {{{ Clipboard support - -static void clipboard_provide_data (GtkClipboard *clipboard, - GtkSelectionData *selection_data, - guint info, - gpointer clipboard_graph_data); -static void clipboard_release_data (GtkClipboard *clipboard, gpointer clipboard_graph_data); -static void clipboard_check_targets (GtkClipboard *clipboard, - GdkAtom *atoms, - gint n_atoms, - gpointer action); -static void clipboard_paste_contents (GtkClipboard *clipboard, - GtkSelectionData *selection_data, - gpointer document); - -// }}} -// {{{ Signals - -static void window_toplevel_focus_changed_cb (GObject *gobject, GParamSpec *pspec, Window *window); -static void graph_divider_position_changed_cb (GObject *gobject, GParamSpec *pspec, Window *window); -static void tikz_buffer_changed_cb (GtkTextBuffer *buffer, Window *window); -static gboolean main_window_delete_event_cb (GtkWidget *widget, GdkEvent *event, Window *window); -static void main_window_destroy_cb (GtkWidget *widget, Window *window); -static gboolean main_window_configure_event_cb (GtkWidget *widget, GdkEventConfigure *event, Window *window); -static void update_paste_action (GtkClipboard *clipboard, GdkEvent *event, GtkAction *action); - -// }}} - -@interface Window (Notifications) -- (void) tikzBufferChanged; -- (void) windowSizeChangedWidth:(int)width height:(int)height; -- (void) documentTikzChanged:(NSNotification*)notification; -- (void) documentSelectionChanged:(NSNotification*)notification; -- (void) undoStackChanged:(NSNotification*)notification; -@end - -@interface Window (InitHelpers) -- (void) _loadUi; -- (void) _restoreUiState; -- (void) _connectSignals; -@end - -@interface Window (Private) <PreviewHandler> -- (BOOL) _askCanClose; -/** Open a document, dealing with errors as necessary */ -- (TikzDocument*) _openDocument:(NSString*)path; -- (void) _placeGraphOnClipboard:(Graph*)graph; -- (void) _clearParseError; -- (void) _setParseError:(NSError*)error; -/** Update the window title. */ -- (void) _updateTitle; -/** Update the window status bar default text. */ -- (void) _updateStatus; -/** Update the displayed tikz code to match the active document. */ -- (void) _updateTikz; -/** Update the undo and redo actions to match the active document's - * undo stack. */ -- (void) _updateUndoActions; -- (void) showPreview; -@end - -// }}} -// {{{ API - -@implementation Window - -@synthesize gtkWindow=window; - -- (id) init { - return [self initWithDocument:[TikzDocument documentWithStyleManager:[app styleManager]]]; -} -+ (id) window { - return [[[self alloc] init] autorelease]; -} -- (id) initWithDocument:(TikzDocument*)doc { - self = [super init]; - - if (self) { - [self _loadUi]; - [self _restoreUiState]; - [self _connectSignals]; - - [self setDocument:doc]; - - gtk_widget_show (GTK_WIDGET (window)); - } - - return self; -} -+ (id) windowWithDocument:(TikzDocument*)doc { - return [[[self alloc] initWithDocument:doc] autorelease]; -} - -- (void) dealloc { - // The GTK+ window has already been destroyed at this point - - [[NSNotificationCenter defaultCenter] removeObserver:self]; - g_signal_handler_disconnect ( - gtk_clipboard_get (GDK_SELECTION_CLIPBOARD), - clipboard_handler_id); - - [previewWindow release]; - [menu release]; - [graphPanel release]; - [document release]; - - g_object_unref (tikzBuffer); - g_object_unref (tikzPane); - g_object_unref (tikzPaneSplitter); - g_object_unref (statusBar); - g_object_unref (window); - - [super dealloc]; -} - -- (TikzDocument*) document { - return document; -} -- (void) setDocument:(TikzDocument*)newDoc { - [[NSNotificationCenter defaultCenter] removeObserver:self name:nil object:[document pickSupport]]; - [[NSNotificationCenter defaultCenter] removeObserver:self name:nil object:document]; - - TikzDocument *oldDoc = document; - document = [newDoc retain]; - - [graphPanel setDocument:document]; - [previewWindow setDocument:document]; - [self _updateTikz]; - [self _updateTitle]; - [self _updateStatus]; - [self _updateUndoActions]; - [menu notifySelectionChanged:[document pickSupport]]; - [[NSNotificationCenter defaultCenter] addObserver:self - selector:@selector(documentTikzChanged:) - name:@"TikzChanged" object:document]; - [[NSNotificationCenter defaultCenter] addObserver:self - selector:@selector(undoStackChanged:) - name:@"UndoStackChanged" object:document]; - [[NSNotificationCenter defaultCenter] addObserver:self - selector:@selector(documentSelectionChanged:) - name:@"NodeSelectionChanged" object:[document pickSupport]]; - [[NSNotificationCenter defaultCenter] addObserver:self - selector:@selector(documentSelectionChanged:) - name:@"EdgeSelectionChanged" object:[document pickSupport]]; - - if ([document path] != nil) { - [[RecentManager defaultManager] addRecentFile:[document path]]; - } - - NSDictionary *userInfo; - userInfo = [NSDictionary dictionaryWithObjectsAndKeys: - document, @"document", - oldDoc, @"oldDocument", - nil]; - [[NSNotificationCenter defaultCenter] - postNotificationName:@"DocumentChanged" - object:self - userInfo:userInfo]; - [oldDoc release]; -} - -- (BOOL) hasFocus { - return gtk_window_has_toplevel_focus (GTK_WINDOW (window)); -} - -- (void) present { - gtk_window_present (GTK_WINDOW (window)); -} - -- (void) openFile { - FileChooserDialog *dialog = [FileChooserDialog openDialogWithParent:window]; - [dialog addStandardFilters]; - if ([document path]) { - [dialog setCurrentFolder:[[document path] stringByDeletingLastPathComponent]]; - } else if ([app lastOpenFolder]) { - [dialog setCurrentFolder:[app lastOpenFolder]]; - } - - if ([dialog showDialog]) { - if ([self openFileAtPath:[dialog filePath]]) { - [app setLastOpenFolder:[dialog currentFolder]]; - } - } - [dialog destroy]; -} - -- (BOOL) openFileAtPath:(NSString*)path { - TikzDocument *doc = [self _openDocument:path]; - if (doc != nil) { - if (![document hasUnsavedChanges] && [document path] == nil) { - // we just have a fresh, untitled document - replace it - [self setDocument:doc]; - } else { - [app newWindowWithDocument:doc]; - } - return YES; - } - return NO; -} - -- (BOOL) saveActiveDocument { - if ([document path] == nil) { - return [self saveActiveDocumentAs]; - } else { - NSError *error = nil; - if (![document save:&error]) { - [self presentError:error]; - return NO; - } else { - [self _updateTitle]; - return YES; - } - } -} - -- (BOOL) saveActiveDocumentAs { - FileChooserDialog *dialog = [FileChooserDialog saveDialogWithParent:window]; - [dialog addStandardFilters]; - if ([document path] != nil) { - [dialog setCurrentFolder:[[document path] stringByDeletingLastPathComponent]]; - } else if ([app lastSaveAsFolder] != nil) { - [dialog setCurrentFolder:[app lastSaveAsFolder]]; - } - [dialog setSuggestedName:[document suggestedFileName]]; - - BOOL saved = NO; - if ([dialog showDialog]) { - NSString *nfile = [dialog filePath]; - - NSError *error = nil; - if (![document saveToPath:nfile error:&error]) { - [self presentError:error]; - } else { - [self _updateTitle]; - [[RecentManager defaultManager] addRecentFile:nfile]; - [app setLastSaveAsFolder:[dialog currentFolder]]; - saved = YES; - } - } - [dialog destroy]; - return saved; -} - -- (void) saveActiveDocumentAsShape { - GtkWidget *dialog = gtk_dialog_new_with_buttons ( - "Save as shape", - window, - GTK_DIALOG_MODAL, - GTK_STOCK_OK, - GTK_RESPONSE_ACCEPT, - GTK_STOCK_CANCEL, - GTK_RESPONSE_REJECT, - NULL); - GtkBox *content = GTK_BOX (gtk_dialog_get_content_area (GTK_DIALOG (dialog))); - GtkWidget *label1 = gtk_label_new ("Please choose a name for the shape"); - GtkWidget *label2 = gtk_label_new ("Name:"); - GtkWidget *input = gtk_entry_new (); - GtkBox *hbox = GTK_BOX (gtk_hbox_new (FALSE, 5)); - gtk_box_pack_start (hbox, label2, FALSE, TRUE, 0); - gtk_box_pack_start (hbox, input, TRUE, TRUE, 0); - gtk_box_pack_start (content, label1, TRUE, TRUE, 5); - gtk_box_pack_start (content, GTK_WIDGET (hbox), TRUE, TRUE, 5); - gtk_widget_show_all (GTK_WIDGET (content)); - gint response = gtk_dialog_run (GTK_DIALOG (dialog)); - while (response == GTK_RESPONSE_ACCEPT) { - response = GTK_RESPONSE_NONE; - NSDictionary *shapeDict = [Shape shapeDictionary]; - const gchar *dialogInput = gtk_entry_get_text (GTK_ENTRY (input)); - NSString *shapeName = [NSString stringWithUTF8String:dialogInput]; - BOOL doSave = NO; - if ([shapeName isEqual:@""]) { - GtkWidget *emptyStrDialog = gtk_message_dialog_new (window, - GTK_DIALOG_DESTROY_WITH_PARENT, - GTK_MESSAGE_ERROR, - GTK_BUTTONS_CLOSE, - "You must specify a shape name"); - gtk_dialog_run (GTK_DIALOG (emptyStrDialog)); - gtk_widget_destroy (emptyStrDialog); - response = gtk_dialog_run (GTK_DIALOG (dialog)); - } else if ([shapeDict objectForKey:shapeName] != nil) { - GtkWidget *overwriteDialog = gtk_message_dialog_new (window, - GTK_DIALOG_DESTROY_WITH_PARENT, - GTK_MESSAGE_QUESTION, - GTK_BUTTONS_YES_NO, - "Do you want to replace the existing shape named '%s'?", - dialogInput); - gint overwriteResp = gtk_dialog_run (GTK_DIALOG (overwriteDialog)); - gtk_widget_destroy (overwriteDialog); - - if (overwriteResp == GTK_RESPONSE_YES) { - doSave = YES; - } else { - response = gtk_dialog_run (GTK_DIALOG (dialog)); - } - } else { - doSave = YES; - } - if (doSave) { - NSError *error = nil; - NSString *userShapeDir = [[SupportDir userSupportDir] stringByAppendingPathComponent:@"shapes"]; - NSString *file = [NSString stringWithFormat:@"%@/%@.tikz", userShapeDir, shapeName]; - if (![[NSFileManager defaultManager] ensureDirectoryExists:userShapeDir error:&error]) { - [self presentError:error withMessage:@"Could not create user shape directory"]; - } else { - if (![document saveCopyToPath:file error:&error]) { - [self presentError:error withMessage:@"Could not save shape file"]; - } else { - [Shape refreshShapeDictionary]; - } - } - } - } - gtk_widget_destroy (dialog); -} - -- (void) close { - if ([self _askCanClose]) { - gtk_widget_destroy (GTK_WIDGET (window)); - } -} - -- (void) selectionCutToClipboard { - if ([[[document pickSupport] selectedNodes] count] > 0) { - [self _placeGraphOnClipboard:[document selectionCut]]; - } -} - -- (void) selectionCopyToClipboard { - if ([[[document pickSupport] selectedNodes] count] > 0) { - [self _placeGraphOnClipboard:[document selectionCopy]]; - } -} - -- (void) pasteFromClipboard { - gtk_clipboard_request_contents (gtk_clipboard_get (GDK_SELECTION_CLIPBOARD), - tikzit_picture_atom, - clipboard_paste_contents, - document); -} - -- (GtkWindow*) gtkWindow { - return window; -} - -- (Configuration*) mainConfiguration { - return [app mainConfiguration]; -} - -- (Menu*) menu { - return menu; -} - -- (void) presentError:(NSError*)error { - GtkWidget *dialog = gtk_message_dialog_new (window, - GTK_DIALOG_DESTROY_WITH_PARENT, - GTK_MESSAGE_ERROR, - GTK_BUTTONS_CLOSE, - "%s", - [[error localizedDescription] UTF8String]); - gtk_dialog_run (GTK_DIALOG (dialog)); - gtk_widget_destroy (dialog); -} - -- (void) presentError:(NSError*)error withMessage:(NSString*)message { - GtkWidget *dialog = gtk_message_dialog_new (window, - GTK_DIALOG_DESTROY_WITH_PARENT, - GTK_MESSAGE_ERROR, - GTK_BUTTONS_CLOSE, - "%s: %s", - [message UTF8String], - [[error localizedDescription] UTF8String]); - gtk_dialog_run (GTK_DIALOG (dialog)); - gtk_widget_destroy (dialog); -} - -- (void) presentGError:(GError*)error { - GtkWidget *dialog = gtk_message_dialog_new (window, - GTK_DIALOG_DESTROY_WITH_PARENT, - GTK_MESSAGE_ERROR, - GTK_BUTTONS_CLOSE, - "%s", - error->message); - gtk_dialog_run (GTK_DIALOG (dialog)); - gtk_widget_destroy (dialog); -} - -- (void) presentGError:(GError*)error withMessage:(NSString*)message { - GtkWidget *dialog = gtk_message_dialog_new (window, - GTK_DIALOG_DESTROY_WITH_PARENT, - GTK_MESSAGE_ERROR, - GTK_BUTTONS_CLOSE, - "%s: %s", - [message UTF8String], - error->message); - gtk_dialog_run (GTK_DIALOG (dialog)); - gtk_widget_destroy (dialog); -} - -- (void) setActiveTool:(id<Tool>)tool { - [graphPanel setActiveTool:tool]; - gboolean hasfocus; - g_object_get (G_OBJECT (window), "has-toplevel-focus", &hasfocus, NULL); - if (hasfocus) { - [graphPanel grabTool]; - } -} - -- (void) zoomIn { - [graphPanel zoomIn]; -} - -- (void) zoomOut { - [graphPanel zoomOut]; -} - -- (void) zoomReset { - [graphPanel zoomReset]; -} - -- (void) presentPreview { -#ifdef HAVE_POPPLER - if (previewWindow == nil) { - previewWindow = [[PreviewWindow alloc] initWithPreambles:[app preambles] - config:[app mainConfiguration]]; - //[previewWindow setParentWindow:self]; - [previewWindow setDocument:document]; - } - [previewWindow present]; -#endif -} - -- (void) updatePreview { -#ifdef HAVE_POPPLER - if (previewWindow == nil) { - previewWindow = [[PreviewWindow alloc] initWithPreambles:[app preambles] - config:[app mainConfiguration]]; - //[previewWindow setParentWindow:self]; - [previewWindow setDocument:document]; - } - [previewWindow show]; -#endif -} - -@end - -// }}} -// {{{ Notifications - -@implementation Window (Notifications) -- (void) graphHeightChanged:(int)newHeight { - [[app mainConfiguration] setIntegerEntry:@"graphHeight" - inGroup:@"window" - value:newHeight]; -} - -- (void) tikzBufferChanged { - if (!suppressTikzUpdates) { - suppressTikzUpdates = TRUE; - - GtkTextIter start, end; - gtk_text_buffer_get_bounds (tikzBuffer, &start, &end); - gchar *text = gtk_text_buffer_get_text (tikzBuffer, &start, &end, FALSE); - - NSError *error = nil; - BOOL success = [document updateTikz:[NSString stringWithUTF8String:text] error:&error]; - if (success) - [self _clearParseError]; - else - [self _setParseError:error]; - - g_free (text); - - suppressTikzUpdates = FALSE; - } -} - -- (void) windowSizeChangedWidth:(int)width height:(int)height { - if (width > 0 && height > 0) { - NSNumber *w = [NSNumber numberWithInt:width]; - NSNumber *h = [NSNumber numberWithInt:height]; - NSMutableArray *size = [NSMutableArray arrayWithCapacity:2]; - [size addObject:w]; - [size addObject:h]; - [[app mainConfiguration] setIntegerListEntry:@"windowSize" - inGroup:@"window" - value:size]; - } -} - -- (void) documentTikzChanged:(NSNotification*)notification { - [self _updateTitle]; - [self _updateTikz]; -} - -- (void) documentSelectionChanged:(NSNotification*)notification { - [self _updateStatus]; - [menu notifySelectionChanged:[document pickSupport]]; -} - -- (void) undoStackChanged:(NSNotification*)notification { - [self _updateUndoActions]; -} -@end - -// }}} -// {{{ InitHelpers - -@implementation Window (InitHelpers) - -- (void) _loadUi { - window = GTK_WINDOW (gtk_window_new (GTK_WINDOW_TOPLEVEL)); - g_object_ref_sink (window); - gtk_window_set_title (window, "TikZiT"); - gtk_window_set_default_size (window, 700, 400); - - GtkBox *mainLayout = GTK_BOX (gtk_vbox_new (FALSE, 0)); - gtk_widget_show (GTK_WIDGET (mainLayout)); - gtk_container_add (GTK_CONTAINER (window), GTK_WIDGET (mainLayout)); - - menu = [[Menu alloc] initForWindow:self]; - - GtkWidget *menubar = [menu menubar]; - gtk_box_pack_start (mainLayout, menubar, FALSE, TRUE, 0); - gtk_box_reorder_child (mainLayout, menubar, 0); - gtk_widget_show (menubar); - - tikzPaneSplitter = GTK_PANED (gtk_vpaned_new ()); - g_object_ref_sink (tikzPaneSplitter); - gtk_widget_show (GTK_WIDGET (tikzPaneSplitter)); - gtk_box_pack_start (mainLayout, GTK_WIDGET (tikzPaneSplitter), TRUE, TRUE, 0); - - graphPanel = [[GraphEditorPanel alloc] initWithDocument:document]; - [graphPanel setPreviewHandler:self]; - GtkWidget *graphEditorWidget = [graphPanel widget]; - gtk_widget_show (graphEditorWidget); - GtkWidget *graphFrame = gtk_frame_new (NULL); - gtk_container_add (GTK_CONTAINER (graphFrame), graphEditorWidget); - gtk_widget_show (graphFrame); - gtk_paned_pack1 (tikzPaneSplitter, graphFrame, TRUE, TRUE); - - tikzBuffer = gtk_text_buffer_new (NULL); - g_object_ref_sink (tikzBuffer); - errorHighlightTag = gtk_text_buffer_create_tag ( - tikzBuffer, NULL, - "foreground", "#d40000", - "foreground-set", TRUE, - "weight", PANGO_WEIGHT_SEMIBOLD, - "weight-set", TRUE, - NULL); - GtkWidget *tikzScroller = gtk_scrolled_window_new (NULL, NULL); - gtk_widget_show (tikzScroller); - - tikzPane = gtk_text_view_new_with_buffer (tikzBuffer); - gtk_text_view_set_left_margin (GTK_TEXT_VIEW (tikzPane), 3); - gtk_text_view_set_right_margin (GTK_TEXT_VIEW (tikzPane), 3); - g_object_ref_sink (tikzPane); - gtk_widget_show (tikzPane); - gtk_container_add (GTK_CONTAINER (tikzScroller), tikzPane); - GtkWidget *tikzFrame = gtk_frame_new (NULL); - gtk_container_add (GTK_CONTAINER (tikzFrame), tikzScroller); - gtk_widget_show (tikzFrame); - gtk_paned_pack2 (tikzPaneSplitter, tikzFrame, FALSE, TRUE); - - statusBar = GTK_STATUSBAR (gtk_statusbar_new ()); - g_object_ref_sink (statusBar); - gtk_widget_show (GTK_WIDGET (statusBar)); - gtk_box_pack_start (mainLayout, GTK_WIDGET (statusBar), FALSE, TRUE, 0); - - GtkClipboard *clipboard = gtk_clipboard_get (GDK_SELECTION_CLIPBOARD); - update_paste_action (clipboard, NULL, [menu pasteAction]); -} - -- (void) _restoreUiState { - Configuration *config = [app mainConfiguration]; - NSArray *windowSize = [config integerListEntry:@"windowSize" - inGroup:@"window"]; - if (windowSize && [windowSize count] == 2) { - gint width = [[windowSize objectAtIndex:0] intValue]; - gint height = [[windowSize objectAtIndex:1] intValue]; - if (width > 0 && height > 0) { - gtk_window_set_default_size (window, width, height); - } - } - int panePos = [config integerEntry:@"graphHeight" - inGroup:@"window"]; - if (panePos > 0) { - gtk_paned_set_position (tikzPaneSplitter, panePos); - } -} - -- (void) _connectSignals { - GtkClipboard *clipboard = gtk_clipboard_get (GDK_SELECTION_CLIPBOARD); - clipboard_handler_id = - g_signal_connect (G_OBJECT (clipboard), - "owner-change", - G_CALLBACK (update_paste_action), - [menu pasteAction]); - g_signal_connect (G_OBJECT (window), - "key-press-event", - G_CALLBACK (tz_hijack_key_press), - NULL); - g_signal_connect (G_OBJECT (window), - "notify::has-toplevel-focus", - G_CALLBACK (window_toplevel_focus_changed_cb), - self); - g_signal_connect (G_OBJECT (tikzPaneSplitter), - "notify::position", - G_CALLBACK (graph_divider_position_changed_cb), - self); - g_signal_connect (G_OBJECT (tikzBuffer), - "changed", - G_CALLBACK (tikz_buffer_changed_cb), - self); - g_signal_connect (G_OBJECT (window), - "delete-event", - G_CALLBACK (main_window_delete_event_cb), - self); - g_signal_connect (G_OBJECT (window), - "destroy", - G_CALLBACK (main_window_destroy_cb), - self); - g_signal_connect (G_OBJECT (window), - "configure-event", - G_CALLBACK (main_window_configure_event_cb), - self); -} -@end - -// }}} -// {{{ Private - -@implementation Window (Private) - -- (BOOL) _askCanClose { - if ([document hasUnsavedChanges]) { - GtkWidget *dialog = gtk_message_dialog_new (window, - GTK_DIALOG_DESTROY_WITH_PARENT, - GTK_MESSAGE_QUESTION, - GTK_BUTTONS_NONE, - "Save changes to the document \"%s\" before closing?", - [[document name] UTF8String]); - gtk_dialog_add_buttons (GTK_DIALOG (dialog), - "Save", GTK_RESPONSE_YES, - "Don't save", GTK_RESPONSE_NO, - "Cancel", GTK_RESPONSE_CANCEL, - NULL); - gint result = gtk_dialog_run (GTK_DIALOG (dialog)); - gtk_widget_destroy (dialog); - if (result == GTK_RESPONSE_YES) { - return [self saveActiveDocument]; - } else { - return result == GTK_RESPONSE_NO; - } - } else { - return YES; - } -} - -- (TikzDocument*) _openDocument:(NSString*)path { - NSError *error = nil; - TikzDocument *d = [TikzDocument documentFromFile:path - styleManager:[app styleManager] - error:&error]; - if (d != nil) { - return d; - } else { - if ([error code] == TZ_ERR_PARSE) { - [self presentError:error withMessage:@"Invalid file"]; - } else { - [self presentError:error withMessage:@"Could not open file"]; - } - [[RecentManager defaultManager] removeRecentFile:path]; - return nil; - } -} - -- (void) _placeGraphOnClipboard:(Graph*)graph { - GtkClipboard *clipboard = gtk_clipboard_get (GDK_SELECTION_CLIPBOARD); - - static const GtkTargetEntry targets[] = { - { "TIKZITPICTURE", 0, TARGET_TIKZIT_PICTURE }, - { "UTF8_STRING", 0, TARGET_UTF8_STRING } }; - - gtk_clipboard_set_with_data (clipboard, - targets, G_N_ELEMENTS (targets), - clipboard_provide_data, - clipboard_release_data, - clipboard_graph_data_new (graph)); -} - -- (void) _clearParseError { - if (!hasParseError) - return; - gtk_statusbar_pop (statusBar, ParseStatus); - text_buffer_clear_tag (tikzBuffer, errorHighlightTag); - widget_clear_error (tikzPane); - hasParseError = NO; -} - -- (void) _setParseError:(NSError*)error { - if (!hasParseError) { - widget_set_error (tikzPane); - hasParseError = YES; - } - NSString *message = [NSString stringWithFormat:@"Parse error: %@", [error localizedDescription]]; - gtk_statusbar_pop (statusBar, ParseStatus); - gtk_statusbar_push (statusBar, ParseStatus, [message UTF8String]); - - text_buffer_clear_tag (tikzBuffer, errorHighlightTag); - - NSDictionary *errorInfo = [error userInfo]; - if ([errorInfo objectForKey:@"startLine"] != nil) { - GtkTextIter symbolStart; - GtkTextIter symbolEnd; - gtk_text_buffer_get_iter_at_line_index (tikzBuffer, &symbolStart, - [[errorInfo objectForKey:@"startLine"] intValue] - 1, - [[errorInfo objectForKey:@"startColumn"] intValue] - 1); - gtk_text_buffer_get_iter_at_line_index (tikzBuffer, &symbolEnd, - [[errorInfo objectForKey:@"endLine"] intValue] - 1, - [[errorInfo objectForKey:@"endColumn"] intValue]); - gtk_text_buffer_apply_tag (tikzBuffer, errorHighlightTag, - &symbolStart, &symbolEnd); - } -} - -- (void) _updateUndoActions { - [menu setUndoActionEnabled:[document canUndo]]; - [menu setUndoActionDetail:[document undoName]]; - - [menu setRedoActionEnabled:[document canRedo]]; - [menu setRedoActionDetail:[document redoName]]; -} - -- (void) _updateTitle { - NSString *title = [NSString stringWithFormat:@"TikZiT - %@%s", - [document name], - ([document hasUnsavedChanges] ? "*" : "")]; - gtk_window_set_title(window, [title UTF8String]); -} - -- (void) _updateStatus { - // FIXME: show tooltips or something instead - GString *buffer = g_string_sized_new (30); - gchar *nextNode = 0; - - for (Node *n in [[document pickSupport] selectedNodes]) { - if (nextNode) { - if (buffer->len == 0) { - g_string_printf(buffer, "Nodes %s", nextNode); - } else { - g_string_append_printf(buffer, ", %s", nextNode); - } - } - nextNode = (gchar *)[[n name] UTF8String]; - } - if (nextNode) { - if (buffer->len == 0) { - g_string_printf(buffer, "Node %s is selected", nextNode); - } else { - g_string_append_printf(buffer, " and %s are selected", nextNode); - } - } - - if (buffer->len == 0) { - int nrNodes = [[[document graph] nodes] count]; - int nrEdges = [[[document graph] edges] count]; - g_string_printf(buffer, "Graph has %d node%s and %d edge%s", - nrNodes, - nrNodes!=1 ? "s" : "", - nrEdges, - nrEdges!=1 ? "s" : ""); - } - gtk_statusbar_pop(statusBar, GraphInfoStatus); - gtk_statusbar_push(statusBar, GraphInfoStatus, buffer->str); - - g_string_free (buffer, TRUE); -} - -- (void) _updateTikz { - if (document != nil && !suppressTikzUpdates) { - suppressTikzUpdates = TRUE; - - if (document != nil) { - const char *tikzString = [[document tikz] UTF8String]; - gtk_text_buffer_set_text (tikzBuffer, tikzString, -1); - } else { - gtk_text_buffer_set_text (tikzBuffer, "", -1); - } - [self _clearParseError]; - - suppressTikzUpdates = FALSE; - } -} - -- (GraphEditorPanel*) _graphPanel { - return graphPanel; -} - -- (void) showPreview { - [self updatePreview]; -} - -@end - -// }}} -// {{{ GTK+ callbacks - -static void window_toplevel_focus_changed_cb (GObject *gobject, GParamSpec *pspec, Window *window) { - NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init]; - gboolean hasfocus; - g_object_get (gobject, "has-toplevel-focus", &hasfocus, NULL); - if (hasfocus) { - [[NSNotificationCenter defaultCenter] - postNotificationName:@"WindowGainedFocus" - object:window]; - [[window _graphPanel] grabTool]; - } else { - [[NSNotificationCenter defaultCenter] - postNotificationName:@"WindowLostFocus" - object:window]; - } - [pool drain]; -} - -static void graph_divider_position_changed_cb (GObject *gobject, GParamSpec *pspec, Window *window) { - NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init]; - gint position; - g_object_get (gobject, "position", &position, NULL); - [window graphHeightChanged:position]; - [pool drain]; -} - -static void tikz_buffer_changed_cb (GtkTextBuffer *buffer, Window *window) { - NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init]; - [window tikzBufferChanged]; - [pool drain]; -} - -static gboolean main_window_delete_event_cb (GtkWidget *widget, GdkEvent *event, Window *window) { - NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init]; - [window close]; - [pool drain]; - return TRUE; -} - -static void main_window_destroy_cb (GtkWidget *widget, Window *window) { - NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init]; - [[NSNotificationCenter defaultCenter] postNotificationName:@"WindowClosed" - object:window]; - [pool drain]; -} - -static gboolean main_window_configure_event_cb (GtkWidget *widget, GdkEventConfigure *event, Window *window) { - NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init]; - [window windowSizeChangedWidth:event->width height:event->height]; - [pool drain]; - return FALSE; -} - -static void clipboard_provide_data (GtkClipboard *clipboard, - GtkSelectionData *selection_data, - guint info, - gpointer clipboard_graph_data) { - NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init]; - - ClipboardGraphData *data = (ClipboardGraphData*)clipboard_graph_data; - if (info == TARGET_UTF8_STRING || info == TARGET_TIKZIT_PICTURE) { - clipboard_graph_data_convert (data); - GdkAtom target = (info == TARGET_UTF8_STRING) ? utf8_atom : tikzit_picture_atom; - gtk_selection_data_set (selection_data, - target, - 8*sizeof(gchar), - (guchar*)data->tikz, - data->tikz_length); - } - - [pool drain]; -} - -static void clipboard_release_data (GtkClipboard *clipboard, gpointer data) { - NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init]; - clipboard_graph_data_free ((ClipboardGraphData*)data); - [pool drain]; -} - -static void clipboard_check_targets (GtkClipboard *clipboard, - GdkAtom *atoms, - gint n_atoms, - gpointer action) { - NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init]; - - gboolean found = FALSE; - for (gint i = 0; i < n_atoms; ++i) { - if (atoms[i] == tikzit_picture_atom) { - found = TRUE; - break; - } - } - gtk_action_set_sensitive (GTK_ACTION (action), found); - - [pool drain]; -} - -static void update_paste_action (GtkClipboard *clipboard, GdkEvent *event, GtkAction *action) { - gtk_action_set_sensitive (action, FALSE); - gtk_clipboard_request_targets (clipboard, clipboard_check_targets, action); -} - -static void clipboard_paste_contents (GtkClipboard *clipboard, - GtkSelectionData *selection_data, - gpointer document) { - NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init]; - - TikzDocument *doc = (TikzDocument*)document; - gint length = gtk_selection_data_get_length (selection_data); - if (length >= 0) { - const guchar *raw_data = gtk_selection_data_get_data (selection_data); - gchar *data = g_new (gchar, length+1); - g_strlcpy (data, (const gchar *)raw_data, length+1); - NSString *tikz = [NSString stringWithUTF8String:data]; - if (tikz != nil) { - [doc pasteFromTikz:tikz]; - } - g_free (data); - } - - [pool drain]; -} - -// }}} - -// vim:ft=objc:ts=8:et:sts=4:sw=4:foldmethod=marker diff --git a/tikzit/src/gtk/cairo_helpers.h b/tikzit/src/gtk/cairo_helpers.h deleted file mode 100644 index e95357b..0000000 --- a/tikzit/src/gtk/cairo_helpers.h +++ /dev/null @@ -1,25 +0,0 @@ -/* - * Copyright 2011 Alex Merry <alex.merry@kdemail.net> - * - * 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 the Free Software Foundation; either version 2 of - * the License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see <http://www.gnu.org/licenses/>. - */ - -#import "TZFoundation.h" -#import "RColor.h" -#import <cairo/cairo.h> - -void cairo_ns_rectangle (cairo_t* cr, NSRect rect); -void cairo_set_source_rcolor (cairo_t* cr, RColor color); - -// vim:ft=objc:sts=4:sw=4:et diff --git a/tikzit/src/gtk/cairo_helpers.m b/tikzit/src/gtk/cairo_helpers.m deleted file mode 100644 index 104e686..0000000 --- a/tikzit/src/gtk/cairo_helpers.m +++ /dev/null @@ -1,28 +0,0 @@ -/* - * Copyright 2011 Alex Merry <alex.merry@kdemail.net> - * - * 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 the Free Software Foundation; either version 2 of - * the License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see <http://www.gnu.org/licenses/>. - */ - -#import "cairo_helpers.h" - -void cairo_ns_rectangle (cairo_t* cr, NSRect rect) { - cairo_rectangle (cr, rect.origin.x, rect.origin.y, rect.size.width, rect.size.height); -} - -void cairo_set_source_rcolor (cairo_t* cr, RColor color) { - cairo_set_source_rgba (cr, color.red, color.green, color.blue, color.alpha); -} - -// vim:ft=objc:sts=4:sw=4:et diff --git a/tikzit/src/gtk/clipboard.h b/tikzit/src/gtk/clipboard.h deleted file mode 100644 index 568fc50..0000000 --- a/tikzit/src/gtk/clipboard.h +++ /dev/null @@ -1,41 +0,0 @@ -/* - * Copyright 2011 Alex Merry <dev@randomguy3.me.uk> - * - * 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 the Free Software Foundation; either version 2 of - * the License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see <http://www.gnu.org/licenses/>. - */ - -#import "TZFoundation.h" -#import <gtk/gtk.h> -#import <Graph.h> - -enum { - TARGET_UTF8_STRING, - TARGET_TIKZIT_PICTURE -}; -typedef struct -{ - Graph *graph; - gchar *tikz; - gint tikz_length; -} ClipboardGraphData; - -extern GdkAtom utf8_atom; -extern GdkAtom tikzit_picture_atom; - -void clipboard_init (); -ClipboardGraphData *clipboard_graph_data_new (Graph *graph); -void clipboard_graph_data_free (ClipboardGraphData *data); -void clipboard_graph_data_convert (ClipboardGraphData *data); - -// vim:ft=objc:ts=8:et:sts=4:sw=4:foldmethod=marker diff --git a/tikzit/src/gtk/clipboard.m b/tikzit/src/gtk/clipboard.m deleted file mode 100644 index 7001717..0000000 --- a/tikzit/src/gtk/clipboard.m +++ /dev/null @@ -1,57 +0,0 @@ -/* - * Copyright 2011 Alex Merry <dev@randomguy3.me.uk> - * - * 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 the Free Software Foundation; either version 2 of - * the License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see <http://www.gnu.org/licenses/>. - */ - -#import "clipboard.h" - -GdkAtom utf8_atom; -GdkAtom tikzit_picture_atom; - -void clipboard_init () { - if (utf8_atom == GDK_NONE) { - utf8_atom = gdk_atom_intern ("UTF8_STRING", FALSE); - } - if (tikzit_picture_atom == GDK_NONE) { - tikzit_picture_atom = gdk_atom_intern ("TIKZITPICTURE", FALSE); - } -} - -ClipboardGraphData *clipboard_graph_data_new (Graph *graph) { - ClipboardGraphData *data = g_new (ClipboardGraphData, 1); - data->graph = [graph retain]; - data->tikz = NULL; - data->tikz_length = 0; - return data; -} - -void clipboard_graph_data_free (ClipboardGraphData *data) { - [data->graph release]; - if (data->tikz) { - g_free (data->tikz); - } - g_free (data); -} - -void clipboard_graph_data_convert (ClipboardGraphData *data) { - if (data->graph != nil && !data->tikz) { - data->tikz = g_strdup ([[data->graph tikz] UTF8String]); - data->tikz_length = strlen (data->tikz); - [data->graph release]; - data->graph = nil; - } -} - -// vim:ft=objc:ts=8:et:sts=4:sw=4:foldmethod=marker diff --git a/tikzit/src/gtk/gtkhelpers.h b/tikzit/src/gtk/gtkhelpers.h deleted file mode 100644 index e4b79b8..0000000 --- a/tikzit/src/gtk/gtkhelpers.h +++ /dev/null @@ -1,60 +0,0 @@ -// -// gtkhelpers.h -// TikZiT -// -// Copyright 2010 Alex Merry. All rights reserved. -// -// -// This file is part of TikZiT. -// -// TikZiT is free software: you can redistribute it and/or modify -// it under the terms of the GNU General Public License as published by -// the Free Software Foundation, either version 3 of the License, or -// (at your option) any later version. -// -// TikZiT is distributed in the hope that it will be useful, -// but WITHOUT ANY WARRANTY; without even the implied warranty of -// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -// GNU General Public License for more details. -// -// You should have received a copy of the GNU General Public License -// along with TikZiT. If not, see <http://www.gnu.org/licenses/>. -// -#import "TZFoundation.h" -#include <gtk/gtk.h> -#import <gdk-pixbuf/gdk-pixbuf.h> - -/** - * Releases the Objective-C object pointed to by data - * - * Intended for use as a cleanup function in Glib/GObject-based - * code. - */ -void release_obj (gpointer data); - -NSString * gtk_editable_get_string (GtkEditable *editable, gint start, gint end); - -GdkRectangle gdk_rectangle_from_ns_rect (NSRect rect); -NSRect gdk_rectangle_to_ns_rect (GdkRectangle rect); - -void gtk_action_set_detailed_label (GtkAction *action, const gchar *baseLabel, const gchar *actionName); - -gint tz_hijack_key_press (GtkWindow *win, - GdkEventKey *event, - gpointer user_data); - -// Equivalent of GTK+3's gdk_pixbuf_get_from_surface() -GdkPixbuf * pixbuf_get_from_surface(cairo_surface_t *surface); - -void tz_restore_window (GtkWindow *window, gint x, gint y, gint w, gint h); - -void label_set_bold (GtkLabel *label); - -void widget_set_error (GtkWidget *widget); -void widget_clear_error (GtkWidget *widget); - -void text_buffer_clear_tag (GtkTextBuffer *buffer, GtkTextTag *tag); - -void utility_window_attach (GtkWindow *util_win, GtkWindow *parent_win); - -// vim:ft=objc:sts=2:sw=2:et diff --git a/tikzit/src/gtk/gtkhelpers.m b/tikzit/src/gtk/gtkhelpers.m deleted file mode 100644 index 9d26af5..0000000 --- a/tikzit/src/gtk/gtkhelpers.m +++ /dev/null @@ -1,275 +0,0 @@ -// -// gtkhelpers.h -// TikZiT -// -// Copyright 2010 Alex Merry. All rights reserved. -// -// Some code from Glade: -// Copyright 2001 Ximian, Inc. -// -// This file is part of TikZiT. -// -// TikZiT is free software: you can redistribute it and/or modify -// it under the terms of the GNU General Public License as published by -// the Free Software Foundation, either version 3 of the License, or -// (at your option) any later version. -// -// TikZiT is distributed in the hope that it will be useful, -// but WITHOUT ANY WARRANTY; without even the implied warranty of -// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -// GNU General Public License for more details. -// -// You should have received a copy of the GNU General Public License -// along with TikZiT. If not, see <http://www.gnu.org/licenses/>. -// -#import "gtkhelpers.h" -#import <gdk/gdkkeysyms.h> - -void release_obj (gpointer data) { - id obj = (id)data; - [obj release]; -} - -NSString * gtk_editable_get_string (GtkEditable *editable, gint start, gint end) -{ - gchar *text = gtk_editable_get_chars (editable, start, end); - NSString *string = [NSString stringWithUTF8String:text]; - g_free (text); - return string; -} - -GdkRectangle gdk_rectangle_from_ns_rect (NSRect box) { - GdkRectangle rect; - rect.x = box.origin.x; - rect.y = box.origin.y; - rect.width = box.size.width; - rect.height = box.size.height; - return rect; -} - -NSRect gdk_rectangle_to_ns_rect (GdkRectangle rect) { - NSRect result; - result.origin.x = rect.x; - result.origin.y = rect.y; - result.size.width = rect.width; - result.size.height = rect.height; - return result; -} - -void gtk_action_set_detailed_label (GtkAction *action, const gchar *baseLabel, const gchar *actionName) { - if (actionName == NULL || *actionName == '\0') { - gtk_action_set_label (action, baseLabel); - } else { - GString *label = g_string_sized_new (30); - g_string_printf(label, "%s: %s", baseLabel, actionName); - gtk_action_set_label (action, label->str); - g_string_free (label, TRUE); - } -} - -/** - * tz_hijack_key_press: - * @win: a #GtkWindow - * event: the GdkEventKey - * user_data: unused - * - * This function is meant to be attached to key-press-event of a toplevel, - * it simply allows the window contents to treat key events /before/ - * accelerator keys come into play (this way widgets dont get deleted - * when cutting text in an entry etc.). - * - * Returns: whether the event was handled - */ -gint -tz_hijack_key_press (GtkWindow *win, - GdkEventKey *event, - gpointer user_data) -{ - GtkWidget *focus_widget; - - focus_widget = gtk_window_get_focus (win); - if (focus_widget && - (event->keyval == GDK_Delete || /* Filter Delete from accelerator keys */ - ((event->state & GDK_CONTROL_MASK) && /* CTRL keys... */ - ((event->keyval == GDK_c || event->keyval == GDK_C) || /* CTRL-C (copy) */ - (event->keyval == GDK_x || event->keyval == GDK_X) || /* CTRL-X (cut) */ - (event->keyval == GDK_v || event->keyval == GDK_V) || /* CTRL-V (paste) */ - (event->keyval == GDK_a || event->keyval == GDK_A) || /* CTRL-A (select-all) */ - (event->keyval == GDK_n || event->keyval == GDK_N))))) /* CTRL-N (new document) ?? */ - { - return gtk_widget_event (focus_widget, - (GdkEvent *)event); - } - return FALSE; -} - -GdkPixbuf * pixbuf_get_from_surface(cairo_surface_t *surface) { - cairo_surface_flush (surface); - - int width = cairo_image_surface_get_width (surface); - int height = cairo_image_surface_get_height (surface); - int stride = cairo_image_surface_get_stride (surface); - unsigned char *data = cairo_image_surface_get_data (surface); - - GdkPixbuf *pixbuf = gdk_pixbuf_new (GDK_COLORSPACE_RGB, - TRUE, - 8, - width, - height); - unsigned char *pbdata = gdk_pixbuf_get_pixels (pixbuf); - int pbstride = gdk_pixbuf_get_rowstride (pixbuf); - - for (int y = 0; y < height; ++y) { - uint32_t *line = (uint32_t*)(data + y*stride); - unsigned char *pbline = pbdata + (y*pbstride); - for (int x = 0; x < width; ++x) { - uint32_t pixel = *(line + x); - unsigned char *pbpixel = pbline + (x*4); - // NB: We should un-pre-mult the alpha here. - // However, in our world, alpha is always - // on or off, so it doesn't really matter - pbpixel[3] = ((pixel & 0xff000000) >> 24); - pbpixel[0] = ((pixel & 0x00ff0000) >> 16); - pbpixel[1] = ((pixel & 0x0000ff00) >> 8); - pbpixel[2] = (pixel & 0x000000ff); - } - } - - return pixbuf; -} - -/* This function mostly lifted from - * gtk+/gdk/gdkscreen.c:gdk_screen_get_monitor_at_window() - */ -static gint -get_appropriate_monitor (GdkScreen *screen, - gint x, - gint y, - gint w, - gint h) -{ - GdkRectangle rect; - gint area = 0; - gint monitor = -1; - gint num_monitors; - gint i; - - rect.x = x; - rect.y = y; - rect.width = w; - rect.height = h; - - num_monitors = gdk_screen_get_n_monitors (screen); - - for (i = 0; i < num_monitors; i++) - { - GdkRectangle geometry; - - gdk_screen_get_monitor_geometry (screen, i, &geometry); - - if (gdk_rectangle_intersect (&rect, &geometry, &geometry) && - geometry.width * geometry.height > area) - { - area = geometry.width * geometry.height; - monitor = i; - } - } - - if (monitor >= 0) - return monitor; - else - return gdk_screen_get_monitor_at_point (screen, - rect.x + rect.width / 2, - rect.y + rect.height / 2); -} - -/* This function mostly lifted from gimp_session_info_apply_geometry - * in gimp-2.6/app/widgets/gimpsessioninfo.c - */ -void tz_restore_window (GtkWindow *window, gint x, gint y, gint w, gint h) -{ - gint forced_w = w; - gint forced_h = h; - if (w <= 0 || h <= 0) { - gtk_window_get_default_size (window, &w, &h); - } - if (w <= 0 || h <= 0) { - gtk_window_get_size (window, &w, &h); - } - - GdkScreen *screen = gtk_widget_get_screen (GTK_WIDGET (window)); - - gint monitor = 0; - if (w > 0 && h > 0) { - monitor = get_appropriate_monitor (screen, x, y, w, h); - } else { - monitor = gdk_screen_get_monitor_at_point (screen, x, y); - } - - GdkRectangle rect; - gdk_screen_get_monitor_geometry (screen, monitor, &rect); - - x = CLAMP (x, - rect.x, - rect.x + rect.width - (w > 0 ? w : 128)); - y = CLAMP (y, - rect.y, - rect.y + rect.height - (h > 0 ? h : 128)); - - gchar geom[32]; - g_snprintf (geom, sizeof (geom), "%+d%+d", x, y); - - gtk_window_parse_geometry (window, geom); - - if (forced_w > 0 && forced_h > 0) { - gtk_window_set_default_size (window, forced_w, forced_h); - } -} - -void label_set_bold (GtkLabel *label) { - PangoAttrList *attrs = pango_attr_list_new (); - pango_attr_list_insert (attrs, - pango_attr_weight_new (PANGO_WEIGHT_SEMIBOLD)); - gtk_label_set_attributes (label, attrs); - pango_attr_list_unref (attrs); -} - -void widget_set_error (GtkWidget *widget) { - GdkColor color = {0, 65535, 61184, 61184}; - gtk_widget_modify_base (widget, GTK_STATE_NORMAL, &color); -} - -void widget_clear_error (GtkWidget *widget) { - gtk_widget_modify_base (widget, GTK_STATE_NORMAL, NULL); -} - -void text_buffer_clear_tag (GtkTextBuffer *buffer, GtkTextTag *tag) { - GtkTextIter start; - GtkTextIter end; - gtk_text_buffer_get_start_iter (buffer, &start); - gtk_text_buffer_get_end_iter (buffer, &end); - gtk_text_buffer_remove_tag (buffer, tag, &start, &end); -} - -void utility_window_attach (GtkWindow *util_win, GtkWindow *parent_win) { - if (parent_win == gtk_window_get_transient_for (util_win)) - return; - - // HACK: X window managers tend to move windows around when they are - // unmapped and mapped again, so we save the position - gint x, y; - gtk_window_get_position (util_win, &x, &y); - - // HACK: Altering WM_TRANSIENT_FOR on a non-hidden but unmapped window - // (eg: when you have minimised the original parent window) can - // cause the window to be lost forever, so we hide it first - gtk_widget_hide (GTK_WIDGET (util_win)); - gtk_window_set_focus_on_map (util_win, FALSE); - gtk_window_set_transient_for (util_win, parent_win); - gtk_widget_show (GTK_WIDGET (util_win)); - - // HACK: see above - gtk_window_move (util_win, x, y); -} - -// vim:ft=objc:ts=8:et:sts=4:sw=4 diff --git a/tikzit/src/gtk/logo.h b/tikzit/src/gtk/logo.h deleted file mode 100644 index e778da9..0000000 --- a/tikzit/src/gtk/logo.h +++ /dev/null @@ -1,32 +0,0 @@ -/* - * Copyright 2012 Alex Merry <alex.merry@kdemail.net> - * - * 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 the Free Software Foundation; either version 2 of - * the License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see <http://www.gnu.org/licenses/>. - */ - -#include <gdk-pixbuf/gdk-pixbuf.h> - -typedef enum { - LOGO_SIZE_16, - LOGO_SIZE_24, - LOGO_SIZE_32, - LOGO_SIZE_48, - LOGO_SIZE_64, - LOGO_SIZE_128, - LOGO_SIZE_COUNT -} LogoSize; - -GdkPixbuf *get_logo (LogoSize size); - -// vim:ft=objc:ts=8:et:sts=4:sw=4 diff --git a/tikzit/src/gtk/logo.m b/tikzit/src/gtk/logo.m deleted file mode 100644 index 57533c7..0000000 --- a/tikzit/src/gtk/logo.m +++ /dev/null @@ -1,64 +0,0 @@ -/* - * Copyright 2012 Alex Merry <alex.merry@kdemail.net> - * - * 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 the Free Software Foundation; either version 2 of - * the License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see <http://www.gnu.org/licenses/>. - */ - -#import "logo.h" -#include <gdk-pixbuf/gdk-pixdata.h> - -#pragma GCC diagnostic push -#pragma GCC diagnostic ignored "-Wpointer-sign" -#import "logodata.m" -#pragma GCC diagnostic pop - -static GdkPixbuf *pixbufCache[LOGO_SIZE_COUNT]; - -GdkPixbuf *get_logo (LogoSize size) { - const GdkPixdata *data = NULL; - switch (size) { - case LOGO_SIZE_16: - data = &logo16; - break; - case LOGO_SIZE_24: - data = &logo24; - break; - case LOGO_SIZE_32: - data = &logo32; - break; - case LOGO_SIZE_48: - data = &logo48; - break; - case LOGO_SIZE_64: - data = &logo64; - break; - case LOGO_SIZE_128: - data = &logo128; - break; - default: - return NULL; - }; - if (pixbufCache[size]) { - g_object_ref (pixbufCache[size]); - return pixbufCache[size]; - } else { - GdkPixbuf *buf = gdk_pixbuf_from_pixdata (data, FALSE, NULL); - pixbufCache[size] = buf; - g_object_add_weak_pointer (G_OBJECT (buf), (void**)(&(pixbufCache[size]))); - return buf; - } -} - -// vim:ft=objc:ts=8:et:sts=4:sw=4 - diff --git a/tikzit/src/gtk/main.m b/tikzit/src/gtk/main.m deleted file mode 100644 index 5d9f4a4..0000000 --- a/tikzit/src/gtk/main.m +++ /dev/null @@ -1,111 +0,0 @@ -// -// main.m -// TikZiT -// -// Copyright 2010 Chris Heunen. All rights reserved. -// -// -// This file is part of TikZiT. -// -// TikZiT is free software: you can redistribute it and/or modify -// it under the terms of the GNU General Public License as published by -// the Free Software Foundation, either version 3 of the License, or -// (at your option) any later version. -// -// TikZiT is distributed in the hope that it will be useful, -// but WITHOUT ANY WARRANTY; without even the implied warranty of -// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -// GNU General Public License for more details. -// -// You should have received a copy of the GNU General Public License -// along with TikZiT. If not, see <http://www.gnu.org/licenses/>. -// - -#import "TZFoundation.h" -#import <gtk/gtk.h> -#import "clipboard.h" -#import "logo.h" -#import "tzstockitems.h" - -#import "Application.h" - -static GOptionEntry entries[] = -{ - //{ "verbose", 'v', 0, G_OPTION_ARG_NONE, &verbose, "Be verbose", NULL }, - { NULL } -}; - -void onUncaughtException(NSException* exception) -{ - NSString *joinStr = @"\n "; - NSLog(@"uncaught exception: %@\n backtrace: %@", - [exception description], - [[exception callStackSymbols] componentsJoinedByString:joinStr]); -} - -int main (int argc, char *argv[]) { - NSSetUncaughtExceptionHandler(&onUncaughtException); - - [[NSAutoreleasePool alloc] init]; - - GError *error = NULL; - GOptionContext *context; - context = g_option_context_new ("[FILES] - PGF/TikZ-based graph editor"); - g_option_context_add_main_entries (context, entries, NULL); - g_option_context_add_group (context, gtk_get_option_group (TRUE)); - if (!g_option_context_parse (context, &argc, &argv, &error)) - { - if (error->domain == G_OPTION_ERROR) { - g_print ("%s\nUse --help to see available options\n", error->message); - } else { - g_print ("Unexpected error parsing options: %s\n", error->message); - } - exit (1); - } - g_option_context_free (context); - -#ifndef WINDOWS - GList *icon_list = NULL; - icon_list = g_list_prepend (icon_list, get_logo(LOGO_SIZE_128)); - icon_list = g_list_prepend (icon_list, get_logo(LOGO_SIZE_64)); - icon_list = g_list_prepend (icon_list, get_logo(LOGO_SIZE_48)); - icon_list = g_list_prepend (icon_list, get_logo(LOGO_SIZE_32)); - icon_list = g_list_prepend (icon_list, get_logo(LOGO_SIZE_24)); - icon_list = g_list_prepend (icon_list, get_logo(LOGO_SIZE_16)); - gtk_window_set_default_icon_list (icon_list); - GList *list_head = icon_list; - while (list_head) { - g_object_unref ((GObject*)list_head->data); - list_head = list_head->next; - } -#endif - - NSAutoreleasePool *initPool = [[NSAutoreleasePool alloc] init]; - - tz_register_stock_items(); - clipboard_init(); - - Application *app = nil; - if (argc > 1) { - NSMutableArray *files = [NSMutableArray arrayWithCapacity:argc-1]; - for (int i = 1; i < argc; ++i) { - [files insertObject:[NSString stringWithGlibFilename:argv[i]] - atIndex:i-1]; - } - NSLog(@"Files: %@", files); - app = [[Application alloc] initWithFiles:files]; - } else { - app = [[Application alloc] init]; - } - - [initPool drain]; - - gtk_main (); - - [app saveConfiguration]; - [app release]; - - return 0; -} - -// vim:ft=objc:et:sts=4:sw=4 diff --git a/tikzit/src/gtk/mkdtemp.h b/tikzit/src/gtk/mkdtemp.h deleted file mode 100644 index 65ee99e..0000000 --- a/tikzit/src/gtk/mkdtemp.h +++ /dev/null @@ -1,32 +0,0 @@ -/* Creating a private temporary directory. - Copyright (C) 2001-2002 Free Software Foundation, Inc. - - 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 - the Free Software Foundation; either version 2, or (at your option) - any later version. - - This program is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU General Public License for more details. - - You should have received a copy of the GNU General Public License - along with this program; if not, write to the Free Software Foundation, - Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */ - -#if HAVE_MKDTEMP - -/* Get mkdtemp() declaration. */ -#include <stdlib.h> - -#else - -/* Create a unique temporary directory from TEMPLATE. - The last six characters of TEMPLATE must be "XXXXXX"; - they are replaced with a string that makes the directory name unique. - Returns TEMPLATE, or a null pointer if it cannot get a unique name. - The directory is created mode 700. */ -extern char * mkdtemp (char *template); - -#endif diff --git a/tikzit/src/gtk/mkdtemp.m b/tikzit/src/gtk/mkdtemp.m deleted file mode 100644 index ee3cd7c..0000000 --- a/tikzit/src/gtk/mkdtemp.m +++ /dev/null @@ -1,180 +0,0 @@ -/* Copyright (C) 1999, 2001-2003 Free Software Foundation, Inc. - This file is part of the GNU C Library. - - The GNU C Library is free software; you can redistribute it and/or - modify it under the terms of the GNU Library General Public License as - published by the Free Software Foundation; either version 2 of the - License, or (at your option) any later version. - - The GNU C Library is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - Library General Public License for more details. - - You should have received a copy of the GNU Library General Public - License along with the GNU C Library; see the file COPYING.LIB. If not, - see <http://www.gnu.org/licenses/>. - */ - -/* Extracted from misc/mkdtemp.c and sysdeps/posix/tempname.c. */ - -#ifdef HAVE_CONFIG_H -# include "config.h" -#endif - -/* Specification. */ -#include "mkdtemp.h" - -#include <errno.h> -#ifndef __set_errno -# define __set_errno(Val) errno = (Val) -#endif - -#include <stddef.h> -#include <stdlib.h> -#include <string.h> - -#include <stdio.h> -#ifndef TMP_MAX -# define TMP_MAX 238328 -#endif - -#if HAVE_STDINT_H || _LIBC -# include <stdint.h> -#endif -#if HAVE_INTTYPES_H -# include <inttypes.h> -#endif - -#if HAVE_UNISTD_H || _LIBC -# include <unistd.h> -#endif - -#if HAVE_GETTIMEOFDAY || _LIBC -# if HAVE_SYS_TIME_H || _LIBC -# include <sys/time.h> -# endif -#else -# if HAVE_TIME_H || _LIBC -# include <time.h> -# endif -#endif - -#include "stat.h" - -#ifdef __MINGW32__ -/* mingw's mkdir() function has 1 argument, but we pass 2 arguments. - Therefore we have to disable the argument count checking. */ -# define mkdir ((int (*)()) mkdir) -#endif - -#if !_LIBC -# define __getpid getpid -# define __gettimeofday gettimeofday -# define __mkdir mkdir -#endif - -/* Use the widest available unsigned type if uint64_t is not - available. The algorithm below extracts a number less than 62**6 - (approximately 2**35.725) from uint64_t, so ancient hosts where - uintmax_t is only 32 bits lose about 3.725 bits of randomness, - which is better than not having mkstemp at all. */ -#if !defined UINT64_MAX && !defined uint64_t -# define uint64_t uintmax_t -#endif - -/* These are the characters used in temporary filenames. */ -static const char letters[] = -"abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789"; - -/* Generate a temporary file name based on TMPL. TMPL must match the - rules for mk[s]temp (i.e. end in "XXXXXX"). The name constructed - does not exist at the time of the call to __gen_tempname. TMPL is - overwritten with the result. - - KIND is: - __GT_DIR: create a directory, which will be mode 0700. - - We use a clever algorithm to get hard-to-predict names. */ -static int -gen_tempname (char *tmpl) -{ - int len; - char *XXXXXX; - static uint64_t value; - uint64_t random_time_bits; - int count, fd = -1; - int save_errno = errno; - - len = strlen (tmpl); - if (len < 6 || strcmp (&tmpl[len - 6], "XXXXXX")) - { - __set_errno (EINVAL); - return -1; - } - - /* This is where the Xs start. */ - XXXXXX = &tmpl[len - 6]; - - /* Get some more or less random data. */ -#ifdef RANDOM_BITS - RANDOM_BITS (random_time_bits); -#else -# if HAVE_GETTIMEOFDAY || _LIBC - { - struct timeval tv; - __gettimeofday (&tv, NULL); - random_time_bits = ((uint64_t) tv.tv_usec << 16) ^ tv.tv_sec; - } -# else - random_time_bits = time (NULL); -# endif -#endif - value += random_time_bits ^ __getpid (); - - for (count = 0; count < TMP_MAX; value += 7777, ++count) - { - uint64_t v = value; - - /* Fill in the random bits. */ - XXXXXX[0] = letters[v % 62]; - v /= 62; - XXXXXX[1] = letters[v % 62]; - v /= 62; - XXXXXX[2] = letters[v % 62]; - v /= 62; - XXXXXX[3] = letters[v % 62]; - v /= 62; - XXXXXX[4] = letters[v % 62]; - v /= 62; - XXXXXX[5] = letters[v % 62]; - - fd = __mkdir (tmpl, S_IRUSR | S_IWUSR | S_IXUSR); - - if (fd >= 0) - { - __set_errno (save_errno); - return fd; - } - else if (errno != EEXIST) - return -1; - } - - /* We got out of the loop because we ran out of combinations to try. */ - __set_errno (EEXIST); - return -1; -} - -/* Generate a unique temporary directory from TEMPLATE. - The last six characters of TEMPLATE must be "XXXXXX"; - they are replaced with a string that makes the filename unique. - The directory is created, mode 700, and its name is returned. - (This function comes from OpenBSD.) */ -char * -mkdtemp (char *template) -{ - if (gen_tempname (template)) - return NULL; - else - return template; -} diff --git a/tikzit/src/gtk/stat.h b/tikzit/src/gtk/stat.h deleted file mode 100644 index a9829ae..0000000 --- a/tikzit/src/gtk/stat.h +++ /dev/null @@ -1,25 +0,0 @@ -#include <sys/stat.h> -#if STAT_MACROS_BROKEN -# undef S_ISDIR -#endif -#if !defined S_ISDIR && defined S_IFDIR -# define S_ISDIR(mode) (((mode) & S_IFMT) == S_IFDIR) -#endif -#if !S_IRUSR && S_IREAD -# define S_IRUSR S_IREAD -#endif -#if !S_IRUSR -# define S_IRUSR 00400 -#endif -#if !S_IWUSR && S_IWRITE -# define S_IWUSR S_IWRITE -#endif -#if !S_IWUSR -# define S_IWUSR 00200 -#endif -#if !S_IXUSR && S_IEXEC -# define S_IXUSR S_IEXEC -#endif -#if !S_IXUSR -# define S_IXUSR 00100 -#endif diff --git a/tikzit/src/gtk/test/gtk.m b/tikzit/src/gtk/test/gtk.m deleted file mode 100644 index aabb0f2..0000000 --- a/tikzit/src/gtk/test/gtk.m +++ /dev/null @@ -1,27 +0,0 @@ -// -// linux.m -// TikZiT -// -// Copyright 2010 Aleks Kissinger. All rights reserved. -// -// -// This file is part of TikZiT. -// -// TikZiT is free software: you can redistribute it and/or modify -// it under the terms of the GNU General Public License as published by -// the Free Software Foundation, either version 3 of the License, or -// (at your option) any later version. -// -// TikZiT is distributed in the hope that it will be useful, -// but WITHOUT ANY WARRANTY; without even the implied warranty of -// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -// GNU General Public License for more details. -// -// You should have received a copy of the GNU General Public License -// along with TikZiT. If not, see <http://www.gnu.org/licenses/>. -// -#import "test/test.h" - -void testGtk() { - -} diff --git a/tikzit/src/gtk/test/main.m b/tikzit/src/gtk/test/main.m deleted file mode 100644 index 639a335..0000000 --- a/tikzit/src/gtk/test/main.m +++ /dev/null @@ -1,50 +0,0 @@ -// -// main.m -// TikZiT -// -// Copyright 2010 Aleks Kissinger. All rights reserved. -// -// -// This file is part of TikZiT. -// -// TikZiT is free software: you can redistribute it and/or modify -// it under the terms of the GNU General Public License as published by -// the Free Software Foundation, either version 3 of the License, or -// (at your option) any later version. -// -// TikZiT is distributed in the hope that it will be useful, -// but WITHOUT ANY WARRANTY; without even the implied warranty of -// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -// GNU General Public License for more details. -// -// You should have received a copy of the GNU General Public License -// along with TikZiT. If not, see <http://www.gnu.org/licenses/>. -// -#include "config.h" -#import "test/test.h" -#include <string.h> -void testCommon(); - -int main(int argc, char **argv) { - if (argc == 2 && strcmp(argv[1], "--disable-color")==0) { - setColorEnabled(NO); - } else { - setColorEnabled(YES); - } - - PUTS(@""); - PUTS(@"**********************************************"); - PUTS(@"TikZiT TESTS, LINUX VERSION %@", VERSION); - PUTS(@"**********************************************"); - PUTS(@""); - - startTests(); - testCommon(); - testLinux(); - - PUTS(@""); - PUTS(@"**********************************************"); - endTests(); - PUTS(@"**********************************************"); - PUTS(@""); -} diff --git a/tikzit/src/gtk/tzstockitems.h b/tikzit/src/gtk/tzstockitems.h deleted file mode 100644 index 5ad0da9..0000000 --- a/tikzit/src/gtk/tzstockitems.h +++ /dev/null @@ -1,26 +0,0 @@ -/* - * Copyright 2012 Alex Merry <dev@randomguy3.me.uk> - * - * 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 the Free Software Foundation; either version 2 of - * the License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see <http://www.gnu.org/licenses/>. - */ - -#define TIKZIT_STOCK_SELECT "tikzit-select" -#define TIKZIT_STOCK_CREATE_NODE "tikzit-create-node" -#define TIKZIT_STOCK_CREATE_EDGE "tikzit-create-edge" -#define TIKZIT_STOCK_BOUNDING_BOX "tikzit-bounding-box" -#define TIKZIT_STOCK_DRAG "tikzit-drag" - -void tz_register_stock_items(); - -// vim:ft=objc:ts=8:et:sts=4:sw=4:foldmethod=marker diff --git a/tikzit/src/gtk/tzstockitems.m b/tikzit/src/gtk/tzstockitems.m deleted file mode 100644 index 5eba912..0000000 --- a/tikzit/src/gtk/tzstockitems.m +++ /dev/null @@ -1,64 +0,0 @@ -/* - * Copyright 2012 Alex Merry <dev@randomguy3.me.uk> - * - * 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 the Free Software Foundation; either version 2 of - * the License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see <http://www.gnu.org/licenses/>. - */ - -#include "tzstockitems.h" -#include <gtk/gtk.h> -#include <gdk-pixbuf/gdk-pixdata.h> - -#pragma GCC diagnostic push -#pragma GCC diagnostic ignored "-Wpointer-sign" -#import "icondata.m" -#pragma GCC diagnostic pop - -static GtkStockItem stock_items[] = { - // gchar *stock_id; - // gchar *label; - // GdkModifierType modifier; - // guint keyval; - // gchar *translation_domain; - { TIKZIT_STOCK_SELECT, "Select", 0, 0, NULL }, - { TIKZIT_STOCK_CREATE_NODE, "Create Node", 0, 0, NULL }, - { TIKZIT_STOCK_CREATE_EDGE, "Create Edge", 0, 0, NULL }, - { TIKZIT_STOCK_BOUNDING_BOX, "Bounding Box", 0, 0, NULL }, - { TIKZIT_STOCK_DRAG, "Drag", 0, 0, NULL }, -}; -static guint n_stock_items = G_N_ELEMENTS (stock_items); - -static void icon_factory_add_pixdata (GtkIconFactory *factory, - const gchar *stock_id, - const GdkPixdata *image_data) { - - GdkPixbuf *buf = gdk_pixbuf_from_pixdata (image_data, FALSE, NULL); - GtkIconSet *icon_set = gtk_icon_set_new_from_pixbuf (buf); - gtk_icon_factory_add (factory, stock_id, icon_set); - gtk_icon_set_unref (icon_set); - g_object_unref (G_OBJECT (buf)); -} - -void tz_register_stock_items() { - gtk_stock_add_static (stock_items, n_stock_items); - - GtkIconFactory *factory = gtk_icon_factory_new (); - icon_factory_add_pixdata (factory, TIKZIT_STOCK_SELECT, &select_rectangular); - icon_factory_add_pixdata (factory, TIKZIT_STOCK_CREATE_NODE, &draw_ellipse); - icon_factory_add_pixdata (factory, TIKZIT_STOCK_CREATE_EDGE, &draw_path); - icon_factory_add_pixdata (factory, TIKZIT_STOCK_BOUNDING_BOX, &transform_crop_and_resize); - icon_factory_add_pixdata (factory, TIKZIT_STOCK_DRAG, &transform_move); - gtk_icon_factory_add_default (factory); -} - -// vim:ft=objc:ts=8:et:sts=4:sw=4:foldmethod=marker diff --git a/tikzit/src/gtk/tztoolpalette.h b/tikzit/src/gtk/tztoolpalette.h deleted file mode 100644 index 45ec2ac..0000000 --- a/tikzit/src/gtk/tztoolpalette.h +++ /dev/null @@ -1,56 +0,0 @@ -/* GIMP - The GNU Image Manipulation Program - * Copyright (C) 1995 Spencer Kimball and Peter Mattis - * - * tztoolpalette.h, based on gimptoolpalette.h - * Copyright (C) 2010 Michael Natterer <mitch@gimp.org> - * - * 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 - * the Free Software Foundation; either version 3 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see <http://www.gnu.org/licenses/>. - */ - -#ifndef __TZ_TOOL_PALETTE_H__ -#define __TZ_TOOL_PALETTE_H__ - - -#define TZ_TYPE_TOOL_PALETTE (tz_tool_palette_get_type ()) -#define TZ_TOOL_PALETTE(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), TZ_TYPE_TOOL_PALETTE, TzToolPalette)) -#define TZ_TOOL_PALETTE_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), TZ_TYPE_TOOL_PALETTE, TzToolPaletteClass)) -#define TZ_IS_TOOL_PALETTE(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), TZ_TYPE_TOOL_PALETTE)) -#define TZ_IS_TOOL_PALETTE_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), TZ_TYPE_TOOL_PALETTE)) -#define TZ_TOOL_PALETTE_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), TZ_TYPE_TOOL_PALETTE, TzToolPaletteClass)) - - -typedef struct _TzToolPaletteClass TzToolPaletteClass; -typedef struct _TzToolPalette TzToolPalette; - -struct _TzToolPalette -{ - GtkToolPalette parent_instance; -}; - -struct _TzToolPaletteClass -{ - GtkToolPaletteClass parent_class; -}; - - -GType tz_tool_palette_get_type (void) G_GNUC_CONST; - -GtkWidget * tz_tool_palette_new (void); - -gboolean tz_tool_palette_get_button_size (TzToolPalette *widget, - gint *width, - gint *height); - - -#endif /* __TZ_TOOL_PALETTE_H__ */ diff --git a/tikzit/src/gtk/tztoolpalette.m b/tikzit/src/gtk/tztoolpalette.m deleted file mode 100644 index a948127..0000000 --- a/tikzit/src/gtk/tztoolpalette.m +++ /dev/null @@ -1,158 +0,0 @@ -/* GIMP - The GNU Image Manipulation Program - * Copyright (C) 1995 Spencer Kimball and Peter Mattis - * - * tztoolpalette.c, based on gimptoolpalette.c - * Copyright (C) 2010 Michael Natterer <mitch@gimp.org> - * Copyright (C) 2012 Alex Merry <alex.merry@kdemail.net> - * - * 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 - * the Free Software Foundation; either version 3 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see <http://www.gnu.org/licenses/>. - */ - -#include <gtk/gtk.h> - -#include "tztoolpalette.h" - - -#define DEFAULT_TOOL_ICON_SIZE GTK_ICON_SIZE_BUTTON -#define DEFAULT_BUTTON_RELIEF GTK_RELIEF_NONE - -#define TOOL_BUTTON_DATA_KEY "tz-tool-palette-item" -#define TOOL_INFO_DATA_KEY "tz-tool-info" - - -typedef struct _TzToolPalettePrivate TzToolPalettePrivate; - -struct _TzToolPalettePrivate -{ - gint tool_rows; - gint tool_columns; -}; - -#define GET_PRIVATE(p) G_TYPE_INSTANCE_GET_PRIVATE (p, \ - TZ_TYPE_TOOL_PALETTE, \ - TzToolPalettePrivate) - - -static void tz_tool_palette_size_allocate (GtkWidget *widget, - GtkAllocation *allocation); - - -G_DEFINE_TYPE (TzToolPalette, tz_tool_palette, GTK_TYPE_TOOL_PALETTE) - -#define parent_class tz_tool_palette_parent_class - - -static void -tz_tool_palette_class_init (TzToolPaletteClass *klass) -{ - GtkWidgetClass *widget_class = GTK_WIDGET_CLASS (klass); - - widget_class->size_allocate = tz_tool_palette_size_allocate; - - g_type_class_add_private (klass, sizeof (TzToolPalettePrivate)); -} - -static void -tz_tool_palette_init (TzToolPalette *palette) -{ -} - -static GtkToolItemGroup * -tz_tool_palette_tool_group (TzToolPalette *palette) -{ - GList *children; - GtkToolItemGroup *group; - - children = gtk_container_get_children (GTK_CONTAINER (palette)); - g_return_val_if_fail (children, NULL); - group = GTK_TOOL_ITEM_GROUP (children->data); - g_list_free (children); - - return group; -} - -gboolean -tz_tool_palette_get_button_size (TzToolPalette *palette, - gint *width, - gint *height) -{ - g_return_val_if_fail (width || height, FALSE); - - GtkToolItemGroup *group = tz_tool_palette_tool_group (palette); - g_return_val_if_fail (group, FALSE); - - guint tool_count = gtk_tool_item_group_get_n_items (group); - if (tool_count > 0) - { - GtkWidget *tool_button; - GtkRequisition button_requisition; - - tool_button = GTK_WIDGET (gtk_tool_item_group_get_nth_item (group, 0)); - gtk_widget_size_request (tool_button, &button_requisition); - if (width) - *width = button_requisition.width; - if (height) - *height = button_requisition.height; - return TRUE; - } - return FALSE; -} - -static void -tz_tool_palette_size_allocate (GtkWidget *widget, - GtkAllocation *allocation) -{ - TzToolPalettePrivate *private = GET_PRIVATE (widget); - GtkToolItemGroup *group = tz_tool_palette_tool_group (TZ_TOOL_PALETTE (widget)); - - g_return_if_fail (group); - - GTK_WIDGET_CLASS (parent_class)->size_allocate (widget, allocation); - - guint tool_count = gtk_tool_item_group_get_n_items (group); - if (tool_count > 0) - { - GtkWidget *tool_button; - GtkRequisition button_requisition; - gint tool_rows; - gint tool_columns; - - tool_button = GTK_WIDGET (gtk_tool_item_group_get_nth_item (group, 0)); - gtk_widget_size_request (tool_button, &button_requisition); - - tool_columns = MAX (1, (allocation->width / button_requisition.width)); - tool_rows = tool_count / tool_columns; - - if (tool_count % tool_columns) - tool_rows++; - - if (private->tool_rows != tool_rows || - private->tool_columns != tool_columns) - { - private->tool_rows = tool_rows; - private->tool_columns = tool_columns; - - gtk_widget_set_size_request (widget, -1, - tool_rows * button_requisition.height); - } - } -} - -GtkWidget * -tz_tool_palette_new (void) -{ - return g_object_new (TZ_TYPE_TOOL_PALETTE, NULL); -} - -// vim:ft=objc:ts=8:et:sts=2:sw=2:foldmethod=marker diff --git a/tikzit/src/osx/AppDelegate.h b/tikzit/src/osx/AppDelegate.h deleted file mode 100644 index 64acc38..0000000 --- a/tikzit/src/osx/AppDelegate.h +++ /dev/null @@ -1,57 +0,0 @@ -// -// AppDelegate.h -// TikZiT -// -// Copyright 2010 Aleks Kissinger. All rights reserved. -// -// -// This file is part of TikZiT. -// -// TikZiT is free software: you can redistribute it and/or modify -// it under the terms of the GNU General Public License as published by -// the Free Software Foundation, either version 3 of the License, or -// (at your option) any later version. -// -// TikZiT is distributed in the hope that it will be useful, -// but WITHOUT ANY WARRANTY; without even the implied warranty of -// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -// GNU General Public License for more details. -// -// You should have received a copy of the GNU General Public License -// along with TikZiT. If not, see <http://www.gnu.org/licenses/>. -// - -#import <Cocoa/Cocoa.h> -#import "StylePaletteController.h" -#import "ToolPaletteController.h" -#import "PropertyInspectorController.h" -#import "PreambleController.h" -#import "PreviewController.h" -#import "GraphicsView.h" -#import "PreferenceController.h"; - -@interface AppDelegate : NSObject { - NSMapTable *table; - StylePaletteController *stylePaletteController; - PropertyInspectorController *propertyInspectorController; - PreambleController *preambleController; - PreviewController *previewController; - PreferenceController *preferenceController; - ToolPaletteController *toolPaletteController; - IBOutlet GraphicsView *graphicsView; - NSString *tempDir; -} - -@property IBOutlet StylePaletteController *stylePaletteController; -@property IBOutlet ToolPaletteController *toolPaletteController; - -- (void)awakeFromNib; -+ (void)setDefaults; -- (void)applicationWillTerminate:(NSNotification *)notification; -- (IBAction)toggleStyleInspector:(id)sender; -- (IBAction)togglePropertyInspector:(id)sender; -- (IBAction)togglePreamble:(id)sender; -- (IBAction)togglePreferences:(id)sender; -- (IBAction)refreshShapes:(id)sender; - -@end diff --git a/tikzit/src/osx/AppDelegate.m b/tikzit/src/osx/AppDelegate.m deleted file mode 100644 index affb95c..0000000 --- a/tikzit/src/osx/AppDelegate.m +++ /dev/null @@ -1,124 +0,0 @@ -// -// AppDelegate.m -// TikZiT -// -// Copyright 2010 Aleks Kissinger. All rights reserved. -// -// -// This file is part of TikZiT. -// -// TikZiT is free software: you can redistribute it and/or modify -// it under the terms of the GNU General Public License as published by -// the Free Software Foundation, either version 3 of the License, or -// (at your option) any later version. -// -// TikZiT is distributed in the hope that it will be useful, -// but WITHOUT ANY WARRANTY; without even the implied warranty of -// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -// GNU General Public License for more details. -// -// You should have received a copy of the GNU General Public License -// along with TikZiT. If not, see <http://www.gnu.org/licenses/>. -// - -#import "AppDelegate.h" -#import "TikzDocument.h" -#import "Shape.h" -#import "SupportDir.h" - -@implementation AppDelegate - -@synthesize stylePaletteController, toolPaletteController; - -+(void)initialize{ - [self setDefaults]; -} - -- (void)awakeFromNib { - [SupportDir createUserSupportDir]; - NSString *supportDir = [SupportDir userSupportDir]; - //NSLog(stylePlist); - stylePaletteController = - [[StylePaletteController alloc] initWithWindowNibName:@"StylePalette" - supportDir:supportDir]; - - propertyInspectorController = - [[PropertyInspectorController alloc] initWithWindowNibName:@"PropertyInspector"]; - - [propertyInspectorController setStylePaletteController:stylePaletteController]; - - NSString *preamblePlist = [supportDir stringByAppendingPathComponent:@"preambles.plist"]; - preambleController = - [[PreambleController alloc] initWithWindowNibName:@"Preamble" - plist:preamblePlist - styles:[stylePaletteController nodeStyles] - edges:[stylePaletteController edgeStyles]]; - - - char template[] = "/tmp/tikzit_tmp_XXXXXXX"; - char *dir = mkdtemp(template); - tempDir = [NSString stringWithUTF8String:dir]; - - NSLog(@"created temp dir: %@", tempDir); - NSLog(@"system support dir: %@", [SupportDir systemSupportDir]); - - previewController = - [[PreviewController alloc] initWithWindowNibName:@"Preview" - preambleController:preambleController - tempDir:tempDir]; - - preferenceController = [[PreferenceController alloc] initWithWindowNibName:@"Preferences"]; - - // each application has one global preview controller - [PreviewController setDefaultPreviewController:previewController]; -} - -+ (void)setDefaults{ - NSString *userDefaultsValuesPath; - NSDictionary *userDefaultsValuesDict; - - userDefaultsValuesPath=[[NSBundle mainBundle] pathForResource:@"UserDefaults" - ofType:@"plist"]; - userDefaultsValuesDict=[NSDictionary dictionaryWithContentsOfFile:userDefaultsValuesPath]; - - [[NSUserDefaults standardUserDefaults] registerDefaults:userDefaultsValuesDict]; -} - -- (void)applicationWillTerminate:(NSNotification *)notification { - NSString *supportDir = [SupportDir userSupportDir]; - [stylePaletteController saveStyles:supportDir]; - [preambleController savePreambles:[supportDir stringByAppendingPathComponent:@"preambles.plist"]]; - - NSLog(@"wiping temp dir: %@", tempDir); - [[NSFileManager defaultManager] removeItemAtPath:tempDir error:NULL]; -} - -- (void)toggleController:(NSWindowController*)c { - if ([[c window] isVisible]) { - [c close]; - } else { - [c showWindow:self]; - } -} - -- (IBAction)toggleStyleInspector:(id)sender { - [self toggleController:stylePaletteController]; -} - -- (IBAction)togglePropertyInspector:(id)sender { - [self toggleController:propertyInspectorController]; -} - -- (IBAction)togglePreamble:(id)sender { - [self toggleController:preambleController]; -} - -- (IBAction)togglePreferences:(id)sender { - [self toggleController:preferenceController]; -} - -- (IBAction)refreshShapes:(id)sender { - [Shape refreshShapeDictionary]; -} - -@end diff --git a/tikzit/src/osx/CALayer+DrawLabel.h b/tikzit/src/osx/CALayer+DrawLabel.h deleted file mode 100644 index 32282d9..0000000 --- a/tikzit/src/osx/CALayer+DrawLabel.h +++ /dev/null @@ -1,21 +0,0 @@ -// -// CALayer+DrawLabel.h -// TikZiT -// -// Created by Aleks Kissinger on 09/05/2011. -// Copyright 2011 Aleks Kissinger. All rights reserved. -// - -#import <Cocoa/Cocoa.h> -#import <QuartzCore/CoreAnimation.h> - -@class Transformer; - -@interface CALayer(DrawLabel) - -- (void)drawLabel:(NSString*)label - atPoint:(NSPoint)pt - inContext:(CGContextRef)context - usingTrans:(Transformer*)t; - -@end diff --git a/tikzit/src/osx/CALayer+DrawLabel.m b/tikzit/src/osx/CALayer+DrawLabel.m deleted file mode 100644 index 4860a3c..0000000 --- a/tikzit/src/osx/CALayer+DrawLabel.m +++ /dev/null @@ -1,84 +0,0 @@ -// -// CALayer+DrawLabel.m -// TikZiT -// -// Created by Aleks Kissinger on 09/05/2011. -// Copyright 2011 Aleks Kissinger. All rights reserved. -// - -#import "CALayer+DrawLabel.h" -#import "Transformer.h" - -@implementation CALayer(DrawLabel) - -- (void)drawLabel:(NSString*)label - atPoint:(NSPoint)pt - inContext:(CGContextRef)context - usingTrans:(Transformer*)t { - - CGContextSaveGState(context); - - if ([label length] > 15) { - label = [[label substringToIndex:12] stringByAppendingString:@"..."]; - } - - float fontSize = [t scaleToScreen:0.18f]; // size 9 @ 100% - if (fontSize > 18.0f) fontSize = 18.0f; - - // Prepare font - CTFontRef font = CTFontCreateWithName(CFSTR("Monaco"), fontSize, NULL); - - // Create an attributed string - CFStringRef keys[] = { kCTFontAttributeName }; - CFTypeRef values[] = { font }; - CFDictionaryRef attr = CFDictionaryCreate(NULL, - (const void **)&keys, - (const void **)&values, - sizeof(keys) / sizeof(keys[0]), - &kCFTypeDictionaryKeyCallBacks, - &kCFTypeDictionaryValueCallBacks); - CFAttributedStringRef attrString = - CFAttributedStringCreate(NULL, (CFStringRef)label, attr); - CFRelease(attr); - - // Draw the string - CTLineRef line = CTLineCreateWithAttributedString(attrString); - CGContextSetTextMatrix(context, CGAffineTransformIdentity); - CGContextSetTextPosition(context, 0, 0); - - CGRect labelBounds = CGRectIntegral(CTLineGetImageBounds(line, context)); - //int shiftx = round(labelBounds.size.width / 2); - - CGContextSetTextPosition(context, - round(pt.x - (labelBounds.size.width/2)), - round(pt.y - (0.9*labelBounds.size.height/2))); - - labelBounds = CGRectIntegral(CTLineGetImageBounds(line, context)); - labelBounds.origin.x -= 2; - labelBounds.origin.y -= 2; - labelBounds.size.width += 4; - labelBounds.size.height += 4; - - CGContextSetShouldAntialias(context, NO); - - CGContextSetRGBFillColor(context, 1.0f, 1.0f, 0.5f, 0.7f); - CGContextSetRGBStrokeColor(context, 0.5f, 0.0f, 0.0f, 0.7f); - - CGContextFillRect(context, labelBounds); - CGContextStrokeRect(context, labelBounds); - - CGContextSetShouldAntialias(context, YES); - - CGContextSetRGBFillColor(context, 0.3f, 0.3f, 0.3f, 0.7f); - - CTLineDraw(line, context); - - // Clean up - CFRelease(line); - CFRelease(attrString); - CFRelease(font); - - CGContextRestoreGState(context); -} - -@end diff --git a/tikzit/src/osx/CoreGraphicsRenderContext.h b/tikzit/src/osx/CoreGraphicsRenderContext.h deleted file mode 100644 index 7b00484..0000000 --- a/tikzit/src/osx/CoreGraphicsRenderContext.h +++ /dev/null @@ -1,44 +0,0 @@ -/* - * Copyright 2011 Alex Merry <alex.merry@kdemail.net> - * - * 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 the Free Software Foundation; either version 2 of - * the License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see <http://www.gnu.org/licenses/>. - */ - -#import <Cocoa/Cocoa.h> -#import "RenderContext.h" - -@interface CoreTextLayout: NSObject<TextLayout> { - CFAttributedStringRef attrString; - CTFontRef font; - CTLineRef line; - CGContextRef ctx; -} - -+ (CoreTextLayout*) layoutForContext:(CGContextRef)c withString:(NSString*)string fontSize:(CGFloat)fontSize; -- (id) initWithContext:(CGContextRef)cr withString:(NSString*)string fontSize:(CGFloat)fontSize; - -@end - -@interface CoreGraphicsRenderContext: NSObject<RenderContext> { - CGContextRef ctx; -} - -+ (CoreGraphicsRenderContext*) contextWithCGContext:(CGContextRef)c; -+ (id) initWithCGContext:(CGContextRef)c; - -- (CGContextRef) ctx; - -@end - -// vim:ft=objc:ts=4:noet:sts=4:sw=4 diff --git a/tikzit/src/osx/CoreGraphicsRenderContext.m b/tikzit/src/osx/CoreGraphicsRenderContext.m deleted file mode 100644 index 1cb0daf..0000000 --- a/tikzit/src/osx/CoreGraphicsRenderContext.m +++ /dev/null @@ -1,234 +0,0 @@ -/* - * Copyright 2011 Alex Merry <alex.merry@kdemail.net> - * - * 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 the Free Software Foundation; either version 2 of - * the License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see <http://www.gnu.org/licenses/>. - */ - -#import <Cocoa/Cocoa.h> -#import "RenderContext.h" - -@implementation CoreTextLayout - -+ (CoreTextLayout*) layoutForContext:(CGContextRef)c withString:(NSString*)string fontSize:(CGFloat)fontSize { - return [[[self alloc] initWithContext:c withString:string fontSize:fontSize] autorelease]; -} - -- (id) initWithContext:(CGContextRef)cr withString:(NSString*)string fontSize:(CGFloat)fontSize { - self = [super init]; - - if (self == nil) { - return nil; - } - - CGContextRetain (cr); - ctx = cr; - font = CTFontCreateWithName(CFSTR("Monaco"), fontSize, NULL); - - // Create an attributed string - CFStringRef keys[] = { kCTFontAttributeName }; - CFTypeRef values[] = { font }; - CFDictionaryRef attr = CFDictionaryCreate(NULL, - (const void **)&keys, - (const void **)&values, - sizeof(keys) / sizeof(keys[0]), - &kCFTypeDictionaryKeyCallBacks, - &kCFTypeDictionaryValueCallBacks); - attrString = CFAttributedStringCreate(NULL, (CFStringRef)lab, attr); - CFRelease(attr); - line = CTLineCreateWithAttributedString(attrString); - - return self; -} - -- (NSSize) size { - CGRect labelBounds = CGRectIntegral(CTLineGetImageBounds(line, ctx)); - return labelBounds.size; -} - -- (NSString*) text { - return CFAttributedStringGetString (attrString); -} - -- (void) showTextAt:(NSPoint)topLeft withColor:(RColor)color { - CGContextSaveGState(ctx); - - CGContextSetRGBFillColor(ctx, color.red, color.green, color.blue, color.alpha); - CGContextSetRGBStrokeColor(ctx, color.red, color.green, color.blue, color.alpha); - CGContextSetShouldAntialias(ctx, YES); - - CGContextSetTextMatrix(ctx, CGAffineTransformIdentity); - CGContextSetTextPosition(ctx, 0, 0); - CGRect bounds = CGRectIntegral(CTLineGetImageBounds(line, ctx)); - CGContextSetTextPosition(ctx, topLeft.x - bounds.x, topLeft.y - bounds.y); - - CTLineDraw(line, ctx); - - CGContextRestoreGState(ctx); -} - -- (void) dealloc { - CFRelease(line); - CFRelease(attrString); - CFRelease(font); - CGContextRelease (ctx); - - [super dealloc]; -} - -@end - -@implementation CoreGraphicsRenderContext - -+ (CoreGraphicsRenderContext*) contextWithCGContext:(CGContextRef)c { - return [[[self alloc] initWithCGContext:c] autorelease]; -} - -+ (id) initWithCGContext:(CGContextRef)c { - self = [super init]; - - if (self) { - ctx = c; - CGContextRetain (ctx); - } - - return self; -} - -- (void) dealloc { - CGContextRelease (ctx); - - [super dealloc]; -} - -- (CGContextRef) ctx { - return ctx; -} - -- (void) saveState { - CGContextSaveGState(ctx); -} - -- (void) restoreState { - CGContextRestoreGState(ctx); -} - -- (NSRect) clipBoundingBox { - return CGContextGetClipBoundingBox (ctx); -} - -- (BOOL) strokeIncludesPoint:(NSPoint)p { - return CGContextPathContainsPoint(ctx, NSPointToCGPoint(p), kCGPathStroke); -} - -- (BOOL) fillIncludesPoint:(NSPoint)p { - return CGContextPathContainsPoint(ctx, NSPointToCGPoint(p), kCGPathFill); -} - -- (id<TextLayout>) layoutText:(NSString*)text withSize:(CGFloat)fontSize { - return [CoreTextLayout layoutForContext:ctx withString:text fontSize:fontSize]; -} - -// this may not affect text rendering -- (void) setAntialiasMode:(AntialiasMode)mode { - CGContextSetShouldAntialias(ctx, mode != AntialiasDisabled); -} - -- (void) setLineWidth:(CGFloat)width { - CGContextSetLineWidth(ctx, width); -} - -// setting to 0 will unset the dash -- (void) setLineDash:(CGFloat)dashLength { - if (dashLength <= 0.0f) { - CGContextSetLineDash(ctx, 0.0f, NULL, 0); - } else { - const CGFloat dash[] = {dashLength, dashLength}; - CGContextSetLineDash(ctx, 0.0f, dash, 2); - } -} - -// paths -- (void) startPath { - CGContextBeginPath (ctx); -} - -- (void) closeSubPath { - CGContextClosePath (ctx); -} - -- (void) moveTo:(NSPoint)p { - CGContextMoveToPoint (ctx, p.x, p.y); -} - -- (void) curveTo:(NSPoint)end withCp1:(NSPoint)cp1 andCp2:(NSPoint)cp2 { - CGContextAddCurveToPoint(ctx, cp1.x, cp1.y, cp2.x, cp2.y, end.x, end.y); -} - -- (void) lineTo:(NSPoint)end { - CGContextAddLineToPoint(ctx, end.x, end.y); -} - -- (void) rect:(NSRect)rect { - CGContextAddRect (ctx, rect); -} - -- (void) circleAt:(NSPoint)c withRadius:(CGFloat)r { - CGContextMoveToPoint (ctx, c.x + r, c.y); - CGContextAddArc (ctx, c.x, c.y, r, 0.0f, M_PI, 1); -} - -// these methods clear the path -- (void) strokePathWithColor:(RColor)color { - CGContextSetRGBStrokeColor(ctx, color.red, color.green, color.blue, color.alpha); - CGContextDrawPath (ctx, kCGPathStroke); -} - -- (void) fillPathWithColor:(RColor)color { - CGContextSetRGBFillColor(ctx, color.red, color.green, color.blue, color.alpha); - CGContextDrawPath (ctx, kCGPathFill); -} - -- (void) strokePathWithColor:(RColor)scolor - andFillWithColor:(RColor)fcolor { - CGContextSetRGBFillColor(ctx, color.red, color.green, color.blue, color.alpha); - CGContextSetRGBStrokeColor(ctx, color.red, color.green, color.blue, color.alpha); - CGContextDrawPath (ctx, kCGPathFillStroke); -} - -- (void) strokePathWithColor:(RColor)scolor - andFillWithColor:(RColor)fcolor - usingAlpha:(CGFloat)alpha { - CGContextSetRGBFillColor(ctx, color.red, color.green, color.blue, color.alpha * alpha); - CGContextSetRGBStrokeColor(ctx, color.red, color.green, color.blue, color.alpha * alpha); - CGContextDrawPath (ctx, kCGPathFillStroke); -} - -- (void) clipToPath { - CGContextClip (ctx); -} - -// paint everywhere within the clip -- (void) paintWithColor:(RColor)color { - CGContextSetRGBFillColor(ctx, color.red, color.green, color.blue, color.alpha); - CGRect r = CGContextGetClipBoundingBox (ctx); - r.origin.x -= 1; - r.origin.y -= 1; - r.size.width += 2; - r.size.height += 2; - CGContextFillRect(context, r); -} - -@end - -// vim:ft=objc:ts=4:noet:sts=4:sw=4 diff --git a/tikzit/src/osx/EdgeControlLayer.h b/tikzit/src/osx/EdgeControlLayer.h deleted file mode 100644 index 4cdf8bc..0000000 --- a/tikzit/src/osx/EdgeControlLayer.h +++ /dev/null @@ -1,44 +0,0 @@ -// -// EdgeControlLayer.h -// TikZiT -// -// Copyright 2010 Aleks Kissinger. All rights reserved. -// -// -// This file is part of TikZiT. -// -// TikZiT is free software: you can redistribute it and/or modify -// it under the terms of the GNU General Public License as published by -// the Free Software Foundation, either version 3 of the License, or -// (at your option) any later version. -// -// TikZiT is distributed in the hope that it will be useful, -// but WITHOUT ANY WARRANTY; without even the implied warranty of -// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -// GNU General Public License for more details. -// -// You should have received a copy of the GNU General Public License -// along with TikZiT. If not, see <http://www.gnu.org/licenses/>. -// - -#import <Cocoa/Cocoa.h> -#import <QuartzCore/CoreAnimation.h> -#import "Edge.h" -#import "Transformer.h" - - -@interface EdgeControlLayer : CALayer { - Edge *edge; - Transformer *transformer; - BOOL selected; -} - -- (id)initWithEdge:(Edge*)e andTransformer:(Transformer*)t; -- (void)highlight; -- (void)unhighlight; -- (void)select; -- (void)deselect; - -+ (float)handleRadius; - -@end diff --git a/tikzit/src/osx/EdgeControlLayer.m b/tikzit/src/osx/EdgeControlLayer.m deleted file mode 100644 index 377cde4..0000000 --- a/tikzit/src/osx/EdgeControlLayer.m +++ /dev/null @@ -1,150 +0,0 @@ -// -// EdgeControlLayer.m -// TikZiT -// -// Copyright 2010 Aleks Kissinger. All rights reserved. -// -// -// This file is part of TikZiT. -// -// TikZiT is free software: you can redistribute it and/or modify -// it under the terms of the GNU General Public License as published by -// the Free Software Foundation, either version 3 of the License, or -// (at your option) any later version. -// -// TikZiT is distributed in the hope that it will be useful, -// but WITHOUT ANY WARRANTY; without even the implied warranty of -// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -// GNU General Public License for more details. -// -// You should have received a copy of the GNU General Public License -// along with TikZiT. If not, see <http://www.gnu.org/licenses/>. -// - -#import "EdgeControlLayer.h" -#import "util.h" - - -@implementation EdgeControlLayer - - -- (id)initWithEdge:(Edge*)e andTransformer:(Transformer*)t { - [super init]; - transformer = t; - edge = e; - self.opacity = 0.0f; - return self; -} - -- (void)select { - selected = YES; - self.opacity = 1.0f; -} - -- (void)deselect { - selected = NO; - self.opacity = 0.0f; -} - -- (void)highlight { - if (!selected) { - self.opacity = 0.5f; - } -} - -- (void)unhighlight { - if (!selected) { - self.opacity = 0.0f; - } -} - -- (void)drawInContext:(CGContextRef)ctx { - CGContextSaveGState(ctx); - - [edge updateControls]; - CGPoint source = NSPointToCGPoint([transformer toScreen:[[edge source] point]]); - CGPoint target = NSPointToCGPoint([transformer toScreen:[[edge target] point]]); - CGPoint mid = NSPointToCGPoint([transformer toScreen:[edge mid]]); - CGPoint cp1 = NSPointToCGPoint([transformer toScreen:[edge cp1]]); - CGPoint cp2 = NSPointToCGPoint([transformer toScreen:[edge cp2]]); - - float dx = (target.x - source.x); - float dy = (target.y - source.y); - - // draw a circle at the midpoint - CGRect mid_rect = CGRectMake(mid.x-3.0f, mid.y-3.0f, 6.0f, 6.0f); - CGContextAddEllipseInRect(ctx, mid_rect); - CGContextSetLineWidth(ctx, 1.0f); - CGContextSetRGBFillColor(ctx, 1.0f, 1.0f, 1.0f, 0.5f); - CGContextSetRGBStrokeColor(ctx, 0.0f, 0.0f, 1.0f, 0.5f); - CGContextDrawPath(ctx, kCGPathFillStroke); - - - CGContextSetShouldAntialias(ctx, YES); - - // compute size of control circles - float cdist; - if (dx == 0 && dy == 0) cdist = [transformer scaleToScreen:edge.weight]; - else cdist = sqrt(dx*dx + dy*dy) * edge.weight; - - // if basic bend, draw blue, if inout, draw green - if ([edge bendMode] == EdgeBendModeBasic) CGContextSetRGBStrokeColor(ctx, 0, 0, 1, 0.4f); - else CGContextSetRGBStrokeColor(ctx, 0, 0.7f, 0, 0.4f); - - // draw source control circle - CGRect ellipse1 = CGRectMake(source.x-cdist, source.y-cdist, cdist*2.0f, cdist*2.0f); - CGContextAddEllipseInRect(ctx, ellipse1); - if (dx!=0 || dy!=0) { - CGRect ellipse2 = CGRectMake(target.x-cdist, target.y-cdist, cdist*2.0f, cdist*2.0f); - CGContextAddEllipseInRect(ctx, ellipse2); - } - - CGContextStrokePath(ctx); - - float handleRad = [EdgeControlLayer handleRadius]; - - // handles - CGRect ctrl1 = CGRectMake(cp1.x-handleRad, cp1.y-handleRad, 2*handleRad, 2*handleRad); - CGRect ctrl2 = CGRectMake(cp2.x-handleRad, cp2.y-handleRad, 2*handleRad, 2*handleRad); - - CGContextSetRGBFillColor(ctx, 1.0f, 1.0f, 1.0f, 0.8f); - - // draw a line from source vertex to first handle - if ([edge bendMode] == EdgeBendModeInOut) { - if ([edge outAngle] % 45 == 0) CGContextSetRGBStrokeColor(ctx, 1, 0, 1, 0.6f); - else CGContextSetRGBStrokeColor(ctx, 0, 0.7f, 0, 0.4f); - } else { - if ([edge bend] % 45 == 0) CGContextSetRGBStrokeColor(ctx, 1, 0, 1, 0.6f); - else CGContextSetRGBStrokeColor(ctx, 0, 0, 1, 0.4f); - } - - CGContextMoveToPoint(ctx, source.x, source.y); - CGContextAddLineToPoint(ctx, cp1.x, cp1.y); - CGContextStrokePath(ctx); - - CGContextAddEllipseInRect(ctx, ctrl1); - CGContextDrawPath(ctx, kCGPathFillStroke); - - - // draw a line from target vertex to second handle - if ([edge bendMode] == EdgeBendModeInOut) { - if ([edge inAngle] % 45 == 0) CGContextSetRGBStrokeColor(ctx, 1, 0, 1, 0.6f); - else CGContextSetRGBStrokeColor(ctx, 0, 0.7f, 0, 0.4f); - } else { - if ([edge bend] % 45 == 0) CGContextSetRGBStrokeColor(ctx, 1, 0, 1, 0.6f); - else CGContextSetRGBStrokeColor(ctx, 0, 0, 1, 0.4f); - } - - CGContextMoveToPoint(ctx, target.x, target.y); - CGContextAddLineToPoint(ctx, cp2.x, cp2.y); - CGContextStrokePath(ctx); - - CGContextAddEllipseInRect(ctx, ctrl2); - CGContextDrawPath(ctx, kCGPathFillStroke); - - CGContextRestoreGState(ctx); -} - -+ (float)handleRadius { return 4.0f; } - -@end diff --git a/tikzit/src/osx/EdgeStyle+Coder.h b/tikzit/src/osx/EdgeStyle+Coder.h deleted file mode 100644 index e35c18f..0000000 --- a/tikzit/src/osx/EdgeStyle+Coder.h +++ /dev/null @@ -1,30 +0,0 @@ -// -// EdgeStyle+Coder.h -// TikZiT -// -// Copyright 2011 Aleks Kissinger. All rights reserved. -// -// -// This file is part of TikZiT. -// -// TikZiT is free software: you can redistribute it and/or modify -// it under the terms of the GNU General Public License as published by -// the Free Software Foundation, either version 3 of the License, or -// (at your option) any later version. -// -// TikZiT is distributed in the hope that it will be useful, -// but WITHOUT ANY WARRANTY; without even the implied warranty of -// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -// GNU General Public License for more details. -// -// You should have received a copy of the GNU General Public License -// along with TikZiT. If not, see <http://www.gnu.org/licenses/>. -// - -#import <Cocoa/Cocoa.h> -#import "EdgeStyle.h" - -@interface EdgeStyle (Coder) -- (id)initWithCoder:(NSCoder*)coder; -- (void)encodeWithCoder:(NSCoder*)coder; -@end diff --git a/tikzit/src/osx/EdgeStyle+Coder.m b/tikzit/src/osx/EdgeStyle+Coder.m deleted file mode 100644 index 208fac0..0000000 --- a/tikzit/src/osx/EdgeStyle+Coder.m +++ /dev/null @@ -1,50 +0,0 @@ -// -// EdgeStyle+Coder.m -// TikZiT -// -// Copyright 2011 Aleks Kissinger. All rights reserved. -// -// -// This file is part of TikZiT. -// -// TikZiT is free software: you can redistribute it and/or modify -// it under the terms of the GNU General Public License as published by -// the Free Software Foundation, either version 3 of the License, or -// (at your option) any later version. -// -// TikZiT is distributed in the hope that it will be useful, -// but WITHOUT ANY WARRANTY; without even the implied warranty of -// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -// GNU General Public License for more details. -// -// You should have received a copy of the GNU General Public License -// along with TikZiT. If not, see <http://www.gnu.org/licenses/>. -// - -#import "EdgeStyle+Coder.h" - -@implementation EdgeStyle (Coder) - -- (id)initWithCoder:(NSCoder*)coder { - [super init]; - - name = [coder decodeObjectForKey:@"name"]; - category = [coder decodeObjectForKey:@"category"]; - headStyle = [coder decodeIntForKey:@"headStyle"]; - tailStyle = [coder decodeIntForKey:@"tailStyle"]; - decorationStyle = [coder decodeIntForKey:@"decorationStyle"]; - thickness = [coder decodeFloatForKey:@"thickness"]; - - return self; -} - -- (void)encodeWithCoder:(NSCoder*)coder { - [coder encodeObject:name forKey:@"name"]; - [coder encodeObject:category forKey:@"category"]; - [coder encodeInt:headStyle forKey:@"headStyle"]; - [coder encodeInt:tailStyle forKey:@"tailStyle"]; - [coder encodeInt:decorationStyle forKey:@"decorationStyle"]; - [coder encodeFloat:thickness forKey:@"thickness"]; -} - -@end diff --git a/tikzit/src/osx/Graph+Coder.h b/tikzit/src/osx/Graph+Coder.h deleted file mode 100644 index 1404fc2..0000000 --- a/tikzit/src/osx/Graph+Coder.h +++ /dev/null @@ -1,17 +0,0 @@ -// -// Graph+Coder.h -// TikZiT -// -// Created by Aleks Kissinger on 27/04/2010. -// Copyright 2010 __MyCompanyName__. All rights reserved. -// - -#import <Foundation/Foundation.h> -#import "Graph.h" - -@interface Graph (Coder) - -- (id)initWithCoder:(NSCoder*)coder; -- (void)encodeWithCoder:(NSCoder*)coder; - -@end diff --git a/tikzit/src/osx/Graph+Coder.m b/tikzit/src/osx/Graph+Coder.m deleted file mode 100644 index 7d3787e..0000000 --- a/tikzit/src/osx/Graph+Coder.m +++ /dev/null @@ -1,24 +0,0 @@ -// -// Graph+Coder.m -// TikZiT -// -// Created by Aleks Kissinger on 27/04/2010. -// Copyright 2010 __MyCompanyName__. All rights reserved. -// - -#import "Graph+Coder.h" -#import "TikzGraphAssembler.h" - -@implementation Graph(Coder) - -- (id)initWithCoder:(NSCoder*)coder { - NSString *tikz = [coder decodeObject]; - [TikzGraphAssembler parseTikz:tikz forGraph:self]; - return self; -} - -- (void)encodeWithCoder:(NSCoder*)coder { - [coder encodeObject:[self tikz]]; -} - -@end diff --git a/tikzit/src/osx/GraphicsView.h b/tikzit/src/osx/GraphicsView.h deleted file mode 100644 index e963ac7..0000000 --- a/tikzit/src/osx/GraphicsView.h +++ /dev/null @@ -1,129 +0,0 @@ -// -// GraphicsView.h -// TikZiT -// -// Copyright 2010 Aleks Kissinger. All rights reserved. -// -// -// This file is part of TikZiT. -// -// TikZiT is free software: you can redistribute it and/or modify -// it under the terms of the GNU General Public License as published by -// the Free Software Foundation, either version 3 of the License, or -// (at your option) any later version. -// -// TikZiT is distributed in the hope that it will be useful, -// but WITHOUT ANY WARRANTY; without even the implied warranty of -// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -// GNU General Public License for more details. -// -// You should have received a copy of the GNU General Public License -// along with TikZiT. If not, see <http://www.gnu.org/licenses/>. -// - -#import <Cocoa/Cocoa.h> -#import <QuartzCore/CoreAnimation.h> -#import "PickSupport.h" -#import "Grid.h" -#import "Transformer.h" -#import "Graph.h" -#import "NodeStyle.h" -#import "StylePaletteController.h" -#import "ToolPaletteController.h" -#import "SelectBoxLayer.h" - -// mouse modes, corresponding to different tools. format: (tool)[sub-mode]Mode -typedef enum { - SelectMode = 0x10, - SelectBoxMode = 0x11, - SelectMoveMode = 0x12, - SelectEdgeBendMode = 0x14, - - NodeMode = 0x20, - - EdgeMode = 0x40, - EdgeDragMode = 0x41, - - CropMode = 0x80, - CropDragMode = 0x81 -} MouseMode; - -@class TikzSourceController; - -@interface GraphicsView : NSView { - BOOL enabled; - - IBOutlet NSApplication *application; - StylePaletteController *stylePaletteController; - ToolPaletteController *toolPaletteController; - - BOOL frameMoveMode; - - Graph *graph; - NSString *graphTikzOnMouseDown; - PickSupport *pickSupport; - //NSMapTable *nodeSelectionLayers; - NSMapTable *edgeControlLayers; - NSMapTable *nodeLayers; - NSPoint dragOrigin; - NSPoint dragTarget; - NSPoint oldTransformerOrigin; - NSPoint oldMainOrigin; - NSRect oldBounds; - //NSRect selectionBox; - Transformer *transformer; - - CALayer *mainLayer; - CALayer *gridLayer; - CALayer *graphLayer; - CALayer *hudLayer; - SelectBoxLayer *selectionLayer; - - MouseMode mouseMode; - Node *leaderNode; - Grid *grid; - - Edge *modifyEdge; - BOOL firstControlPoint; - - int bboxLeftRight; - int bboxBottomTop; - - NSUndoManager *documentUndoManager; - NSPoint startPoint; - - TikzSourceController *tikzSourceController; -} - -@property BOOL enabled; -@property Graph *graph; -@property IBOutlet TikzSourceController *tikzSourceController; -@property (readonly) Transformer *transformer; -@property (readonly) PickSupport *pickSupport; - -- (void)setDocumentUndoManager:(NSUndoManager*)um; -- (void)applyStyleToSelectedNodes:(NodeStyle*)style; -- (void)applyStyleToSelectedEdges:(EdgeStyle*)style; - -- (void)updateMouseMode; -- (void)refreshLayers; - -//- (void)registerUndo:(GraphChange *)change withActionName:(NSString*)name; -- (void)registerUndo:(NSString*)oldTikz withActionName:(NSString*)name; -//- (void)undoGraphChange:(GraphChange *)change; -- (void)undoGraphChange:(NSString*)oldTikz; -- (void)postGraphChange; -- (void)postSelectionChange; - -- (void)deselectAll:(id)sender; -- (void)selectAll:(id)sender; -- (void)cut:(id)sender; -- (void)copy:(id)sender; -- (void)paste:(id)sender; -- (void)delete:(id)sender; -- (void)bringForward:(id)sender; -- (void)flipHorizonal:(id)sender; -- (void)flipVertical:(id)sender; -- (void)reverseEdgeDirection:(id)sender; - -@end diff --git a/tikzit/src/osx/GraphicsView.m b/tikzit/src/osx/GraphicsView.m deleted file mode 100644 index 49b1af6..0000000 --- a/tikzit/src/osx/GraphicsView.m +++ /dev/null @@ -1,1216 +0,0 @@ -// -// GraphicsView.m -// TikZiT -// -// Copyright 2010 Aleks Kissinger. All rights reserved. -// -// -// This file is part of TikZiT. -// -// TikZiT is free software: you can redistribute it and/or modify -// it under the terms of the GNU General Public License as published by -// the Free Software Foundation, either version 3 of the License, or -// (at your option) any later version. -// -// TikZiT is distributed in the hope that it will be useful, -// but WITHOUT ANY WARRANTY; without even the implied warranty of -// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -// GNU General Public License for more details. -// -// You should have received a copy of the GNU General Public License -// along with TikZiT. If not, see <http://www.gnu.org/licenses/>. -// - -#import "GraphicsView.h" -#import "util.h" -#import "CALayer+DrawLabel.h" - -#import "NodeSelectionLayer.h" -#import "NodeLayer.h" -#import "EdgeControlLayer.h" -#import "AppDelegate.h" -#import "TikzGraphAssembler.h" -#import "TikzSourceController.h" - -@interface GraphicsView (Private) -- (void)setupLayers; -- (void)addNodeLayers:(Node*)n; -- (void)addEdgeLayers:(Edge*)e; -- (void)removeNodeLayers:(Node*)n; -- (void)resetMainOrigin; -- (void)setMainOrigin:(NSPoint)o; -@end - -static CGColorRef cgGrayColor, cgWhiteColor, cgClearColor = nil; - - -@implementation GraphicsView - -@synthesize enabled, transformer, pickSupport, tikzSourceController; - -- (void)postGraphChange { - [[NSNotificationCenter defaultCenter] postNotificationName:@"GraphChanged" - object:self]; - [self postSelectionChange]; -} - -- (void)postSelectionChange { - [[NSNotificationCenter defaultCenter] postNotificationName:@"SelectionChanged" - object:self]; -} - -- (id)initWithFrame:(NSRect)frame { - self = [super initWithFrame:frame]; - if (self) { - if (cgClearColor == nil) { - cgClearColor = CGColorGetConstantColor(kCGColorClear); - cgGrayColor = CGColorCreateGenericGray(0.5f, 0.5f); - cgWhiteColor = CGColorCreateGenericRGB(1, 1, 1, 1); - } - - transformer = [[Transformer alloc] init]; - mouseMode = SelectMode; - grid = [Grid gridWithSpacing:1.0f - subdivisions:4 - transformer:transformer]; - [grid setSize:NSSizeFromCGSize([gridLayer bounds].size)]; - [transformer setScale:PIXELS_PER_UNIT]; - - [self setupLayers]; - - leaderNode = nil; - pickSupport = [[PickSupport alloc] init]; - frameMoveMode = NO; - - enabled = YES; - [self setGraph:[Graph graph]]; - } - return self; -} - -- (void)awakeFromNib { - AppDelegate *del = [application delegate]; - stylePaletteController = [del stylePaletteController]; - toolPaletteController = [del toolPaletteController]; - [self refreshLayers]; - [self postGraphChange]; -} - -- (void)setupLayers { - mainLayer = [CALayer layer]; - [mainLayer setBackgroundColor:cgWhiteColor]; - [mainLayer setFrame:CGRectIntegral(NSRectToCGRect([self bounds]))]; - [mainLayer setOpacity:1.0f]; - [self setLayer:mainLayer]; - [self resetMainOrigin]; - - gridLayer = [CALayer layer]; - [gridLayer setDelegate:grid]; - [gridLayer setOpacity:0.3f]; - [mainLayer addSublayer:gridLayer]; - - graphLayer = [CALayer layer]; - [graphLayer setDelegate:self]; - [mainLayer addSublayer:graphLayer]; - - hudLayer = [CALayer layer]; - [mainLayer addSublayer:hudLayer]; - - selectionLayer = [SelectBoxLayer layer]; - [mainLayer addSublayer:selectionLayer]; - - [transformer setOrigin:NSMakePoint(NSMidX([self bounds]),NSMidY([self bounds]))]; - oldBounds = [self bounds]; - [self refreshLayers]; -} - -// Lion resume feature -//- (void)encodeRestorableStateWithCoder:(NSCoder*)coder { -// NSLog(@"got encode request"); -//} -//- (void)restoreStateWithCoder:(NSCoder*)coder { -// NSLog(@"got decode request"); -//} - -- (void)registerUndo:(NSString*)oldTikz withActionName:(NSString*)nm { - [documentUndoManager registerUndoWithTarget:self - selector:@selector(undoGraphChange:) - object:oldTikz]; - [documentUndoManager setActionName:nm]; -} - -- (void)revertToTikz:(NSString*)tikz { - [tikzSourceController setTikz:tikz]; - [tikzSourceController tryParseTikz]; - [self refreshLayers]; - [self postGraphChange]; -} - - -- (void)undoGraphChange:(NSString*)oldTikz { - NSString *currentTikz = [graph tikz]; - [self revertToTikz:oldTikz]; - [documentUndoManager registerUndoWithTarget:self - selector:@selector(undoGraphChange:) - object:currentTikz]; -} - -- (void)setGraph:(Graph*)gr { - graph = gr; - - NSEnumerator *e; - CALayer *layer; - - e = [edgeControlLayers objectEnumerator]; - while (layer = [e nextObject]) [layer removeFromSuperlayer]; - edgeControlLayers = [NSMapTable mapTableWithStrongToStrongObjects]; - - - e = [nodeLayers objectEnumerator]; - while (layer = [e nextObject]) [layer removeFromSuperlayer]; - nodeLayers = [NSMapTable mapTableWithStrongToStrongObjects]; - - for (Node *n in [graph nodes]) { - [n attachStyleFromTable:[stylePaletteController nodeStyles]]; - [self addNodeLayers:n]; - } - - for (Edge *e in [graph edges]) { - [e setAttributesFromData]; - [e attachStyleFromTable:[stylePaletteController edgeStyles]]; - [self addEdgeLayers:e]; - } -} - -- (Graph*)graph { return graph; } - -- (void)setMainOrigin:(NSPoint)o { - o.x = round(o.x); - o.y = round(o.y); - CGRect rect = [mainLayer frame]; - rect.origin = NSPointToCGPoint(o); - [mainLayer setFrame:rect]; -} - -- (void)resetMainOrigin { - NSRect bds = [self bounds]; - bds.origin.x -= bds.size.width; - bds.origin.y -= bds.size.height; - bds.size.width *= 3; - bds.size.height *= 3; - [mainLayer setFrame:NSRectToCGRect([self bounds])]; -} - -- (void)refreshLayers { - [gridLayer setFrame:[mainLayer frame]]; - [graphLayer setFrame:[mainLayer frame]]; - [hudLayer setFrame:[mainLayer frame]]; - [selectionLayer setFrame:[mainLayer frame]]; - - if (enabled) { - [hudLayer setBackgroundColor:cgClearColor]; - } else { - [hudLayer setBackgroundColor:cgGrayColor]; - } - - [grid setSize:NSSizeFromCGSize([gridLayer bounds].size)]; - [gridLayer setNeedsDisplay]; - [graphLayer setNeedsDisplay]; - [hudLayer setNeedsDisplay]; - - NSEnumerator *e = [edgeControlLayers objectEnumerator]; - CALayer *layer; - while (layer = [e nextObject]) { - [layer setFrame:[graphLayer frame]]; - [layer setNeedsDisplay]; - } -} - - -- (void)viewDidEndLiveResize { - [super viewDidEndLiveResize]; - NSPoint o = [transformer origin]; - o.x += round(([self bounds].size.width - oldBounds.size.width)/2.0f); - o.y += round(([self bounds].size.height - oldBounds.size.height)/2.0f); - [transformer setOrigin:o]; - oldBounds = [self bounds]; - [self refreshLayers]; -} - -- (void)applyStyleToSelectedNodes:(NodeStyle*)style { - NSString *oldTikz = [graph tikz]; - - for (Node *n in [pickSupport selectedNodes]) { - [n setStyle:style]; - [[nodeLayers objectForKey:n] setNeedsDisplay]; - } - - [self registerUndo:oldTikz withActionName:@"Apply Style to Nodes"]; - [self refreshLayers]; - [self postGraphChange]; -} - -- (void)applyStyleToSelectedEdges:(EdgeStyle*)style { - NSString *oldTikz = [graph tikz]; - - for (Edge *e in [pickSupport selectedEdges]) { - [e setStyle:style]; - } - - [self registerUndo:oldTikz withActionName:@"Apply Style to Edges"]; - [self refreshLayers]; - [self postGraphChange]; -} - -- (void)addNodeLayers:(Node*)n { - // add a node to the graph - [graph addNode:n]; - - NSPoint pt = [transformer toScreen:[n point]]; - - // add a node layer - NodeLayer *nl = [[NodeLayer alloc] initWithNode:n transformer:transformer]; - [nl setCenter:pt]; - [nodeLayers setObject:nl forKey:n]; - [graphLayer addSublayer:nl]; - [nl setNeedsDisplay]; -} - -- (void)removeNodeLayers:(Node*)n { - [[nodeLayers objectForKey:n] removeFromSuperlayer]; - [nodeLayers removeObjectForKey:n]; -} - -- (void)addEdgeLayers:(Edge *)e { - [graph addEdge:e]; - EdgeControlLayer *ecl = [[EdgeControlLayer alloc] initWithEdge:e andTransformer:transformer]; - [edgeControlLayers setObject:ecl forKey:e]; - [ecl setFrame:CGRectMake(10, 10, 100, 100)]; - [hudLayer addSublayer:ecl]; - [ecl setNeedsDisplay]; -} - -- (void)removeEdgeLayers:(Edge*)e { - [[edgeControlLayers objectForKey:e] removeFromSuperlayer]; - [edgeControlLayers removeObjectForKey:e]; - [self refreshLayers]; -} - -- (BOOL)circleWithCenter:(NSPoint)center andRadius:(float)radius containsPoint:(NSPoint)p { - float dx = center.x - p.x; - float dy = center.y - p.y; - return (dx*dx + dy*dy) <= radius*radius; -} - -- (BOOL)node:(Node*)node containsPoint:(NSPoint)p { - NodeLayer *nl = [nodeLayers objectForKey:node]; - return [nl nodeContainsPoint:p]; -} - -- (BOOL)edge:(Edge*)edge containsPoint:(NSPoint)p { -// NSPoint center = [transformer toScreen:edge.mid]; -// float dx = center.x - p.x; -// float dy = center.y - p.y; -// float radius = 5.0f; // tolerence for clicks -// return (dx*dx + dy*dy) <= radius*radius; - - CGContextRef ctx = (CGContextRef)[[NSGraphicsContext currentContext] graphicsPort]; - - // Save the graphics state before doing the hit detection. - CGContextSaveGState(ctx); - - NSPoint src = [transformer toScreen:[edge tail]]; - NSPoint targ = [transformer toScreen:[edge head]]; - NSPoint cp1 = [transformer toScreen:[edge cp1]]; - NSPoint cp2 = [transformer toScreen:[edge cp2]]; - - CGContextSetLineWidth(ctx, 8.0f); - - CGContextMoveToPoint(ctx, src.x, src.y); - CGContextAddCurveToPoint(ctx, cp1.x, cp1.y, cp2.x, cp2.y, targ.x, targ.y); - - BOOL containsPoint = CGContextPathContainsPoint(ctx, NSPointToCGPoint(p), kCGPathStroke); - - CGContextSetRGBStrokeColor(ctx, 0, 0, 0, 0); - - CGContextStrokePath(ctx); - //CGContextFlush(ctx); - CGContextRestoreGState(ctx); - - return containsPoint; -} - -- (void)shiftNodes:(NSSet*)set from:(NSPoint)source to:(NSPoint)dest { - float dx = dest.x - source.x; - float dy = dest.y - source.y; - - for (Node *n in set) { - NSPoint p = [transformer toScreen:[n point]]; - p = [grid snapScreenPoint:NSMakePoint(p.x+dx, p.y+dy)]; - [n setPoint:[transformer fromScreen:p]]; - } -} - - -- (void)mouseDown:(NSEvent*)theEvent { - if (!enabled) return; - - [self updateMouseMode]; - - dragOrigin = [self convertPoint:[theEvent locationInWindow] fromView:nil]; - dragTarget = dragOrigin; - - graphTikzOnMouseDown = [graph tikz]; - - if ([theEvent modifierFlags] & NSCommandKeyMask) { - oldTransformerOrigin = [transformer origin]; - oldMainOrigin = [self frame].origin; - frameMoveMode = YES; - return; - } - - if (mouseMode == SelectMode) { - [selectionLayer setActive:YES]; - [selectionLayer setSelectBox:NSRectAroundPoints(dragOrigin, dragOrigin)]; - [selectionLayer setNeedsDisplay]; - - modifyEdge = nil; - NSPoint cp1, cp2; - for (Edge *e in [pickSupport selectedEdges]) { - cp1 = [transformer toScreen:[e cp1]]; - cp2 = [transformer toScreen:[e cp2]]; - if ([self circleWithCenter:cp1 - andRadius:[EdgeControlLayer handleRadius] - containsPoint:dragOrigin]) - { - mouseMode = SelectEdgeBendMode; - modifyEdge = e; - firstControlPoint = YES; - break; - } else if ([self circleWithCenter:cp2 - andRadius:[EdgeControlLayer handleRadius] - containsPoint:dragOrigin]) - { - mouseMode = SelectEdgeBendMode; - modifyEdge = e; - firstControlPoint = NO; - break; - } - } - - if (modifyEdge == nil) { // skip all the rest if we're modifying an edge - - leaderNode = nil; - - // in first pass, try to find a leader node, under the mouse - for (Node* n in [graph nodes]) { - if ([self node:n containsPoint:dragOrigin]) { - leaderNode = n; - [gridLayer setOpacity:1.0f]; - break; - } - } - - // if we found one, deselect the others (if appropriate) and go to move mode - if (leaderNode != nil) { - startPoint = [leaderNode point]; - - // if we select a node, we should always deselect all edges: - for (Edge *e in [graph edges]) [[edgeControlLayers objectForKey:e] deselect]; - [pickSupport deselectAllEdges]; - - BOOL shouldDeselect = - !([theEvent modifierFlags] & NSShiftKeyMask) - && ![pickSupport isNodeSelected:leaderNode]; - for (Node *n in [graph nodes]) { - if (n != leaderNode && shouldDeselect) { - [pickSupport deselectNode:n]; - [[[nodeLayers objectForKey:n] selection] deselect]; - } - } - - // ensure the leader node is actually selected - if (![pickSupport isNodeSelected:leaderNode]) { - [pickSupport selectNode:leaderNode]; - [[[nodeLayers objectForKey:leaderNode] selection] select]; - } - - - // put us in move mode - mouseMode = SelectMoveMode; - } else { - mouseMode = SelectBoxMode; - - // if we didn't select a node, start hunting for an edge to select - BOOL shouldDeselect = !([theEvent modifierFlags] & NSShiftKeyMask); - - if (shouldDeselect) { - [pickSupport deselectAllEdges]; - for (Edge *e in graph.edges) [[edgeControlLayers objectForKey:e] deselect]; - } - - for (Edge* e in [graph edges]) { - // find the first node under the pointer, select it, show its controls - // and deselect all others if shift isn't down - if ([self edge:e containsPoint:dragOrigin]) { - for (Node *n in [pickSupport selectedNodes]) [[[nodeLayers objectForKey:n] selection] deselect]; - - [pickSupport deselectAllNodes]; - [pickSupport selectEdge:e]; - [[edgeControlLayers objectForKey:e] select]; - break; - } - } // end for e in [graph edges] - } // end if leaderNode == nil - } // end if modifyEdge == nil - - } else if (mouseMode == NodeMode) { - // do nothing... - } else if (mouseMode == EdgeMode) { - for (Node *n in [graph nodes]) { - if ([self node:n containsPoint:dragOrigin]) { - [[[nodeLayers objectForKey:n] selection] highlight]; - } - } - mouseMode = EdgeDragMode; - } else if (mouseMode == CropMode) { - if ([graph hasBoundingBox]) { - float fudge = 3; - - NSRect bb = [graph boundingBox]; - NSPoint bl = [transformer toScreen:bb.origin]; - NSPoint tr = [transformer - toScreen:NSMakePoint(bb.origin.x+bb.size.width, - bb.origin.y+bb.size.height)]; - if (dragOrigin.x > bl.x-fudge && dragOrigin.x < tr.x+fudge && - dragOrigin.y > tr.y-fudge && dragOrigin.y < tr.y+fudge) - { - bboxBottomTop = 1; - } else if (dragOrigin.x > bl.x-fudge && dragOrigin.x < tr.x+fudge && - dragOrigin.y > bl.y-fudge && dragOrigin.y < bl.y+fudge) - { - bboxBottomTop = -1; - } else { - bboxBottomTop = 0; - } - - if (dragOrigin.y > bl.y-fudge && dragOrigin.y < tr.y+fudge && - dragOrigin.x > tr.x-fudge && dragOrigin.x < tr.x+fudge) - { - bboxLeftRight = 1; - } else if (dragOrigin.y > bl.y-fudge && dragOrigin.y < tr.y+fudge && - dragOrigin.x > bl.x-fudge && dragOrigin.x < bl.x+fudge) - { - bboxLeftRight = -1; - } else { - bboxLeftRight = 0; - } - - if (bboxBottomTop != 0 || bboxLeftRight != 0) { - mouseMode = CropDragMode; - } - } - } else { - printf("WARNING: MOUSE DOWN IN INVALID MODE.\n"); - } - - [self refreshLayers]; -} - -- (void)mouseDragged:(NSEvent *)theEvent { - if (!enabled) return; - dragTarget = [self convertPoint:[theEvent locationInWindow] fromView:nil]; - - if (frameMoveMode) { - NSPoint newTransOrigin, newMainOrigin; - NSPoint diff = NSMakePoint(dragTarget.x - dragOrigin.x, dragTarget.y - dragOrigin.y); - newTransOrigin.x = oldTransformerOrigin.x + diff.x; - newTransOrigin.y = oldTransformerOrigin.y + diff.y; - newMainOrigin.x = oldMainOrigin.x + diff.x; - newMainOrigin.y = oldMainOrigin.y + diff.y; - - [CATransaction begin]; - [CATransaction setValue:(id)kCFBooleanTrue forKey:kCATransactionDisableActions]; - [self setMainOrigin:newMainOrigin]; - [CATransaction commit]; - - [transformer setOrigin:newTransOrigin]; - return; - } - - if (mouseMode == SelectBoxMode) { - [selectionLayer setSelectBox:NSRectAroundPoints(dragOrigin, dragTarget)]; - [selectionLayer setNeedsDisplay]; - - for (Node* n in [graph nodes]) { - if (NSPointInRect([transformer toScreen:[n point]], [selectionLayer selectBox])) { - [[[nodeLayers objectForKey:n] selection] highlight]; - } else if (!([theEvent modifierFlags] & NSShiftKeyMask)) { - [[[nodeLayers objectForKey:n] selection] unhighlight]; - } - } - } else if (mouseMode == SelectMoveMode) { - if (leaderNode != nil) { - [self shiftNodes:[pickSupport selectedNodes] - from:[transformer toScreen:[leaderNode point]] - to:dragTarget]; - } else { - printf("WARNING: LEADER NODE SHOULD NOT BE NIL.\n"); - } - - [self refreshLayers]; - } else if (mouseMode == SelectEdgeBendMode) { - NSPoint src = [transformer toScreen:[[modifyEdge source] point]]; - NSPoint targ = [transformer toScreen:[[modifyEdge target] point]]; - float dx1 = targ.x - src.x; - float dy1 = targ.y - src.y; - float dx2, dy2; - if (firstControlPoint) { - dx2 = dragTarget.x - src.x; - dy2 = dragTarget.y - src.y; - } else { - dx2 = dragTarget.x - targ.x; - dy2 = dragTarget.y - targ.y; - } - float base_dist = sqrt(dx1*dx1 + dy1*dy1); - float handle_dist = sqrt(dx2*dx2 + dy2*dy2); - float wcourseness = 0.1f; - - if (![modifyEdge isSelfLoop]) { - if (base_dist != 0) { - [modifyEdge setWeight:roundToNearest(wcourseness, handle_dist/base_dist)]; - //round(handle_dist / (base_dist*wcourseness)) * wcourseness; - } else { - [modifyEdge setWeight: - roundToNearest(wcourseness, [transformer scaleFromScreen:handle_dist])]; - } - } - - - float control_angle = good_atan(dx2, dy2); - - int bcourseness = 15; - - if ([modifyEdge bendMode] == EdgeBendModeBasic) { - float bnd; - float base_angle = good_atan(dx1, dy1); - if (firstControlPoint) { - bnd = base_angle - control_angle; - } else { - bnd = control_angle - base_angle + pi; - if (bnd > pi) bnd -= 2*pi; - } - - [modifyEdge setBend:round(bnd * (180.0f / pi) * - (1.0f / (float)bcourseness)) * - bcourseness]; - } else { - int bnd = round(control_angle * (180.0f / pi) * - (1.0f / (float)bcourseness)) * - bcourseness; - if (firstControlPoint) { - if ([theEvent modifierFlags] & NSAlternateKeyMask) { - if ([modifyEdge isSelfLoop]) { - [modifyEdge setInAngle:[modifyEdge inAngle] + - (bnd - [modifyEdge outAngle])]; - } else { - [modifyEdge setInAngle:[modifyEdge inAngle] - - (bnd - [modifyEdge outAngle])]; - } - } - - [modifyEdge setOutAngle:bnd]; - } else { - if (theEvent.modifierFlags & NSAlternateKeyMask) { - if ([modifyEdge isSelfLoop]) { - [modifyEdge setOutAngle:[modifyEdge outAngle] + - (bnd - [modifyEdge inAngle])]; - } else { - [modifyEdge setOutAngle:[modifyEdge outAngle] - - (bnd - [modifyEdge inAngle])]; - } - } - - [modifyEdge setInAngle:bnd]; - } - } - - [self refreshLayers]; - } else if (mouseMode == NodeMode) { - // do nothing... - } else if (mouseMode == EdgeDragMode) { - for (Node *n in [graph nodes]) { - if ([self node:n containsPoint:dragOrigin] || - [self node:n containsPoint:dragTarget]) - { - [[[nodeLayers objectForKey:n] selection] highlight]; - } else { - [[[nodeLayers objectForKey:n] selection] unhighlight]; - } - } - - [self refreshLayers]; - } else if (mouseMode == CropMode || mouseMode == CropDragMode) { - NSPoint p1 = [transformer fromScreen:[grid snapScreenPoint:dragOrigin]]; - NSPoint p2 = [transformer fromScreen:[grid snapScreenPoint:dragTarget]]; - - NSRect bbox; - if (mouseMode == CropDragMode) { - bbox = [graph boundingBox]; - if (bboxBottomTop == -1) { - float dy = p2.y - bbox.origin.y; - bbox.origin.y += dy; - bbox.size.height -= dy; - } else if (bboxBottomTop == 1) { - float dy = p2.y - (bbox.origin.y + bbox.size.height); - bbox.size.height += dy; - } - - if (bboxLeftRight == -1) { - float dx = p2.x - bbox.origin.x; - bbox.origin.x += dx; - bbox.size.width -= dx; - } else if (bboxLeftRight == 1) { - float dx = p2.x - (bbox.origin.x + bbox.size.width); - bbox.size.width += dx; - } - } else { - bbox = NSRectAroundPoints(p1, p2); - } - - [graph setBoundingBox:bbox]; - [self postGraphChange]; - [self refreshLayers]; - } else { - printf("WARNING: MOUSE DRAGGED IN INVALID MODE.\n"); - } -} - -- (void)mouseUp:(NSEvent*)theEvent { - if (!enabled) return; - - if (frameMoveMode) { - [CATransaction begin]; - [CATransaction setValue:(id)kCFBooleanTrue forKey:kCATransactionDisableActions]; - [self resetMainOrigin]; - [self refreshLayers]; - [CATransaction commit]; - frameMoveMode = NO; - return; - } - - dragTarget = [self convertPoint:[theEvent locationInWindow] fromView:nil]; - - if ((mouseMode & SelectMode) == SelectMode && [theEvent clickCount] == 2) { - for (Edge *e in [graph edges]) { - if ([self edge:e containsPoint:dragTarget]) { - if ([e bendMode] == EdgeBendModeBasic) { - [e convertBendToAngles]; - [e setBendMode:EdgeBendModeInOut]; - } else { - [e convertAnglesToBend]; - [e setBendMode:EdgeBendModeBasic]; - } - - [self registerUndo:graphTikzOnMouseDown withActionName:@"Change Edge Mode"]; - [self postGraphChange]; - break; - } - } - } - - if (mouseMode == SelectBoxMode) { - for (Node* n in [graph nodes]) { - if (NSPointInRect([transformer toScreen:[n point]], [selectionLayer selectBox])) { - [pickSupport selectNode:n]; - [[[nodeLayers objectForKey:n] selection] select]; - } else if (!([theEvent modifierFlags] & NSShiftKeyMask)) { - [pickSupport deselectNode:n]; - [[[nodeLayers objectForKey:n] selection] deselect]; - } - } - - [selectionLayer setActive:NO]; - [selectionLayer setNeedsDisplay]; - [self postSelectionChange]; - - mouseMode = SelectMode; - } else if (mouseMode == SelectMoveMode) { - [gridLayer setOpacity:0.3f]; - - if (dragTarget.x != dragOrigin.x || dragTarget.y != dragOrigin.y) { - [self registerUndo:graphTikzOnMouseDown withActionName:@"Shift Nodes"]; - } - - leaderNode = nil; - - [self postGraphChange]; - mouseMode = SelectMode; - } else if (mouseMode == SelectEdgeBendMode) { - [self registerUndo:graphTikzOnMouseDown withActionName:@"Adjust Edge"]; - [self postGraphChange]; - mouseMode = SelectMode; - modifyEdge = nil; - } else if (mouseMode == NodeMode) { - NSPoint coords = [transformer fromScreen:[grid snapScreenPoint:dragTarget]]; - Node *n = [Node nodeWithPoint:coords]; - [n setStyle:[stylePaletteController activeNodeStyle]]; - [graph addNode:n]; - - [self registerUndo:graphTikzOnMouseDown withActionName:@"Add Node"]; - - [self addNodeLayers:n]; - [self postGraphChange]; - } else if (mouseMode == EdgeDragMode) { - Node *src = nil; - Node *targ = nil; - BOOL found = NO; // don't break the loop until everything is unhighlighted - for (Node *n in [graph nodes]) { - [[[nodeLayers objectForKey:n] selection] unhighlight]; - if (!found) { - if ([self node:n containsPoint:dragOrigin]) src = n; - if ([self node:n containsPoint:dragTarget]) targ = n; - if (src != nil && targ != nil) { - Edge *e = [Edge edgeWithSource:src andTarget:targ]; - [e setStyle:[stylePaletteController activeEdgeStyle]]; - [graph addEdge:e]; - [self registerUndo:graphTikzOnMouseDown withActionName:@"Add Edge"]; - [self addEdgeLayers:e]; - found = YES; - } - } - } - - [self postGraphChange]; - mouseMode = EdgeMode; - } else if (mouseMode == CropMode || mouseMode == CropDragMode) { - if (dragOrigin.x == dragTarget.x && dragOrigin.y == dragTarget.y) { - [graph setBoundingBox:NSMakeRect(0, 0, 0, 0)]; - [self registerUndo:graphTikzOnMouseDown withActionName:@"Clear Bounding Box"]; - [self postGraphChange]; - } else { - [self registerUndo:graphTikzOnMouseDown withActionName:@"Change Bounding Box"]; - } - - mouseMode = CropMode; - } else { - if (! ([theEvent modifierFlags] & NSCommandKeyMask)) - printf("WARNING: MOUSE UP IN INVALID MODE.\n"); - } - - [self refreshLayers]; -} - -- (void)drawNode:(Node*)nd onLayer:(CALayer*)layer inContext:(CGContextRef)context { - NSPoint pt = [transformer toScreen:[nd point]]; - - NodeLayer *nl = [nodeLayers objectForKey:nd]; - //[nl setStrokeWidth:2.0f]; - [nl setCenter:pt andAnimateWhen:(mouseMode != SelectMoveMode)]; -} - -- (void)drawEdge:(Edge*)e onLayer:(CALayer*)layer inContext:(CGContextRef)context { - CGContextSaveGState(context); - NSPoint src = [transformer toScreen:[e tail]]; - NSPoint targ = [transformer toScreen:[e head]]; - NSPoint cp1 = [transformer toScreen:[e cp1]]; - NSPoint cp2 = [transformer toScreen:[e cp2]]; - - // all nodes have the same radius. this will need to be fixed - float sradius = 0;//(slayer.ghost) ? 0 : slayer.radius; - float tradius = 0;//(tlayer.ghost) ? 0 : tlayer.radius; - - float sdx = cp1.x - src.x; - float sdy = cp1.y - src.y; - float sdist = sqrt(sdx*sdx + sdy*sdy); - float sshortx = (sdist==0) ? 0 : sdx/sdist * sradius; - float sshorty = (sdist==0) ? 0 : sdy/sdist * sradius; - - float tdx = cp2.x - targ.x; - float tdy = cp2.y - targ.y; - float tdist = sqrt(tdx*tdx + tdy*tdy); - float tshortx = (tdist==0) ? 0 : tdx/sdist * tradius; - float tshorty = (tdist==0) ? 0 : tdy/sdist * tradius; - - CGContextMoveToPoint(context, src.x+sshortx, src.y+sshorty); - CGContextAddCurveToPoint(context, cp1.x, cp1.y, cp2.x, cp2.y, targ.x+tshortx, targ.y+tshorty); - - - float lineWidth = [transformer scaleToScreen:0.04f]; - - CGContextSetLineWidth(context, lineWidth); - CGContextSetRGBStrokeColor(context, 0, 0, 0, 1); - CGContextSetRGBFillColor(context, 0, 0, 0, 1); - CGContextStrokePath(context); - - if ([e style] != nil) { - NSPoint p1,p2,p3; - - // draw edge decoration - switch ([[e style] decorationStyle]) { - case ED_None: - break; - case ED_Tick: - p1 = [transformer toScreen:[e leftNormal]]; - p2 = [transformer toScreen:[e rightNormal]]; - CGContextMoveToPoint(context, p1.x, p1.y); - CGContextAddLineToPoint(context, p2.x, p2.y); - CGContextStrokePath(context); - break; - case ED_Arrow: - p1 = [transformer toScreen:[e leftNormal]]; - p2 = [transformer toScreen:[e midTan]]; - p3 = [transformer toScreen:[e rightNormal]]; - CGContextMoveToPoint(context, p1.x, p1.y); - CGContextAddLineToPoint(context, p2.x, p2.y); - CGContextAddLineToPoint(context, p3.x, p3.y); - CGContextStrokePath(context); - break; - } - - // draw arrow head - switch ([[e style] headStyle]) { - case AH_None: - break; - case AH_Plain: - p1 = [transformer toScreen:[e leftHeadNormal]]; - p2 = [transformer toScreen:[e head]]; - p3 = [transformer toScreen:[e rightHeadNormal]]; - CGContextMoveToPoint(context, p1.x, p1.y); - CGContextAddLineToPoint(context, p2.x, p2.y); - CGContextAddLineToPoint(context, p3.x, p3.y); - CGContextStrokePath(context); - break; - case AH_Latex: - p1 = [transformer toScreen:[e leftHeadNormal]]; - p2 = [transformer toScreen:[e head]]; - p3 = [transformer toScreen:[e rightHeadNormal]]; - CGContextMoveToPoint(context, p1.x, p1.y); - CGContextAddLineToPoint(context, p2.x, p2.y); - CGContextAddLineToPoint(context, p3.x, p3.y); - CGContextClosePath(context); - CGContextFillPath(context); - break; - } - - // draw arrow tail - switch ([[e style] tailStyle]) { - case AH_None: - break; - case AH_Plain: - p1 = [transformer toScreen:[e leftTailNormal]]; - p2 = [transformer toScreen:[e tail]]; - p3 = [transformer toScreen:[e rightTailNormal]]; - CGContextMoveToPoint(context, p1.x, p1.y); - CGContextAddLineToPoint(context, p2.x, p2.y); - CGContextAddLineToPoint(context, p3.x, p3.y); - CGContextStrokePath(context); - break; - case AH_Latex: - p1 = [transformer toScreen:[e leftTailNormal]]; - p2 = [transformer toScreen:[e tail]]; - p3 = [transformer toScreen:[e rightTailNormal]]; - CGContextMoveToPoint(context, p1.x, p1.y); - CGContextAddLineToPoint(context, p2.x, p2.y); - CGContextAddLineToPoint(context, p3.x, p3.y); - CGContextClosePath(context); - CGContextFillPath(context); - break; - } - } - - - CGContextRestoreGState(context); - - if ([e hasEdgeNode]) { - Node *en = [e edgeNode]; - NSPoint mid = [transformer toScreen:[e mid]]; - if (![[en label] isEqual:@""]) { - [layer drawLabel:[en label] - atPoint:mid - inContext:context - usingTrans:transformer]; - } - } - - EdgeControlLayer *ecl = [edgeControlLayers objectForKey:e]; - [ecl setNeedsDisplay]; -} - - -// draw the graph layer --(void)drawLayer:(CALayer *)layer inContext:(CGContextRef)context { - for (Edge* e in [graph edges]) [self drawEdge:e onLayer:layer inContext:context]; - - for (Node* n in [graph nodes]) [self drawNode:n onLayer:layer inContext:context]; - - if ([graph hasBoundingBox]) { - CGRect bbox = NSRectToCGRect(NSIntegralRect( - [transformer rectToScreen:[graph boundingBox]])); - CGContextSetRGBStrokeColor(context, 1.0f, 0.7f, 0.5f, 1.0f); - CGContextSetLineWidth(context, 1.0f); - CGContextSetShouldAntialias(context, NO); - CGContextStrokeRect(context, bbox); - CGContextSetShouldAntialias(context, YES); - } - - if (mouseMode == EdgeDragMode) { - CGContextMoveToPoint(context, dragOrigin.x, dragOrigin.y); - CGContextAddLineToPoint(context, dragTarget.x, dragTarget.y); - CGContextSetLineWidth(context, 2); - CGContextSetRGBStrokeColor(context, 0, 0, 1, 1); - CGContextStrokePath(context); - } -} - -// if enabled, suppress the default "bonk" behaviour on key presses -- (void)keyDown:(NSEvent *)theEvent { - if (!enabled) [super keyDown:theEvent]; -} - -- (void)delete:(id)sender { - BOOL didDelete = NO; - NSString *oldTikz = [graph tikz]; - - if ([[pickSupport selectedNodes] count] != 0) { - GraphChange *change = [graph removeNodes:[pickSupport selectedNodes]]; - for (Node *n in [change affectedNodes]) [self removeNodeLayers:n]; - for (Edge *e in [change affectedEdges]) [self removeEdgeLayers:e]; - - [self refreshLayers]; - [self postGraphChange]; - didDelete = YES; - } - - if ([[pickSupport selectedEdges] count] != 0) { - [graph removeEdges:[pickSupport selectedEdges]]; - for (Edge *e in [pickSupport selectedEdges]) [self removeEdgeLayers:e]; - [self refreshLayers]; - [self postGraphChange]; - didDelete = YES; - } - - [pickSupport deselectAllNodes]; - [pickSupport deselectAllEdges]; - - if (didDelete) [self registerUndo:oldTikz withActionName:@"Delete Nodes or Edges"]; -} - -- (void)keyUp:(NSEvent *)theEvent { - if (!enabled) return; - - id sender = self; - switch ([theEvent keyCode]) { - case 51: // delete - [self delete:sender]; // "self" is the sender - break; - case 1: // S - [toolPaletteController setSelectedTool:TikzToolSelect]; - break; - case 45: // N - case 9: // V - [toolPaletteController setSelectedTool:TikzToolNode]; - break; - case 14: // E - [toolPaletteController setSelectedTool:TikzToolEdge]; - //[self updateMouseMode]; - break; - case 40: // K - [toolPaletteController setSelectedTool:TikzToolCrop]; - break; - } - [self refreshLayers]; -} - - -- (void)deselectAll:(id)sender { - [pickSupport deselectAllNodes]; - [pickSupport deselectAllEdges]; - - for (Node *n in [graph nodes]) { - [[[nodeLayers objectForKey:n] selection] deselect]; - } - - for (Edge *e in [graph edges]) { - [[edgeControlLayers objectForKey:e] deselect]; - } - - [self postSelectionChange]; -} - -- (void)selectAll:(id)sender { - [pickSupport selectAllNodes:[NSSet setWithArray:[graph nodes]]]; - - for (Node *n in [graph nodes]) { - [[[nodeLayers objectForKey:n] selection] select]; - } - - [self postSelectionChange]; -} - - -- (void)updateMouseMode { - switch (toolPaletteController.selectedTool) { - case TikzToolSelect: - mouseMode = SelectMode; - break; - case TikzToolNode: - mouseMode = NodeMode; - break; - case TikzToolEdge: - mouseMode = EdgeMode; - break; - case TikzToolCrop: - mouseMode = CropMode; - break; - } -} - -- (void)setDocumentUndoManager:(NSUndoManager *)um { - documentUndoManager = um; -} - -- (void)copy:(id)sender { - if ([[pickSupport selectedNodes] count] != 0) { - Graph *clip = [graph copyOfSubgraphWithNodes:[pickSupport selectedNodes]]; - NSString *tikz = [clip tikz]; - NSData *data = [tikz dataUsingEncoding:NSUTF8StringEncoding]; - //NSLog(@"about to copy: %@", tikz); - NSPasteboard *cb = [NSPasteboard generalPasteboard]; - [cb declareTypes:[NSArray arrayWithObject:@"tikzpicture"] owner:self]; - [cb setData:data forType:@"tikzpicture"]; - } -} - -- (void)cut:(id)sender { - if ([[pickSupport selectedNodes] count] != 0) { - [self copy:sender]; - [self delete:sender]; - - // otherwise, menu will say "Undo Delete Graph" - [documentUndoManager setActionName:@"Cut Graph"]; - } -} - -- (void)paste:(id)sender { - NSPasteboard *cb = [NSPasteboard generalPasteboard]; - NSString *type = [cb availableTypeFromArray:[NSArray arrayWithObject:@"tikzpicture"]]; - if (type) { - NSData *data = [cb dataForType:type]; - NSString *tikz = [[NSString alloc] initWithData:data encoding:NSUTF8StringEncoding]; - //NSLog(@"pasting tikz:\n%@",tikz); - Graph *clip = [TikzGraphAssembler parseTikz:tikz]; - if (clip) { - //NSLog(@"tikz pasted:\n%@",tikz); - NSRect graphBounds = [graph bounds]; - NSRect clipBounds = [clip bounds]; - float dx = graphBounds.origin.x + - graphBounds.size.width - - clipBounds.origin.x + 0.5f; - [clip shiftNodes:[clip nodes] byPoint:NSMakePoint(dx, 0)]; - - if ([[clip nodes] count] != 0) { - NSString *oldTikz = [graph tikz]; - [self deselectAll:self]; - - // select everything from the clipboard - for (Node *n in [clip nodes]) { - [n attachStyleFromTable:[stylePaletteController nodeStyles]]; - [self addNodeLayers:n]; - [pickSupport selectNode:n]; - [[[nodeLayers objectForKey:n] selection] select]; - } - - for (Edge *e in [clip edges]) { - [e attachStyleFromTable:[stylePaletteController edgeStyles]]; - [self addEdgeLayers:e]; - } - - [graph insertGraph:clip]; - - [self registerUndo:oldTikz withActionName:@"Paste Graph"]; - [self refreshLayers]; - [self postGraphChange]; - } - } else { - NSLog(@"Error: couldn't parse tikz picture from clipboard."); - } - - } -} - -- (void)bringForward:(id)sender { - NSString *oldTikz = [graph tikz]; - [graph bringNodesForward:[pickSupport selectedNodes]]; - [graph bringEdgesForward:[pickSupport selectedEdges]]; - [self registerUndo:oldTikz withActionName:@"Bring Forward"]; - [self postGraphChange]; - [self refreshLayers]; -} - -- (void)sendBackward:(id)sender { - NSString *oldTikz = [graph tikz]; - [graph sendNodesBackward:[pickSupport selectedNodes]]; - [graph sendEdgesBackward:[pickSupport selectedEdges]]; - [self registerUndo:oldTikz withActionName:@"Send Backward"]; - [self postGraphChange]; - [self refreshLayers]; -} - -- (void)bringToFront:(id)sender { - NSString *oldTikz = [graph tikz]; - [graph bringNodesToFront:[pickSupport selectedNodes]]; - [graph bringEdgesToFront:[pickSupport selectedEdges]]; - [self registerUndo:oldTikz withActionName:@"Bring to Front"]; - [self postGraphChange]; - [self refreshLayers]; -} - -- (void)sendToBack:(id)sender { - NSString *oldTikz = [graph tikz]; - [graph sendNodesToBack:[pickSupport selectedNodes]]; - [graph sendEdgesToBack:[pickSupport selectedEdges]]; - [self registerUndo:oldTikz withActionName:@"Send to Back"]; - [self postGraphChange]; - [self refreshLayers]; -} - -- (void)flipHorizonal:(id)sender { - NSString *oldTikz = [graph tikz]; - [graph flipHorizontalNodes:[pickSupport selectedNodes]]; - [self registerUndo:oldTikz withActionName:@"Flip Horizontal"]; - [self postGraphChange]; - [self refreshLayers]; -} - -- (void)flipVertical:(id)sender { - NSString *oldTikz = [graph tikz]; - [graph flipVerticalNodes:[pickSupport selectedNodes]]; - [self registerUndo:oldTikz withActionName:@"Flip Vertical"]; - [self postGraphChange]; - [self refreshLayers]; -} - -- (void)reverseEdgeDirection:(id)sender { - NSString *oldTikz = [graph tikz]; - - NSSet *es; - if ([[pickSupport selectedEdges] count] != 0) { - es = [pickSupport selectedEdges]; - } else { - es = [graph incidentEdgesForNodes:[pickSupport selectedNodes]]; - } - - for (Edge *e in es) [e reverse]; - - [self registerUndo:oldTikz withActionName:@"Flip Edge Direction"]; - [self postGraphChange]; - [self refreshLayers]; -} - -- (BOOL)acceptsFirstResponder { return YES; } -- (BOOL)acceptsFirstMouse:(NSEvent *)theEvent { return YES; } -- (BOOL)canBecomeKeyView { return YES; } - - -@end diff --git a/tikzit/src/osx/Grid.h b/tikzit/src/osx/Grid.h deleted file mode 100644 index 76826e2..0000000 --- a/tikzit/src/osx/Grid.h +++ /dev/null @@ -1,48 +0,0 @@ -// -// Grid.h -// TikZiT -// -// Copyright 2010 Aleks Kissinger. All rights reserved. -// -// -// This file is part of TikZiT. -// -// TikZiT is free software: you can redistribute it and/or modify -// it under the terms of the GNU General Public License as published by -// the Free Software Foundation, either version 3 of the License, or -// (at your option) any later version. -// -// TikZiT is distributed in the hope that it will be useful, -// but WITHOUT ANY WARRANTY; without even the implied warranty of -// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -// GNU General Public License for more details. -// -// You should have received a copy of the GNU General Public License -// along with TikZiT. If not, see <http://www.gnu.org/licenses/>. -// - -#import <Cocoa/Cocoa.h> -#import "Transformer.h" - -@interface Grid : NSObject { - float gridX, gridY; - //float gridCellX, gridCellY; - int subdivisions; - Transformer *transformer; - NSSize size; -} - -@property NSSize size; - -- (id)initWithSpacing:(float)spacing subdivisions:(int)subs transformer:(Transformer*)t; -+ (Grid*)gridWithSpacing:(float)spacing subdivisions:(int)subs transformer:(Transformer*)t; -- (NSPoint)snapScreenPoint:(NSPoint)p; -- (float)gridX; -- (float)gridY; -- (int)subdivisions; -- (void)setSubdivisions:(int)subs; - -// Grid can also draw itself on a layer -- (void)drawLayer:(CALayer *)layer inContext:(CGContextRef)ctx; - -@end diff --git a/tikzit/src/osx/Grid.m b/tikzit/src/osx/Grid.m deleted file mode 100644 index 3e412a3..0000000 --- a/tikzit/src/osx/Grid.m +++ /dev/null @@ -1,152 +0,0 @@ -// -// Grid.m -// TikZiT -// -// Copyright 2010 Aleks Kissinger. All rights reserved. -// -// -// This file is part of TikZiT. -// -// TikZiT is free software: you can redistribute it and/or modify -// it under the terms of the GNU General Public License as published by -// the Free Software Foundation, either version 3 of the License, or -// (at your option) any later version. -// -// TikZiT is distributed in the hope that it will be useful, -// but WITHOUT ANY WARRANTY; without even the implied warranty of -// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -// GNU General Public License for more details. -// -// You should have received a copy of the GNU General Public License -// along with TikZiT. If not, see <http://www.gnu.org/licenses/>. -// - -#import "Grid.h" - - -@implementation Grid - -@synthesize size; - -- (id)initWithSpacing:(float)spacing - subdivisions:(int)subs - transformer:(Transformer*)t -{ - [super init]; - gridX = spacing; - gridY = spacing; - subdivisions = subs; - size.width = 0; - size.height = 0; - transformer = t; - return self; -} - -+ (Grid*)gridWithSpacing:(float)spacing - subdivisions:(int)subs - transformer:(Transformer*)t -{ - return [[Grid alloc] initWithSpacing:spacing - subdivisions:subs - transformer:t]; -} - -- (float)gridX { - return gridX; -} - -- (float)gridY { - return gridY; -} - -- (int)subdivisions { - return subdivisions; -} - -- (void)setSubdivisions:(int)subs { - subdivisions = subs; -} - -- (NSPoint)snapScreenPoint:(NSPoint)p { - NSPoint snap; - - float gridCellX = [transformer scaleToScreen:gridX] / (float)subdivisions; - float gridCellY = [transformer scaleToScreen:gridY] / (float)subdivisions; - - // snap along grid lines, relative to the origin - snap.x = floor(((p.x-[transformer origin].x)/gridCellX)+0.5)*gridCellX + [transformer origin].x; - snap.y = floor(((p.y-[transformer origin].y)/gridCellY)+0.5)*gridCellY + [transformer origin].y; - return snap; -} - --(void)drawLayer:(CALayer *)layer inContext:(CGContextRef)context -{ - CGContextSaveGState(context); - - CGContextSetShouldAntialias(context, NO); - - float x,y; - float grX = [transformer scaleToScreen:gridX]; - float grY = [transformer scaleToScreen:gridY]; - - float gridCellX = grX / (float)subdivisions; - float gridCellY = grY / (float)subdivisions; - - for (x = [transformer origin].x + gridCellX; x < size.width; x += gridCellX) { - CGContextMoveToPoint(context, x, 0); - CGContextAddLineToPoint(context, x, size.height); - } - - for (x = [transformer origin].x - gridCellX; x > 0; x -= gridCellX) { - CGContextMoveToPoint(context, x, 0); - CGContextAddLineToPoint(context, x, size.height); - } - - for (y = [transformer origin].y + gridCellY; y < size.height; y += gridCellY) { - CGContextMoveToPoint(context, 0, y); - CGContextAddLineToPoint(context, size.width, y); - } - - for (y = [transformer origin].y - gridCellY; y > 0; y -= gridCellY) { - CGContextMoveToPoint(context, 0, y); - CGContextAddLineToPoint(context, size.width, y); - } - - CGContextSetRGBStrokeColor(context, 0.9, 0.9, 1, 1); - CGContextStrokePath(context); - - for (x = [transformer origin].x + grX; x < size.width; x += grX) { - CGContextMoveToPoint(context, x, 0); - CGContextAddLineToPoint(context, x, size.height); - } - - for (x = [transformer origin].x - grX; x > 0; x -= grX) { - CGContextMoveToPoint(context, x, 0); - CGContextAddLineToPoint(context, x, size.height); - } - - for (y = [transformer origin].y + grY; y < size.height; y += grY) { - CGContextMoveToPoint(context, 0, y); - CGContextAddLineToPoint(context, size.width, y); - } - - for (y = [transformer origin].y + grY; y > 0; y -= grY) { - CGContextMoveToPoint(context, 0, y); - CGContextAddLineToPoint(context, size.width, y); - } - - CGContextSetRGBStrokeColor(context, 0.8, 0.8, 0.9, 1); - CGContextStrokePath(context); - - CGContextMoveToPoint(context, [transformer origin].x, 0); - CGContextAddLineToPoint(context, [transformer origin].x, size.height); - CGContextMoveToPoint(context, 0, [transformer origin].y); - CGContextAddLineToPoint(context, size.width, [transformer origin].y); - - CGContextSetRGBStrokeColor(context, 0.6, 0.6, 0.7, 1); - CGContextStrokePath(context); - - CGContextRestoreGState(context); -} - -@end diff --git a/tikzit/src/osx/MultiCombo.h b/tikzit/src/osx/MultiCombo.h deleted file mode 100644 index c8ec769..0000000 --- a/tikzit/src/osx/MultiCombo.h +++ /dev/null @@ -1,18 +0,0 @@ -// -// MultiCombo.h -// TikZiT -// -// Created by Aleks Kissinger on 21/04/2011. -// Copyright 2011 __MyCompanyName__. All rights reserved. -// - -#import <Cocoa/Cocoa.h> - - -@interface MultiCombo : NSComboBox { - BOOL multi; -} - -@property (readwrite,assign) BOOL multi; - -@end diff --git a/tikzit/src/osx/MultiCombo.m b/tikzit/src/osx/MultiCombo.m deleted file mode 100644 index 8930460..0000000 --- a/tikzit/src/osx/MultiCombo.m +++ /dev/null @@ -1,38 +0,0 @@ -// -// MultiCombo.m -// TikZiT -// -// Created by Aleks Kissinger on 21/04/2011. -// Copyright 2011 __MyCompanyName__. All rights reserved. -// - -#import "MultiCombo.h" - - -@implementation MultiCombo - -- (void)textDidChange:(NSNotification *)notification { - [super textDidChange:notification]; - [self setMulti:NO]; -} - -- (void)setMulti:(BOOL)m { - multi = m; - if (multi) { - [self setTextColor:[NSColor grayColor]]; - [self setStringValue:@"multiple values"]; - } -} - -- (BOOL)multi { return multi; } - -- (BOOL)becomeFirstResponder { - [super becomeFirstResponder]; - if ([self multi]) { - [self setTextColor:[NSColor blackColor]]; - [self setStringValue:@""]; - } - return YES; -} - -@end diff --git a/tikzit/src/osx/MultiField.h b/tikzit/src/osx/MultiField.h deleted file mode 100644 index 39eeefa..0000000 --- a/tikzit/src/osx/MultiField.h +++ /dev/null @@ -1,18 +0,0 @@ -// -// LabelField.h -// TikZiT -// -// Created by Aleks Kissinger on 20/04/2011. -// Copyright 2011 __MyCompanyName__. All rights reserved. -// - -#import <Cocoa/Cocoa.h> - - -@interface MultiField : NSTextField { - BOOL multi; -} - -@property (readwrite,assign) BOOL multi; - -@end diff --git a/tikzit/src/osx/MultiField.m b/tikzit/src/osx/MultiField.m deleted file mode 100644 index 7c5aac3..0000000 --- a/tikzit/src/osx/MultiField.m +++ /dev/null @@ -1,53 +0,0 @@ -// -// LabelField.m -// TikZiT -// -// Created by Aleks Kissinger on 20/04/2011. -// Copyright 2011 __MyCompanyName__. All rights reserved. -// - -#import "MultiField.h" - - -@implementation MultiField - -- (void)textDidChange:(NSNotification *)notification { - [super textDidChange:notification]; - [self setMulti:NO]; -} - -- (void)setMulti:(BOOL)m { - multi = m; - if (multi) { - [self setTextColor:[NSColor grayColor]]; - [self setStringValue:@"multiple values"]; - } -} - -- (BOOL)multi { return multi; } - -- (BOOL)becomeFirstResponder { - [super becomeFirstResponder]; - if ([self multi]) { - [self setTextColor:[NSColor blackColor]]; - [self setStringValue:@""]; - } - return YES; -} - -//- (BOOL)textShouldBeginEditing:(NSText *)textObject { -// [super textShouldBeginEditing:textObject]; -// NSLog(@"about to type"); -// return YES; -//} - -//- (void)textDidEndEditing:(NSNotification *)obj { -// [super textDidEndEditing:obj]; -// -// NSLog(@"focus lost"); -// if ([self multi]) { -// [self setMulti:YES]; -// } -//} - -@end diff --git a/tikzit/src/osx/NilToEmptyStringTransformer.h b/tikzit/src/osx/NilToEmptyStringTransformer.h deleted file mode 100644 index 1445a94..0000000 --- a/tikzit/src/osx/NilToEmptyStringTransformer.h +++ /dev/null @@ -1,28 +0,0 @@ -// -// NilToEmptyStringTransformer.h -// TikZiT -// -// Copyright 2011 Aleks Kissinger. All rights reserved. -// -// -// This file is part of TikZiT. -// -// TikZiT is free software: you can redistribute it and/or modify -// it under the terms of the GNU General Public License as published by -// the Free Software Foundation, either version 3 of the License, or -// (at your option) any later version. -// -// TikZiT is distributed in the hope that it will be useful, -// but WITHOUT ANY WARRANTY; without even the implied warranty of -// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -// GNU General Public License for more details. -// -// You should have received a copy of the GNU General Public License -// along with TikZiT. If not, see <http://www.gnu.org/licenses/>. -// - -#import <Foundation/Foundation.h> - -@interface NilToEmptyStringTransformer : NSValueTransformer - -@end diff --git a/tikzit/src/osx/NilToEmptyStringTransformer.m b/tikzit/src/osx/NilToEmptyStringTransformer.m deleted file mode 100644 index 97267e3..0000000 --- a/tikzit/src/osx/NilToEmptyStringTransformer.m +++ /dev/null @@ -1,53 +0,0 @@ -// -// NilToEmptyStringTransformer.m -// TikZiT -// -// Copyright 2011 Aleks Kissinger. All rights reserved. -// -// -// This file is part of TikZiT. -// -// TikZiT is free software: you can redistribute it and/or modify -// it under the terms of the GNU General Public License as published by -// the Free Software Foundation, either version 3 of the License, or -// (at your option) any later version. -// -// TikZiT is distributed in the hope that it will be useful, -// but WITHOUT ANY WARRANTY; without even the implied warranty of -// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -// GNU General Public License for more details. -// -// You should have received a copy of the GNU General Public License -// along with TikZiT. If not, see <http://www.gnu.org/licenses/>. -// - -#import "NilToEmptyStringTransformer.h" - -@implementation NilToEmptyStringTransformer - -- (id)init { - [super init]; - return self; -} - -+ (Class)transformedValueClass { - return [NSString class]; -} - -+ (BOOL)allowsReverseTransformation { - return YES; -} - -- (id)transformedValue:(id)value { - if (value == nil) { - return @""; - } else { - return value; - } -} - -- (id)reverseTransformedValue:(id)value { - return [self transformedValue:value]; -} - -@end diff --git a/tikzit/src/osx/NodeLayer.h b/tikzit/src/osx/NodeLayer.h deleted file mode 100644 index dfe05e8..0000000 --- a/tikzit/src/osx/NodeLayer.h +++ /dev/null @@ -1,62 +0,0 @@ -// -// NodeLayer.h -// TikZiT -// -// Copyright 2010 Aleks Kissinger. All rights reserved. -// -// -// This file is part of TikZiT. -// -// TikZiT is free software: you can redistribute it and/or modify -// it under the terms of the GNU General Public License as published by -// the Free Software Foundation, either version 3 of the License, or -// (at your option) any later version. -// -// TikZiT is distributed in the hope that it will be useful, -// but WITHOUT ANY WARRANTY; without even the implied warranty of -// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -// GNU General Public License for more details. -// -// You should have received a copy of the GNU General Public License -// along with TikZiT. If not, see <http://www.gnu.org/licenses/>. -// - -#import <Cocoa/Cocoa.h> -#import <QuartzCore/CoreAnimation.h> -#import "Transformer.h" -#import "Shape.h" -#import "Node.h" -#import "NodeStyle+Coder.h" -#import "NodeSelectionLayer.h" - -@interface NodeLayer : CALayer { - Node *node; - Shape *shape; - CGMutablePathRef path; - float textwidth; - NSPoint center; - Transformer *transformer; - Transformer *localTrans; - NodeSelectionLayer *selection; - BOOL rescale; - BOOL dirty; // need to rebuild CGBezierPath of the shape -} - -@property Node *node; -@property (assign) NSPoint center; -@property (assign) BOOL rescale; -@property (retain) NodeSelectionLayer *selection; -@property (readonly) CGMutablePathRef path; - -- (id)initWithNode:(Node*)n transformer:(Transformer*)t; -- (NSColor*)strokeColor; -- (NSColor*)fillColor; -- (float)strokeWidth; - -- (void)setCenter:(NSPoint)ctr andAnimateWhen:(BOOL)anim; -- (void)updateFrame; -- (BOOL)nodeContainsPoint:(NSPoint)p; - -- (void)drawInContext:(CGContextRef)context; - -@end diff --git a/tikzit/src/osx/NodeLayer.m b/tikzit/src/osx/NodeLayer.m deleted file mode 100644 index 2c37c26..0000000 --- a/tikzit/src/osx/NodeLayer.m +++ /dev/null @@ -1,239 +0,0 @@ -// -// NodeLayer.m -// TikZiT -// -// Copyright 2010 Aleks Kissinger. All rights reserved. -// -// -// This file is part of TikZiT. -// -// TikZiT is free software: you can redistribute it and/or modify -// it under the terms of the GNU General Public License as published by -// the Free Software Foundation, either version 3 of the License, or -// (at your option) any later version. -// -// TikZiT is distributed in the hope that it will be useful, -// but WITHOUT ANY WARRANTY; without even the implied warranty of -// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -// GNU General Public License for more details. -// -// You should have received a copy of the GNU General Public License -// along with TikZiT. If not, see <http://www.gnu.org/licenses/>. -// - -#import "NodeLayer.h" -#import "CALayer+DrawLabel.h" -#import "NSString+LatexConstants.h" -#import "Shape.h" -#import "ShapeNames.h" -#import "Node.h" -#import "Edge.h" - -@implementation NodeLayer - -@synthesize node, selection, rescale; - -- (id)initWithNode:(Node *)n transformer:(Transformer*)t { - [super init]; - node = n; - selection = [[NodeSelectionLayer alloc] init]; - [selection setNodeLayer:self]; - localTrans = [[Transformer alloc] init]; - - [self addSublayer:selection]; - textwidth = 0.0f; - center = NSMakePoint(0.0f, 0.0f); - transformer = t; - - path = NULL; - rescale = YES; - dirty = YES; - - [self updateFrame]; - return self; -} - -- (NSColor*)strokeColor { - if ([node style] != nil) { - return [[[node style] strokeColor] colorUsingColorSpace:[NSColorSpace deviceRGBColorSpace]]; - } else { - return nil; - } -} - -- (NSColor*)fillColor { - if ([node style] != nil) { - return [[[node style] fillColor] colorUsingColorSpace:[NSColorSpace deviceRGBColorSpace]]; - } else { - return nil; - } -} - -- (float)strokeWidth { - if ([node style] != nil) { - return [node.style strokeThickness]; - } else { - return [NodeStyle defaultStrokeThickness]; - } -} - -- (NSPoint)center { return center; } - -- (void)setCenter:(NSPoint)ctr { - center.x = round(ctr.x); - center.y = round(ctr.y); - [self updateFrame]; -} - -- (void)setCenter:(NSPoint)ctr andAnimateWhen:(BOOL)anim { - [CATransaction begin]; - if (!anim) { - [CATransaction setValue:(id)kCFBooleanTrue forKey:kCATransactionDisableActions]; - } - [self setCenter:ctr]; - [CATransaction commit]; -} - -- (void)updateShape { - Shape *s = ([node style] != nil) ? - [Shape shapeForName:[[node style] shapeName]] : - [Shape shapeForName:SHAPE_CIRCLE]; - if (s != shape) { // straight pointer comparison - shape = s; - dirty = YES; - } -} - -- (void)updateLocalTrans { - float scale = ([node style] != nil) ? [[node style] scale] : 1.0f; - - Transformer *t = [Transformer transformer]; - float rad = ([transformer scaleToScreen:scale] / 2.0f) + 8.0f; - [t setOrigin:NSMakePoint(rad, rad)]; - [t setScale:[transformer scale]*((rescale)?scale:0.8f)]; - - if (![localTrans isEqual:t]) { - dirty = YES; - localTrans = t; - } -} - -- (void)updateFrame { - [self updateLocalTrans]; - [self updateShape]; - float rad = [localTrans origin].x; - [self setFrame:CGRectIntegral(CGRectMake(center.x - rad, center.y - rad, 2*rad, 2*rad))]; - NSRect bds = NSMakeRect(0, 0, 2*rad, 2*rad); - [selection setFrame:NSRectToCGRect(bds)]; - - [self setNeedsDisplay]; - [selection setNeedsDisplay]; -} - -- (CGMutablePathRef)path { - if (dirty) { - CGMutablePathRef pth = CGPathCreateMutable(); - NSPoint p, cp1, cp2; - for (NSArray *arr in [shape paths]) { - BOOL fst = YES; - for (Edge *e in arr) { - if (fst) { - fst = NO; - p = [localTrans toScreen:[[e source] point]]; - CGPathMoveToPoint(pth, nil, p.x, p.y); - } - - p = [localTrans toScreen:[[e target] point]]; - if ([e isStraight]) { - CGPathAddLineToPoint(pth, nil, p.x, p.y); - } else { - cp1 = [localTrans toScreen:[e cp1]]; - cp2 = [localTrans toScreen:[e cp2]]; - CGPathAddCurveToPoint(pth, nil, cp1.x, cp1.y, cp2.x, cp2.y, p.x, p.y); - } - } - - CGPathCloseSubpath(pth); - } - - if (path != NULL) CFRelease(path); - path = pth; - dirty = NO; - } - - - return path; -} - -- (BOOL)nodeContainsPoint:(NSPoint)p { - CGPoint p1 = CGPointMake(p.x - [self frame].origin.x, p.y - [self frame].origin.y); - return CGPathContainsPoint([self path],nil,p1,NO); -} - - -- (void)drawInContext:(CGContextRef)context { - CGContextSaveGState(context); - - - if ([node style] == nil) { - CGContextSetRGBStrokeColor(context, 0.4f, 0.4f, 0.7f, 1.0f); - CGContextSetRGBFillColor(context, 0.4f, 0.4f, 0.7f, 1.0f); - //CGRect fr = [self frame]; - CGRect bds = NSRectToCGRect([localTrans rectToScreen:NSMakeRect(-0.5, -0.5, 1, 1)]); - CGRect pt = CGRectMake(CGRectGetMidX(bds)-1.0f, CGRectGetMidY(bds)-1.0f, 2.0f, 2.0f); - CGContextSetLineWidth(context, 0); - CGContextAddEllipseInRect(context, pt); - CGContextFillPath(context); - - // HACK: for some reason, CGFloat isn't getting typedef'ed properly - -#ifdef __x86_64__ - const double dash[2] = {2.0,2.0}; -#else - const float dash[2] = {2.0,2.0}; -#endif - CGContextSetLineDash(context, 0.0, dash, 2); - CGContextSetLineWidth(context, 1); - CGContextAddPath(context, [self path]); - CGContextStrokePath(context); - } else { - NSColor *stroke = [self strokeColor]; - NSColor *fill = [self fillColor]; - - CGContextSetRGBStrokeColor(context, - [stroke redComponent], - [stroke greenComponent], - [stroke blueComponent], - [stroke alphaComponent]); - - CGContextSetLineWidth(context, [self strokeWidth]); - - CGContextSetRGBFillColor(context, - [fill redComponent], - [fill greenComponent], - [fill blueComponent], - [fill alphaComponent]); - - - CGContextSetLineWidth(context, [self strokeWidth]); - CGContextAddPath(context, [self path]); - CGContextDrawPath(context, kCGPathFillStroke); - } - - if (!([node label] == nil || [[node label] isEqual:@""])) { - NSPoint labelPt = NSMakePoint([self frame].size.width/2, [self frame].size.height/2); - [self drawLabel:[[node label] stringByExpandingLatexConstants] - atPoint:labelPt - inContext:context - usingTrans:transformer]; - } - - CGContextRestoreGState(context); -} - -- (void)dealloc { - if (path != NULL) CFRelease(path); - [super dealloc]; -} - -@end diff --git a/tikzit/src/osx/NodeSelectionLayer.h b/tikzit/src/osx/NodeSelectionLayer.h deleted file mode 100644 index 99ee75f..0000000 --- a/tikzit/src/osx/NodeSelectionLayer.h +++ /dev/null @@ -1,45 +0,0 @@ -// -// NodeSelectionLayer.h -// TikZiT -// -// Copyright 2010 Aleks Kissinger. All rights reserved. -// -// -// This file is part of TikZiT. -// -// TikZiT is free software: you can redistribute it and/or modify -// it under the terms of the GNU General Public License as published by -// the Free Software Foundation, either version 3 of the License, or -// (at your option) any later version. -// -// TikZiT is distributed in the hope that it will be useful, -// but WITHOUT ANY WARRANTY; without even the implied warranty of -// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -// GNU General Public License for more details. -// -// You should have received a copy of the GNU General Public License -// along with TikZiT. If not, see <http://www.gnu.org/licenses/>. -// - -#import <Cocoa/Cocoa.h> -#import <QuartzCore/CoreAnimation.h> -#import "Shape.h" - -@class NodeLayer; - -@interface NodeSelectionLayer : CALayer { - BOOL selected; - CGMutablePathRef path; - NSLock *drawLock; - NodeLayer *nodeLayer; -} - -@property NodeLayer *nodeLayer; - -- (id)init; -- (void)select; -- (void)deselect; -- (void)highlight; -- (void)unhighlight; - -@end diff --git a/tikzit/src/osx/NodeSelectionLayer.m b/tikzit/src/osx/NodeSelectionLayer.m deleted file mode 100644 index 5efcbf7..0000000 --- a/tikzit/src/osx/NodeSelectionLayer.m +++ /dev/null @@ -1,93 +0,0 @@ -// -// NodeSelectionLayer.m -// TikZiT -// -// Copyright 2010 Aleks Kissinger. All rights reserved. -// -// -// This file is part of TikZiT. -// -// TikZiT is free software: you can redistribute it and/or modify -// it under the terms of the GNU General Public License as published by -// the Free Software Foundation, either version 3 of the License, or -// (at your option) any later version. -// -// TikZiT is distributed in the hope that it will be useful, -// but WITHOUT ANY WARRANTY; without even the implied warranty of -// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -// GNU General Public License for more details. -// -// You should have received a copy of the GNU General Public License -// along with TikZiT. If not, see <http://www.gnu.org/licenses/>. -// - -#import "NodeSelectionLayer.h" -#import "NodeLayer.h" -#import "CircleShape.h" - -@implementation NodeSelectionLayer - -@synthesize nodeLayer; - -- (id)init { - [super init]; - selected = NO; - drawLock = [[NSLock alloc] init]; - nodeLayer = nil; - [self setOpacity:0.0f]; - return self; -} - - -- (void)select { - selected = YES; - [self setOpacity:0.5f]; -} - -- (void)deselect { - selected = NO; - [self setOpacity:0.0f]; -} - -- (void)highlight { - if (!selected) { - [self setOpacity:0.25f]; - } -} - -- (void)unhighlight { - if (!selected) { - [self setOpacity:0.0f]; - } -} - -//- (CGMutablePathRef)path { -// return path; -//} -// -//- (void)setPath:(CGMutablePathRef)p { -// path = CGPathCreateMutableCopy(p); -// CFMakeCollectable(path); -//} - -- (void)drawInContext:(CGContextRef)context { - [drawLock lock]; - CGContextSaveGState(context); - - //CGContextSetRGBStrokeColor(context, 0.61f, 0.735f, 1.0f, 1.0f); - CGContextSetRGBStrokeColor(context, 0.61f, 0.735f, 1.0f, 1.0f); - CGContextSetRGBFillColor(context, 0.61f, 0.735f, 1.0f, 1.0f); - CGContextSetLineWidth(context, 6.0f); - - if (nodeLayer != nil) { - CGContextAddPath(context, [nodeLayer path]); - } else { - NSLog(@"WARNING: attempting to draw selection with path = nil."); - } - CGContextDrawPath(context, kCGPathFillStroke); - - CGContextRestoreGState(context); - [drawLock unlock]; -} - -@end diff --git a/tikzit/src/osx/NodeStyle+Coder.h b/tikzit/src/osx/NodeStyle+Coder.h deleted file mode 100644 index b6443af..0000000 --- a/tikzit/src/osx/NodeStyle+Coder.h +++ /dev/null @@ -1,36 +0,0 @@ -// -// NodeStyle+Coder.h -// TikZiT -// -// Copyright 2010 Aleks Kissinger. All rights reserved. -// -// -// This file is part of TikZiT. -// -// TikZiT is free software: you can redistribute it and/or modify -// it under the terms of the GNU General Public License as published by -// the Free Software Foundation, either version 3 of the License, or -// (at your option) any later version. -// -// TikZiT is distributed in the hope that it will be useful, -// but WITHOUT ANY WARRANTY; without even the implied warranty of -// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -// GNU General Public License for more details. -// -// You should have received a copy of the GNU General Public License -// along with TikZiT. If not, see <http://www.gnu.org/licenses/>. -// - -#import <Cocoa/Cocoa.h> -#import "NodeStyle.h" - - -@interface NodeStyle(Coder) - -@property (copy) NSColor *fillColor; -@property (copy) NSColor *strokeColor; - -- (id)initWithCoder:(NSCoder *)coder; -- (void)encodeWithCoder:(NSCoder *)coder; - -@end diff --git a/tikzit/src/osx/NodeStyle+Coder.m b/tikzit/src/osx/NodeStyle+Coder.m deleted file mode 100644 index 8da91c1..0000000 --- a/tikzit/src/osx/NodeStyle+Coder.m +++ /dev/null @@ -1,91 +0,0 @@ -// -// NodeStyle+Coder.m -// TikZiT -// -// Copyright 2010 Aleks Kissinger. All rights reserved. -// -// -// This file is part of TikZiT. -// -// TikZiT is free software: you can redistribute it and/or modify -// it under the terms of the GNU General Public License as published by -// the Free Software Foundation, either version 3 of the License, or -// (at your option) any later version. -// -// TikZiT is distributed in the hope that it will be useful, -// but WITHOUT ANY WARRANTY; without even the implied warranty of -// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -// GNU General Public License for more details. -// -// You should have received a copy of the GNU General Public License -// along with TikZiT. If not, see <http://www.gnu.org/licenses/>. -// - -#import "NodeStyle+Coder.h" -#import "ShapeNames.h" - -@implementation NodeStyle(Coder) - -- (NSColor*)fillColor { - return [NSColor colorWithDeviceRed:fillColorRGB.redFloat - green:fillColorRGB.greenFloat - blue:fillColorRGB.blueFloat - alpha:1.0f]; -} - -- (void)setFillColor:(NSColor*)c { - NSColor *c1 = [c colorUsingColorSpaceName:NSDeviceRGBColorSpace]; - [self willChangeValueForKey:@"fillColorIsKnown"]; - fillColorRGB = [ColorRGB colorWithFloatRed:c1.redComponent - green:c1.greenComponent - blue:c1.blueComponent]; - [self didChangeValueForKey:@"fillColorIsKnown"]; -} - -- (NSColor*)strokeColor { - return [NSColor colorWithDeviceRed:strokeColorRGB.redFloat - green:strokeColorRGB.greenFloat - blue:strokeColorRGB.blueFloat - alpha:1.0f]; -} - -- (void)setStrokeColor:(NSColor*)c { - NSColor *c1 = [c colorUsingColorSpaceName:NSDeviceRGBColorSpace]; - [self willChangeValueForKey:@"strokeColorIsKnown"]; - strokeColorRGB = [ColorRGB colorWithFloatRed:c1.redComponent - green:c1.greenComponent - blue:c1.blueComponent]; - [self didChangeValueForKey:@"strokeColorIsKnown"]; -} - -- (id)initWithCoder:(NSCoder *)coder { - [super init]; - - // decode keys - name = [coder decodeObjectForKey:@"name"]; - [self setStrokeColor:[coder decodeObjectForKey:@"strokeColor"]]; - [self setFillColor:[coder decodeObjectForKey:@"fillColor"]]; - strokeThickness = [coder decodeIntForKey:@"strokeThickness"]; - shapeName = [coder decodeObjectForKey:@"shapeName"]; - category = [coder decodeObjectForKey:@"category"]; - scale = [coder decodeFloatForKey:@"scale"]; - - // apply defaults - if (scale == 0.0f) scale = 1.0f; - if (shapeName == nil) shapeName = SHAPE_CIRCLE; - - return self; -} - -- (void)encodeWithCoder:(NSCoder *)coder { - [coder encodeObject:name forKey:@"name"]; - [coder encodeObject:[self strokeColor] forKey:@"strokeColor"]; - [coder encodeObject:[self fillColor] forKey:@"fillColor"]; - [coder encodeInt:strokeThickness forKey:@"strokeThickness"]; - [coder encodeObject:shapeName forKey:@"shapeName"]; - [coder encodeObject:category forKey:@"category"]; - [coder encodeFloat:scale forKey:@"scale"]; -} - - -@end diff --git a/tikzit/src/osx/ParseErrorView.h b/tikzit/src/osx/ParseErrorView.h deleted file mode 100644 index bb6141f..0000000 --- a/tikzit/src/osx/ParseErrorView.h +++ /dev/null @@ -1,13 +0,0 @@ -// -// ParseErrorView.h -// TikZiT -// -// Created by Karl Johan Paulsson on 27/01/2013. -// Copyright (c) 2013 Aleks Kissinger. All rights reserved. -// - -#import <Cocoa/Cocoa.h> - -@interface ParseErrorView : NSView - -@end diff --git a/tikzit/src/osx/ParseErrorView.m b/tikzit/src/osx/ParseErrorView.m deleted file mode 100644 index 97b1b94..0000000 --- a/tikzit/src/osx/ParseErrorView.m +++ /dev/null @@ -1,40 +0,0 @@ -// -// ParseErrorView.m -// TikZiT -// -// Created by Karl Johan Paulsson on 27/01/2013. -// Copyright (c) 2013 Aleks Kissinger. All rights reserved. -// - -#import "ParseErrorView.h" - -@implementation ParseErrorView - -- (id)initWithFrame:(NSRect)frame -{ - self = [super initWithFrame:frame]; - if (self) { - // Initialization code here. - } - - return self; -} - -- (void)drawRect:(NSRect)dirtyRect -{ - // Drawing code here. -} - -- (void)awakeFromNib{ - self.layer = [CALayer layer]; - self.wantsLayer = YES; - CALayer *newLayer = [CALayer layer]; - self.layer.backgroundColor = [[NSColor controlColor] CGColor]; - //CGColorCreate(CGColorSpaceCreateDeviceRGB(), (CGFloat[]){ 1, .9, .64, 1 }); -// newLayer.backgroundColor = [NSColor redColor].CGColor; - newLayer.frame = NSMakeRect(100,100,100,100);//NSMakeRect(0,0,image.size.width,image.size.height); - newLayer.position = CGPointMake(20,20); - //[self.layer addSublayer:newLayer]; -} - -@end diff --git a/tikzit/src/osx/PreambleController.h b/tikzit/src/osx/PreambleController.h deleted file mode 100644 index 2d5a8ab..0000000 --- a/tikzit/src/osx/PreambleController.h +++ /dev/null @@ -1,57 +0,0 @@ -// -// PreambleController.h -// TikZiT -// -// Copyright 2010 Aleks Kissinger. All rights reserved. -// -// -// This file is part of TikZiT. -// -// TikZiT is free software: you can redistribute it and/or modify -// it under the terms of the GNU General Public License as published by -// the Free Software Foundation, either version 3 of the License, or -// (at your option) any later version. -// -// TikZiT is distributed in the hope that it will be useful, -// but WITHOUT ANY WARRANTY; without even the implied warranty of -// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -// GNU General Public License for more details. -// -// You should have received a copy of the GNU General Public License -// along with TikZiT. If not, see <http://www.gnu.org/licenses/>. -// - -#import <Cocoa/Cocoa.h> -#import "Preambles.h" -#import "Preambles+Coder.h" - -@interface PreambleController : NSWindowController { - Preambles *preambles; - IBOutlet NSTextView *textView; - IBOutlet NSToolbar *toolbar; - IBOutlet NSToolbarItem *defaultToolbarItem; - IBOutlet NSToolbarItem *customToolbarItem; - IBOutlet NSDictionaryController *preambleDictionaryController; - NSDictionary *textAttrs; - NSAttributedString *preambleText; - NSColor *ghostColor; - - NSIndexSet *selectionIndexes; -} - -@property (readonly) BOOL useDefaultPreamble; -@property (readonly) Preambles *preambles; -@property (retain) NSAttributedString *preambleText; -@property (retain) NSIndexSet *selectionIndexes; - -- (id)initWithWindowNibName:(NSString *)windowNibName plist:(NSString*)plist styles:(NSArray*)sty edges:(NSArray*)edg; -- (void)savePreambles:(NSString*)plist; -- (NSString*)currentPreamble; -- (NSString*)currentPostamble; -- (IBAction)setPreamble:(id)sender; -- (IBAction)insertDefaultStyles:(id)sender; - -- (IBAction)addPreamble:(id)sender; -- (IBAction)duplicatePreamble:(id)sender; - -@end diff --git a/tikzit/src/osx/PreambleController.m b/tikzit/src/osx/PreambleController.m deleted file mode 100644 index e424e7b..0000000 --- a/tikzit/src/osx/PreambleController.m +++ /dev/null @@ -1,169 +0,0 @@ -// -// PreambleController.m -// TikZiT -// -// Copyright 2010 Aleks Kissinger. All rights reserved. -// -// -// This file is part of TikZiT. -// -// TikZiT is free software: you can redistribute it and/or modify -// it under the terms of the GNU General Public License as published by -// the Free Software Foundation, either version 3 of the License, or -// (at your option) any later version. -// -// TikZiT is distributed in the hope that it will be useful, -// but WITHOUT ANY WARRANTY; without even the implied warranty of -// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -// GNU General Public License for more details. -// -// You should have received a copy of the GNU General Public License -// along with TikZiT. If not, see <http://www.gnu.org/licenses/>. -// - -#import "PreambleController.h" - - -@implementation PreambleController - -@synthesize preambleText, preambles; - -- (id)initWithWindowNibName:(NSString *)windowNibName plist:(NSString*)plist styles:(NSArray*)sty edges:(NSArray*)edg { - [super initWithWindowNibName:windowNibName]; - - preambles = (Preambles*)[NSKeyedUnarchiver unarchiveObjectWithFile:plist]; - [preambles setStyles:sty]; - [preambles setEdges:edg]; - if (preambles == nil) preambles = [[Preambles alloc] init]; - - preambleText = nil; - - NSFont *font = [NSFont userFixedPitchFontOfSize:11.0f]; - textAttrs = [NSDictionary dictionaryWithObject:font forKey:NSFontAttributeName]; - ghostColor = [NSColor colorWithDeviceRed:0.9f green:0.9f blue:0.9f alpha:1.0f]; - - - - return self; -} - -- (void)awakeFromNib { - NSArray *arr = [preambleDictionaryController arrangedObjects]; - NSString *current = [preambles selectedPreambleName]; - - if (current != nil && ![current isEqual:@"default"]) { - for (int i = 0; i < [arr count]; ++i) { - if ([[[arr objectAtIndex:i] key] isEqual:current]) { - [self setSelectionIndexes:[NSIndexSet indexSetWithIndex:i]]; - break; - } - } - } -} - -- (BOOL)useDefaultPreamble { - return [[preambles selectedPreambleName] isEqualToString:@"default"]; -} - -- (void)flushText { - if (preambleText != nil && ![self useDefaultPreamble]) { - [preambles setCurrentPreamble:[preambleText string]]; - } -} - -- (void)setCurrentPreamble:(NSString*)current { - [self flushText]; - - [self willChangeValueForKey:@"useDefaultPreamble"]; - [preambles setSelectedPreambleName:current]; - [self didChangeValueForKey:@"useDefaultPreamble"]; - - [self setPreambleText: - [[NSAttributedString alloc] initWithString:[preambles currentPreamble] - attributes:textAttrs]]; -} - -- (void)showWindow:(id)sender { - [super showWindow:sender]; - if ([self useDefaultPreamble]) { - [toolbar setSelectedItemIdentifier:[defaultToolbarItem itemIdentifier]]; - } else { - [toolbar setSelectedItemIdentifier:[customToolbarItem itemIdentifier]]; - } - - [self setPreamble:self]; -} - -- (void)savePreambles:(NSString*)plist { - [self flushText]; - [NSKeyedArchiver archiveRootObject:preambles toFile:plist]; -} - -- (NSString*)currentPreamble { - [self flushText]; - return [preambles currentPreamble]; -} - -- (NSString*)currentPostamble { - return [preambles currentPostamble]; -} - -- (void)setSelectionIndexes:(NSIndexSet *)idx { - [self willChangeValueForKey:@"selectionIndexes"]; - selectionIndexes = idx; - [self didChangeValueForKey:@"selectionIndexes"]; - - [self setPreamble:self]; -} - -- (NSIndexSet*)selectionIndexes { - return selectionIndexes; -} - -- (IBAction)setPreamble:(id)sender { - if ([[toolbar selectedItemIdentifier] isEqualToString:[defaultToolbarItem itemIdentifier]]) { - [self setCurrentPreamble:@"default"]; - [textView setBackgroundColor:ghostColor]; - } else if ([[toolbar selectedItemIdentifier] isEqualToString:[customToolbarItem itemIdentifier]]) { - NSString *key = nil; - if ([selectionIndexes count]==1) { - int i = [selectionIndexes firstIndex]; - key = [[[preambleDictionaryController arrangedObjects] objectAtIndex:i] key]; - } - if (key != nil) { - [self setCurrentPreamble:key]; - //NSLog(@"preamble set to %@", key); - } else { - [self setCurrentPreamble:@"custom"]; - //NSLog(@"preamble set to custom"); - } - [textView setBackgroundColor:[NSColor whiteColor]]; - } -} - -- (IBAction)insertDefaultStyles:(id)sender { - [textView insertText:[preambles styleDefinitions]]; -} - -- (IBAction)addPreamble:(id)sender { - [preambleDictionaryController setInitialKey:@"new preamble"]; - [preambleDictionaryController setInitialValue:[preambles defaultPreamble]]; - [preambleDictionaryController add:sender]; -} - -- (void)controlTextDidEndEditing:(NSNotification *)obj { - //NSLog(@"got a text change"); - [self setPreamble:[obj object]]; -} - - -// NOT IMPLEMENTED -- (IBAction)duplicatePreamble:(id)sender { -// NSLog(@"set text to: %@", [preambles currentPreamble]); -// [preambleDictionaryController setInitialKey:[preambles selectedPreambleName]]; -// [preambleDictionaryController setInitialValue:[preambles currentPreamble]]; -// [preambleDictionaryController add:sender]; -} - - -@end diff --git a/tikzit/src/osx/Preambles+Coder.h b/tikzit/src/osx/Preambles+Coder.h deleted file mode 100644 index 5a270c5..0000000 --- a/tikzit/src/osx/Preambles+Coder.h +++ /dev/null @@ -1,32 +0,0 @@ -// -// Preambles+Coder.h -// TikZiT -// -// Copyright 2010 Aleks Kissinger. All rights reserved. -// -// -// This file is part of TikZiT. -// -// TikZiT is free software: you can redistribute it and/or modify -// it under the terms of the GNU General Public License as published by -// the Free Software Foundation, either version 3 of the License, or -// (at your option) any later version. -// -// TikZiT is distributed in the hope that it will be useful, -// but WITHOUT ANY WARRANTY; without even the implied warranty of -// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -// GNU General Public License for more details. -// -// You should have received a copy of the GNU General Public License -// along with TikZiT. If not, see <http://www.gnu.org/licenses/>. -// - -#import "Preambles.h" -#import <Cocoa/Cocoa.h> - -@interface Preambles (Coder) - -- (id)initWithCoder:(NSCoder *)coder; -- (void)encodeWithCoder:(NSCoder *)coder; - -@end diff --git a/tikzit/src/osx/Preambles+Coder.m b/tikzit/src/osx/Preambles+Coder.m deleted file mode 100644 index 6b9768a..0000000 --- a/tikzit/src/osx/Preambles+Coder.m +++ /dev/null @@ -1,41 +0,0 @@ -// -// Preambles+Coder.m -// TikZiT -// -// Copyright 2010 Aleks Kissinger. All rights reserved. -// -// -// This file is part of TikZiT. -// -// TikZiT is free software: you can redistribute it and/or modify -// it under the terms of the GNU General Public License as published by -// the Free Software Foundation, either version 3 of the License, or -// (at your option) any later version. -// -// TikZiT is distributed in the hope that it will be useful, -// but WITHOUT ANY WARRANTY; without even the implied warranty of -// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -// GNU General Public License for more details. -// -// You should have received a copy of the GNU General Public License -// along with TikZiT. If not, see <http://www.gnu.org/licenses/>. -// - -#import "Preambles+Coder.h" - - -@implementation Preambles (Coder) - -- (id)initWithCoder:(NSCoder *)coder { - [super init]; - selectedPreambleName = [coder decodeObjectForKey:@"selectedPreamble"]; - preambleDict = [coder decodeObjectForKey:@"preambles"]; - return self; -} - -- (void)encodeWithCoder:(NSCoder *)coder { - [coder encodeObject:selectedPreambleName forKey:@"selectedPreamble"]; - [coder encodeObject:preambleDict forKey:@"preambles"]; -} - -@end diff --git a/tikzit/src/osx/PreferenceController.h b/tikzit/src/osx/PreferenceController.h deleted file mode 100644 index bc6ed67..0000000 --- a/tikzit/src/osx/PreferenceController.h +++ /dev/null @@ -1,37 +0,0 @@ -// -// PreferenceController.h -// TikZiT -// -// Created by Karl Johan Paulsson on 26/02/2013. -// Copyright (c) 2013 Aleks Kissinger. All rights reserved. -// -// -// This file is part of TikZiT. -// -// TikZiT is free software: you can redistribute it and/or modify -// it under the terms of the GNU General Public License as published by -// the Free Software Foundation, either version 3 of the License, or -// (at your option) any later version. -// -// TikZiT is distributed in the hope that it will be useful, -// but WITHOUT ANY WARRANTY; without even the implied warranty of -// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -// GNU General Public License for more details. -// -// You should have received a copy of the GNU General Public License -// along with TikZiT. If not, see <http://www.gnu.org/licenses/>. -// - -#import <Cocoa/Cocoa.h> - -@interface PreferenceController : NSWindowController{ - - IBOutlet NSView *engineView; - IBOutlet NSView *generalView; - - int currentViewTag; -} - -- (IBAction)switchView:(id)sender; - -@end diff --git a/tikzit/src/osx/PreferenceController.m b/tikzit/src/osx/PreferenceController.m deleted file mode 100644 index 75d7ef7..0000000 --- a/tikzit/src/osx/PreferenceController.m +++ /dev/null @@ -1,116 +0,0 @@ -// -// PreferenceController.m -// TikZiT -// -// Created by Karl Johan Paulsson on 26/02/2013. -// Copyright (c) 2013 Aleks Kissinger. All rights reserved. -// -// -// This file is part of TikZiT. -// -// TikZiT is free software: you can redistribute it and/or modify -// it under the terms of the GNU General Public License as published by -// the Free Software Foundation, either version 3 of the License, or -// (at your option) any later version. -// -// TikZiT is distributed in the hope that it will be useful, -// but WITHOUT ANY WARRANTY; without even the implied warranty of -// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -// GNU General Public License for more details. -// -// You should have received a copy of the GNU General Public License -// along with TikZiT. If not, see <http://www.gnu.org/licenses/>. -// - -#import "PreferenceController.h" - -@interface PreferenceController () - -@end - -@implementation PreferenceController - -- (id)initWithWindow:(NSWindow *)window -{ - self = [super initWithWindow:window]; - if (self) { - // Initialization code here. - } - - return self; -} - -- (void)windowDidLoad -{ - [super windowDidLoad]; - - // Implement this method to handle any initialization after your window controller's window has been loaded from its nib file. -} - -- (NSRect)newFrameForNewContentView:(NSView*)view { - - NSWindow *window = [self window]; - NSRect newFrameRect = [window frameRectForContentRect:[view frame]]; - NSRect oldFrameRect = [window frame]; - NSSize newSize = newFrameRect.size; - NSSize oldSize = oldFrameRect.size; - - NSRect frame = [window frame]; - frame.size = newSize; - frame.origin.y -= (newSize.height - oldSize.height); - - return frame; -} - -- (NSView *)viewForTag:(int)tag { - - NSView *view = nil; - switch (tag) { - default: - case 0: - view = generalView; - break; - case 1: - view = engineView; - break; - } - - return view; -} - -- (BOOL)validateToolbarItem:(NSToolbarItem *)item { - - if ([item tag] == currentViewTag) return NO; - else return YES; - -} - -- (void)awakeFromNib { - - [[self window] setContentSize:[generalView frame].size]; - [[[self window] contentView] addSubview:generalView]; - [[[self window] contentView] setWantsLayer:YES]; -} - -- (IBAction)switchView:(id)sender { - - int tag = [sender tag]; - NSView *view = [self viewForTag:tag]; - NSView *previousView = [self viewForTag:currentViewTag]; - currentViewTag = tag; - - NSRect newFrame = [self newFrameForNewContentView:view]; - - [NSAnimationContext beginGrouping]; - - if ([[NSApp currentEvent] modifierFlags] & NSShiftKeyMask) - [[NSAnimationContext currentContext] setDuration:1.0]; - - [[[[self window] contentView] animator] replaceSubview:previousView with:view]; - [[[self window] animator] setFrame:newFrame display:YES]; - - [NSAnimationContext endGrouping]; - -} - -@end diff --git a/tikzit/src/osx/Preferences.xib b/tikzit/src/osx/Preferences.xib deleted file mode 100644 index 1b2d0c3..0000000 --- a/tikzit/src/osx/Preferences.xib +++ /dev/null @@ -1,795 +0,0 @@ -<?xml version="1.0" encoding="UTF-8"?> -<archive type="com.apple.InterfaceBuilder3.Cocoa.XIB" version="8.00"> - <data> - <int key="IBDocument.SystemTarget">1080</int> - <string key="IBDocument.SystemVersion">12C60</string> - <string key="IBDocument.InterfaceBuilderVersion">2840</string> - <string key="IBDocument.AppKitVersion">1187.34</string> - <string key="IBDocument.HIToolboxVersion">625.00</string> - <object class="NSMutableDictionary" key="IBDocument.PluginVersions"> - <string key="NS.key.0">com.apple.InterfaceBuilder.CocoaPlugin</string> - <string key="NS.object.0">2840</string> - </object> - <array key="IBDocument.IntegratedClassDependencies"> - <string>IBNSLayoutConstraint</string> - <string>NSButton</string> - <string>NSButtonCell</string> - <string>NSCustomObject</string> - <string>NSCustomView</string> - <string>NSTextField</string> - <string>NSTextFieldCell</string> - <string>NSToolbar</string> - <string>NSToolbarItem</string> - <string>NSUserDefaultsController</string> - <string>NSView</string> - <string>NSWindowTemplate</string> - </array> - <array key="IBDocument.PluginDependencies"> - <string>com.apple.InterfaceBuilder.CocoaPlugin</string> - </array> - <object class="NSMutableDictionary" key="IBDocument.Metadata"> - <string key="NS.key.0">PluginDependencyRecalculationVersion</string> - <integer value="1" key="NS.object.0"/> - </object> - <array class="NSMutableArray" key="IBDocument.RootObjects" id="1000"> - <object class="NSCustomObject" id="1001"> - <string key="NSClassName">PreferenceController</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="1005"> - <int key="NSWindowStyleMask">15</int> - <int key="NSWindowBacking">2</int> - <string key="NSWindowRect">{{196, 240}, {480, 270}}</string> - <int key="NSWTFlags">544735232</int> - <string key="NSWindowTitle">Window</string> - <string key="NSWindowClass">NSWindow</string> - <object class="NSToolbar" key="NSViewClass" id="338765480"> - <object class="NSMutableString" key="NSToolbarIdentifier"> - <characters key="NS.bytes">C1747407-DC9A-4297-9C1C-0A5010984E6C</characters> - </object> - <nil key="NSToolbarDelegate"/> - <bool key="NSToolbarPrefersToBeShown">YES</bool> - <bool key="NSToolbarShowsBaselineSeparator">YES</bool> - <bool key="NSToolbarAllowsUserCustomization">NO</bool> - <bool key="NSToolbarAutosavesConfiguration">NO</bool> - <int key="NSToolbarDisplayMode">1</int> - <int key="NSToolbarSizeMode">1</int> - <dictionary class="NSMutableDictionary" key="NSToolbarIBIdentifiedItems"> - <object class="NSToolbarItem" key="A3DDD070-5637-444B-92C6-905084CAC389" id="914743654"> - <object class="NSMutableString" key="NSToolbarItemIdentifier"> - <characters key="NS.bytes">A3DDD070-5637-444B-92C6-905084CAC389</characters> - </object> - <string key="NSToolbarItemLabel">General</string> - <string key="NSToolbarItemPaletteLabel">General</string> - <string key="NSToolbarItemToolTip"/> - <nil key="NSToolbarItemView"/> - <object class="NSCustomResource" key="NSToolbarItemImage" id="31080890"> - <string key="NSClassName">NSImage</string> - <string key="NSResourceName">NSPreferencesGeneral</string> - </object> - <nil key="NSToolbarItemTarget"/> - <nil key="NSToolbarItemAction"/> - <string key="NSToolbarItemMinSize">{0, 0}</string> - <string key="NSToolbarItemMaxSize">{0, 0}</string> - <bool key="NSToolbarItemEnabled">YES</bool> - <bool key="NSToolbarItemAutovalidates">YES</bool> - <int key="NSToolbarItemTag">0</int> - <bool key="NSToolbarIsUserRemovable">YES</bool> - <int key="NSToolbarItemVisibilityPriority">0</int> - </object> - <object class="NSToolbarItem" key="F85FE7C2-9847-4E58-8BF6-BE334E918CA7" id="641338426"> - <object class="NSMutableString" key="NSToolbarItemIdentifier"> - <characters key="NS.bytes">F85FE7C2-9847-4E58-8BF6-BE334E918CA7</characters> - </object> - <string key="NSToolbarItemLabel">Engine</string> - <string key="NSToolbarItemPaletteLabel">Engine</string> - <string key="NSToolbarItemToolTip"/> - <nil key="NSToolbarItemView"/> - <reference key="NSToolbarItemImage" ref="31080890"/> - <nil key="NSToolbarItemTarget"/> - <nil key="NSToolbarItemAction"/> - <string key="NSToolbarItemMinSize">{0, 0}</string> - <string key="NSToolbarItemMaxSize">{0, 0}</string> - <bool key="NSToolbarItemEnabled">YES</bool> - <bool key="NSToolbarItemAutovalidates">YES</bool> - <int key="NSToolbarItemTag">1</int> - <bool key="NSToolbarIsUserRemovable">YES</bool> - <int key="NSToolbarItemVisibilityPriority">0</int> - </object> - </dictionary> - <array key="NSToolbarIBAllowedItems"> - <reference ref="914743654"/> - <reference ref="641338426"/> - </array> - <array key="NSToolbarIBDefaultItems"> - <reference ref="914743654"/> - <reference ref="641338426"/> - </array> - <array key="NSToolbarIBSelectableItems" id="0"/> - </object> - <nil key="NSUserInterfaceItemIdentifier"/> - <object class="NSView" key="NSWindowView" id="1006"> - <reference key="NSNextResponder"/> - <int key="NSvFlags">256</int> - <string key="NSFrameSize">{480, 270}</string> - <reference key="NSSuperview"/> - <reference key="NSWindow"/> - <reference key="NSNextKeyView"/> - </object> - <string key="NSScreenRect">{{0, 0}, {1680, 1050}}</string> - <string key="NSMaxSize">{10000000000000, 10000000000000}</string> - <bool key="NSWindowIsRestorable">YES</bool> - </object> - <object class="NSCustomView" id="103531975"> - <reference key="NSNextResponder"/> - <int key="NSvFlags">268</int> - <array class="NSMutableArray" key="NSSubviews"> - <object class="NSButton" id="764495169"> - <reference key="NSNextResponder" ref="103531975"/> - <int key="NSvFlags">268</int> - <string key="NSFrame">{{18, 15}, {215, 18}}</string> - <reference key="NSSuperview" ref="103531975"/> - <reference key="NSWindow"/> - <reference key="NSNextKeyView"/> - <string key="NSReuseIdentifierKey">_NS:9</string> - <bool key="NSEnabled">YES</bool> - <object class="NSButtonCell" key="NSCell" id="292348615"> - <int key="NSCellFlags">-2080374784</int> - <int key="NSCellFlags2">268435456</int> - <string key="NSContents">Bring preview window to focus</string> - <object class="NSFont" key="NSSupport" id="924461577"> - <string key="NSName">LucidaGrande</string> - <double key="NSSize">13</double> - <int key="NSfFlags">1044</int> - </object> - <string key="NSCellIdentifier">_NS:9</string> - <reference key="NSControlView" ref="764495169"/> - <int key="NSButtonFlags">1211912448</int> - <int key="NSButtonFlags2">2</int> - <object class="NSCustomResource" key="NSNormalImage"> - <string key="NSClassName">NSImage</string> - <string key="NSResourceName">NSSwitch</string> - </object> - <object class="NSButtonImageSource" key="NSAlternateImage"> - <string key="NSImageName">NSSwitch</string> - </object> - <string key="NSAlternateContents"/> - <string key="NSKeyEquivalent"/> - <int key="NSPeriodicDelay">200</int> - <int key="NSPeriodicInterval">25</int> - </object> - <bool key="NSAllowsLogicalLayoutDirection">NO</bool> - </object> - <object class="NSTextField" id="762565485"> - <reference key="NSNextResponder" ref="103531975"/> - <int key="NSvFlags">268</int> - <string key="NSFrame">{{20, 39}, {440, 22}}</string> - <reference key="NSSuperview" ref="103531975"/> - <reference key="NSWindow"/> - <reference key="NSNextKeyView" ref="764495169"/> - <string key="NSReuseIdentifierKey">_NS:9</string> - <bool key="NSEnabled">YES</bool> - <object class="NSTextFieldCell" key="NSCell" id="186397132"> - <int key="NSCellFlags">-1804599231</int> - <int key="NSCellFlags2">272630784</int> - <string key="NSContents"/> - <reference key="NSSupport" ref="924461577"/> - <string key="NSCellIdentifier">_NS:9</string> - <reference key="NSControlView" ref="762565485"/> - <bool key="NSDrawsBackground">YES</bool> - <object class="NSColor" key="NSBackgroundColor"> - <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"> - <int key="NSColorSpace">6</int> - <string key="NSCatalogName">System</string> - <string key="NSColorName">textColor</string> - <object class="NSColor" key="NSColor" id="433834218"> - <int key="NSColorSpace">3</int> - <bytes key="NSWhite">MAA</bytes> - </object> - </object> - </object> - <bool key="NSAllowsLogicalLayoutDirection">NO</bool> - </object> - <object class="NSTextField" id="539123669"> - <reference key="NSNextResponder" ref="103531975"/> - <int key="NSvFlags">268</int> - <string key="NSFrame">{{17, 69}, {142, 17}}</string> - <reference key="NSSuperview" ref="103531975"/> - <reference key="NSWindow"/> - <reference key="NSNextKeyView" ref="762565485"/> - <string key="NSReuseIdentifierKey">_NS:1535</string> - <bool key="NSEnabled">YES</bool> - <object class="NSTextFieldCell" key="NSCell" id="459248896"> - <int key="NSCellFlags">68157504</int> - <int key="NSCellFlags2">272630784</int> - <string key="NSContents">pdfLaTeX source path</string> - <reference key="NSSupport" ref="924461577"/> - <string key="NSCellIdentifier">_NS:1535</string> - <reference key="NSControlView" ref="539123669"/> - <object class="NSColor" key="NSBackgroundColor" id="1052083660"> - <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">MC42NjY2NjY2NjY3AA</bytes> - </object> - </object> - <object class="NSColor" key="NSTextColor" id="266723537"> - <int key="NSColorSpace">6</int> - <string key="NSCatalogName">System</string> - <string key="NSColorName">controlTextColor</string> - <reference key="NSColor" ref="433834218"/> - </object> - </object> - <bool key="NSAllowsLogicalLayoutDirection">NO</bool> - </object> - </array> - <string key="NSFrameSize">{480, 96}</string> - <reference key="NSSuperview"/> - <reference key="NSWindow"/> - <reference key="NSNextKeyView" ref="539123669"/> - <string key="NSReuseIdentifierKey">_NS:9</string> - <string key="NSClassName">NSView</string> - </object> - <object class="NSCustomView" id="596032684"> - <reference key="NSNextResponder"/> - <int key="NSvFlags">268</int> - <array class="NSMutableArray" key="NSSubviews"> - <object class="NSTextField" id="621229635"> - <reference key="NSNextResponder" ref="596032684"/> - <int key="NSvFlags">268</int> - <string key="NSFrame">{{214, 40}, {53, 17}}</string> - <reference key="NSSuperview" ref="596032684"/> - <reference key="NSWindow"/> - <reference key="NSNextKeyView"/> - <string key="NSReuseIdentifierKey">_NS:1535</string> - <bool key="NSEnabled">YES</bool> - <object class="NSTextFieldCell" key="NSCell" id="653425178"> - <int key="NSCellFlags">68157504</int> - <int key="NSCellFlags2">272630784</int> - <string key="NSContents">General</string> - <reference key="NSSupport" ref="924461577"/> - <string key="NSCellIdentifier">_NS:1535</string> - <reference key="NSControlView" ref="621229635"/> - <reference key="NSBackgroundColor" ref="1052083660"/> - <reference key="NSTextColor" ref="266723537"/> - </object> - <bool key="NSAllowsLogicalLayoutDirection">NO</bool> - </object> - </array> - <string key="NSFrameSize">{480, 96}</string> - <reference key="NSSuperview"/> - <reference key="NSWindow"/> - <reference key="NSNextKeyView" ref="621229635"/> - <string key="NSReuseIdentifierKey">_NS:9</string> - <string key="NSClassName">NSView</string> - </object> - <object class="NSUserDefaultsController" id="706090457"> - <bool key="NSSharedInstance">YES</bool> - </object> - </array> - <object class="IBObjectContainer" key="IBDocument.Objects"> - <array class="NSMutableArray" key="connectionRecords"> - <object class="IBConnectionRecord"> - <object class="IBOutletConnection" key="connection"> - <string key="label">window</string> - <reference key="source" ref="1001"/> - <reference key="destination" ref="1005"/> - </object> - <int key="connectionID">3</int> - </object> - <object class="IBConnectionRecord"> - <object class="IBOutletConnection" key="connection"> - <string key="label">engineView</string> - <reference key="source" ref="1001"/> - <reference key="destination" ref="103531975"/> - </object> - <int key="connectionID">23</int> - </object> - <object class="IBConnectionRecord"> - <object class="IBOutletConnection" key="connection"> - <string key="label">generalView</string> - <reference key="source" ref="1001"/> - <reference key="destination" ref="596032684"/> - </object> - <int key="connectionID">25</int> - </object> - <object class="IBConnectionRecord"> - <object class="IBActionConnection" key="connection"> - <string key="label">switchView:</string> - <reference key="source" ref="1001"/> - <reference key="destination" ref="914743654"/> - </object> - <int key="connectionID">26</int> - </object> - <object class="IBConnectionRecord"> - <object class="IBActionConnection" key="connection"> - <string key="label">switchView:</string> - <reference key="source" ref="1001"/> - <reference key="destination" ref="641338426"/> - </object> - <int key="connectionID">27</int> - </object> - <object class="IBConnectionRecord"> - <object class="IBOutletConnection" key="connection"> - <string key="label">delegate</string> - <reference key="source" ref="1005"/> - <reference key="destination" ref="1001"/> - </object> - <int key="connectionID">4</int> - </object> - <object class="IBConnectionRecord"> - <object class="IBBindingConnection" key="connection"> - <string key="label">value: values.net.sourceforge.tikzit.pdflatexpath</string> - <reference key="source" ref="186397132"/> - <reference key="destination" ref="706090457"/> - <object class="NSNibBindingConnector" key="connector"> - <reference key="NSSource" ref="186397132"/> - <reference key="NSDestination" ref="706090457"/> - <string key="NSLabel">value: values.net.sourceforge.tikzit.pdflatexpath</string> - <string key="NSBinding">value</string> - <string key="NSKeyPath">values.net.sourceforge.tikzit.pdflatexpath</string> - <int key="NSNibBindingConnectorVersion">2</int> - </object> - </object> - <int key="connectionID">54</int> - </object> - <object class="IBConnectionRecord"> - <object class="IBBindingConnection" key="connection"> - <string key="label">value: values.net.sourceforge.tikzit.previewfocus</string> - <reference key="source" ref="292348615"/> - <reference key="destination" ref="706090457"/> - <object class="NSNibBindingConnector" key="connector"> - <reference key="NSSource" ref="292348615"/> - <reference key="NSDestination" ref="706090457"/> - <string key="NSLabel">value: values.net.sourceforge.tikzit.previewfocus</string> - <string key="NSBinding">value</string> - <string key="NSKeyPath">values.net.sourceforge.tikzit.previewfocus</string> - <int key="NSNibBindingConnectorVersion">2</int> - </object> - </object> - <int key="connectionID">62</int> - </object> - </array> - <object class="IBMutableOrderedSet" key="objectRecords"> - <array key="orderedObjects"> - <object class="IBObjectRecord"> - <int key="objectID">0</int> - <reference key="object" ref="0"/> - <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="0"/> - <string key="objectName">File's Owner</string> - </object> - <object class="IBObjectRecord"> - <int key="objectID">-1</int> - <reference key="object" ref="1003"/> - <reference key="parent" ref="0"/> - <string key="objectName">First Responder</string> - </object> - <object class="IBObjectRecord"> - <int key="objectID">-3</int> - <reference key="object" ref="1004"/> - <reference key="parent" ref="0"/> - <string key="objectName">Application</string> - </object> - <object class="IBObjectRecord"> - <int key="objectID">1</int> - <reference key="object" ref="1005"/> - <array class="NSMutableArray" key="children"> - <reference ref="1006"/> - <reference ref="338765480"/> - </array> - <reference key="parent" ref="0"/> - </object> - <object class="IBObjectRecord"> - <int key="objectID">2</int> - <reference key="object" ref="1006"/> - <reference key="parent" ref="1005"/> - </object> - <object class="IBObjectRecord"> - <int key="objectID">5</int> - <reference key="object" ref="338765480"/> - <array class="NSMutableArray" key="children"> - <reference ref="641338426"/> - <reference ref="914743654"/> - </array> - <reference key="parent" ref="1005"/> - </object> - <object class="IBObjectRecord"> - <int key="objectID">11</int> - <reference key="object" ref="641338426"/> - <reference key="parent" ref="338765480"/> - </object> - <object class="IBObjectRecord"> - <int key="objectID">12</int> - <reference key="object" ref="914743654"/> - <reference key="parent" ref="338765480"/> - </object> - <object class="IBObjectRecord"> - <int key="objectID">13</int> - <reference key="object" ref="103531975"/> - <array class="NSMutableArray" key="children"> - <object class="IBNSLayoutConstraint" id="728277728"> - <reference key="firstItem" ref="764495169"/> - <int key="firstAttribute">3</int> - <int key="relation">0</int> - <reference key="secondItem" ref="762565485"/> - <int key="secondAttribute">4</int> - <float key="multiplier">1</float> - <object class="IBNSLayoutSymbolicConstant" key="constant"> - <double key="value">8</double> - </object> - <float key="priority">1000</float> - <reference key="containingView" ref="103531975"/> - <int key="scoringType">6</int> - <float key="scoringTypeFloat">24</float> - <int key="contentType">3</int> - </object> - <object class="IBNSLayoutConstraint" id="116293249"> - <reference key="firstItem" ref="764495169"/> - <int key="firstAttribute">5</int> - <int key="relation">0</int> - <reference key="secondItem" ref="103531975"/> - <int key="secondAttribute">5</int> - <float key="multiplier">1</float> - <object class="IBNSLayoutSymbolicConstant" key="constant"> - <double key="value">20</double> - </object> - <float key="priority">1000</float> - <reference key="containingView" ref="103531975"/> - <int key="scoringType">8</int> - <float key="scoringTypeFloat">29</float> - <int key="contentType">3</int> - </object> - <object class="IBNSLayoutConstraint" id="206376115"> - <reference key="firstItem" ref="103531975"/> - <int key="firstAttribute">6</int> - <int key="relation">0</int> - <reference key="secondItem" ref="762565485"/> - <int key="secondAttribute">6</int> - <float key="multiplier">1</float> - <object class="IBNSLayoutSymbolicConstant" key="constant"> - <double key="value">20</double> - </object> - <float key="priority">1000</float> - <reference key="containingView" ref="103531975"/> - <int key="scoringType">8</int> - <float key="scoringTypeFloat">29</float> - <int key="contentType">3</int> - </object> - <object class="IBNSLayoutConstraint" id="921593038"> - <reference key="firstItem" ref="762565485"/> - <int key="firstAttribute">3</int> - <int key="relation">0</int> - <reference key="secondItem" ref="539123669"/> - <int key="secondAttribute">4</int> - <float key="multiplier">1</float> - <object class="IBNSLayoutSymbolicConstant" key="constant"> - <double key="value">8</double> - </object> - <float key="priority">1000</float> - <reference key="containingView" ref="103531975"/> - <int key="scoringType">6</int> - <float key="scoringTypeFloat">24</float> - <int key="contentType">3</int> - </object> - <object class="IBNSLayoutConstraint" id="783720041"> - <reference key="firstItem" ref="762565485"/> - <int key="firstAttribute">5</int> - <int key="relation">0</int> - <reference key="secondItem" ref="103531975"/> - <int key="secondAttribute">5</int> - <float key="multiplier">1</float> - <object class="IBNSLayoutSymbolicConstant" key="constant"> - <double key="value">20</double> - </object> - <float key="priority">1000</float> - <reference key="containingView" ref="103531975"/> - <int key="scoringType">8</int> - <float key="scoringTypeFloat">29</float> - <int key="contentType">3</int> - </object> - <object class="IBNSLayoutConstraint" id="338893657"> - <reference key="firstItem" ref="539123669"/> - <int key="firstAttribute">3</int> - <int key="relation">0</int> - <reference key="secondItem" ref="103531975"/> - <int key="secondAttribute">3</int> - <float key="multiplier">1</float> - <object class="IBLayoutConstant" key="constant"> - <double key="value">10</double> - </object> - <float key="priority">1000</float> - <reference key="containingView" ref="103531975"/> - <int key="scoringType">3</int> - <float key="scoringTypeFloat">9</float> - <int key="contentType">3</int> - </object> - <object class="IBNSLayoutConstraint" id="559306534"> - <reference key="firstItem" ref="539123669"/> - <int key="firstAttribute">5</int> - <int key="relation">0</int> - <reference key="secondItem" ref="103531975"/> - <int key="secondAttribute">5</int> - <float key="multiplier">1</float> - <object class="IBNSLayoutSymbolicConstant" key="constant"> - <double key="value">20</double> - </object> - <float key="priority">1000</float> - <reference key="containingView" ref="103531975"/> - <int key="scoringType">8</int> - <float key="scoringTypeFloat">29</float> - <int key="contentType">3</int> - </object> - <reference ref="539123669"/> - <reference ref="762565485"/> - <reference ref="764495169"/> - </array> - <reference key="parent" ref="0"/> - </object> - <object class="IBObjectRecord"> - <int key="objectID">14</int> - <reference key="object" ref="596032684"/> - <array class="NSMutableArray" key="children"> - <object class="IBNSLayoutConstraint" id="536442865"> - <reference key="firstItem" ref="621229635"/> - <int key="firstAttribute">10</int> - <int key="relation">0</int> - <reference key="secondItem" ref="596032684"/> - <int key="secondAttribute">10</int> - <float key="multiplier">1</float> - <object class="IBLayoutConstant" key="constant"> - <double key="value">0.0</double> - </object> - <float key="priority">1000</float> - <reference key="containingView" ref="596032684"/> - <int key="scoringType">5</int> - <float key="scoringTypeFloat">22</float> - <int key="contentType">2</int> - </object> - <object class="IBNSLayoutConstraint" id="826972647"> - <reference key="firstItem" ref="621229635"/> - <int key="firstAttribute">9</int> - <int key="relation">0</int> - <reference key="secondItem" ref="596032684"/> - <int key="secondAttribute">9</int> - <float key="multiplier">1</float> - <object class="IBLayoutConstant" key="constant"> - <double key="value">0.0</double> - </object> - <float key="priority">1000</float> - <reference key="containingView" ref="596032684"/> - <int key="scoringType">5</int> - <float key="scoringTypeFloat">22</float> - <int key="contentType">2</int> - </object> - <reference ref="621229635"/> - </array> - <reference key="parent" ref="0"/> - </object> - <object class="IBObjectRecord"> - <int key="objectID">15</int> - <reference key="object" ref="539123669"/> - <array class="NSMutableArray" key="children"> - <reference ref="459248896"/> - </array> - <reference key="parent" ref="103531975"/> - </object> - <object class="IBObjectRecord"> - <int key="objectID">16</int> - <reference key="object" ref="459248896"/> - <reference key="parent" ref="539123669"/> - </object> - <object class="IBObjectRecord"> - <int key="objectID">19</int> - <reference key="object" ref="621229635"/> - <array class="NSMutableArray" key="children"> - <reference ref="653425178"/> - </array> - <reference key="parent" ref="596032684"/> - </object> - <object class="IBObjectRecord"> - <int key="objectID">20</int> - <reference key="object" ref="653425178"/> - <reference key="parent" ref="621229635"/> - </object> - <object class="IBObjectRecord"> - <int key="objectID">28</int> - <reference key="object" ref="826972647"/> - <reference key="parent" ref="596032684"/> - </object> - <object class="IBObjectRecord"> - <int key="objectID">29</int> - <reference key="object" ref="536442865"/> - <reference key="parent" ref="596032684"/> - </object> - <object class="IBObjectRecord"> - <int key="objectID">30</int> - <reference key="object" ref="559306534"/> - <reference key="parent" ref="103531975"/> - </object> - <object class="IBObjectRecord"> - <int key="objectID">31</int> - <reference key="object" ref="338893657"/> - <reference key="parent" ref="103531975"/> - </object> - <object class="IBObjectRecord"> - <int key="objectID">32</int> - <reference key="object" ref="762565485"/> - <array class="NSMutableArray" key="children"> - <reference ref="186397132"/> - </array> - <reference key="parent" ref="103531975"/> - </object> - <object class="IBObjectRecord"> - <int key="objectID">33</int> - <reference key="object" ref="186397132"/> - <reference key="parent" ref="762565485"/> - </object> - <object class="IBObjectRecord"> - <int key="objectID">36</int> - <reference key="object" ref="783720041"/> - <reference key="parent" ref="103531975"/> - </object> - <object class="IBObjectRecord"> - <int key="objectID">39</int> - <reference key="object" ref="706090457"/> - <reference key="parent" ref="0"/> - </object> - <object class="IBObjectRecord"> - <int key="objectID">55</int> - <reference key="object" ref="921593038"/> - <reference key="parent" ref="103531975"/> - </object> - <object class="IBObjectRecord"> - <int key="objectID">56</int> - <reference key="object" ref="206376115"/> - <reference key="parent" ref="103531975"/> - </object> - <object class="IBObjectRecord"> - <int key="objectID">57</int> - <reference key="object" ref="764495169"/> - <array class="NSMutableArray" key="children"> - <reference ref="292348615"/> - </array> - <reference key="parent" ref="103531975"/> - </object> - <object class="IBObjectRecord"> - <int key="objectID">58</int> - <reference key="object" ref="292348615"/> - <reference key="parent" ref="764495169"/> - </object> - <object class="IBObjectRecord"> - <int key="objectID">59</int> - <reference key="object" ref="116293249"/> - <reference key="parent" ref="103531975"/> - </object> - <object class="IBObjectRecord"> - <int key="objectID">60</int> - <reference key="object" ref="728277728"/> - <reference key="parent" ref="103531975"/> - </object> - </array> - </object> - <dictionary class="NSMutableDictionary" key="flattenedProperties"> - <string key="-1.IBPluginDependency">com.apple.InterfaceBuilder.CocoaPlugin</string> - <string key="-2.IBPluginDependency">com.apple.InterfaceBuilder.CocoaPlugin</string> - <string key="-3.IBPluginDependency">com.apple.InterfaceBuilder.CocoaPlugin</string> - <string key="1.IBPluginDependency">com.apple.InterfaceBuilder.CocoaPlugin</string> - <string key="1.IBWindowTemplateEditedContentRect">{{357, 418}, {480, 270}}</string> - <boolean value="NO" key="1.NSWindowTemplate.visibleAtLaunch"/> - <string key="11.IBPluginDependency">com.apple.InterfaceBuilder.CocoaPlugin</string> - <string key="12.IBPluginDependency">com.apple.InterfaceBuilder.CocoaPlugin</string> - <array key="13.IBNSViewMetadataConstraints"> - <reference ref="559306534"/> - <reference ref="338893657"/> - <reference ref="783720041"/> - <reference ref="921593038"/> - <reference ref="206376115"/> - <reference ref="116293249"/> - <reference ref="728277728"/> - </array> - <string key="13.IBPluginDependency">com.apple.InterfaceBuilder.CocoaPlugin</string> - <array class="NSMutableArray" key="14.IBNSViewMetadataConstraints"> - <reference ref="826972647"/> - <reference ref="536442865"/> - </array> - <string key="14.IBPluginDependency">com.apple.InterfaceBuilder.CocoaPlugin</string> - <boolean value="NO" key="15.IBNSViewMetadataTranslatesAutoresizingMaskIntoConstraints"/> - <string key="15.IBPluginDependency">com.apple.InterfaceBuilder.CocoaPlugin</string> - <string key="16.IBPluginDependency">com.apple.InterfaceBuilder.CocoaPlugin</string> - <boolean value="NO" key="19.IBNSViewMetadataTranslatesAutoresizingMaskIntoConstraints"/> - <string key="19.IBPluginDependency">com.apple.InterfaceBuilder.CocoaPlugin</string> - <string key="2.IBPluginDependency">com.apple.InterfaceBuilder.CocoaPlugin</string> - <string key="20.IBPluginDependency">com.apple.InterfaceBuilder.CocoaPlugin</string> - <string key="28.IBPluginDependency">com.apple.InterfaceBuilder.CocoaPlugin</string> - <string key="29.IBPluginDependency">com.apple.InterfaceBuilder.CocoaPlugin</string> - <string key="30.IBPluginDependency">com.apple.InterfaceBuilder.CocoaPlugin</string> - <string key="31.IBPluginDependency">com.apple.InterfaceBuilder.CocoaPlugin</string> - <boolean value="NO" key="32.IBNSViewMetadataTranslatesAutoresizingMaskIntoConstraints"/> - <string key="32.IBPluginDependency">com.apple.InterfaceBuilder.CocoaPlugin</string> - <string key="33.IBPluginDependency">com.apple.InterfaceBuilder.CocoaPlugin</string> - <string key="36.IBPluginDependency">com.apple.InterfaceBuilder.CocoaPlugin</string> - <string key="39.IBPluginDependency">com.apple.InterfaceBuilder.CocoaPlugin</string> - <string key="5.IBPluginDependency">com.apple.InterfaceBuilder.CocoaPlugin</string> - <string key="55.IBPluginDependency">com.apple.InterfaceBuilder.CocoaPlugin</string> - <string key="56.IBPluginDependency">com.apple.InterfaceBuilder.CocoaPlugin</string> - <boolean value="NO" key="57.IBNSViewMetadataTranslatesAutoresizingMaskIntoConstraints"/> - <string key="57.IBPluginDependency">com.apple.InterfaceBuilder.CocoaPlugin</string> - <string key="58.IBPluginDependency">com.apple.InterfaceBuilder.CocoaPlugin</string> - <string key="59.IBPluginDependency">com.apple.InterfaceBuilder.CocoaPlugin</string> - <string key="60.IBPluginDependency">com.apple.InterfaceBuilder.CocoaPlugin</string> - </dictionary> - <dictionary class="NSMutableDictionary" key="unlocalizedProperties"/> - <nil key="activeLocalization"/> - <dictionary class="NSMutableDictionary" key="localizations"/> - <nil key="sourceID"/> - <int key="maxID">62</int> - </object> - <object class="IBClassDescriber" key="IBDocument.Classes"> - <array class="NSMutableArray" key="referencedPartialClassDescriptions"> - <object class="IBPartialClassDescription"> - <string key="className">PreferenceController</string> - <string key="superclassName">NSWindowController</string> - <object class="NSMutableDictionary" key="actions"> - <string key="NS.key.0">switchView:</string> - <string key="NS.object.0">id</string> - </object> - <object class="NSMutableDictionary" key="actionInfosByName"> - <string key="NS.key.0">switchView:</string> - <object class="IBActionInfo" key="NS.object.0"> - <string key="name">switchView:</string> - <string key="candidateClassName">id</string> - </object> - </object> - <dictionary class="NSMutableDictionary" key="outlets"> - <string key="engineView">NSView</string> - <string key="generalView">NSView</string> - </dictionary> - <dictionary class="NSMutableDictionary" key="toOneOutletInfosByName"> - <object class="IBToOneOutletInfo" key="engineView"> - <string key="name">engineView</string> - <string key="candidateClassName">NSView</string> - </object> - <object class="IBToOneOutletInfo" key="generalView"> - <string key="name">generalView</string> - <string key="candidateClassName">NSView</string> - </object> - </dictionary> - <object class="IBClassDescriptionSource" key="sourceIdentifier"> - <string key="majorKey">IBProjectSource</string> - <string key="minorKey">./Classes/PreferenceController.h</string> - </object> - </object> - </array> - </object> - <int key="IBDocument.localizationMode">0</int> - <string key="IBDocument.TargetRuntimeIdentifier">IBCocoaFramework</string> - <bool key="IBDocument.PluginDeclaredDependenciesTrackSystemTargetVersion">YES</bool> - <int key="IBDocument.defaultPropertyAccessControl">3</int> - <dictionary class="NSMutableDictionary" key="IBDocument.LastKnownImageSizes"> - <string key="NSPreferencesGeneral">{32, 32}</string> - <string key="NSSwitch">{15, 15}</string> - </dictionary> - <bool key="IBDocument.UseAutolayout">YES</bool> - </data> -</archive> diff --git a/tikzit/src/osx/PreviewController.h b/tikzit/src/osx/PreviewController.h deleted file mode 100644 index d6d855e..0000000 --- a/tikzit/src/osx/PreviewController.h +++ /dev/null @@ -1,51 +0,0 @@ -// -// PreviewController.h -// TikZiT -// -// Copyright 2010 Aleks Kissinger. All rights reserved. -// -// -// This file is part of TikZiT. -// -// TikZiT is free software: you can redistribute it and/or modify -// it under the terms of the GNU General Public License as published by -// the Free Software Foundation, either version 3 of the License, or -// (at your option) any later version. -// -// TikZiT is distributed in the hope that it will be useful, -// but WITHOUT ANY WARRANTY; without even the implied warranty of -// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -// GNU General Public License for more details. -// -// You should have received a copy of the GNU General Public License -// along with TikZiT. If not, see <http://www.gnu.org/licenses/>. -// - - -#import <Cocoa/Cocoa.h> - -@class PDFView; -@class PreambleController; - -@interface PreviewController : NSWindowController { - IBOutlet PDFView *pdfView; - IBOutlet NSProgressIndicator *progressIndicator; - IBOutlet NSScrollView *errorTextView; - IBOutlet NSTextView *errorText; - PreambleController *preambleController; - NSString *tempDir; - NSLock *latexLock; - int typesetCount; -} - - -- (id)initWithWindowNibName:(NSString*)nib - preambleController:(PreambleController*)pc - tempDir:(NSString*)dir; - -- (void)buildTikz:(NSString*)tikz; - -+ (void)setDefaultPreviewController:(PreviewController*)pc; -+ (PreviewController*)defaultPreviewController; - -@end diff --git a/tikzit/src/osx/PreviewController.m b/tikzit/src/osx/PreviewController.m deleted file mode 100644 index 7c41562..0000000 --- a/tikzit/src/osx/PreviewController.m +++ /dev/null @@ -1,151 +0,0 @@ -// -// PreviewController.m -// TikZiT -// -// Copyright 2010 Aleks Kissinger. All rights reserved. -// -// -// This file is part of TikZiT. -// -// TikZiT is free software: you can redistribute it and/or modify -// it under the terms of the GNU General Public License as published by -// the Free Software Foundation, either version 3 of the License, or -// (at your option) any later version. -// -// TikZiT is distributed in the hope that it will be useful, -// but WITHOUT ANY WARRANTY; without even the implied warranty of -// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -// GNU General Public License for more details. -// -// You should have received a copy of the GNU General Public License -// along with TikZiT. If not, see <http://www.gnu.org/licenses/>. -// - -#import "PreviewController.h" -#import "AppDelegate.h" -#import "PreambleController.h" -#import <Quartz/Quartz.h> - -@implementation PreviewController - -static PreviewController *preview = nil; - -- (id)initWithWindowNibName:(NSString*)nib - preambleController:(PreambleController*)pc - tempDir:(NSString*)dir { - [super initWithWindowNibName:nib]; - tempDir = [dir copy]; - typesetCount = 0; - preambleController = pc; - latexLock = [[NSLock alloc] init]; - return self; -} - -- (void)runLatex:(id)tikz { - // Only build one tex file at a time, so we don't get funky results. - //[latexLock lock]; - [progressIndicator startAnimation:self]; - - if([[NSUserDefaults standardUserDefaults] boolForKey:@"net.sourceforge.tikzit.previewfocus"]){ - [[preview window] makeKeyAndOrderFront:self]; - } - - int fnum = typesetCount++; - - NSString *tex = [NSString stringWithFormat:@"%@%@%@", - [preambleController currentPreamble], - tikz, - [preambleController currentPostamble]]; - - NSString *texFile = [NSString stringWithFormat:@"%@/tikzit_%d.tex", tempDir, fnum]; - NSString *pdfFile = [NSString stringWithFormat:@"%@/tikzit_%d.pdf", tempDir, fnum]; - - [tex writeToFile:texFile atomically:NO encoding:NSUTF8StringEncoding error:NULL]; - - NSString *pdflatexPath = [[NSUserDefaults standardUserDefaults] stringForKey:@"net.sourceforge.tikzit.pdflatexpath"]; - - // We run pdflatex in a bash shell to have easy access to the setup from unix-land - NSTask *latexTask = [[NSTask alloc] init]; - [latexTask setCurrentDirectoryPath:tempDir]; - [latexTask setLaunchPath:@"/bin/bash"]; - - // This assumes the user has $PATH set up to find pdflatex in either .profile - // or .bashrc. This should be improved to take other path setups into account - // and to be customisable. - NSString *latexCmd = - [NSString stringWithFormat: - @"if [ -e ~/.profile ]; then source ~/.profile; fi\n" - @"if [ -e ~/.bashrc ]; then source ~/.bashrc; fi\n" - @"%@ -interaction=nonstopmode -output-format=pdf -halt-on-error '%@'\n", pdflatexPath, texFile]; - - NSLog(@"Telling bash: %@", latexCmd); - - NSPipe *pout = [NSPipe pipe]; - NSPipe *pin = [NSPipe pipe]; - [latexTask setStandardOutput:pout]; - [latexTask setStandardInput:pin]; - - NSFileHandle *latexIn = [pin fileHandleForWriting]; - NSFileHandle *latexOut = [pout fileHandleForReading]; - - [latexTask launch]; - [latexIn writeData:[latexCmd dataUsingEncoding:NSUTF8StringEncoding]]; - [latexIn closeFile]; - - - NSData *data = [latexOut readDataToEndOfFile]; - NSString *str = [[NSString alloc] initWithData:data - encoding:NSUTF8StringEncoding]; - - [latexTask waitUntilExit]; - if ([latexTask terminationStatus] != 0) { - if ([latexTask terminationStatus] == 127) { - [errorTextView setHidden:YES]; - [errorText setString:@"\nCouldn't find pdflatex, change settings and try again."]; - [errorTextView setHidden:NO]; - }else{ - [errorTextView setHidden:YES]; - [errorText setString:[@"\nAN ERROR HAS OCCURRED, PDFLATEX SAID:\n\n" stringByAppendingString:str]]; - [errorTextView setHidden:NO]; - } - } else { - [errorText setString:@""]; - [errorTextView setHidden:YES]; - - data = [NSData dataWithContentsOfFile:pdfFile]; - PDFDocument *doc = [[PDFDocument alloc] initWithData:data]; - - // pad the PDF by a couple of pixels - if ([doc pageCount] >= 1) { - PDFPage *page = [doc pageAtIndex:0]; - NSRect box = [page boundsForBox:kPDFDisplayBoxCropBox]; - box.origin.x -= 2.0f; - box.origin.y -= 2.0f; - box.size.width += 4.0f; - box.size.height += 4.0f; - [page setBounds:box forBox:kPDFDisplayBoxCropBox]; - [page setBounds:box forBox:kPDFDisplayBoxMediaBox]; - } - - [pdfView setDocument:doc]; - } - - [progressIndicator stopAnimation:self]; - //[latexLock unlock]; -} - -- (void)buildTikz:(NSString*)tikz { - // Build on a separate thread to keep the interface responsive. - [NSThread detachNewThreadSelector:@selector(runLatex:) toTarget:self withObject:tikz]; -} - -+ (void)setDefaultPreviewController:(PreviewController*)pc { - preview = pc; -} - -+ (PreviewController*)defaultPreviewController { - return preview; -} - - -@end diff --git a/tikzit/src/osx/PropertyInspectorController.h b/tikzit/src/osx/PropertyInspectorController.h deleted file mode 100644 index 0625f9b..0000000 --- a/tikzit/src/osx/PropertyInspectorController.h +++ /dev/null @@ -1,83 +0,0 @@ -// -// PropertyInspectorController.h -// TikZiT -// -// Created by Aleks Kissinger on 17/07/2011. -// Copyright 2011 Aleks Kissinger. All rights reserved. -// - -#import <Cocoa/Cocoa.h> -#import "NodeStyle.h" -#import "GraphElementData.h" - -@class SFBInspectorView; -@class StylePaletteController; - -@interface PropertyInspectorController : NSWindowController { - IBOutlet SFBInspectorView *propertyInspectorView; - IBOutlet NSView *nodePropertiesView; - IBOutlet NSView *graphPropertiesView; - IBOutlet NSView *edgePropertiesView; - IBOutlet NSComboBox *sourceAnchorComboBox; - IBOutlet NSComboBox *targetAnchorComboBox; - IBOutlet NSTextField *edgeNodeLabelField; - IBOutlet NSButton *edgeNodeCheckbox; - IBOutlet NSArrayController *nodeDataArrayController; - IBOutlet NSArrayController *graphDataArrayController; - IBOutlet NSArrayController *edgeDataArrayController; - IBOutlet NSArrayController *edgeNodeDataArrayController; - - NSMutableArray *sourceAnchorNames; - IBOutlet NSArrayController *sourceAnchorNamesArrayController; - - NSMutableArray *targetAnchorNames; - IBOutlet NSArrayController *targetAnchorNamesArrayController; - - NSMutableArray *selectedNodes; - IBOutlet NSArrayController *selectedNodesArrayController; - - NSMutableArray *selectedEdges; - IBOutlet NSArrayController *selectedEdgesArrayController; - - // this data lists exists solely for displaying messages in disabled data tables - GraphElementData *noSelection; - GraphElementData *multipleSelection; - GraphElementData *noEdgeNode; - GraphElementData *noGraph; - - - // used to get access to the global style table - StylePaletteController *stylePaletteController; -} - -//@property (readonly) BOOL enableNodeDataControls; -//@property (readonly) BOOL enableEdgeDataControls; -@property (retain) NSMutableArray *selectedNodes; -@property (retain) NSMutableArray *selectedEdges; -@property (retain) NSMutableArray *sourceAnchorNames; -@property (retain) NSMutableArray *targetAnchorNames; -@property (retain) StylePaletteController *stylePaletteController; - -- (id)initWithWindowNibName:(NSString *)windowNibName; -- (void)graphSelectionChanged:(NSNotification*)notification; - -- (IBAction)addNodeProperty:(id)sender; -- (IBAction)addNodeAtom:(id)sender; -- (IBAction)removeNodeProperty:(id)sender; - -- (IBAction)addGraphProperty:(id)sender; -- (IBAction)addGraphAtom:(id)sender; -- (IBAction)removeGraphProperty:(id)sender; - -- (IBAction)addEdgeProperty:(id)sender; -- (IBAction)addEdgeAtom:(id)sender; -- (IBAction)removeEdgeProperty:(id)sender; - -- (IBAction)addEdgeNodeProperty:(id)sender; -- (IBAction)addEdgeNodeAtom:(id)sender; -- (IBAction)removeEdgeNodeProperty:(id)sender; - -//- (IBAction)addRemoveChildNode:(id)sender; -- (IBAction)refreshDocument:(id)sender; - -@end diff --git a/tikzit/src/osx/PropertyInspectorController.m b/tikzit/src/osx/PropertyInspectorController.m deleted file mode 100644 index 1411549..0000000 --- a/tikzit/src/osx/PropertyInspectorController.m +++ /dev/null @@ -1,275 +0,0 @@ -// -// PropertyInspectorController.m -// TikZiT -// -// Created by Aleks Kissinger on 17/07/2011. -// Copyright 2011 Aleks Kissinger. All rights reserved. -// - -#import "PropertyInspectorController.h" -#import "StylePaletteController.h" -#import "TikzDocument.h" -#import "SFBInspectors/SFBInspectorView.h" -#import "PickSupport.h" -#import "Node.h" -#import "Edge.h" -#import "NodeStyle.h" -#import "GraphicsView.h" -#import "GraphElementProperty.h" -#import "Shape.h" - -@implementation PropertyInspectorController - -@synthesize stylePaletteController; -@synthesize selectedNodes, selectedEdges; -@synthesize sourceAnchorNames, targetAnchorNames; - -- (id)initWithWindowNibName:(NSString *)windowNibName { - [super initWithWindowNibName:windowNibName]; - - noSelection = [[GraphElementData alloc] init]; - [noSelection setProperty:@"" forKey:@"No Selection"]; - multipleSelection = [[GraphElementData alloc] init]; - [multipleSelection setProperty:@"" forKey:@"Mult. Selection"]; - noEdgeNode = [[GraphElementData alloc] init]; - [noEdgeNode setProperty:@"" forKey:@"No Child"]; - noGraph = [[GraphElementData alloc] init]; - [noGraph setProperty:@"" forKey:@"No Graph"]; - - [[NSNotificationCenter defaultCenter] addObserver:self - selector:@selector(graphSelectionChanged:) - name:@"SelectionChanged" - object:nil]; - -// [[NSDocumentController sharedDocumentController] addObserver:self -// forKeyPath:@"currentDocument" -// options:NSKeyValueObservingOptionNew -// context:NULL]; - - [[NSNotificationCenter defaultCenter] addObserver:self - selector:@selector(graphSelectionChanged:) - name:@"NSWindowDidBecomeMainNotification" - object:nil]; - - [self setSourceAnchorNames: [[NSMutableArray alloc] initWithArray: [@"north south west east" componentsSeparatedByString:@" "]]]; - - [self setTargetAnchorNames: [[NSMutableArray alloc] initWithArray:[@"north south west east" componentsSeparatedByString:@" "]]]; - - - [[self window] setLevel:NSNormalWindowLevel]; - [self showWindow:self]; - return self; -} - -- (void)observeValueForKeyPath:(NSString*)keyPath - ofObject:(id)object - change:(NSDictionary*)change - context:(void*)context { - [self graphSelectionChanged:nil]; -} - -//- (void)willChangeValueForKey:(NSString *)key { -// [super willChangeValueForKey:key]; -// NSLog(@"will: %@",key); -//} -// -//- (void)didChangeValueForKey:(NSString *)key { -// [super didChangeValueForKey:key]; -// NSLog(@"did: %@",key); -//} - -- (void)windowDidLoad { - [[self window] setMovableByWindowBackground:YES]; - - [propertyInspectorView addInspectorPane:graphPropertiesView - title:@"Graph Properties"]; - [propertyInspectorView addInspectorPane:nodePropertiesView - title:@"Node Properties"]; - [propertyInspectorView addInspectorPane:edgePropertiesView - title:@"Edge Properties"]; - [super windowDidLoad]; -} - -- (IBAction)refreshDocument:(id)sender { - NSDocumentController *dc = [NSDocumentController sharedDocumentController]; - TikzDocument *doc = (TikzDocument*)[dc currentDocument]; - - if (doc != nil) { - [[doc graphicsView] postGraphChange]; - [[doc graphicsView] refreshLayers]; - } -} - - -- (void)updateGraphFields { - NSDocumentController *dc = [NSDocumentController sharedDocumentController]; - TikzDocument *doc = (TikzDocument*)[dc currentDocument]; - - if (doc != nil) { - [graphDataArrayController setContent:[[[doc graphicsView] graph] data]]; - [graphDataArrayController setSelectionIndexes:[NSIndexSet indexSet]]; - [graphDataArrayController setEditable:YES]; - } else { - [graphDataArrayController setContent:noGraph]; - [graphDataArrayController setSelectionIndexes:[NSIndexSet indexSet]]; - [graphDataArrayController setEditable:NO]; - } -} - -- (void)updateNodeFields { - NSDocumentController *dc = [NSDocumentController sharedDocumentController]; - TikzDocument *doc = (TikzDocument*)[dc currentDocument]; - if (doc != nil) { - NSSet *sel = [[[doc graphicsView] pickSupport] selectedNodes]; - [self setSelectedNodes:[[sel allObjects] mutableCopy]]; - [selectedNodesArrayController setSelectedObjects:selectedNodes]; - if ([sel count] == 1) { - Node *n = [sel anyObject]; - [nodeDataArrayController setContent:[n data]]; - [nodeDataArrayController setSelectionIndexes:[NSIndexSet indexSet]]; - [nodeDataArrayController setEditable:YES]; - } else if ([sel count] == 0) { - [nodeDataArrayController setContent:noSelection]; - [nodeDataArrayController setSelectionIndexes:[NSIndexSet indexSet]]; - [nodeDataArrayController setEditable:NO]; - } else { - [nodeDataArrayController setContent:multipleSelection]; - [nodeDataArrayController setSelectionIndexes:[NSIndexSet indexSet]]; - [nodeDataArrayController setEditable:NO]; - } - } else { - [nodeDataArrayController setContent:noGraph]; - [nodeDataArrayController setEditable:NO]; - } -} - -- (void)updateEdgeFields { - NSDocumentController *dc = [NSDocumentController sharedDocumentController]; - TikzDocument *doc = (TikzDocument*)[dc currentDocument]; - - if (doc != nil) { - NSSet *sel = [[[doc graphicsView] pickSupport] selectedEdges]; - [self setSelectedEdges:[[sel allObjects] mutableCopy]]; - [selectedEdgesArrayController setSelectedObjects:selectedEdges]; - if ([sel count] == 1) { - Edge *e = [sel anyObject]; - [edgeDataArrayController setContent:[e data]]; - [edgeDataArrayController setSelectionIndexes:[NSIndexSet indexSet]]; - [edgeDataArrayController setEditable:YES]; - if ([e hasEdgeNode]) { - Node *n = [e edgeNode]; - [edgeNodeDataArrayController setContent:[n data]]; - [edgeNodeDataArrayController setSelectionIndexes:[NSIndexSet indexSet]]; - [edgeNodeDataArrayController setEditable:YES]; - } else { - [edgeNodeDataArrayController setContent:noEdgeNode]; - [edgeNodeDataArrayController setSelectionIndexes:[NSIndexSet indexSet]]; - [edgeNodeDataArrayController setEditable:NO]; - } - } else if ([sel count] == 0) { - [edgeDataArrayController setContent:noSelection]; - [edgeDataArrayController setSelectionIndexes:[NSIndexSet indexSet]]; - [edgeDataArrayController setEditable:NO]; - [edgeNodeDataArrayController setContent:noSelection]; - [edgeNodeDataArrayController setSelectionIndexes:[NSIndexSet indexSet]]; - [edgeNodeDataArrayController setEditable:NO]; - } else { - [edgeDataArrayController setContent:multipleSelection]; - [edgeDataArrayController setSelectionIndexes:[NSIndexSet indexSet]]; - [edgeDataArrayController setEditable:NO]; - [edgeNodeDataArrayController setContent:multipleSelection]; - [edgeNodeDataArrayController setSelectionIndexes:[NSIndexSet indexSet]]; - [edgeNodeDataArrayController setEditable:NO]; - } - } else { - [edgeDataArrayController setContent:noGraph]; - [edgeDataArrayController setSelectionIndexes:[NSIndexSet indexSet]]; - [edgeDataArrayController setEditable:NO]; - [edgeNodeDataArrayController setContent:noGraph]; - [edgeNodeDataArrayController setSelectionIndexes:[NSIndexSet indexSet]]; - [edgeNodeDataArrayController setEditable:NO]; - } -} - -- (void)graphSelectionChanged:(NSNotification*)notification { - [self updateNodeFields]; - [self updateEdgeFields]; - [self updateGraphFields]; -} - -- (void)controlTextDidEndEditing:(NSNotification*)notification { - NSDocumentController *dc = [NSDocumentController sharedDocumentController]; - TikzDocument *doc = (TikzDocument*)[dc currentDocument]; - if (doc != nil) { - PickSupport *pick = [[doc graphicsView] pickSupport]; - for (Node *n in [pick selectedNodes]) { - [n attachStyleFromTable:[stylePaletteController nodeStyles]]; - } - - for (Edge *e in [pick selectedEdges]) { - [e attachStyleFromTable:[stylePaletteController edgeStyles]]; - } - } - - [self refreshDocument:[notification object]]; -} - -- (void)addPropertyToAC:(NSArrayController*)ac { - [ac addObject:[[GraphElementProperty alloc] initWithPropertyValue:@"val" forKey:@"new_property"]]; - [self refreshDocument:nil]; -} - -- (void)addAtomToAC:(NSArrayController*)ac { - [ac addObject:[[GraphElementProperty alloc] initWithAtomName:@"new_atom"]]; - [self refreshDocument:nil]; -} - -- (void)removeFromAC:(NSArrayController*)ac { - [ac remove:nil]; - [self refreshDocument:nil]; -} - -- (IBAction)addNodeProperty:(id)sender { [self addPropertyToAC:nodeDataArrayController]; } -- (IBAction)addNodeAtom:(id)sender { [self addAtomToAC:nodeDataArrayController]; } -- (IBAction)removeNodeProperty:(id)sender { [self removeFromAC:nodeDataArrayController]; } - -- (IBAction)addGraphProperty:(id)sender { [self addPropertyToAC:graphDataArrayController]; } -- (IBAction)addGraphAtom:(id)sender { [self addAtomToAC:graphDataArrayController]; } -- (IBAction)removeGraphProperty:(id)sender { [self removeFromAC:graphDataArrayController]; } - -- (IBAction)addEdgeProperty:(id)sender { [self addPropertyToAC:edgeDataArrayController]; } -- (IBAction)addEdgeAtom:(id)sender { [self addAtomToAC:edgeDataArrayController]; } -- (IBAction)removeEdgeProperty:(id)sender { [self removeFromAC:edgeDataArrayController]; } - -- (IBAction)addEdgeNodeProperty:(id)sender { [self addPropertyToAC:edgeNodeDataArrayController]; } -- (IBAction)addEdgeNodeAtom:(id)sender { [self addAtomToAC:edgeNodeDataArrayController]; } -- (IBAction)removeEdgeNodeProperty:(id)sender { [self removeFromAC:edgeNodeDataArrayController]; } - -//- (BOOL)enableEdgeDataControls { -// NSDocumentController *dc = [NSDocumentController sharedDocumentController]; -// TikzDocument *doc = (TikzDocument*)[dc currentDocument]; -// -// if (doc != nil) { -// return ([[[[doc graphicsView] pickSupport] selectedEdges] count] == 1); -// } else { -// return NO; -// } -//} -// -//- (BOOL)enableEdgeNodeDataControls { -// NSDocumentController *dc = [NSDocumentController sharedDocumentController]; -// TikzDocument *doc = (TikzDocument*)[dc currentDocument]; -// -// if (doc != nil) { -// PickSupport *pick = [[doc graphicsView] pickSupport]; -// if ([[pick selectedEdges] count] == 1) { -// return ([[[pick selectedEdges] anyObject] hasEdgeNode]); -// } else { -// return NO; -// } -// } else { -// return NO; -// } -//} - -@end diff --git a/tikzit/src/osx/SelectBoxLayer.h b/tikzit/src/osx/SelectBoxLayer.h deleted file mode 100644 index 45b43c7..0000000 --- a/tikzit/src/osx/SelectBoxLayer.h +++ /dev/null @@ -1,22 +0,0 @@ -// -// SelectBoxLayer.h -// TikZiT -// -// Created by Aleks Kissinger on 14/06/2010. -// Copyright 2010 __MyCompanyName__. All rights reserved. -// - -#import <Cocoa/Cocoa.h> -#import <QuartzCore/CoreAnimation.h> - -@interface SelectBoxLayer : CALayer { - BOOL active; - CGRect box; -} - -@property (assign) BOOL active; -@property (assign) NSRect selectBox; - -+ (SelectBoxLayer*)layer; - -@end diff --git a/tikzit/src/osx/SelectBoxLayer.m b/tikzit/src/osx/SelectBoxLayer.m deleted file mode 100644 index c198ffa..0000000 --- a/tikzit/src/osx/SelectBoxLayer.m +++ /dev/null @@ -1,48 +0,0 @@ -// -// SelectBoxLayer.m -// TikZiT -// -// Created by Aleks Kissinger on 14/06/2010. -// Copyright 2010 __MyCompanyName__. All rights reserved. -// - -#import "SelectBoxLayer.h" - - -@implementation SelectBoxLayer - -@synthesize active; - -- (id)init { - [super init]; - box = CGRectMake(0.0f, 0.0f, 0.0f, 0.0f); - active = NO; - return self; -} - -- (void)setSelectBox:(NSRect)r { - box = NSRectToCGRect(r); -} - -- (NSRect)selectBox { - return NSRectFromCGRect(box); -} - -- (void)drawInContext:(CGContextRef)context { - if (active) { - CGContextAddRect(context, box); - - CGContextSetRGBStrokeColor(context, 0.6, 0.6, 0.6, 1); - CGContextSetRGBFillColor(context, 0.8, 0.8, 0.8, 0.2); - CGContextSetLineWidth(context, 1); - - CGContextSetShouldAntialias(context, NO); - CGContextDrawPath(context, kCGPathFillStroke); - } -} - -+ (SelectBoxLayer*)layer { - return [[[SelectBoxLayer alloc] init] autorelease]; -} - -@end diff --git a/tikzit/src/osx/SelectableCollectionViewItem.h b/tikzit/src/osx/SelectableCollectionViewItem.h deleted file mode 100644 index 4a2c571..0000000 --- a/tikzit/src/osx/SelectableCollectionViewItem.h +++ /dev/null @@ -1,33 +0,0 @@ -// -// SelectableCollectionViewItem.h -// TikZiT -// -// Copyright 2010 Aleks Kissinger. All rights reserved. -// -// -// This file is part of TikZiT. -// -// TikZiT is free software: you can redistribute it and/or modify -// it under the terms of the GNU General Public License as published by -// the Free Software Foundation, either version 3 of the License, or -// (at your option) any later version. -// -// TikZiT is distributed in the hope that it will be useful, -// but WITHOUT ANY WARRANTY; without even the implied warranty of -// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -// GNU General Public License for more details. -// -// You should have received a copy of the GNU General Public License -// along with TikZiT. If not, see <http://www.gnu.org/licenses/>. -// - -#import <Cocoa/Cocoa.h> -#import "StylePaletteController.h" - -@interface SelectableCollectionViewItem : NSCollectionViewItem { - IBOutlet StylePaletteController *stylePaletteController; -} - -- (void)setStylePaletteController:(StylePaletteController*)spc; - -@end diff --git a/tikzit/src/osx/SelectableCollectionViewItem.m b/tikzit/src/osx/SelectableCollectionViewItem.m deleted file mode 100644 index 880c37b..0000000 --- a/tikzit/src/osx/SelectableCollectionViewItem.m +++ /dev/null @@ -1,54 +0,0 @@ -// -// SelectableCollectionViewItem.m -// TikZiT -// -// Copyright 2010 Aleks Kissinger. All rights reserved. -// -// -// This file is part of TikZiT. -// -// TikZiT is free software: you can redistribute it and/or modify -// it under the terms of the GNU General Public License as published by -// the Free Software Foundation, either version 3 of the License, or -// (at your option) any later version. -// -// TikZiT is distributed in the hope that it will be useful, -// but WITHOUT ANY WARRANTY; without even the implied warranty of -// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -// GNU General Public License for more details. -// -// You should have received a copy of the GNU General Public License -// along with TikZiT. If not, see <http://www.gnu.org/licenses/>. -// - -#import "SelectableCollectionViewItem.h" -#import "SelectableNodeView.h" - -@implementation SelectableCollectionViewItem - -- (id)copyWithZone:(NSZone *)zone { - SelectableCollectionViewItem *item = [super copyWithZone:zone]; - [item setStylePaletteController:stylePaletteController]; - return (id)item; -} - -- (void)setSelected:(BOOL)flag { - [super setSelected:flag]; - [(SelectableNodeView*)[self view] setSelected:flag]; - - // only fire this event from the view that lost selection - //if (flag == NO) [stylePaletteController selectionDidChange]; - - [[self view] setNeedsDisplay:YES]; -} - -- (void)setRepresentedObject:(id)object { - [super setRepresentedObject:object]; - [(SelectableNodeView*)[self view] setNodeStyle:(NodeStyle*)object]; -} - -- (void)setStylePaletteController:(StylePaletteController*)spc { - stylePaletteController = spc; -} - -@end diff --git a/tikzit/src/osx/SelectableNodeView.h b/tikzit/src/osx/SelectableNodeView.h deleted file mode 100644 index be7d1a1..0000000 --- a/tikzit/src/osx/SelectableNodeView.h +++ /dev/null @@ -1,38 +0,0 @@ -// -// SelectableView.h -// TikZiT -// -// Copyright 2010 Aleks Kissinger. All rights reserved. -// -// -// This file is part of TikZiT. -// -// TikZiT is free software: you can redistribute it and/or modify -// it under the terms of the GNU General Public License as published by -// the Free Software Foundation, either version 3 of the License, or -// (at your option) any later version. -// -// TikZiT is distributed in the hope that it will be useful, -// but WITHOUT ANY WARRANTY; without even the implied warranty of -// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -// GNU General Public License for more details. -// -// You should have received a copy of the GNU General Public License -// along with TikZiT. If not, see <http://www.gnu.org/licenses/>. -// - -#import <Cocoa/Cocoa.h> -#import "NodeLayer.h" -#import "NodeStyle.h" -#import "NodeStyle+Coder.h" - -@interface SelectableNodeView : NSView { - BOOL selected; - NodeLayer *nodeLayer; -} - -@property (assign) BOOL selected; -@property (retain) NodeStyle *nodeStyle; - - -@end diff --git a/tikzit/src/osx/SelectableNodeView.m b/tikzit/src/osx/SelectableNodeView.m deleted file mode 100644 index 6fdd283..0000000 --- a/tikzit/src/osx/SelectableNodeView.m +++ /dev/null @@ -1,96 +0,0 @@ -// -// SelectableView.m -// TikZiT -// -// Copyright 2010 Aleks Kissinger. All rights reserved. -// -// -// This file is part of TikZiT. -// -// TikZiT is free software: you can redistribute it and/or modify -// it under the terms of the GNU General Public License as published by -// the Free Software Foundation, either version 3 of the License, or -// (at your option) any later version. -// -// TikZiT is distributed in the hope that it will be useful, -// but WITHOUT ANY WARRANTY; without even the implied warranty of -// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -// GNU General Public License for more details. -// -// You should have received a copy of the GNU General Public License -// along with TikZiT. If not, see <http://www.gnu.org/licenses/>. -// - -#import "SelectableNodeView.h" -#import "Shape.h" -#import "Transformer.h" - -@implementation SelectableNodeView - -@synthesize selected; - -- (id)initWithFrame:(NSRect)frameRect { - [super initWithFrame:frameRect]; - nodeLayer = nil; - return self; -} - --(void)drawLayer:(CALayer *)layer inContext:(CGContextRef)context { -// NSLog(@"got draw"); -// CGContextSaveGState(context); -// -// if (selected) { -// CGContextSetRGBStrokeColor(context, 0.61f, 0.735f, 1.0f, 1.0f); -// CGContextSetRGBFillColor(context, 0.61f, 0.735f, 1.0f, 0.5f); -// CGContextSetLineWidth(context, 1.0f); -// -// CGRect box = CGRectMake([layer frame].origin.x + 2, -// [layer frame].origin.y + 2, -// [layer frame].size.width - 4, -// [layer frame].size.height - 4); -// -// //CGContextAddRect(context, box); -// CGContextDrawPath(context, kCGPathFillStroke); -// } -// -// CGContextRestoreGState(context); - - if (nodeLayer!=nil) { - if (![[[self layer] sublayers] containsObject:nodeLayer]) { - [[self layer] addSublayer:nodeLayer]; - NSPoint c = NSMakePoint(CGRectGetMidX([[self layer] frame]), - CGRectGetMidY([[self layer] frame])); - [nodeLayer setCenter:c andAnimateWhen:NO]; - } - - if (selected) [[nodeLayer selection] select]; - else [[nodeLayer selection] deselect]; - - [nodeLayer updateFrame]; - } -} - -- (void)drawRect:(NSRect)rect { - [super drawRect:rect]; -} - -- (BOOL)acceptsFirstMouse:(NSEvent *)theEvent { return YES; } - -- (void)setNodeStyle:(NodeStyle *)sty { - if (nodeLayer == nil) { - nodeLayer = [[NodeLayer alloc] initWithNode:[Node node] - transformer:[Transformer defaultTransformer]]; - [nodeLayer setRescale:NO]; - } - - [[nodeLayer node] setStyle:sty]; - [nodeLayer updateFrame]; -} - -- (NodeStyle*)nodeStyle { - if (nodeLayer != nil) return [[nodeLayer node] style]; - else return nil; -} - - -@end diff --git a/tikzit/src/osx/StylePaletteController.h b/tikzit/src/osx/StylePaletteController.h deleted file mode 100644 index ed30b58..0000000 --- a/tikzit/src/osx/StylePaletteController.h +++ /dev/null @@ -1,80 +0,0 @@ -// -// StylePaletteController.h -// TikZiT -// -// Copyright 2010 Aleks Kissinger. All rights reserved. -// -// -// This file is part of TikZiT. -// -// TikZiT is free software: you can redistribute it and/or modify -// it under the terms of the GNU General Public License as published by -// the Free Software Foundation, either version 3 of the License, or -// (at your option) any later version. -// -// TikZiT is distributed in the hope that it will be useful, -// but WITHOUT ANY WARRANTY; without even the implied warranty of -// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -// GNU General Public License for more details. -// -// You should have received a copy of the GNU General Public License -// along with TikZiT. If not, see <http://www.gnu.org/licenses/>. -// - -#import <Cocoa/Cocoa.h> -#import "NodeStyle.h" -#import "EdgeStyle.h" - -@class SFBInspectorView; - -@interface StylePaletteController : NSWindowController { - NSMutableArray *nodeStyles; - NSMutableArray *edgeStyles; - IBOutlet NSArrayController *nodeStyleArrayController; - IBOutlet NSArrayController *filteredNodeStyleArrayController; - IBOutlet NSArrayController *edgeStyleArrayController; - IBOutlet NSArrayController *filteredEdgeStyleArrayController; - IBOutlet NSCollectionView *collectionView; - IBOutlet SFBInspectorView *nodeStyleInspectorView; - IBOutlet NSView *nodeStyleView; - IBOutlet NSView *edgeStyleView; - IBOutlet NSPopUpButton *shapeDropdown; - NSString *displayedNodeStyleCategory; - NSString *displayedEdgeStyleCategory; -} - -@property (readonly) NSMutableArray *nodeStyles; -@property (readonly) NSMutableArray *edgeStyles; -@property (readonly) BOOL documentActive; -@property (assign) NodeStyle *activeNodeStyle; -@property (assign) EdgeStyle *activeEdgeStyle; -@property (copy) NSString *displayedNodeStyleCategory; -@property (copy) NSString *displayedEdgeStyleCategory; -@property (readonly) NSPredicate *displayedNodeStylePredicate; -@property (readonly) NSPredicate *displayedEdgeStylePredicate; - -//@property NSString *nodeLabel; - -- (id)initWithWindowNibName:(NSString *)windowNibName - supportDir:(NSString*)supportDir; -- (void)saveStyles:(NSString *)plist; - -- (IBAction)refreshCollection:(id)sender; - -- (IBAction)applyActiveNodeStyle:(id)sender; -- (IBAction)clearActiveNodeStyle:(id)sender; -- (IBAction)addNodeStyle:(id)sender; - -- (IBAction)appleActiveEdgeStyle:(id)sender; -- (IBAction)clearActiveEdgeStyle:(id)sender; -- (IBAction)addEdgeStyle:(id)sender; -- (void)setActiveEdgeStyle:(EdgeStyle*)style; - -- (IBAction)setFillToClosestHashed:(id)sender; -- (IBAction)setStrokeToClosestHashed:(id)sender; - - -//- (IBAction)changeShape:(id)sender; - - -@end diff --git a/tikzit/src/osx/StylePaletteController.m b/tikzit/src/osx/StylePaletteController.m deleted file mode 100644 index 8f87bd9..0000000 --- a/tikzit/src/osx/StylePaletteController.m +++ /dev/null @@ -1,247 +0,0 @@ -// -// StylePaletteController.m -// TikZiT -// -// Copyright 2010 Aleks Kissinger. All rights reserved. -// -// -// This file is part of TikZiT. -// -// TikZiT is free software: you can redistribute it and/or modify -// it under the terms of the GNU General Public License as published by -// the Free Software Foundation, either version 3 of the License, or -// (at your option) any later version. -// -// TikZiT is distributed in the hope that it will be useful, -// but WITHOUT ANY WARRANTY; without even the implied warranty of -// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -// GNU General Public License for more details. -// -// You should have received a copy of the GNU General Public License -// along with TikZiT. If not, see <http://www.gnu.org/licenses/>. -// - -#import "StylePaletteController.h" -#import "TikzDocument.h" -#import "SFBInspectors/SFBInspectorView.h" -#import "PickSupport.h" -#import "Node.h" -#import "Edge.h" -#import "NodeStyle.h" -#import "GraphicsView.h" -#import "GraphElementProperty.h" -#import "Shape.h" - -@implementation StylePaletteController - -@synthesize nodeStyles, edgeStyles; - -- (id)initWithWindowNibName:(NSString *)windowNibName - supportDir:(NSString*)supportDir -{ - if (self = [super initWithWindowNibName:windowNibName]) { - NSString *ns = [supportDir stringByAppendingPathComponent:@"nodeStyles.plist"]; - NSString *es = [supportDir stringByAppendingPathComponent:@"edgeStyles.plist"]; - nodeStyles = (NSMutableArray*)[NSKeyedUnarchiver - unarchiveObjectWithFile:ns]; - edgeStyles = (NSMutableArray*)[NSKeyedUnarchiver - unarchiveObjectWithFile:es]; - - if (nodeStyles == nil) nodeStyles = [NSMutableArray array]; - if (edgeStyles == nil) edgeStyles = [NSMutableArray array]; - - [[self window] setLevel:NSNormalWindowLevel]; - [self showWindow:self]; - } - - return self; -} - -- (void)windowDidLoad { - [[self window] setMovableByWindowBackground:YES]; - [shapeDropdown addItemsWithTitles:[[Shape shapeDictionary] allKeys]]; - if ([self activeNodeStyle] != nil) { - [shapeDropdown setTitle:[[self activeNodeStyle] shapeName]]; - } - - [nodeStyleInspectorView addInspectorPane:nodeStyleView - title:@"Node Styles"]; - - [nodeStyleInspectorView addInspectorPane:edgeStyleView - title:@"Edge Styles"]; - - [super windowDidLoad]; -} - -- (void)saveStyles:(NSString*)supportDir { - NSString *ns = [supportDir stringByAppendingPathComponent:@"nodeStyles.plist"]; - NSString *es = [supportDir stringByAppendingPathComponent:@"edgeStyles.plist"]; - [NSKeyedArchiver archiveRootObject:nodeStyles toFile:ns]; - [NSKeyedArchiver archiveRootObject:edgeStyles toFile:es]; -} - -- (IBAction)refreshCollection:(id)sender { - [collectionView setNeedsDisplay:YES]; -} - - -- (BOOL)documentActive { - NSDocumentController *dc = [NSDocumentController sharedDocumentController]; - return dc.currentDocument != nil; -} - --(BOOL)collectionView:(NSCollectionView*)collectionView canDragItemsAtIndexes:(NSIndexSet*)indexes withEvent:(NSEvent*)event { - return YES; -} - - -//=========================== -//= setting SVG-safe colors = -//=========================== -- (IBAction)setFillToClosestHashed:(id)sender { - NSArray *sel = [nodeStyleArrayController selectedObjects]; - if ([sel count] != 0) { - NodeStyle *sty = [sel objectAtIndex:0]; - [sty willChangeValueForKey:@"fillColor"]; - [sty willChangeValueForKey:@"fillColorIsKnown"]; - [sty.fillColorRGB setToClosestHashed]; - [sty didChangeValueForKey:@"fillColor"]; - [sty didChangeValueForKey:@"fillColorIsKnown"]; - } -} - -- (IBAction)setStrokeToClosestHashed:(id)sender { - NSArray *sel = [nodeStyleArrayController selectedObjects]; - if ([sel count] != 0) { - NodeStyle *sty = [sel objectAtIndex:0]; - [sty willChangeValueForKey:@"strokeColor"]; - [sty willChangeValueForKey:@"strokeColorIsKnown"]; - [sty.strokeColorRGB setToClosestHashed]; - [sty didChangeValueForKey:@"strokeColor"]; - [sty didChangeValueForKey:@"strokeColorIsKnown"]; - } -} - -//================================================= -//= setting filter predicates for nodes and edges = -//================================================= -- (NSString*)displayedNodeStyleCategory { - return displayedNodeStyleCategory; -} - -- (void)setDisplayedNodeStyleCategory:(NSString *)cat { - [self willChangeValueForKey:@"displayedNodeStylePredicate"]; - displayedNodeStyleCategory = cat; - [self didChangeValueForKey:@"displayedNodeStylePredicate"]; -} - -- (NSString*)displayedEdgeStyleCategory { - return displayedEdgeStyleCategory; -} - -- (void)setDisplayedEdgeStyleCategory:(NSString *)cat { - [self willChangeValueForKey:@"displayedEdgeStylePredicate"]; - displayedEdgeStyleCategory = cat; - [self didChangeValueForKey:@"displayedEdgeStylePredicate"]; -} - -- (NSPredicate*)displayedNodeStylePredicate { - return [NSPredicate predicateWithFormat:@"category == %@", displayedNodeStyleCategory]; -} - -- (NSPredicate*)displayedEdgeStylePredicate { - return [NSPredicate predicateWithFormat:@"category == %@", displayedEdgeStyleCategory]; -} - - -//============================== -//= getting and setting styles = -//============================== - -- (IBAction)applyActiveNodeStyle:(id)sender { - NSDocumentController *dc = [NSDocumentController sharedDocumentController]; - TikzDocument *doc = (TikzDocument*)[dc currentDocument]; - - if (doc != nil) { - [[doc graphicsView] applyStyleToSelectedNodes:[self activeNodeStyle]]; - } - - [[doc graphicsView] postSelectionChange]; -} - -- (IBAction)clearActiveNodeStyle:(id)sender { - [self setActiveNodeStyle:nil]; - - NSDocumentController *dc = [NSDocumentController sharedDocumentController]; - TikzDocument *doc = (TikzDocument*)[dc currentDocument]; - - if (doc != nil) { - [[doc graphicsView] applyStyleToSelectedNodes:nil]; - } - - [[doc graphicsView] postSelectionChange]; -} - -- (NodeStyle*)activeNodeStyle { - NSArray *sel = [filteredNodeStyleArrayController selectedObjects]; - if ([sel count] == 0) return nil; - else return [sel objectAtIndex:0]; -} - -- (void)setActiveNodeStyle:(NodeStyle*)style { - if ([nodeStyles containsObject:style]) { - [filteredNodeStyleArrayController setSelectedObjects:[NSArray arrayWithObject:style]]; - } else { - [filteredNodeStyleArrayController setSelectedObjects:[NSArray array]]; - } -} - -- (IBAction)appleActiveEdgeStyle:(id)sender { - NSDocumentController *dc = [NSDocumentController sharedDocumentController]; - TikzDocument *doc = (TikzDocument*)[dc currentDocument]; - - if (doc != nil) { - [[doc graphicsView] applyStyleToSelectedEdges:[self activeEdgeStyle]]; - } -} - -- (IBAction)clearActiveEdgeStyle:(id)sender { - [self setActiveEdgeStyle:nil]; - [self appleActiveEdgeStyle:sender]; -} - -- (EdgeStyle*)activeEdgeStyle { - NSArray *sel = [filteredEdgeStyleArrayController selectedObjects]; - if ([sel count] == 0) return nil; - else return [sel objectAtIndex:0]; -} - -- (void)setActiveEdgeStyle:(EdgeStyle*)style { - if ([edgeStyles containsObject:style]) { - [filteredEdgeStyleArrayController setSelectedObjects:[NSArray arrayWithObject:style]]; - } else { - [filteredEdgeStyleArrayController setSelectedObjects:[NSArray array]]; - } -} - - -//================= -//= adding styles = -//================= - -- (IBAction)addEdgeStyle:(id)sender { - EdgeStyle *sty = [[EdgeStyle alloc] init]; - [sty setCategory:displayedEdgeStyleCategory]; - [edgeStyleArrayController addObject:sty]; - [self setActiveEdgeStyle:sty]; -} - -- (IBAction)addNodeStyle:(id)sender { - NodeStyle *sty = [[NodeStyle alloc] init]; - [sty setCategory:displayedNodeStyleCategory]; - [nodeStyleArrayController addObject:sty]; - [self setActiveNodeStyle:sty]; -} - - -@end diff --git a/tikzit/src/osx/TikzDocument.h b/tikzit/src/osx/TikzDocument.h deleted file mode 100644 index d817b2e..0000000 --- a/tikzit/src/osx/TikzDocument.h +++ /dev/null @@ -1,37 +0,0 @@ -// -// TikzDocument.h -// TikZiT -// -// Copyright 2010 Aleks Kissinger. All rights reserved. -// -// -// This file is part of TikZiT. -// -// TikZiT is free software: you can redistribute it and/or modify -// it under the terms of the GNU General Public License as published by -// the Free Software Foundation, either version 3 of the License, or -// (at your option) any later version. -// -// TikZiT is distributed in the hope that it will be useful, -// but WITHOUT ANY WARRANTY; without even the implied warranty of -// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -// GNU General Public License for more details. -// -// You should have received a copy of the GNU General Public License -// along with TikZiT. If not, see <http://www.gnu.org/licenses/>. -// - -#import <Cocoa/Cocoa.h> -#import "GraphicsView.h" -#import "TikzSourceController.h" -#import "PreviewController.h" -#import "GraphicsView.h" - -@interface TikzDocument : NSDocument { - NSString *tikz; -} - -@property (readonly) NSString *tikz; -@property (readonly) GraphicsView *graphicsView; - -@end diff --git a/tikzit/src/osx/TikzDocument.m b/tikzit/src/osx/TikzDocument.m deleted file mode 100644 index ef5908d..0000000 --- a/tikzit/src/osx/TikzDocument.m +++ /dev/null @@ -1,84 +0,0 @@ -// -// TikzDocument.m -// TikZiT -// -// Copyright 2010 Aleks Kissinger. All rights reserved. -// -// -// This file is part of TikZiT. -// -// TikZiT is free software: you can redistribute it and/or modify -// it under the terms of the GNU General Public License as published by -// the Free Software Foundation, either version 3 of the License, or -// (at your option) any later version. -// -// TikZiT is distributed in the hope that it will be useful, -// but WITHOUT ANY WARRANTY; without even the implied warranty of -// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -// GNU General Public License for more details. -// -// You should have received a copy of the GNU General Public License -// along with TikZiT. If not, see <http://www.gnu.org/licenses/>. -// - -#import "TikzDocument.h" -#import "TikzWindowController.h" - -@implementation TikzDocument - -@synthesize tikz; - -- (id)init { - self = [super init]; - if (self) { - tikz = nil; - } - return self; -} - -//- (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 @"TikzDocument"; -//} - -- (void)makeWindowControllers { - TikzWindowController *wc = [[TikzWindowController alloc] initWithDocument:self]; - [self addWindowController:wc]; -} - -- (void)windowControllerDidLoadNib:(NSWindowController *) aController { - [super windowControllerDidLoadNib:aController]; - [[self graphicsView] refreshLayers]; - // Add any code here that needs to be executed once the windowController has loaded the document's window. -} - -- (NSData *)dataOfType:(NSString *)typeName error:(NSError **)outError { - TikzWindowController *wc = - (TikzWindowController*)[[self windowControllers] objectAtIndex:0]; - NSData *outData = [[[wc tikzSourceController] tikz] dataUsingEncoding:NSUTF8StringEncoding]; - - if ( outError != NULL ) { - *outError = [NSError errorWithDomain:NSOSStatusErrorDomain code:unimpErr userInfo:NULL]; - } - return outData; -} - -- (BOOL)readFromData:(NSData *)data ofType:(NSString *)typeName error:(NSError **)outError { - tikz = [[NSString alloc] initWithData:data encoding:NSUTF8StringEncoding]; - - if ( outError != NULL ) { - *outError = [NSError errorWithDomain:NSOSStatusErrorDomain code:unimpErr userInfo:NULL]; - } - - return YES; -} - -- (GraphicsView*)graphicsView { - TikzWindowController *wc = - (TikzWindowController*)[[self windowControllers] objectAtIndex:0]; - return [wc graphicsView]; -} - - -@end diff --git a/tikzit/src/osx/TikzFormatter.h b/tikzit/src/osx/TikzFormatter.h deleted file mode 100644 index 4d9ec04..0000000 --- a/tikzit/src/osx/TikzFormatter.h +++ /dev/null @@ -1,29 +0,0 @@ -// -// NSTikzFormatter.h -// TikZiT -// -// Created by Karl Johan Paulsson on 27/01/2013. -// Copyright (c) 2013 Aleks Kissinger. All rights reserved. -// -// -// This file is part of TikZiT. -// -// TikZiT is free software: you can redistribute it and/or modify -// it under the terms of the GNU General Public License as published by -// the Free Software Foundation, either version 3 of the License, or -// (at your option) any later version. -// -// TikZiT is distributed in the hope that it will be useful, -// but WITHOUT ANY WARRANTY; without even the implied warranty of -// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -// GNU General Public License for more details. -// -// You should have received a copy of the GNU General Public License -// along with TikZiT. If not, see <http://www.gnu.org/licenses/>. -// - -#import <Foundation/Foundation.h> - -@interface TikzFormatter : NSFormatter - -@end diff --git a/tikzit/src/osx/TikzFormatter.m b/tikzit/src/osx/TikzFormatter.m deleted file mode 100644 index 8972706..0000000 --- a/tikzit/src/osx/TikzFormatter.m +++ /dev/null @@ -1,91 +0,0 @@ -// -// NSTikzFormatter.m -// TikZiT -// -// Created by Karl Johan Paulsson on 27/01/2013. -// Copyright (c) 2013 Aleks Kissinger. All rights reserved. -// -// -// This file is part of TikZiT. -// -// TikZiT is free software: you can redistribute it and/or modify -// it under the terms of the GNU General Public License as published by -// the Free Software Foundation, either version 3 of the License, or -// (at your option) any later version. -// -// TikZiT is distributed in the hope that it will be useful, -// but WITHOUT ANY WARRANTY; without even the implied warranty of -// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -// GNU General Public License for more details. -// -// You should have received a copy of the GNU General Public License -// along with TikZiT. If not, see <http://www.gnu.org/licenses/>. -// - -#import "TikzFormatter.h" -#import "TikzGraphAssembler.h" - -@implementation TikzFormatter - -- (NSString *)stringForObjectValue:(id)obj{ - if (![obj isKindOfClass:[NSString class]]) { - return @""; - } - - return [NSString stringWithString:obj]; -} - -- (BOOL)getObjectValue:(out id *)obj forString:(NSString *)string errorDescription:(out NSString **)error{ - *obj = [NSString stringWithString:string]; - - BOOL r = [TikzGraphAssembler validateTikzPropertyNameOrValue:string]; - - if (!r && error) - *error = NSLocalizedString(@"Invalid input, couldn't parse value.", @"tikz user input error"); - - return r; -} - -- (BOOL)isPartialStringValid:(NSString **)partialStringPtr proposedSelectedRange:(NSRangePointer)proposedSelRangePtr originalString:(NSString *)origString originalSelectedRange:(NSRange)origSelRange errorDescription:(NSString **)error{ - NSRange addedRange; - NSString *addedString; - - addedRange = NSMakeRange(origSelRange.location, proposedSelRangePtr->location - origSelRange.location); - addedString = [*partialStringPtr substringWithRange: addedRange]; - - if([addedString isEqualToString:@"{"]){ - NSString *s = [[NSString stringWithString:*partialStringPtr] stringByAppendingString:@"}"]; - *partialStringPtr = s; - - return NO; - } - - if([addedString isEqualToString:@"}"]){ - NSScanner *scanner = [NSScanner scannerWithString:*partialStringPtr]; - - NSCharacterSet *cs = [NSCharacterSet characterSetWithCharactersInString:@"{}"]; - NSMutableString *strippedString = [NSMutableString stringWithCapacity:[*partialStringPtr length]]; - - while ([scanner isAtEnd] == NO) { - NSString *buffer; - if ([scanner scanCharactersFromSet:cs intoString:&buffer]) { - [strippedString appendString:buffer]; - - } else { - [scanner setScanLocation:([scanner scanLocation] + 1)]; - } - } - - [cs autorelease]; - [scanner autorelease]; - [strippedString autorelease]; - - if([strippedString length] % 2 == 1){ - return NO; - } - } - - return YES; -} - -@end diff --git a/tikzit/src/osx/TikzParser.h b/tikzit/src/osx/TikzParser.h deleted file mode 100644 index 18b183f..0000000 --- a/tikzit/src/osx/TikzParser.h +++ /dev/null @@ -1,66 +0,0 @@ -// -// TikzParser.h -// TikZiT -// -// Copyright 2010 Aleks Kissinger. All rights reserved. -// -// -// This file is part of TikZiT. -// -// TikZiT is free software: you can redistribute it and/or modify -// it under the terms of the GNU General Public License as published by -// the Free Software Foundation, either version 3 of the License, or -// (at your option) any later version. -// -// TikZiT is distributed in the hope that it will be useful, -// but WITHOUT ANY WARRANTY; without even the implied warranty of -// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -// GNU General Public License for more details. -// -// You should have received a copy of the GNU General Public License -// along with TikZiT. If not, see <http://www.gnu.org/licenses/>. -// - -#import <Cocoa/Cocoa.h> -#import <ParseKit/ParseKit.h> - -#import "Graph.h" - -@interface TikzParser : NSObject { - PKParser *nodeParser; - PKParser *edgeParser; - PKParser *tikzPictureParser; - PKTokenizer *tokenizer; - - NSString *currentKey; - NSString *currentSourceArrow; - - NSMutableArray *atoms; - NSMutableDictionary *properties; - NSString *leftArrow; - NSString *rightArrow; - - GraphElementData *elementData; - - Graph *graph; - Node *currentNode; - NSMutableDictionary *nodeTable; - - Edge *currentEdge; - BOOL matchingEdgeNode; - NSString *sourceName; - NSString *targName; - - NSPoint bbox1, bbox2; - BOOL bboxFirstPoint; -} - -@property (retain) Graph *graph; - -- (id)init; -- (BOOL)parseNode:(NSString*)str; -- (BOOL)parseEdge:(NSString*)str; -- (BOOL)parseTikzPicture:(NSString*)str forGraph:(Graph*)g; -- (BOOL)parseTikzPicture:(NSString *)str; - -@end diff --git a/tikzit/src/osx/TikzParser.m b/tikzit/src/osx/TikzParser.m deleted file mode 100644 index 2bb5a15..0000000 --- a/tikzit/src/osx/TikzParser.m +++ /dev/null @@ -1,574 +0,0 @@ -// -// TikzParser.m -// TikZiT -// -// Copyright 2010 Aleks Kissinger. All rights reserved. -// -// -// This file is part of TikZiT. -// -// TikZiT is free software: you can redistribute it and/or modify -// it under the terms of the GNU General Public License as published by -// the Free Software Foundation, either version 3 of the License, or -// (at your option) any later version. -// -// TikZiT is distributed in the hope that it will be useful, -// but WITHOUT ANY WARRANTY; without even the implied warranty of -// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -// GNU General Public License for more details. -// -// You should have received a copy of the GNU General Public License -// along with TikZiT. If not, see <http://www.gnu.org/licenses/>. -// - -#import "TikzParser.h" - -// custom parsekit extensions -#import "PKNaturalNumber.h" -#import "PKRepetition+RepeatPlus.h" -#import "PKSpecificDelimitedString.h" -#import "PKBalancingDelimitState.h" - -#import "util.h" - -@interface TikzParser () - -- (NSString*)popAllToString:(PKAssembly*)a withSeparator:(NSString*)sep; -- (PKParser*)eatSymbol:(NSString*)s; -- (PKParser*)eatLiteral:(NSString*)s; -- (PKParser*)eatWord; - -// properties -- (void)willMatchProplist:(PKAssembly*)a; -- (void)didMatchProplist:(PKAssembly*)a; -- (void)willMatchProperty:(PKAssembly*)a; -- (void)didMatchArrowSpecDash:(PKAssembly*)a; - -// nodes -- (void)didMatchNodeCommand:(PKAssembly*)a; -- (void)didMatchNodeLabel:(PKAssembly*)a; -- (void)didMatchNode:(PKAssembly*)a; -- (void)didMatchNodeName:(PKAssembly*)a; -- (void)didMatchCoords:(PKAssembly*)a; - -// edges -- (void)didMatchDrawCommand:(PKAssembly *)a; -- (void)didMatchEdge:(PKAssembly*)a; -- (void)didMatchEdgeNodeCommand:(PKAssembly*)a; -- (void)didMatchEdgeNode:(PKAssembly*)a; - -// bounding box -- (void)didMatchPathCommand:(PKAssembly*)a; -- (void)didMatchBoundingBox:(PKAssembly*)a; - -// tikzpicture -- (void)willMatchTikzPicture:(PKAssembly*)a; -- (void)didMatchTikzPicture:(PKAssembly*)a; - -@end - - -@implementation TikzParser - -@synthesize graph; - -- (id)init { - [super init]; - - currentKey = nil; - currentSourceArrow = nil; - tokenizer = [PKTokenizer tokenizer]; - - graph = nil; - currentNode = nil; - currentEdge = nil; - matchingEdgeNode = NO; - - // tweak the tokenizer a bit - [tokenizer.symbolState remove:@"<="]; - [tokenizer.symbolState remove:@">="]; - [tokenizer.symbolState remove:@"{"]; - [tokenizer.symbolState remove:@"}"]; - [tokenizer setTokenizerState:tokenizer.wordState from:'\\' to:'\\']; - [tokenizer.wordState setWordChars:NO from:'-' to:'-']; - tokenizer.delimitState = [[PKBalancingDelimitState alloc] init]; - [tokenizer.delimitState addStartMarker:@"{" - endMarker:@"}" - allowedCharacterSet:nil]; - [tokenizer setTokenizerState:tokenizer.delimitState from:'{' to:'{']; - - /* - - - GRAMMAR FOR TIKZPICTURE - - tikzpicture = '\begin' '{tikzpicture}' - optproplist - expr* - '\end' '{tikzpicture}' - expr = node | edge | boundingbox | layerexpr - layerexpr = '\begin' '{pgfonlayer}' DelimitedString | '\end' '{pgfonlayer}' - - - GRAMMAR FOR PROPERTY LISTS - - optproplist = proplist | Empty; - proplist = '[' property property1* ']'; - property = arrowspec | keyval | atom; - property1 = ',' property; - keyval = key '=' val; - atom = propsym+; - arrowspec = propsym* '-' propsym*; - key = propsym+; - val = propsym+ | QuotedString; - propsym = (Word | Number | '<' | '>'); - - - GRAMMAR FOR NODES - - node = '\node' optproplist name 'at' coords DelimitedString ';'; - nodename = '(' nodeid ')'; - nodeid = Word | NaturalNumber; - coords = '(' Number ',' Number ')'; - - - GRAMMAR FOR EDGES - - edge = '\draw' optproplist nodename 'to' optedgenode ( nodename | selfloop ) ';'; - selfloop = '(' ')'; - optedgenode = Empty | edgenode - edgenode = 'node' optproplist name coords '{' '}' ';'; - - GRAMMAR FOR BOUNDING BOX - - boundingbox = '\path' '[' 'use' 'as' 'bounding' 'box' ']' coords 'rectangle' coords ';' - - */ - - - PKAlternation *nodeid = [PKAlternation alternation]; - nodeid.name = @"node identifier"; - [nodeid add:[PKWord word]]; - [nodeid add:[PKNaturalNumber number]]; - - PKAlternation *propsym = [PKAlternation alternation]; - propsym.name = @"property symbol"; - [propsym add:[PKWord word]]; - [propsym add:[PKNumber number]]; - [propsym add:[PKSymbol symbolWithString:@"<"]]; - [propsym add:[PKSymbol symbolWithString:@">"]]; - - PKSequence *anchor = [PKSequence sequence]; - [anchor add:[self eatSymbol:@"."]]; - [anchor add:[self eatWord]]; - - PKAlternation *optanchor = [PKAlternation alternation]; - [optanchor add:anchor]; - [optanchor add:[PKEmpty empty]]; - - PKSequence *nodename = [PKSequence sequence]; - nodename.name = @"node name"; - [nodename add:[self eatSymbol:@"("]]; - [nodename add:nodeid]; - [nodename add:optanchor]; - [nodename add:[self eatSymbol:@")"]]; - [nodename setAssembler:self selector:@selector(didMatchNodeName:)]; - - PKTrack *coords = [PKTrack track]; - coords.name = @"coordinate definition"; - [coords add:[self eatSymbol:@"("]]; - [coords add:[PKNumber number]]; - [coords add:[self eatSymbol:@","]]; - [coords add:[PKNumber number]]; - [coords add:[self eatSymbol:@")"]]; - [coords setAssembler:self selector:@selector(didMatchCoords:)]; - - PKSequence *key = [PKRepetition repetitionPlusWithSubparser:propsym]; - - PKAlternation *val = [PKAlternation alternation]; - [val add:[PKRepetition repetitionPlusWithSubparser:propsym]]; - [val add:[PKQuotedString quotedString]]; - [val setPreassembler:self selector:@selector(willMatchVal:)]; - - PKSequence *keyval = [PKSequence sequence]; - [keyval add:key]; - [keyval add:[self eatLiteral:@"="]]; - [keyval add:val]; - - PKSequence *atom = [PKRepetition repetitionPlusWithSubparser:propsym]; - - PKSymbol *arrowspecdash = [PKSymbol symbolWithString:@"-"]; - [arrowspecdash setAssembler:self selector:@selector(didMatchArrowSpecDash:)]; - - PKSequence *arrowspec = [PKSequence sequence]; - [arrowspec add:[PKRepetition repetitionWithSubparser:propsym]]; - [arrowspec add:arrowspecdash]; - [arrowspec add:[PKRepetition repetitionWithSubparser:propsym]]; - - PKAlternation *property = [PKAlternation alternation]; - property.name = @"property, atom, or arrow specification"; - [property add:keyval]; - [property add:arrowspec]; - [property add:atom]; - [property setPreassembler:self selector:@selector(willMatchProperty:)]; - - PKSequence *property1 = [PKSequence sequence]; - [property1 add:[self eatLiteral:@","]]; - [property1 add:property]; - - PKTrack *proplist = [PKTrack track]; - proplist.name = @"property list"; - [proplist add:[self eatSymbol:@"["]]; - [proplist add:property]; - [proplist add:[PKRepetition repetitionWithSubparser:property1]]; - [proplist add:[self eatSymbol:@"]"]]; - [proplist setPreassembler:self selector:@selector(willMatchProplist:)]; - [proplist setAssembler:self selector:@selector(didMatchProplist:)]; - - PKAlternation *optproplist = [PKAlternation alternation]; - [optproplist add:proplist]; - [optproplist add:[PKEmpty empty]]; - - PKLiteral *nodeCommand = [PKLiteral literalWithString:@"\\node"]; - [nodeCommand setAssembler:self selector:@selector(didMatchNodeCommand:)]; - - PKTerminal *nodeLabel = [PKDelimitedString delimitedString]; - nodeLabel.name = @"Possibly empty node label"; - [nodeLabel setAssembler:self selector:@selector(didMatchNodeLabel:)]; - - PKTrack *node = [PKTrack track]; - [node add:nodeCommand]; - [node add:optproplist]; - [node add:nodename]; - [node add:[self eatLiteral:@"at"]]; - [node add:coords]; - [node add:nodeLabel]; - //[node add:[[PKDelimitedString delimitedString] discard]]; - [node add:[self eatSymbol:@";"]]; - [node setAssembler:self selector:@selector(didMatchNode:)]; - - PKLiteral *drawCommand = [PKLiteral literalWithString:@"\\draw"]; - [drawCommand setAssembler:self selector:@selector(didMatchDrawCommand:)]; - - PKSequence *parens = [PKSequence sequence]; - [parens add:[self eatSymbol:@"("]]; - [parens add:[self eatSymbol:@")"]]; - - PKAlternation *nodenamealt = [PKAlternation alternation]; - nodenamealt.name = @"node name or '()'"; - [nodenamealt add:nodename]; - [nodenamealt add:parens]; - - PKLiteral *edgenodeCommand = [PKLiteral literalWithString:@"node"]; - edgenodeCommand.name = @"edge node command"; - [edgenodeCommand setAssembler:self selector:@selector(didMatchEdgeNodeCommand:)]; - - PKSequence *edgenode = [PKSequence sequence]; - [edgenode add:edgenodeCommand]; - [edgenode add:optproplist]; - [edgenode add:nodeLabel]; - edgenode.name = @"edge node"; - [edgenode setAssembler:self selector:@selector(didMatchEdgeNode:)]; - - - PKAlternation *optedgenode = [PKAlternation alternation]; - [optedgenode add:[PKEmpty empty]]; - [optedgenode add:edgenode]; - - - PKTrack *edge = [PKTrack track]; - [edge add:drawCommand]; - [edge add:optproplist]; - [edge add:nodename]; - [edge add:[self eatLiteral:@"to"]]; - [edge add:optedgenode]; - [edge add:nodenamealt]; - [edge add:[self eatSymbol:@";"]]; - [edge setAssembler:self selector:@selector(didMatchEdge:)]; - - - PKLiteral *pathliteral = [PKLiteral literalWithString:@"\\path"]; - [pathliteral setAssembler:self selector:@selector(didMatchPathCommand:)]; - - PKTrack *boundingbox = [PKTrack track]; - [boundingbox add:pathliteral]; - [boundingbox add:[self eatSymbol:@"["]]; - [boundingbox add:[self eatLiteral:@"use"]]; - [boundingbox add:[self eatLiteral:@"as"]]; - [boundingbox add:[self eatLiteral:@"bounding"]]; - [boundingbox add:[self eatLiteral:@"box"]]; - [boundingbox add:[self eatSymbol:@"]"]]; - [boundingbox add:coords]; - [boundingbox add:[self eatLiteral:@"rectangle"]]; - [boundingbox add:coords]; - [boundingbox add:[self eatSymbol:@";"]]; - [boundingbox setAssembler:self selector:@selector(didMatchBoundingBox:)]; - - PKTerminal *layerLiteral = - [[PKSpecificDelimitedString delimitedStringWithValue:@"{pgfonlayer}"] - discard]; - - PKSequence *beginLayer = [PKSequence sequence]; - [beginLayer add:[self eatLiteral:@"\\begin"]]; - [beginLayer add:layerLiteral]; - [beginLayer add:[[PKDelimitedString delimitedString] discard]]; - - PKSequence *endLayer = [PKSequence sequence]; - [endLayer add:[self eatLiteral:@"\\end"]]; - [endLayer add:layerLiteral]; - - PKAlternation *expr = [PKAlternation alternation]; - [expr add:node]; - [expr add:edge]; - [expr add:boundingbox]; - [expr add:beginLayer]; - [expr add:endLayer]; - - PKTerminal *tikzpicLiteral = - [[PKSpecificDelimitedString delimitedStringWithValue:@"{tikzpicture}"] - discard]; - - //tikzpicLiteral.name = @"{tikzpicture}"; - - PKTrack *tikzpic = [PKTrack track]; - [tikzpic add:[PKEmpty empty]]; - [tikzpic add:[self eatLiteral:@"\\begin"]]; - [tikzpic add:tikzpicLiteral]; - [tikzpic add:optproplist]; - [tikzpic add:[PKRepetition repetitionWithSubparser:expr]]; - [tikzpic add:[self eatLiteral:@"\\end"]]; - [tikzpic add:tikzpicLiteral]; - [tikzpic setPreassembler:self selector:@selector(willMatchTikzPicture:)]; - [tikzpic setAssembler:self selector:@selector(didMatchTikzPicture:)]; - - nodeParser = node; - edgeParser = edge; - tikzPictureParser = tikzpic; - - return self; -} - -- (NSString*)popAllToString:(PKAssembly*)a withSeparator:(NSString*)sep { - NSString *str = @""; - BOOL fst = YES; - - while (![a isStackEmpty]) { - if (fst) fst = NO; - else str = [sep stringByAppendingString:str]; - - PKToken *tok = [a pop]; - str = [tok.stringValue stringByAppendingString:str]; - } - - return str; -} - -- (PKParser*)eatSymbol:(NSString*)s { - return [[PKSymbol symbolWithString:s] discard]; -} - -- (PKParser*)eatLiteral:(NSString*)s { - return [[PKLiteral literalWithString:s] discard]; -} - -- (PKParser*)eatWord { - return [[PKWord word] discard]; -} - -- (void)packProperty:(PKAssembly*)a { - BOOL empty = [a isStackEmpty]; - NSString *val = [self popAllToString:a withSeparator:@" "]; - - if (currentKey != nil) { - [elementData setProperty:val forKey:currentKey]; -// NSLog(@" keyval: (%@) => (%@)", currentKey, val); - } else if (currentSourceArrow != nil) { - [elementData setArrowSpecFrom:currentSourceArrow to:val]; -// NSLog(@" arrowspec: (%@-%@)", currentSourceArrow, val); - } else if (!empty) { - [elementData setAtom:val]; -// NSLog(@" atom: (%@)", val); - } - - currentKey = nil; - currentSourceArrow = nil; -} - -- (BOOL)parseNode:(NSString *)str { - tokenizer.string = str; - PKAssembly *res = [nodeParser completeMatchFor:[PKTokenAssembly assemblyWithTokenizer:tokenizer]]; - -// NSLog(@"result: %@", res); - return res != nil; -} - -- (BOOL)parseEdge:(NSString *)str { - tokenizer.string = str; - PKAssembly *res = [edgeParser completeMatchFor:[PKTokenAssembly assemblyWithTokenizer:tokenizer]]; - -// NSLog(@"result: %@", res); - return res != nil; -} - -- (BOOL)parseTikzPicture:(NSString*)str forGraph:(Graph*)g { - self.graph = g; - tokenizer.string = str; - PKTokenAssembly *assm = [PKTokenAssembly assemblyWithTokenizer:tokenizer]; - PKAssembly *res = [tikzPictureParser completeMatchFor:assm]; - -// NSLog(@"result: %@", res); - return res != nil; -} - -- (BOOL)parseTikzPicture:(NSString *)str { - return [self parseTikzPicture:str forGraph:[Graph graph]]; -} - - -- (void)didMatchNodeCommand:(PKAssembly*)a { - [a pop]; - currentNode = [Node node]; - [currentNode updateData]; -// NSLog(@"<node>"); -} - -- (void)didMatchNodeLabel:(PKAssembly*)a { - PKToken *tok = [a pop]; - NSString *s = tok.stringValue; - s = [s substringWithRange:NSMakeRange(1, [s length]-2)]; - if (matchingEdgeNode) currentEdge.edgeNode.label = s; - else currentNode.label = s; -} - -- (void)didMatchNode:(PKAssembly*)a { - [nodeTable setObject:currentNode forKey:currentNode.name]; - [graph addNode:currentNode]; - currentNode = nil; -// NSLog(@"</node>"); -} - -- (void)didMatchDrawCommand:(PKAssembly*)a { - [a pop]; - currentEdge = [Edge edge]; - sourceName = nil; - targName = nil; -// NSLog(@"<edge>"); -} - -- (void)didMatchEdge:(PKAssembly*)a { - Node *src = [nodeTable objectForKey:sourceName]; - currentEdge.source = src; - currentEdge.target = (targName == nil) ? src : [nodeTable objectForKey:targName]; - [currentEdge setAttributesFromData]; - [graph addEdge:currentEdge]; - currentEdge = nil; -// NSLog(@"</edge>"); -} - -- (void)didMatchEdgeNodeCommand:(PKAssembly*)a { - [a pop]; - matchingEdgeNode = YES; - currentEdge.edgeNode = [Node node]; -} - -- (void)didMatchEdgeNode:(PKAssembly*)a { - matchingEdgeNode = NO; -} - -- (void)willMatchVal:(PKAssembly*)a { - currentKey = [self popAllToString:a withSeparator:@" "]; -// NSLog(@"key: %@", currentKey); -} - -- (void)willMatchProperty:(PKAssembly*)a { - [self packProperty:a]; -} - -- (void)willMatchProplist:(PKAssembly*)a { - elementData = [[GraphElementData alloc] init]; -} - -- (void)didMatchProplist:(PKAssembly*)a { - [self packProperty:a]; - - if (currentNode != nil) { - currentNode.data = elementData; - } else if (currentEdge != nil) { - if (matchingEdgeNode) currentEdge.edgeNode.data = elementData; - else currentEdge.data = elementData; - } else { // add properties to to graph - graph.data = elementData; - } - - elementData = nil; -} - -- (void)didMatchNodeName:(PKAssembly*)a { - NSString *name = ((PKToken*)[a pop]).stringValue; - - if (currentNode != nil) { - currentNode.name = name; -// NSLog(@" name: (%@)", name); - } else if (currentEdge != nil) { - if (sourceName == nil) { - sourceName = name; -// NSLog(@" source: (%@)", name); - } else { - targName = name; -// NSLog(@" target: (%@)", name); - } - } -} - -- (void)didMatchCoords:(PKAssembly*)a { - NSPoint p; - p.y = ((PKToken*)[a pop]).floatValue; - p.x = ((PKToken*)[a pop]).floatValue; - - if (currentNode != nil) { - currentNode.point = p; - } else { - if (bboxFirstPoint) { - bboxFirstPoint = NO; - bbox1 = p; - } else { - bbox2 = p; - } - } - -// NSLog(@" coord: (%f, %f)", p.x, p.y); -} - -- (void)didMatchPathCommand:(PKAssembly*)a { - [a pop]; - bboxFirstPoint = YES; -} - -- (void)didMatchBoundingBox:(PKAssembly*)a { - graph.boundingBox = NSRectAroundPoints(bbox1, bbox2); -} - -- (void)didMatchArrowSpecDash:(PKAssembly*)a { - [a pop]; // pop off the dash - currentSourceArrow = [self popAllToString:a withSeparator:@" "]; -} - -- (void)willMatchTikzPicture:(PKAssembly*)a { -// NSLog(@"<tikz>"); - nodeTable = [NSMutableDictionary dictionary]; -} - -- (void)didMatchTikzPicture:(PKAssembly*)a { -// NSLog(@"</tikz>"); -// NSLog(@"%@", [graph tikz]); -} - -- (void)finalize { -// NSLog(@"releasing subparser trees"); - PKReleaseSubparserTree(nodeParser); - PKReleaseSubparserTree(edgeParser); - PKReleaseSubparserTree(tikzPictureParser); - [super finalize]; -} - -@end diff --git a/tikzit/src/osx/TikzSourceController.h b/tikzit/src/osx/TikzSourceController.h deleted file mode 100644 index 3408d9f..0000000 --- a/tikzit/src/osx/TikzSourceController.h +++ /dev/null @@ -1,71 +0,0 @@ -// -// TikzSourceController.h -// TikZiT -// -// Copyright 2010 Aleks Kissinger. All rights reserved. -// -// -// This file is part of TikZiT. -// -// TikZiT is free software: you can redistribute it and/or modify -// it under the terms of the GNU General Public License as published by -// the Free Software Foundation, either version 3 of the License, or -// (at your option) any later version. -// -// TikZiT is distributed in the hope that it will be useful, -// but WITHOUT ANY WARRANTY; without even the implied warranty of -// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -// GNU General Public License for more details. -// -// You should have received a copy of the GNU General Public License -// along with TikZiT. If not, see <http://www.gnu.org/licenses/>. -// - -#import <Cocoa/Cocoa.h> - -#import "GraphicsView.h" -#import "ParseErrorView.h" - -@interface TikzSourceController : NSObject { - GraphicsView *graphicsView; - NSTextView *sourceView; - NSAttributedString *source; - NSTextField *status; - NSDictionary *textAttrs; - NSColor *successColor; - NSColor *failedColor; - NSTextField *errorMessage; - ParseErrorView *errorNotification; - - NSUndoManager *documentUndoManager; - - BOOL tikzChanged; - BOOL justUndid; - - NSError *lastError; -} - -@property BOOL tikzChanged; -@property IBOutlet GraphicsView *graphicsView; -@property IBOutlet NSTextView *sourceView; -@property IBOutlet NSTextField *status; -@property NSUndoManager *documentUndoManager; -@property (copy) NSAttributedString *source; -@property (copy) NSString *tikz; -@property IBOutlet ParseErrorView *errorNotification; -@property IBOutlet NSTextField *errorMessage; - -- (void)updateTikzFromGraph; -- (void)graphChanged:(NSNotification*)n; - -- (IBAction)closeParseError:(id)pId; - -// called by code, these do not register an undo -- (BOOL)tryParseTikz; -- (void)doRevertTikz; - -// called by user, these do register an undo -- (void)parseTikz:(id)sender; -- (void)revertTikz:(id)sender; - -@end diff --git a/tikzit/src/osx/TikzSourceController.m b/tikzit/src/osx/TikzSourceController.m deleted file mode 100644 index 0cb3703..0000000 --- a/tikzit/src/osx/TikzSourceController.m +++ /dev/null @@ -1,237 +0,0 @@ -// -// TikzSourceController.m -// TikZiT -// -// Copyright 2010 Aleks Kissinger. All rights reserved. -// -// -// This file is part of TikZiT. -// -// TikZiT is free software: you can redistribute it and/or modify -// it under the terms of the GNU General Public License as published by -// the Free Software Foundation, either version 3 of the License, or -// (at your option) any later version. -// -// TikZiT is distributed in the hope that it will be useful, -// but WITHOUT ANY WARRANTY; without even the implied warranty of -// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -// GNU General Public License for more details. -// -// You should have received a copy of the GNU General Public License -// along with TikZiT. If not, see <http://www.gnu.org/licenses/>. -// - -#import "TikzSourceController.h" -#import "TikzGraphAssembler.h" -#import "Graph.h" - -@implementation TikzSourceController - -@synthesize graphicsView, sourceView, source, status; -@synthesize documentUndoManager, tikzChanged; -@synthesize errorMessage, errorNotification; - -- (void)endEditing { - NSResponder *res = [[sourceView window] firstResponder]; - [[sourceView window] makeFirstResponder:nil]; - [[sourceView window] makeFirstResponder:res]; -} - -- (void)undoParseTikz:(Graph *)oldGraph { - [graphicsView setGraph:oldGraph]; - [graphicsView setEnabled:NO]; - [graphicsView postGraphChange]; - [graphicsView refreshLayers]; - - [documentUndoManager registerUndoWithTarget:self - selector:@selector(parseTikz:) - object:self]; - [documentUndoManager setActionName:@"Parse Tikz"]; -} - -- (void)undoRevertTikz:(NSString*)oldTikz { - [self setTikz:oldTikz]; - [graphicsView setEnabled:NO]; - [graphicsView refreshLayers]; - - [documentUndoManager registerUndoWithTarget:self - selector:@selector(revertTikz:) - object:self]; - [documentUndoManager setActionName:@"Revert Tikz"]; -} - -- (void)undoTikzChange:(id)ignore { - [graphicsView setEnabled:YES]; - [graphicsView refreshLayers]; - [self endEditing]; - [self updateTikzFromGraph]; - [documentUndoManager registerUndoWithTarget:self - selector:@selector(redoTikzChange:) - object:nil]; - [documentUndoManager setActionName:@"Tikz Change"]; -} - -- (void)redoTikzChange:(id)ignore { - [graphicsView setEnabled:NO]; - [graphicsView refreshLayers]; - [documentUndoManager registerUndoWithTarget:self - selector:@selector(undoTikzChange:) - object:nil]; - [documentUndoManager setActionName:@"Tikz Change"]; -} - - -- (void)awakeFromNib { - justUndid = NO; - successColor = [NSColor colorWithCalibratedRed:0.0f - green:0.5f - blue:0.0f - alpha:1.0f]; - failedColor = [NSColor redColor]; - - NSFont *font = [NSFont userFixedPitchFontOfSize:11.0f]; - - if (font != nil) { - textAttrs = [NSDictionary dictionaryWithObject:font - forKey:NSFontAttributeName]; - } else { - NSLog(@"WARNING: couldn't find monospaced font."); - textAttrs = [NSDictionary dictionary]; - } - - - [self graphChanged:nil]; - [[NSNotificationCenter defaultCenter] addObserver:self - selector:@selector(graphChanged:) - name:@"GraphChanged" - object:graphicsView]; -} - -- (void)setTikz:(NSString *)str { - [self willChangeValueForKey:@"source"]; - source = [[NSAttributedString alloc] initWithString:str attributes:textAttrs]; - [self didChangeValueForKey:@"source"]; -} - -- (NSString*)tikz { - return [source string]; -} - -- (void)updateTikzFromGraph { - [self setTikz:[[graphicsView graph] tikz]]; - [errorNotification setHidden:TRUE]; -} - -- (void)graphChanged:(NSNotification*)n { - if ([graphicsView enabled]) [self updateTikzFromGraph]; -} - -- (IBAction)closeParseError:(id)pId{ - [errorNotification setHidden:TRUE]; -} - -- (void)textDidBeginEditing:(NSNotification *)notification { - if ([graphicsView enabled]){ - [graphicsView setEnabled:NO]; - [graphicsView refreshLayers]; - [documentUndoManager registerUndoWithTarget:self - selector:@selector(undoTikzChange:) - object:nil]; - [documentUndoManager setActionName:@"Tikz Change"]; - } -} - -- (BOOL)tryParseTikz { - Graph *g = [TikzGraphAssembler parseTikz:[self tikz] - error:&lastError]; - - if (g) { - [graphicsView deselectAll:self]; - [graphicsView setGraph:g]; - [graphicsView refreshLayers]; - [self doRevertTikz]; - } - - return success; -} - -- (void)doRevertTikz { - [self updateTikzFromGraph]; - [self endEditing]; - [graphicsView setEnabled:YES]; - [graphicsView refreshLayers]; - [status setStringValue:@""]; -} - -- (void)parseTikz:(id)sender { - if (![graphicsView enabled]) { - Graph *oldGraph = [graphicsView graph]; - if ([self tryParseTikz]) { - [self endEditing]; - [documentUndoManager registerUndoWithTarget:self - selector:@selector(undoParseTikz:) - object:oldGraph]; - [documentUndoManager setActionName:@"Parse Tikz"]; - - [status setStringValue:@"success"]; - [status setTextColor:successColor]; - - [errorNotification setHidden:TRUE]; - } else { - [status setStringValue:@"parse error"]; - [status setTextColor:failedColor]; - - NSDictionary *d = [lastError userInfo]; - - NSString *ts = [NSString stringWithFormat: @"Parse error on line %@: %@\n", [d valueForKey:@"startLine"], [d valueForKey:NSLocalizedDescriptionKey]]; - NSMutableAttributedString *as = [[NSMutableAttributedString alloc] initWithString:[NSString stringWithFormat: @"Parse error on line %@: %@\n%@\n", [d valueForKey:@"startLine"], [d valueForKey:NSLocalizedDescriptionKey], [[d valueForKey:@"syntaxString"] stringByReplacingOccurrencesOfString:@"\t" withString:@""]]]; - - NSInteger tokenLength = [[d valueForKey:@"tokenLength"] integerValue]; - // Bit of a mess, offset around to find correct position and correct for 4 characters for every one character of \t - NSInteger addedTokenStart = [[d valueForKey:@"tokenStart"] integerValue] + [ts length] - ([[[d valueForKey:@"syntaxString"] componentsSeparatedByString:@"\t"] count]-1)*4 - tokenLength; - - // Can't see if the error is a start paranthesis as only that will be underlined, underline the entire paranthesis instead - if(tokenLength == 1 && [[as string] characterAtIndex:addedTokenStart] == '('){ - tokenLength += [[[as string] substringFromIndex:addedTokenStart+1] rangeOfString:@")"].location + 1; - } - - // Same if unexpected endparanthesis - if(tokenLength == 1 && [[as string] characterAtIndex:addedTokenStart] == ')'){ - NSInteger d = addedTokenStart - [[[as string] substringToIndex:addedTokenStart] rangeOfString:@"(" options:NSBackwardsSearch].location; - - tokenLength += d; - addedTokenStart -= d; - } - - [as beginEditing]; - [as addAttributes:[NSDictionary dictionaryWithObjectsAndKeys: - [NSNumber numberWithInt:NSUnderlineStyleSingle | NSUnderlinePatternDot], NSUnderlineStyleAttributeName, - [NSColor redColor], NSUnderlineColorAttributeName, - nil] - range:NSMakeRange(addedTokenStart, tokenLength)]; - [as endEditing]; - - [errorMessage setAttributedStringValue:as]; - [errorNotification setHidden:FALSE]; - } - } -} - -- (void)revertTikz:(id)sender { - if (![graphicsView enabled]) { - NSString *oldTikz = [[self tikz] copy]; - [self doRevertTikz]; - - [documentUndoManager registerUndoWithTarget:self - selector:@selector(undoRevertTikz:) - object:oldTikz]; - [documentUndoManager setActionName:@"Revert Tikz"]; - } -} - -- (void)finalize { - [[NSNotificationCenter defaultCenter] removeObserver:self]; - [super finalize]; -} - -@end diff --git a/tikzit/src/osx/TikzWindowController.h b/tikzit/src/osx/TikzWindowController.h deleted file mode 100644 index e35b7eb..0000000 --- a/tikzit/src/osx/TikzWindowController.h +++ /dev/null @@ -1,31 +0,0 @@ -// -// TikzWindowController.h -// TikZiT -// -// Created by Aleks Kissinger on 26/01/2011. -// Copyright 2011 __MyCompanyName__. All rights reserved. -// - -#import <Cocoa/Cocoa.h> - -@class TikzDocument, GraphicsView, TikzSourceController; - -@interface TikzWindowController : NSWindowController { - GraphicsView *graphicsView; - TikzSourceController *tikzSourceController; - TikzDocument *document; -} - -@property IBOutlet GraphicsView *graphicsView; -@property IBOutlet TikzSourceController *tikzSourceController; - -- (id)initWithDocument:(TikzDocument*)doc; - -// pass these straight to the tikz source controller -- (void)parseTikz:(id)sender; -- (void)revertTikz:(id)sender; -- (void)zoomIn:(id)sender; -- (void)zoomOut:(id)sender; -- (void)zoomToActualSize:(id)sender; - -@end diff --git a/tikzit/src/osx/TikzWindowController.m b/tikzit/src/osx/TikzWindowController.m deleted file mode 100644 index 2e672d2..0000000 --- a/tikzit/src/osx/TikzWindowController.m +++ /dev/null @@ -1,66 +0,0 @@ -// -// TikzWindowController.m -// TikZiT -// -// Created by Aleks Kissinger on 26/01/2011. -// Copyright 2011 __MyCompanyName__. All rights reserved. -// - -#import "TikzWindowController.h" -#import "TikzDocument.h" -#import "GraphicsView.h" -#import "TikzSourceController.h" - -@implementation TikzWindowController - -@synthesize graphicsView, tikzSourceController; - -- (id)initWithDocument:(TikzDocument*)doc { - [super initWithWindowNibName:@"TikzDocument"]; - document = doc; - return self; -} - -- (void)awakeFromNib { - if ([document tikz] != nil) { - [graphicsView setEnabled:NO]; - [tikzSourceController setTikz:[document tikz]]; - [tikzSourceController parseTikz:self]; - } - - [graphicsView setDocumentUndoManager:[document undoManager]]; - [tikzSourceController setDocumentUndoManager:[document undoManager]]; -} - -- (void)parseTikz:(id)sender { - [tikzSourceController parseTikz:sender]; -} - -- (void)revertTikz:(id)sender { - [tikzSourceController revertTikz:sender]; -} - -- (void)previewTikz:(id)sender { - PreviewController *pc = [PreviewController defaultPreviewController]; - if (![[pc window] isVisible]) [pc showWindow:sender]; - [pc buildTikz:[tikzSourceController tikz]]; -} - -- (void)zoomIn:(id)sender { - float scale = [[graphicsView transformer] scale] * 1.25f; - [[graphicsView transformer] setScale:scale]; - [graphicsView refreshLayers]; -} - -- (void)zoomOut:(id)sender { - float scale = [[graphicsView transformer] scale] * 0.8f; - [[graphicsView transformer] setScale:scale]; - [graphicsView refreshLayers]; -} - -- (void)zoomToActualSize:(id)sender { - [[graphicsView transformer] setScale:50.0f]; - [graphicsView refreshLayers]; -} - -@end diff --git a/tikzit/src/osx/ToolPaletteController.h b/tikzit/src/osx/ToolPaletteController.h deleted file mode 100644 index e45c08d..0000000 --- a/tikzit/src/osx/ToolPaletteController.h +++ /dev/null @@ -1,42 +0,0 @@ -// -// ToolPaletteController.h -// TikZiT -// -// Copyright 2010 Aleks Kissinger. All rights reserved. -// -// -// This file is part of TikZiT. -// -// TikZiT is free software: you can redistribute it and/or modify -// it under the terms of the GNU General Public License as published by -// the Free Software Foundation, either version 3 of the License, or -// (at your option) any later version. -// -// TikZiT is distributed in the hope that it will be useful, -// but WITHOUT ANY WARRANTY; without even the implied warranty of -// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -// GNU General Public License for more details. -// -// You should have received a copy of the GNU General Public License -// along with TikZiT. If not, see <http://www.gnu.org/licenses/>. -// -#import <Cocoa/Cocoa.h> - -typedef enum { - TikzToolSelect, - TikzToolNode, - TikzToolEdge, - TikzToolCrop -} TikzTool; - -@interface ToolPaletteController : NSObject { - NSPanel *toolPalette; - NSMatrix *toolMatrix; -} - -@property TikzTool selectedTool; -@property IBOutlet NSPanel *toolPalette; -@property IBOutlet NSMatrix *toolMatrix; - - -@end diff --git a/tikzit/src/osx/ToolPaletteController.m b/tikzit/src/osx/ToolPaletteController.m deleted file mode 100644 index 000287d..0000000 --- a/tikzit/src/osx/ToolPaletteController.m +++ /dev/null @@ -1,58 +0,0 @@ -// -// ToolPaletteController.m -// TikZiT -// -// Copyright 2010 Aleks Kissinger. All rights reserved. -// -// -// This file is part of TikZiT. -// -// TikZiT is free software: you can redistribute it and/or modify -// it under the terms of the GNU General Public License as published by -// the Free Software Foundation, either version 3 of the License, or -// (at your option) any later version. -// -// TikZiT is distributed in the hope that it will be useful, -// but WITHOUT ANY WARRANTY; without even the implied warranty of -// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -// GNU General Public License for more details. -// -// You should have received a copy of the GNU General Public License -// along with TikZiT. If not, see <http://www.gnu.org/licenses/>. -// - -#import "ToolPaletteController.h" - - -@implementation ToolPaletteController - -@synthesize toolPalette, toolMatrix; - -- (TikzTool)selectedTool { - switch (toolMatrix.selectedRow) { - case 0: return TikzToolSelect; - case 1: return TikzToolNode; - case 2: return TikzToolEdge; - case 3: return TikzToolCrop; - } - return TikzToolSelect; -} - -- (void)setSelectedTool:(TikzTool)tool { - switch (tool) { - case TikzToolSelect: - [toolMatrix selectCellAtRow:0 column:0]; - break; - case TikzToolNode: - [toolMatrix selectCellAtRow:1 column:0]; - break; - case TikzToolEdge: - [toolMatrix selectCellAtRow:2 column:0]; - break; - case TikzToolCrop: - [toolMatrix selectCellAtRow:3 column:0]; - break; - } -} - -@end diff --git a/tikzit/src/osx/main.m b/tikzit/src/osx/main.m deleted file mode 100644 index e6b4499..0000000 --- a/tikzit/src/osx/main.m +++ /dev/null @@ -1,26 +0,0 @@ -// -// main.m -// TikZiT -// -// Copyright 2010 Aleks Kissinger. All rights reserved. -// -// -// This file is part of TikZiT. -// -// TikZiT is free software: you can redistribute it and/or modify -// it under the terms of the GNU General Public License as published by -// the Free Software Foundation, either version 3 of the License, or -// (at your option) any later version. -// -// TikZiT is distributed in the hope that it will be useful, -// but WITHOUT ANY WARRANTY; without even the implied warranty of -// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -// GNU General Public License for more details. -// - -#import <Cocoa/Cocoa.h> - -int main(int argc, char *argv[]) -{ - return NSApplicationMain(argc, (const char **) argv); -} diff --git a/tikzit/src/osx/test/main.m b/tikzit/src/osx/test/main.m deleted file mode 100644 index ad0c1f7..0000000 --- a/tikzit/src/osx/test/main.m +++ /dev/null @@ -1,56 +0,0 @@ -// -// main.m -// TikZiT -// -// Copyright 2010 Aleks Kissinger. All rights reserved. -// -// -// This file is part of TikZiT. -// -// TikZiT is free software: you can redistribute it and/or modify -// it under the terms of the GNU General Public License as published by -// the Free Software Foundation, either version 3 of the License, or -// (at your option) any later version. -// -// TikZiT is distributed in the hope that it will be useful, -// but WITHOUT ANY WARRANTY; without even the implied warranty of -// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -// GNU General Public License for more details. -// -// You should have received a copy of the GNU General Public License -// along with TikZiT. If not, see <http://www.gnu.org/licenses/>. -// - -#import "test/test.h" -#include <string.h> - -void testCommon(); -void testOSX(); - -int main(int argc, char **argv) { - if (argc == 2 && strcmp(argv[1], "--disable-color")==0) { - setColorEnabled(NO); - } else { - setColorEnabled(YES); - } - - NSBundle *bund = [NSBundle bundleWithPath:@"TikZiT.app"]; - - - PUTS(@""); - PUTS(@"**********************************************"); - PUTS(@"TikZiT TESTS, OS X BUNDLE VERSION %@", - [bund objectForInfoDictionaryKey:@"CFBundleVersion"]); - PUTS(@"**********************************************"); - PUTS(@""); - - startTests(); - testCommon(); - testOSX(); - - PUTS(@""); - PUTS(@"**********************************************"); - endTests(); - PUTS(@"**********************************************"); - PUTS(@""); -}
\ No newline at end of file diff --git a/tikzit/src/osx/test/osx.m b/tikzit/src/osx/test/osx.m deleted file mode 100644 index f9565ab..0000000 --- a/tikzit/src/osx/test/osx.m +++ /dev/null @@ -1,64 +0,0 @@ -// -// osx.m -// TikZiT -// -// Copyright 2010 Aleks Kissinger. All rights reserved. -// -// -// This file is part of TikZiT. -// -// TikZiT is free software: you can redistribute it and/or modify -// it under the terms of the GNU General Public License as published by -// the Free Software Foundation, either version 3 of the License, or -// (at your option) any later version. -// -// TikZiT is distributed in the hope that it will be useful, -// but WITHOUT ANY WARRANTY; without even the implied warranty of -// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -// GNU General Public License for more details. -// -// You should have received a copy of the GNU General Public License -// along with TikZiT. If not, see <http://www.gnu.org/licenses/>. -// -#import "test/test.h" - -#import <Cocoa/Cocoa.h> - -void testOSX() { -// char template[] = "/tmp/tikzit_test_tmp_XXXXXXX"; -// char *dir = mkdtemp(template); -// NSString *tempDir = [NSString stringWithUTF8String:dir]; -// -// NSString *testLatex = -// @"\\documentclass{article}\n" -// @"\\begin{document}\n" -// @"test document\n" -// @"\\end{document}\n"; -// -// NSString *texFile = [NSString stringWithFormat:@"%@/test.tex", tempDir]; -// NSString *pdfFile = [NSString stringWithFormat:@"%@/test.pdf", tempDir]; -// -// [testLatex writeToFile:texFile atomically:NO encoding:NSUTF8StringEncoding error:NULL]; -// -// NSTask *task = [[NSTask alloc] init]; -// [task setLaunchPath:@"/bin/bash"]; -// NSPipe *inpt = [NSPipe pipe]; -// NSPipe *outpt = [NSPipe pipe]; -// [task setStandardInput:inpt]; -// [task setStandardOutput:outpt]; -// -// [task launch]; -// -// NSFileHandle *wr = [inpt fileHandleForWriting]; -// NSString *cmd = -// [NSString stringWithFormat: -// @"if [ -e ~/.profile ]; then source ~/.profile; fi" -// @"if [ -e ~/.profile ]; then source ~/.profile; fi"; -// [wr writeData:[cmd dataUsingEncoding:NSUTF8StringEncoding]]; -// [wr closeFile]; -// -// NSFileHandle *rd = [outpt fileHandleForReading]; -// NSString *res = [[NSString alloc] initWithData:[rd readDataToEndOfFile] -// encoding:NSUTF8StringEncoding]; -// NSLog(@"got:\n %@", res); -} diff --git a/tikzit/src/tikzit.rc b/tikzit/src/tikzit.rc deleted file mode 100644 index 072f825..0000000 --- a/tikzit/src/tikzit.rc +++ /dev/null @@ -1,24 +0,0 @@ -1 VERSIONINFO -FILEVERSION 0,7,0,0 -PRODUCTVERSION 0,7,0,0 -BEGIN - BLOCK "StringFileInfo" - BEGIN - BLOCK "080904E4" - BEGIN - VALUE "FileDescription", "A graph editor for LaTeX" - VALUE "FileVersion", "1.0" - VALUE "InternalName", "tikzit" - VALUE "LegalCopyright", "Aleks Kissinger, Alex Merry, Chris Heunen" - VALUE "OriginalFilename", "tikzit.exe" - VALUE "ProductName", "TikZiT" - VALUE "ProductVersion", "0.7" - END - END - - BLOCK "VarFileInfo" - BEGIN - VALUE "Translation", 0x809, 1252 - END -END -id ICON "../tikzit.ico" diff --git a/tikzit/text-x-generic.png b/tikzit/text-x-generic.png Binary files differdeleted file mode 100644 index 928a679..0000000 --- a/tikzit/text-x-generic.png +++ /dev/null diff --git a/tikzit/text-x-script.png b/tikzit/text-x-script.png Binary files differdeleted file mode 100644 index 801dcd6..0000000 --- a/tikzit/text-x-script.png +++ /dev/null diff --git a/tikzit/tikzit.icns b/tikzit/tikzit.icns Binary files differdeleted file mode 100644 index dc66f7f..0000000 --- a/tikzit/tikzit.icns +++ /dev/null diff --git a/tikzit/tikzit.ico b/tikzit/tikzit.ico Binary files differdeleted file mode 100644 index 3132b4c..0000000 --- a/tikzit/tikzit.ico +++ /dev/null diff --git a/tikzit/tikzit.spec b/tikzit/tikzit.spec deleted file mode 100644 index 880a3e5..0000000 --- a/tikzit/tikzit.spec +++ /dev/null @@ -1,91 +0,0 @@ -Name: tikzit -Version: 1.0 -Release: 1%{?dist} -Summary: Tool for creating and modifying pgf/TikZ diagrams for TeX - -# try to choose a sensible group for this distro -%if 0%{?suse_version} -Group: Productivity/Graphics/Visualization/Graph -%else -%if 0%{?mdkversion} -Group: Sciences/Other -%else -Group: Applications/Productivity -%endif -%endif - -License: GPLv2+ -URL: http://tikzit.sourceforge.net -Source0: http://switch.dl.sourceforge.net/project/%{name}/%{name}-%{version}/%{name}-%{version}.tar.bz2 -BuildRoot: %{_tmppath}/%{name}-%{version}-%{release}-build - -BuildRequires: gcc-objc >= 4.6.0 -BuildRequires: gnustep-base-devel >= 1.18.0 -BuildRequires: gtk2-devel >= 2.18.0 -BuildRequires: pango-devel >= 1.16 -BuildRequires: cairo-devel >= 1.4 -%if 0%{?suse_version}%{?mdkversion} -BuildRequires: libpoppler-glib-devel >= 0.10 -%else -BuildRequires: poppler-glib-devel >= 0.10 -%endif -%if 0%{?suse_version} -BuildRequires: update-desktop-files -%endif - -%description -TikZiT is a GTK+ application that allows the creation and modification of TeX -diagrams written using the pgf/TikZ macro library. It is especially geared -toward rapidly creating "dot"-diagrams for use in academic papers. - - -%prep -%setup -q - - -%build -%configure -make %{?_smp_mflags} - - -%install -rm -rf %{buildroot} -make install DESTDIR=%{buildroot} -%if 0%{?suse_version} -# SuSE is particularly fussy about desktop file categories -%suse_update_desktop_file %{name} -r Graphics 2DGraphics -%endif - - -%clean -rm -rf %{buildroot} - - -%files -%defattr(-,root,root,-) -%doc -%{_bindir}/tikzit -%{_datadir}/tikzit/ -%{_datadir}/applications/tikzit.desktop -%{_datadir}/icons/hicolor/* - - -%changelog -* Tue May 7 2013 Alex Merry <dev@randomguy3.me.uk> 1.0-1 --Bumped version - -* Fri Aug 24 2012 Alex Merry <dev@randomguy3.me.uk> 0.9-1 --Bumped version --Bumped requirements - -* Tue Dec 06 2011 Alex Merry <dev@randomguy3.me.uk> 0.7-1 --Bumped version - -* Tue Feb 08 2011 Alex Merry <dev@randomguy3.me.uk> 0.6-1 --Bumped version --Added Pango and Cairo to BuildRequires --Set minimum version for GNUStep-base - -* Thu Dec 02 2010 Alex Merry <dev@randomguy3.me.uk> 0.5-1 --Rewrote spec file - diff --git a/tikzit/tikzit48x48.png b/tikzit/tikzit48x48.png Binary files differdeleted file mode 100644 index 056d04b..0000000 --- a/tikzit/tikzit48x48.png +++ /dev/null diff --git a/tikzit/tikzit_dsa_pub.pem b/tikzit/tikzit_dsa_pub.pem deleted file mode 100644 index c97cc04..0000000 --- a/tikzit/tikzit_dsa_pub.pem +++ /dev/null @@ -1,20 +0,0 @@ ------BEGIN PUBLIC KEY----- -MIIDOjCCAi0GByqGSM44BAEwggIgAoIBAQDAdRlqLgJYjdAKkDsKtZDXgVlhqwyl -OXWCILHuE/MLh24I/mAaro4hucdhj92V5td9KNdM/R19904yZ3XcLj2/SodDVD7I -lEHPGwC/y+mJd9CaMNI/ARgFbLwJ+3+l/Ia3sraa/ASGAzardJPzYdkkRbZ/1DJn -wtHh2HgmPBdOMZZrbDmw3g4lj69Vacj4Wdz+YDG7750FjAUd+IcOvaDip28B8ogj -ogVirSXGe5YLoYbw078gx92PzSw6vfOZ3b7Gqk7zilYGB0bUJXUPSLOkxa5TMSx1 -Lr2UdW+vXrudI76rBhW52B32i7f801N4/W/qUfg8tw4tUGi/Uw8n2/S5AhUA0F82 -Qxit1jmqP0mZSLAn+qIVPuUCggEAEkSBjRxMo4KRvHOSppZphdaV2RWmQ6w9mxMj -3Z4AGDNU/buQ+TWJEYGVsIXpykI7DYCfgp8XO9uhj1hporfDsU4QGNZd0rG7SLK3 -DHwSf9QTgXY+D5IRQvkBtocxYRgNpuW+mfwl886SPmrRcT3QvsiFaI7/Iw787Tr6 -Yip4D7GjqTvj+epJH6kZq1xbdnrfBEA4dKs5IrZupF75npU8d1EjcdLlTyuzxuoZ -5a3SQWoBvT4l0xvbtR4yv+Af++MB+uxdxBSYMIgtQPgoIjFWtTDRZCwFAig1RWxz -fHEI5Fk4mqGhLAVbROL/pebYYZ5UxTKt9AMjmgmuM10/L5TXbwOCAQUAAoIBAA7t -W96VBoZgbbO2EfSxt5az4EnAJmuua6DNjZzESpcb67/DR7nLd5yveZEPL+9x6c1S -FtduIk8allplryOJtwysf8KkxrPVej83XiVJ9PDLMktsYjtnVksGIk9CS3v98OgT -c3g+xgJpRbwB6dROa5ZMxvoCU100ngfI3F/RUqeYYh7PP5kEL6SfqEHG5udIf1K7 -jUmOycNzI5Fsi+IDh8qtzxoOVTjoMPlN2F4T27xuWXA0BEd/NZqtgGLIFsbww5oD -8VPQIeo9UwQkYo/Qz1/uuaXi1u2PbTbbx2FTUL+zJuqrAv3oqmG2Ktyi0RXZaUAJ -4+P+kdS46Ip2NybQbkE= ------END PUBLIC KEY----- diff --git a/tikzit/tikzitdoc.icns b/tikzit/tikzitdoc.icns Binary files differdeleted file mode 100644 index 2f8bbcd..0000000 --- a/tikzit/tikzitdoc.icns +++ /dev/null diff --git a/tikzit/transform-crop-and-resize.png b/tikzit/transform-crop-and-resize.png Binary files differdeleted file mode 100644 index 4dedd93..0000000 --- a/tikzit/transform-crop-and-resize.png +++ /dev/null diff --git a/tikzit/transform-move.png b/tikzit/transform-move.png Binary files differdeleted file mode 100644 index ae4201b..0000000 --- a/tikzit/transform-move.png +++ /dev/null |