diff options
Diffstat (limited to 'kjsembed')
454 files changed, 64847 insertions, 0 deletions
diff --git a/kjsembed/Doxyfile b/kjsembed/Doxyfile new file mode 100644 index 00000000..2fc6e61d --- /dev/null +++ b/kjsembed/Doxyfile @@ -0,0 +1,227 @@ +# Doxyfile 1.3.8-KDevelop + +#--------------------------------------------------------------------------- +# Project related configuration options +#--------------------------------------------------------------------------- +PROJECT_NAME = KJSEmbed +PROJECT_NUMBER = 0.3 +OUTPUT_DIRECTORY = ./docs/classdocs +CREATE_SUBDIRS = NO +OUTPUT_LANGUAGE = English +USE_WINDOWS_ENCODING = NO +BRIEF_MEMBER_DESC = NO +REPEAT_BRIEF = YES +ABBREVIATE_BRIEF = +ALWAYS_DETAILED_SEC = YES +INLINE_INHERITED_MEMB = YES +FULL_PATH_NAMES = NO +STRIP_FROM_PATH = +STRIP_FROM_INC_PATH = +SHORT_NAMES = NO +JAVADOC_AUTOBRIEF = YES +MULTILINE_CPP_IS_BRIEF = NO +DETAILS_AT_TOP = YES +INHERIT_DOCS = YES +DISTRIBUTE_GROUP_DOC = YES +TAB_SIZE = 8 +ALIASES = +OPTIMIZE_OUTPUT_FOR_C = NO +OPTIMIZE_OUTPUT_JAVA = NO +SUBGROUPING = YES +#--------------------------------------------------------------------------- +# Build related configuration options +#--------------------------------------------------------------------------- +EXTRACT_ALL = YES +EXTRACT_PRIVATE = NO +EXTRACT_STATIC = YES +EXTRACT_LOCAL_CLASSES = NO +EXTRACT_LOCAL_METHODS = NO +HIDE_UNDOC_MEMBERS = NO +HIDE_UNDOC_CLASSES = NO +HIDE_FRIEND_COMPOUNDS = NO +HIDE_IN_BODY_DOCS = NO +INTERNAL_DOCS = NO +CASE_SENSE_NAMES = YES +HIDE_SCOPE_NAMES = NO +SHOW_INCLUDE_FILES = YES +INLINE_INFO = YES +SORT_MEMBER_DOCS = YES +SORT_BRIEF_DOCS = YES +SORT_BY_SCOPE_NAME = YES +GENERATE_TODOLIST = YES +GENERATE_TESTLIST = YES +GENERATE_BUGLIST = YES +GENERATE_DEPRECATEDLIST= YES +ENABLED_SECTIONS = +MAX_INITIALIZER_LINES = 30 +SHOW_USED_FILES = YES +#--------------------------------------------------------------------------- +# configuration options related to warning and progress messages +#--------------------------------------------------------------------------- +QUIET = NO +WARNINGS = YES +WARN_IF_UNDOCUMENTED = YES +WARN_IF_DOC_ERROR = YES +WARN_FORMAT = +WARN_LOGFILE = +#--------------------------------------------------------------------------- +# configuration options related to the input files +#--------------------------------------------------------------------------- +INPUT = . +FILE_PATTERNS = *.h +RECURSIVE = NO +EXCLUDE = doxygen_fakes.h \ + slotutils.h \ + slotproxy.h \ + jseventmapper.h \ + jseventutils.h \ + jsobjecteventproxy.h \ + xmlactionclient.h \ + ksimpleprocess.h +EXCLUDE_SYMLINKS = NO +EXCLUDE_PATTERNS = *.moc.* \ + *_imp.h +EXAMPLE_PATH = docs/examples \ + docs/embedding/simple-embed \ + docs/tutorial \ + cpptests/jsaccess +EXAMPLE_PATTERNS = *.js \ + *.cpp \ + *.html +EXAMPLE_RECURSIVE = YES +IMAGE_PATH = docs/images +INPUT_FILTER = +FILTER_PATTERNS = +FILTER_SOURCE_FILES = NO +#--------------------------------------------------------------------------- +# configuration options related to source browsing +#--------------------------------------------------------------------------- +SOURCE_BROWSER = NO +INLINE_SOURCES = NO +STRIP_CODE_COMMENTS = YES +REFERENCED_BY_RELATION = YES +REFERENCES_RELATION = YES +VERBATIM_HEADERS = YES +#--------------------------------------------------------------------------- +# configuration options related to the alphabetical class index +#--------------------------------------------------------------------------- +ALPHABETICAL_INDEX = YES +COLS_IN_ALPHA_INDEX = 5 +IGNORE_PREFIX = KJSEmbed \ + JS +#--------------------------------------------------------------------------- +# configuration options related to the HTML output +#--------------------------------------------------------------------------- +GENERATE_HTML = YES +HTML_OUTPUT = . +HTML_FILE_EXTENSION = .html +HTML_HEADER = +HTML_FOOTER = +HTML_STYLESHEET = docs/kjsembed.css +HTML_ALIGN_MEMBERS = YES +GENERATE_HTMLHELP = NO +CHM_FILE = +HHC_LOCATION = +GENERATE_CHI = NO +BINARY_TOC = NO +TOC_EXPAND = NO +DISABLE_INDEX = NO +ENUM_VALUES_PER_LINE = 4 +GENERATE_TREEVIEW = NO +TREEVIEW_WIDTH = 250 +#--------------------------------------------------------------------------- +# configuration options related to the LaTeX output +#--------------------------------------------------------------------------- +GENERATE_LATEX = NO +LATEX_OUTPUT = +LATEX_CMD_NAME = latex +MAKEINDEX_CMD_NAME = makeindex +COMPACT_LATEX = NO +PAPER_TYPE = a4wide +EXTRA_PACKAGES = +LATEX_HEADER = +PDF_HYPERLINKS = NO +USE_PDFLATEX = NO +LATEX_BATCHMODE = NO +LATEX_HIDE_INDICES = NO +#--------------------------------------------------------------------------- +# configuration options related to the RTF output +#--------------------------------------------------------------------------- +GENERATE_RTF = NO +RTF_OUTPUT = +COMPACT_RTF = NO +RTF_HYPERLINKS = NO +RTF_STYLESHEET_FILE = +RTF_EXTENSIONS_FILE = +#--------------------------------------------------------------------------- +# configuration options related to the man page output +#--------------------------------------------------------------------------- +GENERATE_MAN = NO +MAN_OUTPUT = +MAN_EXTENSION = +MAN_LINKS = NO +#--------------------------------------------------------------------------- +# configuration options related to the XML output +#--------------------------------------------------------------------------- +GENERATE_XML = NO +XML_OUTPUT = xml +XML_SCHEMA = +XML_DTD = +XML_PROGRAMLISTING = YES +#--------------------------------------------------------------------------- +# configuration options for the AutoGen Definitions output +#--------------------------------------------------------------------------- +GENERATE_AUTOGEN_DEF = NO +#--------------------------------------------------------------------------- +# configuration options related to the Perl module output +#--------------------------------------------------------------------------- +GENERATE_PERLMOD = NO +PERLMOD_LATEX = NO +PERLMOD_PRETTY = YES +PERLMOD_MAKEVAR_PREFIX = +#--------------------------------------------------------------------------- +# Configuration options related to the preprocessor +#--------------------------------------------------------------------------- +ENABLE_PREPROCESSING = YES +MACRO_EXPANSION = YES +EXPAND_ONLY_PREDEF = YES +SEARCH_INCLUDES = YES +INCLUDE_PATH = +INCLUDE_FILE_PATTERNS = +PREDEFINED = Q_PROPERTY()= +EXPAND_AS_DEFINED = KJSEMBED_EXPORT +SKIP_FUNCTION_MACROS = NO +#--------------------------------------------------------------------------- +# Configuration::additions related to external references +#--------------------------------------------------------------------------- +TAGFILES = +GENERATE_TAGFILE = +ALLEXTERNALS = NO +EXTERNAL_GROUPS = YES +PERL_PATH = +#--------------------------------------------------------------------------- +# Configuration options related to the dot tool +#--------------------------------------------------------------------------- +CLASS_DIAGRAMS = YES +HIDE_UNDOC_RELATIONS = YES +HAVE_DOT = NO +CLASS_GRAPH = YES +COLLABORATION_GRAPH = YES +UML_LOOK = YES +TEMPLATE_RELATIONS = YES +INCLUDE_GRAPH = YES +INCLUDED_BY_GRAPH = YES +CALL_GRAPH = YES +GRAPHICAL_HIERARCHY = YES +DOT_IMAGE_FORMAT = png +DOT_PATH = +DOTFILE_DIRS = +MAX_DOT_GRAPH_WIDTH = 800 +MAX_DOT_GRAPH_HEIGHT = 600 +MAX_DOT_GRAPH_DEPTH = 0 +GENERATE_LEGEND = YES +DOT_CLEANUP = YES +#--------------------------------------------------------------------------- +# Configuration::additions related to the search engine +#--------------------------------------------------------------------------- +SEARCHENGINE = NO diff --git a/kjsembed/Doxyfile-Internal b/kjsembed/Doxyfile-Internal new file mode 100644 index 00000000..1987988c --- /dev/null +++ b/kjsembed/Doxyfile-Internal @@ -0,0 +1,824 @@ +# Doxyfile 1.2.9.1 + +# 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 (" ") + +#--------------------------------------------------------------------------- +# General configuration options +#--------------------------------------------------------------------------- + +# The PROJECT_NAME tag is a single word (or a sequence of words surrounded +# by quotes) that should identify the project. + +PROJECT_NAME = KJSEmbed + +# 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 = + +# 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 = ./docs/internal + +# 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: +# Brazilian, Chinese, Croatian, Czech, Danish, Dutch, Finnish, French, +# German, Hungarian, Italian, Japanese, Korean, Norwegian, Polish, +# Portuguese, Romanian, Russian, Slovak, Slovene, Spanish and Swedish. + +OUTPUT_LANGUAGE = English + +# 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 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 = NO + +# 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 class will be included in the various +# overviews. This option has no effect if EXTRACT_ALL is enabled. + +HIDE_UNDOC_CLASSES = YES + +# 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 = NO + +# 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 + +# 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 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 = NO + +# 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. It is allowed to use relative paths in the argument list. + +STRIP_FROM_PATH = + +# 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 CLASS_DIAGRAMS tag is set to YES (the default) Doxygen will +# generate a class diagram (in Html and LaTeX) for classes with base or +# super classes. Setting the tag to NO turns the diagrams off. + +CLASS_DIAGRAMS = YES + +# 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. + +SOURCE_BROWSER = NO + +# 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 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 +# users are adviced to set this option to NO. + +CASE_SENSE_NAMES = YES + +# 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 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 = YES + +# 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 = YES + +# If the SHOW_INCLUDE_FILES tag is set to YES (the default) then Doxygen +# will put list of the files that are included by a file in the documentation +# of that file. + +SHOW_INCLUDE_FILES = YES + +# 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 the Qt-style comments (thus requiring an +# explict @brief command for a brief description. + +JAVADOC_AUTOBRIEF = YES + +# If the INHERIT_DOCS tag is set to YES (the default) then an undocumented +# member inherits the documentation from any documented member that it +# reimplements. + +INHERIT_DOCS = YES + +# 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 = NO + +# 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 + +# 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 + +# The ENABLED_SECTIONS tag can be used to enable conditional +# documentation sections, marked by \if sectionname ... \endif. + +ENABLED_SECTIONS = + +# 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 + +# 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 = + +# The MAX_INITIALIZER_LINES tag determines the maximum number of lines +# the initial value of a variable or define consist 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 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 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 + +#--------------------------------------------------------------------------- +# 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 = NO + +# 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. + +WARN_FORMAT = + +# 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 = . bindings builtins + +# 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 all files are included. + +FILE_PATTERNS = *.h + +# 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 = NO + +# 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 = doxygen_fakes.h +#EXCLUDE = customobject_imp.h jsfactory_imp.h jsproxy_imp.h \ +# kjsembedpart_imp.h jsbuiltin_imp.h \ +# jsobjectproxy_imp.h jsvalueproxy_imp.h \ +# doxygen_fakes.h + +# 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. + +EXCLUDE_PATTERNS = *.moc.* + +# 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 = + +# 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. + +INPUT_FILTER = + +# 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. + +FILTER_SOURCE_FILES = 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 = KJSEmbed + +#--------------------------------------------------------------------------- +# 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 = . + +# 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 + +HTML_STYLESHEET = + +# 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 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 compressed HTML help file (.chm) +# of the generated HTML documentation. + +GENERATE_HTMLHELP = NO + +# 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 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 + +# 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 + +# If the GENERATE_TREEVIEW tag 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 and frames is required (for instance Netscape 4.0+ +# or Internet explorer 4.0+). + +GENERATE_TREEVIEW = 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 + +#--------------------------------------------------------------------------- +# 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 = + +# 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 = NO + +# 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 = NO + +# 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 + +#--------------------------------------------------------------------------- +# 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 optimised 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 = + +# 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 assigments. 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 = + +# The MAN_EXTENSION tag determines the extension that is added to +# the generated man pages (default is the subroutine's section .3) + +MAN_EXTENSION = + +# 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. Note that this +# feature is still experimental and incomplete at the +# moment. + +GENERATE_XML = NO + +#--------------------------------------------------------------------------- +# 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 = YES + +# 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_PREDEFINED tags. + +EXPAND_ONLY_PREDEF = YES + +# 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. + +PREDEFINED = Q_PROPERTY()= + +# If the MACRO_EXPANSION and EXPAND_PREDEF_ONLY 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 = + +#--------------------------------------------------------------------------- +# Configuration::addtions related to external references +#--------------------------------------------------------------------------- + +# The TAGFILES tag can be used to specify one or more tagfiles. + +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 + +# The PERL_PATH should be the absolute path and name of the perl script +# interpreter (i.e. the result of `which perl'). + +PERL_PATH = + +#--------------------------------------------------------------------------- +# Configuration options related to the dot tool +#--------------------------------------------------------------------------- + +# 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 = NO + +# 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 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 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 + +# 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 on the path. + +DOT_PATH = + +# The MAX_DOT_GRAPH_WIDTH tag can be used to set the maximum allowed width +# (in pixels) of the graphs generated by dot. If a graph becomes larger than +# this value, doxygen will try to truncate the graph, so that it fits within +# the specified constraint. Beware that most browsers cannot cope with very +# large images. + +MAX_DOT_GRAPH_WIDTH = 1024 + +# The MAX_DOT_GRAPH_HEIGHT tag can be used to set the maximum allows height +# (in pixels) of the graphs generated by dot. If a graph becomes larger than +# this value, doxygen will try to truncate the graph, so that it fits within +# the specified constraint. Beware that most browsers cannot cope with very +# large images. + +MAX_DOT_GRAPH_HEIGHT = 1024 + +# 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 intermedate dot files that are used to generate +# the various graphs. + +DOT_CLEANUP = YES + +#--------------------------------------------------------------------------- +# Configuration::addtions related to the search engine +#--------------------------------------------------------------------------- + +# The SEARCHENGINE tag specifies whether or not a search engine should be +# used. If set to NO the values of all tags below this one will be ignored. + +SEARCHENGINE = NO + +# The CGI_NAME tag should be the name of the CGI script that +# starts the search engine (doxysearch) with the correct parameters. +# A script with this name will be generated by doxygen. + +CGI_NAME = + +# The CGI_URL tag should be the absolute URL to the directory where the +# cgi binaries are located. See the documentation of your http daemon for +# details. + +CGI_URL = + +# The DOC_URL tag should be the absolute URL to the directory where the +# documentation is located. If left blank the absolute path to the +# documentation, with file:// prepended to it, will be used. + +DOC_URL = + +# The DOC_ABSPATH tag should be the absolute path to the directory where the +# documentation is located. If left blank the directory on the local machine +# will be used. + +DOC_ABSPATH = + +# The BIN_ABSPATH tag must point to the directory where the doxysearch binary +# is installed. + +BIN_ABSPATH = + +# The EXT_DOC_PATHS tag can be used to specify one or more paths to +# documentation generated for other projects. This allows doxysearch to search +# the documentation for these projects as well. + +EXT_DOC_PATHS = diff --git a/kjsembed/Makefile.am b/kjsembed/Makefile.am new file mode 100644 index 00000000..d64849c6 --- /dev/null +++ b/kjsembed/Makefile.am @@ -0,0 +1,88 @@ +# -*- makefile -*- +AM_CXXFLAGS = -frtti + +# Make sure the include path includes Qt's uilib +INCLUDES = -I$(QTDIR)/tools/designer/uilib -I$(srcdir)/.. $(all_includes) + +INCLUDES += -DQT_CLEAN_NAMESPACE -DQT_NO_ASCII_CAST + +SUBDIRS = bindings builtins qtbindings . plugin plugins kscript stdlib cpptests docs + +lib_LTLIBRARIES = libkjsembed.la +bin_PROGRAMS = kjscmd + +libkjsembed_la_METASOURCES = AUTO +libkjsembed_la_SOURCES = jsconsolewidget.cpp kjsembedpart.cpp jsobjectproxy.cpp \ + slotutils.cpp jsproxy.cpp slotproxy.cpp jsbinding.cpp jssecuritypolicy.cpp \ + xmlactionclient.cpp jsfactory.cpp kjsembedpart_imp.cpp jsobjectproxy_imp.cpp \ + customobject_imp.cpp jsvalueproxy_imp.cpp jsvalueproxy.cpp jsobjecteventproxy.cpp \ + jseventmapper.cpp jsbuiltin.cpp jsproxy_imp.cpp jsfactory_imp.cpp jsbuiltin_imp.cpp \ + jsopaqueproxy.cpp jsopaqueproxy_imp.cpp jseventutils.cpp jsbindingplugin.cpp \ + ksimpleprocess.cpp global.cpp jsbuiltinproxy.cpp + +kjsembedincludedir = $(includedir)/kjsembed +kjsembedinclude_HEADERS = jsconsolewidget.h \ + kjsembedpart.h \ + jsobjectproxy.h \ + slotutils.h \ + jsproxy.h \ + slotproxy.h \ + jsbinding.h \ + jssecuritypolicy.h \ + xmlactionclient.h \ + jsfactory.h \ + kjsembedpart_imp.h \ + jsobjectproxy_imp.h \ + customobject_imp.h \ + jsvalueproxy_imp.h \ + jsvalueproxy.h \ + jsobjecteventproxy.h \ + jseventmapper.h \ + jsbuiltin.h \ + jsproxy_imp.h \ + jsfactory_imp.h \ + jsbuiltin_imp.h \ + jsopaqueproxy.h \ + jsopaqueproxy_imp.h \ + jseventutils.h \ + jsbindingplugin.h \ + global.h + +libkjsembed_la_LDFLAGS = -no-undefined -version-info 1:0 $(all_libraries) $(KDE_RPATH) + +libkjsembed_la_LIBADD = bindings/libkjsembedbindings.la \ + builtins/libkjsembedbuiltins.la \ + qtbindings/libkjsembedqtbindings.la \ + -lqui \ + $(LIB_QT) $(LIB_KDECORE) $(LIB_KDEUI) $(LIB_KPARTS) \ + $(LIB_KFILE) $(LIB_KHTML) -lkjs $(LIBSOCKET) + +kjscmd_SOURCES = kjscmd.cpp +kjscmd_LDFLAGS = $(all_libraries) $(KDE_RPATH) +kjscmd_LDADD = libkjsembed.la + +man_MANS = kjscmd.1 + +xdg_apps_DATA = kjscmd.desktop + +plugintypedir = $(kde_servicetypesdir) +plugintype_DATA = binding_type.desktop + +changes: + cvs2cl --ignore 'ChangeLog' \ + --prune --day-of-week \ + --hide-filenames --no-wrap \ + --stdout | grep -v 'CCMAIL' > docs/ChangeLog + +srcdoc: + $(kde_bindir)/kdoc -a -p -d classdocs -n 'KJSEmbed' *.h -lqt -lkdecore -lkdeui + +srcdox: + doxygen -u Doxyfile + +tidytildes: + rm -f *~ + + + +noinst_HEADERS = jsbindingbase.h diff --git a/kjsembed/README b/kjsembed/README new file mode 100644 index 00000000..aa0ca684 --- /dev/null +++ b/kjsembed/README @@ -0,0 +1,48 @@ +WARNING: +------- +This library does not keep source or binary compatibility. Unless every one +of your users compiles from source and recompiles after upgrading kjsembed, +you should be making a complete copy of this code in your app and using that +instead of the installed version. +----------------------------------------------------------------------------- + + +A library for embedding the KJS Javascript interpreter in application. + +- A tutorial is under development, see http://xmelegance.org/kjsembed/ + or take a look in the docs directory. + +- For information on using the library run kdoc over the header files. + + +Here is an example interactive session with the test application, all +lines beginning with 'kjs>' show the commands typed. + +-- Enter a JS expression and press enter -- +kjs> 10+20 +30 +kjs> print("Hello World!") +Hello World! +undefined +kjs> Math.sin(0) +0 +kjs> Math.cos(0) +1 +kjs> console +JSConsoleWidget (KJSEmbed::JSConsoleWidget) +kjs> console.childCount() +4 +kjs> console.child(1) +CmdEdit (QComboBox) +kjs> console.child(2) +RunButton (QPushButton) +kjs> console.child("RunButton") +RunButton (QPushButton) +kjs> console.child("RunButton").text = "Go!" +Go! +kjs> console.caption = "Different Title" +Different Title + + +Copyright (C) 2001-2003, Richard J. Moore <rich@kde.org> + diff --git a/kjsembed/TODO b/kjsembed/TODO new file mode 100644 index 00000000..54fb9edf --- /dev/null +++ b/kjsembed/TODO @@ -0,0 +1 @@ +This file has moved into the docs directory. diff --git a/kjsembed/binding_type.desktop b/kjsembed/binding_type.desktop new file mode 100644 index 00000000..0b8d0ca3 --- /dev/null +++ b/kjsembed/binding_type.desktop @@ -0,0 +1,3 @@ +[Desktop Entry] +Type=ServiceType +X-KDE-ServiceType=JSBindingPlugin/Binding diff --git a/kjsembed/bindings/Makefile.am b/kjsembed/bindings/Makefile.am new file mode 100644 index 00000000..95b634bd --- /dev/null +++ b/kjsembed/bindings/Makefile.am @@ -0,0 +1,29 @@ + +INCLUDES= -I$(srcdir)/.. -I$(srcdir)/../.. $(all_includes) +KDE_CXXFLAGS = -DQT_NO_ASCII_CAST -DQT_CLEAN_NAMESPACE -Wno-unused + +noinst_LTLIBRARIES = libkjsembedbindings.la + +libkjsembedbindings_la_SOURCES = image_imp.cpp \ + dcop_imp.cpp \ + painter_imp.cpp \ + pixmap_imp.cpp \ + netaccess_imp.cpp \ + kconfig_imp.cpp \ + bindingobject.cpp \ + movie_imp.cpp \ + sql_imp.cpp \ + pen_imp.cpp \ + brush_imp.cpp \ + iconset_imp.cpp \ + point_imp.cpp \ + rect_imp.cpp \ + size_imp.cpp + +libkjsembedbindings_la_LDFLAGS = $(all_libraries) $(KDE_RPATH) +libkjsembedbindings_la_LIBADD = $(LIB_QT) $(LIB_KDECORE) $(LIB_KDEUI) $(LIB_KPARTS) \ + $(LIB_KFILE) $(LIBSOCKET) + +libkjsembedbindings_la_METASOURCES = AUTO + + diff --git a/kjsembed/bindings/bindingobject.cpp b/kjsembed/bindings/bindingobject.cpp new file mode 100644 index 00000000..4477c336 --- /dev/null +++ b/kjsembed/bindings/bindingobject.cpp @@ -0,0 +1,18 @@ +#include "bindingobject.h" +#ifndef QT_ONLY +#include "bindingobject.moc" +#endif +namespace KJSEmbed { +namespace Bindings { + +BindingObject::BindingObject( QObject *parent, const char *name ) + : QObject( parent, name ) +{ +} + +BindingObject::~BindingObject() +{ +} + +} +} diff --git a/kjsembed/bindings/bindingobject.h b/kjsembed/bindings/bindingobject.h new file mode 100644 index 00000000..1516ade2 --- /dev/null +++ b/kjsembed/bindings/bindingobject.h @@ -0,0 +1,61 @@ +// -*- c++ -*- + +/* + * Copyright (C) 2003, Richard J. Moore <rich@kde.org> + * + * This 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. + * + * This 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 this library; see the file COPYING.LIB. If not, write to + * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, + * Boston, MA 02110-1301, USA. + */ + +#ifndef KJSEMBED_BINDING_OBJECT_H +#define KJSEMBED_BINDING_OBJECT_H + +#include <qobject.h> + +namespace KJSEmbed { +namespace Bindings { + +/** + * A baseclass for QObject bindings. This class is currently just a + * stub, but I hope it will contain utilities for QObject wrapper + * classes. + * + * @author Richard Moore, rich@kde.org + * @version $Id$ + */ +class BindingObject : public QObject +{ + Q_OBJECT + +public: + BindingObject( QObject *parent, const char *name=0 ); + virtual ~BindingObject(); + + const char *jsClassName() const { return jsClazz; } + +protected: + void setJSClassName( const char *clazz ) { jsClazz = clazz; } + +private: + QCString jsClazz; + class BindingObjectPrivate *d; +}; + +} +} + +#endif // KJSEMBED_BINDING_OBJECT_H + + diff --git a/kjsembed/bindings/bindings.pro b/kjsembed/bindings/bindings.pro new file mode 100644 index 00000000..d83d3ba5 --- /dev/null +++ b/kjsembed/bindings/bindings.pro @@ -0,0 +1,35 @@ +include(../qjsembed.pri) + +INCLUDEPATH += .. . ../.. +CONFIG += staticlib +TEMPLATE = lib + + +# Input +HEADERS += bindingobject.h \ + brush_imp.h \ + iconset_imp.h \ + image_imp.h \ + movie_imp.h \ + painter_imp.h \ + pen_imp.h \ + pixmap_imp.h \ + sql_imp.h \ + kconfig_imp.h \ + point_imp.h \ + rect_imp.h \ + size_imp.h + +SOURCES += bindingobject.cpp \ + brush_imp.cpp \ + iconset_imp.cpp \ + image_imp.cpp \ + movie_imp.cpp \ + painter_imp.cpp \ + pen_imp.cpp \ + pixmap_imp.cpp \ + sql_imp.cpp \ + kconfig_imp.cpp \ + point_imp.cpp \ + rect_imp.cpp \ + size_imp.cpp diff --git a/kjsembed/bindings/brush_imp.cpp b/kjsembed/bindings/brush_imp.cpp new file mode 100644 index 00000000..061dc1f4 --- /dev/null +++ b/kjsembed/bindings/brush_imp.cpp @@ -0,0 +1,121 @@ +// -*- c++ -*- + +/* + * Copyright (C) 2003, Ian Reinhart Geiser <geiseri@kde.org> + * + * This 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. + * + * This 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 this library; see the file COPYING.LIB. If not, write to + * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, + * Boston, MA 02110-1301, USA. + */ + +#include <kjsembed/global.h> +#include <kjsembed/jsvalueproxy.h> +#include <kjsembed/jsbinding.h> +#include <qvariant.h> +#include <qbrush.h> + +#include "brush_imp.h" + +namespace KJSEmbed { +namespace Bindings { + +BrushImp::BrushImp( KJS::ExecState *exec, int id ) + : JSProxyImp(exec), mid(id) +{ +} + +BrushImp::~BrushImp() +{ +} + +void BrushImp::addBindings( KJS::ExecState *exec, KJS::Object &object ) { + + if( !JSProxy::checkType(object, JSProxy::ValueProxy, "QBrush") ) return; + + JSProxy::MethodTable methods[] = { + { Methodstyle, "style"}, + { MethodsetStyle, "setStyle"}, + { MethodColor, "color"}, + { MethodsetColor, "setColor"}, + { 0, 0 } + }; + + JSProxy::addMethods<BrushImp>(exec, methods, object ); + + JSProxy::EnumTable enums[] = { + // BrushType + { "NoBrush", 0 }, + { "SolidBrush", 1 }, + { "Dense1Pattern", 2 }, + { "Dense2Pattern", 3 }, + { "Dense3Pattern", 4 }, + { "Dense4Pattern", 5 }, + { "Dense5Pattern", 6 }, + { "Dense6Pattern", 7 }, + { "Dense7Pattern", 8 }, + { "HorPattern", 9 }, + { "VerPattern", 10 }, + { "CrossPattern", 11}, + { "BDiagPattern", 12 }, + { "FDiagPattern", 13 }, + { "DiagCrossPattern", 14}, + + { 0, 0 } + }; + + JSProxy::addEnums(exec, enums, object); + +} + +KJS::Value BrushImp::call( KJS::ExecState *exec, KJS::Object &self, const KJS::List &args ) { + + if( !JSProxy::checkType(self, JSProxy::ValueProxy, "QBrush") ) return KJS::Value(); + JSValueProxy *op = JSProxy::toValueProxy( self.imp() ); + QBrush brush = op->toVariant().toBrush(); + + KJS::Value retValue = KJS::Value(); + switch ( mid ) { + case Methodstyle: + { + return KJS::Number((int) brush.style() ); + break; + } + case MethodsetStyle: + { + int style = extractInt(exec, args, 0); + brush.setStyle((Qt::BrushStyle)style); + break; + } + case MethodColor: + { + return convertToValue(exec, brush.color()); + break; + } + case MethodsetColor: + { + QColor color = extractQColor(exec, args, 0); + brush.setColor(color); + break; + } + default: + kdWarning() << "Brush has no method " << mid << endl; + break; + } + + op->setValue(brush); + return retValue; +} + +} // namespace KJSEmbed::Bindings +} // namespace KJSEmbed diff --git a/kjsembed/bindings/brush_imp.h b/kjsembed/bindings/brush_imp.h new file mode 100644 index 00000000..040c73b6 --- /dev/null +++ b/kjsembed/bindings/brush_imp.h @@ -0,0 +1,57 @@ +// -*- c++ -*- + +/* + * Copyright (C) 2003, Richard J. Moore <rich@kde.org> + * + * This 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. + * + * This 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 this library; see the file COPYING.LIB. If not, write to + * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, + * Boston, MA 02110-1301, USA. + */ + +#ifndef KJSEMBED_BRUSH_PLUGIN_H +#define KJSEMBED_BRUSH_PLUGIN_H + +#include <kjsembed/jsproxy_imp.h> + +namespace KJSEmbed { +namespace Bindings { + +class BrushImp : public JSProxyImp { + + /** Identifiers for the methods provided by this class. */ + enum MethodId { Methodstyle, MethodsetStyle, MethodColor, MethodsetColor }; + +public: + BrushImp( KJS::ExecState *exec, int id ); + virtual ~BrushImp(); + + static void addBindings( KJS::ExecState *exec, KJS::Object &object ); + + /** Returns true iff this object implements the call function. */ + virtual bool implementsCall() const { + return true; + } + + /** Invokes the call function. */ + virtual KJS::Value call( KJS::ExecState *exec, KJS::Object &self, const KJS::List &args ); + + +private: + int mid; +}; + +} // namespace +} // namespace + +#endif // KJSEMBED_IMAGE_IMP_H diff --git a/kjsembed/bindings/dcop_imp.cpp b/kjsembed/bindings/dcop_imp.cpp new file mode 100644 index 00000000..caa47313 --- /dev/null +++ b/kjsembed/bindings/dcop_imp.cpp @@ -0,0 +1,1020 @@ +// $Id$ +// -*- c++ -*- + +/* + * Copyright (C) 2003, Ian Reinhart Geiser <geiseri@kde.org> + * + * This 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. + * + * This 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 this library; see the file COPYING.LIB. If not, write to + * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, + * Boston, MA 02110-1301, USA. + */ +#include <kapplication.h> +#include <dcopref.h> +#include <dcopclient.h> +#include <kdebug.h> +#include <qregexp.h> + +#include "dcop_imp.h" +#include "dcop_imp.moc" + +#include <kdatastream.h> +#include <kurl.h> +#include <qvariant.h> +#include <qstring.h> +#include <qmap.h> +#include <qfont.h> +#include <qpixmap.h> +#include <qbrush.h> +#include <qrect.h> +#include <qsize.h> +#include <qcolor.h> +#include <qimage.h> +#include <qpoint.h> +#include <qvaluelist.h> +#include <qiconset.h> +#include <qpointarray.h> +#include <qbitmap.h> +#include <qcursor.h> +#include <qdatetime.h> +#include <qmemarray.h> +#include <qkeysequence.h> +#include <qbitarray.h> + +#include <kjs/interpreter.h> +#include <kjs/identifier.h> +#include <kjs/types.h> +#include <kjs/ustring.h> +#include <kjs/value.h> + +#include "../jsbinding.h" +#include <kjsembed/jsopaqueproxy.h> +#include <kjsembed/jsobjectproxy.h> +#include <kjsembed/kjsembedpart.h> +namespace KJSEmbed { +namespace Bindings { +KJS::Object JSDCOPRefLoader::createBinding(KJSEmbedPart *jspart, KJS::ExecState *exec, const KJS::List &args) const +{ + QString application = extractQString(exec, args, 0); + QString object = extractQString(exec, args, 1); + JSOpaqueProxy * prx; + if( application.isEmpty() ) + prx= new JSOpaqueProxy( new DCOPRef(), "DCOPRef" ); + else + prx= new JSOpaqueProxy( new DCOPRef(application.latin1(),object.latin1()), "DCOPRef" ); + + KJS::Object proxyObj( prx ); + prx->setOwner( JSProxy::JavaScript ); + addBindings(jspart,exec,proxyObj); + return proxyObj; +} + +void JSDCOPRefLoader::addBindings( KJSEmbedPart *jspart, KJS::ExecState *exec, KJS::Object &proxy ) const +{ + JSDCOPRef::addBindings( exec, proxy ); +} + +JSDCOPRef::JSDCOPRef(KJS::ExecState *exec, int id) + : JSProxyImp(exec), mid(id) +{ +} + +JSDCOPRef::~JSDCOPRef() +{ +} + +void JSDCOPRef::addBindings( KJS::ExecState *exec, KJS::Object &object ) +{ + JSOpaqueProxy *op = JSProxy::toOpaqueProxy( object.imp() ); + if ( !op ) { + kdWarning() << "JSDCOPRef::addBindings() failed, not a JSOpaqueProxy" << endl; + return; + } + + if ( op->typeName() != "DCOPRef" ) { + kdWarning() << "JSDCOPRef::addBindings() failed, type is " << op->typeName() << endl; + return; + } + + DCOPRef *ref = op->toNative<DCOPRef>(); + + JSProxy::MethodTable methods[] = { + { Methodcall, "call"}, + { Methodsend, "send" }, + { Methodapp, "app" }, + { Methodobj, "obj" }, + { Methodtype, "type" }, + { MethodsetRef, "setRef" }, + { 0, 0 } + }; + + int idx = 0; + do { + JSDCOPRef *meth = new JSDCOPRef( exec, methods[idx].id ); + object.put( exec, methods[idx].name, KJS::Object(meth) ); + ++idx; + } while( methods[idx].id ); + +} + +KJS::Value JSDCOPRef::call( KJS::ExecState *exec, KJS::Object &self, const KJS::List &args ) { + + + JSOpaqueProxy *op = JSProxy::toOpaqueProxy( self.imp() ); + if ( !op ) { + kdWarning() << "JSDCOPRef::call() failed, not a JSOpaqueProxy" << endl; + return KJS::Boolean(false); + } + + if ( op->typeName() != "DCOPRef" ) { + kdWarning() << "JSDCOPRef::call() failed, type is " << op->typeName() << endl; + return KJS::Boolean(false); + } + DCOPRef *ref = op->toNative<DCOPRef>(); + kdDebug() << "Ref valid" << ref << endl; + if( !ref ) + { + kdWarning() << "Ref invalid" << ref << endl; + return KJS::Null(); + } + kdDebug() << "DCOPRef call. " << mid << endl; + KJS::Value retValue = KJS::Value(); + switch ( mid ) { + case Methodcall: + { + if ( args.size() < 1 ) + { + kdWarning() << "Not enough args..." << endl; + return KJS::Boolean(false); + } + QByteArray data, replyData; + QDataStream ds( replyData, IO_ReadOnly); + QCString type; + + QString app = ref->app(); + QString interface = ref->obj(); + QString function = extractQString(exec, args, 0); + QStringList argTypes = JSDCOPClient::getTypes( function ); + + if( args.size() > 1) + for( int idx = 1; idx < args.size(); ++idx) + { + JSDCOPClient::marshall(convertToVariant(exec,args[idx] ), argTypes[idx - 1], data); + } + if( !kapp->dcopClient()->call(app.local8Bit(), interface.local8Bit(), function.local8Bit(), data, type, replyData)) + retValue = KJS::Boolean(false); + else + retValue = JSDCOPClient::demarshall(exec, type, ds); + break; + } + case Methodsend: + { + if ( args.size() < 1 ) + return KJS::Boolean(false); + + QByteArray data; + QString app = ref->app(); + QString interface = ref->obj(); + QString function = extractQString(exec, args, 0); + + QStringList argTypes = JSDCOPClient::getTypes( function ); + + if( args.size() > 1) + for( int idx = 1; idx < args.size(); ++idx) + { + JSDCOPClient::marshall(convertToVariant(exec,args[idx] ), argTypes[idx - 1], data); + } + retValue = KJS::Boolean( kapp->dcopClient()->send(app.local8Bit(), interface.local8Bit(), + function.local8Bit(), data)); + break; + } + case Methodapp: + { + retValue = convertToValue( exec, ref->app() ); + break; + } + case Methodobj: + { + retValue = convertToValue( exec, ref->obj() ); + break; + } + case Methodtype: + { + retValue = convertToValue( exec, ref->type() ); + break; + } + case MethodsetRef: + { + QString arg0 = extractQString(exec, args, 0); + QString arg1 = extractQString(exec, args, 1); + QString arg2 = extractQString(exec, args, 0); + ref->setRef(arg0.latin1(), arg1.latin1(), arg2.latin1() ); + break; + } + default: + { + kdWarning() << "JSDCOPClient has no method " << mid << endl; + break; + } + } + op->setValue( ref, "DCOPRef" ); + return retValue; +} + +KJS::Object JSDCOPClientLoader::createBinding(KJSEmbedPart *jspart, KJS::ExecState *exec, const KJS::List &/*args*/) const +{ + JSOpaqueProxy * prx = new JSOpaqueProxy( kapp->dcopClient(), "DCOPClient" ); + prx->setOwner( JSProxy::Native ); + KJS::Object proxyObj( prx ); + addBindings( jspart, exec, proxyObj ); + return proxyObj; +} + +void JSDCOPClientLoader::addBindings( KJSEmbedPart *jspart, KJS::ExecState *exec, KJS::Object &proxy ) const +{ + JSDCOPClient::addBindings( exec, proxy ); +} + +JSDCOPClient::JSDCOPClient( KJS::ExecState *exec, int id ) + : JSProxyImp(exec), mid(id) +{ +} + +JSDCOPClient::~JSDCOPClient() +{ +} + + +void JSDCOPClient::addBindings( KJS::ExecState *exec, KJS::Object &object ) +{ + if( !JSProxy::checkType(object, JSProxy::OpaqueProxy, "DCOPClient") ) return; + + JSProxy::MethodTable methods[] = { + { Methodattach, "attach"}, + { Methoddetach, "detach"}, + { MethodisAttached, "isAttached" }, + { MethodregisteredApplications, "registeredApplications" }, + { MethodremoteObjects, "remoteObjects" }, + { MethodremoteInterfaces, "remoteInterfaces" }, + { MethodremoteFunctions, "remoteFunctions" }, + { MethodconnectDCOPSignal, "connectDCOPSignal" }, + { MethoddisconnectDCOPSignal, "disconnectDCOPSignal"}, + { Methodcall, "call"}, + { Methodsend, "send"}, + { MethodDCOPStart, "dcopStart"}, + { MethodappId, "appId"}, + { MethodisApplicationRegistered, "isApplicationRegistered" }, + { 0, 0 } + }; + + JSProxy::addMethods<JSDCOPClient>(exec, methods, object ); +} + +KJS::Value JSDCOPClient::call( KJS::ExecState *exec, KJS::Object &self, const KJS::List &args ) { + if( !JSProxy::checkType(self, JSProxy::OpaqueProxy, "DCOPClient") ) return KJS::Value(); + + JSOpaqueProxy *op = JSProxy::toOpaqueProxy( self.imp() ); + + KJS::Value retValue = KJS::Value(); + switch ( mid ) { + case Methodattach: { + retValue = KJS::Boolean(attach( )); + break; + } + case Methoddetach: { + retValue = KJS::Boolean(detach( )); + break; + } + case MethodisAttached: { + retValue = KJS::Boolean(isAttached( )); + break; + } + case MethodregisteredApplications: { + retValue = convertToValue(exec, registeredApplications()); + break; + } + case MethodremoteObjects: { + QString arg0 = extractQString(exec, args, 0); + retValue = convertToValue( exec, remoteObjects(arg0)); + break; + } + case MethodremoteInterfaces: { + QString arg0 = extractQString(exec, args, 0); + QString arg1 = extractQString(exec, args, 1); + this->remoteInterfaces(arg0, arg1); + break; + } + case MethodremoteFunctions: { + QString arg0 = extractQString(exec, args, 0); + QString arg1 = extractQString(exec, args, 1); + remoteFunctions(arg0, arg1); + break; + } + case MethodconnectDCOPSignal: { + QString arg0 = extractQString(exec, args, 0); + QString arg1 = extractQString(exec, args, 1); + QString arg2 = extractQString(exec, args, 2); + QString arg3 = extractQString(exec, args, 3); + QString arg4 = extractQString(exec, args, 4); + bool arg5 = (args.size() > 5) ? args[5].toBoolean(exec) : false; + connectDCOPSignal( arg0, arg1, arg2, arg3, arg4, arg5); + break; + } + case MethoddisconnectDCOPSignal: { + QString arg0 = extractQString(exec, args, 0); + QString arg1 = extractQString(exec, args, 1); + QString arg2 = extractQString(exec, args, 2); + QString arg3 = extractQString(exec, args, 3); + QString arg4 = extractQString(exec, args, 4); + disconnectDCOPSignal(arg0, arg1, arg2, arg3, arg4); + break; + } + case MethodDCOPStart: { + QString arg0 = extractQString(exec, args, 0); + + retValue = KJS::String( dcopStart( arg0, QStringList() ) ); + break; + } + case MethodappId: + retValue = KJS::String( kapp->dcopClient()->appId().data() ); + break; + case MethodisApplicationRegistered: { + QString arg0 = extractQString(exec, args, 0); + retValue = KJS::Boolean( kapp->dcopClient()->isApplicationRegistered( arg0.latin1() ) ); + break; + } + case Methodsend: + return dcopSend( exec, self, args ); + break; + case Methodcall: + return dcopCall( exec, self, args ); + break; + default: + kdWarning() << "JSDCOPClient has no method " << mid << endl; + break; + } + return retValue; +} + +bool JSDCOPClient::attach() const +{ + if( !kapp->dcopClient()->isAttached() ) + return kapp->dcopClient()->attach(); + return true; +} +bool JSDCOPClient::detach() const +{ return kapp->dcopClient()->detach(); + +} + +bool JSDCOPClient::isAttached() const +{ + return kapp->dcopClient()->isAttached(); +} + +KJS::Value JSDCOPClient::dcopCall( KJS::ExecState * exec, KJS::Object &, const KJS::List & args ) +{ + if ( args.size() < 3 ) + return KJS::Boolean(false); + + QStringList types; + QByteArray data, replyData; + QDataStream ds( replyData, IO_ReadOnly); + QCString type; + + QString app = extractQString(exec, args, 0); + QString interface = extractQString(exec, args, 1); + QString function = extractQString(exec, args, 2); + QStringList argTypes = getTypes( function ); + + if( args.size() > 3) + for( int idx = 3; idx < args.size(); ++idx) + { + QVariant var = convertToVariant(exec,args[idx] ); + marshall(var, argTypes[idx -3 ], data); + } + if( !kapp->dcopClient()->call(app.local8Bit(), interface.local8Bit(), function.local8Bit(), data, type, replyData)) + return KJS::Boolean(false); + else + return demarshall(exec, type, ds); +} + +KJS::Value JSDCOPClient::dcopSend( KJS::ExecState * exec, KJS::Object &, const KJS::List & args ) +{ + if ( args.size() < 3 ) + return KJS::Boolean(false); + + QByteArray data; + QString app = extractQString(exec, args, 0); + QString interface = extractQString(exec, args, 1); + QString function = extractQString(exec, args, 2); + QStringList argTypes = getTypes( function ); + + if( args.size() > 3) + for( int idx = 3; idx < args.size(); ++idx) + { + QVariant var = convertToVariant(exec,args[idx] ); + marshall(var, argTypes[idx - 3], data); + } + return KJS::Boolean( kapp->dcopClient()->send(app.local8Bit(), interface.local8Bit(), + function.local8Bit(), data)); +} + +KJS::Value JSDCOPClient::demarshall( KJS::ExecState * exec, const QCString& type, QDataStream& data) +{ + kdDebug() << "Demarshall " << type << endl; + + if( type == "DCOPRef" ) + { + DCOPRef *ref = new DCOPRef(); + data >> *ref; + JSOpaqueProxy *prx = new JSOpaqueProxy(ref, "DCOPRef" ); + + KJS::Object proxyObj(prx); + kdDebug() << "DCOPRef " << ref->app() << endl; + Bindings::JSDCOPRef::addBindings( exec, proxyObj ); + return proxyObj; + } + else + return convertToValue(exec, demarshall(type, data)); +} + +QStringList JSDCOPClient::getTypes( const QString& function ) +{ + QCString myFunction = DCOPClient::normalizeFunctionSignature (function.latin1()); + QString args = myFunction.mid( myFunction.find('(') + 1 ); + args = args.left( args.length() - 1); + return QStringList::split(',', args); +} + +void JSDCOPClient::marshall( const QVariant& data, const QString& typeName, QByteArray& buffer ) +{ + QDataStream stream(buffer, IO_WriteOnly | IO_Append); + + if ( typeName == "QString" ) + { + stream << data.toString(); + } + else if ( typeName == "QCString") + { + stream << data.toCString(); + } + else if ( typeName == "int") + { + stream << data.toInt(); + } + else if ( typeName == "uint") + { + stream << data.toUInt(); + } + else if ( typeName == "bool") + { + stream << data.toBool(); + } + else if ( typeName == "double") + { + stream << data.toDouble(); + } + else if ( typeName == "QMap" ) + { + stream << data.toMap(); + } + else if ( typeName == "QValueList") + { + stream << data.toList(); + } + else if ( typeName == "QFont") + { + stream << data.toFont(); + } + else if ( typeName == "QPixmap") + { + stream << data.toPixmap(); + } + else if ( typeName == "QBrush") + { + stream << data.toBrush(); + } + else if ( typeName == "QRect") + { + stream << data.toRect(); + } + else if ( typeName == "QSize") + { + stream << data.toSize(); + } + else if ( typeName == "QColor") + { + stream << data.toColor(); + } + else if ( typeName == "QPalette") + { + stream << data.toPalette(); + } + else if ( typeName == "QColorGroup") + { + stream << data.toColorGroup(); + } + /*else if ( typeName == "QIconSet") + { + stream << data.toIconSet(); + }*/ + else if ( typeName == "QPoint") + { + stream << data.toPoint(); + } + else if ( typeName == "QImage") + { + stream << data.toImage(); + } + else if ( typeName == "QPointArray") + { + stream << data.toPointArray(); + } + else if ( typeName == "QRegion") + { + stream << data.toRegion(); + } + else if ( typeName == "QBitmap") + { + stream << data.toBitmap(); + } + else if ( typeName == "QCursor") + { + stream << data.toCursor(); + } + /*else if ( typeName == "QSizePolicy") + { + stream << data.toSizePolicy(); + }*/ + else if ( typeName == "QDate") + { + stream << data.toDate(); + } + else if ( typeName == "QTime") + { + stream << data.toTime(); + } + else if ( typeName == "QDateTime") + { + stream << data.toDateTime(); + } + else if ( typeName == "QByteArray") + { + stream << data.toByteArray(); + } + else if ( typeName == "QBitArray") + { + stream << data.toBitArray(); + } + else if ( typeName == "QKeySequence") + { + stream << data.toKeySequence(); + } + else if ( typeName == "KURL" ) + { + KURL url = data.toString(); + stream << url; + } + else + stream << 0; + +} + +QString JSDCOPClient::dcopStart( const QString &appName, const QStringList& args ) +{ + QString error; + QString startFunction; + if (appName.endsWith(".desktop")) + startFunction = "start_service_by_desktop_path(QString,QStringList)"; + else + startFunction = "start_service_by_desktop_name(QString,QStringList)"; + + QByteArray data, replyData; + QCString replyType; + QDataStream arg(data, IO_WriteOnly); + arg << appName << args; + + if ( !kapp->dcopClient()->call( "klauncher", "klauncher", startFunction.latin1(), data, replyType, replyData) ) + { + kdWarning() << "Error: Dcop call failed" << endl; + } + else + { + QDataStream reply(replyData, IO_ReadOnly); + + if ( replyType != "serviceResult" ) + { + kdWarning() << "Error: No serviceResult " << endl; + } + else + { + int result; + QCString dcopName; + QString error; + reply >> result >> dcopName >> error; + if (result != 0) + { + kdWarning() << "Error: " << error.local8Bit().data() << endl; + } + else if (!dcopName.isEmpty()) + { + return dcopName; + } + else + kdWarning() << "Error: no app name returned." << endl; + } + } + + return ""; + +} + +QStringList JSDCOPClient::remoteFunctions( const QString & remApp, const QString & remObj ) +{ + QStringList returnList; + QCStringList lst = kapp->dcopClient()->remoteFunctions(remApp.local8Bit(), remObj.local8Bit()); + for(uint idx = 0; idx < lst.count(); ++idx) + returnList += lst[idx]; + return returnList; +} + +QStringList JSDCOPClient::remoteInterfaces( const QString & remApp, const QString & remObj ) +{ + QStringList returnList; + QCStringList lst = kapp->dcopClient()->remoteInterfaces(remApp.local8Bit(), remObj.local8Bit()); + for(uint idx = 0; idx < lst.count(); ++idx) + returnList += lst[idx]; + return returnList; +} + +QStringList JSDCOPClient::remoteObjects( const QString & remApp ) +{ + QStringList returnList; + QCStringList lst = kapp->dcopClient()->remoteObjects(remApp.local8Bit()); + for(uint idx = 0; idx < lst.count(); ++idx) + returnList += lst[idx]; + return returnList; +} + +QStringList JSDCOPClient::registeredApplications( ) +{ + QStringList returnList; + QCStringList lst = kapp->dcopClient()->registeredApplications( ); + for(uint idx = 0; idx < lst.count(); ++idx) + returnList += lst[idx]; + return returnList; +} + +bool JSDCOPClient::connectDCOPSignal (const QString &sender, const QString &senderObj, const QString &signal, const QString &receiverObj, const QString &slot, bool Volatile) +{ + return kapp->dcopClient()->connectDCOPSignal(sender.latin1(), senderObj.latin1(), signal.latin1(), receiverObj.latin1(), slot.latin1(), Volatile); +} + +bool JSDCOPClient::disconnectDCOPSignal (const QString &sender, const QString &senderObj, const QString &signal, const QString &receiverObj, const QString &slot) +{ + return kapp->dcopClient()->disconnectDCOPSignal(sender.latin1(), senderObj.latin1(), signal.latin1(), receiverObj.latin1(), slot.latin1()); +} + +KJS::Object JSDCOPInterfacerLoader::createBinding(KJSEmbedPart *jspart, KJS::ExecState *exec, const KJS::List &args) const +{ + QObject *parent = extractQObject(exec, args, 0); + QString name = extractQString(exec, args, 1); + QObject *obj = new JSDCOPInterface(jspart->interpreter(),parent, name.latin1() ); + JSObjectProxy *prxy = new JSObjectProxy(jspart, obj); + KJS::Object object(prxy); + addBindings(jspart,exec,object); + return object; +} + +void JSDCOPInterfacerLoader::addBindings( KJSEmbedPart *jspart, KJS::ExecState *exec, KJS::Object &proxy ) const +{ + JSObjectProxy *prx = JSProxy::toObjectProxy( proxy.imp() ); + if( prx ) + prx->addBindings( exec, proxy ); +} + +void JSDCOPInterface::publish( const QString & signature ) +{ + if( m_Members.find(signature.latin1() ) == m_Members.end()) + m_Members.append(signature.latin1() ); +} + +JSDCOPInterface::~ JSDCOPInterface( ) +{ +} + +JSDCOPInterface::JSDCOPInterface( KJS::Interpreter *js, QObject * parent, const char * name ) + : BindingObject( parent, name ),DCOPObject(name), m_js(js) +{ + m_Members.clear(); +} + +QCStringList JSDCOPInterface::functionsDynamic( ) +{ + return m_Members; +} + +bool JSDCOPInterface::processDynamic( const QCString & rawFunction, const QByteArray & data, QCString & replyType, QByteArray & replyData ) +{ + bool isOkay = false; + + QRegExp reg = QRegExp("([_\\d\\w]+)(\\()(.*)(\\))"); + reg.search(rawFunction); + + kdDebug() << "Raw function: " << rawFunction << endl; + kdDebug() << "Reply type: " << replyType << endl; + kdDebug() << "Signature: " << reg.cap(1) << endl; + kdDebug() << "Args: " << reg.cap(3) << endl; + + QString signature = reg.cap(1); + + QStringList argStrings = QStringList::split(',', reg.cap(3), false); + kdDebug() << argStrings.count() << " args..." << endl; + + KJS::ExecState *exec = m_js->globalExec(); + KJS::Object obj = m_js->globalObject(); + KJS::Identifier id( KJS::UString( signature.latin1() ) ); + KJS::Object fun = obj.get(exec, id ).toObject( exec ); + KJS::Value retValue; + + + if ( fun.implementsCall() ) + { + QDataStream ds( data, IO_ReadOnly ); + KJS::List args; + for( uint idx = 0; idx < argStrings.count(); ++idx) + { + kdDebug() << "Get arg: " << argStrings[idx] << endl; + args.append( JSDCOPClient::demarshall( exec, argStrings[idx].latin1(), ds)); + } + + retValue = fun.call(exec, obj, args); + + if( exec->hadException() ) + { + kdWarning() << "Got error: " << exec->exception().toString(exec).qstring() << endl; + } + else + { + kdDebug() << "Returned type is a " << retValue.type() << endl; + if( retValue.isA(KJS::UndefinedType) ) + { + replyType = "void"; + isOkay = true; + } + else if( retValue.isA(KJS::ObjectType) ) + { + JSOpaqueProxy *oprx = JSProxy::toOpaqueProxy( retValue.imp() ); + if( oprx ) + { + replyType = "DCOPRef"; + QDataStream refStream( replyData, IO_WriteOnly ); + if( oprx->typeName() == "DCOPRef" ) + { + DCOPRef ref(*oprx->toNative<DCOPRef>()); + refStream << ref; + isOkay = true; + } + } + } + else + { + QVariant returnVariant = convertToVariant(exec, retValue); + JSDCOPClient::marshall(returnVariant,returnVariant.typeName(), replyData); + replyType = returnVariant.typeName(); + isOkay = true; + } + } + } + return isOkay; +} + +QVariant JSDCOPClient::demarshall( const QCString & type, QDataStream & reply ) +{ + kdDebug() << "Type: '" << type << "'"<< endl; + /*if ( type == "QMap" ) // ? dont handle? + { + QMap<QVariant, QVariant> result; + reply >> result; + return QVariant(result); + } + else if ( type == "QValueList") // ? dont handle? + { + QValueList<QVariant> result; + reply >> result; + return QVariant(result); + }else if ( type == "QVariantList") + { + QVariantList result; + reply >> result; + return QVariant(result); + } + else */ + if ( type == "QString") + { + QString result; + reply >> result; + return QVariant(result); + } + else if ( type == "int") + { + int result; + reply >> result; + kdDebug() << "Result: " << result << endl; + return QVariant(result); + } + else if ( type == "uint") + { + uint result; + reply >> result; + return QVariant(result); + } + else if ( type == "bool") + { + bool result; + reply >> result; + return QVariant(result); + } + else if ( type == "double") + { + double result; + reply >> result; + return QVariant(result); + } + else if ( type == "QCString") + { + QCString result; + reply >> result; + return QVariant(result); + } + else if ( type == "QVariant") + { + QVariant result; + reply >> result; + return QVariant(result); + } + else if ( type == "QFont") + { + QFont result; + reply >> result; + return QVariant(result); + } + else if ( type == "QPixmap") + { + QPixmap result; + reply >> result; + return QVariant(result); + } + else if ( type == "QBrush") + { + QBrush result; + reply >> result; + return QVariant(result); + } + else if ( type == "QRect") + { + QRect result; + reply >> result; + return QVariant(result); + } + else if ( type == "QSize") + { + QSize result; + reply >> result; + return QVariant(result); + } + else if ( type == "QColor") + { + QColor result; + reply >> result; + return QVariant(result); + } + else if ( type == "QPalette") + { + QPalette result; + reply >> result; + return QVariant(result); + } + else if ( type == "QColorGroup") + { + QColorGroup result; + reply >> result; + return QVariant(result); + } + /*else if ( type == "QIconSet") + { + QIconSet result; + reply >> result; + return QVariant(result); + }*/ + else if ( type == "QPoint") + { + QPoint result; + reply >> result; + return QVariant(result); + } + else if ( type == "QImage") + { + QImage result; + reply >> result; + return QVariant(result); + } + else if ( type == "QPointArray") + { + QPointArray result; + reply >> result; + return QVariant(result); + } + else if ( type == "QRegion") + { + QRegion result; + reply >> result; + return QVariant(result); + } + else if ( type == "QBitmap") + { + QBitmap result; + reply >> result; + return QVariant(result); + } + else if ( type == "QCursor") + { + QCursor result; + reply >> result; + return QVariant(result); + } + /*else if ( type == "QSizePolicy") + { + QSizePolicy result; + reply >> result; + return QVariant(result); + }*/ + else if ( type == "QDate") + { + QDate result; + reply >> result; + return QVariant(result); + } + else if ( type == "QTime") + { + QTime result; + reply >> result; + return QVariant(result); + } + else if ( type == "QDateTime") + { + QDateTime result; + reply >> result; + return QVariant(result); + } + else if ( type == "QByteArray") + { + QByteArray result; + reply >> result; + return QVariant(result); + } + else if ( type == "QBitArray") + { + QBitArray result; + reply >> result; + return QVariant(result); + } + else if ( type == "QKeySequence") + { + QKeySequence result; + reply >> result; + return QVariant(result); + } + else if ( type == "QStringList") + { + QStringList result; + reply >> result; + return QVariant(result); + } + else if ( type == "QCStringList") + { + QStringList result; + reply >> result; + return QVariant(result); + } + else + return QVariant(); + +} +} // namespace Bindings +} // namespace KJSEmbed + + + + diff --git a/kjsembed/bindings/dcop_imp.h b/kjsembed/bindings/dcop_imp.h new file mode 100644 index 00000000..56466a11 --- /dev/null +++ b/kjsembed/bindings/dcop_imp.h @@ -0,0 +1,152 @@ +// $Id$ +// -*- c++ -*- + +/* + * Copyright (C) 2003, Ian Reinhart Geiser <geiseri@kde.org> + * + * This 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. + * + * This 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 this library; see the file COPYING.LIB. If not, write to + * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, + * Boston, MA 02110-1301, USA. + */ + +#ifndef KJSEMBED_DCOP_IMP_H +#define KJSEMBED_DCOP_IMP_H + +#include "bindingobject.h" +#include <kjsembed/jsobjectproxy_imp.h> +#include <kjsembed/jsbindingbase.h> +#include <dcopobject.h> + +class DCOPClient; +#include <kdatastream.h> +#include <qvariant.h> +#include <qstring.h> + +namespace KJS +{ + class Interpreter; +} + +namespace KJSEmbed { +namespace Bindings { +class JSDCOPInterfacerLoader : public JSBindingBase +{ + public: + KJS::Object createBinding(KJSEmbedPart *jspart, KJS::ExecState *exec, const KJS::List &args) const; + void addBindings( KJSEmbedPart *jspart, KJS::ExecState *exec, KJS::Object &proxy) const; +}; + +/** +* QObject Binding for a DCOP interface +*/ +class JSDCOPInterface : public BindingObject, public DCOPObject +{ + Q_OBJECT + +public: + JSDCOPInterface( KJS::Interpreter *js, QObject *parent, const char *name=0 ); + virtual ~JSDCOPInterface(); + QCStringList functionsDynamic(); + bool processDynamic (const QCString &fun, const QByteArray &data, QCString &replyType, QByteArray &replyData); +public slots: + void publish(const QString& signature); + +private: + QCStringList m_Members; + KJS::Interpreter *m_js; +}; + +class JSDCOPRefLoader : public JSBindingBase +{ + public: + KJS::Object createBinding(KJSEmbedPart *jspart, KJS::ExecState *exec, const KJS::List &args) const; + void addBindings( KJSEmbedPart *jspart, KJS::ExecState *exec, KJS::Object &proxy) const; +}; + +/** + * DCOPRef binding. +*/ +class JSDCOPRef : public JSProxyImp +{ + enum MethodId { Methodcall, Methodsend, Methodapp, Methodobj, Methodtype, MethodsetRef }; + +public: + JSDCOPRef( KJS::ExecState *exec, int id ); + virtual ~JSDCOPRef(); + static void addBindings( KJS::ExecState *exec, KJS::Object &object ); + + /** Returns true iff this object implements the call function. */ + virtual bool implementsCall() const { return true; } + + /** Invokes the call function. */ + virtual KJS::Value call( KJS::ExecState *exec, KJS::Object &self, const KJS::List &args ); + +private: + int mid; + +}; + +class JSDCOPClientLoader : public JSBindingBase +{ + public: + KJS::Object createBinding(KJSEmbedPart *jspart, KJS::ExecState *exec, const KJS::List &args) const; + void addBindings( KJSEmbedPart *jspart, KJS::ExecState *exec, KJS::Object &proxy) const; +}; + +/** + * Binding for DCOPClient. + */ +class JSDCOPClient : public JSProxyImp +{ + enum MethodId { Methodattach, Methoddetach, MethodisAttached, MethodregisteredApplications, MethodremoteObjects, MethodremoteInterfaces, MethodremoteFunctions, MethodconnectDCOPSignal, MethoddisconnectDCOPSignal, Methodcall, Methodsend, MethodDCOPStart, MethodappId, MethodisApplicationRegistered }; + +public: + JSDCOPClient( KJS::ExecState *exec, int id ); + virtual ~JSDCOPClient(); + + static void addBindings( KJS::ExecState *exec, KJS::Object &object ); + + /** Returns true iff this object implements the call function. */ + virtual bool implementsCall() const { return true; } + + /** Invokes the call function. */ + virtual KJS::Value call( KJS::ExecState *exec, KJS::Object &self, const KJS::List &args ); + + static KJS::Value demarshall( KJS::ExecState * exec, const QCString& type, QDataStream& data); + static QVariant demarshall( const QCString &type, QDataStream &ds); + static void marshall( const QVariant& data, const QString &typeName, QByteArray& buffer ); + static QStringList getTypes( const QString& function); + + bool attach() const; + bool detach() const; + + bool isAttached() const; + + QString dcopStart( const QString& appName, const QStringList& args); + QStringList registeredApplications(); + QStringList remoteObjects( const QString& remApp); + QStringList remoteInterfaces( const QString& remApp, const QString& remObj ); + QStringList remoteFunctions( const QString& remApp, const QString& remObj); + bool connectDCOPSignal (const QString &sender, const QString &senderObj, const QString &signal, const QString &receiverObj, const QString &slot, bool Volatile = false); + bool disconnectDCOPSignal (const QString &sender, const QString &senderObj, const QString &signal, const QString &receiverObj, const QString &slot); + KJS::Value dcopCall(KJS::ExecState *exec, KJS::Object &, const KJS::List &args); + KJS::Value dcopSend(KJS::ExecState *exec, KJS::Object &, const KJS::List &args); + private: + int mid; +}; + +} // namespace Bindings +} // namespace KJSEmbed + +#endif // KJSEMBED_TEXTSTREAM_IMP_H diff --git a/kjsembed/bindings/iconset_imp.cpp b/kjsembed/bindings/iconset_imp.cpp new file mode 100644 index 00000000..3575cc94 --- /dev/null +++ b/kjsembed/bindings/iconset_imp.cpp @@ -0,0 +1,167 @@ +// -*- c++ -*- + +/* + * Copyright (C) 2003, Ian Reinhart Geiser <geiseri@kde.org> + * + * This 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. + * + * This 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 this library; see the file COPYING.LIB. If not, write to + * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, + * Boston, MA 02110-1301, USA. + */ + +#include <kjsembed/global.h> +#include <kjsembed/jsvalueproxy.h> +#include <kjsembed/jsbinding.h> +#include <qvariant.h> +#include <qiconset.h> +#include <qpixmap.h> + +#include "iconset_imp.h" + +namespace KJSEmbed { +namespace Bindings { + +IconsetImp::IconsetImp( KJS::ExecState *exec, int id ) + : JSProxyImp(exec), mid(id) +{ +} + +IconsetImp::~IconsetImp() +{ +} + +void IconsetImp::addBindings( KJS::ExecState *exec, KJS::Object &object ) { + + JSValueProxy *op = JSProxy::toValueProxy( object.imp() ); + if ( !op ) { + kdWarning() << "IconsetImp::addBindings() failed, not a JSValueProxy" << endl; + return; + } + + if ( op->typeName() != "QIconset" ) { + kdWarning() << "IconsetImp::addBindings() failed, type is " << op->typeName() << endl; + return; + } + + JSProxy::MethodTable methods[] = { + { MethodReset, "reset"}, + { MethodSetPixmap, "setPixmap"}, + { MethodPixmap, "pixmap"}, + { MethodIsGenerated, "isGenerated"}, + { MethodClearGenerated, "clearGenerated"}, + { MethodIsNull, "isNull"}, + { MethodDetach, "detach"}, + { 0, 0 } + }; + + int idx = 0; + do { + IconsetImp *meth = new IconsetImp( exec, methods[idx].id ); + object.put( exec , methods[idx].name, KJS::Object(meth) ); + ++idx; + } while( methods[idx].id ); + + // + // Define the enum constants + // + struct EnumValue { + const char *id; + int val; + }; + + EnumValue enums[] = { + // Size + { "Automatic", 0 }, + { "Small", 1 }, + { "Large", 2 }, + // Mode + { "Normal", 0 }, + { "Disabled", 1 }, + { "Active", 2 }, + // State + { "On", 0 }, + { "Off", 1 }, + { 0, 0 } + }; + + int enumidx = 0; + do { + object.put( exec, enums[enumidx].id, KJS::Number(enums[enumidx].val), KJS::ReadOnly ); + ++enumidx; + } while( enums[enumidx].id ); +} + +KJS::Value IconsetImp::call( KJS::ExecState *exec, KJS::Object &self, const KJS::List &args ) { + + JSValueProxy *op = JSProxy::toValueProxy( self.imp() ); + if ( !op ) { + kdWarning() << "IconsetImp::call() failed, not a JSValueProxy" << endl; + return KJS::Value(); + } + + if ( op->typeName() != "QIconSet" ) { + kdWarning() << "IconsetImp::call() failed, type is " << op->typeName() << endl; + return KJS::Value(); + } + + QIconSet iconset = op->toVariant().toIconSet(); + + KJS::Value retValue = KJS::Value(); + switch ( mid ) { + case MethodReset: + { + QPixmap pix = extractQPixmap(exec, args, 0); + QIconSet::Size size = (QIconSet::Size) extractInt(exec, args, 1 ); + iconset.reset(pix,size); + break; + } + case MethodSetPixmap: + { + QPixmap pix = extractQPixmap( exec, args, 0); + QString fname = extractQString( exec, args, 0); + QIconSet::Size size = (QIconSet::Size) extractInt(exec, args, 1 ); + QIconSet::Mode mode = (QIconSet::Mode) extractInt( exec, args, 2 ); + QIconSet::State state = (QIconSet::State) extractInt( exec, args, 3); + if( pix.isNull() ) + iconset.setPixmap( fname, size, mode, state ); + else + iconset.setPixmap( pix, size, mode, state ); + break; + } + case MethodPixmap: + { + QPixmap pix; + + if( args.size() == 3 ) + { + QIconSet::Size size = (QIconSet::Size)extractInt( exec, args, 0 ); + QIconSet::Mode mode = (QIconSet::Mode)extractInt( exec, args, 1 ); + QIconSet::State state = (QIconSet::State)extractInt( exec, args, 1 ); + pix = iconset.pixmap( size, mode, state ); + } + else + pix = iconset.pixmap(); + + break; + } + default: + kdWarning() << "Iconset has no method " << mid << endl; + break; + } + + op->setValue(iconset); + return retValue; +} + +} // namespace KJSEmbed::Bindings +} // namespace KJSEmbed diff --git a/kjsembed/bindings/iconset_imp.h b/kjsembed/bindings/iconset_imp.h new file mode 100644 index 00000000..d758f0b5 --- /dev/null +++ b/kjsembed/bindings/iconset_imp.h @@ -0,0 +1,59 @@ +// -*- c++ -*- + +/* + * Copyright (C) 2004, Ian Reinhart Geiser <geiseri@kde.org> + * + * This 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. + * + * This 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 this library; see the file COPYING.LIB. If not, write to + * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, + * Boston, MA 02110-1301, USA. + */ + +#ifndef KJSEMBED_ICONSET_H +#define KJSEMBED_ICONSET_H + +#include <kjsembed/jsproxy_imp.h> + +namespace KJSEmbed { +namespace Bindings { + +class IconsetImp : public JSProxyImp { + + /** Identifiers for the methods provided by this class. */ + enum MethodId { MethodReset, MethodSetPixmap, MethodPixmap, + MethodIsGenerated, MethodClearGenerated, MethodIsNull, + MethodDetach }; + +public: + IconsetImp( KJS::ExecState *exec, int id ); + virtual ~IconsetImp(); + + static void addBindings( KJS::ExecState *exec, KJS::Object &object ); + + /** Returns true iff this object implements the call function. */ + virtual bool implementsCall() const { + return true; + } + + /** Invokes the call function. */ + virtual KJS::Value call( KJS::ExecState *exec, KJS::Object &self, const KJS::List &args ); + + +private: + int mid; +}; + +} // namespace +} // namespace + +#endif // KJSEMBED_IMAGE_IMP_H diff --git a/kjsembed/bindings/image_imp.cpp b/kjsembed/bindings/image_imp.cpp new file mode 100644 index 00000000..7f6abdca --- /dev/null +++ b/kjsembed/bindings/image_imp.cpp @@ -0,0 +1,259 @@ +// -*- c++ -*- + +/* + * Copyright (C) 2003, Richard J. Moore <rich@kde.org> + * + * This 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. + * + * This 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 this library; see the file COPYING.LIB. If not, write to + * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, + * Boston, MA 02110-1301, USA. + */ + +#include <qfile.h> +#include <kjsembed/global.h> +#include <kjsembed/jsopaqueproxy.h> +#include <kjsembed/jsvalueproxy.h> +#include <kjsembed/jsbinding.h> +#include <qvariant.h> + +#include "image_imp.h" + +namespace KJSEmbed { +namespace Bindings { + + +ImageImp::ImageImp( KJS::ExecState *exec, int id ) + : JSProxyImp(exec), mid(id) +{ +} + +ImageImp::~ImageImp() +{ +} + +void ImageImp::addBindings( KJS::ExecState *exec, KJS::Object &object ) { + + if( !JSProxy::checkType(object, JSProxy::ValueProxy, "QImage") ) return; + + JSProxy::MethodTable methods[] = { + { Methodwidth, "width" }, + { Methodheight, "height" }, + { Methoddepth, "depth" }, + { MethodisOk, "isOk" }, + { Methodpixmap, "pixmap" }, + { Methodload, "load" }, + { Methodsave, "save" }, + { MethodsetFormat, "setFormat" }, + { MethodsmoothScale, "smoothScale" }, + { MethodsmoothScaleMin, "smoothScaleMin" }, + { MethodsetPixmap, "setPixmap" }, + { MethodinvertPixels, "invertPixels" }, + { Methodpixel, "pixel"}, + { MethodsetPixel, "setPixel"}, + { Methodmirror, "mirror" }, + { 0, 0 } + }; + JSProxy::addMethods<ImageImp>(exec, methods, object); + +} + +KJS::Value ImageImp::call( KJS::ExecState *exec, KJS::Object &self, const KJS::List &args ) { + if( !JSProxy::checkType(self, JSProxy::ValueProxy, "QImage") ) return KJS::Value(); + JSValueProxy *op = JSProxy::toValueProxy( self.imp() ); + img = op->toVariant().toImage(); + + KJS::Value retValue = KJS::Value(); + switch ( mid ) { +// case Methodfilename: +// retValue = KJS::String(filename()); +// break; +// case Methodformat: +// retValue = KJS::String(format()); +// break; + case Methodwidth: + retValue = KJS::Number(width()); + break; + case Methodheight: + retValue = KJS::Number(height()); + break; + case Methoddepth: + retValue = KJS::Number(depth()); + break; + case MethodisOk: + retValue = KJS::Boolean(isOk()); + break; + case Methodpixmap: + { + retValue = convertToValue(exec, pixmap()); + break; + } + + case Methodload: { + QString arg0 = extractQString( exec, args, 0); + retValue = KJS::Boolean( load( arg0 )); + break; + } + case Methodsave: { + QString arg0 = extractQString( exec, args, 0); + QString arg1 = extractQString( exec, args, 1); + retValue = KJS::Boolean( save( arg0, arg1 )); + break; + } + case MethodsetFormat: { + QString arg0 = extractQString( exec, args, 0); + setFormat( arg0 ); + break; + } + case MethodsmoothScale: { + int arg0 = extractInt( exec, args, 0); + int arg1 = extractInt( exec, args, 1); + smoothScale(arg0, arg1); + break; + } + case MethodsmoothScaleMin: { + int arg0 = extractInt( exec, args, 0); + int arg1 = extractInt( exec, args, 1); + smoothScaleMin(arg0, arg1); + break; + } + case MethodsetPixmap: { + QPixmap pix = extractQPixmap(exec, args, 0); + setPixmap(pix); + break; + } + case MethodinvertPixels: { + bool alpha = extractBool( exec, args, 0); + img.invertPixels(alpha); + break; + } + case Methodpixel: { + int x = extractInt(exec, args, 0); + int y = extractInt(exec, args, 1); + retValue = KJS::Number( img.pixel(x, y) ); + break; + } + case MethodsetPixel: { + int x = extractInt(exec, args, 0); + int y = extractInt(exec, args, 1); + uint col = extractUInt(exec, args, 2); + img.setPixel(x, y, col); + break; + } + case Methodmirror: + { + if ( img.isNull()) + break; + + bool arg0 = extractBool( exec, args, 0); + bool arg1 = extractBool( exec, args, 1); + img = img.mirror( arg0, arg1 ); + } + default: + kdWarning() << "Image has no method " << mid << endl; + break; + } + + op->setValue(img); + return retValue; +} + +int ImageImp::width() const { + + return !img.isNull() ? img.width() : 0; +} + +int ImageImp::height() const { + return !img.isNull() ? img.height() : 0; +} + +int ImageImp::depth() const { + return !img.isNull() ? img.depth() : 0; +} + +bool ImageImp::isOk() const { + return !img.isNull(); +} + +QPixmap ImageImp::pixmap() const { + if ( img.isNull() ) + return QPixmap(); + + QPixmap pix; + pix.convertFromImage( img ); + return pix; +} + +void ImageImp::setPixmap( const QPixmap &pix ) { + if ( img.isNull() ) + img = QImage(); + + img = pix.convertToImage(); +} + +QString ImageImp::format() const { + return fmt; +} + +QString ImageImp::filename() const { + return nm; +} + +void ImageImp::setFormat( const QString &f ) { + fmt = f; +} + +bool ImageImp::load( const QString &filename ) { + + if ( !img.isNull() ) + img = QImage(); + + nm = filename; + fmt = QImageIO::imageFormat( filename ); + bool ok = img.load( filename ); + if ( !ok ) { + kdWarning() << "Error loading " << filename << endl; + img = QImage(); + } + return ok; +} + +bool ImageImp::save( const QString &filename, const QString &fmt ) { + + if ( img.isNull() ) { + kdWarning() << "Attempt to save a null image to '" << filename << "'" << endl; + return false; + } + + bool ok = img.save( filename, fmt.isNull() ? "PNG" : fmt.ascii() ); + if ( ok ) + nm = filename; + + return ok; +} + +void ImageImp::smoothScale( int w, int h ) { + if ( img.isNull()) + return; + img = img.smoothScale( w, h ); +} + +void ImageImp::smoothScaleMin( int w, int h ) { + if ( img.isNull()) + return; + img = img.smoothScale( w, h, QImage::ScaleMin ); +} + + +} // namespace KJSEmbed::Bindings +} // namespace KJSEmbed + diff --git a/kjsembed/bindings/image_imp.h b/kjsembed/bindings/image_imp.h new file mode 100644 index 00000000..4104d3b5 --- /dev/null +++ b/kjsembed/bindings/image_imp.h @@ -0,0 +1,95 @@ +// -*- c++ -*- + +/* + * Copyright (C) 2003, Richard J. Moore <rich@kde.org> + * + * This 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. + * + * This 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 this library; see the file COPYING.LIB. If not, write to + * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, + * Boston, MA 02110-1301, USA. + */ + +#ifndef KJSEMBED_IMAGE_IMP_H +#define KJSEMBED_IMAGE_IMP_H + +#include <kjsembed/jsobjectproxy_imp.h> + +#include <qimage.h> +#include <qpixmap.h> + + +namespace KJSEmbed { +namespace Bindings { + +/** + * Methods for the QImage binding. + * + * @author Richard Moore, rich@kde.org + * @version $Id$ + */ + +class ImageImp : public JSProxyImp { + + /** Identifiers for the methods provided by this class. */ + enum MethodId { + /*Methodfilename, Methodformat,*/Methodwidth, Methodheight, Methoddepth, + MethodisOk, Methodpixmap, Methodload, Methodsave,MethodsetFormat, + MethodsmoothScale, MethodsmoothScaleMin, MethodsetPixmap, MethodinvertPixels, + Methodpixel, MethodsetPixel, Methodmirror + }; + + +public: + ImageImp( KJS::ExecState *exec, int id ); + virtual ~ImageImp(); + + static void addBindings( KJS::ExecState *exec, KJS::Object &object ); + + /** Returns true iff this object implements the call function. */ + virtual bool implementsCall() const { + return true; + } + + /** Invokes the call function. */ + virtual KJS::Value call( KJS::ExecState *exec, KJS::Object &self, const KJS::List &args ); + + +private: + + QString filename() const; + QString format() const; + int width() const; + int height() const; + int depth() const; + + bool isOk() const; + QPixmap pixmap() const; + + bool load( const QString &filename ); + bool save( const QString &filename, const QString &fmt ); + void setFormat( const QString &fmt ); + void smoothScale( int w, int h ); + void smoothScaleMin( int w, int h ); + void setPixmap( const QPixmap &pix ); + + + int mid; + QImage img; // this is a temp!!! + QString nm; + QString fmt; +}; + +} // namespace +} // namespace + +#endif // KJSEMBED_IMAGE_IMP_H diff --git a/kjsembed/bindings/kconfig_imp.cpp b/kjsembed/bindings/kconfig_imp.cpp new file mode 100644 index 00000000..f45e4d42 --- /dev/null +++ b/kjsembed/bindings/kconfig_imp.cpp @@ -0,0 +1,536 @@ +/* +* Copyright (C) 2003, Ian Reinhart Geiser <geiseri@kde.org> + * + * This 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. + * + * This 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 this library; see the file COPYING.LIB. If not, write to + * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, + * Boston, MA 02110-1301, USA. + */ + +#include "kconfig_imp.h" + +#include <kjsembed/global.h> + +#ifndef QT_ONLY +#include <kconfig.h> +#include <kstddirs.h> +#include <kapplication.h> +#include "kconfig_imp.moc" +#else +#include <qsettings.h> +#endif +namespace KJSEmbed { +namespace Bindings { + +Config::Config( QObject *parent, const char *name) + : BindingObject(parent, name) +{ + +#ifndef QT_ONLY + if( name == 0) + m_config = kapp->config(); + else + m_config = new KConfig(name); + if( !m_config->checkConfigFilesWritable(true) ) + { + kdWarning( 80001 ) << "Could not write to config file." << endl; + } +#else + m_config = new QSettings(); + if( name == 0) + m_name = "qjcmd"; + else + m_name = name; + m_config->setPath( "QJSEmbed",m_name, QSettings::User ); + m_forceGlobal = false; +#endif +} + +/* +Config::Config( QObject *parent, const char *name , const QString& confName) + : BindingObject(parent, name) +{ + QString fileName = ::locate("kde_config", confName); + m_config = new KConfig(fileName); +} +*/ +Config::~Config() +{ +#ifndef QT_ONLY + if( kapp->config() != m_config ) +#endif + delete m_config; +} + +void Config::setDesktopGroup() +{ +#ifndef QT_ONLY + m_config->setDesktopGroup(); +#else + m_config->resetGroup(); + m_config->beginGroup("/Desktop Entry"); +#endif +} + +void Config::setGroup(const QString& group) +{ +#ifndef QT_ONLY + m_config->setGroup(group); +#else + m_config->resetGroup(); + m_config->beginGroup(group); +#endif +} + +QString Config::group() +{ + return m_config->group(); +} + +QStringList Config::groupList() +{ +#ifndef QT_ONLY + return m_config->groupList(); +#else + m_config->resetGroup(); + return m_config->subkeyList(group()); +#endif +} + +QString Config::locale() +{ +#ifndef QT_ONLY + return m_config->locale(); +#else + return "C"; +#endif +} + +void Config::setForceGlobal( bool force ) +{ +#ifndef QT_ONLY + m_config->setForceGlobal(force); +#else + m_forceGlobal = force; + m_config->setPath( "QJSEmbed",m_name, (force)?QSettings::Global:QSettings::User ); +#endif +} + +bool Config::forceGlobal( ) const +{ +#ifndef QT_ONLY + return m_config->forceGlobal(); +#else + return m_forceGlobal; +#endif +} + +void Config::setDollarExpansion( bool _bExpand ) +{ +#ifndef QT_ONLY + m_config->setDollarExpansion(_bExpand); +#else + Q_UNUSED(_bExpand); +#endif +} + +bool Config::isDollarExpansion() const +{ +#ifndef QT_ONLY + return m_config->isDollarExpansion(); +#else + return false; +#endif +} + +void Config::setReadOnly(bool _ro) +{ +#ifndef QT_ONLY + m_config->setReadOnly(_ro); +#else + Q_UNUSED(_ro); +#endif +} + +bool Config::isReadOnly() const +{ +#ifndef QT_ONLY + return m_config->isReadOnly(); +#else + return false; +#endif +} + +void Config::setReadDefaults(bool b) +{ +#ifndef QT_ONLY + m_config->setReadDefaults(b); +#else + Q_UNUSED(b); +#endif +} + +bool Config::readDefaults() const +{ +#ifndef QT_ONLY + return m_config->readDefaults(); +#else + return false; +#endif +} + +void Config::rollback( bool bDeep ) +{ +#ifndef QT_ONLY + m_config->rollback(bDeep); +#else + Q_UNUSED(bDeep); +#endif +} + +void Config::sync() +{ + m_config->sync(); +} + +bool Config::hasKey( const QString& key ) const +{ +#ifndef QT_ONLY + return m_config->hasKey(key); +#else + return false; +#endif +} + +bool Config::entryIsImmutable(const QString &key) const +{ +#ifndef QT_ONLY + return m_config->entryIsImmutable(key); +#else + Q_UNUSED( key ); + return false; +#endif +} + +void Config::revertToDefault(const QString &key) +{ +#ifndef QT_ONLY + m_config->revertToDefault(key); +#else + Q_UNUSED(key); +#endif +} + +bool Config::hasDefault(const QString &key) const +{ +#ifndef QT_ONLY + return m_config->hasDefault(key); +#else + Q_UNUSED(key); + return false; +#endif +} + +void Config::setFileWriteMode(int mode) +{ +#ifndef QT_ONLY + m_config->setFileWriteMode(mode); +#else + Q_UNUSED(mode); +#endif +} + +QString Config::readEntry(const QString& pKey, const QString& aDefault ) const +{ + return m_config->readEntry(pKey,aDefault); +} + +QVariant Config::readPropertyEntry( const QString& pKey, const QVariant &pDefault) const +{ +#ifndef QT_ONLY + return m_config->readPropertyEntry(pKey,pDefault); +#else + QVariant returnVariant; + returnVariant = m_config->readEntry(pKey, pDefault.toString()); + return returnVariant; +#endif +} + +QStringList Config::readListEntry( const QString& pKey ) const +{ + return m_config->readListEntry(pKey); +} + +QString Config::readPathEntry( const QString& pKey, const QString & aDefault ) const +{ +#ifndef QT_ONLY + return m_config->readPathEntry(pKey,aDefault); +#else + return readEntry(pKey,aDefault); +#endif +} + +QStringList Config::readPathListEntry( const QString& pKey ) const +{ +#ifndef QT_ONLY + return m_config->readPathListEntry(pKey); +#else + return readListEntry(pKey); +#endif + +} + +int Config::readNumEntry( const QString& pKey, int nDefault) const +{ + return m_config->readNumEntry(pKey,nDefault); +} + +uint Config::readUnsignedNumEntry( const QString& pKey, uint nDefault) const +{ +#ifndef QT_ONLY + return m_config->readUnsignedNumEntry(pKey,nDefault); +#else + return (uint)readNumEntry(pKey,nDefault); +#endif +} + +long Config::readLongNumEntry( const QString& pKey, long nDefault) const +{ +#ifndef QT_ONLY + return m_config->readLongNumEntry(pKey,nDefault); +#else + return (long)readNumEntry(pKey,nDefault); +#endif +} + +double Config::readDoubleNumEntry( const QString& pKey, double nDefault ) const +{ +#ifndef QT_ONLY + return m_config->readDoubleNumEntry(pKey,nDefault); +#else + return m_config->readDoubleEntry(pKey,nDefault); +#endif +} + +QFont Config::readFontEntry( const QString& pKey, const QFont* pDefault ) const +{ +#ifndef QT_ONLY + return m_config->readFontEntry(pKey,pDefault); +#else + return readPropertyEntry(pKey,QVariant(*pDefault)).toFont(); +#endif +} + +bool Config::readBoolEntry( const QString& pKey, const bool bDefault ) const +{ + return m_config->readBoolEntry(pKey,bDefault); +} + +QRect Config::readRectEntry( const QString& pKey, const QRect* pDefault ) const +{ +#ifndef QT_ONLY + return m_config->readRectEntry(pKey,pDefault); +#else + return readPropertyEntry(pKey,QVariant(*pDefault)).toRect(); +#endif +} + +QPoint Config::readPointEntry( const QString& pKey, const QPoint* pDefault ) const +{ +#ifndef QT_ONLY + return m_config->readPointEntry(pKey,pDefault); +#else + return readPropertyEntry(pKey,QVariant(*pDefault)).toPoint(); +#endif +} + +QSize Config::readSizeEntry( const QString& pKey, const QSize* pDefault ) const +{ +#ifndef QT_ONLY + return m_config->readSizeEntry(pKey,pDefault); +#else + return readPropertyEntry(pKey,QVariant(*pDefault)).toSize(); +#endif +} + +QColor Config::readColorEntry( const QString& pKey, const QColor* pDefault ) const +{ +#ifndef QT_ONLY + return m_config->readColorEntry(pKey,pDefault); +#else + return readPropertyEntry(pKey,QVariant(*pDefault)).toColor(); +#endif +} + +QDateTime Config::readDateTimeEntry( const QString& pKey, const QDateTime* pDefault) const +{ +#ifndef QT_ONLY + return m_config->readDateTimeEntry(pKey,pDefault); +#else + return readPropertyEntry(pKey,QVariant(*pDefault)).toDateTime(); +#endif +} + +QString Config::readEntryUntranslated( const QString& pKey, const QString& aDefault ) const +{ +#ifndef QT_ONLY + return m_config->readEntryUntranslated(pKey,aDefault); +#else + return m_config->readEntry(pKey,aDefault); +#endif +} +void Config::writeEntry( const QString& pKey, const QString& pValue ) +{ + m_config->writeEntry(pKey,pValue); +} + +void Config::writePropertyEntry( const QString& pKey, const QVariant& pValue ) +{ +#ifndef QT_ONLY + m_config->writeEntry(pKey, pValue ); +#else + m_config->writeEntry(pKey,pValue.toString()); +#endif +} + +void Config::writeListEntry( const QString& pKey, const QStringList &rValue ) +{ +#ifndef QT_ONLY + m_config->writeEntry(pKey, rValue ); +#else + m_config->writeEntry(pKey,rValue); +#endif +} + +void Config::writeNumEntry( const QString& pKey, int nValue ) +{ +#ifndef QT_ONLY + m_config->writeEntry(pKey, nValue ); +#else + m_config->writeEntry(pKey,nValue); +#endif +} +void Config::writeUnsignedNumEntry( const QString& pKey, uint nValue ) +{ +#ifndef QT_ONLY + m_config->writeEntry(pKey, nValue ); +#else + writeNumEntry(pKey, (int)nValue ); +#endif +} +void Config::writeLongNumEntry( const QString& pKey, unsigned long nValue ) +{ +#ifndef QT_ONLY + m_config->writeEntry(pKey, nValue ); +#else + writeNumEntry(pKey, (int)nValue); +#endif +} +void Config::writeDoubleNumEntry( const QString& pKey, double nValue ) +{ + m_config->writeEntry(pKey,nValue); +} +void Config::writeBoolEntry( const QString& pKey, bool bValue ) +{ + m_config->writeEntry(pKey,bValue); +} +void Config::writeFontEntry( const QString& pKey, const QFont& rFont ) +{ +#ifndef QT_ONLY + m_config->writeEntry(pKey, rFont ); +#else + writePropertyEntry(pKey,rFont); +#endif + +} +void Config::writeColorEntry( const QString& pKey, const QColor& rColor ) +{ +#ifndef QT_ONLY + m_config->writeEntry(pKey, rColor ); +#else + writePropertyEntry(pKey,rColor); +#endif + +} +void Config::writeDateTimeEntry( const QString& pKey, const QDateTime& rDateTime ) +{ +#ifndef QT_ONLY + m_config->writeEntry(pKey, rDateTime ); +#else + writePropertyEntry(pKey,rDateTime); +#endif + +} +void Config::writeRectEntry( const QString& pKey, const QRect& rValue ) +{ +#ifndef QT_ONLY + m_config->writeEntry(pKey, rValue ); +#else + writePropertyEntry(pKey,rValue); +#endif + +} +void Config::writePointEntry( const QString& pKey, const QPoint& rValue ) +{ +#ifndef QT_ONLY + m_config->writeEntry(pKey, rValue ); +#else + writePropertyEntry(pKey,rValue); +#endif + +} +void Config::writeSizeEntry( const QString& pKey, const QSize& rValue ) +{ +#ifndef QT_ONLY + m_config->writeEntry(pKey, rValue ); +#else + writePropertyEntry(pKey,rValue); +#endif +} +void Config::writePathEntry( const QString& pKey, const QString & path ) +{ +#ifndef QT_ONLY + m_config->writePathEntry(pKey,path); +#else + writeEntry(pKey,path); +#endif +} +void Config::writePathListEntry( const QString& pKey, const QStringList &rValue ) +{ +#ifndef QT_ONLY + m_config->writePathEntry(pKey,rValue); +#else + writeListEntry(pKey,rValue); +#endif +} +void Config::deleteEntry( const QString& pKey, bool bNLS , bool bGlobal ) +{ +#ifndef QT_ONLY + m_config->deleteEntry(pKey,bNLS,bGlobal); +#else + Q_UNUSED(bNLS); + Q_UNUSED(bGlobal); + m_config->removeEntry(pKey); +#endif +} +bool Config::deleteGroup( const QString& group, bool bDeep , bool bGlobal ) +{ +#ifndef QT_ONLY + return m_config->deleteGroup(group,bDeep,bGlobal); +#else + return false; +#endif +} + +} +} diff --git a/kjsembed/bindings/kconfig_imp.h b/kjsembed/bindings/kconfig_imp.h new file mode 100644 index 00000000..55f58e34 --- /dev/null +++ b/kjsembed/bindings/kconfig_imp.h @@ -0,0 +1,135 @@ +// -*- c++ -*- + +/* + * Copyright (C) 2003, Ian Reinhart Geiser <geiseri@kde.org> + * + * This 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. + * + * This 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 this library; see the file COPYING.LIB. If not, write to + * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, + * Boston, MA 02110-1301, USA. + */ + +#ifndef KJSEMBED_CONFIG_IMP_H +#define KJSEMBED_CONFIG_IMP_H + +#include <qdatetime.h> +#include <qfont.h> +#include <qvariant.h> +#include <qpoint.h> +#include <qrect.h> +#include <qsize.h> +#include <qcolor.h> +#include <qstringlist.h> + +#include "bindingobject.h" + +#ifndef QT_ONLY +class KConfig; +#else +class QSettings; +#endif + +namespace KJSEmbed { +namespace Bindings { + +class Config : public BindingObject +{ + Q_OBJECT + Q_PROPERTY( bool forceGlobal READ forceGlobal WRITE setForceGlobal ) + Q_PROPERTY( bool dollarExpansion READ isDollarExpansion WRITE setDollarExpansion ) + Q_PROPERTY( bool readOnly READ isReadOnly WRITE setReadOnly ) + Q_PROPERTY( bool readDefaults READ readDefaults WRITE setReadDefaults ) + +public: + Config( QObject *parent=0, const char *name=0); + /* + Config( QObject *parent, const char *name, const QString& confName ); + */ + virtual ~Config(); + + void setForceGlobal( bool force ); + bool forceGlobal() const; + void setDollarExpansion( bool _bExpand ); + bool isDollarExpansion() const; + void setReadOnly(bool _ro); + bool isReadOnly() const; + void setReadDefaults(bool b); + bool readDefaults() const; + +public slots: + + // Group + void setDesktopGroup(); + void setGroup(const QString&); + QString group(); + QStringList groupList(); + QString locale(); + + void rollback( bool bDeep ); + void sync(); + bool hasKey( const QString& key ) const; + bool entryIsImmutable(const QString &key) const; + void revertToDefault(const QString &key); + bool hasDefault(const QString &key) const; + + void setFileWriteMode(int mode); + QString readEntry(const QString& pKey, const QString& aDefault ) const; + QVariant readPropertyEntry( const QString& pKey, const QVariant &var) const; + QStringList readListEntry( const QString& pKey ) const; + QString readPathEntry( const QString& pKey, const QString & aDefault) const; + QStringList readPathListEntry( const QString& pKey ) const; + int readNumEntry( const QString& pKey, int nDefault ) const; + uint readUnsignedNumEntry( const QString& pKey, uint nDefault ) const; + long readLongNumEntry( const QString& pKey, long nDefault ) const; + double readDoubleNumEntry( const QString& pKey, double nDefault ) const; + QFont readFontEntry( const QString& pKey, const QFont* pDefault) const; + bool readBoolEntry( const QString& pKey, const bool bDefault ) const; + QRect readRectEntry( const QString& pKey, const QRect* pDefault) const; + QPoint readPointEntry( const QString& pKey, const QPoint* pDefault) const; + QSize readSizeEntry( const QString& pKey, const QSize* pDefault) const; + QColor readColorEntry( const QString& pKey, const QColor* pDefault) const; + QDateTime readDateTimeEntry( const QString& pKey, const QDateTime* pDefault) const; + QString readEntryUntranslated( const QString& pKey, const QString& aDefault ) const; + + void writeEntry( const QString& pKey, const QString& pValue ); + void writePropertyEntry( const QString& pKey, const QVariant& pValue ); + void writeListEntry( const QString& pKey, const QStringList &rValue ); + void writeNumEntry( const QString& pKey, int nValue ); + void writeUnsignedNumEntry( const QString& pKey, uint nValue ); + void writeLongNumEntry( const QString& pKey, unsigned long nValue ); + void writeDoubleNumEntry( const QString& pKey, double nValue ); + void writeBoolEntry( const QString& pKey, bool bValue ); + void writeFontEntry( const QString& pKey, const QFont& rFont ); + void writeColorEntry( const QString& pKey, const QColor& rColor ); + void writeDateTimeEntry( const QString& pKey, const QDateTime& rDateTime ); + void writeRectEntry( const QString& pKey, const QRect& rValue ); + void writePointEntry( const QString& pKey, const QPoint& rValue ); + void writeSizeEntry( const QString& pKey, const QSize& rValue ); + void writePathEntry( const QString& pKey, const QString & path ); + void writePathListEntry( const QString& pKey, const QStringList &rValue); + void deleteEntry( const QString& pKey, bool bNLS , bool bGlobal ); + bool deleteGroup( const QString& group, bool bDeep , bool bGlobal ); + +private: +#ifndef QT_ONLY + KConfig *m_config; +#else + QSettings *m_config; + QString m_name; + bool m_forceGlobal; +#endif +}; +} +} + +#endif diff --git a/kjsembed/bindings/movie_imp.cpp b/kjsembed/bindings/movie_imp.cpp new file mode 100644 index 00000000..8a5ced01 --- /dev/null +++ b/kjsembed/bindings/movie_imp.cpp @@ -0,0 +1,158 @@ +// -*- c++ -*- + +/* + * Copyright (C) 2003, Ian Reinhart Geiser <geiseri@kde.org> + * + * This 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. + * + * This 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 this library; see the file COPYING.LIB. If not, write to + * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, + * Boston, MA 02110-1301, USA. + */ + +#include <qpixmap.h> +#include <kjsembed/global.h> +#include "movie_imp.h" + + +namespace KJSEmbed { +namespace Bindings { + +Movie::Movie( QObject *parent, const char *name ) : BindingObject(parent, name) +{ + movie = QMovie(); +} +Movie::~Movie() +{ + +} +QColor Movie::backgroundColor() const +{ + if( movie.isNull() ) + return QColor(); + return movie.backgroundColor(); +} +void Movie::setBackgroundColor( const QColor &c ) +{ + if( movie.isNull() ) + return; + movie.setBackgroundColor(c); +} +int Movie::speed() const +{ + if( movie.isNull() ) + return 0; + return movie.speed(); +} +void Movie::setSpeed( int percent ) +{ + if( movie.isNull() ) + return; + movie.setSpeed(percent); +} +bool Movie::load( const QString &filename, int bufsize) +{ + movie = QMovie( filename, bufsize); + if ( movie.isNull() ) + return false; + else + return true; +} +QRect Movie::getValidRect() +{ + if( movie.isNull() ) + return QRect(); + return movie.getValidRect(); +} +QPixmap Movie::framePixmap() +{ + if( movie.isNull() ) + return QPixmap(); + return movie.framePixmap(); +} +QImage Movie::frameImage() +{ + if( movie.isNull() ) + return QImage(); + return movie.frameImage(); +} +bool Movie::isNull() +{ + return movie.isNull(); +} +int Movie::frameNumber() +{ + if( movie.isNull() ) + return 0; + return movie.frameNumber(); +} +int Movie::steps() +{ + if( movie.isNull() ) + return 0; + return movie.steps(); +} +bool Movie::paused() +{ + if( movie.isNull() ) + return false; + return movie.paused(); +} +bool Movie::finished() +{ + if( movie.isNull() ) + return false; + return movie.finished(); +} +bool Movie::running() +{ + if( movie.isNull() ) + return false; + return movie.running(); +} +void Movie::unpause() +{ + if( movie.isNull() ) + return; + movie.unpause(); +} +void Movie::pause() +{ + if( movie.isNull() ) + return; + movie.pause(); +} +void Movie::step() +{ + if( movie.isNull() ) + return; + movie.step(); +} +void Movie::step( int steps ) +{ + if( movie.isNull() ) + return; + movie.step(steps); +} +void Movie::restart() +{ + if( movie.isNull() ) + return; + movie.restart(); +} + +} // namespace KJSEmbed::Bindings +} // namespace KJSEmbed + +#ifndef QT_ONLY +#include "movie_imp.moc" +#endif diff --git a/kjsembed/bindings/movie_imp.h b/kjsembed/bindings/movie_imp.h new file mode 100644 index 00000000..2b3024e4 --- /dev/null +++ b/kjsembed/bindings/movie_imp.h @@ -0,0 +1,77 @@ +// -*- c++ -*- + +/* + * Copyright (C) 2003, Ian Reinhart Geiser <geiseri@kde.org> + * + * This 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. + * + * This 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 this library; see the file COPYING.LIB. If not, write to + * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, + * Boston, MA 02110-1301, USA. + */ + +#ifndef KJSEMBED_MOVIE_IMP_H +#define KJSEMBED_MOVIE_IMP_H + +#include "bindingobject.h" +#include <qmovie.h> +#include <qimage.h> + +namespace KJSEmbed { +namespace Bindings { + +/** + * QObject Binding for QMovie. + * + * @author Ian Reinhart Geiser, geiseri@kde.org + * @version $Id$ + */ +class Movie : public BindingObject +{ + Q_OBJECT + + Q_PROPERTY( QColor setBackgroundColor READ backgroundColor ) + Q_PROPERTY( int setSpeed READ speed ) + +public: + Movie( QObject *parent=0, const char *name=0 ); + virtual ~Movie(); + QColor backgroundColor() const; + void setBackgroundColor( const QColor &c ); + int speed() const; + void setSpeed ( int percent ); + +public slots: + bool load( const QString &filename, int bufsize = 1024); + QRect getValidRect(); + QPixmap framePixmap(); + QImage frameImage(); + bool isNull(); + int frameNumber(); + int steps(); + bool paused(); + bool finished(); + bool running(); + void unpause(); + void pause(); + void step(); + void step( int steps ); + void restart(); + +private: + QMovie movie; +}; + +} // namespace +} // namespace + +#endif // KJSEMBED_MOVIE_IMP_H diff --git a/kjsembed/bindings/netaccess_imp.cpp b/kjsembed/bindings/netaccess_imp.cpp new file mode 100644 index 00000000..b2d6cce7 --- /dev/null +++ b/kjsembed/bindings/netaccess_imp.cpp @@ -0,0 +1,156 @@ +// -*- Mode: C++; c-basic-offset: 4; indent-tabs-mode: nil; -*- +/** + * netaccess_imp.cpp + * + * Copyright (C) 2003 Zack Rusin <zack@kde.org> + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) any later version. + * + * This 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 + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA + * 02110-1301 USA + */ +#include "netaccess_imp.h" + +#include <kio/netaccess.h> +#include <kpropertiesdialog.h> + +#include <kurl.h> +#include <kdebug.h> +#include <kdeversion.h> +#include <ktempfile.h> + +namespace KJSEmbed { +namespace Bindings { + +NetAccess::NetAccess( QObject *parent, const char *name ) + : BindingObject( parent, name ) +{ +} + +NetAccess::~NetAccess() +{ +} + +bool NetAccess::download( const KURL& src, const QString& loc ) +{ + QString mloc = loc; +#if KDE_IS_VERSION(3,1,90) + return KIO::NetAccess::download( src, mloc, 0 ); +#else + return KIO::NetAccess::download( src, mloc ); +#endif +} + +QString NetAccess::createTempFile( const QString& prefix, const QString& ext, uint mode ) +{ + KTempFile tmpFile = KTempFile(prefix, ext, mode); + tmpFile.setAutoDelete(false); + return tmpFile.name(); +} + +void NetAccess::removeTempFile( const QString& name ) +{ + KIO::NetAccess::removeTempFile( name ); +} + +bool NetAccess::upload( const QString& src, const KURL& dest ) +{ +#if KDE_IS_VERSION(3,1,90) + return KIO::NetAccess::upload( src, dest, 0 ); +#else + return KIO::NetAccess::upload( src, dest ); +#endif +} + +bool NetAccess::copy( const KURL& src, const KURL& target ) +{ +#if KDE_IS_VERSION(3,1,90) + return KIO::NetAccess::copy( src, target, 0 ); +#else + return KIO::NetAccess::copy( src, target ); +#endif +} + +bool NetAccess::dircopy( const KURL& src, const KURL& target ) +{ +#if KDE_IS_VERSION(3,1,90) + return KIO::NetAccess::dircopy( src, target, 0 ); +#else + return KIO::NetAccess::dircopy( src, target ); +#endif +} + +bool NetAccess::move( const KURL& src, const KURL& target ) +{ +#if KDE_IS_VERSION(3,1,90) + return KIO::NetAccess::move( src, target, 0 ); +#else + kdWarning() << "NetAccess::move(src,target) is not supported on 3.1" << endl; + return false; +#endif +} + +bool NetAccess::exists( const KURL& url, bool source ) +{ +#if KDE_IS_VERSION(3,1,90) + return KIO::NetAccess::exists( url, source, 0 ); +#else + return KIO::NetAccess::exists( url, source ); +#endif +} + +bool NetAccess::del( const KURL & url ) +{ +#if KDE_IS_VERSION(3,1,90) + return KIO::NetAccess::del( url, 0 ); +#else + return KIO::NetAccess::del( url ); +#endif +} + +int NetAccess::propertiesDialog( const KURL &url ) +{ + KPropertiesDialog dlg( url, 0, "file_properties", true, false ); + return dlg.exec(); +} + +QString NetAccess::fish_execute( const KURL& url, const QString& command ) +{ +#if KDE_IS_VERSION(3,1,90) + return KIO::NetAccess::fish_execute( url, command, 0 ); +#else + kdWarning() << "NetAccess::fish_execute(url,command) is not supported on 3.1" << endl; + return QString::null; +#endif +} + +QString NetAccess::mimetype( const KURL& url ) +{ + kdDebug()<<"mimetype CALLED "<<endl; + +#if KDE_IS_VERSION(3,1,90) + return KIO::NetAccess::mimetype( url, 0 ); +#else + return KIO::NetAccess::mimetype( url ); +#endif +} + +QString NetAccess::lastErrorString() +{ + return KIO::NetAccess::lastErrorString(); +} + +} +} + +#include "netaccess_imp.moc" diff --git a/kjsembed/bindings/netaccess_imp.h b/kjsembed/bindings/netaccess_imp.h new file mode 100644 index 00000000..c2c01bfe --- /dev/null +++ b/kjsembed/bindings/netaccess_imp.h @@ -0,0 +1,62 @@ +// -*- Mode: C++; c-basic-offset: 4; indent-tabs-mode: nil; -*- +/** + * netaccess.h + * + * Copyright (C) 2003 Zack Rusin <zack@kde.org> + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) any later version. + * + * This 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 + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA + * 02110-1301 USA + */ +#ifndef KJSEMBED_NETACCESS_IMP_H +#define KJSEMBED_NETACCESS_IMP_H + +#include <qstring.h> +#include "bindingobject.h" + +class KURL; + +namespace KJSEmbed { +namespace Bindings { + +/** + * Provides a binding to KIO::NetAccess. + */ +class NetAccess : public BindingObject +{ + Q_OBJECT +public: + NetAccess( QObject *parent, const char *name=0 ); + virtual ~NetAccess(); +public slots: + bool download( const KURL& src, const QString & loc ); + QString createTempFile(const QString& prefix, const QString& ext, uint mode ); + void removeTempFile( const QString& name ); + bool upload( const QString& src, const KURL& dest ); + bool copy( const KURL& src, const KURL& target ); + bool dircopy( const KURL& src, const KURL& target ); + bool move( const KURL& src, const KURL& target ); + bool exists( const KURL& url, bool source ); + bool del( const KURL& url ); + int propertiesDialog( const KURL &url ); + + QString fish_execute( const KURL& url, const QString& command ); + QString mimetype( const KURL& url ); + QString lastErrorString(); +}; + +} // namespace Bindings +} // namespace KJSEmbed + +#endif diff --git a/kjsembed/bindings/painter_imp.cpp b/kjsembed/bindings/painter_imp.cpp new file mode 100644 index 00000000..8fa77de0 --- /dev/null +++ b/kjsembed/bindings/painter_imp.cpp @@ -0,0 +1,521 @@ +// -*- c++ -*- + +/* + * Copyright (C) 2003, Richard J. Moore <rich@kde.org> + * + * This 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. + * + * This 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 this library; see the file COPYING.LIB. If not, write to + * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, + * Boston, MA 02110-1301, USA. + */ + +#include <qpainter.h> +#include <qpixmap.h> +#include <qimage.h> +#include <kjsembed/jsopaqueproxy.h> +#include <kjsembed/jsobjectproxy.h> +#include <kjsembed/jsvalueproxy.h> +#include <kjsembed/jsbinding.h> +#include <qfont.h> +#include <kjsembed/global.h> + +#include "painter_imp.h" + +namespace KJSEmbed { +namespace Bindings { + + KJS::Object PainterLoader::createBinding(KJSEmbedPart *jspart, KJS::ExecState *exec, const KJS::List &args) const + { + PainterRef * p = new PainterRef(); + /* + QWidget *w = extractQWidget(exec, args, 0); + QPixmap pix = extractQPixmap(exec, args, 0); + if( w ) + { + p->setDevice(w); + p->setCanDelete(false); + } + else if( !pix.isNull() ) + p->setDevice( new QPixmap(pix) ); + */ + JSOpaqueProxy *prx = new JSOpaqueProxy( p, "Painter" ); + prx->setOwner( JSProxy::JavaScript ); + KJS::Object proxyObj( prx ); + Painter::addBindings( exec, proxyObj ); + return proxyObj; + } + + void PainterLoader::addBindings( KJSEmbedPart *jspart, KJS::ExecState *exec, KJS::Object &proxy ) const + { + Painter::addBindings( exec, proxy ); + } + +PainterRef::PainterRef() +{ + m_device = 0L; + m_painter = new QPainter; + m_canDelete = true; +} +PainterRef::~PainterRef() +{ + kdDebug() << "Painter ref going away..." << endl; + if( m_device && m_canDelete) + delete m_device; + delete m_painter; +} + +QPainter *PainterRef::painter() +{ + return m_painter; +} + +QPaintDevice *PainterRef::device() +{ + return m_device; +} + +void PainterRef::setDevice(QPaintDevice *d) +{ + if( m_device && m_canDelete) + { + delete m_device; + m_device = 0L; + } + m_device = d; + +} + +void Painter::addBindings( KJS::ExecState *exec, KJS::Object &object ) { + + if( !JSProxy::checkType(object, JSProxy::OpaqueProxy, "Painter") ) return; + + JSProxy::MethodTable methods[] = { + { Methodbegin, "begin" }, + { Methodend, "end" }, + { Methodpixmap, "pixmap" }, + { MethodsetPixmap, "setPixmap" }, + { MethodsetPen, "setPen" }, + { Methodpen, "pen" }, + { MethodtextBox, "textBox" }, + { MethodmoveTo, "moveTo" }, + { MethodlineTo, "lineTo" }, + { MethoddrawPoint, "drawPoint" }, + { MethoddrawLine, "drawLine" }, + { MethoddrawRect, "drawRect" }, + { MethoddrawRoundRect, "drawRoundRect" }, + { MethoddrawEllipse, "drawEllipse" }, + { MethoddrawText, "drawText" }, + { MethoddrawArc, "drawArc" }, + { MethoddrawPie, "drawPie" }, + { MethoddrawPixmap, "drawPixmap" }, + { MethoddrawImage, "drawImage" }, + { MethoddrawTiledPixmap, "drawTiledPixmap" }, + { Methodscale, "scale" }, + { Methodshear, "shear" }, + { Methodrotate, "rotate" }, + { Methodtranslate, "translate" }, + { MethodsetFont, "setFont" }, + { Methodfont, "font" }, + { MethodsetBrush, "setBrush" }, + { Methodbrush, "brush" }, + { MethodbackgroundColor, "backgroundColor" }, + { MethodsetBackgroundColor, "setBackgroundColor" }, + { 0, 0 } + }; + + JSProxy::addMethods<Painter>(exec, methods, object ); + +} + +KJS::Value Painter::call( KJS::ExecState *exec, KJS::Object &self, const KJS::List &args ) { + if( !JSProxy::checkType(self, JSProxy::OpaqueProxy, "Painter") ) return KJS::Boolean(false); + + KJS::Value retValue = KJS::Boolean(false); + JSOpaqueProxy *op = JSProxy::toOpaqueProxy( self.imp() ); + + pr = op->toNative<PainterRef>(); + + switch ( mid ) { + case Methodbegin: + { + if ( args.size() == 1 ) { + JSObjectProxy *objp = JSProxy::toObjectProxy(args[0].imp() ); + JSValueProxy *vp = JSProxy::toValueProxy(args[0].imp() ); + JSOpaqueProxy *op = JSProxy::toOpaqueProxy(args[0].imp() ); + if ( objp ) + { + if( objp->widget() ) + { + pr->setDevice( objp->widget() ); + pr->setCanDelete(false); + retValue = KJS::Boolean( begin() ); + } + else + { + QString msg = i18n( "Paintdevice was not a valid widget." ); + throwError(exec,msg); + retValue = KJS::Boolean(false); + } + } + else if ( vp ) + { + QPixmap *p = new QPixmap(vp->toVariant().toPixmap()); + if( p->isNull() ) + { + QString msg = i18n( "Cannto paint to a null pixmap." ).arg( op->typeName() ); + throwError(exec,msg); + retValue = KJS::Boolean(false); + } + else + { + pr->setDevice( p ); + pr->setCanDelete(true); + retValue = KJS::Boolean( begin() ); + } + } + else if ( op && op->typeName() == "QPaintDevice" ) + { + pr->setDevice( op->toNative<QPaintDevice>() ); + pr->setCanDelete(false); + retValue = KJS::Boolean( begin() ); + } + else + { + QString msg = i18n( "Paintdevice of type '%1' is not supported." ).arg( op->typeName() ); + throwError(exec,msg); + retValue = KJS::Boolean(false); + } + } + else + { + QString msg = i18n( "Incorrect number of arguements '%1'." ).arg( args.size() ); + throwError(exec,msg); + retValue = KJS::Boolean(false); + } + break; + } + case Methodend: + retValue = KJS::Boolean( end() ); + break; + case Methodpixmap: + { + retValue = convertToValue(exec, pixmap()); + break; + } + case MethodsetPixmap: + break; + case MethodsetPen: + { + QPen pn = extractQPen(exec, args, 0); + setPen(pn); + break; + } + case Methodpen: + { + retValue = convertToValue(exec, pen()); + break; + } + case MethodtextBox: + { + retValue = convertToValue(exec, textBox(extractQString(exec, args, 0))); + break; + } + case MethodmoveTo: + { + moveTo(extractInt(exec, args, 0), extractInt(exec, args, 1)); + break; + } + case MethodlineTo: + { + lineTo(extractInt(exec, args, 0), extractInt(exec, args, 1)); + break; + } + case MethoddrawPoint: + { + drawPoint(extractInt(exec, args, 0), extractInt(exec, args, 1)); + break; + } + case MethoddrawLine: + { + drawLine(extractInt(exec, args, 0), extractInt(exec, args, 1),extractInt(exec, args, 2), extractInt(exec, args, 3)); + break; + } + case MethoddrawRect: + { + drawRect(extractInt(exec, args, 0), extractInt(exec, args, 1),extractInt(exec, args, 2), extractInt(exec, args, 3)); + break; + } + case MethoddrawRoundRect: + { + drawRoundRect(extractInt(exec, args, 0), extractInt(exec, args, 1),extractInt(exec, args, 2), extractInt(exec, args, 3),extractInt(exec, args, 4), extractInt(exec, args, 5)); + break; + } + case MethoddrawEllipse: + { + drawEllipse(extractInt(exec, args, 0), extractInt(exec, args, 1),extractInt(exec, args, 2), extractInt(exec, args, 3)); + break; + } + case MethoddrawText: + { + drawText(extractInt(exec, args, 0), extractInt(exec, args, 1), extractQString(exec, args, 2)); + break; + } + case MethoddrawArc: + { + drawArc(extractInt(exec, args, 0), extractInt(exec, args, 1),extractInt(exec, args, 2), extractInt(exec, args, 3),extractInt(exec, args, 4), extractInt(exec, args, 5)); + break; + } + case MethoddrawPie: + { + drawPie(extractInt(exec, args, 0), extractInt(exec, args, 1),extractInt(exec, args, 2), extractInt(exec, args, 3),extractInt(exec, args, 4), extractInt(exec, args, 5)); + break; + } + case MethoddrawPixmap: + { + drawPixmap(extractInt(exec, args, 0), extractInt(exec, args, 1), extractQPixmap(exec, args, 2), extractInt(exec, args, 3), extractInt(exec, args, 4), extractInt(exec, args, 5), extractInt(exec, args, 6)); + break; + } + case MethoddrawImage: + { + drawImage( extractInt(exec, args, 0), extractInt(exec, args, 1), extractQImage(exec, args, 2), extractInt(exec, args, 3), extractInt(exec, args, 4), extractInt(exec, args, 5), extractInt(exec, args, 6), extractInt(exec, args, 7) ); + break; + } + case MethoddrawTiledPixmap: + { + drawTiledPixmap(extractInt(exec, args, 0), extractInt(exec, args, 1), extractInt(exec, args, 2), extractInt(exec, args, 3), extractQPixmap(exec, args, 4), extractInt(exec, args, 5), extractInt(exec, args, 6)); + break; + } + case Methodscale: + { + scale(extractDouble(exec, args, 0), extractDouble(exec, args, 1)); + break; + } + case Methodshear: + { + shear(extractDouble(exec, args, 0), extractDouble(exec, args, 1)); + break; + } + case Methodrotate: + { + rotate(extractDouble(exec, args, 0)); + break; + } + case Methodtranslate: + { + translate(extractDouble(exec, args, 0), extractDouble(exec, args, 1)); + break; + } + case MethodsetFont: + { + setFont(extractQFont(exec, args, 0)); + break; + } + case Methodfont: + { + retValue = convertToValue(exec, font()); + break; + } + case MethodsetBrush: + { + pr->painter()->setBrush(extractQBrush(exec, args, 0)); + break; + } + case Methodbrush: + { + retValue = convertToValue(exec, brush()); + break; + } + case MethodbackgroundColor: + { + retValue = convertToValue(exec, backgroundColor()); + break; + } + case MethodsetBackgroundColor: + { + setBackgroundColor(extractQColor(exec, args, 0)); + break; + } + default: + kdWarning() << "Painter has no method " << mid << endl; + break; + } + + //op->setValue(pr, "Painter"); + return retValue; +} + +Painter::Painter( KJS::ExecState *exec, int id ) + : JSProxyImp(exec), mid(id), pr(0) +{ +} + +Painter::~Painter() +{ +} + +bool Painter::begin() +{ + return pr->painter()->begin(pr->device()); +} +bool Painter::begin(QPaintDevice *dev) +{ + return pr->painter()->begin(dev); +} + +bool Painter::end() +{ + return pr->painter()->end(); +} + +QPixmap Painter::pixmap() const +{ + QPixmap *pix = dynamic_cast<QPixmap *>(pr->device()); + if( pix ) + { + return *pix; + } + return QPixmap(); +} + +void Painter::setPen( const QPen& pn ) +{ + pr->painter()->setPen(pn); +} + +QPen Painter::pen() const +{ + return pr->painter()->pen(); +} + +QRect Painter::textBox(const QString &text) +{ + QFontMetrics fnt = pr->painter()->fontMetrics(); + return fnt.boundingRect(text); +} + +void Painter::moveTo( int x, int y ) +{ + pr->painter()->moveTo( x, y ); +} + +void Painter::lineTo( int x, int y ) +{ + pr->painter()->lineTo( x, y ); +} + +void Painter::drawPoint( int x, int y ) +{ + pr->painter()->drawPoint( x, y ); +} + +void Painter::drawLine( int x1, int y1, int x2, int y2 ) +{ + pr->painter()->drawLine( x1, y1, x2, y2 ); +} + +void Painter::drawRect( int x, int y, int w, int h ) +{ + pr->painter()->drawRect( x, y, w, h ); +} + +void Painter::drawRoundRect( int x, int y, int w, int h, int xrnd, int yrnd ) +{ + pr->painter()->drawRoundRect( x, y, w, h, xrnd, yrnd ); +} + +void Painter::drawEllipse( int x, int y, int w, int h ) +{ + pr->painter()->drawEllipse( x, y, w, h ); +} + +void Painter::drawText( int x, int y, const QString &txt ) +{ + pr->painter()->drawText( x, y, txt ); +} + +void Painter::drawArc ( int x, int y, int w, int h, int a, int alen ) +{ + pr->painter()->drawArc( x, y, w, h, a, alen ); +} +void Painter::drawPie ( int x, int y, int w, int h, int a, int alen ) +{ + pr->painter()->drawPie( x, y, w, h, a, alen); +} +void Painter::drawPixmap ( int x, int y, const QPixmap & pixmap, int sx, int sy, int sw, int sh ) +{ + pr->painter()->drawPixmap( x, y, pixmap, sx, sy, sw, sh ); +} +void Painter::drawImage ( int x, int y, const QImage &image, int sx , int sy, int sw , int sh, int conversionFlags) +{ + pr->painter()->drawImage( x, y, image, sx, sy, sw, sh, conversionFlags ); +} +void Painter::drawTiledPixmap ( int x, int y, int w, int h, const QPixmap & pixmap, int sx, int sy ) +{ + pr->painter()->drawTiledPixmap( x, y, w, h, pixmap, sx, sy ); +} + +void Painter::scale ( double sx, double sy ) +{ + pr->painter()->scale( sx,sy ); +} +void Painter::shear ( double sh, double sv ) +{ + pr->painter()->shear( sh, sv ); +} +void Painter::rotate ( double a ) +{ + pr->painter()->rotate( a ); +} +void Painter::translate ( double dx, double dy ) +{ + pr->painter()->translate( dx, dy ); +} + +void KJSEmbed::Bindings::Painter::setFont( const QFont & font ) +{ + pr->painter()->setFont(font); +} + +QFont KJSEmbed::Bindings::Painter::font( ) const +{ + return pr->painter()->font(); +} + +QColor KJSEmbed::Bindings::Painter::backgroundColor( ) const +{ + return pr->painter()->backgroundColor(); +} + +void KJSEmbed::Bindings::Painter::setBackgroundColor( const QColor & color ) +{ + pr->painter()->setBackgroundColor(color); +} + +} // namespace Bindings +} // namespace KJSEmbed + + +void KJSEmbed::Bindings::Painter::setBrush( const QColor & brush ) +{ + pr->painter()->setBrush(brush); +} + +QColor KJSEmbed::Bindings::Painter::brush( ) const +{ + return pr->painter()->brush().color(); +} +// Local Variables: +// c-basic-offset: 4 +// End: + + diff --git a/kjsembed/bindings/painter_imp.h b/kjsembed/bindings/painter_imp.h new file mode 100644 index 00000000..0660a7ba --- /dev/null +++ b/kjsembed/bindings/painter_imp.h @@ -0,0 +1,127 @@ +// -*- c++ -*- + +/* + * Copyright (C) 2003, Richard J. Moore <rich@kde.org> + * + * This 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. + * + * This 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 this library; see the file COPYING.LIB. If not, write to + * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, + * Boston, MA 02110-1301, USA. + */ + +#ifndef KJSEMBED_PAINTER_IMP_H +#define KJSEMBED_PAINTER_IMP_H + +#include <kjsembed/jsbindingbase.h> +#include <kjsembed/jsproxy_imp.h> +#include <qpen.h> +#include <qpainter.h> + +class QPixmap; + +namespace KJSEmbed { +namespace Bindings { + + class PainterLoader : public JSBindingBase + { + public: + KJS::Object createBinding(KJSEmbedPart *jspart, KJS::ExecState *exec, const KJS::List &args) const; + void addBindings( KJSEmbedPart *jspart, KJS::ExecState *exec, KJS::Object &proxy) const; + }; + + +class PainterRef +{ + public: + PainterRef(); + ~PainterRef(); + + QPainter *painter(); + + QPaintDevice *device(); + void setDevice(QPaintDevice *d); + + void setCanDelete(bool can ) {m_canDelete = can;} + bool canDelete() const { return m_canDelete;} + + private: + QPainter *m_painter; + QPaintDevice *m_device; + bool m_canDelete; +}; + +/** + * JSProxyImp binding for painting on a QPixmap. + * + * @author Richard Moore, rich@kde.org + */ + +class Painter : public JSProxyImp +{ + /** Identifiers for the methods provided by this class. */ + enum MethodId {Methodbegin, Methodend, Methodpixmap, MethodsetPixmap, MethodsetPen, Methodpen, MethodtextBox, MethodmoveTo, MethodlineTo, MethoddrawPoint, MethoddrawLine, MethoddrawRect, MethoddrawRoundRect, MethoddrawEllipse, MethoddrawText, MethoddrawArc, MethoddrawPie, MethoddrawPixmap, MethoddrawImage, MethoddrawTiledPixmap, Methodscale, Methodshear, Methodrotate, Methodtranslate, MethodsetFont, Methodfont, MethodsetBrush, Methodbrush, MethodbackgroundColor, MethodsetBackgroundColor}; +public: + Painter( KJS::ExecState *exec, int id ); + virtual ~Painter(); + + static void addBindings( KJS::ExecState *exec, KJS::Object &object ); + + /** Returns true iff this object implements the call function. */ + virtual bool implementsCall() const { return true; } + + /** Invokes the call function. */ + virtual KJS::Value call( KJS::ExecState *exec, KJS::Object &self, const KJS::List &args ); +private: + + bool begin(); + bool begin(QPaintDevice *dev); + bool end(); + QPixmap pixmap() const; + void setPen( const QPen& pn); + QPen pen() const; + QRect textBox(const QString &text); + void moveTo( int x, int y ); + void lineTo( int x, int y ); + void drawPoint( int x, int y ); + void drawLine( int x1, int y1, int x2, int y2 ); + void drawRect( int x, int y, int w, int h ); + void drawRoundRect( int x, int y, int w, int h, int, int); + void drawEllipse( int x, int y, int w, int h ); + void drawText( int x, int y, const QString &txt ); + void drawArc( int x, int y, int w, int h, int a, int alen ); + void drawPie( int x, int y, int w, int h, int a, int alen ); + void drawPixmap ( int x, int y, const QPixmap &pixmap, int sx, int sy, int sw, int sh ); + void drawImage ( int x, int y, const QImage &image, int sx, int sy, int sw, int sh, int conversionFlags ); + void drawTiledPixmap ( int x, int y, int w, int h, const QPixmap &pixmap, int sx, int sy); + void scale ( double sx, double sy ); + void shear ( double sh, double sv ); + void rotate ( double a ); + void translate ( double dx, double dy ); + void setFont( const QFont &font); + QFont font() const; + void setBrush( const QColor &brush ); + QColor brush() const; + QColor backgroundColor() const; + void setBackgroundColor(const QColor &color); + +private: + int mid; + PainterRef *pr; // temps now + +}; + +} // namespace Bindings +} // namespace KJSEmbed + +#endif // KJSEMBED_PAINTER_IMP_H + diff --git a/kjsembed/bindings/pen_imp.cpp b/kjsembed/bindings/pen_imp.cpp new file mode 100644 index 00000000..67ada965 --- /dev/null +++ b/kjsembed/bindings/pen_imp.cpp @@ -0,0 +1,127 @@ +// -*- c++ -*- + +/* + * Copyright (C) 2003, Richard J. Moore <rich@kde.org> + * + * This 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. + * + * This 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 this library; see the file COPYING.LIB. If not, write to + * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, + * Boston, MA 02110-1301, USA. + */ + +#include <qpainter.h> +#include <qpixmap.h> +#include <kjsembed/global.h> +#include <qpen.h> +#include "pen_imp.h" +#include <kjsembed/jsvalueproxy.h> +#include <kjsembed/jsbinding.h> + +namespace KJSEmbed { +namespace Bindings { + +Pen::Pen( KJS::ExecState *exec, int id ) + : JSProxyImp(exec), mid(id) +{ +} + +Pen::~Pen() +{ +} +void Pen::addBindings( KJS::ExecState *exec, KJS::Object &object ) { + + if( !JSProxy::checkType(object, JSProxy::ValueProxy, "QPen") ) return; + + JSProxy::MethodTable methods[] = { + { Methodwidth, "width"}, + { MethodsetWidth, "setWidth"}, + { MethodColor, "color"}, + { MethodsetColor, "setColor"}, + { 0, 0 } + }; + + JSProxy::addMethods<Pen>(exec, methods, object ); + + JSProxy::EnumTable enums[] = { + // PenStyle + { "NoPen", 0 }, + { "SolidLine", 1 }, + { "DashLine", 2 }, + { "DotLine", 3 }, + { "DashDotLine", 4 }, + { "DashDotDotLine", 5 }, + { "MPenStyle", 6 }, + // Pen Join Style + { "MiterJoin", 7 }, + { "BevelJoin", 8 }, + { "RoundJoin", 9 }, + { "MPenJoinStyle", 10 }, + // Pen Cap Style + { "FlatCap", 11}, + { "SquareCap", 12 }, + { "RoundCap", 13 }, + { "MPenCapStyle", 14}, + + { 0, 0 } + }; + + JSProxy::addEnums(exec, enums, object); +} + +KJS::Value Pen::call( KJS::ExecState *exec, KJS::Object &self, const KJS::List &args ) { + + if( !JSProxy::checkType(self, JSProxy::ValueProxy, "QPen") ) return KJS::Value(); + JSValueProxy *op = JSProxy::toValueProxy( self.imp() ); + QPen pen = op->toVariant().toPen(); + + KJS::Value retValue = KJS::Value(); + switch ( mid ) { + case Methodwidth: + { + return KJS::Number((int) pen.width() ); + break; + } + case MethodsetWidth: + { + uint w = extractUInt(exec, args, 0); + pen.setWidth(w); + break; + } + case MethodColor: + { + return convertToValue(exec, pen.color()); + break; + } + case MethodsetColor: + { + QColor color = extractQColor(exec, args, 0); + pen.setColor(color); + break; + } + default: + kdWarning() << "Pen has no method " << mid << endl; + break; + } + + op->setValue(pen); + return retValue; +} + +} // namespace Bindings +} // namespace KJSEmbed + +// Local Variables: +// c-basic-offset: 4 +// End: + + diff --git a/kjsembed/bindings/pen_imp.h b/kjsembed/bindings/pen_imp.h new file mode 100644 index 00000000..2068a6a5 --- /dev/null +++ b/kjsembed/bindings/pen_imp.h @@ -0,0 +1,57 @@ +// -*- c++ -*- + +/* + * Copyright (C) 2003, Richard J. Moore <rich@kde.org> + * + * This 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. + * + * This 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 this library; see the file COPYING.LIB. If not, write to + * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, + * Boston, MA 02110-1301, USA. + */ + +#ifndef KJSEMBED_PEN_IMP_H +#define KJSEMBED_PEN_IMP_H + +#include <kjsembed/jsproxy_imp.h> + + +namespace KJSEmbed { +namespace Bindings { + +class Pen : public JSProxyImp +{ + + /** Identifiers for the methods provided by this class. */ + enum MethodId { Methodwidth, MethodsetWidth, MethodColor, MethodsetColor }; +public: + Pen( KJS::ExecState *exec, int id ); + virtual ~Pen(); + + static void addBindings( KJS::ExecState *exec, KJS::Object &object ); + + /** Returns true iff this object implements the call function. */ + virtual bool implementsCall() const { return true; } + + /** Invokes the call function. */ + virtual KJS::Value call( KJS::ExecState *exec, KJS::Object &self, const KJS::List &args ); + + +private: + int mid; +}; + +} // namespace Bindings +} // namespace KJSEmbed + +#endif // KJSEMBED_PEN_IMP_H + diff --git a/kjsembed/bindings/pixmap_imp.cpp b/kjsembed/bindings/pixmap_imp.cpp new file mode 100644 index 00000000..68e93658 --- /dev/null +++ b/kjsembed/bindings/pixmap_imp.cpp @@ -0,0 +1,180 @@ +// -*- c++ -*- + +/* + * Copyright (C) 2003, Richard J. Moore <rich@kde.org> + * + * This 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. + * + * This 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 this library; see the file COPYING.LIB. If not, write to + * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, + * Boston, MA 02110-1301, USA. + */ + +#include <qpixmap.h> +#include <qbitmap.h> + +#include <kjsembed/global.h> +#include <kjsembed/jsvalueproxy.h> +#include <kjsembed/jsbinding.h> +#include <qvariant.h> + +#include "pixmap_imp.h" + +namespace KJSEmbed { +namespace Bindings { + +Pixmap::Pixmap( KJS::ExecState *exec, int id ) + : JSProxyImp(exec), mid(id) +{ +} + +Pixmap::~Pixmap() +{ +} + +void Pixmap::addBindings( KJS::ExecState *exec, KJS::Object &object ) { + + if( !JSProxy::checkType( object, JSProxy::ValueProxy, "QPixmap") ) + return; + + JSProxy::MethodTable methods[] = { + { MethodisNull, "isNull" }, + { Methodwidth, "width" }, + { Methodheight, "height" }, + { Methodsize, "size" }, + { Methodrect, "rect" }, + { Methoddepth, "depth" }, + { Methodresize, "resize" }, + { Methodfill, "fill" }, + { Methodmask, "mask" }, + { MethodsetMask, "setMask" }, + { MethodcreateHeuristicMask, "createHeuristicMask" }, + { MethodgrabWindow, "grabWindow" }, + { 0, 0 } + }; + + JSProxy::addMethods<Pixmap>(exec, methods, object); + +} + +KJS::Value Pixmap::call( KJS::ExecState *exec, KJS::Object &self, const KJS::List &args ) { + + if( !JSProxy::checkType( self, JSProxy::ValueProxy, "QPixmap") ) + return KJS::Value(); + + JSValueProxy *op = JSProxy::toValueProxy( self.imp() ); + pix = op->toVariant().toPixmap(); + + KJS::Value retValue = KJS::Value(); + switch ( mid ) { + case Methodwidth: + retValue = KJS::Number(width()); + break; + case Methodheight: + retValue = KJS::Number(height()); + break; + case Methoddepth: + retValue = KJS::Number(depth()); + break; + case MethodisNull: + retValue = KJS::Boolean(isNull()); + break; + case Methodsize: + retValue = convertToValue(exec, size()); + break; + case Methodrect: + retValue = convertToValue(exec, rect()); + break; + case Methodresize: + { + if( args.size() == 2) + resize(extractInt(exec, args, 0), extractInt(exec, args, 1)); + else if( args.size() == 1) + resize(extractQSize(exec, args, 0) ); + break; + } + case Methodfill: + fill( extractQColor(exec, args, 0)); + break; + case Methodmask: + { + retValue = convertToValue(exec, mask() ); + break; + } + case MethodsetMask: + { + setMask(extractQPixmap(exec, args, 0)); + break; + } + case MethodcreateHeuristicMask: + { + retValue = convertToValue(exec, createHeuristicMask(extractBool(exec, args, 0))); + break; + } + case MethodgrabWindow: + { + int winid = extractInt(exec, args,0); + int x = extractInt(exec, args,1); + int y = extractInt(exec, args,2); + int w = extractInt(exec, args,3); + int h = extractInt(exec, args,4); + grabWindow(winid,x,y,w,h); + break; + } + default: + kdWarning() << "Image has no method " << mid << endl; + break; + } + + op->setValue(pix); + return retValue; +} + +void Pixmap::resize( int w, int h ) +{ + pix.resize( w, h ); +} + +void Pixmap::resize( const QSize &size ) +{ + pix.resize( size ); +} + +void Pixmap::fill( const QColor &c ) +{ + pix.fill( c ); +} + +void Pixmap::grabWindow(int winID, int x, int y, int w, int h) +{ + pix = QPixmap::grabWindow((WId)winID, x, y, w, h); +} + +QPixmap Pixmap::mask() +{ + return *(pix.mask()); +} +void Pixmap::setMask(const QPixmap& mask) +{ + QBitmap bm; + bm = mask; + pix.setMask(bm); +} + +QPixmap Pixmap::createHeuristicMask ( bool clipTight ) +{ + return (QPixmap)pix.createHeuristicMask(clipTight); +} + +} // namespace KJSEmbed::Bindings +} // namespace KJSEmbed + diff --git a/kjsembed/bindings/pixmap_imp.h b/kjsembed/bindings/pixmap_imp.h new file mode 100644 index 00000000..994c2699 --- /dev/null +++ b/kjsembed/bindings/pixmap_imp.h @@ -0,0 +1,87 @@ +// -*- c++ -*- + +/* + * Copyright (C) 2003, Richard J. Moore <rich@kde.org> + * + * This 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. + * + * This 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 this library; see the file COPYING.LIB. If not, write to + * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, + * Boston, MA 02110-1301, USA. + */ + +#ifndef KJSEMBED_PIXMAP_IMP_H +#define KJSEMBED_PIXMAP_IMP_H + +#include <kjsembed/jsobjectproxy_imp.h> + +#include <qpixmap.h> + +namespace KJSEmbed { +namespace Bindings { + +/** + * QObject Binding for QPixmap. + * + * @author Richard Moore, rich@kde.org + * @version $Id$ + */ +class Pixmap : public JSProxyImp +{ + + /** Identifiers for the methods provided by this class. */ + enum MethodId { MethodisNull, Methodwidth, Methodheight, Methodsize, Methodrect, Methoddepth, Methodresize, Methodfill, Methodmask, MethodsetMask, MethodcreateHeuristicMask, MethodgrabWindow }; + +public: + Pixmap( KJS::ExecState *exec, int id ); + virtual ~Pixmap(); + + static void addBindings( KJS::ExecState *exec, KJS::Object &object ); + + /** Returns true iff this object implements the call function. */ + virtual bool implementsCall() const { return true; } + + /** Invokes the call function. */ + virtual KJS::Value call( KJS::ExecState *exec, KJS::Object &self, const KJS::List &args ); + + + +private: + bool isNull() const { return pix.isNull(); } + + int width() const { return pix.width(); } + int height() const { return pix.height(); } + QSize size() const { return pix.size(); } + QRect rect() const { return pix.rect(); } + + int depth() const { return pix.depth(); } + + void resize( int w, int h ); + void resize( const QSize &size ); + void fill( const QColor &color ); + + QPixmap mask(); + void setMask(const QPixmap& mask); + QPixmap createHeuristicMask ( bool clipTight ); + + // Image Capture + void grabWindow(int winID, int x =0, int y = 0, int w = -1, int h = -1); + +private: + int mid; + QPixmap pix; +}; + +} // namespace +} // namespace + +#endif // KJSEMBED_PIXMAP_IMP_H diff --git a/kjsembed/bindings/point_imp.cpp b/kjsembed/bindings/point_imp.cpp new file mode 100644 index 00000000..9eeb5c6a --- /dev/null +++ b/kjsembed/bindings/point_imp.cpp @@ -0,0 +1,92 @@ +// -*- c++ -*- + +/* + * Copyright (C) 2004 Ian Reinhart Geiser <geiseri@kde.org> + * + * This 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. + * + * This 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 this library; see the file COPYING.LIB. If not, write to + * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, + * Boston, MA 02110-1301, USA. + */ + +#include <kjsembed/global.h> +#include "point_imp.h" +#include <qpoint.h> +#include <kjsembed/jsvalueproxy.h> +#include <kjsembed/jsbinding.h> + +namespace KJSEmbed { +namespace Bindings { + + Point::Point( KJS::ExecState *exec, int id ) + : JSProxyImp(exec), mid(id) + { + } + + Point::~Point() + { + } + void Point::addBindings( KJS::ExecState *exec, KJS::Object &object ) { + + if( !JSProxy::checkType(object, JSProxy::ValueProxy, "QPoint") ) return; + + JSProxy::MethodTable methods[] = { + { Methodx, "x"}, + { MethodsetX, "setX"}, + { Methody, "y"}, + { MethodsetY, "setY"}, + { MethodmanhattanLength, "manhattanLength"}, + { 0, 0 } + }; + JSProxy::addMethods<Point>(exec, methods, object); + + } + + KJS::Value Point::call( KJS::ExecState *exec, KJS::Object &self, const KJS::List &args ) { + if( !JSProxy::checkType(self, JSProxy::ValueProxy, "QPoint") ) return KJS::Value(); + JSValueProxy *vp = JSProxy::toValueProxy( self.imp() ); + KJS::Value retValue = KJS::Value(); + QPoint val = vp->toVariant().toPoint(); + + switch ( mid ) { + case Methodx: + retValue = KJS::Number(val.x()); + break; + case MethodsetX: + val.setX(extractInt(exec,args,0)); + break; + case Methody: + retValue = KJS::Number(val.y()); + break; + case MethodsetY: + val.setY(extractInt(exec,args,0)); + break; + case MethodmanhattanLength: + retValue = KJS::Number(val.manhattanLength()); + break; + default: + QString msg = i18n( "Point has no method %1" ).arg(mid); + return throwError(exec, msg); + break; + } + + vp->setValue(val); + return retValue; + } + +} // namespace Bindings +} // namespace KJSEmbed + +// Local Variables: +// c-basic-offset: 4 +// End: diff --git a/kjsembed/bindings/point_imp.h b/kjsembed/bindings/point_imp.h new file mode 100644 index 00000000..950cce7d --- /dev/null +++ b/kjsembed/bindings/point_imp.h @@ -0,0 +1,56 @@ +// -*- c++ -*- + +/* + * Copyright (C) 2004 Ian Reinhart Geiser <geiseri@kde.org> + * + * This 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. + * + * This 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 this library; see the file COPYING.LIB. If not, write to + * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, + * Boston, MA 02110-1301, USA. + */ + +#ifndef KJSEMBED_POINT_IMP_H +#define KJSEMBED_POINT_IMP_H + +#include <kjsembed/jsproxy_imp.h> + + +namespace KJSEmbed { +namespace Bindings { + + class Point : public JSProxyImp + { + + /** Identifiers for the methods provided by this class. */ + enum MethodId { Methodx, MethodsetX, Methody, MethodsetY, MethodmanhattanLength }; + public: + Point( KJS::ExecState *exec, int id ); + virtual ~Point(); + + static void addBindings( KJS::ExecState *exec, KJS::Object &object ); + + /** Returns true iff this object implements the call function. */ + virtual bool implementsCall() const { return true; } + + /** Invokes the call function. */ + virtual KJS::Value call( KJS::ExecState *exec, KJS::Object &self, const KJS::List &args ); + + + private: + int mid; + }; + +} // namespace Bindings +} // namespace KJSEmbed + +#endif // KJSEMBED_POINT_IMP_H diff --git a/kjsembed/bindings/rect_imp.cpp b/kjsembed/bindings/rect_imp.cpp new file mode 100644 index 00000000..82b5268b --- /dev/null +++ b/kjsembed/bindings/rect_imp.cpp @@ -0,0 +1,111 @@ +// -*- c++ -*- + +/* + * Copyright (C) 2004 Ian Reinhart Geiser <geiseri@kde.org> + * + * This 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. + * + * This 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 this library; see the file COPYING.LIB. If not, write to + * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, + * Boston, MA 02110-1301, USA. + */ + +#include <kjsembed/global.h> +#include "rect_imp.h" +#include <qrect.h> +#include <kjsembed/jsvalueproxy.h> +#include <kjsembed/jsbinding.h> + +namespace KJSEmbed { +namespace Bindings { + + Rect::Rect( KJS::ExecState *exec, int id ) + : JSProxyImp(exec), mid(id) + { + } + + Rect::~Rect() + { + } + void Rect::addBindings( KJS::ExecState *exec, KJS::Object &object ) { + + if( !JSProxy::checkType(object, JSProxy::ValueProxy, "QRect") ) return; + + JSProxy::MethodTable methods[] = { + { Methodx, "x" }, + { MethodsetX, "setX" }, + { Methody, "y" }, + { MethodsetY, "setY" }, + { Methodheight, "height" }, + { MethodsetHeight, "setHeight" }, + { Methodwidth, "width" }, + { MethodsetWidth,"setWidth" }, + { Methodcontains,"contains" }, + { 0, 0 } + }; + + JSProxy::addMethods<Rect>(exec, methods, object ); + + } + + KJS::Value Rect::call( KJS::ExecState *exec, KJS::Object &self, const KJS::List &args ) { + if( !JSProxy::checkType(self, JSProxy::ValueProxy, "QRect") ) return KJS::Value(); + + KJS::Value retValue = KJS::Value(); + JSValueProxy *vp = JSProxy::toValueProxy( self.imp() ); + + QRect val = vp->toVariant().toRect(); + + switch ( mid ) { + case Methodx: + retValue = KJS::Number(val.x()); + break; + case MethodsetX: + val.setX(extractInt(exec, args, 0)); + break; + case Methody: + retValue = KJS::Number(val.y()); + break; + case MethodsetY: + val.setY(extractInt(exec, args, 0)); + break; + case Methodheight: + retValue = KJS::Number(val.height()); + break; + case MethodsetHeight: + val.setHeight(extractInt(exec, args, 0)); + break; + case Methodwidth: + retValue = KJS::Number(val.width()); + break; + case MethodsetWidth: + val.setWidth(extractInt(exec, args, 0)); + break; + case Methodcontains: + retValue = convertToValue( exec, val.contains( extractQRect(exec, args, 0), extractBool(exec, args, 1)) ); + break; + default: + QString msg = i18n( "Rect has no method %1" ).arg(mid); + return throwError(exec, msg); + break; + } + + vp->setValue(val); + return retValue; + } + +} // namespace Bindings +} // namespace KJSEmbed + +// Local Variables: +// c-basic-offset: 4 +// End: diff --git a/kjsembed/bindings/rect_imp.h b/kjsembed/bindings/rect_imp.h new file mode 100644 index 00000000..16910e4e --- /dev/null +++ b/kjsembed/bindings/rect_imp.h @@ -0,0 +1,56 @@ +// -*- c++ -*- + +/* + * Copyright (C) 2004 Ian Reinhart Geiser <geiseri@kde.org> + * + * This 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. + * + * This 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 this library; see the file COPYING.LIB. If not, write to + * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, + * Boston, MA 02110-1301, USA. + */ + +#ifndef KJSEMBED_RECT_IMP_H +#define KJSEMBED_RECT_IMP_H + +#include <kjsembed/jsproxy_imp.h> + + +namespace KJSEmbed { +namespace Bindings { + + class Rect : public JSProxyImp + { + + /** Identifiers for the methods provided by this class. */ + enum MethodId { Methodx, MethodsetX, Methody, MethodsetY, Methodheight, MethodsetHeight, Methodwidth, MethodsetWidth, Methodcontains }; + public: + Rect( KJS::ExecState *exec, int id ); + virtual ~Rect(); + + static void addBindings( KJS::ExecState *exec, KJS::Object &object ); + + /** Returns true iff this object implements the call function. */ + virtual bool implementsCall() const { return true; } + + /** Invokes the call function. */ + virtual KJS::Value call( KJS::ExecState *exec, KJS::Object &self, const KJS::List &args ); + + + private: + int mid; + }; + +} // namespace Bindings +} // namespace KJSEmbed + +#endif // KJSEMBED_RECT_IMP_H diff --git a/kjsembed/bindings/size_imp.cpp b/kjsembed/bindings/size_imp.cpp new file mode 100644 index 00000000..09c01427 --- /dev/null +++ b/kjsembed/bindings/size_imp.cpp @@ -0,0 +1,133 @@ +// -*- c++ -*- + +/* + * Copyright (C) 2004 Ian Reinhart Geiser <geiseri@kde.org> + * + * This 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. + * + * This 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 this library; see the file COPYING.LIB. If not, write to + * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, + * Boston, MA 02110-1301, USA. + */ + +#include <kjsembed/global.h> +#include "size_imp.h" +#include <qsize.h> +#include <kjsembed/jsvalueproxy.h> +#include <kjsembed/jsbinding.h> + +namespace KJSEmbed { +namespace Bindings { + +Size::Size( KJS::ExecState *exec, int id ) + : JSProxyImp(exec), mid(id) +{ +} + +Size::~Size() +{ +} +void Size::addBindings( KJS::ExecState *exec, KJS::Object &object ) { + + if( !JSProxy::checkType(object, JSProxy::ValueProxy, "QSize") ) return; + + JSProxy::MethodTable methods[] = { + { Methodwidth, "width"}, + { MethodsetWidth, "setWidth"}, + { MethodHeight, "height"}, + { MethodsetHeight, "setHeight"}, + { Methodscale, "scale"}, + { Methodtranspose, "transpose"}, + { MethodexpandedTo, "expandedTo"}, + { MethodboundedTo, "boundedTo"}, + { 0, 0 } + }; + + JSProxy::addMethods<Size>(exec, methods, object ); + // + // Define the enum constants + // + + JSProxy::EnumTable enums[] = { + { "ScaleFree", (int)QSize::ScaleFree }, + { "ScaleMin", (int)QSize::ScaleMin }, + { "ScaleMax", (int)QSize::ScaleMax }, + { 0, 0 } + }; + + JSProxy::addEnums(exec, enums, object); +} + +KJS::Value Size::call( KJS::ExecState *exec, KJS::Object &self, const KJS::List &args ) { + if( !JSProxy::checkType(self, JSProxy::ValueProxy, "QSize") ) return KJS::Value(); + KJS::Value retValue = KJS::Value(); + JSValueProxy *vp = JSProxy::toValueProxy( self.imp() ); + QSize val = vp->toVariant().toSize(); + + switch ( mid ) { + case Methodwidth: + retValue = KJS::Number(val.width()); + break; + case MethodsetWidth: + val.setWidth(extractInt(exec,args,0)); + break; + case MethodHeight: + retValue = KJS::Number(val.height()); + break; + case MethodsetHeight: + val.setHeight(extractInt(exec,args,0)); + break; + case Methodscale: + { + if( args.size() == 2 ) { + QSize sz = extractQSize(exec, args, 0); + int mode = extractInt(exec, args, 1); + val.scale(sz, (QSize::ScaleMode)mode); + } else { + int x = extractInt(exec, args, 0); + int y = extractInt(exec, args, 1); + int mode = extractInt(exec, args, 2); + val.scale(x,y, (QSize::ScaleMode)mode); + } + break; + } + case Methodtranspose: + val.transpose(); + break; + case MethodexpandedTo: + { + QSize sz = extractQSize(exec, args, 0); + retValue = convertToValue( exec, val.expandedTo(sz) ); + break; + } + case MethodboundedTo: + { + QSize sz = extractQSize(exec, args, 0); + retValue = convertToValue( exec, val.boundedTo(sz) ); + break; + } + default: + QString msg = i18n( "Size has no method %1" ).arg(mid); + return throwError(exec, msg); + break; + } + + vp->setValue(val); + return retValue; +} + +} // namespace Bindings +} // namespace KJSEmbed + +// Local Variables: +// c-basic-offset: 4 +// End: diff --git a/kjsembed/bindings/size_imp.h b/kjsembed/bindings/size_imp.h new file mode 100644 index 00000000..9a1fb4eb --- /dev/null +++ b/kjsembed/bindings/size_imp.h @@ -0,0 +1,56 @@ +// -*- c++ -*- + +/* + * Copyright (C) 2004 Ian Reinhart Geiser <geiseri@kde.org> + * + * This 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. + * + * This 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 this library; see the file COPYING.LIB. If not, write to + * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, + * Boston, MA 02110-1301, USA. + */ + +#ifndef KJSEMBED_SIZE_IMP_H +#define KJSEMBED_SIZE_IMP_H + +#include <kjsembed/jsproxy_imp.h> + + +namespace KJSEmbed { +namespace Bindings { + + class Size : public JSProxyImp + { + + /** Identifiers for the methods provided by this class. */ + enum MethodId { Methodwidth, MethodsetWidth, MethodHeight, MethodsetHeight, Methodscale, Methodtranspose, MethodexpandedTo, MethodboundedTo }; + public: + Size( KJS::ExecState *exec, int id ); + virtual ~Size(); + + static void addBindings( KJS::ExecState *exec, KJS::Object &object ); + + /** Returns true iff this object implements the call function. */ + virtual bool implementsCall() const { return true; } + + /** Invokes the call function. */ + virtual KJS::Value call( KJS::ExecState *exec, KJS::Object &self, const KJS::List &args ); + + + private: + int mid; + }; + +} // namespace Bindings +} // namespace KJSEmbed + +#endif // KJSEMBED_SIZE_IMP_H diff --git a/kjsembed/bindings/sql_imp.cpp b/kjsembed/bindings/sql_imp.cpp new file mode 100644 index 00000000..31c7f53c --- /dev/null +++ b/kjsembed/bindings/sql_imp.cpp @@ -0,0 +1,310 @@ +// -*- c++ -*- + +/* + * Copyright (C) 2003, Ian Reinhart Geiser <geiseri@kde.org> + * + * This 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. + * + * This 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 this library; see the file COPYING.LIB. If not, write to + * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, + * Boston, MA 02110-1301, USA. + */ + +#include <kjsembed/global.h> +#include <qsqldatabase.h> +#include <qsqlquery.h> +#include <qsqlerror.h> +#include "sql_imp.h" + + + +namespace KJSEmbed { +namespace Bindings { + +SqlDatabase::SqlDatabase( QObject *parent, const char *name): BindingObject(parent, name) +{ + connectionName = "defaultConnection"; + setJSClassName( "SqlDatabase" ); +} +SqlDatabase::~SqlDatabase() +{ + QSqlDatabase::removeDatabase(connectionName); +} +bool SqlDatabase::addDatabase ( const QString &type, const QString &conn ) +{ + connectionName = conn; + QSqlDatabase *db = QSqlDatabase::addDatabase(type, connectionName); + if ( !db ) + return false; + return true; +} +QStringList SqlDatabase::drivers () +{ + return QSqlDatabase::drivers(); +} +bool SqlDatabase::open ( ) +{ + QSqlDatabase *db = QSqlDatabase::database(connectionName,false); + if ( db ) + return db->open(); + return false; +} +bool SqlDatabase::open ( const QString &user, const QString &password ) +{ + QSqlDatabase *db = QSqlDatabase::database(connectionName,false); + if ( db ) + return db->open(user, password); + return false; +} +void SqlDatabase::close () +{ + QSqlDatabase *db = QSqlDatabase::database(connectionName,false); + if ( db ) + { + db->close(); + } +} +bool SqlDatabase::isOpen () +{ + QSqlDatabase *db = QSqlDatabase::database(connectionName,false); + if ( db ) + return db->isOpen(); + return false; +} +bool SqlDatabase::isOpenError () +{ + QSqlDatabase *db = QSqlDatabase::database(connectionName,false); + if ( db ) + return db->isOpenError(); + return true; +} +QStringList SqlDatabase::tables () +{ + QSqlDatabase *db = QSqlDatabase::database(connectionName,false); + if ( db ) + return db->tables(); + return QStringList(); +} +SqlQuery *SqlDatabase::exec (const QString &query ) +{ + QSqlDatabase *db = QSqlDatabase::database(connectionName,false); + if ( db ) + { + kdDebug() <<" exec query " << query << endl; + SqlQuery *qw = new SqlQuery(this, "query",db->exec( query )); + //JSFactory::instance()->addType( "SqlQuery" ); + kdDebug() <<" size " << qw->size() << endl; + kdDebug() <<" valid " << qw->isValid() << endl; + return qw; + } + return 0L; +} +QString SqlDatabase::lastError () const +{ + QSqlDatabase *db = QSqlDatabase::database(connectionName,false); + if ( db ) + { + return db->lastError().text(); + } + return "No Database Driver Loaded"; +} +bool SqlDatabase::transaction () +{ + QSqlDatabase *db = QSqlDatabase::database(connectionName,false); + if ( db ) + return db->transaction(); + return false; +} +bool SqlDatabase::commit () +{ + QSqlDatabase *db = QSqlDatabase::database(connectionName,false); + if ( db ) + return db->commit(); + return false; +} +bool SqlDatabase::rollback () +{ + QSqlDatabase *db = QSqlDatabase::database(connectionName,false); + if ( db ) + return db->rollback(); + return false; +} +void SqlDatabase::setDatabaseName (const QString &name ) +{ + QSqlDatabase *db = QSqlDatabase::database(connectionName,false); + if ( db ) + db->setDatabaseName(name); +} +void SqlDatabase::setUserName (const QString &name ) +{ + QSqlDatabase *db = QSqlDatabase::database(connectionName,false); + if ( db ) + db->setUserName(name); +} +void SqlDatabase::setPassword (const QString &password ) +{ + QSqlDatabase *db = QSqlDatabase::database(connectionName,false); + if ( db ) + db->setPassword(password); +} +void SqlDatabase::setHostName (const QString &host ) +{ + QSqlDatabase *db = QSqlDatabase::database(connectionName,false); + if ( db ) + db->setHostName(host); +} +void SqlDatabase::setPort ( int p ) +{ + QSqlDatabase *db = QSqlDatabase::database(connectionName,false); + if ( db ) + db->setPort(p); +} +QString SqlDatabase::databaseName () const +{ + QSqlDatabase *db = QSqlDatabase::database(connectionName,false); + if ( db ) + return db->databaseName(); + return ""; +} +QString SqlDatabase::userName () const +{ + QSqlDatabase *db = QSqlDatabase::database(connectionName,false); + if ( db ) + return db->userName(); + return ""; +} +QString SqlDatabase::password () const +{ + QSqlDatabase *db = QSqlDatabase::database(connectionName,false); + if ( db ) + return db->password(); + return ""; +} +QString SqlDatabase::hostName () const +{ + QSqlDatabase *db = QSqlDatabase::database(connectionName,false); + if ( db ) + return db->hostName(); + return ""; +} +QString SqlDatabase::driverName () const +{ + QSqlDatabase *db = QSqlDatabase::database(connectionName,false); + if ( db ) + return db->driverName(); + return ""; +} +int SqlDatabase::port () const +{ + QSqlDatabase *db = QSqlDatabase::database(connectionName,false); + if ( db ) + return db->port(); + return 0; +} + +SqlQuery::SqlQuery( QObject *parent, const char *name ): BindingObject(parent, name) +{ + kdDebug() << "New null SQL Query" << endl; + m_query = QSqlQuery(); + setJSClassName( "SqlQuery" ); +} +SqlQuery::SqlQuery( QObject *parent, const char *name, const QSqlQuery &q ): BindingObject(parent, name) +{ + kdDebug() << "New SQL Query with argument" << endl; + m_query = q; +} +SqlQuery::~SqlQuery() +{ + kdDebug() << "SQL Query going away..." << endl; +} + +/*SqlQuery::SqlQuery(const SqlQuery ©) : BindingObject(copy.parent(), copy.name()) +{ + m_query = copy.m_query; +} +*/ +bool SqlQuery::isValid () const +{ + if ( m_query.isValid()) + kdDebug() << "Query is valid" << endl; + else + kdDebug() << "Query is not valid" << endl; + return m_query.isValid(); +} +bool SqlQuery::isActive () const +{ + return m_query.isActive(); +} +bool SqlQuery::isNull ( int field ) +{ + return m_query.isNull(field); +} +int SqlQuery::at () const +{ + return m_query.at(); +} +QString SqlQuery::lastQuery () const +{ + kdDebug() << "Last query error: " << m_query.lastQuery() << endl; + return m_query.lastQuery(); +} +int SqlQuery::numRowsAffected () const +{ + return m_query.numRowsAffected(); +} +QString SqlQuery::lastError () const +{ + return m_query.lastError().text(); +} +bool SqlQuery::isSelect () const +{ + return m_query.isSelect(); +} +int SqlQuery::size () const +{ + return m_query.size(); +} +bool SqlQuery::exec ( const QString & query ) +{ + return m_query.exec( query ); +} +QVariant SqlQuery::value ( int i ) +{ + return m_query.value(i); +} +bool SqlQuery::seek ( int i, bool relative ) +{ + return m_query.seek(i,relative); +} +bool SqlQuery::next () +{ + return m_query.next(); +} +bool SqlQuery::prev () +{ + return m_query.prev(); +} +bool SqlQuery::first () +{ + return m_query.first(); +} +bool SqlQuery::last () +{ + return m_query.last(); +} + +} // namespace KJSEmbed::Bindings +} // namespace KJSEmbed + +#ifndef QT_ONLY +#include "sql_imp.moc" +#endif diff --git a/kjsembed/bindings/sql_imp.h b/kjsembed/bindings/sql_imp.h new file mode 100644 index 00000000..78e54756 --- /dev/null +++ b/kjsembed/bindings/sql_imp.h @@ -0,0 +1,141 @@ +/* + * Copyright (C) 2003, Ian Reinhart Geiser <geiseri@kde.org> + * + * This 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. + * + * This 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 this library; see the file COPYING.LIB. If not, write to + * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, + * Boston, MA 02110-1301, USA. + */ + +#ifndef KJSEMBED_SQL_IMP_H +#define KJSEMBED_SQL_IMP_H + +#include "bindingobject.h" +#include <qsqlquery.h> +#include <qsqldatabase.h> + +namespace KJSEmbed { +namespace Bindings { + +/** + * QObject Binding for QSQLQuery. + * + * @author Ian Reinhart Geiser, geiseri@kde.org + * @version $Id$ + */ +class SqlQuery : public BindingObject +{ + Q_OBJECT + Q_PROPERTY( int size READ size) + Q_PROPERTY( int at READ at) + Q_PROPERTY( int numRowsAffected READ numRowsAffected ) + Q_PROPERTY( bool select READ isSelect) + Q_PROPERTY( bool valid READ isValid) + Q_PROPERTY( bool active READ isActive) + Q_PROPERTY( QString lastError READ lastError) + Q_PROPERTY( QString lastQuery READ lastQuery) + +public: + SqlQuery( QObject *parent=0, const char *name=0 ); + SqlQuery( QObject *parent, const char *name, const QSqlQuery &q ); + //SqlQuery( const SqlQuery ©); + virtual ~SqlQuery(); + + QSqlQuery query(){ return m_query; } + void setQuery(const QSqlQuery &q) {m_query = QSqlQuery(q); } + + int size () const; + bool isSelect () const; + bool isValid () const; + bool isActive () const; + int at () const; + int numRowsAffected () const; + QString lastError () const; + QString lastQuery () const; + +public slots: + + + + bool isNull ( int field ); + bool exec ( const QString & m_query ); + QVariant value ( int i ); + bool seek ( int i, bool relative = FALSE ); + bool next (); + bool prev (); + bool first (); + bool last (); + +private: + QSqlQuery m_query; +}; + +/** + * QObject Binding for QSQLDatabase. + * + * @author Ian Reinhart Geiser, geiseri@kde.org + * @version $Id$ + */ +class SqlDatabase : public BindingObject +{ + Q_OBJECT + Q_PROPERTY( QString databaseName READ databaseName WRITE setDatabaseName) + Q_PROPERTY( QString userName READ userName WRITE setUserName) + Q_PROPERTY( QString password READ password WRITE setPassword) + Q_PROPERTY( QString hostName READ hostName WRITE setHostName) + Q_PROPERTY( int port READ port WRITE setPort) + Q_PROPERTY( QString driverName READ driverName) + Q_PROPERTY( QString lastError READ lastError) + +public: + SqlDatabase( QObject *parent=0, const char *name=0 ); + virtual ~SqlDatabase(); + + +public slots: + void setDatabaseName (const QString &name ); + void setUserName (const QString &name ); + void setPassword (const QString &password ); + void setHostName (const QString &host ); + void setPort ( int p ); + QString databaseName () const; + QString userName () const; + QString password () const; + QString hostName () const; + int port () const; + QString driverName () const; + + bool addDatabase ( const QString & type, const QString & connectionName = QSqlDatabase::defaultConnection ); + QStringList drivers (); + bool open (); + bool open ( const QString &user, const QString &password ); + void close (); + bool isOpen (); + bool isOpenError (); + QStringList tables (); + SqlQuery *exec( const QString &query ); + QString lastError () const; + bool transaction (); + bool commit (); + bool rollback (); + +private: + QString connectionName; + //QSqlDatabase *db; +}; + + +} // namespace KJSEmbed::Bindings +} // namespace KJSEmbed + +#endif // KJSEMBED_SQL_IMP_H diff --git a/kjsembed/bindwizard/Doxyfile.in b/kjsembed/bindwizard/Doxyfile.in new file mode 100644 index 00000000..291c78cd --- /dev/null +++ b/kjsembed/bindwizard/Doxyfile.in @@ -0,0 +1,824 @@ +# Doxyfile 1.2.9.1 + +# 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 (" ") + +#--------------------------------------------------------------------------- +# General configuration options +#--------------------------------------------------------------------------- + +# The PROJECT_NAME tag is a single word (or a sequence of words surrounded +# by quotes) that should identify the project. + +PROJECT_NAME = __PLUGIN_NAME__ + +# 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 = + +# 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 = + +# 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: +# Brazilian, Chinese, Croatian, Czech, Danish, Dutch, Finnish, French, +# German, Hungarian, Italian, Japanese, Korean, Norwegian, Polish, +# Portuguese, Romanian, Russian, Slovak, Slovene, Spanish and Swedish. + +OUTPUT_LANGUAGE = English + +# 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 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 = NO + +# 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 class will be included in the various +# overviews. This option has no effect if EXTRACT_ALL is enabled. + +HIDE_UNDOC_CLASSES = YES + +# 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 = NO + +# 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 + +# 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 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 = NO + +# 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. It is allowed to use relative paths in the argument list. + +STRIP_FROM_PATH = + +# 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 CLASS_DIAGRAMS tag is set to YES (the default) Doxygen will +# generate a class diagram (in Html and LaTeX) for classes with base or +# super classes. Setting the tag to NO turns the diagrams off. + +CLASS_DIAGRAMS = YES + +# 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. + +SOURCE_BROWSER = NO + +# 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 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 +# users are adviced to set this option to NO. + +CASE_SENSE_NAMES = YES + +# 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 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 = YES + +# 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 + +# If the SHOW_INCLUDE_FILES tag is set to YES (the default) then Doxygen +# will put list of the files that are included by a file in the documentation +# of that file. + +SHOW_INCLUDE_FILES = YES + +# 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 the Qt-style comments (thus requiring an +# explict @brief command for a brief description. + +JAVADOC_AUTOBRIEF = YES + +# If the INHERIT_DOCS tag is set to YES (the default) then an undocumented +# member inherits the documentation from any documented member that it +# reimplements. + +INHERIT_DOCS = YES + +# 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 = NO + +# 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 + +# 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 + +# The ENABLED_SECTIONS tag can be used to enable conditional +# documentation sections, marked by \if sectionname ... \endif. + +ENABLED_SECTIONS = + +# 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 + +# 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 = + +# The MAX_INITIALIZER_LINES tag determines the maximum number of lines +# the initial value of a variable or define consist 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 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 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 + +#--------------------------------------------------------------------------- +# 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 = YES + +# 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 = NO + +# 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. + +WARN_FORMAT = + +# 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 = __HEADER_DIR__ + +# 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 all files are included. + +FILE_PATTERNS = *.h + +# 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 = NO + +# 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 = doxygen_fakes.h +#EXCLUDE = customobject_imp.h jsfactory_imp.h jsproxy_imp.h \ +# kjsembedpart_imp.h jsbuiltin_imp.h \ +# jsobjectproxy_imp.h jsvalueproxy_imp.h \ +# doxygen_fakes.h + +# 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. + +EXCLUDE_PATTERNS = *.moc.* + +# 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 = + +# 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. + +INPUT_FILTER = + +# 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. + +FILTER_SOURCE_FILES = 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 = KJSEmbed + +#--------------------------------------------------------------------------- +# 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 = NO + +# 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 = . + +# 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 + +HTML_STYLESHEET = + +# 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 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 compressed HTML help file (.chm) +# of the generated HTML documentation. + +GENERATE_HTMLHELP = NO + +# 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 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 + +# 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 + +# If the GENERATE_TREEVIEW tag 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 and frames is required (for instance Netscape 4.0+ +# or Internet explorer 4.0+). + +GENERATE_TREEVIEW = 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 + +#--------------------------------------------------------------------------- +# 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 = + +# 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 = NO + +# 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 = NO + +# 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 + +#--------------------------------------------------------------------------- +# 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 optimised 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 = + +# 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 assigments. 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 = + +# The MAN_EXTENSION tag determines the extension that is added to +# the generated man pages (default is the subroutine's section .3) + +MAN_EXTENSION = + +# 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. Note that this +# feature is still experimental and incomplete at the +# moment. + +GENERATE_XML = YES + +#--------------------------------------------------------------------------- +# 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 = YES + +# 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_PREDEFINED tags. + +EXPAND_ONLY_PREDEF = YES + +# 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. + +PREDEFINED = Q_PROPERTY()= + +# If the MACRO_EXPANSION and EXPAND_PREDEF_ONLY 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 = + +#--------------------------------------------------------------------------- +# Configuration::addtions related to external references +#--------------------------------------------------------------------------- + +# The TAGFILES tag can be used to specify one or more tagfiles. + +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 + +# The PERL_PATH should be the absolute path and name of the perl script +# interpreter (i.e. the result of `which perl'). + +PERL_PATH = + +#--------------------------------------------------------------------------- +# Configuration options related to the dot tool +#--------------------------------------------------------------------------- + +# 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 = NO + +# 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 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 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 + +# 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 on the path. + +DOT_PATH = + +# The MAX_DOT_GRAPH_WIDTH tag can be used to set the maximum allowed width +# (in pixels) of the graphs generated by dot. If a graph becomes larger than +# this value, doxygen will try to truncate the graph, so that it fits within +# the specified constraint. Beware that most browsers cannot cope with very +# large images. + +MAX_DOT_GRAPH_WIDTH = 1024 + +# The MAX_DOT_GRAPH_HEIGHT tag can be used to set the maximum allows height +# (in pixels) of the graphs generated by dot. If a graph becomes larger than +# this value, doxygen will try to truncate the graph, so that it fits within +# the specified constraint. Beware that most browsers cannot cope with very +# large images. + +MAX_DOT_GRAPH_HEIGHT = 1024 + +# 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 intermedate dot files that are used to generate +# the various graphs. + +DOT_CLEANUP = YES + +#--------------------------------------------------------------------------- +# Configuration::addtions related to the search engine +#--------------------------------------------------------------------------- + +# The SEARCHENGINE tag specifies whether or not a search engine should be +# used. If set to NO the values of all tags below this one will be ignored. + +SEARCHENGINE = NO + +# The CGI_NAME tag should be the name of the CGI script that +# starts the search engine (doxysearch) with the correct parameters. +# A script with this name will be generated by doxygen. + +CGI_NAME = + +# The CGI_URL tag should be the absolute URL to the directory where the +# cgi binaries are located. See the documentation of your http daemon for +# details. + +CGI_URL = + +# The DOC_URL tag should be the absolute URL to the directory where the +# documentation is located. If left blank the absolute path to the +# documentation, with file:// prepended to it, will be used. + +DOC_URL = + +# The DOC_ABSPATH tag should be the absolute path to the directory where the +# documentation is located. If left blank the directory on the local machine +# will be used. + +DOC_ABSPATH = + +# The BIN_ABSPATH tag must point to the directory where the doxysearch binary +# is installed. + +BIN_ABSPATH = + +# The EXT_DOC_PATHS tag can be used to specify one or more paths to +# documentation generated for other projects. This allows doxysearch to search +# the documentation for these projects as well. + +EXT_DOC_PATHS = diff --git a/kjsembed/bindwizard/binding_wizard.js b/kjsembed/bindwizard/binding_wizard.js new file mode 100755 index 00000000..7fb35679 --- /dev/null +++ b/kjsembed/bindwizard/binding_wizard.js @@ -0,0 +1,244 @@ +#!/usr/bin/env kjscmd + +// +// Script for automatically generating bindings to C++ classes. +// + +plugin_name = ''; +header_dir = ''; +output_dir = ''; + +wiz = Factory.loadui( 'binding_wizard.ui' ); + +classview = wiz.child('classes'); +classes = new Array(); +page = 0; +output = new Array(); + +imp = new BindingWizard(); + +function BindingWizard() +{ + // + // Update the GUI view from the classview list. + // + this.update_classes = function() { + classview.clear(); + for ( var i=0 ; i < classes.length ; i++ ) { + classview.insertItem( 'Yes', classes[i] ); + } + } + + // + // Selects all the classes. + // + this.select_all = function() { + classview.selectAll( true ); + } + + // + // Populate list views + // + this.choose_classes = function( view, name ) { + + sax = new Object(); + sax.chars = ''; + + sax.endElement = function( namespace, localname, qualifiedname ) { + if ( localname == 'class' ) { + classes[ classes.length ] = this.chars; + } + this.chars = ''; + return true; + } + + sax.characters = function( chars ) { + this.chars = chars; + return true; + } + + try { + saxLoadFile( sax, name ); + } + catch( theErr ) + { + println(theErr); + } + } + + // + // Creates the binding for the named class. + // + this.bind_class = function( clazz ) { + + var out = "<b>Binding Class '" + clazz + "'...</b><pre>\n"; + + var outfile = output_dir + '/' + clazz.toLowerCase() + '_imp.h'; + var cmd = 'xsltproc -o ' + outfile + ' doxygen2imp_h.xsl xml/class' + clazz + '.xml'; + + out += cmd + '\n'; + out += shell( cmd ); + output[ output.length ] = outfile; + + outfile = output_dir + '/' + clazz.toLowerCase() + '_imp.cpp'; + var cmd2 = 'xsltproc -o ' + outfile + ' doxygen2imp_cpp.xsl xml/class' + clazz + '.xml'; + + out += cmd2 + '\n'; + out += shell( cmd2 ); + + out += '</pre>'; + + return out; + } + + this.create_makefile = function() { + + var sources = output.join(' '); + sources = sources.replace( /\w*\//g, '' ); + + var make = System.readFile( 'plugin_Makefile.in' ); + make = make.replace( /__PLUGIN_NAME__/g, plugin_name ); + make = make.replace( /__PLUGIN_NAME_LC__/g, plugin_name.toLowerCase() ); + make = make.replace( /__PLUGIN_SOURCES__/g, sources ); + + System.writeFile( output_dir + '/' + 'Makefile.am', make ); + } + + // + // Called when the wizard has all the information it needs. This method + // binds the classes the user specified. + // + this.invoke = function() { + + wiz.child('next').enabled = false; + wiz.child('output').clear(); + + for ( var i=0 ; i < classes.length ; i++ ) { + wiz.child('output').append( this.bind_class( classes[i] ) ); + } + + wiz.child('next').enabled = true; + } + + this.browse_input = function() { + res = StdDialog.getExistingDirectory( '.' ); + wiz.child('header_dir').text = res; + } + + this.browse_output = function() { + res = StdDialog.getExistingDirectory( '.' ); + wiz.child('output_dir').text = res; + } + + // + // Lists the classes available for binding. In future, this will let you + // control which classes are processed. + // + this.list_classes = function() { + + wiz.child('next').enabled = false; + + // Create class index + var clazz = shell( 'xsltproc index_classes.xsl xml/index.xml' ); + System.writeFile( 'classes.xml', clazz ); + + // Offer class selection + var classview = wiz.child('classes'); + classview.selectionMode = 2 // Extended mode; + classview.resizeMode = 2; + + this.choose_classes( classview, 'classes.xml' ); + this.update_classes(); + + wiz.connect( wiz.child('select_all'), 'clicked()', this, 'select_all' ); + wiz.child('next').enabled = true; + } + + // + // Create the doxygen config + // + this.analyse = function() { + + wiz.child('next').enabled = false; + + led = wiz.child('analyse_led'); + led.color = 'orange'; + + plugin_name = wiz.child('plugin_name').text; + header_dir = wiz.child('header_dir').text; + output_dir = wiz.child('output_dir').text; + + // Create Doxygen config + var doxy = System.readFile( 'Doxyfile.in' ); + + doxy = doxy.replace( /__PLUGIN_NAME__/, plugin_name ); + doxy = doxy.replace( /__HEADER_DIR__/, header_dir ); + + System.writeFile( 'Doxyfile', doxy ); + + // Run doxygen + shell( 'doxygen' ); + + wiz.child('analyse_led').color = 'green'; + wiz.child('analyse_status').text = 'Done'; + + wiz.child('next').enabled = true; + } + + this.view_results = function() { + + this.create_makefile(); + + var lv = wiz.child('bindings'); + + for ( var i=0 ; i < output.length ; i++ ) { + lv.insertItem( output[i] ); + } + + wiz.child('finish').enabled = true; + } + + // + // Called to setup the display of the next page. + // + this.do_next = function() { + + try { + page++; + + if ( page == 1 ) { + this.analyse(); + } + else if ( page == 2 ) { + this.list_classes(); + } + else if ( page == 3 ) { + this.invoke(); + } + else if ( page == 4 ) { + this.view_results(); + } + } + catch(err) { + warn( 'Error: ' + err ); + } + } + + this.do_back = function() { + + page--; + + } + + wiz.connect( wiz.child('next'), 'clicked()', this, 'do_next' ); + wiz.connect( wiz.child('back'), 'clicked()', this, 'do_back' ); + + // + // Connnect the first page + // + wiz.connect( wiz.child('browse_header'), 'clicked()', this, 'browse_input' ); + wiz.connect( wiz.child('browse_output' ), 'clicked()', this, 'browse_output' ); +} + +wiz.show(); +application.exec(); diff --git a/kjsembed/bindwizard/binding_wizard.ui b/kjsembed/bindwizard/binding_wizard.ui new file mode 100644 index 00000000..f6697bd3 --- /dev/null +++ b/kjsembed/bindwizard/binding_wizard.ui @@ -0,0 +1,490 @@ +<!DOCTYPE UI><UI version="3.2" stdsetdef="1"> +<class>binding_wizard</class> +<widget class="QWizard"> + <property name="name"> + <cstring>binding_wizard</cstring> + </property> + <property name="geometry"> + <rect> + <x>0</x> + <y>0</y> + <width>802</width> + <height>564</height> + </rect> + </property> + <property name="sizePolicy"> + <sizepolicy> + <hsizetype>3</hsizetype> + <vsizetype>5</vsizetype> + <horstretch>0</horstretch> + <verstretch>0</verstretch> + </sizepolicy> + </property> + <property name="caption"> + <string>KJSEmbed Binding Wizard</string> + </property> + <widget class="QWidget"> + <property name="name"> + <cstring>WizardPage</cstring> + </property> + <attribute name="title"> + <string>Specify Target Information</string> + </attribute> + <grid> + <property name="name"> + <cstring>unnamed</cstring> + </property> + <widget class="QLabel" row="0" column="0" rowspan="1" colspan="3"> + <property name="name"> + <cstring>textLabel1</cstring> + </property> + <property name="sizePolicy"> + <sizepolicy> + <hsizetype>3</hsizetype> + <vsizetype>0</vsizetype> + <horstretch>0</horstretch> + <verstretch>0</verstretch> + </sizepolicy> + </property> + <property name="text"> + <string>Please specify a name for your binding plugin, and the directory the header +files of the C++ classes you want to make available to Javascript are located.</string> + </property> + </widget> + <spacer row="1" column="1"> + <property name="name"> + <cstring>spacer2</cstring> + </property> + <property name="orientation"> + <enum>Vertical</enum> + </property> + <property name="sizeType"> + <enum>Fixed</enum> + </property> + <property name="sizeHint"> + <size> + <width>20</width> + <height>40</height> + </size> + </property> + </spacer> + <spacer row="5" column="1"> + <property name="name"> + <cstring>spacer1</cstring> + </property> + <property name="orientation"> + <enum>Vertical</enum> + </property> + <property name="sizeType"> + <enum>Expanding</enum> + </property> + <property name="sizeHint"> + <size> + <width>20</width> + <height>50</height> + </size> + </property> + </spacer> + <widget class="QLabel" row="2" column="0"> + <property name="name"> + <cstring>textLabel3</cstring> + </property> + <property name="text"> + <string>Header files:</string> + </property> + </widget> + <widget class="QLabel" row="3" column="0"> + <property name="name"> + <cstring>textLabel2</cstring> + </property> + <property name="text"> + <string>Plugin name:</string> + </property> + </widget> + <widget class="QLabel" row="4" column="0"> + <property name="name"> + <cstring>textLabel2_2</cstring> + </property> + <property name="text"> + <string>Output directory:</string> + </property> + </widget> + <widget class="KPushButton" row="2" column="2"> + <property name="name"> + <cstring>browse_header</cstring> + </property> + <property name="sizePolicy"> + <sizepolicy> + <hsizetype>0</hsizetype> + <vsizetype>0</vsizetype> + <horstretch>0</horstretch> + <verstretch>0</verstretch> + </sizepolicy> + </property> + <property name="text"> + <string>...</string> + </property> + </widget> + <widget class="KPushButton" row="4" column="2"> + <property name="name"> + <cstring>browse_output</cstring> + </property> + <property name="sizePolicy"> + <sizepolicy> + <hsizetype>0</hsizetype> + <vsizetype>0</vsizetype> + <horstretch>0</horstretch> + <verstretch>0</verstretch> + </sizepolicy> + </property> + <property name="text"> + <string>...</string> + </property> + </widget> + <widget class="KLineEdit" row="2" column="1"> + <property name="name"> + <cstring>header_dir</cstring> + </property> + <property name="sizePolicy"> + <sizepolicy> + <hsizetype>1</hsizetype> + <vsizetype>0</vsizetype> + <horstretch>0</horstretch> + <verstretch>0</verstretch> + </sizepolicy> + </property> + <property name="text"> + <string>input</string> + </property> + </widget> + <widget class="KLineEdit" row="3" column="1"> + <property name="name"> + <cstring>plugin_name</cstring> + </property> + <property name="sizePolicy"> + <sizepolicy> + <hsizetype>3</hsizetype> + <vsizetype>0</vsizetype> + <horstretch>0</horstretch> + <verstretch>0</verstretch> + </sizepolicy> + </property> + </widget> + <widget class="KLineEdit" row="4" column="1"> + <property name="name"> + <cstring>output_dir</cstring> + </property> + <property name="sizePolicy"> + <sizepolicy> + <hsizetype>3</hsizetype> + <vsizetype>0</vsizetype> + <horstretch>0</horstretch> + <verstretch>0</verstretch> + </sizepolicy> + </property> + <property name="text"> + <string>output</string> + </property> + </widget> + </grid> + </widget> + <widget class="QWidget"> + <property name="name"> + <cstring>WizardPage</cstring> + </property> + <attribute name="title"> + <string>Analysing Classes</string> + </attribute> + <grid> + <property name="name"> + <cstring>unnamed</cstring> + </property> + <spacer row="0" column="0"> + <property name="name"> + <cstring>spacer4</cstring> + </property> + <property name="orientation"> + <enum>Vertical</enum> + </property> + <property name="sizeType"> + <enum>Expanding</enum> + </property> + <property name="sizeHint"> + <size> + <width>20</width> + <height>191</height> + </size> + </property> + </spacer> + <spacer row="2" column="0"> + <property name="name"> + <cstring>spacer4_3</cstring> + </property> + <property name="orientation"> + <enum>Vertical</enum> + </property> + <property name="sizeType"> + <enum>Expanding</enum> + </property> + <property name="sizeHint"> + <size> + <width>20</width> + <height>191</height> + </size> + </property> + </spacer> + <spacer row="2" column="1"> + <property name="name"> + <cstring>spacer4_4</cstring> + </property> + <property name="orientation"> + <enum>Vertical</enum> + </property> + <property name="sizeType"> + <enum>Expanding</enum> + </property> + <property name="sizeHint"> + <size> + <width>20</width> + <height>191</height> + </size> + </property> + </spacer> + <widget class="QLabel" row="1" column="0"> + <property name="name"> + <cstring>analysing_label</cstring> + </property> + <property name="text"> + <string>Analysing the classes available for binding...</string> + </property> + </widget> + <spacer row="0" column="1"> + <property name="name"> + <cstring>spacer4_2</cstring> + </property> + <property name="orientation"> + <enum>Vertical</enum> + </property> + <property name="sizeType"> + <enum>Expanding</enum> + </property> + <property name="sizeHint"> + <size> + <width>20</width> + <height>191</height> + </size> + </property> + </spacer> + <widget class="QLayoutWidget" row="1" column="1"> + <property name="name"> + <cstring>layout1</cstring> + </property> + <hbox> + <property name="name"> + <cstring>unnamed</cstring> + </property> + <widget class="KLed"> + <property name="name"> + <cstring>analyse_led</cstring> + </property> + <property name="sizePolicy"> + <sizepolicy> + <hsizetype>0</hsizetype> + <vsizetype>0</vsizetype> + <horstretch>0</horstretch> + <verstretch>0</verstretch> + </sizepolicy> + </property> + </widget> + <widget class="QLabel"> + <property name="name"> + <cstring>analyse_status</cstring> + </property> + <property name="frameShape"> + <enum>Box</enum> + </property> + <property name="text"> + <string>Working</string> + </property> + <property name="alignment"> + <set>AlignVCenter|AlignLeft</set> + </property> + </widget> + </hbox> + </widget> + </grid> + </widget> + <widget class="QWidget"> + <property name="name"> + <cstring>WizardPage</cstring> + </property> + <attribute name="title"> + <string>Select Classes</string> + </attribute> + <grid> + <property name="name"> + <cstring>unnamed</cstring> + </property> + <widget class="QLabel" row="0" column="0" rowspan="1" colspan="2"> + <property name="name"> + <cstring>textLabel6</cstring> + </property> + <property name="text"> + <string>Select the classes that are to be made available to scripts.</string> + </property> + </widget> + <widget class="KPushButton" row="2" column="1"> + <property name="name"> + <cstring>select_all</cstring> + </property> + <property name="enabled"> + <bool>false</bool> + </property> + <property name="text"> + <string>Select &All</string> + </property> + </widget> + <widget class="KListView" row="1" column="0" rowspan="1" colspan="2"> + <column> + <property name="text"> + <string>Scriptable</string> + </property> + <property name="clickable"> + <bool>true</bool> + </property> + <property name="resizable"> + <bool>false</bool> + </property> + </column> + <column> + <property name="text"> + <string>Class Name</string> + </property> + <property name="clickable"> + <bool>true</bool> + </property> + <property name="resizable"> + <bool>false</bool> + </property> + </column> + <property name="name"> + <cstring>classes</cstring> + </property> + <property name="resizeMode"> + <enum>LastColumn</enum> + </property> + </widget> + <spacer row="2" column="0"> + <property name="name"> + <cstring>spacer8</cstring> + </property> + <property name="orientation"> + <enum>Horizontal</enum> + </property> + <property name="sizeType"> + <enum>Expanding</enum> + </property> + <property name="sizeHint"> + <size> + <width>430</width> + <height>20</height> + </size> + </property> + </spacer> + </grid> + </widget> + <widget class="QWidget"> + <property name="name"> + <cstring>WizardPage</cstring> + </property> + <attribute name="title"> + <string>Generate Bindings</string> + </attribute> + <grid> + <property name="name"> + <cstring>unnamed</cstring> + </property> + <widget class="QTextEdit" row="0" column="0"> + <property name="name"> + <cstring>output</cstring> + </property> + <property name="font"> + <font> + <family>Courier New</family> + <pointsize>8</pointsize> + </font> + </property> + <property name="readOnly"> + <bool>true</bool> + </property> + <property name="undoRedoEnabled"> + <bool>false</bool> + </property> + </widget> + </grid> + </widget> + <widget class="QWidget"> + <property name="name"> + <cstring>WizardPage</cstring> + </property> + <attribute name="title"> + <string>Results</string> + </attribute> + <widget class="QLabel"> + <property name="name"> + <cstring>textLabel3_2</cstring> + </property> + <property name="geometry"> + <rect> + <x>0</x> + <y>10</y> + <width>312</width> + <height>19</height> + </rect> + </property> + <property name="text"> + <string>The following binding files have been created:</string> + </property> + </widget> + <widget class="KListView"> + <column> + <property name="text"> + <string>File Name</string> + </property> + <property name="clickable"> + <bool>false</bool> + </property> + <property name="resizable"> + <bool>false</bool> + </property> + </column> + <property name="name"> + <cstring>bindings</cstring> + </property> + <property name="geometry"> + <rect> + <x>10</x> + <y>40</y> + <width>700</width> + <height>430</height> + </rect> + </property> + <property name="resizeMode"> + <enum>LastColumn</enum> + </property> + </widget> + </widget> +</widget> +<layoutdefaults spacing="6" margin="11"/> +<includehints> + <includehint>kpushbutton.h</includehint> + <includehint>kpushbutton.h</includehint> + <includehint>klineedit.h</includehint> + <includehint>klineedit.h</includehint> + <includehint>klineedit.h</includehint> + <includehint>kled.h</includehint> + <includehint>kpushbutton.h</includehint> + <includehint>klistview.h</includehint> + <includehint>klistview.h</includehint> +</includehints> +</UI> diff --git a/kjsembed/bindwizard/doxygen2imp_cpp.xsl b/kjsembed/bindwizard/doxygen2imp_cpp.xsl new file mode 100644 index 00000000..c65b5650 --- /dev/null +++ b/kjsembed/bindwizard/doxygen2imp_cpp.xsl @@ -0,0 +1,560 @@ +<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform"> +<xsl:output method="text" /> + +<xsl:template match="/doxygen/compounddef"> + +<!-- Find the name of the class --> +<xsl:variable name="clazz" select="compoundname" /> + +<!-- Find the constructors and methods --> +<xsl:variable name="consmeth" select="sectiondef/memberdef[@kind='function' and @prot='public']" /> + +<!-- Find the enums --> +<xsl:variable name="enums" select="sectiondef/memberdef[@kind='enum' and @prot='public']" /> + +#include <qcstring.h> +#include <qimage.h> +#include <qpainter.h> +#include <qpalette.h> +#include <qpixmap.h> +#include <qfont.h> + +#include <kjs/object.h> + +#include <kjsembed/global.h> +#include <kjsembed/jsobjectproxy.h> +#include <kjsembed/jsopaqueproxy.h> +#include <kjsembed/jsbinding.h> + +#include <<xsl:value-of select="includes" />> +#include "<xsl:value-of select="translate($clazz,'ABCDEFGHIJKLMNOPQRSTUVWXYZ','abcdefghijklmnopqrstuvwxyz')"/>_imp.h" + +/** + * Namespace containing the KJSEmbed library. + */ +namespace KJSEmbed { + +<xsl:value-of select="$clazz" />Imp::<xsl:value-of select="$clazz" />Imp( KJS::ExecState *exec, int mid, bool constructor ) + : JSProxyImp(exec), id(mid), cons(constructor) +{ +} + +<xsl:value-of select="$clazz" />Imp::~<xsl:value-of select="$clazz" />Imp() +{ +} + +/** + * Adds bindings for static methods and enum constants to the specified Object. + */ +void <xsl:value-of select="$clazz" />Imp::addStaticBindings( KJS::ExecState *exec, KJS::Object &object ) +{ + JSProxy::MethodTable methods[] = { +<xsl:for-each select="consmeth"> + <xsl:variable name="method_name"><xsl:value-of select="name" />_<xsl:value-of select="position()" /></xsl:variable> + <xsl:variable name="method_id">Method_<xsl:value-of select="$method_name" /></xsl:variable> + <xsl:choose> + <xsl:when test="@static = 'yes'"> + { <xsl:value-of select="$method_id" />, "<xsl:value-of select="name" />" },</xsl:when></xsl:choose> +</xsl:for-each> + { 0, 0 } + }; + + int idx = 0; + QCString lastName; + + while( methods[idx].name ) { + if ( lastName != methods[idx].name ) { + <xsl:value-of select="$clazz" />Imp *meth = new <xsl:value-of select="$clazz" />Imp( exec, methods[idx].id ); + object.put( exec , methods[idx].name, KJS::Object(meth) ); + lastName = methods[idx].name; + } + ++idx; + } + +<xsl:if test="count($enums) != 0"> + // + // Define the enum constants + // + struct EnumValue { + const char *id; + int val; + }; + + EnumValue enums[] = { +<xsl:for-each select="$enums"> + // enum <xsl:value-of select="./name" /> + <xsl:for-each select="./enumvalue"> + { "<xsl:value-of select="./name" />", <xsl:value-of select="$clazz" />::<xsl:value-of select="./name" /> },</xsl:for-each> +</xsl:for-each> + { 0, 0 } + }; + + int enumidx = 0; + while( enums[enumidx].id ) { + object.put( exec, enums[enumidx].id, KJS::Number(enums[enumidx].val), KJS::ReadOnly ); + ++enumidx; + } +</xsl:if> +} + +/** + * Adds bindings for instance methods to the specified Object. + */ +void <xsl:value-of select="$clazz" />Imp::addBindings( KJS::ExecState *exec, KJS::Object &object ) +{ + JSProxy::MethodTable methods[] = { +<xsl:for-each select="$consmeth"> + <xsl:variable name="method_name"><xsl:value-of select="name" />_<xsl:value-of select="position()" /></xsl:variable> + <xsl:variable name="method_id">Method_<xsl:value-of select="$method_name" /></xsl:variable> + <xsl:choose> + <xsl:when test="not( @static = 'yes' + or starts-with( name, 'operator' ) + or starts-with( name, '~' ) + or starts-with( name, $clazz ))"> + { <xsl:value-of select="$method_id" />, "<xsl:value-of select="name" />" },</xsl:when></xsl:choose> +</xsl:for-each> + { 0, 0 } + }; + + int idx = 0; + QCString lastName; + + while( methods[idx].name ) { + if ( lastName != methods[idx].name ) { + <xsl:value-of select="$clazz" />Imp *meth = new <xsl:value-of select="$clazz" />Imp( exec, methods[idx].id ); + object.put( exec , methods[idx].name, KJS::Object(meth) ); + lastName = methods[idx].name; + } + ++idx; + } +} + +/** + * Extract a <xsl:value-of select="$clazz" /> pointer from an Object. + */ +<xsl:value-of select="$clazz" /> *<xsl:value-of select="$clazz" />Imp::to<xsl:value-of select="$clazz" />( KJS::Object &self ) +{ + JSObjectProxy *ob = JSProxy::toObjectProxy( self.imp() ); + if ( ob ) { + QObject *obj = ob->object(); + if ( obj ) + return dynamic_cast<<xsl:value-of select="$clazz" /> *>( obj ); + } + + JSOpaqueProxy *op = JSProxy::toOpaqueProxy( self.imp() ); + if ( !op ) + return 0; + + if ( op->typeName() != "<xsl:value-of select="$clazz" />" ) + return 0; + + return (<xsl:value-of select="$clazz" /> *)( op->toVoidStar() ); +} + +/** + * Select and invoke the correct constructor. + */ +KJS::Object <xsl:value-of select="$clazz" />Imp::construct( KJS::ExecState *exec, const KJS::List &args ) +{ + switch( id ) { +<xsl:for-each select="$consmeth"> + <xsl:choose> + <xsl:when test="name = $clazz"> + <xsl:variable name="cons_name"><xsl:value-of select="name" />_<xsl:value-of select="position()" /></xsl:variable> + <xsl:variable name="cons_id">Constructor_<xsl:value-of select="$cons_name" /></xsl:variable> + case <xsl:value-of select="$cons_id" />: + return <xsl:value-of select="$cons_name" />( exec, args ); + break; + </xsl:when> + </xsl:choose> +</xsl:for-each> + default: + break; + } + + QString msg = i18n("<xsl:value-of select="$clazz" />Cons has no constructor with id '%1'").arg(id); + KJS::Object err = KJS::Error::create( exec, KJS::ReferenceError, msg.utf8() ); + exec->setException( err ); + return err; +} + +<!-- Implementations of the constructors. --> +<xsl:for-each select="$consmeth"> + <xsl:choose> + <xsl:when test="(name = $clazz)"> + <xsl:variable name="cons_name"><xsl:value-of select="name" />_<xsl:value-of select="position()" /></xsl:variable> + <xsl:variable name="cons_id">Constructor_<xsl:value-of select="$cons_name" /></xsl:variable> +KJS::Object <xsl:value-of select="$clazz" />Imp::<xsl:value-of select="$cons_name" />( KJS::ExecState *exec, const KJS::List &args ) +{ + <xsl:if test="($clazz = 'QCanvasItem') or ($clazz = 'QCanvasPolygonalItem')"> +#if 0 // This constructor has been disabled by the XSL template + </xsl:if> + + <xsl:for-each select="param/type"> + + <xsl:variable name="idx" select="position()-1" /> + + <xsl:choose> + <xsl:when test=". = 'QString'"> + QString arg<xsl:value-of select="$idx" /> = extractQString(exec, args, <xsl:value-of select="$idx" />); + </xsl:when> + <xsl:when test=". = 'const QString &'"> + QString arg<xsl:value-of select="$idx" /> = extractQString(exec, args, <xsl:value-of select="$idx" />); + </xsl:when> + <xsl:when test=". = 'QString &'"> + QString arg<xsl:value-of select="$idx" /> = extractQString(exec, args, <xsl:value-of select="$idx" />); + </xsl:when> + <xsl:when test=". = 'const QCString &'"> + const QCString arg<xsl:value-of select="$idx" /> = (args.size() >= <xsl:value-of select="position()" />) ? args[<xsl:value-of select="$idx" />].toString(exec).ascii() : 0; + </xsl:when> + <xsl:when test=". = 'const char *'"> + const char *arg<xsl:value-of select="$idx" /> = (args.size() >= <xsl:value-of select="position()" />) ? args[<xsl:value-of select="$idx" />].toString(exec).ascii() : 0; + </xsl:when> + <xsl:when test=". = 'int'"> + int arg<xsl:value-of select="$idx" /> = extractInt(exec, args, <xsl:value-of select="$idx" />); + </xsl:when> + <xsl:when test=". = 'uint'"> + uint arg<xsl:value-of select="$idx" /> = extractUInt(exec, args, <xsl:value-of select="$idx" />); + </xsl:when> + <xsl:when test=". = 'double'"> + double arg<xsl:value-of select="$idx" /> = extractDouble(exec, args, <xsl:value-of select="$idx" />); + </xsl:when> + <xsl:when test=". = 'bool'"> + bool arg<xsl:value-of select="$idx" /> = extractBool(exec, args, <xsl:value-of select="$idx" />); + </xsl:when> + <xsl:when test=". = 'const QFont &'"> + QFont arg<xsl:value-of select="$idx" /> = extractQFont(exec, args, <xsl:value-of select="$idx" />); + </xsl:when> + <xsl:when test=". = 'const QPalette &'"> + QPalette arg<xsl:value-of select="$idx" /> = extractQPalette(exec, args, <xsl:value-of select="$idx" />); + </xsl:when> + <xsl:when test=". = 'const QStringList &'"> + QStringList arg<xsl:value-of select="$idx" /> = extractQStringList(exec, args, <xsl:value-of select="$idx" />); + </xsl:when> + <xsl:when test=". = 'const QStrList &'"> + QStrList arg<xsl:value-of select="$idx" /> = extractQStrList(exec, args, <xsl:value-of select="$idx" />); + </xsl:when> + <xsl:when test=". = 'const QPoint &'"> + QPoint arg<xsl:value-of select="$idx" /> = extractQPoint(exec, args, <xsl:value-of select="$idx" />); + </xsl:when> + <xsl:when test=". = 'const QRect &'"> + QRect arg<xsl:value-of select="$idx" /> = extractQRect(exec, args, <xsl:value-of select="$idx" />); + </xsl:when> + <xsl:when test=". = 'const QSize &'"> + QSize arg<xsl:value-of select="$idx" /> = extractQSize(exec, args, <xsl:value-of select="$idx" />); + </xsl:when> + <xsl:when test=". = 'const QPixmap &'"> + QPixmap arg<xsl:value-of select="$idx" /> = extractQPixmap(exec, args, <xsl:value-of select="$idx" />); + </xsl:when> + <xsl:when test=". = 'const QImage &'"> + QImage arg<xsl:value-of select="$idx" /> = extractQImage(exec, args, <xsl:value-of select="$idx" />); + </xsl:when> + <xsl:when test=". = 'const QColor &'"> + QColor arg<xsl:value-of select="$idx" /> = extractQColor(exec, args, <xsl:value-of select="$idx" />); + </xsl:when> + <xsl:when test=". = 'const QDate &'"> + QDate arg<xsl:value-of select="$idx" /> = extractQDate(exec, args, <xsl:value-of select="$idx" />); + </xsl:when> + <xsl:when test=". = 'const QTime &'"> + QTime arg<xsl:value-of select="$idx" /> = extractQTime(exec, args, <xsl:value-of select="$idx" />); + </xsl:when> + <xsl:when test=". = 'const QDateTime &'"> + QDateTime arg<xsl:value-of select="$idx" /> = extractQDateTime(exec, args, <xsl:value-of select="$idx" />); + </xsl:when> + + <xsl:when test=". = 'WFlags'"> + Qt::WFlags arg<xsl:value-of select="$idx" />; // TODO (hack for QCanvasView) + </xsl:when> + + <xsl:otherwise> + // Unsupported parameter <xsl:value-of select="." /> + return KJS::Object(); + + <xsl:value-of select="." /> arg<xsl:value-of select="$idx" />; // Dummy + </xsl:otherwise> + </xsl:choose> + </xsl:for-each> + + // We should now create an instance of the <xsl:value-of select="$clazz" /> object + + <xsl:value-of select="$clazz" /> *ret = new <xsl:value-of select="$clazz" />( + <xsl:for-each select="param"> + arg<xsl:value-of select="position()-1" /><xsl:if test="position() != count(../param)">,</xsl:if> + </xsl:for-each> ); + + <xsl:if test="($clazz = 'QCanvasItem') or ($clazz = 'QCanvasPolygonalItem')"> +#endif // This constructor has been disabled by the XSL template + </xsl:if> +} + </xsl:when> + </xsl:choose> +</xsl:for-each> + +<!-- Select and invoke the correct method. --> +KJS::Value <xsl:value-of select="$clazz" />Imp::call( KJS::ExecState *exec, KJS::Object &self, const KJS::List &args ) +{ + instance = <xsl:value-of select="$clazz" />Imp::to<xsl:value-of select="$clazz" />( self ); + + switch( id ) { +<xsl:for-each select="$consmeth"> + <xsl:variable name="method_name"><xsl:value-of select="name" />_<xsl:value-of select="position()" /></xsl:variable> + <xsl:variable name="method_id">Method_<xsl:value-of select="$method_name" /></xsl:variable> + <xsl:choose> + <xsl:when test="not(starts-with( name, 'operator' ) or starts-with( name, '~' ) or starts-with( name, $clazz ))"> + case <xsl:value-of select="$method_id" />: + return <xsl:value-of select="$method_name" />( exec, self, args ); + break; + </xsl:when> + </xsl:choose> +</xsl:for-each> + default: + break; + } + + QString msg = i18n( "<xsl:value-of select="$clazz" />Imp has no method with id '%1'" ).arg( id ); + KJS::Object err = KJS::Error::create( exec, KJS::ReferenceError, msg.utf8() ); + exec->setException( err ); + return err; +} + +<!-- Create the implementation for each method. --> +<xsl:for-each select="$consmeth"> +<xsl:variable name="method"> +<xsl:value-of select="$clazz" />Imp::<xsl:value-of select="name" />_<xsl:value-of select="position()" /> +</xsl:variable> + + <xsl:choose> + <xsl:when test="(name != $clazz) and not(starts-with(name, 'operator') or starts-with(name, '~'))"> +<!-- Binding defined for a specific method. --> +KJS::Value <xsl:value-of select="$method" />( KJS::ExecState *exec, KJS::Object &obj, const KJS::List &args ) +{ + <xsl:for-each select="param/type"> + + <xsl:variable name="idx" select="position()-1" /> + + <xsl:choose> + <xsl:when test=". = 'QString'"> + QString arg<xsl:value-of select="$idx" /> = extractQString(exec, args, <xsl:value-of select="$idx" />); + </xsl:when> + <xsl:when test=". = 'const QString &'"> + QString arg<xsl:value-of select="$idx" /> = extractQString(exec, args, <xsl:value-of select="$idx" />); + </xsl:when> + <xsl:when test=". = 'QString &'"> + QString arg<xsl:value-of select="$idx" /> = extractQString(exec, args, <xsl:value-of select="$idx" />); + </xsl:when> + <xsl:when test=". = 'const QCString &'"> + const QCString arg<xsl:value-of select="$idx" /> = (args.size() >= <xsl:value-of select="position()" />) ? args[<xsl:value-of select="$idx" />].toString(exec).ascii() : 0; + </xsl:when> + <xsl:when test=". = 'const char *'"> + const char *arg<xsl:value-of select="$idx" /> = (args.size() >= <xsl:value-of select="position()" />) ? args[<xsl:value-of select="$idx" />].toString(exec).ascii() : 0; + </xsl:when> + <xsl:when test=". = 'int'"> + int arg<xsl:value-of select="$idx" /> = extractInt(exec, args, <xsl:value-of select="$idx" />); + </xsl:when> + <xsl:when test=". = 'uint'"> + uint arg<xsl:value-of select="$idx" /> = extractUInt(exec, args, <xsl:value-of select="$idx" />); + </xsl:when> + <xsl:when test=". = 'double'"> + double arg<xsl:value-of select="$idx" /> = extractDouble(exec, args, <xsl:value-of select="$idx" />); + </xsl:when> + <xsl:when test=". = 'bool'"> + bool arg<xsl:value-of select="$idx" /> = extractBool(exec, args, <xsl:value-of select="$idx" />); + </xsl:when> + <xsl:when test=". = 'const QFont &'"> + QFont arg<xsl:value-of select="$idx" /> = extractQFont(exec, args, <xsl:value-of select="$idx" />); + </xsl:when> + <xsl:when test=". = 'const QPalette &'"> + QPalette arg<xsl:value-of select="$idx" /> = extractQPalette(exec, args, <xsl:value-of select="$idx" />); + </xsl:when> + <xsl:when test=". = 'const QStringList &'"> + QStringList arg<xsl:value-of select="$idx" /> = extractQStringList(exec, args, <xsl:value-of select="$idx" />); + </xsl:when> + <xsl:when test=". = 'const QStrList &'"> + QStrList arg<xsl:value-of select="$idx" /> = extractQStrList(exec, args, <xsl:value-of select="$idx" />); + </xsl:when> + <xsl:when test=". = 'const QPoint &'"> + QPoint arg<xsl:value-of select="$idx" /> = extractQPoint(exec, args, <xsl:value-of select="$idx" />); + </xsl:when> + <xsl:when test=". = 'const QRect &'"> + QRect arg<xsl:value-of select="$idx" /> = extractQRect(exec, args, <xsl:value-of select="$idx" />); + </xsl:when> + <xsl:when test=". = 'const QSize &'"> + QSize arg<xsl:value-of select="$idx" /> = extractQSize(exec, args, <xsl:value-of select="$idx" />); + </xsl:when> + <xsl:when test=". = 'const QPixmap &'"> + QPixmap arg<xsl:value-of select="$idx" /> = extractQPixmap(exec, args, <xsl:value-of select="$idx" />); + </xsl:when> + <xsl:when test=". = 'const QImage &'"> + QImage arg<xsl:value-of select="$idx" /> = extractQImage(exec, args, <xsl:value-of select="$idx" />); + </xsl:when> + <xsl:when test=". = 'const QColor &'"> + QColor arg<xsl:value-of select="$idx" /> = extractQColor(exec, args, <xsl:value-of select="$idx" />); + </xsl:when> + <xsl:when test=". = 'const QDate &'"> + QDate arg<xsl:value-of select="$idx" /> = extractQDate(exec, args, <xsl:value-of select="$idx" />); + </xsl:when> + <xsl:when test=". = 'const QTime &'"> + QTime arg<xsl:value-of select="$idx" /> = extractQTime(exec, args, <xsl:value-of select="$idx" />); + </xsl:when> + <xsl:when test=". = 'const QDateTime &'"> + QDateTime arg<xsl:value-of select="$idx" /> = extractQDateTime(exec, args, <xsl:value-of select="$idx" />); + </xsl:when> + + <!-- Hacks for enum types, this should be handled in a much cleaner way. --> + + <xsl:when test=". = 'Policy'"> + QComboBox::Policy arg<xsl:value-of select="$idx" />; // TODO (hack for combo box) + </xsl:when> + <xsl:when test=". = 'Shape'"> + QFrame::Shape arg<xsl:value-of select="$idx" />; // TODO (hack for frame) + </xsl:when> + <xsl:when test=". = 'Shadow'"> + QFrame::Shadow arg<xsl:value-of select="$idx" />; // TODO (hack for frame) + </xsl:when> + <xsl:when test=". = 'FILE *'"> + FILE *arg<xsl:value-of select="$idx" />; // TODO (hack for qfile) + </xsl:when> + <xsl:when test=". = 'Offset'"> + QFile::Offset arg<xsl:value-of select="$idx" />; // TODO (hack for qfile) + </xsl:when> + <xsl:when test=". = 'EncoderFn'"> + QFile::EncoderFn arg<xsl:value-of select="$idx" />; // TODO (hack for qfile) + </xsl:when> + <xsl:when test=". = 'DecoderFn'"> + QFile::DecoderFn arg<xsl:value-of select="$idx" />; // TODO (hack for qfile) + </xsl:when> + <xsl:when test=". = 'FrameAnimationType'"> + QCanvasSprite::FrameAnimationType arg<xsl:value-of select="$idx" />; // TODO (hack for QCanvasSprite) + </xsl:when> + <xsl:when test=". = 'WFlags'"> + Qt::WFlags arg<xsl:value-of select="$idx" />; // TODO (hack for QCanvasView) + </xsl:when> + + <!-- Unsupported for now --> + + <xsl:when test=". = 'const QByteArray &'"> + QByteArray arg<xsl:value-of select="$idx" />; // TODO (hack for qfile) + </xsl:when> + <xsl:when test=". = 'const QPointArray &'"> + QPointArray arg<xsl:value-of select="$idx" />; // TODO (hack for qcanvas) + </xsl:when> + <xsl:when test=". = 'QPainter &'"> + QPainter arg<xsl:value-of select="$idx" />; // TODO (hack for qcanvas) + </xsl:when> + <xsl:when test=". = 'const QPainter &'"> + QPainter arg<xsl:value-of select="$idx" />; // TODO (hack for qcanvas) + </xsl:when> + <xsl:when test=". = 'const QWMatrix &'"> + QWMatrix arg<xsl:value-of select="$idx" />; // TODO (hack for qcanvasview) + </xsl:when> + + <xsl:otherwise> + // Unsupported parameter <xsl:value-of select="." /> + return KJS::Value(); + + <xsl:value-of select="." /> arg<xsl:value-of select="$idx" />; // Dummy + </xsl:otherwise> + </xsl:choose> + </xsl:for-each> + + <!-- Specifies the return type --> + <xsl:variable name="rettype"> + <xsl:choose> + <xsl:when test="starts-with(type,'virtual ')"> + <xsl:value-of select="substring-after(type,'virtual ')" /> + </xsl:when> + <xsl:otherwise><xsl:value-of select="type" /></xsl:otherwise> + </xsl:choose> + </xsl:variable> + + <xsl:choose> + + <xsl:when test="$rettype = 'bool'"> + bool ret; + ret = instance-><xsl:value-of select="name" />( <xsl:for-each select="param"> + arg<xsl:value-of select="position()-1" /><xsl:if test="position() != count(../param)">,</xsl:if></xsl:for-each> ); + return KJS::Boolean( ret ); + </xsl:when> + + <xsl:when test="$rettype = 'int'"> + int ret; + ret = instance-><xsl:value-of select="name" />( <xsl:for-each select="param"> + arg<xsl:value-of select="position()-1" /><xsl:if test="position() != count(../param)">,</xsl:if></xsl:for-each> ); + return KJS::Number( ret ); + </xsl:when> + + <xsl:when test="$rettype = 'uint'"> + uint ret; + ret = instance-><xsl:value-of select="name" />( <xsl:for-each select="param"> + arg<xsl:value-of select="position()-1" /><xsl:if test="position() != count(../param)">,</xsl:if></xsl:for-each> ); + return KJS::Number( ret ); + </xsl:when> + + <xsl:when test="$rettype = 'double'"> + double ret; + ret = instance-><xsl:value-of select="name" />( <xsl:for-each select="param"> + arg<xsl:value-of select="position()-1" /><xsl:if test="position() != count(../param)">,</xsl:if></xsl:for-each> ); + return KJS::Number( ret ); + </xsl:when> + + <xsl:when test="$rettype = 'QString'"> + QString ret; + ret = instance-><xsl:value-of select="name" />( <xsl:for-each select="param"> + arg<xsl:value-of select="position()-1" /><xsl:if test="position() != count(../param)">,</xsl:if></xsl:for-each> ); + return KJS::String( ret ); + </xsl:when> + + <xsl:when test="$rettype = 'const char *'"> + const char *ret; + ret = instance-><xsl:value-of select="name" />( <xsl:for-each select="param"> + arg<xsl:value-of select="position()-1" /><xsl:if test="position() != count(../param)">,</xsl:if></xsl:for-each> ); + return KJS::String( ret ); + </xsl:when> + + <!-- Value returns --> + + <xsl:when test="($rettype = 'QRect') or ($rettype = 'QSize') or ($rettype = 'QPoint') + or ($rettype = 'QPixmap') or ($rettype = 'QImage') or ($rettype = 'QBrush') + or ($rettype = 'QPen') or ($rettype = 'QDate') or ($rettype = 'QDateTime') + or ($rettype = 'QTime')"> + <xsl:value-of select="$rettype"/> ret; + ret = instance-><xsl:value-of select="name" />( <xsl:for-each select="param"> + arg<xsl:value-of select="position()-1" /><xsl:if test="position() != count(../param)">,</xsl:if></xsl:for-each> ); + + return convertToValue( exec, ret ); + </xsl:when> + <xsl:when test="$rettype = 'QStringList'"> + QStringList ret; + ret = instance-><xsl:value-of select="name" />( <xsl:for-each select="param"> + arg<xsl:value-of select="position()-1" /><xsl:if test="position() != count(../param)">,</xsl:if></xsl:for-each> ); + + return convertToValue( exec, ret ); + </xsl:when> + + <!-- Special returns --> + + <xsl:when test="$rettype = 'void'"> + instance-><xsl:value-of select="name" />( <xsl:for-each select="param"> + arg<xsl:value-of select="position()-1" /><xsl:if test="position() != count(../param)">,</xsl:if></xsl:for-each> ); + return KJS::Value(); // Returns void + </xsl:when> + + <xsl:otherwise> + instance-><xsl:value-of select="name" />( <xsl:for-each select="param"> + arg<xsl:value-of select="position()-1" /><xsl:if test="position() != count(../param)">,</xsl:if></xsl:for-each> ); + return KJS::Value(); // Returns '<xsl:value-of select="$rettype" />' + </xsl:otherwise> + </xsl:choose> +} + </xsl:when> + </xsl:choose> +</xsl:for-each> + +} // namespace KJSEmbed + +// Local Variables: +// c-basic-offset: 4 +// End: + +</xsl:template> +</xsl:stylesheet> diff --git a/kjsembed/bindwizard/doxygen2imp_h.xsl b/kjsembed/bindwizard/doxygen2imp_h.xsl new file mode 100644 index 00000000..d5aaa8d2 --- /dev/null +++ b/kjsembed/bindwizard/doxygen2imp_h.xsl @@ -0,0 +1,128 @@ +<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform"> +<xsl:output method="text" /> + +<xsl:template match="/doxygen/compounddef"> + +<xsl:variable name="clazz" select="compoundname" /> +<xsl:variable name="consmeth" select="sectiondef/memberdef[@kind='function' and @prot='public']" /> + +#ifndef KJSEMBED_<xsl:value-of select="$clazz" />_H +#define KJSEMBED_<xsl:value-of select="$clazz" />_H + +#include <kjs/interpreter.h> +#include <kjs/object.h> + +#include <kjsembed/jsobjectproxy_imp.h> + +class <xsl:value-of select="$clazz" />; + +/** + * Namespace containing the KJSEmbed library. + */ +namespace KJSEmbed { + +/** + * Wrapper class for <xsl:value-of select="$clazz" /> methods. + * + * @author Richard Moore, rich@kde.org + */ +class <xsl:value-of select="$clazz" />Imp : public JSProxyImp +{ +public: + /** Enumerates the constructors supported by this class. */ + enum Constructors { +<xsl:for-each select="$consmeth"> + <xsl:choose> + <xsl:when test="name = $clazz"> + <xsl:variable name="cons_name"><xsl:value-of select="name" />_<xsl:value-of select="position()" /></xsl:variable> + <xsl:variable name="cons_id">Constructor_<xsl:value-of select="$cons_name" /></xsl:variable> + <xsl:text> </xsl:text><xsl:value-of select="$cons_id" />, +</xsl:when> + </xsl:choose> +</xsl:for-each> + LastConstuctor = -1 + }; + + /** Enumerates the methods supported by this class. */ + enum Methods { +<xsl:for-each select="$consmeth"> + <xsl:variable name="method_name"><xsl:value-of select="name" />_<xsl:value-of select="position()" /></xsl:variable> + <xsl:choose> + <xsl:when test="not(starts-with( name, 'operator' ) or starts-with( name, '~' ) or starts-with( name, $clazz ))"> + Method_<xsl:value-of select="$method_name" />,</xsl:when> + </xsl:choose> +</xsl:for-each> + Method_Last = -1 + }; + + <xsl:value-of select="$clazz" />Imp( KJS::ExecState *exec, int id, bool constructor=false ); + ~<xsl:value-of select="$clazz" />Imp(); + + /** + * Adds the static bindings for this class to the specified Object. The + * static bindings are the static methods and the enums of this class. + */ + static void addStaticBindings( KJS::ExecState *exec, KJS::Object &object ); + + /** + * Adds the bindings for this class to the specified Object. The bindings + * added are the instance methods of this class. + */ + static void addBindings( KJS::ExecState *exec, KJS::Object &object ); + + static <xsl:value-of select="$clazz" /> *to<xsl:value-of select="$clazz" />( KJS::Object &object ); + + // + // Constructors implemented by this class. + // +<xsl:for-each select="$consmeth"> + <xsl:variable name="cons_name"><xsl:value-of select="name" />_<xsl:value-of select="position()" /></xsl:variable> + <xsl:choose> + <xsl:when test="name = $clazz"> + KJS::Object <xsl:value-of select="$cons_name" />( KJS::ExecState *exec, const KJS::List &args );</xsl:when> + </xsl:choose> +</xsl:for-each> + + // + // Methods implemented by this class. + // +<xsl:for-each select="$consmeth"> + <xsl:variable name="method_name"><xsl:value-of select="name" />_<xsl:value-of select="position()" /></xsl:variable> + <xsl:choose> + <xsl:when test="not(starts-with( name, 'operator' ) or starts-with( name, '~' ) or starts-with( name, $clazz ))"> + KJS::Value <xsl:value-of select="$method_name" />( KJS::ExecState *exec, KJS::Object &obj, const KJS::List &args );</xsl:when> + </xsl:choose> +</xsl:for-each> + + // + // JS binding code. + // + + /** Returns true iff this object implements the construct function. */ + virtual bool implementsConstruct() const { return cons; } + + /** Invokes the construct function. */ + virtual KJS::Object construct( KJS::ExecState *exec, const KJS::List &args ); + + /** Returns true iff this object implements the call function. */ + virtual bool implementsCall() const { return !cons; } + + /** Invokes the call function. */ + virtual KJS::Value call( KJS::ExecState *exec, KJS::Object &self, const KJS::List &args ); + +private: + <xsl:value-of select="$clazz" /> *instance; // Temp + int id; + bool cons; +}; + +} // namespace KJSEmbed + +#endif // KJSEMBED_<xsl:value-of select="compoundname" />_H + +// Local Variables: +// c-basic-offset: 4 +// End: + +</xsl:template> +</xsl:stylesheet> diff --git a/kjsembed/bindwizard/index_classes.xsl b/kjsembed/bindwizard/index_classes.xsl new file mode 100644 index 00000000..88309be6 --- /dev/null +++ b/kjsembed/bindwizard/index_classes.xsl @@ -0,0 +1,11 @@ +<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform"> +<xsl:output method="xml" /> + +<xsl:template match="/doxygen"> +<classes> + <xsl:for-each select="compound[@kind='class']"> + <class><xsl:value-of select="name/text()" /></class> + </xsl:for-each> +</classes> +</xsl:template> +</xsl:stylesheet> diff --git a/kjsembed/builtins/Makefile.am b/kjsembed/builtins/Makefile.am new file mode 100644 index 00000000..d1b1ade9 --- /dev/null +++ b/kjsembed/builtins/Makefile.am @@ -0,0 +1,18 @@ +INCLUDES= -I$(srcdir)/../.. -I.. -I$(top_srcdir)/kjsembed $(all_includes) +KDE_CXXFLAGS = -DQT_NO_ASCII_CAST -DQT_CLEAN_NAMESPACE -Wno-unused + +noinst_LTLIBRARIES = libkjsembedbuiltins.la + +libkjsembedbuiltins_la_SOURCES = stdaction_imp.cpp \ + resources.cpp \ + stddialog_imp.cpp \ + saxhandler.cpp \ + textstream_imp.cpp \ + qdir_imp.cpp \ + qfile_imp.cpp + +libkjsembedbuiltins_la_LDFLAGS = $(all_libraries) $(KDE_RPATH) +libkjsembedbuiltins_la_LIBADD = $(LIB_QT) $(LIB_KDECORE) $(LIB_KDEUI) $(LIB_KPARTS) \ + $(LIB_KFILE) -lkjs $(LIBSOCKET) + +libkjsembedbuiltins_la_METASOURCES = AUTO diff --git a/kjsembed/builtins/builtins.pro b/kjsembed/builtins/builtins.pro new file mode 100644 index 00000000..cb408cf2 --- /dev/null +++ b/kjsembed/builtins/builtins.pro @@ -0,0 +1,18 @@ +# File generated by kdevelop's qmake manager. +# ------------------------------------------- +# Subdir relative project main directory: ./builtins +# Target is a library: +include(../qjsembed.pri) +INCLUDEPATH += .. . ../.. +CONFIG += staticlib +TEMPLATE = lib +HEADERS += textstream_imp.h \ + qdir_imp.h \ + saxhandler.h \ + stddialog_imp.h + +SOURCES += saxhandler.cpp \ + qdir_imp.cpp \ + stddialog_imp.cpp \ + textstream_imp.cpp \ + qfile_imp.cpp diff --git a/kjsembed/builtins/qdir_imp.cpp b/kjsembed/builtins/qdir_imp.cpp new file mode 100644 index 00000000..32d79d14 --- /dev/null +++ b/kjsembed/builtins/qdir_imp.cpp @@ -0,0 +1,1009 @@ + + + +#include <kjsembed/global.h> + +#include <kjs/object.h> + +#ifndef QT_ONLY +#include <klocale.h> +#include <kdebug.h> +#endif + + +#include <kjsembed/jsopaqueproxy.h> +#include <kjsembed/jsbinding.h> + +#include <qdir.h> +#include "qdir_imp.h" + +/** + * Namespace containing the KJSEmbed library. + */ +namespace KJSEmbed { +namespace Bindings { + KJS::Object QDirLoader::createBinding(KJSEmbedPart *jspart, KJS::ExecState *exec, const KJS::List &args) const + { + JSOpaqueProxy * prx; + if ( args.size() == 0 ) { + prx = new JSOpaqueProxy( new QDir( QDir::current() ), "QDir" ); + } else { + QString arg0 = ( args.size() >= 1 ) ? args[ 0 ].toString( exec ).qstring() : QString::null; + prx = new JSOpaqueProxy( new QDir( arg0 ), "QDir" ); + } + prx->setOwner( JSProxy::JavaScript ); + KJS::Object proxyObj( prx ); + addBindings( jspart, exec, proxyObj ); + return proxyObj; + } + + void QDirLoader::addBindings( KJSEmbedPart *jspart, KJS::ExecState *exec, KJS::Object &proxy ) const + { + QDirImp::addBindings( exec, proxy ); + } + +} + +QDirImp::QDirImp( KJS::ExecState *exec, int id ) + : JSProxyImp(exec), mid(id) +{ +} + +QDirImp::~QDirImp() +{ +} + +void QDirImp::addBindings( KJS::ExecState *exec, KJS::Object &object ) +{ + JSProxy::MethodTable methods[] = { + + { Method_setPath_7, "setPath" }, + + { Method_path_8, "path" }, + + { Method_absPath_9, "absPath" }, + + { Method_canonicalPath_10, "canonicalPath" }, + + { Method_dirName_11, "dirName" }, + + { Method_filePath_12, "filePath" }, + + { Method_absFilePath_13, "absFilePath" }, + + { Method_cd_14, "cd" }, + + { Method_cdUp_15, "cdUp" }, + + { Method_nameFilter_16, "nameFilter" }, + + { Method_setNameFilter_17, "setNameFilter" }, + + { Method_filter_18, "filter" }, + + { Method_setFilter_19, "setFilter" }, + + { Method_sorting_20, "sorting" }, + + { Method_setSorting_21, "setSorting" }, + + { Method_matchAllDirs_22, "matchAllDirs" }, + + { Method_setMatchAllDirs_23, "setMatchAllDirs" }, + + { Method_count_24, "count" }, + + { Method_encodedEntryList_26, "encodedEntryList" }, + + { Method_encodedEntryList_27, "encodedEntryList" }, + + { Method_entryList_28, "entryList" }, + + { Method_entryList_29, "entryList" }, + + { Method_entryInfoList_30, "entryInfoList" }, + + { Method_entryInfoList_31, "entryInfoList" }, + + { Method_mkdir_32, "mkdir" }, + + { Method_rmdir_33, "rmdir" }, + + { Method_isReadable_34, "isReadable" }, + + { Method_exists_35, "exists" }, + + { Method_isRoot_36, "isRoot" }, + + { Method_isRelative_37, "isRelative" }, + + { Method_convertToAbs_38, "convertToAbs" }, + + { Method_remove_41, "remove" }, + + { Method_rename_42, "rename" }, + + { Method_exists_43, "exists" }, + + { Method_refresh_44, "refresh" }, + + { Method_convertSeparators_45, "convertSeparators" }, + + { Method_drives_46, "drives" }, + + { Method_separator_47, "separator" }, + + { Method_setCurrent_48, "setCurrent" }, + + { Method_current_49, "current" }, + + { Method_home_50, "home" }, + + { Method_root_51, "root" }, + + { Method_currentDirPath_52, "currentDirPath" }, + + { Method_homeDirPath_53, "homeDirPath" }, + + { Method_rootDirPath_54, "rootDirPath" }, + + { Method_match_55, "match" }, + + { Method_match_56, "match" }, + + { Method_cleanDirPath_57, "cleanDirPath" }, + + { Method_isRelativePath_58, "isRelativePath" }, + + { 0, 0 } + }; + + int idx = 0; + do { + QDirImp *meth = new QDirImp( exec, methods[idx].id ); + object.put( exec , methods[idx].name, KJS::Object(meth) ); + ++idx; + } while( methods[idx].id ); + + // + // Define the enum constants + // + struct EnumValue { + const char *id; + int val; + }; + + + EnumValue enums[] = { + + // enum FilterSpec + { "Dirs", QDir::Dirs }, + { "Files", QDir::Files }, + { "Drives", QDir::Drives }, + { "NoSymLinks", QDir::NoSymLinks }, + { "All", QDir::All }, + { "TypeMask", QDir::TypeMask }, + { "Readable", QDir::Readable }, + { "Writable", QDir::Writable }, + { "Executable", QDir::Executable }, + { "RWEMask", QDir::RWEMask }, + { "Modified", QDir::Modified }, + { "Hidden", QDir::Hidden }, + { "System", QDir::System }, + { "AccessMask", QDir::AccessMask }, + { "DefaultFilter", QDir::DefaultFilter }, + // enum SortSpec + { "Name", QDir::Name }, + { "Time", QDir::Time }, + { "Size", QDir::Size }, + { "Unsorted", QDir::Unsorted }, + { "SortByMask", QDir::SortByMask }, + { "DirsFirst", QDir::DirsFirst }, + { "Reversed", QDir::Reversed }, + { "IgnoreCase", QDir::IgnoreCase }, + { "DefaultSort", QDir::DefaultSort }, + { 0, 0 } + }; + + int enumidx = 0; + do { + object.put( exec, enums[enumidx].id, KJS::Number(enums[enumidx].val), KJS::ReadOnly ); + ++enumidx; + } while( enums[enumidx].id ); + +} + + +KJS::Value QDirImp::call( KJS::ExecState *exec, KJS::Object &self, const KJS::List &args ) +{ + JSOpaqueProxy *op = JSProxy::toOpaqueProxy( self.imp() ); + if ( !op ) { + kdWarning() << "QDirImp::call() failed, not a JSOpaqueProxy" << endl; + return KJS::Value(); + } + + if ( op->typeName() != "QDir" ) { + kdWarning() << "QDirImp::call() failed, type is " << op->typeName() << endl; + return KJS::Value(); + } + + instance = op->toNative<QDir>(); + + switch( mid ) { + + case Method_setPath_7: + return setPath_7( exec, self, args ); + break; + + case Method_path_8: + return path_8( exec, self, args ); + break; + + case Method_absPath_9: + return absPath_9( exec, self, args ); + break; + + case Method_canonicalPath_10: + return canonicalPath_10( exec, self, args ); + break; + + case Method_dirName_11: + return dirName_11( exec, self, args ); + break; + + case Method_filePath_12: + return filePath_12( exec, self, args ); + break; + + case Method_absFilePath_13: + return absFilePath_13( exec, self, args ); + break; + + case Method_cd_14: + return cd_14( exec, self, args ); + break; + + case Method_cdUp_15: + return cdUp_15( exec, self, args ); + break; + + case Method_nameFilter_16: + return nameFilter_16( exec, self, args ); + break; + + case Method_setNameFilter_17: + return setNameFilter_17( exec, self, args ); + break; + + case Method_filter_18: + return filter_18( exec, self, args ); + break; + + case Method_setFilter_19: + return setFilter_19( exec, self, args ); + break; + + case Method_sorting_20: + return sorting_20( exec, self, args ); + break; + + case Method_setSorting_21: + return setSorting_21( exec, self, args ); + break; + + case Method_matchAllDirs_22: + return matchAllDirs_22( exec, self, args ); + break; + + case Method_setMatchAllDirs_23: + return setMatchAllDirs_23( exec, self, args ); + break; + + case Method_count_24: + return count_24( exec, self, args ); + break; + + case Method_encodedEntryList_26: + return encodedEntryList_26( exec, self, args ); + break; + + case Method_encodedEntryList_27: + return encodedEntryList_27( exec, self, args ); + break; + + case Method_entryList_28: + return entryList_28( exec, self, args ); + break; + + case Method_entryList_29: + return entryList_29( exec, self, args ); + break; + + case Method_entryInfoList_30: + return entryInfoList_30( exec, self, args ); + break; + + case Method_entryInfoList_31: + return entryInfoList_31( exec, self, args ); + break; + + case Method_mkdir_32: + return mkdir_32( exec, self, args ); + break; + + case Method_rmdir_33: + return rmdir_33( exec, self, args ); + break; + + case Method_isReadable_34: + return isReadable_34( exec, self, args ); + break; + + case Method_exists_35: + return exists_35( exec, self, args ); + break; + + case Method_isRoot_36: + return isRoot_36( exec, self, args ); + break; + + case Method_isRelative_37: + return isRelative_37( exec, self, args ); + break; + + case Method_convertToAbs_38: + return convertToAbs_38( exec, self, args ); + break; + + case Method_remove_41: + return remove_41( exec, self, args ); + break; + + case Method_rename_42: + return rename_42( exec, self, args ); + break; + + case Method_exists_43: + return exists_43( exec, self, args ); + break; + + case Method_refresh_44: + return refresh_44( exec, self, args ); + break; + + case Method_convertSeparators_45: + return convertSeparators_45( exec, self, args ); + break; + + case Method_drives_46: + return drives_46( exec, self, args ); + break; + + case Method_separator_47: + return separator_47( exec, self, args ); + break; + + case Method_setCurrent_48: + return setCurrent_48( exec, self, args ); + break; + + case Method_current_49: + return current_49( exec, self, args ); + break; + + case Method_home_50: + return home_50( exec, self, args ); + break; + + case Method_root_51: + return root_51( exec, self, args ); + break; + + case Method_currentDirPath_52: + return currentDirPath_52( exec, self, args ); + break; + + case Method_homeDirPath_53: + return homeDirPath_53( exec, self, args ); + break; + + case Method_rootDirPath_54: + return rootDirPath_54( exec, self, args ); + break; + + case Method_match_55: + return match_55( exec, self, args ); + break; + + case Method_match_56: + return match_56( exec, self, args ); + break; + + case Method_cleanDirPath_57: + return cleanDirPath_57( exec, self, args ); + break; + + case Method_isRelativePath_58: + return isRelativePath_58( exec, self, args ); + break; + + default: + break; + } + + QString msg = i18n( "QDirImp has no method with id '%1'." ).arg( mid ); + return throwError(exec, msg,KJS::ReferenceError); +} + + +KJS::Value QDirImp::setPath_7( KJS::ExecState *exec, KJS::Object &obj, const KJS::List &args ) +{ + + QString arg0 = (args.size() >= 1) ? args[0].toString(exec).qstring() : QString::null; + + instance->setPath( + arg0 ); + return KJS::Value(); // Returns void + +} + +KJS::Value QDirImp::path_8( KJS::ExecState *exec, KJS::Object &obj, const KJS::List &args ) +{ + + QString ret; + ret = instance->path( ); + return KJS::String( ret ); + +} + +KJS::Value QDirImp::absPath_9( KJS::ExecState *exec, KJS::Object &obj, const KJS::List &args ) +{ + + QString ret; + ret = instance->absPath( ); + return KJS::String( ret ); + +} + +KJS::Value QDirImp::canonicalPath_10( KJS::ExecState *exec, KJS::Object &obj, const KJS::List &args ) +{ + + QString ret; + ret = instance->canonicalPath( ); + return KJS::String( ret ); + +} + +KJS::Value QDirImp::dirName_11( KJS::ExecState *exec, KJS::Object &obj, const KJS::List &args ) +{ + + QString ret; + ret = instance->dirName( ); + return KJS::String( ret ); + +} + +KJS::Value QDirImp::filePath_12( KJS::ExecState *exec, KJS::Object &obj, const KJS::List &args ) +{ + + QString arg0 = (args.size() >= 1) ? args[0].toString(exec).qstring() : QString::null; + + bool arg1 = (args.size() >= 2) ? args[1].toBoolean(exec) : false; + + QString ret; + ret = instance->filePath( + arg0, + arg1 ); + return KJS::String( ret ); + +} + +KJS::Value QDirImp::absFilePath_13( KJS::ExecState *exec, KJS::Object &obj, const KJS::List &args ) +{ + + QString arg0 = (args.size() >= 1) ? args[0].toString(exec).qstring() : QString::null; + + bool arg1 = (args.size() >= 2) ? args[1].toBoolean(exec) : false; + + QString ret; + ret = instance->absFilePath( + arg0, + arg1 ); + return KJS::String( ret ); + +} + +KJS::Value QDirImp::cd_14( KJS::ExecState *exec, KJS::Object &obj, const KJS::List &args ) +{ + + QString arg0 = (args.size() >= 1) ? args[0].toString(exec).qstring() : QString::null; + + bool arg1 = (args.size() >= 2) ? args[1].toBoolean(exec) : false; + + bool ret; + ret = instance->cd( + arg0, + arg1 ); + return KJS::Boolean( ret ); + +} + +KJS::Value QDirImp::cdUp_15( KJS::ExecState *exec, KJS::Object &obj, const KJS::List &args ) +{ + + bool ret; + ret = instance->cdUp( ); + return KJS::Boolean( ret ); + +} + +KJS::Value QDirImp::nameFilter_16( KJS::ExecState *exec, KJS::Object &obj, const KJS::List &args ) +{ + + QString ret; + ret = instance->nameFilter( ); + return KJS::String( ret ); + +} + +KJS::Value QDirImp::setNameFilter_17( KJS::ExecState *exec, KJS::Object &obj, const KJS::List &args ) +{ + + QString arg0 = (args.size() >= 1) ? args[0].toString(exec).qstring() : QString::null; + + instance->setNameFilter( + arg0 ); + return KJS::Value(); // Returns void + +} + +KJS::Value QDirImp::filter_18( KJS::ExecState *exec, KJS::Object &obj, const KJS::List &args ) +{ + + instance->filter( ); + return KJS::Value(); // Returns 'FilterSpec' + +} + +KJS::Value QDirImp::setFilter_19( KJS::ExecState *exec, KJS::Object &obj, const KJS::List &args ) +{ + + int arg0 = (args.size() >= 1) ? args[0].toInteger(exec) : -1; + + instance->setFilter( + arg0 ); + return KJS::Value(); // Returns void + +} + +KJS::Value QDirImp::sorting_20( KJS::ExecState *exec, KJS::Object &obj, const KJS::List &args ) +{ + + instance->sorting( ); + return KJS::Value(); // Returns 'SortSpec' + +} + +KJS::Value QDirImp::setSorting_21( KJS::ExecState *exec, KJS::Object &obj, const KJS::List &args ) +{ + + int arg0 = (args.size() >= 1) ? args[0].toInteger(exec) : -1; + + instance->setSorting( + arg0 ); + return KJS::Value(); // Returns void + +} + +KJS::Value QDirImp::matchAllDirs_22( KJS::ExecState *exec, KJS::Object &obj, const KJS::List &args ) +{ + + bool ret; + ret = instance->matchAllDirs( ); + return KJS::Boolean( ret ); + +} + +KJS::Value QDirImp::setMatchAllDirs_23( KJS::ExecState *exec, KJS::Object &obj, const KJS::List &args ) +{ + + bool arg0 = (args.size() >= 1) ? args[0].toBoolean(exec) : false; + + instance->setMatchAllDirs( + arg0 ); + return KJS::Value(); // Returns void + +} + +KJS::Value QDirImp::count_24( KJS::ExecState *exec, KJS::Object &obj, const KJS::List &args ) +{ + + uint ret; + ret = instance->count( ); + return KJS::Number( ret ); + +} + +KJS::Value QDirImp::encodedEntryList_26( KJS::ExecState *exec, KJS::Object &obj, const KJS::List &args ) +{ + + int arg0 = (args.size() >= 1) ? args[0].toInteger(exec) : -1; + + int arg1 = (args.size() >= 2) ? args[1].toInteger(exec) : -1; + + instance->encodedEntryList( + arg0, + arg1 ); + return KJS::Value(); // Returns 'QStrList' + +} + +KJS::Value QDirImp::encodedEntryList_27( KJS::ExecState *exec, KJS::Object &obj, const KJS::List &args ) +{ + + QString arg0 = (args.size() >= 1) ? args[0].toString(exec).qstring() : QString::null; + + int arg1 = (args.size() >= 2) ? args[1].toInteger(exec) : -1; + + int arg2 = (args.size() >= 3) ? args[2].toInteger(exec) : -1; + + instance->encodedEntryList( + arg0, + arg1, + arg2 ); + return KJS::Value(); // Returns 'QStrList' + +} + +KJS::Value QDirImp::entryList_28( KJS::ExecState *exec, KJS::Object &obj, const KJS::List &args ) +{ + + int arg0 = (args.size() >= 1) ? args[0].toInteger(exec) : -1; + + int arg1 = (args.size() >= 2) ? args[1].toInteger(exec) : -1; + + QStringList ret; + ret = instance->entryList( + arg0, + arg1 ); + + return convertToValue( exec, ret ); + +} + +KJS::Value QDirImp::entryList_29( KJS::ExecState *exec, KJS::Object &obj, const KJS::List &args ) +{ + + QString arg0 = (args.size() >= 1) ? args[0].toString(exec).qstring() : QString::null; + + int arg1 = (args.size() >= 2) ? args[1].toInteger(exec) : -1; + + int arg2 = (args.size() >= 3) ? args[2].toInteger(exec) : -1; + + QStringList ret; + ret = instance->entryList( + arg0, + arg1, + arg2 ); + + return convertToValue( exec, ret ); + +} + +KJS::Value QDirImp::entryInfoList_30( KJS::ExecState *exec, KJS::Object &obj, const KJS::List &args ) +{ + + int arg0 = (args.size() >= 1) ? args[0].toInteger(exec) : -1; + + int arg1 = (args.size() >= 2) ? args[1].toInteger(exec) : -1; + + instance->entryInfoList( + arg0, + arg1 ); + return KJS::Value(); // Returns 'const QFileInfoList *' + +} + +KJS::Value QDirImp::entryInfoList_31( KJS::ExecState *exec, KJS::Object &obj, const KJS::List &args ) +{ + + QString arg0 = (args.size() >= 1) ? args[0].toString(exec).qstring() : QString::null; + + int arg1 = (args.size() >= 2) ? args[1].toInteger(exec) : -1; + + int arg2 = (args.size() >= 3) ? args[2].toInteger(exec) : -1; + + instance->entryInfoList( + arg0, + arg1, + arg2 ); + return KJS::Value(); // Returns 'const QFileInfoList *' + +} + +KJS::Value QDirImp::mkdir_32( KJS::ExecState *exec, KJS::Object &obj, const KJS::List &args ) +{ + + QString arg0 = (args.size() >= 1) ? args[0].toString(exec).qstring() : QString::null; + + bool arg1 = (args.size() >= 2) ? args[1].toBoolean(exec) : false; + + bool ret; + ret = instance->mkdir( + arg0, + arg1 ); + return KJS::Boolean( ret ); + +} + +KJS::Value QDirImp::rmdir_33( KJS::ExecState *exec, KJS::Object &obj, const KJS::List &args ) +{ + + QString arg0 = (args.size() >= 1) ? args[0].toString(exec).qstring() : QString::null; + + bool arg1 = (args.size() >= 2) ? args[1].toBoolean(exec) : false; + + bool ret; + ret = instance->rmdir( + arg0, + arg1 ); + return KJS::Boolean( ret ); + +} + +KJS::Value QDirImp::isReadable_34( KJS::ExecState *exec, KJS::Object &obj, const KJS::List &args ) +{ + + bool ret; + ret = instance->isReadable( ); + return KJS::Boolean( ret ); + +} + +KJS::Value QDirImp::exists_35( KJS::ExecState *exec, KJS::Object &obj, const KJS::List &args ) +{ + + bool ret; + ret = instance->exists( ); + return KJS::Boolean( ret ); + +} + +KJS::Value QDirImp::isRoot_36( KJS::ExecState *exec, KJS::Object &obj, const KJS::List &args ) +{ + + bool ret; + ret = instance->isRoot( ); + return KJS::Boolean( ret ); + +} + +KJS::Value QDirImp::isRelative_37( KJS::ExecState *exec, KJS::Object &obj, const KJS::List &args ) +{ + + bool ret; + ret = instance->isRelative( ); + return KJS::Boolean( ret ); + +} + +KJS::Value QDirImp::convertToAbs_38( KJS::ExecState *exec, KJS::Object &obj, const KJS::List &args ) +{ + + instance->convertToAbs( ); + return KJS::Value(); // Returns void + +} + +KJS::Value QDirImp::remove_41( KJS::ExecState *exec, KJS::Object &obj, const KJS::List &args ) +{ + + QString arg0 = (args.size() >= 1) ? args[0].toString(exec).qstring() : QString::null; + + bool arg1 = (args.size() >= 2) ? args[1].toBoolean(exec) : false; + + bool ret; + ret = instance->remove( + arg0, + arg1 ); + return KJS::Boolean( ret ); + +} + +KJS::Value QDirImp::rename_42( KJS::ExecState *exec, KJS::Object &obj, const KJS::List &args ) +{ + + QString arg0 = (args.size() >= 1) ? args[0].toString(exec).qstring() : QString::null; + + QString arg1 = (args.size() >= 2) ? args[1].toString(exec).qstring() : QString::null; + + bool arg2 = (args.size() >= 3) ? args[2].toBoolean(exec) : false; + + bool ret; + ret = instance->rename( + arg0, + arg1, + arg2 ); + return KJS::Boolean( ret ); + +} + +KJS::Value QDirImp::exists_43( KJS::ExecState *exec, KJS::Object &obj, const KJS::List &args ) +{ + + QString arg0 = (args.size() >= 1) ? args[0].toString(exec).qstring() : QString::null; + + bool arg1 = (args.size() >= 2) ? args[1].toBoolean(exec) : false; + + bool ret; + ret = instance->exists( + arg0, + arg1 ); + return KJS::Boolean( ret ); + +} + +KJS::Value QDirImp::refresh_44( KJS::ExecState *exec, KJS::Object &obj, const KJS::List &args ) +{ + + instance->refresh( ); + return KJS::Value(); // Returns void + +} + +KJS::Value QDirImp::convertSeparators_45( KJS::ExecState *exec, KJS::Object &obj, const KJS::List &args ) +{ + + QString arg0 = (args.size() >= 1) ? args[0].toString(exec).qstring() : QString::null; + + QString ret; + ret = instance->convertSeparators( + arg0 ); + return KJS::String( ret ); + +} + +KJS::Value QDirImp::drives_46( KJS::ExecState *exec, KJS::Object &obj, const KJS::List &args ) +{ + + instance->drives( ); + return KJS::Value(); // Returns 'const QFileInfoList *' + +} + +KJS::Value QDirImp::separator_47( KJS::ExecState *exec, KJS::Object &obj, const KJS::List &args ) +{ + + instance->separator( ); + return KJS::Value(); // Returns 'char' + +} + +KJS::Value QDirImp::setCurrent_48( KJS::ExecState *exec, KJS::Object &obj, const KJS::List &args ) +{ + + QString arg0 = (args.size() >= 1) ? args[0].toString(exec).qstring() : QString::null; + + bool ret; + ret = instance->setCurrent( + arg0 ); + return KJS::Boolean( ret ); + +} + +KJS::Value QDirImp::current_49( KJS::ExecState *exec, KJS::Object &obj, const KJS::List &args ) +{ + + instance->current( ); + return KJS::Value(); // Returns 'QDir' + +} + +KJS::Value QDirImp::home_50( KJS::ExecState *exec, KJS::Object &obj, const KJS::List &args ) +{ + + instance->home( ); + return KJS::Value(); // Returns 'QDir' + +} + +KJS::Value QDirImp::root_51( KJS::ExecState *exec, KJS::Object &obj, const KJS::List &args ) +{ + + instance->root( ); + return KJS::Value(); // Returns 'QDir' + +} + +KJS::Value QDirImp::currentDirPath_52( KJS::ExecState *exec, KJS::Object &obj, const KJS::List &args ) +{ + + QString ret; + ret = instance->currentDirPath( ); + return KJS::String( ret ); + +} + +KJS::Value QDirImp::homeDirPath_53( KJS::ExecState *exec, KJS::Object &obj, const KJS::List &args ) +{ + + QString ret; + ret = instance->homeDirPath( ); + return KJS::String( ret ); + +} + +KJS::Value QDirImp::rootDirPath_54( KJS::ExecState *exec, KJS::Object &obj, const KJS::List &args ) +{ + + QString ret; + ret = instance->rootDirPath( ); + return KJS::String( ret ); + +} + +KJS::Value QDirImp::match_55( KJS::ExecState *exec, KJS::Object &obj, const KJS::List &args ) +{ + + QStringList arg0; + if ( args.size() >= 1 ) { + // TODO: populate the list + } + + QString arg1 = (args.size() >= 2) ? args[1].toString(exec).qstring() : QString::null; + + bool ret; + ret = instance->match( + arg0, + arg1 ); + return KJS::Boolean( ret ); + +} + +KJS::Value QDirImp::match_56( KJS::ExecState *exec, KJS::Object &obj, const KJS::List &args ) +{ + + QString arg0 = (args.size() >= 1) ? args[0].toString(exec).qstring() : QString::null; + + QString arg1 = (args.size() >= 2) ? args[1].toString(exec).qstring() : QString::null; + + bool ret; + ret = instance->match( + arg0, + arg1 ); + return KJS::Boolean( ret ); + +} + +KJS::Value QDirImp::cleanDirPath_57( KJS::ExecState *exec, KJS::Object &obj, const KJS::List &args ) +{ + + QString arg0 = (args.size() >= 1) ? args[0].toString(exec).qstring() : QString::null; + + QString ret; + ret = instance->cleanDirPath( + arg0 ); + return KJS::String( ret ); + +} + +KJS::Value QDirImp::isRelativePath_58( KJS::ExecState *exec, KJS::Object &obj, const KJS::List &args ) +{ + + QString arg0 = (args.size() >= 1) ? args[0].toString(exec).qstring() : QString::null; + + bool ret; + ret = instance->isRelativePath( + arg0 ); + return KJS::Boolean( ret ); + +} + + +} // namespace KJSEmbed + +// Local Variables: +// c-basic-offset: 4 +// End: + + diff --git a/kjsembed/builtins/qdir_imp.h b/kjsembed/builtins/qdir_imp.h new file mode 100644 index 00000000..f78850e7 --- /dev/null +++ b/kjsembed/builtins/qdir_imp.h @@ -0,0 +1,172 @@ + + + +#ifndef KJSEMBED_QDir_H +#define KJSEMBED_QDir_H + +#include <kjs/interpreter.h> +#include <kjs/object.h> + +#include <kjsembed/jsobjectproxy_imp.h> +#include <kjsembed/jsbindingbase.h> + +class QDir; + +/** + * Namespace containing the KJSEmbed library. + */ +namespace KJSEmbed { +namespace Bindings { + class QDirLoader : public JSBindingBase + { + public: + KJS::Object createBinding(KJSEmbedPart *jspart, KJS::ExecState *exec, const KJS::List &args) const; + void addBindings( KJSEmbedPart *jspart, KJS::ExecState *exec, KJS::Object &proxy) const; + }; +} +/** + * Wrapper class for QDir methods. + * + * @author Richard Moore, rich@kde.org + */ +class QDirImp : public JSProxyImp +{ +public: + /** Enumerates the methods supported by this class. */ + enum Methods { + + Method_setPath_7, + Method_path_8, + Method_absPath_9, + Method_canonicalPath_10, + Method_dirName_11, + Method_filePath_12, + Method_absFilePath_13, + Method_cd_14, + Method_cdUp_15, + Method_nameFilter_16, + Method_setNameFilter_17, + Method_filter_18, + Method_setFilter_19, + Method_sorting_20, + Method_setSorting_21, + Method_matchAllDirs_22, + Method_setMatchAllDirs_23, + Method_count_24, + Method_encodedEntryList_26, + Method_encodedEntryList_27, + Method_entryList_28, + Method_entryList_29, + Method_entryInfoList_30, + Method_entryInfoList_31, + Method_mkdir_32, + Method_rmdir_33, + Method_isReadable_34, + Method_exists_35, + Method_isRoot_36, + Method_isRelative_37, + Method_convertToAbs_38, + Method_remove_41, + Method_rename_42, + Method_exists_43, + Method_refresh_44, + Method_convertSeparators_45, + Method_drives_46, + Method_separator_47, + Method_setCurrent_48, + Method_current_49, + Method_home_50, + Method_root_51, + Method_currentDirPath_52, + Method_homeDirPath_53, + Method_rootDirPath_54, + Method_match_55, + Method_match_56, + Method_cleanDirPath_57, + Method_isRelativePath_58, + Method_Last = -1 + }; + + QDirImp( KJS::ExecState *exec, int id ); + ~QDirImp(); + + static void addBindings( KJS::ExecState *exec, KJS::Object &object ); + + // + // Methods implemented by this class. + // + + KJS::Value setPath_7( KJS::ExecState *exec, KJS::Object &obj, const KJS::List &args ); + KJS::Value path_8( KJS::ExecState *exec, KJS::Object &obj, const KJS::List &args ); + KJS::Value absPath_9( KJS::ExecState *exec, KJS::Object &obj, const KJS::List &args ); + KJS::Value canonicalPath_10( KJS::ExecState *exec, KJS::Object &obj, const KJS::List &args ); + KJS::Value dirName_11( KJS::ExecState *exec, KJS::Object &obj, const KJS::List &args ); + KJS::Value filePath_12( KJS::ExecState *exec, KJS::Object &obj, const KJS::List &args ); + KJS::Value absFilePath_13( KJS::ExecState *exec, KJS::Object &obj, const KJS::List &args ); + KJS::Value cd_14( KJS::ExecState *exec, KJS::Object &obj, const KJS::List &args ); + KJS::Value cdUp_15( KJS::ExecState *exec, KJS::Object &obj, const KJS::List &args ); + KJS::Value nameFilter_16( KJS::ExecState *exec, KJS::Object &obj, const KJS::List &args ); + KJS::Value setNameFilter_17( KJS::ExecState *exec, KJS::Object &obj, const KJS::List &args ); + KJS::Value filter_18( KJS::ExecState *exec, KJS::Object &obj, const KJS::List &args ); + KJS::Value setFilter_19( KJS::ExecState *exec, KJS::Object &obj, const KJS::List &args ); + KJS::Value sorting_20( KJS::ExecState *exec, KJS::Object &obj, const KJS::List &args ); + KJS::Value setSorting_21( KJS::ExecState *exec, KJS::Object &obj, const KJS::List &args ); + KJS::Value matchAllDirs_22( KJS::ExecState *exec, KJS::Object &obj, const KJS::List &args ); + KJS::Value setMatchAllDirs_23( KJS::ExecState *exec, KJS::Object &obj, const KJS::List &args ); + KJS::Value count_24( KJS::ExecState *exec, KJS::Object &obj, const KJS::List &args ); + KJS::Value encodedEntryList_26( KJS::ExecState *exec, KJS::Object &obj, const KJS::List &args ); + KJS::Value encodedEntryList_27( KJS::ExecState *exec, KJS::Object &obj, const KJS::List &args ); + KJS::Value entryList_28( KJS::ExecState *exec, KJS::Object &obj, const KJS::List &args ); + KJS::Value entryList_29( KJS::ExecState *exec, KJS::Object &obj, const KJS::List &args ); + KJS::Value entryInfoList_30( KJS::ExecState *exec, KJS::Object &obj, const KJS::List &args ); + KJS::Value entryInfoList_31( KJS::ExecState *exec, KJS::Object &obj, const KJS::List &args ); + KJS::Value mkdir_32( KJS::ExecState *exec, KJS::Object &obj, const KJS::List &args ); + KJS::Value rmdir_33( KJS::ExecState *exec, KJS::Object &obj, const KJS::List &args ); + KJS::Value isReadable_34( KJS::ExecState *exec, KJS::Object &obj, const KJS::List &args ); + KJS::Value exists_35( KJS::ExecState *exec, KJS::Object &obj, const KJS::List &args ); + KJS::Value isRoot_36( KJS::ExecState *exec, KJS::Object &obj, const KJS::List &args ); + KJS::Value isRelative_37( KJS::ExecState *exec, KJS::Object &obj, const KJS::List &args ); + KJS::Value convertToAbs_38( KJS::ExecState *exec, KJS::Object &obj, const KJS::List &args ); + KJS::Value remove_41( KJS::ExecState *exec, KJS::Object &obj, const KJS::List &args ); + KJS::Value rename_42( KJS::ExecState *exec, KJS::Object &obj, const KJS::List &args ); + KJS::Value exists_43( KJS::ExecState *exec, KJS::Object &obj, const KJS::List &args ); + KJS::Value refresh_44( KJS::ExecState *exec, KJS::Object &obj, const KJS::List &args ); + KJS::Value convertSeparators_45( KJS::ExecState *exec, KJS::Object &obj, const KJS::List &args ); + KJS::Value drives_46( KJS::ExecState *exec, KJS::Object &obj, const KJS::List &args ); + KJS::Value separator_47( KJS::ExecState *exec, KJS::Object &obj, const KJS::List &args ); + KJS::Value setCurrent_48( KJS::ExecState *exec, KJS::Object &obj, const KJS::List &args ); + KJS::Value current_49( KJS::ExecState *exec, KJS::Object &obj, const KJS::List &args ); + KJS::Value home_50( KJS::ExecState *exec, KJS::Object &obj, const KJS::List &args ); + KJS::Value root_51( KJS::ExecState *exec, KJS::Object &obj, const KJS::List &args ); + KJS::Value currentDirPath_52( KJS::ExecState *exec, KJS::Object &obj, const KJS::List &args ); + KJS::Value homeDirPath_53( KJS::ExecState *exec, KJS::Object &obj, const KJS::List &args ); + KJS::Value rootDirPath_54( KJS::ExecState *exec, KJS::Object &obj, const KJS::List &args ); + KJS::Value match_55( KJS::ExecState *exec, KJS::Object &obj, const KJS::List &args ); + KJS::Value match_56( KJS::ExecState *exec, KJS::Object &obj, const KJS::List &args ); + KJS::Value cleanDirPath_57( KJS::ExecState *exec, KJS::Object &obj, const KJS::List &args ); + KJS::Value isRelativePath_58( KJS::ExecState *exec, KJS::Object &obj, const KJS::List &args ); + + // + // JS binding code. + // + + /** Returns true iff this object implements the call function. */ + virtual bool implementsCall() const { return true; } + + /** Invokes the call function. */ + virtual KJS::Value call( KJS::ExecState *exec, KJS::Object &self, const KJS::List &args ); + +private: + QDir *instance; // Temp + int mid; +}; + +} // namespace KJSEmbed + +#endif // KJSEMBED_QDir_H + +// Local Variables: +// c-basic-offset: 4 +// End: + + diff --git a/kjsembed/builtins/qfile_imp.cpp b/kjsembed/builtins/qfile_imp.cpp new file mode 100644 index 00000000..d404e239 --- /dev/null +++ b/kjsembed/builtins/qfile_imp.cpp @@ -0,0 +1,622 @@ + + +#include <qcstring.h> +#include <qpalette.h> +#include <qpixmap.h> +#include <qfont.h> + +#ifndef QT_ONLY +#include <klocale.h> +#include <kdebug.h> +#endif + +#include <kjs/object.h> + +#include <kjsembed/jsobjectproxy.h> +#include <kjsembed/jsopaqueproxy.h> +#include <kjsembed/jsbinding.h> +#include <kjsembed/global.h> + +#include <qfile.h> +#include "qfile_imp.h" + +/** + * Namespace containing the KJSEmbed library. + */ +namespace KJSEmbed { + +QFileImp::QFileImp( KJS::ExecState *exec, int mid, bool constructor ) + : JSProxyImp(exec), id(mid), cons(constructor) +{ +} + +QFileImp::~QFileImp() +{ +} + +void QFileImp::addBindings( KJS::ExecState *exec, KJS::Object &object ) +{ + JSProxy::MethodTable methods[] = { + + { Method_name_4, "name" }, + { Method_setName_5, "setName" }, + { Method_exists_6, "exists" }, + { Method_remove_7, "remove" }, + { Method_open_8, "open" }, + { Method_open_9, "open" }, + { Method_open_10, "open" }, + { Method_close_11, "close" }, + { Method_flush_12, "flush" }, + { Method_size_13, "size" }, + { Method_at_14, "at" }, + { Method_at_15, "at" }, + { Method_atEnd_16, "atEnd" }, + { Method_readBlock_17, "readBlock" }, + { Method_writeBlock_18, "writeBlock" }, + { Method_writeBlock_19, "writeBlock" }, + { Method_readLine_20, "readLine" }, + { Method_readLine_21, "readLine" }, + { Method_getch_22, "getch" }, + { Method_putch_23, "putch" }, + { Method_ungetch_24, "ungetch" }, + { Method_handle_25, "handle" }, + { Method_errorString_26, "errorString" }, + { Method_encodeName_27, "encodeName" }, + { Method_decodeName_28, "decodeName" }, + { Method_setEncodingFunction_29, "setEncodingFunction" }, + { Method_setDecodingFunction_30, "setDecodingFunction" }, + { Method_exists_31, "exists" }, + { Method_remove_32, "remove" }, + { 0, 0 } + }; + + int idx = 0; + QCString lastName; + + do { + if ( lastName != methods[idx].name ) { + QFileImp *meth = new QFileImp( exec, methods[idx].id ); + object.put( exec , methods[idx].name, KJS::Object(meth) ); + lastName = methods[idx].name; + } + ++idx; + } while( methods[idx].id ); + + +} + +QFile *QFileImp::toQFile( KJS::Object &self ) +{ + JSObjectProxy *ob = JSProxy::toObjectProxy( self.imp() ); + if ( ob ) { + QObject *obj = ob->object(); + if ( obj ) + return dynamic_cast<QFile *>( obj ); + } + + JSOpaqueProxy *op = JSProxy::toOpaqueProxy( self.imp() ); + if ( !op ) + return 0; + + if ( op->typeName() != "QFile" ) + return 0; + + return op->toNative<QFile>(); +} + + +KJS::Object QFileImp::construct( KJS::ExecState *exec, const KJS::List &args ) +{ + switch( id ) { + + case Constructor_QFile_1: + return QFile_1( exec, args ); + break; + + case Constructor_QFile_2: + return QFile_2( exec, args ); + break; + + default: + break; + } + + QString msg = i18n("QFileCons has no constructor with id '%1'.").arg(id); + return throwError(exec, msg,KJS::ReferenceError); +} + + +KJS::Object QFileImp::QFile_1( KJS::ExecState *exec, const KJS::List &args ) +{ + return KJS::Object(); +} + +KJS::Object QFileImp::QFile_2( KJS::ExecState *exec, const KJS::List &args ) +{ + + // TODO + QWidget *arg0 = 0L; + return KJS::Object(); + +} + +KJS::Value QFileImp::call( KJS::ExecState *exec, KJS::Object &self, const KJS::List &args ) +{ + instance = QFileImp::toQFile( self ); + + switch( id ) { + + case Method_name_4: + return name_4( exec, self, args ); + break; + + case Method_setName_5: + return setName_5( exec, self, args ); + break; + + case Method_exists_6: + return exists_6( exec, self, args ); + break; + + case Method_remove_7: + return remove_7( exec, self, args ); + break; + + case Method_open_8: + return open_8( exec, self, args ); + break; + + case Method_open_9: + return open_9( exec, self, args ); + break; + + case Method_open_10: + return open_10( exec, self, args ); + break; + + case Method_close_11: + return close_11( exec, self, args ); + break; + + case Method_flush_12: + return flush_12( exec, self, args ); + break; + + case Method_size_13: + return size_13( exec, self, args ); + break; + + case Method_at_14: + return at_14( exec, self, args ); + break; + + case Method_at_15: + return at_15( exec, self, args ); + break; + + case Method_atEnd_16: + return atEnd_16( exec, self, args ); + break; + + case Method_readBlock_17: + return readBlock_17( exec, self, args ); + break; + + case Method_writeBlock_18: + return writeBlock_18( exec, self, args ); + break; + + case Method_writeBlock_19: + return writeBlock_19( exec, self, args ); + break; + + case Method_readLine_20: + return readLine_20( exec, self, args ); + break; + + case Method_readLine_21: + return readLine_21( exec, self, args ); + break; + + case Method_getch_22: + return getch_22( exec, self, args ); + break; + + case Method_putch_23: + return putch_23( exec, self, args ); + break; + + case Method_ungetch_24: + return ungetch_24( exec, self, args ); + break; + + case Method_handle_25: + return handle_25( exec, self, args ); + break; + + case Method_errorString_26: + return errorString_26( exec, self, args ); + break; + + case Method_encodeName_27: + return encodeName_27( exec, self, args ); + break; + + case Method_decodeName_28: + return decodeName_28( exec, self, args ); + break; + + case Method_setEncodingFunction_29: + return setEncodingFunction_29( exec, self, args ); + break; + + case Method_setDecodingFunction_30: + return setDecodingFunction_30( exec, self, args ); + break; + + case Method_exists_31: + return exists_31( exec, self, args ); + break; + + case Method_remove_32: + return remove_32( exec, self, args ); + break; + + default: + break; + } + + QString msg = i18n( "QFileImp has no method with id '%1'." ).arg( id ); + return throwError(exec, msg, KJS::ReferenceError ); +} + + +KJS::Value QFileImp::name_4( KJS::ExecState *exec, KJS::Object &obj, const KJS::List &args ) +{ + + QString ret; + ret = instance->name( ); + return KJS::String( ret ); + +} + +KJS::Value QFileImp::setName_5( KJS::ExecState *exec, KJS::Object &obj, const KJS::List &args ) +{ + + QString arg0 = (args.size() >= 1) ? args[0].toString(exec).qstring() : QString::null; + + instance->setName( + arg0 ); + return KJS::Value(); // Returns void + +} + +KJS::Value QFileImp::exists_6( KJS::ExecState *exec, KJS::Object &obj, const KJS::List &args ) +{ + + bool ret; + ret = instance->exists( ); + return KJS::Boolean( ret ); + +} + +KJS::Value QFileImp::remove_7( KJS::ExecState *exec, KJS::Object &obj, const KJS::List &args ) +{ + + bool ret; + ret = instance->remove( ); + return KJS::Boolean( ret ); + +} + +KJS::Value QFileImp::open_8( KJS::ExecState *exec, KJS::Object &obj, const KJS::List &args ) +{ + + int arg0 = (args.size() >= 1) ? args[0].toInteger(exec) : -1; + + bool ret; + ret = instance->open( + arg0 ); + return KJS::Boolean( ret ); + +} + +KJS::Value QFileImp::open_9( KJS::ExecState *exec, KJS::Object &obj, const KJS::List &args ) +{ + + int arg0 = (args.size() >= 1) ? args[0].toInteger(exec) : -1; + + // Unsupported parameter FILE * + return KJS::Value(); + + FILE * arg1; // Dummy + + bool ret; + ret = instance->open( + arg0, + arg1 ); + return KJS::Boolean( ret ); + +} + +KJS::Value QFileImp::open_10( KJS::ExecState *exec, KJS::Object &obj, const KJS::List &args ) +{ + + int arg0 = (args.size() >= 1) ? args[0].toInteger(exec) : -1; + + int arg1 = (args.size() >= 2) ? args[1].toInteger(exec) : -1; + + bool ret; + ret = instance->open( + arg0, + arg1 ); + return KJS::Boolean( ret ); + +} + +KJS::Value QFileImp::close_11( KJS::ExecState *exec, KJS::Object &obj, const KJS::List &args ) +{ + + instance->close( ); + return KJS::Value(); // Returns void + +} + +KJS::Value QFileImp::flush_12( KJS::ExecState *exec, KJS::Object &obj, const KJS::List &args ) +{ + + instance->flush( ); + return KJS::Value(); // Returns void + +} + +KJS::Value QFileImp::size_13( KJS::ExecState *exec, KJS::Object &obj, const KJS::List &args ) +{ + + instance->size( ); + return KJS::Value(); // Returns 'Offset' + +} + +KJS::Value QFileImp::at_14( KJS::ExecState *exec, KJS::Object &obj, const KJS::List &args ) +{ + + instance->at( ); + return KJS::Value(); // Returns 'Offset' + +} + +KJS::Value QFileImp::at_15( KJS::ExecState *exec, KJS::Object &obj, const KJS::List &args ) +{ + + QFile::Offset arg0 = 0; // TODO (hack for qfile) + + bool ret; + ret = instance->at( + arg0 ); + return KJS::Boolean( ret ); + +} + +KJS::Value QFileImp::atEnd_16( KJS::ExecState *exec, KJS::Object &obj, const KJS::List &args ) +{ + + bool ret; + ret = instance->atEnd( ); + return KJS::Boolean( ret ); + +} + +KJS::Value QFileImp::readBlock_17( KJS::ExecState *exec, KJS::Object &obj, const KJS::List &args ) +{ + + // Unsupported parameter char * + return KJS::Value(); + + char * arg0; // Dummy + + // Unsupported parameter Q_ULONG + return KJS::Value(); + + Q_ULONG arg1; // Dummy + + instance->readBlock( + arg0, + arg1 ); + return KJS::Value(); // Returns 'Q_LONG' + +} + +KJS::Value QFileImp::writeBlock_18( KJS::ExecState *exec, KJS::Object &obj, const KJS::List &args ) +{ + + const char *arg0 = (args.size() >= 1) ? args[0].toString(exec).ascii() : 0; + + // Unsupported parameter Q_ULONG + return KJS::Value(); + + Q_ULONG arg1; // Dummy + + instance->writeBlock( + arg0, + arg1 ); + return KJS::Value(); // Returns 'Q_LONG' + +} + +KJS::Value QFileImp::writeBlock_19( KJS::ExecState *exec, KJS::Object &obj, const KJS::List &args ) +{ + + QByteArray arg0; // TODO (hack for qfile) + + instance->writeBlock( + arg0 ); + return KJS::Value(); // Returns 'Q_LONG' + +} + +KJS::Value QFileImp::readLine_20( KJS::ExecState *exec, KJS::Object &obj, const KJS::List &args ) +{ + + // Unsupported parameter char * + return KJS::Value(); + + char * arg0; // Dummy + + // Unsupported parameter Q_ULONG + return KJS::Value(); + + Q_ULONG arg1; // Dummy + + instance->readLine( + arg0, + arg1 ); + return KJS::Value(); // Returns 'Q_LONG' + +} + +KJS::Value QFileImp::readLine_21( KJS::ExecState *exec, KJS::Object &obj, const KJS::List &args ) +{ + + QString arg0 = (args.size() >= 1) ? args[0].toString(exec).qstring() : QString::null; + + // Unsupported parameter Q_ULONG + return KJS::Value(); + + Q_ULONG arg1; // Dummy + + instance->readLine( + arg0, + arg1 ); + return KJS::Value(); // Returns 'Q_LONG' + +} + +KJS::Value QFileImp::getch_22( KJS::ExecState *exec, KJS::Object &obj, const KJS::List &args ) +{ + + int ret; + ret = instance->getch( ); + return KJS::Number( ret ); + +} + +KJS::Value QFileImp::putch_23( KJS::ExecState *exec, KJS::Object &obj, const KJS::List &args ) +{ + + int arg0 = (args.size() >= 1) ? args[0].toInteger(exec) : -1; + + int ret; + ret = instance->putch( + arg0 ); + return KJS::Number( ret ); + +} + +KJS::Value QFileImp::ungetch_24( KJS::ExecState *exec, KJS::Object &obj, const KJS::List &args ) +{ + + int arg0 = (args.size() >= 1) ? args[0].toInteger(exec) : -1; + + int ret; + ret = instance->ungetch( + arg0 ); + return KJS::Number( ret ); + +} + +KJS::Value QFileImp::handle_25( KJS::ExecState *exec, KJS::Object &obj, const KJS::List &args ) +{ + + int ret; + ret = instance->handle( ); + return KJS::Number( ret ); + +} + +KJS::Value QFileImp::errorString_26( KJS::ExecState *exec, KJS::Object &obj, const KJS::List &args ) +{ + + QString ret; + ret = instance->errorString( ); + return KJS::String( ret ); + +} + +KJS::Value QFileImp::encodeName_27( KJS::ExecState *exec, KJS::Object &obj, const KJS::List &args ) +{ + + QString arg0 = (args.size() >= 1) ? args[0].toString(exec).qstring() : QString::null; + + instance->encodeName( + arg0 ); + return KJS::Value(); // Returns 'QCString' + +} + +KJS::Value QFileImp::decodeName_28( KJS::ExecState *exec, KJS::Object &obj, const KJS::List &args ) +{ + + const QCString arg0 = (args.size() >= 1) ? args[0].toString(exec).ascii() : 0; + + QString ret; + ret = instance->decodeName( + arg0 ); + return KJS::String( ret ); + +} + +KJS::Value QFileImp::setEncodingFunction_29( KJS::ExecState *exec, KJS::Object &obj, const KJS::List &args ) +{ + + QFile::EncoderFn arg0 = 0; // TODO (hack for qfile) + + instance->setEncodingFunction( + arg0 ); + return KJS::Value(); // Returns void + +} + +KJS::Value QFileImp::setDecodingFunction_30( KJS::ExecState *exec, KJS::Object &obj, const KJS::List &args ) +{ + + QFile::DecoderFn arg0 = 0; // TODO (hack for qfile) + + instance->setDecodingFunction( + arg0 ); + return KJS::Value(); // Returns void + +} + +KJS::Value QFileImp::exists_31( KJS::ExecState *exec, KJS::Object &obj, const KJS::List &args ) +{ + + QString arg0 = (args.size() >= 1) ? args[0].toString(exec).qstring() : QString::null; + + bool ret; + ret = instance->exists( + arg0 ); + return KJS::Boolean( ret ); + +} + +KJS::Value QFileImp::remove_32( KJS::ExecState *exec, KJS::Object &obj, const KJS::List &args ) +{ + + QString arg0 = (args.size() >= 1) ? args[0].toString(exec).qstring() : QString::null; + + bool ret; + ret = instance->remove( + arg0 ); + return KJS::Boolean( ret ); + +} + + +} // namespace KJSEmbed + +// Local Variables: +// c-basic-offset: 4 +// End: + + diff --git a/kjsembed/builtins/qfile_imp.h b/kjsembed/builtins/qfile_imp.h new file mode 100644 index 00000000..ae88dd52 --- /dev/null +++ b/kjsembed/builtins/qfile_imp.h @@ -0,0 +1,148 @@ + + + +#ifndef KJSEMBED_QFile_H +#define KJSEMBED_QFile_H + +#include <kjs/interpreter.h> +#include <kjs/object.h> + +#include <kjsembed/jsobjectproxy_imp.h> + +class QFile; + +/** + * Namespace containing the KJSEmbed library. + */ +namespace KJSEmbed { + +/** + * Wrapper class for QFile methods. + * + * @author Richard Moore, rich@kde.org + */ +class QFileImp : public JSProxyImp +{ +public: + /** Enumerates the constructors supported by this class. */ + enum Constructors { + Constructor_QFile_1, + Constructor_QFile_2, + + LastConstuctor = -1 + }; + + /** Enumerates the methods supported by this class. */ + enum Methods { + + Method_name_4, + Method_setName_5, + Method_exists_6, + Method_remove_7, + Method_open_8, + Method_open_9, + Method_open_10, + Method_close_11, + Method_flush_12, + Method_size_13, + Method_at_14, + Method_at_15, + Method_atEnd_16, + Method_readBlock_17, + Method_writeBlock_18, + Method_writeBlock_19, + Method_readLine_20, + Method_readLine_21, + Method_getch_22, + Method_putch_23, + Method_ungetch_24, + Method_handle_25, + Method_errorString_26, + Method_encodeName_27, + Method_decodeName_28, + Method_setEncodingFunction_29, + Method_setDecodingFunction_30, + Method_exists_31, + Method_remove_32, + Method_Last = -1 + }; + + QFileImp( KJS::ExecState *exec, int id, bool constructor=false ); + ~QFileImp(); + + static void addBindings( KJS::ExecState *exec, KJS::Object &object ); + + static QFile *toQFile( KJS::Object &object ); + + // + // Constructors implemented by this class. + // + + KJS::Object QFile_1( KJS::ExecState *exec, const KJS::List &args ); + KJS::Object QFile_2( KJS::ExecState *exec, const KJS::List &args ); + + // + // Methods implemented by this class. + // + + KJS::Value name_4( KJS::ExecState *exec, KJS::Object &obj, const KJS::List &args ); + KJS::Value setName_5( KJS::ExecState *exec, KJS::Object &obj, const KJS::List &args ); + KJS::Value exists_6( KJS::ExecState *exec, KJS::Object &obj, const KJS::List &args ); + KJS::Value remove_7( KJS::ExecState *exec, KJS::Object &obj, const KJS::List &args ); + KJS::Value open_8( KJS::ExecState *exec, KJS::Object &obj, const KJS::List &args ); + KJS::Value open_9( KJS::ExecState *exec, KJS::Object &obj, const KJS::List &args ); + KJS::Value open_10( KJS::ExecState *exec, KJS::Object &obj, const KJS::List &args ); + KJS::Value close_11( KJS::ExecState *exec, KJS::Object &obj, const KJS::List &args ); + KJS::Value flush_12( KJS::ExecState *exec, KJS::Object &obj, const KJS::List &args ); + KJS::Value size_13( KJS::ExecState *exec, KJS::Object &obj, const KJS::List &args ); + KJS::Value at_14( KJS::ExecState *exec, KJS::Object &obj, const KJS::List &args ); + KJS::Value at_15( KJS::ExecState *exec, KJS::Object &obj, const KJS::List &args ); + KJS::Value atEnd_16( KJS::ExecState *exec, KJS::Object &obj, const KJS::List &args ); + KJS::Value readBlock_17( KJS::ExecState *exec, KJS::Object &obj, const KJS::List &args ); + KJS::Value writeBlock_18( KJS::ExecState *exec, KJS::Object &obj, const KJS::List &args ); + KJS::Value writeBlock_19( KJS::ExecState *exec, KJS::Object &obj, const KJS::List &args ); + KJS::Value readLine_20( KJS::ExecState *exec, KJS::Object &obj, const KJS::List &args ); + KJS::Value readLine_21( KJS::ExecState *exec, KJS::Object &obj, const KJS::List &args ); + KJS::Value getch_22( KJS::ExecState *exec, KJS::Object &obj, const KJS::List &args ); + KJS::Value putch_23( KJS::ExecState *exec, KJS::Object &obj, const KJS::List &args ); + KJS::Value ungetch_24( KJS::ExecState *exec, KJS::Object &obj, const KJS::List &args ); + KJS::Value handle_25( KJS::ExecState *exec, KJS::Object &obj, const KJS::List &args ); + KJS::Value errorString_26( KJS::ExecState *exec, KJS::Object &obj, const KJS::List &args ); + KJS::Value encodeName_27( KJS::ExecState *exec, KJS::Object &obj, const KJS::List &args ); + KJS::Value decodeName_28( KJS::ExecState *exec, KJS::Object &obj, const KJS::List &args ); + KJS::Value setEncodingFunction_29( KJS::ExecState *exec, KJS::Object &obj, const KJS::List &args ); + KJS::Value setDecodingFunction_30( KJS::ExecState *exec, KJS::Object &obj, const KJS::List &args ); + KJS::Value exists_31( KJS::ExecState *exec, KJS::Object &obj, const KJS::List &args ); + KJS::Value remove_32( KJS::ExecState *exec, KJS::Object &obj, const KJS::List &args ); + + // + // JS binding code. + // + + /** Returns true iff this object implements the construct function. */ + virtual bool implementsConstruct() const { return cons; } + + /** Invokes the construct function. */ + virtual KJS::Object construct( KJS::ExecState *exec, const KJS::List &args ); + + /** Returns true iff this object implements the call function. */ + virtual bool implementsCall() const { return !cons; } + + /** Invokes the call function. */ + virtual KJS::Value call( KJS::ExecState *exec, KJS::Object &self, const KJS::List &args ); + +private: + QFile *instance; // Temp + int id; + bool cons; +}; + +} // namespace KJSEmbed + +#endif // KJSEMBED_QFile_H + +// Local Variables: +// c-basic-offset: 4 +// End: + + diff --git a/kjsembed/builtins/resources.cpp b/kjsembed/builtins/resources.cpp new file mode 100644 index 00000000..14912303 --- /dev/null +++ b/kjsembed/builtins/resources.cpp @@ -0,0 +1,231 @@ +/* + * Copyright (C) 2003, Richard J. Moore <rich@kde.org> + * + * This 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. + * + * This 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 this library; see the file COPYING.LIB. If not, write to + * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, + * Boston, MA 02110-1301, USA. + */ + +#include <kstandarddirs.h> +#include <kiconloader.h> +#include <kglobal.h> +#include <kdebug.h> +#include <jsproxy.h> +#include <jsbinding.h> +#include <jsfactory.h> +#include <qdir.h> +#include <qapplication.h> +#include "resources.h" + +namespace KJSEmbed { +namespace BuiltIns { + + +StdDirsImp::StdDirsImp( KJS::ExecState *exec, uint mid ) + : JSProxyImp(exec), id(mid) +{ + +} + +StdDirsImp::~StdDirsImp() {} + +void StdDirsImp::addBindings( KJS::ExecState *exec, KJS::Object &parent ) +{ + + JSProxy::MethodTable methods[] = { + { StdDirsImp::findResource, "findResource" }, + { StdDirsImp::addResourceType, "addResourceType" }, + { StdDirsImp::kde_default, "kde_default" }, + { StdDirsImp::addResourceDir, "addResourceDir" }, + { StdDirsImp::findResourceDir, "findResourceDir" }, + { StdDirsImp::saveLocation, "saveLocation" }, + { StdDirsImp::makeDir, "makeDir" }, + { StdDirsImp::exists, "exists" }, + { StdDirsImp::realPath, "realPath" }, + { StdDirsImp::currentDirPath, "currentDirPath" }, + { StdDirsImp::homeDirPath, "homeDirPath" }, + { StdDirsImp::applicationDirPath, "applicationDirPath" }, + { 0, 0 } + }; + + int idx = 0; + do { + StdDirsImp *sdi = new StdDirsImp( exec, idx ); + parent.put( exec , methods[idx].name, KJS::Object(sdi) ); + ++idx; + } while( methods[idx].id ); + +} + +KJS::Value StdDirsImp::call( KJS::ExecState *exec, KJS::Object &/*self*/, const KJS::List &args ) +{ +// QString arg0 = extractQString(exec, args, 0); +// QString arg1 = extractQString(exec, args, 1); + + switch( id ) { + case StdDirsImp::findResource: + { + QString arg0 = extractQString(exec, args, 0); + QString arg1 = extractQString(exec, args, 1); + QString path = KGlobal::dirs ()->findResource(arg0.latin1(), arg1); + return KJS::String( path ); + } + case StdDirsImp::addResourceType: + { + QString arg0 = extractQString(exec, args, 0); + QString arg1 = extractQString(exec, args, 1); + bool isOk = KGlobal::dirs ()->addResourceType(arg0.latin1(), arg1); + return KJS::Boolean( isOk ); + } + case StdDirsImp::kde_default: + { + QString arg0 = extractQString(exec, args, 0); + QString path = KGlobal::dirs ()->kde_default(arg0.latin1()); + return KJS::String( path ); + } + case StdDirsImp::addResourceDir: + { + QString arg0 = extractQString(exec, args, 0); + QString arg1 = extractQString(exec, args, 1); + bool isOk = KGlobal::dirs ()->addResourceDir(arg0.latin1(), arg1); + return KJS::Boolean( isOk ); + } + case StdDirsImp::findResourceDir: + { + QString arg0 = extractQString(exec, args, 0); + QString arg1 = extractQString(exec, args, 1); + QString path = KGlobal::dirs ()->findResourceDir(arg0.latin1(), arg1); + return KJS::String( path ); + } + case StdDirsImp::saveLocation: + { + QString arg0 = extractQString(exec, args, 0); + QString arg1 = extractQString(exec, args, 1); + bool arg2 = (args.size() > 2) ? args[2].toBoolean(exec) : true; + QString path = KGlobal::dirs ()->saveLocation(arg0.latin1(), arg1, arg2); + return KJS::String( path ); + } + case StdDirsImp::makeDir: + { + QString arg0 = extractQString(exec, args, 0); + int arg1 = (args.size() > 1) ? args[1].toInteger(exec) : 0755; + bool isOk = KStandardDirs::makeDir(arg0, arg1); + return KJS::Boolean( isOk ); + } + case StdDirsImp::exists: + { + QString arg0 = extractQString(exec, args, 0); + bool isOk = KStandardDirs::exists(arg0); + return KJS::Boolean( isOk ); + } + case StdDirsImp::realPath: + { + QString arg0 = extractQString(exec, args, 0); + QString path = KStandardDirs::realPath(arg0); + return KJS::String( path ); + } + case StdDirsImp::currentDirPath: + return KJS::String(QDir::currentDirPath()); + case StdDirsImp::homeDirPath: + return KJS::String(QDir::homeDirPath()); + case StdDirsImp::applicationDirPath: + return KJS::String(qApp->applicationDirPath()); + default: + kdWarning() << "StdDirsImp has no method " << id << endl; + } + + kdWarning() << "StdDirsImp returning null" << endl; + + return KJS::Null(); +} + +StdIconsImp::StdIconsImp( JSFactory *fact, KJS::ExecState *exec, uint mid ) + : JSProxyImp(exec), id(mid), jsfact(fact) +{ +} + +StdIconsImp::~StdIconsImp() {} + +void StdIconsImp::addBindings( JSFactory *fact, KJS::ExecState *exec, KJS::Object &parent ) +{ + JSProxy::MethodTable methods[] = { + { StdIconsImp::BarIcon, "BarIcon" }, + { StdIconsImp::DesktopIcon, "DesktopIcon" }, + { StdIconsImp::SmallIcon, "SmallIcon" }, + { StdIconsImp::MainBarIcon, "MainBarIcon" }, + { StdIconsImp::UserIcon, "UserIcon" }, + { StdIconsImp::MimeSourceIcon, "MimeSourceIcon" }, + { 0, 0 } + }; + + int idx = 0; + do { + StdIconsImp *sdi = new StdIconsImp( fact, exec, idx ); + parent.put( exec , methods[idx].name, KJS::Object(sdi) ); + ++idx; + } while( methods[idx].id ); + +} + +KJS::Value StdIconsImp::wrapPixmap(KJS::ExecState *exec, const QPixmap &icon) +{ + return convertToValue(exec, icon); +} + +KJS::Value StdIconsImp::call( KJS::ExecState *exec, KJS::Object &/*obj*/, const KJS::List &args ) +{ + QString arg0 = extractQString(exec, args, 0); // Name + int arg1 = extractInt(exec, args, 1); // Size 0, 16, 24, 32, 48, 64, 128 + int arg2 = extractInt(exec, args, 2); + // State 0 DefaultState, 1 ActiveState, 2 DisabledState, 3 LastState + switch( id ) { + case StdIconsImp::BarIcon: + { + return wrapPixmap(exec, ::BarIcon(arg0, arg1, arg2)); + } + case StdIconsImp::DesktopIcon: + { + return wrapPixmap(exec, ::DesktopIcon(arg0, arg1, arg2)); + } + case StdIconsImp::SmallIcon: + { + return wrapPixmap(exec, ::SmallIcon(arg0, arg1, arg2)); + } + case StdIconsImp::MainBarIcon: + { + return wrapPixmap(exec, ::MainBarIcon(arg0, arg1, arg2)); + } + case StdIconsImp::UserIcon: + { + return wrapPixmap(exec, ::UserIcon(arg0, arg2)); + } + case StdIconsImp::MimeSourceIcon: + { + return wrapPixmap( exec, QPixmap::fromMimeSource(arg0)); + } + default: + kdWarning() << "StdDirsImp has no method " << id << endl; + } + + kdWarning() << "StdDirsImp returning null" << endl; + + return KJS::Null(); +} + +} // namespace KJSEmbed::BuiltIns +} // namespace KJSEmbed + +// Local Variables: +// c-basic-offset: 4 +// End: diff --git a/kjsembed/builtins/resources.h b/kjsembed/builtins/resources.h new file mode 100644 index 00000000..d83cd0b3 --- /dev/null +++ b/kjsembed/builtins/resources.h @@ -0,0 +1,99 @@ +// -*- c++ -*- + +/* + * Copyright (C) 2003, Ian Reinhart Geiser <geiseri@kde.org> + * + * This 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. + * + * This 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 this library; see the file COPYING.LIB. If not, write to + * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, + * Boston, MA 02110-1301, USA. + */ + +#ifndef KJSEMBED_RESOURCES_H +#define KJSEMBED_RESOURCES_H + +#include <qpixmap.h> + +#include <kjs/interpreter.h> +#include <kjs/object.h> + +#include <kjsembed/jsobjectproxy_imp.h> + +namespace KJSEmbed { +namespace BuiltIns { + +/** + * KJS binding for KStandardDirs. + * + * @author Ian Reinhart Geiser geiseri@kde.org + */ +class StdDirsImp : public JSProxyImp +{ + +public: + /** Identifiers for the various methods. */ + enum DirMethods { + findResource, addResourceType, kde_default, + addResourceDir, findResourceDir, saveLocation, + makeDir, exists, realPath, currentDirPath, + homeDirPath, applicationDirPath }; + StdDirsImp( KJS::ExecState *exec, uint id ); + virtual ~StdDirsImp(); + + /** Adds the StdActions object to the specified parent. */ + static void addBindings( KJS::ExecState *exec, KJS::Object &parent ); + + /** Returns true iff this object implements the call function. */ + virtual bool implementsCall() const { return true; } + + /** Invokes the call function. */ + virtual KJS::Value call( KJS::ExecState *exec, KJS::Object &self, const KJS::List &args ); + +private: + uint id; + JSFactory *jsfact; +}; + + +/** + * KJS binding for KIconLoader. + * + * @author Ian Reinhart Geiser geiseri@kde.org + */ +class StdIconsImp : public JSProxyImp +{ +public: + enum IconMethods { BarIcon, DesktopIcon, SmallIcon, MainBarIcon, UserIcon, MimeSourceIcon }; + StdIconsImp(JSFactory *fac, KJS::ExecState *exec, uint id ); + virtual ~StdIconsImp(); + + /** Adds the StdActions object to the specified parent. */ + static void addBindings( JSFactory *fac, KJS::ExecState *exec, KJS::Object &parent ); + + /** Returns true iff this object implements the call function. */ + virtual bool implementsCall() const { return true; } + + /** Invokes the call function. */ + virtual KJS::Value call( KJS::ExecState *exec, KJS::Object &self, const KJS::List &args ); + +private: + /** wrap a QPixmap **/ + KJS::Value wrapPixmap(KJS::ExecState *exec,const QPixmap &icon); + uint id; + JSFactory *jsfact; +}; + +} // namespace BuiltIns +} // namespace KJSEmbed + +#endif // KJSEMBED_RESOURCES_H diff --git a/kjsembed/builtins/saxhandler.cpp b/kjsembed/builtins/saxhandler.cpp new file mode 100644 index 00000000..d4a6f5f3 --- /dev/null +++ b/kjsembed/builtins/saxhandler.cpp @@ -0,0 +1,186 @@ +/* + * Copyright (C) 2003, Richard J. Moore <rich@kde.org> + * + * This 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. + * + * This 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 this library; see the file COPYING.LIB. If not, write to + * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, + * Boston, MA 02110-1301, USA. + */ +#include "kjsembed/jsbinding.h" +#include "saxhandler.h" + +namespace KJSEmbed { +namespace BuiltIns { + +SaxHandler::SaxHandler( KJS::ExecState *execstate ) + : QXmlDefaultHandler(), exec(execstate), error( ErrorNone ) +{ +} + +SaxHandler::~SaxHandler() +{ +} + +void SaxHandler::setHandler( const KJS::Object &handler ) +{ + jshandler = handler; +} + +bool SaxHandler::startDocument() +{ + if ( !jshandler.isValid() ) { + error = ErrorNoHandler; + return false; + } + + KJS::Identifier funName("startDocument"); + if ( !jshandler.hasProperty(exec, funName) ) + return QXmlDefaultHandler::startDocument(); + + KJS::Object fun = jshandler.get(exec, funName).toObject( exec ); + if ( !fun.implementsCall() ) { + error = ErrorNotCallable; + return false; + } + + KJS::Value ret = fun.call( exec, jshandler, KJS::List() ); + return ret.toBoolean( exec ); +} + +bool SaxHandler::endDocument() +{ + if ( !jshandler.isValid() ) { + error = ErrorNoHandler; + return false; + } + + KJS::Identifier funName("endDocument"); + if ( !jshandler.hasProperty(exec, funName) ) + return QXmlDefaultHandler::endDocument(); + + KJS::Object fun = jshandler.get(exec, funName).toObject( exec ); + if ( !fun.implementsCall() ) { + error = ErrorNotCallable; + return false; + } + + KJS::Value ret = fun.call( exec, jshandler, KJS::List() ); + return ret.toBoolean( exec ); +} + +bool SaxHandler::startElement( const QString &ns, const QString &ln, const QString &qn, + const QXmlAttributes &attrs ) +{ + if ( !jshandler.isValid() ) { + error = ErrorNoHandler; + return false; + } + + KJS::Identifier funName("startElement"); + if ( !jshandler.hasProperty(exec, funName) ) + return QXmlDefaultHandler::startElement( ns, ln, qn, attrs ); + + KJS::Object fun = jshandler.get(exec, funName).toObject( exec ); + if ( !fun.implementsCall() ) { + error = ErrorNotCallable; + return false; + } + + KJS::List args; + args.append( KJS::String(ns) ); + args.append( KJS::String(ln) ); + args.append( KJS::String(qn) ); + // TODO: XmlAttributes not yet supported + + KJS::Value ret = fun.call( exec, jshandler, args ); + return ret.toBoolean( exec ); +} + +bool SaxHandler::endElement( const QString &ns, const QString &ln, const QString &qn ) +{ + if ( !jshandler.isValid() ) { + error = ErrorNoHandler; + return false; + } + + KJS::Identifier funName("endElement"); + if ( !jshandler.hasProperty(exec, funName) ) + return QXmlDefaultHandler::endElement( ns, ln, qn ); + + KJS::Object fun = jshandler.get(exec, funName).toObject( exec ); + if ( !fun.implementsCall() ) { + error = ErrorNotCallable; + return false; + } + + KJS::List args; + args.append( KJS::String(ns) ); + args.append( KJS::String(ln) ); + args.append( KJS::String(qn) ); + + KJS::Value ret = fun.call( exec, jshandler, args ); + return ret.toBoolean( exec ); +} + +bool SaxHandler::characters( const QString &chars ) +{ + if ( !jshandler.isValid() ) { + error = ErrorNoHandler; + return false; + } + + KJS::Identifier funName("characters"); + if ( !jshandler.hasProperty(exec, funName) ) + return QXmlDefaultHandler::characters( chars ); + + KJS::Object fun = jshandler.get(exec, funName).toObject( exec ); + if ( !fun.implementsCall() ) { + error = ErrorNotCallable; + return false; + } + + KJS::List args; + args.append( KJS::String(chars) ); + + KJS::Value ret = fun.call( exec, jshandler, args ); + return ret.toBoolean( exec ); +} + +QString SaxHandler::errorString() +{ + switch( error ) { + + case ErrorNoHandler: + return QString("No handler specified"); + break; + case ErrorNotCallable: + return QString("One of the callbacks of the handler is not callable"); + break; + case ErrorNone: + // This only means that no error occured in the JS dispatch, there + // could still have been an error from the parser so we fall + // though to call the baseclass. + break; + default: + break; + } + + return QXmlDefaultHandler::errorString(); +} + +} // namespace KJSEmbed::BuiltIns +} // namespace KJSEmbed + +// Local Variables: +// c-basic-offset: 4 +// End: diff --git a/kjsembed/builtins/saxhandler.h b/kjsembed/builtins/saxhandler.h new file mode 100644 index 00000000..f396dbfe --- /dev/null +++ b/kjsembed/builtins/saxhandler.h @@ -0,0 +1,80 @@ +// -*- c++ -*- + +/* + * Copyright (C) 2003, Richard J. Moore <rich@kde.org> + * + * This 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. + * + * This 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 this library; see the file COPYING.LIB. If not, write to + * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, + * Boston, MA 02110-1301, USA. + */ + +#ifndef KJSEMBED_SAXHANDLER_H +#define KJSEMBED_SAXHANDLER_H + +#include <qxml.h> +#include <kjs/object.h> + +namespace KJSEmbed { +namespace BuiltIns { + +/** + * SAX handler that calls JS methods according to the SAX API. + * + * @author Richard Moore, rich@kde.org + */ +class SaxHandler : public QXmlDefaultHandler +{ +public: + /** Defines the errors that are specific to the KJS SAX support. */ + enum SaxHandlerError { + ErrorNone, + ErrorNoHandler, + ErrorNotCallable + }; + + /** Creates a SaxHandler. */ + SaxHandler( KJS::ExecState *exec ); + /** Cleans up. */ + virtual ~SaxHandler(); + + /** + * Sets the handler object that defines the callbacks to be invoked + * according to the SAX api. + */ + void setHandler( const KJS::Object &handler ); + + virtual bool startDocument(); + virtual bool endDocument(); + + virtual bool startElement( const QString &ns, const QString &ln, const QString &qn, + const QXmlAttributes &attrs ); + virtual bool endElement( const QString &ns, const QString &ln, const QString &qn ); + virtual bool characters( const QString &chars ); + + virtual QString errorString(); + +private: + KJS::ExecState *exec; + KJS::Object jshandler; + int error; + + class SaxHandlerPrivate *d; +}; + +} // namespace KJSEmbed::BuiltIns +} // namespace KJSEmbed + +#endif // KJSEMBED_SAXHANDLER_H + + diff --git a/kjsembed/builtins/stdaction_imp.cpp b/kjsembed/builtins/stdaction_imp.cpp new file mode 100644 index 00000000..1361acf8 --- /dev/null +++ b/kjsembed/builtins/stdaction_imp.cpp @@ -0,0 +1,99 @@ +/* + * Copyright (C) 2003, Richard J. Moore <rich@kde.org> + * + * This 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. + * + * This 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 this library; see the file COPYING.LIB. If not, write to + * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, + * Boston, MA 02110-1301, USA. + */ + +#include <kaction.h> +#include <kdebug.h> +#include <kstdaction.h> + +#include <jsfactory.h> +#include <jsobjectproxy.h> + +#include "stdaction_imp.h" + +namespace KJSEmbed { +namespace BuiltIns { + +StdActionImp::StdActionImp( KJS::ExecState *exec, JSFactory *fact, uint actid ) + : JSProxyImp(exec), id(actid), jsfact( fact ) +{ +} + +StdActionImp::~StdActionImp() +{ +} + +static uint KSTDACTION_START = KStdAction::New; +static uint KSTDACTION_END = KStdAction::ConfigureNotifications+1; + +const char *factoryMethodNames[] = { + "START_MARKER", + "fileNew", "open", "openRecent", "save", "saveAs", "revert", "close", + "print", "printPreview", "mail", "quit", + "undo", "redo", "cut", "copy", "paste", "selectAll", "deselect", "find", "findNext", "findPrev", + "replace", + "actualSize", "fitToPage", "fitToWidth", "fitToHeight", "zoomIn", "zoomOut", + "zoom", "redisplay", + "up", "back", "forward", "home", "prior", "next", "goGoto", "gotoPage", "gotoLine", + "firstPage", "lastPage", + "addBookmark", "editBookmarks", + "spelling", + "showMenubar", "showToolbar", "showStatusbar", "saveOptions", "keyBindings", + "preferences", "configureToolbars", + "help", "helpContents", "whatsThis", "reportBug", "aboutApp", "aboutKDE", + "tipofDay", + "configureNotifications", + "END_MARKER" +}; + +void StdActionImp::addBindings( JSFactory *fact, KJS::ExecState *exec, KJS::Object &parent ) +{ + for ( uint i = KSTDACTION_START; i < KSTDACTION_END; i++ ) { + StdActionImp *sai = new StdActionImp( exec, fact, i ); + parent.put( exec, factoryMethodNames[i], KJS::Object( sai ) ); + } +} + +KJS::Value StdActionImp::call( KJS::ExecState *exec, KJS::Object &/*self*/, const KJS::List &args ) +{ + if ( ( args.size() < 3 ) || ( args.size() > 4 ) ) + return KJS::Null(); + + // recv, slot, parent, name? + QObject *recv = extractQObject( exec, args, 0); + + QString sl = extractQString( exec, args, 1 ); + const char *slc = sl.isNull() ? "" : sl.ascii(); + + QObject *parentobj = extractQObject( exec, args, 2 ); + KActionCollection *parent = parentobj ? dynamic_cast<KActionCollection *>( parentobj ) : 0; + + KStdAction::StdAction actid = static_cast<KStdAction::StdAction>(id); + const char *arg3 = (args.size() == 4) ? args[3].toString(exec).ascii() : KStdAction::name( actid ); + + // Create the object + KAction *act = KStdAction::create( actid, arg3, recv, slc, parent ); + return jsfact->createProxy( exec, act ); +} + +} // namespace KJSEmbed::BuiltIns +} // namespace KJSEmbed + +// Local Variables: +// c-basic-offset: 4 +// End: diff --git a/kjsembed/builtins/stdaction_imp.h b/kjsembed/builtins/stdaction_imp.h new file mode 100644 index 00000000..9a64174b --- /dev/null +++ b/kjsembed/builtins/stdaction_imp.h @@ -0,0 +1,68 @@ +// -*- c++ -*- + +/* + * Copyright (C) 2003, Richard J. Moore <rich@kde.org> + * + * This 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. + * + * This 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 this library; see the file COPYING.LIB. If not, write to + * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, + * Boston, MA 02110-1301, USA. + */ + +#ifndef KJSEMBED_STDACTION_IMP_H +#define KJSEMBED_STDACTION_IMP_H + +#include <kjs/interpreter.h> +#include <kjs/object.h> + +#include <kjsembed/jsobjectproxy_imp.h> + +/** + * Namespace containing the KJSEmbed library. + */ +namespace KJSEmbed { +namespace BuiltIns { + +/** + * KJS bindings to KStdAction. + * + * @author Richard Moore, rich@kde.org + */ +class StdActionImp : public JSProxyImp +{ +public: + StdActionImp( KJS::ExecState *exec, JSFactory *fact, uint id ); + virtual ~StdActionImp(); + + /** Adds the StdActions object to the specified parent. */ + static void addBindings( JSFactory *fact, KJS::ExecState *exec, KJS::Object &parent ); + + /** Returns true iff this object implements the call function. */ + virtual bool implementsCall() const { return true; } + + /** Invokes the call function. */ + virtual KJS::Value call( KJS::ExecState *exec, KJS::Object &self, const KJS::List &args ); + +private: + uint id; + JSFactory *jsfact; +}; + +} // namespace KJSEmbed::BuiltIns +} // namespace KJSEmbed + +#endif // KJSEMBED_STDACTION_IMP_H + +// Local Variables: +// c-basic-offset: 4 +// End: diff --git a/kjsembed/builtins/stddialog_imp.cpp b/kjsembed/builtins/stddialog_imp.cpp new file mode 100644 index 00000000..1b45c5e0 --- /dev/null +++ b/kjsembed/builtins/stddialog_imp.cpp @@ -0,0 +1,147 @@ +/* + * Copyright (C) 2003, Richard J. Moore <rich@kde.org> + * + * This 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. + * + * This 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 this library; see the file COPYING.LIB. If not, write to + * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, + * Boston, MA 02110-1301, USA. + */ + +#ifndef QT_ONLY + +#include <kcolordialog.h> +#include <kfiledialog.h> +#include <kpropertiesdialog.h> + +#else + +#include <qfiledialog.h> +#define KFileDialog QFileDialog + +#endif // QT_ONLY + +#include <kjsembed/jsbinding.h> +#include <kjsembed/global.h> + +#include "stddialog_imp.h" + +namespace KJSEmbed { +namespace BuiltIns { + +StdDialogImp::StdDialogImp( KJS::ExecState *exec, int mid ) + : JSProxyImp(exec), id(mid) +{ +} + +StdDialogImp::~StdDialogImp() {} + +void StdDialogImp::addBindings( KJS::ExecState *exec, KJS::Object &parent ) +{ + StdDialogImp *sdi; + + sdi = new StdDialogImp( exec, StdDialogImp::MethodGetOpenFileName ); + parent.put( exec, "getOpenFileName", KJS::Object( sdi ) ); + sdi = new StdDialogImp( exec, StdDialogImp::MethodGetSaveFileName ); + parent.put( exec, "getSaveFileName", KJS::Object( sdi ) ); + + sdi = new StdDialogImp( exec, StdDialogImp::MethodGetOpenURL ); + parent.put( exec, "getOpenURL", KJS::Object( sdi ) ); + sdi = new StdDialogImp( exec, StdDialogImp::MethodGetSaveURL ); + parent.put( exec, "getSaveURL", KJS::Object( sdi ) ); + + sdi = new StdDialogImp( exec, StdDialogImp::MethodGetExistingDirectory ); + parent.put( exec, "getExistingDirectory", KJS::Object( sdi ) ); + sdi = new StdDialogImp( exec, StdDialogImp::MethodGetExistingURL ); + parent.put( exec, "getExistingURL", KJS::Object( sdi ) ); + + sdi = new StdDialogImp( exec, StdDialogImp::MethodGetImageOpenURL ); + parent.put( exec, "getImageOpenURL", KJS::Object( sdi ) ); + + sdi = new StdDialogImp( exec, StdDialogImp::MethodGetColor ); + parent.put( exec, "getColor", KJS::Object( sdi ) ); + + sdi = new StdDialogImp( exec, StdDialogImp::MethodShowProperties ); + parent.put( exec, "showProperties", KJS::Object( sdi ) ); +} + +KJS::Value StdDialogImp::call( KJS::ExecState *exec, KJS::Object &/*self*/, const KJS::List &args ) +{ + QString arg0 = (args.size() > 0) ? args[0].toString(exec).qstring() : QString::null; + QString arg1 = (args.size() > 1) ? args[1].toString(exec).qstring() : QString::null; + + switch( id ) { + case MethodGetOpenFileName: + { + QString s = KFileDialog::getOpenFileName( arg0, arg1 ); + return KJS::String( s ); + } + case MethodGetSaveFileName: + { + QString s = KFileDialog::getSaveFileName( arg0, arg1 ); + return KJS::String( s ); + } + case MethodGetExistingDirectory: + { + QString s = KFileDialog::getExistingDirectory( arg0 ); + return KJS::String( s ); + } +#ifndef QT_ONLY + case MethodGetColor: + { + QColor col; + int res = KColorDialog::getColor( col ); + if ( res == QDialog::Accepted ) + return convertToValue( exec, QVariant(col) ); + } + case MethodGetOpenURL: + { + KURL u = KFileDialog::getOpenURL( arg0, arg1 ); + return KJS::String( u.url() ); + } + case MethodGetSaveURL: + { + KURL u = KFileDialog::getSaveURL( arg0, arg1 ); + return KJS::String( u.url() ); + } + case MethodGetExistingURL: + { + KURL u = KFileDialog::getExistingURL( arg0 ); + return KJS::String( u.url() ); + } + case MethodGetImageOpenURL: + { + KURL u = KFileDialog::getImageOpenURL( arg0 ); + return KJS::String( u.url() ); + } + case MethodShowProperties: + { + // The default args mean this dialog auto-shows + /*KPropertiesDialog *dlg =*/ new KPropertiesDialog( KURL(arg0) ); + return KJS::Null(); + } +#endif // QT_ONLY + default: + kdWarning() << "StdDialogImp has no method " << id << endl; + } + + kdWarning() << "StdDialogImp returning null" << endl; + + return KJS::Null(); +} + +} // namespace KJSEmbed::BuiltIns +} // namespace KJSEmbed + +// Local Variables: +// c-basic-offset: 4 +// End: diff --git a/kjsembed/builtins/stddialog_imp.h b/kjsembed/builtins/stddialog_imp.h new file mode 100644 index 00000000..ea70db73 --- /dev/null +++ b/kjsembed/builtins/stddialog_imp.h @@ -0,0 +1,81 @@ +// -*- c++ -*- + +/* + * Copyright (C) 2003, Richard J. Moore <rich@kde.org> + * + * This 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. + * + * This 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 this library; see the file COPYING.LIB. If not, write to + * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, + * Boston, MA 02110-1301, USA. + */ + +#ifndef KJSEMBED_STDDIALOG_IMP_H +#define KJSEMBED_STDDIALOG_IMP_H + +#include <kjs/interpreter.h> +#include <kjs/object.h> + +#include <kjsembed/jsobjectproxy_imp.h> + +/** + * Namespace containing the KJSEmbed library. + */ +namespace KJSEmbed { +namespace BuiltIns { + +/** + * KJS bindings to the standard KDE dialogs. + * + * @author Richard Moore, rich@kde.org + */ +class StdDialogImp : public JSProxyImp +{ +public: + /** Identifiers for the various methods. */ + enum MethodId { + // KFileDialog + MethodGetOpenFileName, MethodGetSaveFileName, + MethodGetOpenURL, MethodGetSaveURL, + MethodGetExistingDirectory, MethodGetExistingURL, + MethodGetImageOpenURL, + + // KColorDialog + MethodGetColor, + // KPropertiesDialog + MethodShowProperties + }; + + StdDialogImp( KJS::ExecState *exec, int id ); + ~StdDialogImp(); + + /** Adds the StdDialogs object to the specified parent. */ + static void addBindings( KJS::ExecState *exec, KJS::Object &parent ); + + /** Returns true iff this object implements the call function. */ + virtual bool implementsCall() const { return true; } + + /** Invokes the call function. */ + virtual KJS::Value call( KJS::ExecState *exec, KJS::Object &self, const KJS::List &args ); + +private: + uint id; +}; + +} // namespace KJSEmbed::BuiltIns +} // namespace KJSEmbed + +#endif // KJSEMBED_STDDIALOG_IMP_H + +// Local Variables: +// c-basic-offset: 4 +// End: diff --git a/kjsembed/builtins/textstream_imp.cpp b/kjsembed/builtins/textstream_imp.cpp new file mode 100644 index 00000000..6be24dd9 --- /dev/null +++ b/kjsembed/builtins/textstream_imp.cpp @@ -0,0 +1,134 @@ +/* + * Copyright (C) 2003, Richard J. Moore <rich@kde.org> + * + * This 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. + * + * This 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 this library; see the file COPYING.LIB. If not, write to + * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, + * Boston, MA 02110-1301, USA. + */ + +#include <qtextstream.h> +#include <qiodevice.h> + +#include <kjsembed/global.h> +#include <kjsembed/jsbinding.h> +#include "jsopaqueproxy.h" +#include "textstream_imp.h" + +namespace KJSEmbed { +namespace BuiltIns { + +TextStreamImp::TextStreamImp( KJS::ExecState *exec, int mid, QTextStream *textstream ) + : JSProxyImp(exec), id(mid), ts(textstream) +{ +} + +TextStreamImp::~TextStreamImp() +{ +} + +void TextStreamImp::addBindings( KJS::ExecState *exec, KJS::Object &parent ) +{ + kdDebug() << "TextStreamImp::addBindings()" << endl; + + JSOpaqueProxy *op = JSProxy::toOpaqueProxy( parent.imp() ); + if ( !op ) { + kdWarning() << "TextStreamImp::addBindings() failed, not a JSOpaqueProxy" << endl; + return; + } + + QTextStream *ts = op->toTextStream(); + if ( !ts ) { + kdWarning() << "TextStreamImp::addBindings() failed, type is " << op->typeName() << endl; + return; + } + + JSProxy::MethodTable methods[] = { + { MethodIsReadable, "isReadable" }, + { MethodIsWritable, "isWritable" }, + { MethodPrint, "print" }, + { MethodPrintLn, "println" }, + { MethodReadLine, "readLine" }, + { MethodFlush, "flush" }, + { 0, 0 } + }; + + int idx = 0; + do { + TextStreamImp *tsi = new TextStreamImp( exec, idx, ts ); + parent.put( exec , methods[idx].name, KJS::Object(tsi) ); + ++idx; + } while( methods[idx].id ); +} + +KJS::Value TextStreamImp::call( KJS::ExecState *exec, KJS::Object &/*self*/, const KJS::List &args ) +{ + QString not_readable = i18n( "Attempt to read from a write-only text stream." ); + QString not_writable = i18n( "Attempt to write to a read-only text stream." ); + + QString arg0 = extractQString(exec, args, 0); + + QIODevice *dev = ts->device(); + KJS::Object err; + + switch ( id ) { + case MethodIsReadable: + return KJS::Boolean( dev->isReadable() ); + break; + case MethodIsWritable: + return KJS::Boolean( dev->isWritable() ); + break; + case MethodPrint: + if ( !dev->isWritable() ) { + return throwError(exec, not_writable.utf8()); + } + (*ts) << arg0; + break; + case MethodPrintLn: + if ( !dev->isWritable() ) { + return throwError(exec, not_writable.utf8()); + } + (*ts) << arg0 << endl; + break; + case MethodReadLine: + if ( dev->isReadable() ) { + QString line = ts->readLine(); + if ( line.isNull() ) + return KJS::Null(); + else + return KJS::String( line ); + } + else { + return throwError(exec, not_readable.utf8()); + } + break; + case MethodFlush: + if ( !dev->isWritable() ) { + return throwError(exec, not_writable.utf8()); + } + (*ts) << flush; + break; + default: + kdWarning() << "TextStreamImp has no method " << id << endl; + break; + } + + return KJS::Value(); +} + +} // namespace KJSEmbed::BuiltIns +} // namespace KJSEmbed + +// Local Variables: +// c-basic-offset: 4 +// End: diff --git a/kjsembed/builtins/textstream_imp.h b/kjsembed/builtins/textstream_imp.h new file mode 100644 index 00000000..ca46fc37 --- /dev/null +++ b/kjsembed/builtins/textstream_imp.h @@ -0,0 +1,79 @@ +// -*- c++ -*- + +/* + * Copyright (C) 2003, Richard J. Moore <rich@kde.org> + * + * This 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. + * + * This 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 this library; see the file COPYING.LIB. If not, write to + * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, + * Boston, MA 02110-1301, USA. + */ + +#ifndef KJSEMBEDTEXTSTREAMIMP_H +#define KJSEMBEDTEXTSTREAMIMP_H + +#include <kjs/object.h> +#include <kjsembed/jsbinding.h> + +#include <kjsembed/jsobjectproxy_imp.h> + +class QTextStream; + +namespace KJSEmbed { +namespace BuiltIns { + +/** + * Implements the JS methods of text stream object bindings. + * + * @author Richard Moore, rich@kde.org + * @version $Id$ + */ +class TextStreamImp : public JSProxyImp +{ +public: + /** Identifiers for the methods provided by this class. */ + enum MethodId { + MethodIsReadable, + MethodIsWritable, + MethodPrint, + MethodPrintLn, + MethodReadLine, + MethodFlush + }; + + TextStreamImp( KJS::ExecState *exec, int id, QTextStream *ts ); + ~TextStreamImp(); + + static void addBindings( KJS::ExecState *exec, KJS::Object &object ); + + /** Returns true iff this object implements the call function. */ + virtual bool implementsCall() const { return true; } + + /** Invokes the call function. */ + virtual KJS::Value call( KJS::ExecState *exec, KJS::Object &self, const KJS::List &args ); + +private: + int id; + QTextStream *ts; + + class TextStreamImpPrivate *d; +}; + +} // namespace KJSEmbed::BuiltIns +} // namespace KJSEmbed + +#endif // KJSEMBEDTEXTSTREAMIMP_H + +// Local Variables: +// c-basic-offset: 4 +// End: diff --git a/kjsembed/cpptests/Makefile.am b/kjsembed/cpptests/Makefile.am new file mode 100644 index 00000000..f70b1e8b --- /dev/null +++ b/kjsembed/cpptests/Makefile.am @@ -0,0 +1,2 @@ +SUBDIRS = jsaccess + diff --git a/kjsembed/cpptests/jsaccess/Makefile.am b/kjsembed/cpptests/jsaccess/Makefile.am new file mode 100644 index 00000000..eda2e3e1 --- /dev/null +++ b/kjsembed/cpptests/jsaccess/Makefile.am @@ -0,0 +1,18 @@ +# -*- makefile -*- + +# Make sure the include path includes Qt's uilib +INCLUDES = -I$(QTDIR)/tools/designer/uilib -I$(srcdir)/../../../.. -I.. -I$(top_srcdir) $(all_includes) + +INCLUDES += -DQT_CLEAN_NAMESPACE -DQT_NO_ASCII_CAST + +bin_PROGRAMS = jsaccess + +jsaccess_SOURCES = jsaccess.cpp +jsaccess_LDFLAGS = $(all_libraries) $(KDE_RPATH) +jsaccess_LDADD = $(top_builddir)/kjsembed/libkjsembed.la + +METASOURCES = AUTO + + + + diff --git a/kjsembed/cpptests/jsaccess/jsaccess.cpp b/kjsembed/cpptests/jsaccess/jsaccess.cpp new file mode 100644 index 00000000..5693ceea --- /dev/null +++ b/kjsembed/cpptests/jsaccess/jsaccess.cpp @@ -0,0 +1,106 @@ +/* + * Copyright (C) 2004 Ian Reinhart Geiser <geiseri@kde.org> + * + * This 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. + * + * This 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 this library; see the file COPYING.LIB. If not, write to + * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, + * Boston, MA 02110-1301, USA. + */ + +#include <kdebug.h> + +#include <kaboutdata.h> +#include <kapplication.h> +#include <kcmdlineargs.h> +#include <klocale.h> +#include <kjs/interpreter.h> + +#include <kjsembed/jsconsolewidget.h> +#include <kjsembed/jsobjectproxy.h> +#include <kjsembed/jsfactory.h> +#include <kjsembed/kjsembedpart.h> +#include <kjsembed/jssecuritypolicy.h> + +using namespace KJSEmbed; + +int main( int argc, char **argv ) +{ + KAboutData about( "test-kjsembed", I18N_NOOP("KJS Embed Test For C++ access of variables and functions."), "0.1", + I18N_NOOP("Test"), + KAboutData::License_LGPL, I18N_NOOP("(c) 2004 Ian Reinhart Geiser") ); + KCmdLineArgs::init( argc, argv, &about ); + KApplication app; + + // Setup Interpreter + KJSEmbed::JSSecurityPolicy::setDefaultPolicy( KJSEmbed::JSSecurityPolicy::CapabilityAll ); + KJSEmbed::KJSEmbedPart *part = new KJSEmbed::KJSEmbedPart; + KJS::Interpreter *js = part->interpreter(); + KJS::ExecState *exec = js->globalExec(); + + QString script = "var foobar = \"test from javascript.\";" + "function testNoArgsFunction( ){ return foobar; }" + "function testNoReturnFunction( value ){ foobar = value; }" + "function testFunction( value ){ return \"testFunction dorks with \" + value;}"; + KJS::Value returnValue = part->evaluate(script,js->globalObject()); + if( returnValue.isValid() && !returnValue.toBoolean(exec ) ) + kdWarning() << "Script failed to run." << endl; + + /** + * Test extraction of a Variant from javascript + */ + QString value = part->getVariant("foobar").toString(); + if( value != "test from javascript." ) + kdWarning() << "Get variant failed with: " << value << endl; + + /** + * Test manipulation of a Variant from C++ + */ + part->putVariant("foobar", "test from C++."); + value = part->getVariant("foobar").toString(); + if( value != "test from C++." ) + kdWarning() << "Put variant failed with: " << value << endl; + + /** + * Test to see if a function is present + */ + if( !part->hasMethod("testFunction") ) + kdWarning() << "error finding testFunction" << endl; + + if( part->hasMethod("foobar") ) + kdWarning() << "error i found a value and was looking for a method" << endl; + /** + * Test calling function that takes an arg, and returns a value. + */ + KJS::List args; + args.append(KJS::String("C++ String")); + value = part->callMethod("testFunction", args).toString(exec).qstring(); + if ( value != "testFunction dorks with C++ String" ) + kdWarning() << "error calling testFunction, wanted \"testFunction dorks with C++ String\" but got " << value << endl; + + /** + * Test calling function that takes an arg, and returns nothing. + */ + args.clear(); + args.append(KJS::String("C++ String")); + returnValue = part->callMethod("testNoReturnFunction", args); + if ( returnValue.isNull() ) + kdWarning() << "error calling testNoReturnFunction is suppose to be null and was " << returnValue.toString(exec).qstring() << endl; + /** + * Test calling function that takes no args, and returns a value + */ + args.clear(); + value = part->callMethod("testNoArgsFunction", args).toString(exec).qstring(); + if ( value != "C++ String" ) + kdWarning() << "error calling testNoArgsFunction, wanted \"C++ String\" but got " << value << endl; + return 1; +} diff --git a/kjsembed/customobject_imp.cpp b/kjsembed/customobject_imp.cpp new file mode 100644 index 00000000..8dd9fc24 --- /dev/null +++ b/kjsembed/customobject_imp.cpp @@ -0,0 +1,1444 @@ +/* + * Copyright (C) 2001-2004, Richard J. Moore <rich@kde.org> + * + * This 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. + * + * This 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 this library; see the file COPYING.LIB. If not, write to + * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, + * Boston, MA 02110-1301, USA. + */ +#include "global.h" +#include <qapplication.h> +#include <qobject.h> +#include <qobjectlist.h> +#include <qcombobox.h> +#include <qpopupmenu.h> +#include <qdialog.h> +#include <qhbox.h> +#include <qlayout.h> +#include <qlistbox.h> +#include <qlistview.h> +#include <qmetaobject.h> +#include <qpainter.h> +#include <qregexp.h> +#include <qsignal.h> +#include <qstrlist.h> +#include <qtabwidget.h> +#include <qtimer.h> +#include <qvariant.h> +#include <qcanvas.h> +#include <qsplashscreen.h> +#include <qtoolbox.h> +#include <qmenudata.h> + +#include <private/qucom_p.h> +#include <private/qucomextra_p.h> + +#ifndef QT_ONLY + +#include <khtml_part.h> +#include <kaction.h> + +#include <klistview.h> +#include <kurl.h> +#include <kmainwindow.h> +#include <kmenubar.h> +#include <kstatusbar.h> +#include <ksystemtray.h> +#include <kpopupmenu.h> + +#endif // QT_ONLY + +#include <kjs/interpreter.h> +#include <kjs/types.h> +#include <kjs/ustring.h> + +#include "kjsembedpart.h" +#include "jssecuritypolicy.h" +#include "jsfactory.h" +#include "jsbinding.h" +#include "slotproxy.h" +#include "jsopaqueproxy.h" + +#include "customobject_imp.h" + +#include "qtbindings/qcombobox_imp.h" +//#include "qtbindings/qlistviewitem_imp.h" +//#include "qtbindings/qlistview_imp.h" +#include "qtbindings/qcanvasview_imp.h" +//#include "qtbindings/qchecklistitem_imp.h" +#include "qtbindings/qpopupmenu_imp.h" +#include "qtbindings/qframe_imp.h" +#include "qtbindings/qmenudata_imp.h" +#include "qtbindings/qmenuitem_imp.h" + + + +#define ADDBINDING(TYPE,PROXY) \ +TYPE *ptr ## TYPE = dynamic_cast< TYPE *> ( PROXY );\ +if ( ptr ## TYPE ) \ +{ \ + TYPE ## Imp::addBindings( exec, object ); \ +} + +namespace KJSEmbed { +namespace Bindings { + +void CustomObjectImp::addBindings( KJS::ExecState *exec, KJS::Object &object ) +{ + kdDebug() << "CustomObjectImp::addBindings for " << object.className().qstring() << endl; + CustomObjectImp *obj = 0; + + JSObjectProxy *proxy = JSProxy::toObjectProxy( object.imp() ); + if ( !proxy ) + return; + kdDebug() << "CustomObjectImp::addBindings is a proxy" << endl; + QObject *qobj = proxy->object(); + QWidget *widget = proxy->widget(); + +#ifndef QT_ONLY + if ( qobj ) { + KXMLGUIClient *gc = dynamic_cast<KXMLGUIClient *>( qobj ); + if ( gc ) { + obj = new CustomObjectImp( exec, KXMLGUIClientActionCollection, proxy ); + object.put( exec, "actionCollection", KJS::Object(obj) ); + } + } + + KActionCollection *collection = dynamic_cast<KActionCollection*>( qobj ); + if( collection ) proxy->setOwner(JSProxy::Native); +#endif // QT_ONLY + + if ( widget ) { + obj = new CustomObjectImp( exec, WidgetGrabWidget, proxy ); + object.put(exec, "grabWidget", KJS::Object(obj)); + obj = new CustomObjectImp( exec, WidgetDrawLine, proxy ); + object.put( exec, "drawLine", KJS::Object(obj) ); + obj = new CustomObjectImp( exec, WidgetDrawText, proxy ); + object.put( exec, "drawText", KJS::Object(obj) ); + + QListBox *listbox = dynamic_cast<QListBox *>( widget ); + if ( listbox ) { + obj = new CustomObjectImp( exec, ListBoxInsertItem, proxy ); + object.put( exec, "insertItem", KJS::Object(obj) ); + } + + QListView *listview = dynamic_cast<QListView *>( widget ); + if ( listview ) { + obj = new CustomObjectImp( exec, ListViewAddColumn, proxy ); + object.put( exec, "addColumn", KJS::Object(obj) ); + obj = new CustomObjectImp( exec, ListViewInsertItem, proxy ); + object.put( exec, "insertItem", KJS::Object(obj) ); + obj = new CustomObjectImp( exec, ListViewSelectedItem, proxy ); + object.put( exec, "selectedItem", KJS::Object(obj) ); + obj = new CustomObjectImp( exec, ListViewHideColumn, proxy ); + object.put( exec, "hideColumn", KJS::Object(obj) ); + obj = new CustomObjectImp( exec, ListViewTakeItem, proxy ); + object.put( exec, "takeItem", KJS::Object(obj) ); + obj = new CustomObjectImp( exec, ListViewFirstChild, proxy ); + object.put( exec, "firstChild", KJS::Object(obj) ); + obj = new CustomObjectImp( exec, ListViewCurrentItem, proxy ); + object.put( exec, "currentItem", KJS::Object(obj) ); + } + QSplashScreen *splashscreen = dynamic_cast<QSplashScreen *>(widget); + if( splashscreen ) + { + obj = new CustomObjectImp(exec, QSplashScreenSetPixmap, proxy ); + object.put(exec, "setPixmap", KJS::Object(obj) ); + obj = new CustomObjectImp(exec, QSplashScreenPixmap, proxy ); + object.put(exec, "pixmap", KJS::Object(obj) ); + obj = new CustomObjectImp(exec, QSplashScreenFinish, proxy ); + object.put(exec, "finish", KJS::Object(obj) ); + obj = new CustomObjectImp(exec, QSplashScreenRepaint, proxy ); + object.put(exec, "repaint", KJS::Object(obj) ); + } + +#ifndef QT_ONLY + KMainWindow *mw = dynamic_cast<KMainWindow *>( widget ); + if ( mw ) { + obj = new CustomObjectImp( exec, MainWindowSetCentralWidget, proxy ); + object.put( exec, "setCentralWidget", KJS::Object(obj) ); + obj = new CustomObjectImp( exec, MainWindowCreateGUI, proxy ); + object.put( exec, "createGUI", KJS::Object(obj) ); + obj = new CustomObjectImp( exec, MainWindowMenuBar, proxy ); + object.put( exec, "menuBar", KJS::Object(obj) ); + obj = new CustomObjectImp( exec, MainWindowStatusBar, proxy ); + object.put( exec, "statusBar", KJS::Object(obj) ); + obj = new CustomObjectImp( exec, MainWindowSetStandardToolBarMenuEnabled, proxy ); + object.put( exec, "setStandardToolBarMenuEnabled", KJS::Object(obj) ); + } + + KSystemTray *systray = dynamic_cast<KSystemTray *>( qobj ); + if ( systray ) { + obj = new CustomObjectImp( exec, KSystemTrayContextMenu, proxy ); + object.put( exec, "contextMenu", KJS::Object(obj) ); + obj = new CustomObjectImp( exec, KSystemTrayActionCollection, proxy ); + object.put( exec, "actionCollection", KJS::Object(obj) ); + obj = new CustomObjectImp( exec, KSystemTrayLoadIcon, proxy ); + object.put( exec, "loadIcon", KJS::Object(obj) ); + } + +#endif // QT_ONLY + + QTabWidget *tw = dynamic_cast<QTabWidget *>( widget ); + if ( tw ) { + obj = new CustomObjectImp( exec, TabWidgetAddTab, proxy ); + object.put( exec, "addTab", KJS::Object(obj) ); + } + + QScrollView *sv = dynamic_cast<QScrollView *>( widget ); + if ( sv ) { + obj = new CustomObjectImp( exec, ScrollViewViewport, proxy ); + object.put( exec, "viewport", KJS::Object(obj) ); + obj = new CustomObjectImp( exec, ScrollViewAddChild, proxy ); + object.put( exec, "addChild", KJS::Object(obj) ); + } + + //ADDBINDING( QMenuItem, widget) + //ADDBINDING( QMenuData, widget) + + ADDBINDING( QPopupMenu, widget ) + ADDBINDING( QComboBox, widget ) + //ADDBINDING( QFrame, widget ) + /*ADDBINDING( QListView, widget )*/ + ADDBINDING( QCanvasView, widget ) + + /* + QMenuData *md = dynamic_cast<QMenuData *>( widget ); + if ( md ) { + QMenuDataImp::addBindings( exec, object ); + } + + QMenuItem *mitem = dynamic_cast<QMenuItem *>( widget ); + if ( mitem ) { + QMenuItemImp::addBindings( exec, object ); + } + */ + QMenuData *menuData = dynamic_cast<QMenuData*>(widget); + if( menuData ) + { + obj = new CustomObjectImp( exec, QMenuDataInsertItem, proxy ); + object.put( exec, "insertItem", KJS::Object(obj) ); + obj = new CustomObjectImp( exec, QMenuDataRemoveItem, proxy ); + object.put( exec, "removeItem", KJS::Object(obj) ); + obj = new CustomObjectImp( exec, QMenuDataRemoveItem, proxy ); + object.put( exec, "insertSeparator", KJS::Object(obj) ); + } + + QHBox *hbox = dynamic_cast<QHBox *>( widget ); + if ( hbox ) { + obj = new CustomObjectImp( exec, HBoxSpacing, proxy ); + object.put( exec, "setSpacing", KJS::Object(obj) ); + } + QToolBox *tb = dynamic_cast<QToolBox *>( qobj ); + if ( tb ) { + obj = new CustomObjectImp( exec, QToolBoxAddItem, proxy ); + object.put( exec, "addItem", KJS::Object(obj) ); + obj = new CustomObjectImp( exec, QToolBoxInsertItem, proxy ); + object.put( exec, "insertItem", KJS::Object(obj) ); + obj = new CustomObjectImp( exec, QToolBoxRemoveItem, proxy ); + object.put( exec, "removeItem", KJS::Object(obj) ); + obj = new CustomObjectImp( exec, QToolBoxItemLabel, proxy ); + object.put( exec, "itemLabel", KJS::Object(obj) ); + obj = new CustomObjectImp( exec, QToolBoxSetItemLabel, proxy ); + object.put( exec, "setItemLabel", KJS::Object(obj) ); + obj = new CustomObjectImp( exec, QToolBoxItemIconSet, proxy ); + object.put( exec, "itemIconSet", KJS::Object(obj) ); + obj = new CustomObjectImp( exec, QToolBoxSetItemIconSet, proxy ); + object.put( exec, "setItemIconSet", KJS::Object(obj) ); + obj = new CustomObjectImp( exec, QToolBoxItem, proxy ); + object.put( exec, "item", KJS::Object(obj) ); + } + return; + } + + if ( qobj ) { + QApplication *app = dynamic_cast<QApplication *>( qobj ); + if ( app ) { + obj = new CustomObjectImp( exec, ApplicationExec, proxy ); + object.put( exec, "exec", KJS::Object(obj) ); + } + +#ifndef QT_ONLY + + KParts::ReadOnlyPart *ropart = dynamic_cast<KParts::ReadOnlyPart *>( qobj ); + if ( ropart ) { + obj = new CustomObjectImp( exec, KReadOnlyPartOpenStream, proxy ); + object.put( exec, "openStream", KJS::Object(obj) ); + obj = new CustomObjectImp( exec, KReadOnlyPartWriteStream, proxy ); + object.put( exec, "writeStream", KJS::Object(obj) ); + obj = new CustomObjectImp( exec, KReadOnlyPartCloseStream, proxy ); + object.put( exec, "closeStream", KJS::Object(obj) ); + } + + KHTMLPart *htmlpart = dynamic_cast<KHTMLPart *>( qobj ); + if ( htmlpart ) { + obj = new CustomObjectImp( exec, KHTMLPartSelectAll, proxy ); + object.put( exec, "selectAll", KJS::Object(obj) ); + obj = new CustomObjectImp( exec, KHTMLPartHasSelection, proxy ); + object.put( exec, "hasSelection", KJS::Object(obj) ); + obj = new CustomObjectImp( exec, KHTMLPartSelectedText, proxy ); + object.put( exec, "selectedText", KJS::Object(obj) ); + } + +#endif // QT_ONLY + + QTimer *timer = dynamic_cast<QTimer *>( qobj ); + if ( timer ) { + obj = new CustomObjectImp( exec, TimerIsActive, proxy ); + object.put( exec, "isActive", KJS::Object(obj) ); + obj = new CustomObjectImp( exec, TimerStart, proxy ); + object.put( exec, "start", KJS::Object(obj) ); + obj = new CustomObjectImp( exec, TimerStop, proxy ); + object.put( exec, "stop", KJS::Object(obj) ); + } + + QBoxLayout *box = dynamic_cast<QBoxLayout *>( qobj ); + if ( box ) { + obj = new CustomObjectImp( exec, BoxLayoutAddWidget, proxy ); + object.put( exec, "addWidget", KJS::Object(obj) ); + obj = new CustomObjectImp( exec, BoxLayoutAddSpacing, proxy ); + object.put( exec, "addSpacing", KJS::Object(obj) ); + obj = new CustomObjectImp( exec, BoxLayoutAddStretch, proxy ); + object.put( exec, "addStretch", KJS::Object(obj) ); + obj = new CustomObjectImp( exec, BoxLayoutAddLayout, proxy ); + object.put( exec, "addLayout", KJS::Object(obj) ); + } + } +} + +CustomObjectImp::CustomObjectImp( KJS::ExecState *exec, int mid, JSObjectProxy *parent ) + : JSProxyImp(exec), id(mid), proxy(parent) +{ +} + +KJS::Value CustomObjectImp::call( KJS::ExecState *exec, KJS::Object &self, const KJS::List &args ) +{ + switch( id ) { + case WidgetGrabWidget: + return widgetGrabWidget( exec, self, args ); + break; + case WidgetDrawLine: + widgetDrawLine( exec, self, args ); + return KJS::Value(); + break; + case WidgetDrawText: + widgetDrawText( exec, self, args ); + return KJS::Value(); + break; + case ListBoxInsertItem: + listBoxInsertItem( exec, self, args ); + return KJS::Value(); + break; + case ListViewAddColumn: + listViewAddColumn( exec, self, args ); + return KJS::Value(); + break; + case ListViewInsertItem: + listViewInsertItem( exec, self, args ); + return KJS::Value(); + break; + case ListViewSelectedItem: + return listViewSelectedItem( exec, self, args ); + break; + case ListViewHideColumn: + listViewHideColumn( exec, self, args ); + return KJS::Value(); + break; + case MainWindowSetCentralWidget: + mainWinSetCentralWidget( exec, self, args ); + return KJS::Value(); + break; + case MainWindowCreateGUI: + mainWinCreateGUI( exec, self, args ); + return KJS::Value(); + break; + case MainWindowMenuBar: + return mainWinMenuBar( exec, self, args ); + break; + case MainWindowStatusBar: + return mainWinStatusBar( exec, self, args ); + break; + case MainWindowSetStandardToolBarMenuEnabled: + mainWinSetStandardToolBarMenuEnabled( exec, self, args ); + return KJS::Value(); + break; + case TabWidgetAddTab: + tabWidgetAddTab( exec, self, args ); + return KJS::Value(); + break; + case ScrollViewViewport: + return scrollViewViewport( exec, self, args ); + break; + case ScrollViewAddChild: + scrollViewAddChild( exec, self, args ); + return KJS::Value(); + break; + case ApplicationExec: + return applicationExec( exec, self, args ); + break; + case TimerIsActive: + return timerIsActive( exec, self, args ); + break; + case TimerStart: + return timerStart( exec, self, args ); + break; + case TimerStop: + return timerStop( exec, self, args ); + break; + case BoxLayoutAddWidget: + boxLayoutAddWidget( exec, self, args ); + return KJS::Value(); + break; + case BoxLayoutAddSpacing: + boxLayoutAddSpacing( exec, self, args ); + return KJS::Value(); + break; + case BoxLayoutAddStretch: + boxLayoutAddStretch( exec, self, args ); + return KJS::Value(); + break; + case BoxLayoutAddLayout: + boxLayoutAddLayout( exec, self, args ); + return KJS::Value(); + break; + case URLRequesterSetMode: + case URLRequesterSetFilter: + case URLRequesterUrl: + case URLRequesterSetLocalProtocol: + case URLRequesterLocalProtocol: + kdWarning() << "CustomObjectImp unsupported method call " << id << endl; + break; + case KXMLGUIClientActionCollection: + return xmlguiClientActionCollection( exec, self, args ); + break; + case KReadOnlyPartOpenStream: + return kroPartOpenStream( exec, self, args ); + break; + case KReadOnlyPartWriteStream: + return kroPartWriteStream( exec, self, args ); + break; + case KReadOnlyPartCloseStream: + return kroPartCloseStream( exec, self, args ); + break; + case HBoxSpacing: + hboxSpacing( exec, self, args ); + return KJS::Value(); + break; + case KHTMLPartSelectAll: + khtmlPartSelectAll( exec, self, args ); + return KJS::Value(); + break; + case KHTMLPartHasSelection: + return khtmlPartHasSelection( exec, self, args ); + break; + case KHTMLPartSelectedText: + return khtmlPartSelectedText( exec, self, args ); + break; + case KSystemTrayContextMenu: + return ksystemtrayContextMenu( exec, self, args ); + break; + case KSystemTrayActionCollection: + return ksystemtrayActionCollection( exec, self, args ); + break; + case KSystemTrayLoadIcon: + return ksystemtrayLoadIcon( exec, self, args ); + break; + case QCanvasViewCanvas: + return qcanvasViewCanvas( exec, self, args ); + break; + case QCanvasViewSetCanvas: + qcanvasViewSetCanvas( exec, self, args ); + return KJS::Value(); + break; + case QSplashScreenSetPixmap: + return qsplashScreenSetPixmap(exec, self, args ); + break; + case QSplashScreenPixmap: + return qsplashScreenPixmap(exec, self, args ); + break; + case QSplashScreenFinish: + return qsplashScreenFinish(exec, self, args ); + break; + case QSplashScreenRepaint: + return qsplashScreenRepaint(exec, self, args ); + break; + case QToolBoxAddItem: + return qtoolBoxAddItem(exec, self, args ); + break; + case QToolBoxInsertItem: + return qtoolBoxInsertItem(exec, self, args ); + break; + case QToolBoxRemoveItem: + qtoolBoxRemoveItem(exec, self, args ); + return KJS::Boolean(true); + break; + case QToolBoxItemLabel: + return qtoolBoxItemLabel(exec, self, args ); + break; + case QToolBoxSetItemLabel: + qtoolBoxSetItemLabel(exec, self, args ); + return KJS::Boolean(true); + break; + case QToolBoxItemIconSet: + return qtoolBoxItemIconSet(exec, self, args ); + break; + case QToolBoxSetItemIconSet: + qtoolBoxSetItemIconSet(exec, self, args ); + return KJS::Boolean(true); + break; + case QToolBoxItem: + return qtoolBoxItem(exec, self, args ); + break; + case QMenuDataInsertItem: + return qmenuDataInsertItem(exec, self, args ); + break; + case QMenuDataRemoveItem: + qmenuDataRemoveItem(exec, self, args ); + return KJS::Boolean(true); + break; + case QMenuDataInsertSeparator: + qmenuDataInsertSeparator(exec, self, args ); + return KJS::Boolean(true); + break; + + case ListViewTakeItem: + return qlistViewTakeItem(exec, self, args ); + break; + case ListViewFirstChild: + return qlistViewFirstChild(exec, self, args ); + break; + case ListViewCurrentItem: + return qlistViewFirstChild(exec, self, args ); + break; + default: + break; + } + + return KJS::ObjectImp::call( exec, self, args ); +} + +KJS::Value CustomObjectImp::qsplashScreenSetPixmap(KJS::ExecState *exec, KJS::Object &, const KJS::List &args ) +{ + QSplashScreen *ss = dynamic_cast<QSplashScreen*>(proxy->widget()); + if ( ss ) + { + QPixmap pix = extractQPixmap(exec, args, 0 ); + ss->setPixmap(pix); + } + return KJS::Value(); +} + +KJS::Value CustomObjectImp::qsplashScreenPixmap(KJS::ExecState *exec, KJS::Object &, const KJS::List & ) +{ + QSplashScreen *ss = dynamic_cast<QSplashScreen*>(proxy->widget()); + if ( ss ) + { + QPixmap pix = *(ss->pixmap()); + return convertToValue(exec, pix); + } + return KJS::Value(); +} + +KJS::Value CustomObjectImp::qsplashScreenFinish(KJS::ExecState *exec, KJS::Object &, const KJS::List &args ) +{ + QSplashScreen *ss = dynamic_cast<QSplashScreen*>(proxy->widget()); + if ( ss ) + { + QWidget *w = extractQWidget(exec, args, 0 ); + ss->finish(w); + } + return KJS::Value(); +} + +KJS::Value CustomObjectImp::qsplashScreenRepaint(KJS::ExecState *exec, KJS::Object &, const KJS::List & ) +{ + QSplashScreen *ss = dynamic_cast<QSplashScreen*>(proxy->widget()); + if ( ss ) + { + ss->repaint(); + } + return KJS::Value(); +} + + +KJS::Value CustomObjectImp::widgetGrabWidget(KJS::ExecState *exec, KJS::Object &, const KJS::List & ) +{ + QWidget *w = proxy->widget(); + if ( !w ) + return KJS::Value(); + QVariant pix(QPixmap::grabWidget(w) ); + return convertToValue( exec, pix ); + +} +void CustomObjectImp::widgetDrawLine( KJS::ExecState *exec, KJS::Object &, const KJS::List &args ) +{ + if ( args.size() != 4 ) + return; + + QWidget *w = proxy->widget(); + if ( !w ) + return; + + int x = extractInt( exec, args, 0 ); + int y = extractInt( exec, args, 1 ); + int x1 = extractInt( exec, args, 2 ); + int y1 = extractInt( exec, args, 3 ); + + QPainter p(w); + p.drawLine(x,y,x1,y1); +} + +void CustomObjectImp::widgetDrawText( KJS::ExecState *exec, KJS::Object &, const KJS::List &args ) +{ + if ( args.size() != 3 ) + return; + + QWidget *w = proxy->widget(); + if ( !w ) + return; + + int x = extractInt( exec, args, 0 ); + int y = extractInt( exec, args, 1 ); + QString s = extractQString( exec, args, 2 ); + w->drawText( x, y, s ); +} + +void CustomObjectImp::listBoxInsertItem( KJS::ExecState *exec, KJS::Object &, const KJS::List &args ) +{ + if ( args.size() != 1 ) + return; + + QListBox *lb = dynamic_cast<QListBox *>( proxy->object() ); + if ( !lb ) + return; + + QString s = extractQString( exec, args, 0 ); + lb->insertItem( s ); +} + +void CustomObjectImp::listViewAddColumn( KJS::ExecState *exec, KJS::Object &, const KJS::List &args ) +{ + if ( args.size() != 1 ) + return; + + QListView *lv = dynamic_cast<QListView *>( proxy->object() ); + if ( !lv ) + return; + + QString s = extractQString( exec, args, 0 ); + lv->addColumn( s ); +} + +void CustomObjectImp::listViewInsertItem( KJS::ExecState *exec, KJS::Object &, const KJS::List &args ) +{ + if ( !args.size() ) + return; + +#ifndef QT_ONLY + + KListView *klv = dynamic_cast<KListView *>( proxy->object() ); + if ( klv ) { + KListViewItem *lvm = new KListViewItem(klv); + + for( int idx = 0; idx < args.size(); ++idx){ + QVariant arg = convertToVariant(exec, args[idx]); + if( arg.canCast(QVariant::String) ) + lvm->setText(idx, arg.toString()); + else if ( arg.canCast(QVariant::Pixmap) ) + lvm->setPixmap(idx, arg.toPixmap()); + } + return; + } + +#endif // QT_ONLY + + QListView *lv = dynamic_cast<QListView *>( proxy->object() ); + if ( lv ) { + QListViewItem *lvm = new QListViewItem(lv); + + for( int idx = 0; idx < args.size(); ++idx){ + QVariant arg = convertToVariant(exec, args[idx]); + if( arg.canCast(QVariant::String) ) + lvm->setText(idx, arg.toString()); + else if ( arg.canCast(QVariant::Pixmap) ) + lvm->setPixmap(idx, arg.toPixmap()); + } + + } +} + +KJS::Value CustomObjectImp::listViewSelectedItem( KJS::ExecState *exec, KJS::Object &, const KJS::List &args ) +{ + if ( args.size() ) + return KJS::Value(); + + QListView *lv = dynamic_cast<QListView *>( proxy->object() ); + if ( !lv ) + return KJS::Value(); + + QListViewItem *lvi = lv->selectedItem(); + if ( !lvi ) + return KJS::Null(); + + QCheckListItem *cli = dynamic_cast<QCheckListItem *>( lvi ); + if ( cli ) { + JSOpaqueProxy *prx = new JSOpaqueProxy( lvi, "QCheckListItem" ); + KJS::Object proxyObj(prx); + proxy->part()->factory()->extendOpaqueProxy(exec, proxyObj); + return proxyObj; + } + + JSOpaqueProxy *prx = new JSOpaqueProxy( lvi, "QListViewItem" ); + KJS::Object proxyObj(prx); + proxy->part()->factory()->extendOpaqueProxy(exec, proxyObj); + return proxyObj; + +} + +void CustomObjectImp::listViewHideColumn( KJS::ExecState *exec, KJS::Object &, const KJS::List &args ) +{ + if ( args.size() != 1 ) + return; + + QListView *lv = dynamic_cast<QListView *>( proxy->object() ); + if ( !lv ) + return; + + int i = extractInt( exec, args, 0 ); + lv->hideColumn( i ); +} + +void CustomObjectImp::mainWinSetCentralWidget( KJS::ExecState *exec, + KJS::Object &, const KJS::List &args ) +{ +#ifndef QT_ONLY + + if ( args.size() != 1 ) + return; + + KJS::Object jsobj = args[0].toObject(exec); + JSObjectProxy *cwproxy = JSProxy::toObjectProxy( jsobj.imp() ); + QWidget *cw = cwproxy ? cwproxy->widget() : 0; + if ( !cw ) + return; + KMainWindow *mw = dynamic_cast<KMainWindow *>( proxy->object() ); + if ( !mw ) + return; + + mw->setCentralWidget( cw ); + +#else // QT_ONLY + Q_UNUSED( exec ); + Q_UNUSED( args ); + return; +#endif // QT_ONLY +} + +void CustomObjectImp::mainWinSetStandardToolBarMenuEnabled( KJS::ExecState *exec, + KJS::Object &, const KJS::List &args ) +{ +#ifndef QT_ONLY + + if ( args.size() != 1 ) + return; + + KMainWindow *mw = dynamic_cast<KMainWindow *>( proxy->object() ); + if ( !mw ) + return; + + mw->setStandardToolBarMenuEnabled( args[0].toBoolean(exec) ); + +#else // QT_ONLY + Q_UNUSED( exec ); + Q_UNUSED( args ); + return; +#endif // QT_ONLY +} + +void CustomObjectImp::mainWinCreateGUI( KJS::ExecState *exec, KJS::Object &, const KJS::List &args ) +{ +#ifndef QT_ONLY + kdDebug(80001) << "mainWinCreateGUI() called" << endl; + KMainWindow *mw = dynamic_cast<KMainWindow *>( proxy->object() ); + if ( !mw ) { + kdWarning() << "mainWinCreateGUI() called on non-KMainWindow" << endl; + return; + } + + mw->createGUI( extractQString( exec, args, 0 ) ); +#else // QT_ONLY + Q_UNUSED( exec ); + Q_UNUSED( args ); + return; +#endif // QT_ONLY +} + +KJS::Value CustomObjectImp::mainWinMenuBar( KJS::ExecState *exec, KJS::Object &, const KJS::List & ) +{ +#ifndef QT_ONLY + kdDebug(80001) << "mainWinMenuBar() called" << endl; + KMainWindow *mw = dynamic_cast<KMainWindow *>( proxy->object() ); + if ( !mw ) { + kdWarning() << "mainWinMenuBar() called on non-KMainWindow" << endl; + return KJS::Value(); + } + + QObject *obj = mw->menuBar(); + return proxy->part()->factory()->createProxy( exec, obj, proxy ); + +#else // QT_ONLY + Q_UNUSED( exec ); + return KJS::Value(); +#endif // QT_ONLY +} + +KJS::Value CustomObjectImp::mainWinStatusBar( KJS::ExecState *exec, KJS::Object &, const KJS::List & ) +{ +#ifndef QT_ONLY + kdDebug(80001) << "mainWinStatusBar() called" << endl; + KMainWindow *mw = dynamic_cast<KMainWindow *>( proxy->object() ); + if ( !mw ) { + kdWarning() << "mainWinStatusBar() called on non-KMainWindow" << endl; + return KJS::Value(); + } + + QObject *obj = mw->statusBar(); + return proxy->part()->factory()->createProxy( exec, obj, proxy ); + +#else // QT_ONLY + Q_UNUSED( exec ); + return KJS::Value(); +#endif // QT_ONLY +} + +KJS::Value CustomObjectImp::xmlguiClientActionCollection( KJS::ExecState *exec, KJS::Object&, const KJS::List& ) +{ +#ifndef QT_ONLY + KXMLGUIClient *gc = dynamic_cast<KXMLGUIClient *>( proxy->object() ); + if ( !gc ) { + kdDebug(80001) << "Unable to cast to XMLGUIClient" << endl; + return KJS::Value(); + } + + KActionCollection *ac = gc->actionCollection(); + if (!ac) { + kdDebug(80001) << "XMLGUIClient action collection is null" << endl; + return KJS::Null(); + } +/* JSObjectProxy *prxy = new JSObjectProxy( proxy->part(), ac ); + KJS::Object proxyObject( prxy ); + prxy->setOwner(JSProxy::Native); + prxy->addBindings( exec, proxyObject ); + return proxyObject; + */ + return proxy->part()->factory()->createProxy( exec, ac, proxy ); +#else // QT_ONLY + Q_UNUSED( exec ); + return KJS::Value(); +#endif // QT_ONLY +} + +void CustomObjectImp::tabWidgetAddTab( KJS::ExecState *exec, KJS::Object&, const KJS::List &args ) +{ + if ( args.size() < 2 ) + return; + + QTabWidget *tw = dynamic_cast<QTabWidget *>( proxy->object() ); + if ( !tw ) + return; + + KJS::Object jsobj = args[0].toObject(exec); + JSObjectProxy *tproxy = JSProxy::toObjectProxy( jsobj.imp() ); + QWidget *w = tproxy ? tproxy->widget() : 0; + if ( !w ) + return; + + tw->addTab( w, extractQString( exec, args, 0 ) ); +} + +KJS::Value CustomObjectImp::scrollViewViewport( KJS::ExecState *exec, KJS::Object&, const KJS::List &args ) +{ + QScrollView *sv = dynamic_cast<QScrollView *>( proxy->object() ); + if ( !sv ) + return KJS::Value(); + + KJS::Object jsobj = args[0].toObject(exec); + JSObjectProxy *sproxy = JSProxy::toObjectProxy( jsobj.imp() ); + QWidget *w = sproxy ? sproxy->widget() : 0; + if ( !w ) + return KJS::Value(); + + return proxy->part()->factory()->createProxy( exec, w, proxy ); +} + +void CustomObjectImp::scrollViewAddChild( KJS::ExecState *exec, KJS::Object&, const KJS::List &args ) +{ + if ( args.size() < 1 ) + return; + + QScrollView *sv = dynamic_cast<QScrollView *>( proxy->object() ); + if ( !sv ) + return; + + KJS::Object jsobj = args[0].toObject(exec); + JSObjectProxy *sproxy = JSProxy::toObjectProxy( jsobj.imp() ); + QWidget *w = sproxy ? sproxy->widget() : 0; + if ( !w ) + return; + + int x = args.size() >= 2 ? extractInt( exec, args, 1 ) : 0; + int y = args.size() >= 3 ? extractInt( exec, args, 2 ) : 0; + + sv->addChild( w, x, y ); +} + +KJS::Value CustomObjectImp::applicationExec( KJS::ExecState *, KJS::Object&, const KJS::List& ) +{ + QApplication *app = dynamic_cast<QApplication *>( proxy->object() ); + if ( !app ) + return KJS::Value(); + + return KJS::Number( app->exec() ); +} + +KJS::Value CustomObjectImp::timerIsActive( KJS::ExecState *, KJS::Object &, const KJS::List & ) +{ + QTimer *timer = dynamic_cast<QTimer *>( proxy->object() ); + if ( !timer ) + return KJS::Value(); + + return KJS::Boolean( timer->isActive() ); +} + +KJS::Value CustomObjectImp::timerStart( KJS::ExecState *exec, KJS::Object &, const KJS::List &args ) +{ + QTimer *timer = dynamic_cast<QTimer *>( proxy->object() ); + if ( !timer ) + return KJS::Value(); + + int timerid; + if ( args.size() == 1 ) + timerid = timer->start( extractInt( exec, args, 0 ) ); + else if ( args.size() == 2 ) + timerid = timer->start( extractInt( exec, args, 0 ), extractBool( exec, args, 0 ) ); + else + return KJS::Value(); + + return KJS::Number( timerid ); +} + +KJS::Value CustomObjectImp::timerStop( KJS::ExecState *, KJS::Object &, const KJS::List & ) +{ + QTimer *timer = dynamic_cast<QTimer *>( proxy->object() ); + if ( !timer ) + return KJS::Value(); + + timer->stop(); + return KJS::Value(); +} + +void CustomObjectImp::boxLayoutAddWidget( KJS::ExecState *exec, KJS::Object &, const KJS::List &args ) +{ + if ( (args.size() < 1) || (args.size() > 3) ) + return; + + QBoxLayout *box = dynamic_cast<QBoxLayout *>( proxy->object() ); + if ( !box ) + return; + + KJS::Object jsobj = args[0].toObject(exec); + JSObjectProxy *proxy = JSProxy::toObjectProxy( jsobj.imp() ); + QWidget *w = proxy ? proxy->widget() : 0; + if ( !w ) + return; + + if ( args.size() == 1 ) + box->addWidget( w ); + else if ( args.size() == 2 ) + box->addWidget( w, extractInt( exec, args, 1 ) ); + else if ( args.size() == 3 ) + box->addWidget( w, extractInt( exec, args, 1 ), extractInt( exec, args, 2 ) ); +} + +void CustomObjectImp::boxLayoutAddSpacing( KJS::ExecState *exec, KJS::Object &, const KJS::List &args ) +{ + if ( args.size() != 1 ) + return; + + QBoxLayout *box = dynamic_cast<QBoxLayout *>( proxy->object() ); + if ( !box ) + return; + + box->addSpacing( extractInt( exec, args, 0 ) ); +} + +void CustomObjectImp::boxLayoutAddStretch( KJS::ExecState *exec, KJS::Object &, const KJS::List &args ) +{ + if ( args.size() > 1 ) + return; + + QBoxLayout *box = dynamic_cast<QBoxLayout *>( proxy->object() ); + if ( !box ) + return; + + if ( args.size() == 0 ) + box->addStretch(); + else + box->addStretch( extractInt( exec, args, 0 ) ); +} + +void CustomObjectImp::boxLayoutAddLayout( KJS::ExecState *exec, KJS::Object &, const KJS::List &args ) +{ + if ( (args.size() < 1) || (args.size() > 2) ) + return; + + QBoxLayout *box = dynamic_cast<QBoxLayout *>( proxy->object() ); + if ( !box ) + return; + + KJS::Object jsobj = args[0].toObject(exec); + JSObjectProxy *proxy = JSProxy::toObjectProxy( jsobj.imp() ); + QLayout *l = proxy ? (dynamic_cast<QLayout *>(proxy->object())) : 0; + if ( !l ) + return; + + if ( args.size() == 1 ) + box->addLayout( l ); + else if ( args.size() == 2 ) + box->addLayout( l, extractInt( exec, args, 1 ) ); +} + +KJS::Value CustomObjectImp::kroPartOpenStream( KJS::ExecState *exec, KJS::Object &, const KJS::List &args ) +{ +#ifndef QT_ONLY + + if ( args.size() != 2 ) + return KJS::Boolean( false ); + + KParts::ReadOnlyPart *ro = dynamic_cast<KParts::ReadOnlyPart *>( proxy->object() ); + if ( !ro ) + return KJS::Boolean( false ); + + bool ok = ro->openStream( extractQString( exec, args, 0 ) + , KURL(extractQString( exec, args, 1 )) ); + return KJS::Boolean( ok ); + +#else // QT_ONLY + Q_UNUSED( exec ); + Q_UNUSED( args ); + return KJS::Boolean( false ); +#endif // QT_ONLY +} + +KJS::Value CustomObjectImp::kroPartWriteStream( KJS::ExecState *exec, KJS::Object &, const KJS::List &args ) +{ +#ifndef QT_ONLY + + if ( args.size() != 1 ) + return KJS::Boolean( false ); + + KParts::ReadOnlyPart *ro = dynamic_cast<KParts::ReadOnlyPart *>( proxy->object() ); + if ( !ro ) + return KJS::Boolean( false ); + + QCString s = extractQString( exec, args, 0 ).latin1(); + bool ok = ro->writeStream( s ); + return KJS::Boolean( ok ); + +#else // QT_ONLY + Q_UNUSED( exec ); + Q_UNUSED( args ); + return KJS::Boolean( false ); +#endif // QT_ONLY +} + +KJS::Value CustomObjectImp::kroPartCloseStream( KJS::ExecState *, KJS::Object &, const KJS::List &args ) +{ +#ifndef QT_ONLY + + if ( args.size() != 0 ) + return KJS::Boolean( false ); + + KParts::ReadOnlyPart *ro = dynamic_cast<KParts::ReadOnlyPart *>( proxy->object() ); + if ( !ro ) + return KJS::Boolean( false ); + + bool ok = ro->closeStream(); + return KJS::Boolean( ok ); + +#else // QT_ONLY + Q_UNUSED( args ); + return KJS::Boolean( false ); +#endif // QT_ONLY +} + +void CustomObjectImp::hboxSpacing( KJS::ExecState *exec, KJS::Object &, const KJS::List &args ) +{ + if ( args.size() != 1 ) + return; + + QHBox *box = dynamic_cast<QHBox *>( proxy->object() ); + if ( !box ) + return; + + box->setSpacing( extractInt( exec, args, 0 ) ); +} + +void CustomObjectImp::khtmlPartSelectAll( KJS::ExecState *, KJS::Object &, const KJS::List & ) +{ +#ifndef QT_ONLY + + KHTMLPart *htmlpart = dynamic_cast<KHTMLPart *>( proxy->object() ); + if ( htmlpart ) + htmlpart->selectAll(); + +#endif // QT_ONLY +} + +KJS::Value CustomObjectImp::khtmlPartHasSelection( KJS::ExecState *, KJS::Object &, const KJS::List & ) +{ +#ifndef QT_ONLY + + KHTMLPart *htmlpart = dynamic_cast<KHTMLPart *>( proxy->object() ); + if ( !htmlpart ) + return KJS::Boolean(); + + return KJS::Boolean( htmlpart->hasSelection() ); +#endif // QT_ONLY + return KJS::Null(); +} + +KJS::Value CustomObjectImp::khtmlPartSelectedText( KJS::ExecState *, KJS::Object &, const KJS::List & ) +{ +#ifndef QT_ONLY + + KHTMLPart *htmlpart = dynamic_cast<KHTMLPart *>( proxy->object() ); + if ( !htmlpart ) + return KJS::String(); + + return KJS::String( htmlpart->selectedText() ); +#endif // QT_ONLY +return KJS::Null(); +} + +KJS::Value CustomObjectImp::ksystemtrayContextMenu( KJS::ExecState *exec, KJS::Object&, const KJS::List & ) +{ +#ifndef QT_ONLY + KSystemTray *st = dynamic_cast<KSystemTray *>( proxy->widget() ); + if ( !st ) + { + kdWarning() << "Not a KSystemTray" << endl; + return KJS::Boolean(false); + } + kdDebug() << "Valid system tray?" << endl; + KPopupMenu *pop = st->contextMenu(); + return proxy->part()->factory()->createProxy( exec, pop, proxy ); +#endif // QT_ONLY +return KJS::Null(); +} + +KJS::Value CustomObjectImp::ksystemtrayActionCollection( KJS::ExecState *exec, KJS::Object&, const KJS::List & ) +{ +#ifndef QT_ONLY + KSystemTray *st = dynamic_cast<KSystemTray *>( proxy->object() ); + if ( !st ) + return KJS::Value(); + + KActionCollection *ac = st->actionCollection(); + return proxy->part()->factory()->createProxy( exec, ac, proxy ); +#endif // QT_ONLY +return KJS::Null(); +} + +KJS::Value CustomObjectImp::ksystemtrayLoadIcon( KJS::ExecState *exec, KJS::Object&, const KJS::List &args ) +{ +#ifndef QT_ONLY + // TODO: Support the 2 arg form of KSystemTray::loadIcon() when we support KInstance args + if ( args.size() != 1 ) + return KJS::Value(); + + QVariant pix( KSystemTray::loadIcon( extractQString( exec, args, 0 ) ) ); + return convertToValue( exec, pix ); +#endif // QT_ONLY +return KJS::Null(); +} + +KJS::Value CustomObjectImp::qcanvasViewCanvas( KJS::ExecState *exec, KJS::Object&, const KJS::List &args ) +{ + QCanvasView *cv = dynamic_cast<QCanvasView *>( proxy->object() ); + if ( !cv ) + return KJS::Value(); + + return proxy->part()->factory()->createProxy( exec, cv->canvas(), proxy ); +} + +void CustomObjectImp::qcanvasViewSetCanvas( KJS::ExecState *exec, KJS::Object&, const KJS::List &args ) +{ + QCanvasView *cv = dynamic_cast<QCanvasView *>( proxy->object() ); + if ( !cv ) + return; + + KJS::Object jsobj = args[0].toObject(exec); + JSObjectProxy *proxy = JSProxy::toObjectProxy( jsobj.imp() ); + + QObject *obj = proxy->object(); + if ( !obj ) + return; + + QCanvas *c = (QCanvas *) obj; + cv->setCanvas(c); +} +KJS::Value Bindings::CustomObjectImp::qlistViewTakeItem( KJS::ExecState * exec, KJS::Object &, const KJS::List &args ) +{ + QListView *lv = dynamic_cast<QListView *>( proxy->object() ); + if( !lv ) + return KJS::Boolean(false); + KJS::Object lviObj = args[0].toObject(exec); + JSOpaqueProxy *prxy = JSProxy::toOpaqueProxy(lviObj.imp() ); + QListViewItem *itm = prxy->toNative<QListViewItem>(); + if( !itm ) + { + // Trow an error... + return KJS::Boolean(false); + } + lv->takeItem(itm); + return KJS::Boolean(true); +} + +KJS::Value Bindings::CustomObjectImp::qlistViewFirstChild( KJS::ExecState * exec, KJS::Object &, const KJS::List &args ) +{ + QListView *lv = dynamic_cast<QListView *>( proxy->object() ); + if( !lv ) + return KJS::Boolean(false); + QListViewItem *itm = lv->firstChild(); + KJS::Object jsObject( new JSOpaqueProxy( itm, "QListViewItem") ); + proxy->part()->factory()->extendOpaqueProxy(exec, jsObject); + return jsObject; +} + +KJS::Value Bindings::CustomObjectImp::qlistViewCurrentItem( KJS::ExecState * exec, KJS::Object &, const KJS::List &args ) +{ + QListView *lv = dynamic_cast<QListView *>( proxy->object() ); + if( !lv ) + return KJS::Boolean(false); + QListViewItem *itm = lv->currentItem(); + KJS::Object jsObject( new JSOpaqueProxy( itm, "QListViewItem") ); + proxy->part()->factory()->extendOpaqueProxy(exec, jsObject); + return jsObject; +} + +KJS::Value Bindings::CustomObjectImp::qtoolBoxAddItem(KJS::ExecState *exec, KJS::Object &, const KJS::List &args) +{ + QToolBox *tb = dynamic_cast<QToolBox *>( proxy->object() ); + if( !tb ) + return KJS::Boolean(false); + if( args.size() == 2) + { + QWidget *w = extractQWidget( exec, args, 0 ); + QString lab = extractQString( exec, args, 1 ); + return KJS::Number( tb->addItem(w,lab) ); + } + if( args.size() == 3) + { + QWidget *w = extractQWidget( exec, args, 0 ); + QIconSet ico = extractQPixmap( exec, args, 1 ); + QString lab = extractQString( exec, args, 2 ); + return KJS::Number( tb->addItem(w,ico,lab) ); + } + return KJS::Boolean(false); +} + +KJS::Value Bindings::CustomObjectImp::qtoolBoxInsertItem(KJS::ExecState *exec, KJS::Object &, const KJS::List &args ) +{ + QToolBox *tb = dynamic_cast<QToolBox *>( proxy->object() ); + if( !tb ) + return KJS::Boolean(false); + if( args.size() == 3) + { + int idx = extractInt(exec, args, 0); + QWidget *w = extractQWidget( exec, args, 1 ); + QString lab = extractQString( exec, args, 2 ); + return KJS::Number( tb->insertItem(idx,w,lab) ); + } + if( args.size() == 4) + { + int idx = extractInt(exec, args, 0); + QWidget *w = extractQWidget( exec, args, 1 ); + QIconSet ico = extractQPixmap( exec, args, 2 ); + QString lab = extractQString( exec, args, 3 ); + return KJS::Number( tb->insertItem(idx,w,ico,lab) ); + } + return KJS::Boolean(false); +} + +void Bindings::CustomObjectImp::qtoolBoxRemoveItem(KJS::ExecState *exec, KJS::Object &, const KJS::List &args ) +{ + QToolBox *tb = dynamic_cast<QToolBox *>( proxy->object() ); + if( !tb ) + return; + QWidget *w = extractQWidget(exec, args, 0); + tb->removeItem(w); +} + +KJS::Value Bindings::CustomObjectImp::qtoolBoxItemLabel(KJS::ExecState *exec, KJS::Object &, const KJS::List &args ) +{ + QToolBox *tb = dynamic_cast<QToolBox *>( proxy->object() ); + if( !tb ) + return KJS::Boolean(false); + int idx = extractInt(exec, args, 0); + return KJS::String(tb->itemLabel(idx).latin1()); +} + +void Bindings::CustomObjectImp::qtoolBoxSetItemLabel(KJS::ExecState *exec, KJS::Object &, const KJS::List &args ) +{ + QToolBox *tb = dynamic_cast<QToolBox *>( proxy->object() ); + if( !tb ) + return; + + int idx = extractInt(exec, args, 0); + QString lab = extractQString( exec, args, 1 ); + tb->setItemLabel(idx,lab); +} + +KJS::Value Bindings::CustomObjectImp::qtoolBoxItemIconSet(KJS::ExecState *exec, KJS::Object &, const KJS::List &args ) +{ + QToolBox *tb = dynamic_cast<QToolBox *>( proxy->object() ); + if( !tb ) + return KJS::Boolean(false); + int idx = extractInt(exec, args, 0); + QPixmap pix = tb->itemIconSet(idx).pixmap(); + return convertToValue( exec, pix ); + +} + +void Bindings::CustomObjectImp::qtoolBoxSetItemIconSet(KJS::ExecState *exec, KJS::Object &, const KJS::List &args) +{ + QToolBox *tb = dynamic_cast<QToolBox *>( proxy->object() ); + if( !tb ) + return; + int idx = extractInt(exec, args, 0); + QIconSet ico = extractQPixmap( exec, args, 1); + tb->setItemIconSet(idx,ico); +} + +KJS::Value Bindings::CustomObjectImp::qtoolBoxItem(KJS::ExecState *exec, KJS::Object &, const KJS::List &args ) +{ + QToolBox *tb = dynamic_cast<QToolBox *>( proxy->object() ); + if( !tb ) + return KJS::Boolean(false); + int idx = extractInt(exec, args, 0); + return proxy->part()->factory()->createProxy( exec, tb->item(idx), proxy ); +} +QPopupMenu *getMenu(const KJS::Object &obj) +{ + JSObjectProxy *jsproxy = JSProxy::toObjectProxy( obj.imp() ); + return dynamic_cast<QPopupMenu *>( jsproxy->object() ); +} + +KJS::Value Bindings::CustomObjectImp::qmenuDataInsertItem(KJS::ExecState *exec, KJS::Object &, const KJS::List &args ) +{ + QMenuData *menu = dynamic_cast<QMenuData *>( proxy->object() ); + if( !menu ) + return KJS::Boolean(false); + int offset = 0; + + QString text = extractQString(exec,args, offset); + QPixmap pix = extractQPixmap(exec,args, offset); + int id = -1; + int idx = -1; + int newIndex = 0; + QPopupMenu *parentMenu = 0; + + if( !pix.isNull() ) + { + ++offset; + if( args.size() > offset) + text = extractQString(exec,args,offset); + } + kdDebug() << "text " << text << " " << offset << endl; + + ++offset; + if( args.size() > offset) + parentMenu = getMenu(args[offset].toObject(exec)); + + if( parentMenu ) + ++offset; + kdDebug() << "text " << text << " " << offset << endl; + + if( args.size() > offset ) + id = extractInt(exec, args, offset); + ++offset; + kdDebug() << "text " << text << " " << offset << endl; + + if( args.size() > offset ) + idx = extractInt(exec, args, offset); + + kdDebug() << "text " << text << " " << offset << endl; + + if( parentMenu ) + { + if( pix.isNull() ) + { + newIndex = menu->insertItem(text, parentMenu, id, idx); // text, parent, id, idx + } + else + { + if( text.isEmpty() ) + newIndex = menu->insertItem(pix, parentMenu, id, idx); // pixmap, parent, id, idx + else + newIndex = menu->insertItem(pix, text, parentMenu, id, idx); // pixmap, text, parent, id, idx + } + } + else + { + if( pix.isNull() ) + { + newIndex = menu->insertItem(text, id, idx); // text, id, idx + } + else + { + if( text.isEmpty() ) + newIndex = menu->insertItem(pix, id, idx); // pixmap, id, idx + else + newIndex = menu->insertItem(pix, text, id, idx); // pixmap, text, id, idx + } + } + + return KJS::Number(newIndex); +} + +void Bindings::CustomObjectImp::qmenuDataRemoveItem(KJS::ExecState *exec, KJS::Object &, const KJS::List &args ) +{ + QMenuData *menu = dynamic_cast<QMenuData *>( proxy->object() ); + if( !menu ) + return; + int idx = extractInt(exec, args, 0); + menu->removeItem(idx); +} + +KJS::Value Bindings::CustomObjectImp::qmenuDataInsertSeparator(KJS::ExecState *exec, KJS::Object &, const KJS::List &args ) +{ + QMenuData *menu = dynamic_cast<QMenuData *>( proxy->object() ); + if( !menu ) + return KJS::Boolean(false); + int idx = extractInt(exec, args, 0); + return KJS::Number( menu->insertSeparator(idx) ); +} + +} // namespace KJSEmbed::Bindings +}// namespace KJSEmbed + +// Local Variables: +// c-basic-offset: 4 +// End: + diff --git a/kjsembed/customobject_imp.h b/kjsembed/customobject_imp.h new file mode 100644 index 00000000..553e55b9 --- /dev/null +++ b/kjsembed/customobject_imp.h @@ -0,0 +1,224 @@ +// -*- c++ -*- + +/* + * Copyright (C) 2001-2004, Richard J. Moore <rich@kde.org> + * + * This 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. + * + * This 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 this library; see the file COPYING.LIB. If not, write to + * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, + * Boston, MA 02110-1301, USA. + */ + +#ifndef KJSEMBEDCUSTOMOBJECTIMP_H +#define KJSEMBEDCUSTOMOBJECTIMP_H + +#include <kjs/object.h> +#include <kjsembed/jsbinding.h> +#include <kjsembed/slotutils.h> + +#include <kjsembed/jsobjectproxy_imp.h> + +class QObject; + +namespace KJSEmbed { +namespace Bindings { + +/** + * Implements the JS methods of custom object bindings. + * + * @author Richard Moore, rich@kde.org + * @version $Id$ + */ +class KJSEMBED_EXPORT CustomObjectImp : public JSProxyImp +{ +public: + /** Identifiers for the methods provided by this class. */ + enum MethodId { + WidgetGrabWidget, + WidgetDrawLine, + WidgetDrawText, + + ListBoxInsertItem, + ListBoxRemoveItem, + + ListViewAddColumn, + ListViewInsertItem, + ListViewSelectedItem, + ListViewHideColumn, + ListViewTakeItem, + ListViewFirstChild, + ListViewCurrentItem, + + + MainWindowSetCentralWidget, + MainWindowCreateGUI, + MainWindowMenuBar, + MainWindowStatusBar, + MainWindowSetStandardToolBarMenuEnabled, + + TabWidgetAddTab, + + ScrollViewViewport, + ScrollViewAddChild, + + ApplicationExec, + + TimerIsActive, + TimerStart, + TimerStop, + + BoxLayoutAddWidget, + BoxLayoutAddSpacing, + BoxLayoutAddStretch, + BoxLayoutAddLayout, + + URLRequesterSetMode, + URLRequesterSetFilter, + URLRequesterUrl, + URLRequesterSetLocalProtocol, + URLRequesterLocalProtocol, + + KXMLGUIClientActionCollection, + + KReadOnlyPartOpenStream, + KReadOnlyPartWriteStream, + KReadOnlyPartCloseStream, + + HBoxSpacing, + + KHTMLPartSelectAll, + KHTMLPartHasSelection, + KHTMLPartSelectedText, + + KSystemTrayContextMenu, + KSystemTrayActionCollection, + KSystemTrayLoadIcon, + + QCanvasViewCanvas, + QCanvasViewSetCanvas, + + QSplashScreenSetPixmap, + QSplashScreenPixmap, + QSplashScreenFinish, + QSplashScreenRepaint, + + QToolBoxAddItem, + QToolBoxInsertItem, + QToolBoxRemoveItem, + QToolBoxItemLabel, + QToolBoxSetItemLabel, + QToolBoxItemIconSet, + QToolBoxSetItemIconSet, + QToolBoxItem, + + QMenuDataInsertItem, + QMenuDataRemoveItem, + QMenuDataInsertSeparator + }; + + static void addBindings( KJS::ExecState *exec, KJS::Object &object ); + + CustomObjectImp( KJS::ExecState *exec, int id, JSObjectProxy *parent ); + virtual ~CustomObjectImp() {} + + KJS::Value widgetGrabWidget(KJS::ExecState *exec, KJS::Object &, const KJS::List &args ); + void widgetDrawLine( KJS::ExecState *exec, KJS::Object &, const KJS::List &args ); + void widgetDrawText( KJS::ExecState *exec, KJS::Object &, const KJS::List &args ); + + void listBoxInsertItem( KJS::ExecState *exec, KJS::Object &, const KJS::List &args ); + + void listViewAddColumn( KJS::ExecState *exec, KJS::Object &, const KJS::List &args ); + void listViewInsertItem( KJS::ExecState *exec, KJS::Object &, const KJS::List &args ); + KJS::Value listViewSelectedItem( KJS::ExecState *exec, KJS::Object &, const KJS::List & ); + void listViewHideColumn( KJS::ExecState *exec, KJS::Object &, const KJS::List &args ); + + void mainWinSetCentralWidget( KJS::ExecState *exec, KJS::Object &, const KJS::List &args ); + void mainWinCreateGUI( KJS::ExecState *exec, KJS::Object &, const KJS::List &args ); + KJS::Value mainWinMenuBar( KJS::ExecState *exec, KJS::Object &, const KJS::List &args ); + KJS::Value mainWinStatusBar( KJS::ExecState *exec, KJS::Object &, const KJS::List &args ); + void mainWinSetStandardToolBarMenuEnabled( KJS::ExecState *exec, KJS::Object &, const KJS::List &args ); + + void tabWidgetAddTab( KJS::ExecState *exec, KJS::Object&, const KJS::List &args ); + + KJS::Value scrollViewViewport( KJS::ExecState *exec, KJS::Object&, const KJS::List &args ); + void scrollViewAddChild( KJS::ExecState *exec, KJS::Object&, const KJS::List &args ); + + KJS::Value applicationExec( KJS::ExecState *exec, KJS::Object &, const KJS::List &args ); + + KJS::Value timerIsActive( KJS::ExecState *exec, KJS::Object &, const KJS::List &args ); + KJS::Value timerStart( KJS::ExecState *exec, KJS::Object &, const KJS::List &args ); + KJS::Value timerStop( KJS::ExecState *exec, KJS::Object &, const KJS::List &args ); + + void boxLayoutAddWidget( KJS::ExecState *exec, KJS::Object &, const KJS::List &args ); + void boxLayoutAddSpacing( KJS::ExecState *exec, KJS::Object &, const KJS::List &args ); + void boxLayoutAddStretch( KJS::ExecState *exec, KJS::Object &, const KJS::List &args ); + void boxLayoutAddLayout( KJS::ExecState *exec, KJS::Object &, const KJS::List &args ); + + KJS::Value xmlguiClientActionCollection( KJS::ExecState *exec, KJS::Object &, const KJS::List &args ); + + KJS::Value kroPartOpenStream( KJS::ExecState *exec, KJS::Object &, const KJS::List &args ); + KJS::Value kroPartWriteStream( KJS::ExecState *exec, KJS::Object &, const KJS::List &args ); + KJS::Value kroPartCloseStream( KJS::ExecState *exec, KJS::Object &, const KJS::List &args ); + + void hboxSpacing( KJS::ExecState *exec, KJS::Object &, const KJS::List &args ); + + void khtmlPartSelectAll( KJS::ExecState *, KJS::Object &, const KJS::List & ); + KJS::Value khtmlPartHasSelection( KJS::ExecState *, KJS::Object &, const KJS::List & ); + KJS::Value khtmlPartSelectedText( KJS::ExecState *, KJS::Object &, const KJS::List &args ); + + KJS::Value ksystemtrayContextMenu( KJS::ExecState *exec, KJS::Object&, const KJS::List &args ); + KJS::Value ksystemtrayActionCollection( KJS::ExecState *exec, KJS::Object&, const KJS::List &args ); + KJS::Value ksystemtrayLoadIcon( KJS::ExecState *exec, KJS::Object&, const KJS::List &args ); + + KJS::Value qcanvasViewCanvas( KJS::ExecState *exec, KJS::Object&, const KJS::List &args ); + void qcanvasViewSetCanvas( KJS::ExecState *exec, KJS::Object&, const KJS::List &args ); + + KJS::Value qsplashScreenSetPixmap(KJS::ExecState *exec, KJS::Object &, const KJS::List & ); + KJS::Value qsplashScreenPixmap(KJS::ExecState *exec, KJS::Object &, const KJS::List & ); + KJS::Value qsplashScreenFinish(KJS::ExecState *exec, KJS::Object &, const KJS::List & ); + KJS::Value qsplashScreenRepaint(KJS::ExecState *exec, KJS::Object &, const KJS::List & ); + + KJS::Value qlistViewTakeItem(KJS::ExecState *exec, KJS::Object &, const KJS::List & ); + KJS::Value qlistViewFirstChild(KJS::ExecState *exec, KJS::Object &, const KJS::List & ); + KJS::Value qlistViewCurrentItem(KJS::ExecState *exec, KJS::Object &, const KJS::List & ); + + KJS::Value qtoolBoxAddItem(KJS::ExecState *exec, KJS::Object &, const KJS::List & ); + KJS::Value qtoolBoxInsertItem(KJS::ExecState *exec, KJS::Object &, const KJS::List & ); + void qtoolBoxRemoveItem(KJS::ExecState *exec, KJS::Object &, const KJS::List & ); + KJS::Value qtoolBoxItemLabel(KJS::ExecState *exec, KJS::Object &, const KJS::List & ); + void qtoolBoxSetItemLabel(KJS::ExecState *exec, KJS::Object &, const KJS::List & ); + KJS::Value qtoolBoxItemIconSet(KJS::ExecState *exec, KJS::Object &, const KJS::List & ); + void qtoolBoxSetItemIconSet(KJS::ExecState *exec, KJS::Object &, const KJS::List & ); + KJS::Value qtoolBoxItem(KJS::ExecState *exec, KJS::Object &, const KJS::List & ); + + KJS::Value qmenuDataInsertItem(KJS::ExecState *exec, KJS::Object &, const KJS::List & ); + void qmenuDataRemoveItem(KJS::ExecState *exec, KJS::Object &, const KJS::List & ); + KJS::Value qmenuDataInsertSeparator(KJS::ExecState *exec, KJS::Object &, const KJS::List & ); + + virtual bool implementsCall() const { return true; } + virtual KJS::Value call( KJS::ExecState *exec, KJS::Object &self, const KJS::List &args ); + +private: + int id; + JSObjectProxy *proxy; + class CustomObjectImpPrivate *d; +}; + +} // namespace KJSEmbed::Bindings +} // namespace KJSEmbed + +#endif // KJSEMBEDCUSTOMOBJECTIMP_H + +// Local Variables: +// c-basic-offset: 4 +// End: diff --git a/kjsembed/design.h b/kjsembed/design.h new file mode 100644 index 00000000..d255aeef --- /dev/null +++ b/kjsembed/design.h @@ -0,0 +1,183 @@ +/* + * Copyright (C) 2002-2004, Richard J. Moore <rich@kde.org> + * + * This 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. + * + * This 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 this library; see the file COPYING.LIB. If not, write to + * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, + * Boston, MA 02110-1301, USA. + */ + +/** + * @mainpage Framework for embedding the KJS Javascript Interpreter + * + * @section intro Introduction + * + * The KJSEmbed library provides a framework that makes it easy for + * applications to embed KJS, the KDE JavaScript interpreter. The + * facilities available include a JS console widget, a dialog loader + * and a binding between JS and the properties and slots of QObjects. + * + * @section classes Important Classes + * + * The most important classes to consider are: + * + * @ref KJSEmbed::KJSEmbedPart : + * Main API for KJSEmbed. + * + * @ref KJSEmbed::JSConsoleWidget : + * A widget that provides an interactive JS console. + * + * @ref KJSEmbed::JSObjectProxy : + * A Javascript object that can access the properties of a QObject, + * + * @ref KJSEmbed::SecurityPolicy : + * Defines a security policy for @ref JSObjectProxy. + * + * @section basic Basic Usage + * + * The simplest way to use KJSEmbed is by simply creating a Javascript + * console widget. The console allows the user to enter and run arbitrary + * Javascript expressions. + * <pre> + * KJSEmbed::JSConsoleWidget *win = new KJSEmbed::JSConsoleWidget(); + * win->show(); + * </pre> + * The embedding application can run scripts in the console using the + * execute() method. + * + * The best way to use KJSEmbed is keep control of the interpreter + * yourself using the KJSEmbedPart, this way you can make parts of your + * application available to scripts. The following example creates its + * own interpreter then binds it to the console: + * <pre> + * KJSEmbed::KJSEmbedPart *js = new KJSEmbed::KJSEmbedPart(); + * KJSEmbed::JSConsoleWidget *console = js->view(); + * </pre> + * + * @section proxy Publishing QObjects + * + * KJSEmbed allows applications to make arbitrary QObjects visible to a + * Javascript interpreter. The binding itself is provided by the @ref JSProxyObject + * class, but is more easily used via the addObject(...) methods of @ref KJSEmbedPart. + * + * The following code shows how easy it is to make an object available for + * scripting. It creates a QVBox containing two QLabels then makes them visible + * to KJSEmbed: + * <pre> + * QVBox *toplevel = new QVBox( 0, "box" ); + * QLabel *title = new QLabel( "Some Title", toplevel, "title"); + * QLabel *main = new QLabel( "Some text, more text.", toplevel, "main" ); + * + * js->addObject( title ); + * js->addObject( main, "text" ); + * </pre> + * + * Publishing an object makes it possibile for scripts to access both the + * properties and slots as if it was a normal Javascript object. The code + * above allows scripts read-write access to the label properties as this + * script illustrates: + * <pre> + * title.text = "World" + * title.text = "Hello " + title.text + * </pre> + * The script above would set the text of the label to 'Hello World'. + * + * The slots of a QObject bound to the interpreter are made available to + * scripts as if they normal methods. In the example above, we could conceal + * the label 'main' entirely by calling its hide() slot: + * <pre> + * main.hide() + * </pre> + * + * @section tree Access To the QObject Tree + * + * As well as providing script access to an individual widget, KJSEmbed + * allows scripts to walk the object tree and access others. If we + * modified the previous example to publish the QBox widget 'toplevel' as + * follows: + * <pre> + * js->addObject( toplevel, "window" ); + * </pre> + * Then, despite the fact we've only explicitly published a single widget, + * we've also provided access to both 'main' and 'title'. The ability + * to navigate the object tree is limited by the SecurityPolicy, the default + * policy only allows scripts access to children of the published object. + * + * To achieve the same result as before, we could use script like this: + * <pre> + * window.child("main").text = "World" + * window.child("main").text = "Hello " + window.child("main").text + * </pre> + * The result of this script is identical to the previous example. + * + * @section examples Some KJSEmbed examples + * @subsection embedjs Example of embedding KJSEmbed into an application. + * @image html embedjs.png + * This is an example of how to embed and interface with KJSEmbed. This + * example covers: + * @li embedding the kpart. + * @li publishing the interface. + * @li calling javascript members. + * @li handling javascript objects returned by these members. + * @li embedding the KJSEmbed console. + * @dontinclude embedviewimp.cpp + * To embed the interpreter we can just create a new KJSEmbed part. + * @skipline m_part + * To publish the objects we can then call @ref KJSEmbed::KJSEmbedPart::addObject on our part. + * This will then add any QObject based class the the global scope of the + * javascript interperter. + * @skipline addObject + * Once you have your objects published you can then execute javascript code from a file. + * @skipline runFile + * @dontinclude embedviewimp.cpp + * When the script is running javascript methods can be accessed by calling the + * @ref KJSEmbed::KJSEmbedPart::callMethod method. + * @skipline args + * @until callMethod + * Any arguments that you wish to pass into the javascript method are contained in the + * @ref KJS::List. This is just a list of @ref KJS::Value objects and can be created from + * QVariants or from custom @ref KJS::Object based classes. + * Once you have the data back from the method you can convert it easily from the @ref KJS::Value + * type to a QVariant with the @ref KJSEmbed::convertToVariant method. + * @line personalData + * @until notes: + * Complex arrays or @ref KJS::Objects are transparently converted to QVariant::Map types so + * they can easily be manipulated from C++. + * The KJSEmbed::console is also easy to add to applications. An example of a method that + * will toggle the console is below. + * @skipline consoleClicked + * @until } + * + * @subsection embedjs Example of Using Qt Designer files in KJSEmbed. + * @image html jscalc.png + * This is a very simple example that shows off how to use Qt widget files + * and connect the objects to javascript functions. + * @dontinclude calc.js + * To load the Qt Designer user interface file and publish the objects in the XML file + * the KJSEmbed Factory class has a UI loader. + * @skipline Factory.loadui + * Once the file is loaded the user interface object can then be manipulated by javascript. + * @line new Calculator + * @until application.exec + * It is important to note that before the javascript will support connecting signals and slots + * the application.exec() method must be called. + * + * Connecting the user interface to javascript methods is similar C++ in that you create + * a method and then use the connect(...) method to connect the signal to the method. + * @dontinclude calc.js + * @skipline function + * @until display + * @skipline this.clear + * @skipline clear + * @skipline } + */ diff --git a/kjsembed/docs/ChangeLog b/kjsembed/docs/ChangeLog new file mode 100644 index 00000000..95cedca2 --- /dev/null +++ b/kjsembed/docs/ChangeLog @@ -0,0 +1,4243 @@ +2004-12-11 Saturday 09:01 geiseri + + Added two examples to the Doxygen documentation. + +2004-12-11 Saturday 07:27 geiseri + + Updated Doxyfile. + +2004-12-11 Saturday 07:22 geiseri + + Added method throwError(...). + This method will take an error message and a type and throw a + complete exception with an error object. This object has the + following properties that can be accessed: + line - the line number the exception happened at. + sourceid - the source fragment the exception happened in. + message - the actual error message. + name - the error type. + + This object can be accessed in both javascript and C++, and + will be returned as the completion object when there is an + exception in an executed script. + + Moved all errors in the code to throwError() + +2004-12-11 Saturday 07:15 geiseri + + Use extractQObject here because it is safer. + +2004-12-11 Saturday 07:15 geiseri + + Added home directory path, current path, and application directory path. + +2004-12-11 Saturday 07:12 geiseri + + Added more verbose documentation on how to use the part interface. + +2004-12-11 Saturday 07:11 geiseri + + documentation cleanup + +2004-12-11 Saturday 02:25 geiseri + + Actually return the line number that the error happened. + +2004-12-10 Friday 13:12 geiseri + + Things that are created via the widgetFactory should be owned in + javascript. So when the parent is destroyed so will the children. + +2004-12-10 Friday 13:10 geiseri + + Make sure the KActionCollection is native, it seems that + it has no parent so the GC will happily collect it. + +2004-12-10 Friday 13:09 geiseri + + Added registration of more proxies. + +2004-12-10 Friday 13:07 geiseri + + Small code cleanup. + +2004-12-10 Friday 13:03 geiseri + + remove some debug information + +2004-12-10 Friday 13:01 geiseri + + Added some debugging info for object ownership. + Moved the typeName to a pure virtual here. We already + broke BC here, and this method is in every child class. + +2004-12-10 Friday 12:59 geiseri + + Implemented better QVariant to JSObject mappings. The big change here + that Javascript arrays and Javascript objects can be mapped to QVariants + in C++. Conversions break down as follows: + QStringList -> Array of javascript strings. + QValueList<QVariant> -> Array of Javascript values. + QMap<QString,QVariant> -> Object/Array that has each QString key as + a property, and the QVariant is mapped to a Javascript value. + + From Javascript the conversions are a little different. + All arrays that have a numeric index will be converted to + QValueList<QVariant> QVariants. These can be mapped to both + QStringList and to normal QValueList. An example would be like this: + KJS::Value someArrayValue; + QStringList strLst = convertToVariant(exec, someArrayValue).toStringList(); + QValueList<QVariant> varLst + = convertToVariant( exec, someArrayValue).toList(); + + Now if the Javascript value is a Javascript object or a map then + the conversion will go to a QMap<QString,QVariant>. An example of + this would be like: + KJS::Value someJSObject; + QMap<QString,QVariant> map = convertToVariant(exec,someJSObject) + .toMap(); + QString someVal = map["someProp"].toString(); + + This is done via some testing of the array and you can trip + it up in some cases: + 1) If the object is empty, or null will return an empty QMap + 2) If the object is an array that has the last element null + then a QMap will be returned. + + The first case is not much of an issue because an empty variant + is the same for all types, but the second case can cause + unexpected results. + + In cases of sparse arrays the empty values will be filled in + with empty QVariants in the QValueList. + +2004-12-10 Friday 12:42 geiseri + + Changed the example to actually show off using KJSEmbed. + Example shows the following: + 1) Embedding KJSEmbed. + 2) Calling Javascript methods from C++. + 3) Transparent mapping of custom javascript objects into QVariant maps. + 4) Adding widgets to a C++ based form from Javascript. + 5) Execution of a script from outside of the main application. + +2004-12-09 Thursday 23:55 geiseri + + removed generated docs from cvs + +2004-12-09 Thursday 15:09 geiseri + + torture test for QFrame, still fails. + +2004-12-09 Thursday 15:07 geiseri + + more complete test for arrays + +2004-12-08 Wednesday 11:15 geiseri + + Added a QVariant slot so C++ bindings can easier get more + complex data types into the bindings. + +2004-12-08 Wednesday 11:12 geiseri + + Fixed some logic errors. + Throw exceptions with meaningful errors. + +2004-12-08 Wednesday 11:12 geiseri + + Removed debug information that was screwing with QVariants. + +2004-12-07 Tuesday 20:10 staikos + + compile + +2004-12-07 Tuesday 12:02 geiseri + + do not delete a QWidget if you are painting on it, its rude + +2004-12-07 Tuesday 12:01 geiseri + + fix name of include + +2004-12-06 Monday 14:08 geiseri + + Moved to new bindings extension class. + +2004-12-06 Monday 14:07 geiseri + + With new API QListViewItem objects now iterate properly. + + QListView::firstChild() and QListView::currentSelection now work. + QListViewItems can now iterate property. + + The test now shows how to use these methods. + + +2004-12-06 Monday 14:04 geiseri + + Moved registered bindings to their own baseclass. This API is not stable + so it is subject to change. More documentation on this will follow once + it is more solid. + +2004-12-06 Monday 13:34 geiseri + + Removed autogenerated docs, since the scripts now work to generate them + property on Qt only and KDE mode. + +2004-12-05 Sunday 19:54 geiseri + + Moved QListViewItem and QCheckListItem to the object registry. + +2004-12-05 Sunday 19:11 geiseri + + Moved bindings to the new object registry. + + The new object registry allows developers to add custom types + to KJSEmbed when they embed the interpreter into their applications. + + To add a binding you create the binding as binding plugin, but instead + of using the KTrader to register the plugin, you call + JSFactory::registerOpaqueType("Name", new TypeFactory(parent,"name"); + + Now KJS can create your type and manipulate it. This currently supports + only opaque types, QObject types are next once this migration is + complete. + +2004-12-05 Sunday 19:08 geiseri + + Throw errors on type mismatches. This causes scripts to + actually give errors where they happen vs at some random + later point. + +2004-12-05 Sunday 10:12 geiseri + + Test for QFrame + +2004-12-04 Saturday 17:57 geiseri + + Do not delete the internal dcop client pointer, it is considered rude. + +2004-12-04 Saturday 14:25 geiseri + + Added QProgressDialog to the list of creatable types. + +2004-12-04 Saturday 02:34 geiseri + + QT_NO_ASCII_CAST build fix. + +2004-12-04 Saturday 02:25 geiseri + + Gave the KJSEmbed documentation viewer a facelift. + Runs in Qt only and KDE mode just fine. + Search is not implemented, but most browser features are. + Maybe we need to fix up the dump() output and make it + follow the current KDE color styles? + +2004-12-04 Saturday 01:33 geiseri + + Add QToolBox items to the published children when comming from QWidgetFactory + +2004-12-03 Friday 21:28 geiseri + + Small cleanup. + +2004-12-03 Friday 21:27 geiseri + + Add config to Qt only. + +2004-12-03 Friday 21:27 geiseri + + dont delete the builting kapplication ptr. + +2004-12-03 Friday 21:25 geiseri + + code cleanup. + +2004-12-03 Friday 20:07 geiseri + + These are no longer needed. + +2004-12-03 Friday 20:06 geiseri + + Added createObject method. + +2004-12-03 Friday 20:06 geiseri + + logic fix + +2004-12-03 Friday 20:05 geiseri + + Do not delete QObjects that are managed by their parents. + +2004-12-03 Friday 20:04 geiseri + + Added Factory.createObject(classname,args,...) for those coming + from windows land. + +2004-12-03 Friday 20:01 geiseri + + Do not manage QListView, and ListBox items as the containers will. + Had to wash this file over with AStyle, it was getting to be a mess. + +2004-12-02 Thursday 22:15 geiseri + + note start position + +2004-12-02 Thursday 21:50 geiseri + + Added QRect::contains(...) to Rect class. + Updated game board to detect objects getting in the target. + +2004-12-01 Wednesday 14:45 geiseri + + make 10 items, use QFrame for formatting. + +2004-12-01 Wednesday 11:25 geiseri + + added a small gameboard example + +2004-12-01 Wednesday 09:58 geiseri + + Added tests for QSize, QPoint and QRect. + +2004-12-01 Wednesday 09:58 geiseri + + Added support for: + QPoint + QRect + QSize + + Cleanup headers in QPen + + These are all handled as value proxies so they are transparently supported + in slots, QObject bindings, and dcop. These can be used by their variant + names of Point, Rect and Size respectivly. Also constructors are provided + for Point, Rect and Size so you can construct items in one step + ex: + var point = new Point(x,y); + var size = new Size(w,h); + var rect = new Rect(x,y,w,h); + +2004-12-01 Wednesday 09:54 geiseri + + Throw an exception on a handler error so the user can figure out what went wrong. + +2004-12-01 Wednesday 09:54 geiseri + + Added drag and drop event handlers. + +2004-11-30 Tuesday 17:47 geiseri + + test kconfig more robustly. + +2004-11-30 Tuesday 12:02 geiseri + + Fixed issue where config files where not reading and writing properly + When the default args where removed they would pass invalid items to + the KConfig methods. This would basicly cause the methods to fail + in strange and entertaining ways. Since the methods with default + args had the default args ignored before this really changes nothing + on the public API. This will someday change to an opaque proxy + though and those args will work. + +2004-11-30 Tuesday 12:00 geiseri + + save the max input from the dialog + +2004-11-30 Tuesday 10:45 geiseri + + Added support for passing QStringList through slots. This fixed the problems with KConfig bindings not showing up. It should also fix the problem of not being able to pass StringLists to C++ slots that have been published to javascript. + +2004-11-29 Monday 17:41 annma + + add a maximum value that can be changed in config + config dialog is a bit bloated though now ;-) + +2004-11-29 Monday 13:26 geiseri + + Start of QSettings support for real. Binding is complete hozed though so it probably needs to be replaced before we release the next release. + +2004-11-29 Monday 13:25 geiseri + + Qt only fixes + +2004-11-29 Monday 13:22 geiseri + + Qt only fixes. + +2004-11-29 Monday 13:22 geiseri + + Remove unused headers. + +2004-11-29 Monday 11:14 geiseri + + Update to use KJSEmbed from KDE 3.3 features. + +2004-11-28 Sunday 21:38 geiseri + + removed default args, they really screw up QObject bindings. + +2004-11-28 Sunday 21:32 geiseri + + more qtonly config fixes + +2004-11-28 Sunday 21:11 geiseri + + Added some help + +2004-11-28 Sunday 20:39 geiseri + + added widget extraction methods to cleanup code elsewhere + +2004-11-28 Sunday 20:23 geiseri + + Small example application with KJSEmbed: + This is a small math drill application I wrote for my cousin this weekend. She is + having a horrible time of it in math, so I created a simple drill utility for addition and + subtraction. Basicly what it does is throws random math problems at you for a + minute. The goal is to see how many you can get correct in that time. This is loosely + based off of a very foggy memory of a math drill that I did in second grade. I + think the important message here is that KJSEmbed could be a powerful tool + that teachers who are not strong programmers could create learning tools in short + order. This particular app took me all of 45 minutes, and after three days of random + playing of the game (that and khangman) she got up to 38 questions correctly answered + in a minute up from about 25. Not sure if its earth shattering, but its an improvement. + + ccmail: annma@kde.org + +2004-11-28 Sunday 20:14 geiseri + + Test for Config. + +2004-11-28 Sunday 20:13 geiseri + + Splashscreen test. + +2004-11-28 Sunday 20:13 geiseri + + Add bindings to Qt only. + +2004-11-28 Sunday 20:12 geiseri + + Vain attempt to fix the QCanvas bindings. They are no longer crashing, but they are so not implemented they don't do much yet. + +2004-11-28 Sunday 20:12 geiseri + + Attempt at unscrewing up this binding. + It compiles and works slightly more, but it needs a friend seriously. + +2004-11-28 Sunday 20:11 geiseri + + QFrame now actually works as expected. + +2004-11-28 Sunday 20:10 geiseri + + Remove dead code. + Fix stupid corner case where the QPainter would become invalid and crash kjsembed. + +2004-11-28 Sunday 20:09 geiseri + + Compile in Qt Only mode + +2004-11-28 Sunday 20:08 geiseri + + Remove dead code. + Enable working with Qt Only mode. + +2004-11-28 Sunday 20:08 geiseri + + Change this so the Config bindings handle all the dirty work. This + removes a very strange misbehavior with the Config object when + used with scripts. + Started adding support for QSettings in Qt Only mode, but its disabled for now. + +2004-11-28 Sunday 20:07 geiseri + + Change this so the Config bindings handle all the dirty work. This + removes a very strange misbehavior with the Config object when + used with scripts. + +2004-11-28 Sunday 20:06 geiseri + + QSplashScreen works again, the object was there but the bindings where not. + General code cleanup. + Made the factory throw some exceptions instead of just warnings. This will + allow developers to actually be able to debug their scripts with a nondebug + version of KJSEmbed. + +2004-11-28 Sunday 20:03 geiseri + + Clean up old debug messages. + +2004-11-28 Sunday 20:00 geiseri + + Clean up code. + Remove old debug messages. + +2004-11-28 Sunday 19:59 geiseri + + Throw a real exception on a slot error so the script actually knows what the heck went wrong. + Remove some debug messages that no longer make sense. + +2004-11-28 Sunday 19:57 geiseri + + Add bindings to Qt only compile + +2004-11-24 Wednesday 19:49 geiseri + + there is suck and there is this, temporary fix until we can get a better solution. + +2004-11-24 Wednesday 17:00 geiseri + + sync with zack's tree, builds but sucks + +2004-11-24 Wednesday 16:59 geiseri + + sync with zack's tree, isnt building yet + +2004-11-24 Wednesday 16:58 geiseri + + cleanup dead code + +2004-11-24 Wednesday 11:37 geiseri + + Removed the copy operator and clone functions. They are never called, and if they + where they would not function as one would expect. + + Check for void types in the destructor. This should keep anyone from trying + to delete a void *. + +2004-11-24 Wednesday 01:59 staikos + + QT_NO_COMPAT fix (untested, but at least it compiles now): + int match ( const QString & str, int index = 0, int * len = 0, bool indexIsStart = TRUE ) const (obsolete) + int search ( const QString & str, int offset = 0, CaretMode caretMode = CaretAtZero ) const + +2004-11-24 Wednesday 01:36 geiseri + + remove debug information + +2004-11-24 Wednesday 01:28 geiseri + + fixed example + +2004-11-24 Wednesday 01:21 geiseri + + globals is now gone. + +2004-11-24 Wednesday 01:21 geiseri + + toNative fixes + +2004-11-24 Wednesday 01:20 geiseri + + added missing include + +2004-11-24 Wednesday 01:19 geiseri + + symbol visibility can work in KDE land now too. + +2004-11-24 Wednesday 01:02 geiseri + + toNative<> fixes. + +2004-11-24 Wednesday 00:54 geiseri + + More memory management fun: + 1) Removed the any object, it basicly was useless for + managing pointers. + 2) Changed the opaque proxy to handle the pointers + internally. Based heavily on boost::any but focuses on + pointers only. + 3) Things to note now that KJS is actually managing + memory. If you create a QObject binding but do not store + it anywhere and let it go out of scope the GC WILL delete + it. This may cause some unwanted side effects, so + please keep track of your objects. + 4) Fixed some casting problems that was causing the + QCanvas bindings not to work. They have not been completely + solved yet but they are at least not crashing anymore. + + There are still a few crashes, but these should be easier to + track down now that we have more clear ownership roles. + +2004-11-23 Tuesday 18:06 staikos + + warn the users + +2004-11-23 Tuesday 11:51 geiseri + + Clarified the object ownership symantics. This changes the interface a bit so instead of a boolean there is now an enum. Also the create methods in the factory will automaticly give ownership of pointers created by the factory to KJSEmbed. Any external proxies created will be owned by the object that creates it. To change ownership you now use the method JSProxy::setOwner() and JSProxy::owner() to read it. + +2004-11-23 Tuesday 11:44 geiseri + + do not screw up dlls + +2004-11-23 Tuesday 11:44 geiseri + + header cleanup + +2004-11-23 Tuesday 11:43 geiseri + + Share symbol visibility with GCC + +2004-11-22 Monday 01:27 zrusin + + We should have a law preventing Ian/Rich from creating Makefile's ;) + +2004-11-19 Friday 21:16 bmeyer + + Terminal=0 -> Terminal=false + Added missing ; to Categories + +2004-11-08 Monday 10:12 geiseri + + Qt Events now work on windows. + GC works on win32. + NOTE on win32: the standard in/out/err will crash if you do not have + matching Qt debug and KJSEmbed debug libs. So if you have a nondebug + build of Qt NEVER build a debug version of QJSEmbed. Gold star for + MS on this one. + +2004-10-03 Sunday 23:25 zrusin + + fixing build + +2004-09-23 Thursday 15:51 mlaurent + + CVS_SILENT QString(i18n(...)) -> i18n(...) + +2004-09-01 Wednesday 20:47 geiseri + + more include fixes + +2004-09-01 Wednesday 20:43 geiseri + + one more makefile.am fix + +2004-09-01 Wednesday 20:42 geiseri + + i just cant get enough of autohell... + +2004-09-01 Wednesday 20:36 geiseri + + added qtonly project files. + +2004-09-01 Wednesday 20:31 geiseri + + More updates from qtonly version to bring it in sync with KDE version + +2004-09-01 Wednesday 20:11 geiseri + + More updates from qtonly version to bring it in sync with KDE version + +2004-09-01 Wednesday 20:03 geiseri + + move to plain boost::any. need to move the deletion of the pointers to the opaque proxies themselves. + +2004-09-01 Wednesday 19:58 geiseri + + More updates from qtonly version to bring it in sync with KDE version + +2004-09-01 Wednesday 19:52 geiseri + + for some reason vc7 gets confused on casting... + +2004-09-01 Wednesday 19:50 geiseri + + qtonly fixes to the globals methods. + +2004-09-01 Wednesday 19:49 geiseri + + More updates from qtonly version to bring it in sync with KDE version + +2004-09-01 Wednesday 19:00 geiseri + + start merging win32 changes + +2004-09-01 Wednesday 10:32 geiseri + + gc test + +2004-08-25 Wednesday 11:07 geiseri + + Introduced any object to remove the void* in opaque proxy. + Introduced the concept of pointer ownership, this api is not yet stable though. + +2004-08-20 Friday 16:10 geiseri + + doesnt anyone compile this anymore? + +2004-08-16 Monday 19:44 geiseri + + mumble mumble, didnt this compile at one time... + +2004-08-16 Monday 09:28 geiseri + + Qt only changes merged into KJSEmbed. + +2004-08-16 Monday 09:27 geiseri + + Qt only fixes merged back into KJSEmbed. + +2004-08-16 Monday 09:22 geiseri + + more robust exception handling. soon backtraces. + +2004-08-16 Monday 09:22 geiseri + + attempt at custom signatures. + +2004-08-16 Monday 09:13 geiseri + + Added KFileItem bindings for doing directory listviews with KFile. + +2004-08-16 Monday 08:54 geiseri + + Update dcop test. + +2004-08-16 Monday 08:52 geiseri + + moved methods to slots, since when this becomes a nonQt binding the properties will break. + +2004-08-16 Monday 08:51 geiseri + + Added iconset bindings. + +2004-08-16 Monday 08:48 geiseri + + Reorganization of the bindings here to make Qt/KDE separation easier. + +2004-08-16 Monday 08:46 geiseri + + QWidget and QObject extraction helper functions. + +2004-08-16 Monday 08:45 geiseri + + QComboBox and QPopup menu fixes. + +2004-07-14 Wednesday 04:31 binner + + CVS_SILENT + +2004-06-21 Monday 14:58 binner + + CVS_SILENT No punctuation in command line descriptions + +2004-06-21 Monday 06:17 binner + + CVS_SILENT i18n style guide fixes + +2004-06-20 Sunday 18:51 rich + + - Added a missing doc file and the test program for qcanvas. + +2004-06-20 Sunday 18:49 rich + + - Improvements to the bindingwizard. + + - Start of bindings for QCanvasXX. These might need to be disabled for the + 3.3 release but they're a good stress test of the code. + + - Update docs. + + - Added support for QPoint to jsbinding methods. + +2004-06-18 Friday 19:44 rich + + - Added newlines to the documentation to make the html sources more readable. + +2004-06-18 Friday 19:33 rich + + - Update docs + +2004-06-18 Friday 19:27 rich + + - Added support for the QStringList parameter argument of the KParts + constructors. For now, this can only be used with the full 5 argument + forms of the factory's part construction methods. Added the test script + from Koos, though it can't be used without an accompanying applet! + + +2004-06-18 Friday 18:51 rich + + - Updated the qtbindings using the bindwizard. The problems identified in + #83427 and my own QListView testing turned out to be caused by a stupid + logic error in the code generated by the XSL. Basically, I forgot that + enum values start at 0 even if they're being automagically generated. + +2004-06-18 Friday 17:34 rich + + - Reverted the updated QComboBox bindings. Looks like I need to do some + more work on making the XSL binding generator work with the custom + bindings code. + + - Added a test case so I don't break this again. + + +2004-06-12 Saturday 23:03 rich + + - Update docs + +2004-06-12 Saturday 22:53 rich + + - Added support for a couple of new types to the extractXX() methods. + + - Major improvements to the binding wizard. + +2004-06-12 Saturday 20:51 rich + + - Added action for launching ksnapshot. + +2004-06-12 Saturday 20:49 rich + + - Reverted update of the QListViewItem bindings as it broke things. + +2004-06-11 Friday 20:52 rich + + - Handling for slots with signatures xx( const QTime &) and xx( QWidget *). + + +2004-06-11 Friday 19:03 rich + + - Added a way for non-konq users to view the changelog. + +2004-06-11 Friday 18:45 rich + + - Disable compilation of the embedding example. This example wasn't + written to support compilation with the library (something which + needs addressing). Bug #83020, Bug #82991. + + - Added the missing kjs.pro for the qt-only build. + + +2004-06-06 Sunday 20:58 rich + + - Fixes to make qt-only mode work with the latest changes. + +2004-06-06 Sunday 20:42 rich + + - Forgot to add the implementation. + +2004-06-06 Sunday 20:40 rich + + - Added support for QCheckListItem. + + - Regenerated qtbindings using the wizard. + +2004-06-06 Sunday 19:37 rich + + - Added support for signals and slots with signature func(const QTime &) + including support for handling them from scripts. + + - Added a check for exceptions occurring in event handlers. + + +2004-06-06 Sunday 19:03 rich + + - Added a few missing files. + +2004-06-06 Sunday 19:00 rich + + - Updated documentation. + +2004-06-06 Sunday 18:44 rich + + - Added a binding for the Qt namespace class. This gives scripts access to + important constants such as the alignment flags. + + - Added an accessor for the KPropertiesDialog of a URL to NetAccess. + + - Minor fix to the binding wizard to support classes that provide no methods. + + - Added partially complete cropping tool to imunge, along with support for + showing the file's properties dialog. + +2004-06-06 Sunday 18:10 rich + + CVS_SILENT fix ignores + +2004-06-05 Saturday 22:07 rich + + - JSObjectProxy now reuses the same JSObjectEventProxy no matter how many + event handlers there are. + +2004-06-04 Friday 22:06 rich + + - Added an example script that provides a documentation browser for the + qt-only build. + +2004-06-04 Friday 21:31 rich + + - Added a script that makes building the qt-only kjsembed easy. All you + need to do is ./setup_qtonly in a clean checkout of kjsembed. + + - Fixed some minor issues with types that only showed up because the + qt-only tree uses an unusual set of header files. (it's nice that this + development has the side effect of making some rare bugs visible). + + - Added a minimal command line for the qt-only build. You can see that + things are working by running tests/test_stdio.js. Note that this test + script is one of the kde build scripts which shows how easy it should + be to migrate between the two. + +2004-06-04 Friday 18:52 geiseri + + Resolve conflicts. + +2004-05-28 Friday 22:10 rich + + - Updated js reference documentation. + +2004-05-28 Friday 22:06 rich + + - Removing docs. + +2004-05-28 Friday 21:08 rich + + - Improved the documentation generation. + +2004-05-28 Friday 19:55 rich + + - Ensure we always use our debug area in our kdDebug() calls. + +2004-05-28 Friday 19:51 rich + + - JS exceptions that occur when a js function has been invoked by a signal + are now reported and cleaned up properly. + +2004-05-28 Friday 19:15 rich + + - Fixed the problem of the time property of a QTimeEdit returning -1. This + in fact turned out to be a general problem that affects all QTime + properties and was happening because you can't create a Date object in js + with just a time in it. + + +2004-05-27 Thursday 21:05 rich + + - Added the missing mirror() method to the image binding. + + - Added missing icons to imunge. + +2004-05-27 Thursday 17:41 rich + + - Added support for passing opaque types as arguments to slots. This is a big + win and turned out to be pretty simple once I tracked down a logic error + that caused any subsequent args to be ignored. This would all be perfect + except for the minor flaw that it doesn't work. + + - Improvements to imunge. + - Made it work again after I broke it. + - Added support for a bunch more effects. + - Shows the filename in the status bar. + + - Added an accessor to the KConfig wrapper that lets you obtain an opaque + pointer to the KConfig object. + + - Updated class docs + +2004-05-20 Thursday 20:24 rich + + - Improved the Imunge example code by splitting the image effect handling into + a standalone file. In addition, I added support to the GUI for several + additional effects and added a toolbar that makes it easy to invoke them. + +2004-05-19 Wednesday 21:24 geiseri + + Added the ability to query if a function is available. + +2004-05-19 Wednesday 21:17 rich + + - Added support for the selectedItem() method of QListView then converted the + docviewer example to use QListView. + +2004-05-19 Wednesday 20:10 rich + + - Modified the imunge demo to avoid hard-coding the path to the ui.rc file I + use here. + +2004-05-19 Wednesday 20:08 rich + + - Added support for creating system tray icons from scripts using + KSystemTray, and an example that shows how this can be used. + +2004-05-19 Wednesday 18:54 rich + + - Fixed a couple of naming errors in QProcess's signals that resulted from + the conversion from KProcess. + +2004-05-19 Wednesday 18:31 rich + + - Missed this in the last commit. + +2004-05-19 Wednesday 18:29 rich + + - Added a new directory for the Qt bindings. This means that these bindings + can now be made available for the qtonly version of kjsembed. This also + greatly simplifies the structure of the code (basically it's what I should + have done initially). + +2004-05-19 Wednesday 18:02 rich + + Added something for testing + +2004-05-19 Wednesday 16:55 rich + + - Added the first bit of an image manipulation app for kde (using + KImageEffect). The app is implemented in javascript. + +2004-05-17 Monday 14:52 geiseri + + added the java test applet + +2004-05-17 Monday 14:52 geiseri + + I added a test for the args stuff. Is this correct code? + + +2004-05-13 Thursday 12:36 geiseri + + Test for slots that use pixmaps + +2004-05-13 Thursday 12:35 geiseri + + Qt wants the real thing, not cheap immitations. + + Fixed QPixmaps in slots. + +2004-05-07 Friday 17:13 geiseri + + Added tests to the make file. + +2004-05-07 Friday 17:10 geiseri + + Added the C++ based tests used to develop the new part code for manipulating the script engine. + + These need to be refactored, but I hate CPPUnit too much to use that here. + +2004-05-05 Wednesday 23:51 geiseri + + Const cleanups + Fixed accidental memory leak + Added the following methods to make access of QVariant based objects + easier: + void putVariant( const QString &valueName, const QVariant &value); + QVariant getVariant( const QString &valueName ) const; + + Started an implementation of a scope walker so the added methods + will work beyond the global scope. Not reliable yet, so its not used. + +2004-05-05 Wednesday 22:26 geiseri + + Added the following functions to the part for embedders to enjoy: + KJS::Value getValue( const QString &valueName ); + KJS::Value callMethod(const QString &methodName, KJS::List &args); + void putValue( const QString &valueName, const KJS::Value &value); + + Rich I have tests, but they require being compiled. We need a C++ tests + directory at this point i think to show off what we are up to. + +2004-05-04 Tuesday 19:52 rich + + - Update class reference + +2004-05-04 Tuesday 19:50 rich + + - Improved the argument handling of kjscmd so that it will automatically + invoke the console if there is no script to run. It will also call exec + implicitly in this situation, though not if there is a script to invoke + so the exec() call in the graphical scripts is still required. + + - Added a directory for a standard library of javascript utilities and put + the command line prompt script in it - other reusable scripts and objects + will follow. Scripts installed in this location will be found automatically + by the include(...) method. + + - Added an option to kjscmd to tell it to invoke the cmdprompt script from + the standard library. + + - Updated the man page to reflect these changes. + +2004-05-03 Monday 21:21 rich + + - Added support for a few KHTMLPart method to the custom bindings. + + - Added a simple example of embedding the engine. This will be used + by the embedding tutorial i'm working on. The example is based on + the KDevelop template for a non-parts KDE app and embeds the + interpreter. It then offers an action to show the js console, and + a word count action that is implemented in js. + +2004-04-30 Friday 20:53 rich + + - Improved binding wizard. + +2004-04-30 Friday 20:27 rich + + - Extended the range of types supported by the XSL stylesheet to allow QFile + and QFrame to be wrapped. Added the generated wrappers to the build. + +2004-04-30 Friday 19:36 rich + + - Integrated the constructor bindings into the binding wizard and added a hack + that only enables the first method we see with a given name, meaning that + only the first version of overloaded methods can be used. This change means + that the QComboBox binding is now generated directly from the Qt header file + using the wizard. + +2004-04-30 Friday 17:38 rich + + - Started rolling the code for instantiating bound objects into the wizard. + I accidentally deleted the stylesheet it uses to index the classes, so i'm + adding that to the repository now too so I don't have to write it a third + time. + +2004-04-29 Thursday 21:11 rich + + - Improved the command line tool. + +2004-04-29 Thursday 20:37 rich + + - Further steps towards a GUI for binding generation. The wizard pages are now + split up into functions and it uses an LED to provide feedback when it's + running doxygen. There's still a way to go, but this is slowly approaching + release quality. + +2004-04-29 Thursday 20:34 rich + + - Update class reference + +2004-04-29 Thursday 20:33 rich + + - Update class reference. + +2004-04-29 Thursday 18:57 rich + + - More updates to the binding generation wizard. + + - Added support for the flush method to textstreams. + + - Added a script that provides an interactive command line prompt. + +2004-04-23 Friday 22:19 rich + + Added the start of a wizard that will make creating bindings for a set of + C++ classes a point-and-click process. + +2004-04-23 Friday 18:47 geiseri + + Added event support for: + QEvent::QTimer + QEvent::ContextMenu + QEvent::DragMove + QEvent::DragEnter + QEvent::Drop + QEvent::Enter + QEvent::Leave + QEvent::Clipboard + QEvent::DragLeave + Based all events off the default handler so interited + properties are preserved. + +2004-04-23 Friday 15:57 geiseri + + move to QProcess. + +2004-04-23 Friday 15:20 rich + + Update to qt-only support + +2004-04-23 Friday 10:57 geiseri + + added some of my things i want to see. + +2004-04-22 Thursday 20:33 rich + + Update changelog. + + Allow C++ doc pages to link to each other in the docviewer. + +2004-04-22 Thursday 20:27 rich + + Improvements to the docviewer. + +2004-04-22 Thursday 20:17 geiseri + + remove printfs + +2004-04-22 Thursday 20:01 geiseri + + since im trapped in the basement here, i figured id fix + the appname patch rich commited. Rich friends dont + let friends use C string crap ;) + +2004-04-22 Thursday 18:27 rich + + Changed the behaviour of kjscmd so that it uses the name of the script as + the name of the instance it uses. This means that scripts can now have their + own config files etc. + +2004-04-22 Thursday 17:33 geiseri + + Added extractQPalette + Added extractQStrList + +2004-04-22 Thursday 16:57 rich + + Added support for Ian's new string munging functions to the XSL binding + generator. + +2004-04-22 Thursday 15:07 geiseri + + Normalized the size and color extraction. + Added QRect helper function. + +2004-04-22 Thursday 15:03 geiseri + + Normalize extraction helper function so its easier to use with + the bindings generator. + +2004-04-22 Thursday 12:59 geiseri + + remove noise... + +2004-04-22 Thursday 12:58 geiseri + + Found out javascripts month index starts at 0. + Fixed validation test, and code + Added ability to handle date, datetime, and time in slots + Added ability to call slots that use datetime, date, and time. + +2004-04-22 Thursday 10:01 geiseri + + added test for dealing with time in slots + +2004-04-22 Thursday 09:17 geiseri + + Rich I really dont like this one bit. + Added a few more slot signatures. + Way more effort than its worth, we need to rethink how this all ties + together. + +2004-04-21 Wednesday 23:10 geiseri + + There is a moral here... untested code is buggy code. + +2004-04-21 Wednesday 22:17 geiseri + + Added transparent mapping between Javascript dates and Qt's dates + +2004-04-21 Wednesday 16:09 geiseri + + forgot to add the one i really wanted to. Now we can map a string array to a QVariant properly. + +2004-04-21 Wednesday 15:48 geiseri + + Added the ability to convert from JS Arrays to stringlists. Rich to use this + code follow what i did in qcombobox_imp.cpp. Its a oneliner and Hari says + its the most maintainable way to do it... Learned more about KJS than I ever + did today. Hari I owe you a beer, or 3, and john, you owe me your first born. + +2004-04-19 Monday 11:53 geiseri + + fixed QBoxLayouts. might want to backport + +2004-04-16 Friday 21:51 rich + + We can now build kjsembed without needing KDE! There is tidying up needed, + but it builds ok. + +2004-04-16 Friday 19:47 rich + + More work on making a qt only build possible. This build mode doesn't work + yet, but the standard mode is unaffected by the changes. + + Tidied up the header file inclusion in various places which makes life simpler + and should also speed up compilation. + +2004-04-15 Thursday 20:19 rich + + More work towards a qt-only build + +2004-04-15 Thursday 18:53 rich + + Began adding support for Qt-only builds. + Explained to Ian's copyrights that the year is now 2004. + +2004-04-13 Tuesday 12:08 geiseri + + Added DCOPClient::isApplicationRegistered(...) + Added validation test for it. + +2004-04-13 Tuesday 11:10 geiseri + + Test for clobbering return values of dcoprefs call. + The fixed dcopref code... yay validation tests... + +2004-04-12 Monday 17:48 geiseri + + DCOPRefs now work correctly as return values from javascript + dcop interfaces. + +2004-04-12 Monday 16:53 geiseri + + Added testcase for pixmaps. + Fixed no object type returned bug. + + Dcop interfaces now work for more cases. + +2004-04-12 Monday 16:28 geiseri + + test case to show off problems calling void functions in dcop interfaces. + +2004-04-12 Monday 13:08 geiseri + + Fixed an issue with dcop interfaces where only the first + argument was being read. + +2004-04-12 Monday 10:11 geiseri + + Added ktempfile support. + +2004-04-12 Monday 10:11 geiseri + + Added ability to invert pixels on the painter. + +2004-04-12 Monday 10:10 geiseri + + More spacing and formatting fixes... soon my cvs will be in sync. + +2004-04-12 Monday 10:09 geiseri + + Added support for the command shell(...). + Added ksimple process ( a blocking shell process that returns the output) + I dont like where this is going, but ideally in cvs we can work this out. + The goal is to get a function that allows us to do the following: + var response = shell( 'ps -aux' ); + prinln( response ); + So we can run simple shell commands and get a response back. + Suggestions welcome. + +2004-04-12 Monday 10:05 geiseri + + Formatting and spacing. + +2004-04-12 Monday 10:03 geiseri + + Formatting and spacing cleanups. + +2004-04-12 Monday 10:02 geiseri + + Added support for dcopstart (like the shell command line version). + Added tests for dcopreferences. + +2004-04-12 Monday 10:00 geiseri + + Added support for QProcess as a bindings plugin. + Exposed API identical to QProcess. + +2004-04-10 Saturday 20:40 rich + + Added support for the setSpacing method of QHBox. + + Converted the docviewer example to use the KHTML streaming API and made it + work properly. + +2004-04-10 Saturday 17:24 rich + + Fix link to livedata example. + +2004-04-09 Friday 21:26 rich + + Added support for streaming data to a KPart, and an example of doing so. This + means you no longer need to have a temporary file to display stuff in khtml. + +2004-04-09 Friday 20:22 rich + + Added an example of how to embed several parts in one scripts GUI. + +2004-04-09 Friday 19:34 rich + + Added some methods that should allow us to have a unified interface to the + proxy types in future. This change is the first step towards an understanding + of inheritence. The first win of the change is that the code now understands + that KXMLGUIClient's are not necessarily QWidgets. + +2004-04-09 Friday 17:52 rich + + Added proper support for QComboBox. This binding was generated automagically + using the xsl stuff in the tools dir, but I had to disable 4 methods to work + around missing support for method overloading. There's also an example. + +2004-04-09 Friday 16:39 rich + + Added support for loading read-write parts, and an example showing how it's + done. + +2004-04-09 Friday 15:32 rich + + - Made it so the man page gets installed. + + - Fixed some unused variable warnings. + +2004-04-08 Thursday 09:52 geiseri + + Oh this is an annoying one. For some reason I thought I could trust + QVariants to tell me what type they where. It seems that in the + instance of QString vs QCString this is not the case, so I am now + doing this correctly and using the dcop functions type signature to + get the correct types. This fixes a few courious bugs I was chasing + after in dcop. I am trying to backport this fix now. + +2004-04-07 Wednesday 19:38 rich + + Fix missing exec call found by David Joham. + +2004-04-04 Sunday 19:33 rich + + Added a man page for kjscmd + +2004-03-25 Thursday 19:48 geiseri + + Added the ability to expose child widgets as properties of a loaded UI file. + This will allow one to import a UI file and then transparently address + each of the UI elements via their name as given in the UI file. + +2004-03-25 Thursday 19:16 geiseri + + this moved a few days ago. + +2004-03-25 Thursday 19:12 rich + + Added an accessor to let the imp specify its factory. + +2004-03-23 Tuesday 10:06 geiseri + + Moved the mimetype for javascripts to the kdelibs mimetypes. + Removed useless feilds per davids advice. + Matches the freedesktop.org format. + + +2004-03-22 Monday 20:29 geiseri + + hack to make javascripts open here with kdevelop. + +2004-03-17 Wednesday 11:48 faure + + Lazy loading - don't slow down the loading of every KHTMLPart in Konqueror. + OKayed by Rich. + +2004-03-05 Friday 16:29 jowenn + + wrong warning + +2004-03-04 Thursday 17:52 jowenn + + don't crash on slots having uint parameters. I could put it into a function, but I don't like my hack at all. I would appreciate, if somebody comes up with a better solution. + + +2004-02-29 Sunday 12:54 jowenn + + support for plugin based decorating of qobject derived return values from slots. If somebody has a problem with that, please let me know, I'll fork the code than, since i need it for kate scripting. the jsproxy behaves really bad for slots with default values and overloaded methods. From what I see they should get numbered, but they aren't + + +2004-02-29 Sunday 05:35 jowenn + + It's not nice, for each proxy implementation one QGuardedPtr. :( I hope Qt's next generation smart pointer will be more lightweight. Why a qguardedptr? + + If you do the following in kjscmd it would crash without guardedptr + var k=new KMainWindow(); + k.show(); + var k1=new KMainWindow(); + k1.show8); + ---> close k1 with the mouse + k1.hide(); or k1.show(); + ====> Crash + +2004-02-16 Monday 02:42 geiseri + + Small code consolidation. No real functional changes, just cleaner code. + +2004-02-16 Monday 01:28 geiseri + + Added missing Brush type conversion. + +2004-02-16 Monday 01:09 geiseri + + Added signatures for: + void slot_color( const QColor &color ); + void slot_point( const QPoint &point ); + void slot_rect( const QRect &rec ); + void slot_size( const QSize &size ); + void slot_pixmap( const QPixmap &pix ); + void slot_url( const KURL &url ); + void slot_intint( int , int ); + void slot_intbool( int , bool ); + void slot_intintint( int , int , int ); + + This should cover almost every signal that we can handle with + native types in KJSEmbed. Thanks Adam Treat from the C# stuff + for the hints... now to streamline this junk. + +2004-02-12 Thursday 14:51 geiseri + + Added an example of how RSSService can be interacted with + using DCOPRefs and dcop signals. + +2004-02-12 Thursday 14:51 geiseri + + Fixed an issue where dcoprefs would not be marshalled + properly. + +2004-02-11 Wednesday 19:02 rich + + Fixed a problem with non-mainwindow xmlgui clients not getting the + actionCollection() method. + +2004-02-11 Wednesday 17:19 rich + + Backport: Better fix for the crash when there is no actioncollection. + +2004-02-11 Wednesday 17:15 rich + + Better fix for the crash when there is no actioncollection. + +2004-02-11 Wednesday 17:12 rich + + Fix a crash when there is no actioncollection. + +2004-02-11 Wednesday 14:33 staikos + + backport crash fix + +2004-02-11 Wednesday 10:18 staikos + + don't krash + +2004-02-09 Monday 13:41 rich + + Disable the KJS embed console plugin. + +2004-02-01 Sunday 19:45 geiseri + + helps if you can actually create the little buggers too. + +2004-02-01 Sunday 19:44 geiseri + + added support for dcoprefs. the test assumes that your + running the dcoprss service though. to run the dcop test + $rssservice + $kjscmd dcop.js + +2004-01-20 Tuesday 19:49 staikos + + No you really can't, Ian. :-) This fixes KJSEmbed from crashing all over the + place and I consider it a KJSEmbed showstopper pending review by Rich. Without + this patch I can't run space invaders. + + +2004-01-20 Tuesday 19:48 staikos + + For some reason [perhaps old admin/? don't think so...] at least one of my + machines insists on generating moc for these even though it's commented out. + +2004-01-15 Thursday 01:35 geiseri + + oh how i hate to merge xml files... + +2004-01-14 Wednesday 14:51 zander + + Fix some bad layed-out button -- GUI problems + +2004-01-11 Sunday 08:41 geiseri + + forgot to commit the image test. + +2004-01-11 Sunday 02:08 geiseri + + use imagefx plugin. + +2004-01-11 Sunday 02:08 geiseri + + reflect the changes to use include. + +2004-01-11 Sunday 02:06 geiseri + + import was taken so include seems to work better for loading script libraries into kjsembed. + +2004-01-11 Sunday 01:27 geiseri + + updat to ImageFX + +2004-01-10 Saturday 21:35 rich + + - A first cut at specifying the public classes and generating their + documentation. Internal documentation (for people working on the code can be + created with doxygen Doxyfile-Internal). + +2004-01-10 Saturday 20:38 rich + + - Added a hook for future bc virtuals. + +2004-01-10 Saturday 20:12 rich + + - Fixed buffer overrun in argument handling. + + - Updated docs. + +2004-01-10 Saturday 20:10 geiseri + + Use new image effects code. + Works like a charm ;) + +2004-01-10 Saturday 20:04 geiseri + + This is the ImageFX plugin. It provides a wrapper arround KImageEffect and can be dynamicly + loaded at runtime. + + To activate: + var imgfx = new ImageFX(); + + To use: + var img = imgfx.blend(color, img, 0.25); + + All methods mirror their KImageEffects counterparts in function signatures. + +2004-01-10 Saturday 20:00 geiseri + + Step 2. Remove Image effects from the Image Bindings + +2004-01-10 Saturday 19:48 rich + + - Added the unlisted demos to the index page. + +2004-01-10 Saturday 19:45 geiseri + + Step 1 in conversion of ImageEffects to a plugin. + +2004-01-10 Saturday 19:25 rich + + - Fixed support for QChildEvent. It now has a type specific conversion + function rather than falling back to the generic one. Without this change, + it is pretty useless as you can't access anything or even distinguish + between insert and remove events. + + The new code splits the childEvent() handler into two methods + childInsertEvent() and childRemoveEvent(). The code is disabled for now + behind the ENABLE_CHILDEVENTS define because there seem to be some problems + with reentrancy. This problem occurs if the callback is invoked because + kjsembed created an object. + + - Added my coverage checking scripts to the tools directory. These aren't + exactly the best, but they give an idea of which classes need adding. + + - Removed hard-coded list length from the event type <-> handler name map. + + - Commented out some unused args. + + - Updated TODO list. + +2004-01-10 Saturday 14:33 rich + + - Add exception example + +2004-01-10 Saturday 14:23 rich + + - Throw an exception when we fail to create a plugin too. + +2004-01-10 Saturday 14:11 geiseri + + change the enums to work as they do, not as we hoped ;) + +2004-01-10 Saturday 14:09 geiseri + + update the test + +2004-01-10 Saturday 01:50 geiseri + + buttonmaker cleanup and moved to kjsuic + +2004-01-10 Saturday 01:45 geiseri + + more changes to handle containers properly + +2004-01-10 Saturday 00:28 geiseri + + some docs, and a minor cleanup to make it even cooler + +2004-01-10 Saturday 00:19 geiseri + + This is a really simple class that simplifies dealing with UI files. + It basicly wraps the loadUI function and autocreates an object for the + main form, and presents the objects as properties. + +2004-01-07 Wednesday 11:46 geiseri + + EnvelopeMaker example for KJSEmbed: + This example will create postscript files for #10 Envelopes from a simple form. + It will generate compliant postnet barcodes. Im not sure if this works outside + of the united states, but it works here. It also is a nice example of how KJSEmbed + can be used to build simple one off apps for your company. + +2004-01-02 Friday 23:27 geiseri + + more exploration of how this works + +2004-01-02 Friday 16:34 aseigo + + exec the application so something actually happens + +2004-01-02 Friday 16:31 geiseri + + added some examples to test bumpmap code. + +2004-01-02 Friday 16:31 geiseri + + fixed some minor issues with the bump map stuff + +2004-01-02 Friday 16:30 geiseri + + Added abillity to set image mask correctly now. + +2004-01-02 Friday 01:41 zrusin + + This is a huge present for geiseri. Fixing the biggest problem he had + with his buttonmaker demo. + +2004-01-01 Thursday 02:23 geiseri + + Removed the extra JSProxy argument from the convertToValue() function. + All types should now be a ValueProxy, or a OpaqueProxy. + +2003-12-31 Wednesday 11:54 geiseri + + use new QPixmap code + +2003-12-31 Wednesday 11:12 geiseri + + updated todo list + +2003-12-31 Wednesday 11:11 geiseri + + missing include + +2003-12-31 Wednesday 11:10 geiseri + + Moved Pen -> ValueProxy + Moved Painter -> OpaqueProxy + Moved Pixmap -> ValueProxy + + Fixed Pen and Pixmap handleing in the bindings + Simplified Pixmap and Pen hadeling more + + Updated button maker to use new pillbox code + +2003-12-30 Tuesday 14:23 geiseri + + move buttonmaker.js to new QPainter stuff + +2003-12-30 Tuesday 14:17 geiseri + + more for the pillbox test, we can paint directly on widgets now + +2003-12-30 Tuesday 13:37 geiseri + + desktop file + +2003-12-30 Tuesday 13:37 geiseri + + + Added test for pillbox generation + package script to make ButtonMaker installed as a real app. + +2003-12-30 Tuesday 13:24 geiseri + + compile the correct file. + +2003-12-30 Tuesday 11:41 geiseri + + compile the listview bindings... + +2003-12-30 Tuesday 11:07 rich + + - Oops + +2003-12-30 Tuesday 10:56 geiseri + + moved arg extraction code to slotutils + converted QPainter bindings to Opaque Proxy... it has issues still, but pending + QPixmaps conversion they cannot all be fixed yet. + added arg extraction methods to simplify the code + +2003-12-29 Monday 16:08 rich + + - Added a test program for the qlistview. + +2003-12-29 Monday 16:08 rich + + - Added the binding for QListViewItem and the latest xsl templates. + +2003-12-28 Sunday 21:22 rich + + - Massive improvements to the binding generation tool. It can now create + usable code!!! To prove this, I've added a new binding to the builtins + directory for QDir. This binding was generated directly from the qdir.h + header file using the scripts in the tools directory. There is a simple test + program in the test directory. + +2003-12-28 Sunday 17:56 rich + + - More work on the bindings generator. + +2003-12-28 Sunday 15:55 rich + + - More work towards automating the bindings process. It's getting there! + +2003-12-28 Sunday 08:49 larkang + + CVS_SILENT ignore + +2003-12-28 Sunday 08:43 larkang + + Some srcdir!=builddir fixes + + Ok'd by Richard Dale + +2003-12-22 Monday 10:11 wildfox + + Fix invalid kjscmd sources, use /usr/bin/env kjscmd everywhere and chmod +x the right .js files + +2003-12-22 Monday 07:57 cartman + + CVS_SILENT Add a GenericName. Use konsole icon as the app already uses it in title. + +2003-12-21 Sunday 19:05 geiseri + + Changes to the plugins to autoregister... more later once i get a real network connection. + +2003-12-20 Saturday 22:42 zrusin + + Fixing makefiles and a path. The makefile's in kjsembed need cleaning up, Coolo? :) + +2003-12-20 Saturday 21:40 rich + + - Added a gray button template + +2003-12-20 Saturday 21:08 rich + + - Added buttonmaker to the index page of the demos. + +2003-12-20 Saturday 20:48 rich + + - Fix warning caused by attempting to overwrite the x and y properties of the + widget. + +2003-12-20 Saturday 20:43 rich + + - Added support for command line args to the button maker. It will now read + the first argument and use that as the text. I also improved the defaults + including making it attempt to load the default button image on startup. + +2003-12-20 Saturday 19:57 rich + + - Added keyboard shortcuts to buttonmaker + +2003-12-18 Thursday 17:19 geiseri + + start of docs for this class, since an example will be in order. + +2003-12-18 Thursday 17:15 geiseri + + Added support for adding bindings via KParts Plugins. + I have tested ValueProxy and OpaqueProxy plugins and those work perfectly. + QObject based plugins are mostly working, but enums seem broken. + + The plugin interface is pretty thin right now, because I dont think we need + a heck of alot to bootstrap the process of adding a binding. + + This is a start, I feel we need to ship 3.2 with this since we need a way to + add bindings later without rebuilding kjsembed. This also allows us to get + arround messy instances where we may or may not want to have custom + bindings to interfaces that are in KDE but may not make sense to be built + into KJSEmbed. + + This api is subject to change as we kick it arround and clean it up, but so far + it seems to work for my tests. + +2003-12-18 Thursday 14:00 geiseri + + more clear idea of what happend when calling this slot. + +2003-12-18 Thursday 13:58 geiseri + + Brush bindings to make the painter more fun. + +2003-12-18 Thursday 02:23 geiseri + + maby even save the file too... + +2003-12-18 Thursday 02:14 geiseri + + used the text box stuff to center the image. + +2003-12-18 Thursday 02:02 geiseri + + a nice button for testing. + +2003-12-18 Thursday 01:49 geiseri + + This might not be the right place for it, but we need a good way to get + the bounding boxes of text drawn on the painter with the current font + metrics. Ideally we can move this later when we bind QFontMetrics? + +2003-12-17 Wednesday 23:37 geiseri + + Added a neat demo applet to show off KJSEmbed. Its only a start, but a + very good example of how KJSEmbed can do pretty powerful things in less + than 100 Lines of code. + +2003-12-17 Wednesday 18:50 geiseri + + painter fixes to change the font. + +2003-12-17 Wednesday 18:12 geiseri + + group single arg members together + +2003-12-17 Wednesday 18:10 geiseri + + Added ability to connect Qt signals to KJS Slots that have a single QFont or QColor. + Not as cool as I would have liked, but I guess its okay. + +2003-12-16 Tuesday 18:21 geiseri + + cleaned up the Image headers + +2003-12-16 Tuesday 18:21 geiseri + + Moved DCOPClient code into a OpaqueProxy class. This put it all + into one place. The big issue now is that until Pixmap is moved + to a ValueProxy it will crash KJSEmbed when you pass pixmaps + over DCOP. + +2003-12-16 Tuesday 18:17 geiseri + + fixed test to reflect the real DCOP api + +2003-12-16 Tuesday 14:11 rich + + - Fix imagegallery script for exceptions. + +2003-12-16 Tuesday 14:01 rich + + - Fixed for new names of System. + +2003-12-16 Tuesday 12:51 geiseri + + properties -> methods + +2003-12-16 Tuesday 12:32 geiseri + + move properties -> methods + +2003-12-16 Tuesday 12:29 geiseri + + make sure tables can stay in sync + +2003-12-16 Tuesday 12:23 geiseri + + comment out unused functions for now + +2003-12-16 Tuesday 12:05 rich + + - Fix image code. + +2003-12-16 Tuesday 11:42 geiseri + + Start of move from opaque proxy to valueproxy + Cleanup in Image to make it easier to follow. + +2003-12-15 Monday 19:40 rich + + - Removed moc reference from ImageImp - it's not a QObject anymore. + + - Fixed a crash when the factory is asked for an invalid part. + +2003-12-15 Monday 18:35 rich + + - Improved the code of the image binding: + + - Changed the name from Image to ImageImp as now that it doesn't use + QObject, this class only handles the methods. + + - Added support for the enums from KImageEffect. The output of the test + program should now be upside down. + + - Added a second parameter to the save() method that specifies the format to + save in. + + - Made all the constants defined in enums read-only. This means scripts can no + longer corrupt the API (at least in this fashion). + +2003-12-15 Monday 17:06 rich + + - Fixed the new image binding support so it works for the test program I've + added. I expect there is more work to be done to make this work nicely with + the property support, but you can load, transform and save files again. + +2003-12-14 Sunday 12:36 geiseri + + Fixed the Image stuff so it will at least load. + + Came to the conclusion that there is all wrong, and we should revert + back to the QObject bindings. The current implimentation makes + no sense for how the Image binding is suppose to operate. + + Maby we really wanted a JSValueProxy? + + Rich please review this and let me know your thoughts. + +2003-12-14 Sunday 11:02 geiseri + + Attempt at activating the Image bindings. + +2003-12-14 Sunday 10:45 rich + + - const fix for gcc 3.3. + +2003-12-14 Sunday 10:39 rich + + - Minor fixups. + +2003-12-14 Sunday 10:23 rich + + - Add pen bindings + +2003-12-14 Sunday 10:08 rich + + - Started adding the framework needed to allow custom value types to become + first class citizens. + + - Replaced the NewQObject method of the factory with NewInstance which + supports the creation of instances of any type. + + - Added support for event types to the opaque proxy. + +2003-12-12 Friday 23:58 geiseri + + removed old kdDebug statements and moved the ones that made + sense to kdWarning. + +2003-12-12 Friday 23:56 geiseri + + half of the move from QObject binding to JSProxyImp + rich this needs to be enabled, i was unsure of how to activate + it. + + also am i correct in assuming that properties will no longer work for + Image now that we are using a non QObject binding? + +2003-12-12 Friday 17:10 rich + + - Moved the registration of the global objects so it is handled inside the + JSBuiltins class rather than the part. + +2003-12-12 Friday 17:03 rich + + - oops 2 + +2003-12-12 Friday 17:02 rich + + - oops + +2003-12-12 Friday 16:49 geiseri + + example to show failure in enums on slots + +2003-12-12 Friday 16:48 geiseri + + more fixes for enum values. + +2003-12-12 Friday 15:18 rich + + - Replaced the QObject wrapper for QTextStream with a native binding + class. This reduces the overhead of this binding, and allows more + flexibility in the API we present to scripts. The new binding provides the + same API to scripts as the old one, except that the current() and + setCurrent() methods have been removed as they are redundant. + + This binding is the first one to be based on the JSOpaqueProxy class, but + this will in future be a common approach to wrapping non-QObject classes. + + - Made a few methods of the factory that were previously protected have + private access. These methods are only useful internally, so there is no + reason to make them visible to users. + + - Renamed System.in -> System.stdin to avoid nameclash with the in operator + and made corresponding changes to the other stdio streams. + +2003-12-10 Wednesday 21:05 rich + + - Major rewrite of the documentation generator script. The new version is a + lot cleaner and uses JS exceptions to handle problems rather than having + a hard-coded list of trouble-some classes. This change also makes a single + function responsible for the page template. The docs have also gained a + bunch of new index pages. + +2003-12-09 Tuesday 20:42 geiseri + + example for message boxes. + +2003-12-09 Tuesday 20:40 geiseri + + Added support for: + alert(textMessage); + confirm(textMessage); + promp(textMessage, [inputDefault]); + i18n(text); + + Added examples of the message boxes. + + i18n sorta works but may get removed if i cannot get it to work reliably. + +2003-12-08 Monday 18:22 rich + + - Fix for gcc 2.95. + +2003-12-08 Monday 17:53 rich + + - Don't use -no-undefined as this now requires libkjsembed. + +2003-12-08 Monday 17:16 rich + + - Fix for --noexec -> --exec change. + +2003-12-07 Sunday 21:00 geiseri + + Added a neat demo to show off event handling, and how generally awesome + kjsembed is. + + Classic Space Invaders: + Keys: + <- go left + -> go right + <space> fire + Mouse: + click mouse to fire. + + Have fun. + +2003-12-07 Sunday 20:59 geiseri + + Fixed some small confusion on the event mapper. + +2003-12-07 Sunday 13:19 geiseri + + We can now grab windows. Not sure how you get the winID yet though. + +2003-12-06 Saturday 21:21 geiseri + + Reflect namechange from Dcop -> DCOPClient. + +2003-12-06 Saturday 20:59 geiseri + + Added ability to connect dcop signals to kjs dcop slots. + Added example to show this off. + Removed a few compiler warnings. + +2003-12-05 Friday 18:13 geiseri + + reflect a name change in the dcop client object. + +2003-12-05 Friday 18:12 geiseri + + The ability to export a JS Method to a dcop interface now works. + use DCOPInterface.publish("returnType signaure(ArgType)"); + as the format for publishing an interface. The rest is transparent + to the user. + +2003-12-05 Friday 15:19 rich + + - Add a d pointer. + +2003-12-04 Thursday 20:54 rich + + - Moved call to custombindings to a standalone method that encapsulates the + qobject handling. + + - Added warnings for unsupported methods that are defined in the + custombindings enum. + + - Fix warning in resources.cpp. + +2003-12-04 Thursday 18:35 rich + + - Changed the inline version methods to non-inline. This means that the + concept behind these methods might actually work! + +2003-12-04 Thursday 18:33 rich + + - Update js class reference. + +2003-12-03 Wednesday 20:57 rich + + - Fixed a whole bunch of examples to call application.exec() themselves now + that kjscmd no longer does this automatically. + + - Moved call that adds custom object bindings into the factory. + + - Changed the default context Object for the parts execute methods to be the + global object of the interpreter, and changed the default global object to + be the one defined in libkjs. + + - Added a new optinal argument to the runFile() method of the part (and the + load() method it is bound to) that allows you to specify the context object + for the executed script. + + - Removed the virtual for the overloaded version of the part's execute() + method. + + - Made the part add its own binding to the interpreter instead of getting + kjscmd to do it, this means that the methods will be available when the code + is embedded in apps as well as standalone. + + - Simplified the API for publishing objects. + + - Changed the publish() method to use the Object prototype. + - Simplified the addObject() method by using the factory properly. + - Renamed the publish() method to addObject() making the API + self-consistent (and made the code match). + - Fixed the design.h docs for the above. + + - Removed the createProxy() method that takes no context from the factory, and + replaced by making the context default to 0 on the overloaded + implementation. In many cases we were using because there was no sane + context to choose which indicates that the previous API was poor. + +2003-12-03 Wednesday 17:47 rich + + - Oops. Finish removing self binding class. + +2003-12-03 Wednesday 17:39 rich + + - Changed the default behaviour of kjscmd to /not/ call the exec() method of + the application. This method has available to scripts for some time now, and + the old behaviour forced scripts that called exec() themselves to include + convoluted work arounds. + + - Removed the mainwin option from kjscmd as scripts can now handle this + themselves. + + - Modified dumpCompletion() to use convertToValue(). + + - Removed the SelfBinding class as it is now unused. + +2003-11-30 Sunday 23:32 geiseri + + Merged CVS with local changes. + +2003-11-30 Sunday 23:31 geiseri + + Added test that agrivates odd bug where "this" gets trashed. + +2003-11-30 Sunday 23:31 geiseri + + Added QStringList -> KJS Array support. + Added QPen -> Bindings::Pen support. + +2003-11-30 Sunday 23:30 geiseri + + Added DCOP remoteFunctions, remoteInterfaces, + remoteObjects, registeredApplication. + +2003-11-28 Friday 20:30 rich + + - More work on using XSLT to generate the bindings. The code present at the + moment goes some way towards allowing us to move automatically from + doxygen's xml output mode to a set of JS bindings. + +2003-11-28 Friday 04:27 coolo + + kdebindings relying on kdesdk? Next century perhaps + +2003-11-27 Thursday 21:05 rich + + - Added some basic support for QScrollView illustrated by the imagetweak + example, which will become more feature-full in future. + + - Added the very incomplete beginning of support for generating bindings from + doxygen's xml output. + +2003-11-27 Thursday 19:43 rich + + - Moved the TODO list from the top-level directory to the docs directory. + +2003-11-27 Thursday 19:34 rich + + - Moved the methods that wrap events into a standalone class + JSEventUtils. This class is not used directly, instead there is now an + additional createProxy() method in the JSFactory. + + This change is a step towards adding some custom methods to enable us to + provide support for all the methods of the event classes, rather than just + the data members. + +2003-11-22 Saturday 23:20 geiseri + + Moved the dcop call and send into the custom bindings. + Rich im not sure if this is the correct location for these, but + they currently work. + + Added a demo to show off the new dcop stuff, requires + KWeatherService from kdetoys to be running, since i dont + know how to start a service from KJSEmbed yet. + +2003-11-22 Saturday 01:49 geiseri + + Added variable length args to K/QListView. + Added ability to handle Strings vs Pixmaps correctly. + Added native method for grabWidget on QWidget, this + may get moved to Pixmap when i figure out how to handle + a widget pointer. + +2003-11-22 Saturday 00:54 geiseri + + Make the compiler a little quieter by commenting out unused args in functions. + +2003-11-21 Friday 20:13 rich + + - Moved the native binding classes in builtins from the KJSEmbed::Bindings + namespace to the KJSEmbed::BuiltIns namespaces. Moved JSProxyImp from the + KJSEmbed::Bindings namespace to the KJSEmbed namespace. + + - Minor cleanups to SAX handling that make the code a bit easier to follow. + +2003-11-21 Friday 17:22 rich + + - Update the demo to work properly with the changes made to the names of the + widgets in the console a few weeks ago. + +2003-11-20 Thursday 20:04 rich + + - Renamed the 'global' object to 'Global' for consistency with web browsers. + + - Fixed some minor documentation error in the new builtin objects Ian added + (they're not QObject wrappers!). + + - Added basic support for loading files via the SAX api, a callback based + mechanism for processing XML. The implementation is far from complete, but + it is enough to let you load some XML without hastle. You can use the api by + calling saxLoadFile( Object, String ) which takes as parameters, the object + implementing the callbacks and the name of the file to be loaded. + + The callback methods that are currently working are: + + Boolean startDocument() + Boolean endDocument() + Boolean startElement( namespaceURI, localName, qName ) + - note that the attrs argument is missing. + Boolean endElement( namespaceURI, localName, qName ) + Boolean characters( chars ) + + For a more detailed look at what's going on with all this, check out the + example in docs/examples/sax. + +2003-11-20 Thursday 16:50 geiseri + + update the Todos so we know where we stand... still have to go back and check what is done. + +2003-11-20 Thursday 01:13 geiseri + + Fixed the index to show the actual functions. + +2003-11-20 Thursday 01:04 geiseri + + update readme + +2003-11-20 Thursday 01:03 geiseri + + merge with changes from head. + +2003-11-20 Thursday 01:02 geiseri + + Added a completion object for the KDevelop KJSEmbed support. + You can expose this via KJSEmbed's console via the raw() function + that behaves just like dump() only it returns an array instead + of a string. + +2003-11-19 Wednesday 21:55 geiseri + + Updated docs to reflect the latest API. These where generated with build-docs.js. Its starting to look like this might not be the best place to keep this stuff since we can now autogenerate it almost completely. Maby this will be the last update. + +2003-11-19 Wednesday 21:53 geiseri + + updated build-docs.js so that it now generates almost exactly what build-docs.sh does... only about 50x faster + +2003-11-19 Wednesday 14:47 geiseri + + This is a sucky fix, but it works... this function really needs a clean up + all these arrays screaming to be put out of their misery... + + any takers ;) + +2003-11-19 Wednesday 00:58 geiseri + + Added support for KIconLoader and KStdDirs so we can find junk in KDE. + Exposed : + findResource, addResourceType, kde_default, + addResourceDir, findResourceDir, saveLocation, + makeDir, exists, realPath + BarIcon, DesktopIcon, SmallIcon, MainBarIcon, UserIcon + +2003-11-19 Wednesday 00:53 geiseri + + Updated docs for latest code in cvs. Has new StdDirs and StdIcons stuff. + Added SQL docs. + +2003-11-18 Tuesday 19:02 rich + + - Fixed the image fun example. You can now pass pens around. + +2003-11-18 Tuesday 18:16 rich + + - Minor change to debug output and an increase in the maximum number of args + to slots. + +2003-11-17 Monday 19:20 rich + + - Added a mention of the scribble demo + +2003-11-16 Sunday 02:23 geiseri + + yay we can now populate a KListView from an SQL query... maby we need to put in a better demo app ;) + +2003-11-16 Sunday 02:04 geiseri + + hrmmm it seems that implantQVariant dosent work as i thought it should. it seems once that is fixed things may + work a bit better. + +2003-11-16 Sunday 01:36 geiseri + + Fixed the QPainter crash, it seems i had a booliean mistake + Added QVariant insertion support for DCOP... this still crashes, but gets further. + +2003-11-14 Friday 22:48 rich + + - Fixed a problem in StdDialog where the bindings were returning strings that + told you 'this is null' rather than the real null value when the file + dialogs were cancelled. This error caused bad behaviour in the xmlgui demo. + + - Improved the type handling of the JSFactory class. + + - The mapping between typenames and proxy types now supports all the proxy + types. This is essential if we are to support creation of non-QObject + proxies properly. + + - Removed the 'special case' code that handled identification of classes + supported by QWidgetFactory. + + - You can now remove support for particular classes by calling addType() and + specifying the proxy type TypeInvalid. I'm not sure how useful this is, + but we may as well allow it since it is trivial to implement. + + - Split the code that adds the types into one method for each type of + object. + + - Added some new JS methods to the Factory: + + - isSupported(String) + Returns true iff the specified type is supported by the factory. + - types() + Returns an array naming all the types supported by the factory. This + list includes objects which can be wrapped but not created unlike the + constructors method. + + - The methods now use QString rather than QCString to avoid needing lots of + charset conversions as these are an expensive operation. + + - Added a new method addObjectTypes() that is responsible for telling the + factory about all the QObject types it knows about that do not have any + sort of custom bindings. The list of currently unsupported types was + created by the scripts and data files in docs/examples/coverage/. + + - The readFile() method now throws an exception when the file cannot be + loaded. + +2003-11-14 Friday 18:40 rich + + - Fixed the imageviewer example. + + - It now loads the image specified on the command line rather than + hard-coding the name. + + - Restructured the code so the water color operation is a function. + + - Changed the code so it no longer uses return outside of a function (this + is invalid js and causes a warning from the interpreter). Instead, we use + throw which lets us send a message up the call stack to whatever invoked + us. This is a nice technique as it means things will work properly both + standalone, when we're called from another script and when we're called + by something that embeds the kjsembed part. + + - Added a new binding to the System class that lets you call exit. This is + needed because the kjscmd tool is currently calls exec() automatically. It's + a band-aid rather than a real fix, but it will give us time to decide on the + best solution to the problem. + + - System.exit() Exits with the status code 0 + - System.exit(Number) Exits with the status code specified. + + - Added support for the QLayout classes QHBoxLayout and QVBoxLayout. In + addition to the slots and properties, the following custom bindings are + available for box layouts: + + - addWidget + - addSpacing + - addStretch + - addLayout + + The creation code is current ifdef'd out as there are some problems, but the + methods are available to layouts created elsewhere. + +2003-11-14 Friday 06:08 faure + + CVS_SILENT -I.. should be before all_includes + +2003-11-11 Tuesday 19:27 geiseri + + yay more crashing test cases :) + +2003-11-10 Monday 23:33 geiseri + + nice little test to crash dcop with :) + +2003-11-10 Monday 23:12 geiseri + + fixes for dcop so it actually gets to the point of crashing, added a pen type + +2003-11-10 Monday 23:11 geiseri + + Yay we can now officially do SQL queries... we really need a SQL cursor though to make it + realy useful. + +2003-11-10 Monday 23:10 geiseri + + Tried to get further, you can now set a pixmap, still cannot change it, no clue why... + Added a pen type, it wont marshall properly, more type fun rich :) + + we crash when you do a drawText() it seems the qstring's dptr goes invalid... yeah thats cool + +2003-11-10 Monday 23:09 geiseri + + Fixed a few things, we can now attach, and call commands, but now im getting the same issue we + have in painter. Things crash when reading a QString that has been passed in... not sure why + rich you have ideas? + +2003-11-01 Saturday 11:34 rich + + - Attempt to fix problem with geiseri's SQL code. + +2003-10-30 Thursday 20:20 rich + + - Moved the factory method implementations from JSBuiltInImp to + JSFactoryImp. The previous location was a mistake and made no sense at all. + + - Fixed the handling of KParts - the object was being registered incorrectly + which meant things were totally borked. + +2003-10-30 Thursday 20:01 staniek + + retval fixed + +2003-10-30 Thursday 19:29 rich + + - Split the JSValueProxy into two in order to solve the problem that QObject + wrapper classes were broken by the increasing type-safety of the code. + + - JSValueProxy now handles variant proxies and nothing else. + - JSOpaqueProxy takes over the handling of opaque pointer proxies. + + - Fixed the slot return code to fall back to the opaque type if the return + type is a pointer, but is not known by the factory as a QObject. + + - convertToValue() now returns Undefined() for invalid QVariant values and + unsupported types. This prevents scripts incorrectly reporting that the + method was successfull. + + - NOTE: These changes have fixed the problems that were occuring with QObject + wrapper types. + +2003-10-30 Thursday 17:57 rich + + - Made the remaining methods use the new naming code made possible by the + InternalFunctionImp code. This means that all the methods implemented in + native code now behave properly. The new code for adding the methods to + their parent objects is table driven which should make it easier to + maintain (or at least so I hope). + + The methods that are wrappers for slots still need to be changed to use the + new code properly. + + - Removed the old ChangeLog stub (the real thing is in the docs directory). + + - Added d pointers to anything that didn't have one. + + - Removed the remaining createImp() methods because since the code was + refactored to remove the misuse of the part's imp they're a unnecessary + blight on the API. + + - Removed some TODO items that have been implemented. + +2003-10-29 Wednesday 19:32 rich + + - Changed the base class of JSProxyImp from ObjectImp to the newly public + InternalFunctionImp (the internal here refers to the fact they are native + code rather than JS). This change fixes the problem that scripts could not + properly inspect the methods (for example instanceof was broken). The + InternalFunctionImp constructor requires an ExecState, so a few incidental + changes were required to accomodate this. + + NOTE: This change requires the patch to KJS that I just committed. + + - Added some missing d pointers. + + - Improvements to doc comments. + +2003-10-24 Friday 21:30 rich + + - Added a new class JSBuiltInImp that implements the bindings for the methods + defined by JSBuiltIn. Moved the code for these bindings out of the part imp + into the new class. + + - Minor cleanups to the initialisation of the builtins. + + - Improved class docs. + + - Made a couple more methods return exceptions instead of Null on + errors. These error types need to be centralised somewhere, perhaps in the + JSBuiltIn class. + +2003-10-24 Friday 20:13 rich + + - Added some properties to the KPart that let scripts query the version of + KJSEmbed they are running in. + + - Improvements to the XMLActionClient class. + + - Removed the XMLActionRunner member from the kpart because the default + runner is now an opaque class and you can do what you need via the + XMLActionClient. + + - Fixed a potential crash in XMLActionClient (caused by the bad choice of + semantics when changing the runner). + + - The actions are now deleted with the action client, this prevents a crash + when an action that was left behind is invoked. + + - Added a copy constructor to XMLActionScript to ensure the semantics are + sane. + +2003-10-24 Friday 19:01 rich + + - Added a new class JSFactoryImp which implements the constructors for + JSFactory. This is rather better than stuffing all this stuff into + KJSEmbedPartImp as we did before. + + - Renamed some of the public classes to add the js name prefix. + - factory.h/.cpp -> jsfactory.h/.cpp + - securitypolicy.h/.cpp -> jssecuritypolicy.h/.cpp + + - Moved JSProxyImp into its own file. + + - Moved the handling of JSBuiltIn from the factory to the part. This change + makes the logic make more sense, and removes a couple of methods that only + existed to work around the previous location in the factory. + +2003-10-23 Thursday 19:26 rich + + - Started moving the builtin objects out of the factory and into a standalone + class JSBuiltIn. The part will ultimately be responsible for managing the + JSBuiltIn class which should simplify the factory (useful when we have + multiple factories). + + NOTE: Access to the QObject-based wrapper objects is broken at the + moment. This is a known issue and is being addressed, but as things are being + restructured a bit fixing it will have to wait so I don't have to do it twice. + +2003-10-18 Saturday 19:43 rich + + - Began adding support for non-QObject ptr types. + + - The part no longer inherits XMLActionRunner, instead there's an internal + class that binds the two together. This makes the class hierarchy a lot + cleaner and reduces the linking between the xml action handling and kjsembed + which are really fairly distinct. Possibly this separation should go even + further and the part should avoid automatically creating an XMLActionClient + now that scripts can do this themselves. + + - Made some of the methods of the factory object take 'const QString &' rather + than 'QString'. + + - Reworked the handling of the JSFactory object. The factory is now a propery + of the kpart rather than being global. This means that applications can have + multiple active parts, each with their own factory. This change has required + changes throughout KJSEmbed: + + - Changes to allow the static js objects to know which factory they should + be using. + + - Changes to the proxies so they know which part they use rather than just + which interpreter. This has required changes all over the place, but + better now than later. + +2003-10-18 Saturday 16:16 geiseri + + imageviewer with nifty watercolor effect now. + +2003-10-18 Saturday 15:32 geiseri + + More updates to the SQL support. Changed the name to make it more clear + that it was SQL. Still cannot get SqlDatabase.exec() to return a real + query, even thought the database says its all good. + +2003-10-17 Friday 21:52 rich + + - Removed the createSubProxy() method of JSObjectProxy and made the JSFactory + take over this operation completely. + + - Made a create() method in the factory that returns a pre-wrapped + object. This method also throws a JS exception if creation fails instead of + needing the client to check the return value. + + - Removed support for the create() method that early scripts used to + instantiate things, now you must always use new to create objects. This + method was only ever introduced because I hadn't figured out how to define + proper constructors, so no one should really miss it. + +2003-10-17 Friday 17:50 rich + + - Moved the kjsconsole plugin into its own directory. This has been requested + by people working on a couple of apps that would like to use the code. This + is a good idea anyway because it makes the separation between the core of + kjsembed and the clients clearer. + + - Fixed a few unused parameter warnings. + +2003-10-17 Friday 17:26 rich + + - Moved builtins to a new directory. This isn't really needed yet, by doing it + now we avoid lots of pain later. + + - Improved support for QTimer. + + - You now have access to the start(), stop() and isActive() methods. + - Added an example that uses the new timer support. + +2003-10-17 Friday 10:57 rich + + - Removed kpublished as it is unnecessary and seems to be unmaintained. + +2003-10-11 Saturday 20:05 rich + + - Extended the code for dumping slots so the output includes the return type. + + - Added a debug area (80001) to the list in kdecore and changed all the debug + messages to use it. + + - Added the ability to tell the factory that particular class names are + qobjects and made the creation code call it when it creates an object that + is an instance of an unsupported class. Note that this code does not + understand namespaces, so you need to explicitly qualify everything for it + to work properly. + + - Changed the addConstructors method of the factory up so that it uses the + fully qualified names for the bindings classes. + + - Changed the jscript() method of the console widget to use the qualified + name for the part. + +2003-10-11 Saturday 16:26 rich + + - Fixed code for implanting Qt types in unsupported signatures. The code was + ignoring the index of the parameter. + + - Improved slot parameter support. + + - Abort on the first unsuppored type so we don't waste time if we're already + stuffed. + + - If the parameter type is a pointer and the passed value is a proxy we now + pass the value to the slot. Hopefully this will work for both + JSObjectProxy values and for opaque values. + + - If the parameter type is supported by QVariant and the passed value is a + proxy we should now support that too. + +2003-10-11 Saturday 15:32 rich + + - Began to add some flesh to the JSProxy class. + + - Added a bunch of methods to handle the type conversions and tests + cleanly. Used these to centralise a whole bunch of down-casts making the + rest of the code a lot more readable. + + - Added an implant method for proxy classes. This method will make it possible + to pass QObjects, opaque values and unsupported variant types as parameters + to slots. + +2003-10-09 Thursday 21:14 rich + + - Made the arguments passed around during slot invocation a lot simpler. We + now pass around the slotimpl itself rather than all of the members it holds. + +2003-10-09 Thursday 20:41 rich + + - Did some tidying up of the slot handling code. + + - Removed unused JSObjectProxyImp constructor. + + - Lots of work on handling slots that return pointers. Slots that return types + supported by QWidgetFactory now work, adding support for the other QObject + types will be pretty simple at this point. The code really needs to be a lot + more generic - rather than asking the factory if the object is a QObject, it + should be asking the factory if there is a wrapper available for the class. + + - Did most of the grunt work required to handle slot pointer return types + properly. At the time we bind a slot we extract the return type from the + metaobject, the classname we obtain is stored in the slot binding + implementation. + + - Extended the slot invocation stuff to use the addition information about + the return type we've now stored. + +2003-10-08 Wednesday 20:37 rich + + - Added some notes to the TODO file that show how we can extract the return + type of a slot that returns an object from the metainfo. + + - Tidied up and documented the console widget class. + + - Removed the clear button Ian added. I really don't think this fits very + well as it removes the correspondence with a normal console. I've added an + access to for the hbox that arranges the entry fields to make it possible + for client class to do this sort of thing themselves if they feel it is + needed. This accessor also lets you use the console widget in a + non-interactive fashion as you can hide the entire entry section. + + - Initialised proc to 0 and made the child handling slots back into slots so + that the process invocation code will work properly. + + - Changed the names of the child objects to be lower-case for consistency + with everything else. + + - Moved the popup title out of the d pointer object since we're not + retaining b/c for kjsembed this release. + + - Set both large and small WM icons. + + - Updated result handling code to use the facilities the part provides now. + +2003-10-02 Thursday 02:11 geiseri + + added the abilty to clear the cmd line with a button... not sure if i like this operation yet.... maby clear + should clear the log, and when you execute a command the line should get cleared. going to play with this for a + while + +2003-10-02 Thursday 02:01 geiseri + + Added support for the javascript mime type. + Added desktop file so clicking on a js script will execute it... NOTE: im not happy about this but i cannot + figure out how to get it to open in a text editor when its chmod -x and kjscmd when its +x... ideall this will + be fixed in the next few days or ill disable the kjscmd desktop file. + +2003-09-28 Sunday 13:30 geiseri + + start of port ob build-docs.js to kjs + +2003-09-27 Saturday 20:37 geiseri + + updated the docs to reflect the new members + +2003-09-19 Friday 19:58 rich + + - Improved the System class API: + + - Added new method bool writeFile( filename, text ). + - Renamed System.stdin etc. to System.in, System.out and System.err. + - Fixed examples for the new names. + + - Started adding support for classes. The first stage here has been to add + (somewhat messy) support for associating enum values with the correct + type. This means that rather than having to reference these values via the + class instance, you can say things like: + + var f = new QFrame(); + f.frameShape = QFrame.WinPanel | QFrame.Sunken; + + It is important to note that with the current code, the enum values are not + available until after the first instance of the specified type has been + created. + + - Moved EventType back into the cpp class as it is only used internally. + +2003-09-18 Thursday 19:35 rich + + - Added a new class JSProxy to be a baseclass for JSValueProxy and + JSObjectProxy. + + - Moved the event handler mapping code into a standalone class JSEventMapper + which will be its final location. Added various methods etc. to make this + work with everything else. + + - Added a new example that creates a complete KDE mainwindow with all the + standard menus and toolbar using the KStdAction bindings and XMLGUI. This + example also shows how you can wire a KAction to a JS function using the + slot support by adding proper support for the file open action. + +2003-09-18 Thursday 18:36 mueller + + unbreak compilation. I wonder why I waste time on fixing it if the + fixes get reverted anyway. + +2003-09-18 Thursday 16:58 rich + + - Fix geiseri's code from last night. + + - Fix Makefile.am to work properly. + +2003-09-18 Thursday 15:48 rich + + - Minor updates + +2003-09-17 Wednesday 22:13 geiseri + + workarround for Qt bug where moc cannot handle ',' any more... + +2003-09-17 Wednesday 21:38 geiseri + + crackrock EVERYWHERE! im going to bed... + +2003-09-17 Wednesday 21:33 geiseri + + god dammnit, i obviously cannot code anymore this evening... + +2003-09-17 Wednesday 21:09 geiseri + + Added start of bindings for a KConfig object. + this is mostly untested, but it compiles so we can start to debug it. + +2003-09-17 Wednesday 01:43 geiseri + + im sure rich really dosent want credit for this sucker ;) + +2003-09-17 Wednesday 01:41 geiseri + + Added SQL Database and Query bindings. + Known issue is with Database::exec(); This returns a Qt SQL Query. I added what I thought was the + correct constructor to Query() so that we could handle it from JS, but it keeps responding that the query + is a null type. Rich what is the correct way to handle these types? Once this is resolved we can start + on the more advanced SQL features. + +2003-09-17 Wednesday 01:37 geiseri + + Added demo of SQL features. We can now connect to the database, but there are some issues with the + query. + +2003-09-16 Tuesday 01:26 geiseri + + Added support for QMovie so we can spice up our boring GUIs... + +2003-09-15 Monday 22:52 geiseri + + fixed Painter::drawText to really draw text + added: + void drawArc( ... ); + void drawPie( ... ); + void drawPixmap ( ... ); + void drawImage ( ... ); + void drawTiledPixmap ( ... ); + + void scale ( ... ); + void shear ( ... ); + void rotate ( ... ); + void translate ( ... ); + to Painter + +2003-09-15 Monday 20:18 geiseri + + changed image viewer to apply some effects. + +2003-09-15 Monday 20:17 geiseri + + Moved image_imp from a QImage * to a QImage value. + Added image effect members to pixmap_imp + Added image effect members to image_imp + + These need more testing but just a simple test seems to pass and look good. + + +2003-09-15 Monday 19:07 rich + + - Added 3 new methods to the KPart that provide access to the defined + constructors. These replace the dumpConstructors() function in + jsbindings.h which has been now been removed. + + QStringList constructorNames() const; + KJS::Value constructors() const; + KJS::List constructorList() const; + + - Moved some methods of the part so they are no longer slots since it + seems that returning non-ptr, non-variant types like KJS::Object + through a slot isn't going to work due to limitations in moc. The + same limitations apply to properties unfortunately. + + - Added more debug info. + +2003-09-15 Monday 17:04 geiseri + + Added support for the following events: + QKeyEvent, QWheelEvent, QFocusEvent, QPaintEvent, QMoveEvent + QResizeEvent, QCloseEvent, QShowEvent, QHideEvent, and QIMEvent. + + These need to be tested and it should be noted funcitons that return void, are not currently implemented. + + +2003-09-14 Sunday 18:18 rich + + - The events are now defined using an array, this makes it much easier + to maintain and to add support for new event handlers. + + - Added a binding to QApplication::exec(). If this works ok, I think I + should probably make no-exec mode the default and leave the decision + entirely up to the script. This would mean I'd need to add a -exec + option to allow you to use the console widget with non-graphical + scripts. + + - Various clean ups. + + - Added support for the QObject className() method to the object + proxy, and an extra method superClassName() that queries the + metaobject. + + - Note that I'm still working on the 'no default value' problem. + +2003-09-11 Thursday 18:30 rich + + - Rename the new factory to avoid the reserved word. + +2003-09-11 Thursday 05:45 rich + + - Doh, forgot the code + +2003-09-10 Wednesday 20:20 rich + + - Added support for some more of the QMouseEvent class. + state() + stateAfter() + globalX() + globalY() + + - Fixed some of the KMainWindow method bindings which were totally + broken. These bugs explain why a number of things I was trying to + write never worked. + + - Added a binding to KStdAction. This lets you create instances of any + of the standard KDE actions from scripts. For example, you can write + the following: + + var act = StdAction.quit( recv, slot, parent, name ); + + Note that at the moment the receiver and slot cannot be a JS object + and method, they must be a slot defined in C++. + + - Added an example to docs/examples/actions/ + + +2003-09-06 Saturday 17:36 rich + + - Added getParentNode() to the DOM api. + + - Added implementation of KJS::Identifer::qstring(). + + - Added the JSObjectEventProxy class. This class forwards Qt events to + javascript handler methods. This means you can now write scripts + that handle events! + + The basic method it uses is to install an event filter for the + target of the JSObjectProxy it is created for and test if any events + the target receives should be forwarded using a bit array. If the + event needs forwarding it looks up the name of the handler and calls + it, if not then processing occurs as normal. + + The creation of the event proxy is handled by the object proxy which + overrides the set property handling in ObjectImp to detect when a + script assigns to a method that is an eventhandler. The event proxy + is created the first time this happens (and is deleted when the last + handler is removed). + + In order to implement the scheme described, there needs to be a + both a mapping between handler names and QEvent::Type, and a mapping + between the type and the handler. The first is used to determine + if assigning to a property should cause any event types to be + forwarded (and which types they are), the second lets the event + filter know which js method it should call. + + In addition to supporting the standard event handlers needed to + write Qt/KDE wrappers, this code is intended to support weird + compatibility stuff like kaxul. :-) This requirement means we need + to allow for the possibility of custom event types, events mapping + to custom handler names, and also custom signatures in event + handlers. The same difficulties occur when support for custom + QEvents is considered. This side of things is very much a work in + progress. + + At the moment both mappings are stored in the factory object, but + I'm not convinced this should be their real location. If anyone has + any thoughts on this, then please let me know. The other big + question is the time at which names should be resolved to + (hopefully) callable objects. + + +2003-09-03 Wednesday 17:02 rich + + - Added bindings to KColorDialog and KPropertiesDialog to StdDialog. + + - Moved StdDialog binding code from the factory to the class itself. + + - Added support for creating QScrollView and QCanvasView widgets. + + - Added support for KMainWindow::createGUI(). + + +2003-08-27 Wednesday 18:37 rich + + - Fixed tree example (I added a sh-style comment) and added a better + demo ui file. + +2003-08-27 Wednesday 18:24 rich + + - Added binding to isWidgetType(). + + - Added an example that generates a graphical tree of the QWidget + hierarchy. + + - Fixed const warning in convertToValue(). Various other irritating + const fixes. + + - Added support for enums! This means that you can now use enums that + have been declared using Q_ENUM in scripts. The enums are published + as properties of the object itself for now, rather than the class + (this will be fixed). This means that for now you do things like + this: + + f = new QFrame(); + f.frameShape = f.Panel; + + - Added a new demo 'frame' that illustrates QFrame and enum support. + + +2003-08-27 Wednesday 14:30 geiseri + + made the slot invoke a little smarter. we now have both the old and new methods to keep everyone happy. + +2003-08-26 Tuesday 20:10 rich + + - Moved code for adding custom functions to the corresponding imp + class. + + - Added context information to convertToValue() so that we can ensure + the security policy is followed. Without this change, proxies that + are created by this method will revert to the default policy. This + fixes the security hole I referred to earlier. + + - Added a binding to JSValueProxy that returns the name of the + contained type. + + - Added a new native binding StdDialog that will provide an easy way + to access the common KDE dialogs. This class is far from complete at + the moment. + + getOpenURL(...) + getSaveURL(...) + getExistingDirectory(...) + getOpenFileName(...) + getExistingURL(...) + getImageOpenURL(...) + getSaveFileName(...) + + +2003-08-21 Thursday 19:45 rich + + - Added a factory method for proxies that are explicitly published. + + - Renamed some ExecState params called 'state' to 'exec' for + consistency and reordered some method args for the same reason. + + - Moved the JS method load() out of the factory object and into the + global namespace. + + - Added an example showing how to write scripts that span multiple + source files. + + +2003-08-21 Thursday 18:36 rich + + - Modified the JSFactory class so that it is no longer used via static + method calls. These changes have been made so that host applications + can define custom factories. There are more changes to come in this + area, so please don't use on it yet. + + - Moved creation of sub-proxies to the factory. + + - Something seems to have broken the listview example. I'm not sure if + it is one of my changes, or if it's the generic slot support geiseri + added. + + +2003-08-18 Monday 23:48 geiseri + + Variable length slots now work for the currently known types. Things seem + to pass the old tests, and some new dcop tests now pass. QVariants still + need to be handled. I leave for my flight in 17hours so im not optimistic + ill get in one more commit. Rich please dont try to clean this up yet, as + ill probibly work on it before i get net access on thursday. + + +2003-08-18 Monday 23:46 geiseri + + Make this work with Qt 3.2... not sure if this has bad side effects yet, + please test. + + +2003-08-18 Monday 15:40 rich + + + drawRoundRect(). + + - Added a new example that illustrates support for KListView. + + - JSValueProxy instances that contain a QVariant can now be converted + back to QVariant. + + - Moved JSValueProxy out of the Bindings namespace. + + - Added a new example that tests the support for opaque values. + + - Did a bit of work on the Painter binding, still doesn't work + though. :-( + + - Added support for opening files (ro/rw) a TextStream is returned. + (currently commented out as it is flawed). + + +2003-08-18 Monday 13:39 geiseri + + it helps rich to debug it if he has the same code. + +2003-08-17 Sunday 11:46 rich + + - Added a new class JSValueProxy which provides an opaque binding to + either a QVariant or a void pointer. + + - Extended the property handling code to automatically generate opaque + bindings for unknown types. + + - Added a new method Factory.widgets() that returns a list of the + widgets supported by QWidgetFactory. + + - Added support for pointer slot return values. + + +2003-08-16 Saturday 18:33 rich + + - Moved the implementations of the custom methods (ie. those that are + not slots) to their own class. + + - Documentation + + - Made the built-in objects use the default Object prototype for their + KJS::Object. + + +2003-08-16 Saturday 17:16 rich + + - Added some more doc comments. + + - Added support for slot signatures needed by NetAccess: + + slot(const KURL&,const QString&) + slot(const QString&,const KURL&) + + +2003-08-16 Saturday 16:48 rich + + - Minor cleanups of the kpublished code. + + - Cleaned up the factory's create methods. There is now one for each + type of object created. + + - Fixed NetAccess (I was too enthusiastic in converting stuff to + KURL). + + +2003-08-16 Saturday 15:52 rich + + - Modify KIO::NetAccess binding to use KURLs now we support the 2 + argument variant. + + +2003-08-16 Saturday 15:42 rich + + - Added support for slots that take 2 kurls. + + +2003-08-16 Saturday 15:01 jowenn + + A modified dcopidl* toolchain for restricting which slots should be published to kjsembed. It's quite generic from the idea, so it should be usable with any other script language too. It's a first try/begin though, so it doesn't do much yet except for the test also committed I hope to get signal restrictions to work too and fix some compatibility problems with Qt's moc + +2003-08-16 Saturday 14:41 rich + + - Added support for a 4 argument for of createROPart() to allow you to + specify custom constraints for the KTrader query. + + +2003-08-16 Saturday 13:48 zrusin + + Fix implicit casts. + +2003-08-15 Friday 19:53 rich + + Update changelog and docs + +2003-08-15 Friday 19:46 rich + + - Ensure we add the args array to the application object even when it + is empty. + + - Improved the readonlypart demo to be proper browser (ie. make links + work). + + - Improved factory creation code. + + +2003-08-15 Friday 18:45 rich + + - Added support for creating read-only KParts. + + - Added an example that displays the KDE homepage in a KHTMLPart. This + example also shows the use of the main window bindings. + + +2003-08-15 Friday 18:08 zrusin + + Use new instead of app.create and a few path fixes. + +2003-08-15 Friday 17:55 zrusin + + Make the new call work with NetAccess + +2003-08-15 Friday 17:49 rich + + - Added compatibility with KDE 3.1 so I can actually use this stuff! + + - Minor cleanups to the examples. + + +2003-08-15 Friday 09:13 zrusin + + Don't crash when creating widgets/dialogs from ui files (and use more + sensible way of detecting kjscmd) + +2003-08-15 Friday 04:59 zrusin + + Adding KIO::NetAccess binding. So now from within scripts you can do: + var net = application.create( 'NetAccess', 'net' ); + net.download( 'http://www.kde.org/media/images/kde_logo.jpg', '~/logo.jpg' ); + To download anything you want. It be cool if one could disable the progress + dialog for netaccess. + +2003-08-14 Thursday 22:00 rich + + - Added some more slot signatures: + + - slot(const QString &,uint) + - slot(const QString &, bool) + - slot(int,const QColor &) + - slot(int,int,int,int,int) + - slot(const QPixmap&) + - slot(const QRect&,bool) + - slot(const QString&,bool) + - slot(const QString&,bool,bool) + - slot(const QString&,int,int) + - slot(int,const QColor&,bool) + - slot(int,const QColor&) + - slot(int,int,float,float) + - slot(const QString&,bool,bool,bool) + + - Added a utility method for getting the QWidget in a proxy. + + - Added support for QPixmap properties. + + - Added imageviewer example. + + +2003-08-14 Thursday 19:07 zrusin + + Yeah, real funny + +2003-08-14 Thursday 19:02 zrusin + + Correct makefile for a static lib. + +2003-08-14 Thursday 18:02 rich + + - It helps if we actually make the QString,QString slots available to + the JS interpreter... + +2003-08-14 Thursday 17:57 rich + + - Added a JS prefix to a couple of classes. + + - Added support for slots with 2 string arguments + + +2003-08-14 Thursday 14:39 rich + + - Add support for the full loadui command including the connector. + +2003-08-14 Thursday 14:16 rich + + - Make kawil happy by fixing the parent argument to loadui. + +2003-08-13 Wednesday 15:58 zrusin + + Adding bindings as a subdir dir. Fixing the non-working implicit cast of + QString to const char* to make it compile. + Rich are sure the bindings lib should be installable shared lib, and not + a static, non-installable one? + + +2003-08-12 Tuesday 18:06 rich + + Oops + +2003-08-12 Tuesday 18:03 rich + + Moved to bindings/ + +2003-08-12 Tuesday 17:57 rich + + - Moved the QObject classes that only exist to provide bindings into a + new directory. This will hold all the classes that exist only to + provide a binding. + +2003-08-12 Tuesday 17:02 rich + + Grr, i fucked this up again + +2003-08-12 Tuesday 16:29 rich + + - Added calculator example + +2003-08-12 Tuesday 16:24 rich + + - Factory can now create KMainWindow. + + - Added binding methods to KMainWindow. + - setCentralWidget() + - actionCollection() + + - SlotUtils is no longer used by inheritence, woo hoo! + This means that apps will be able to extend it soon. + + +2003-08-08 Friday 01:04 staikos + + This thing really hampers Konqueror startup time, and it provides nothing of + value to konqueror itself. Any solution, rich? Do we really need it? + + +2003-07-30 Wednesday 18:52 rich + + + - Added support for calling slots with signatures uint, long and ulong + as methods. + + - Added support for connecting signals with unsupported signatures to + JS methods. Note that currently *none* of the arguments will be + passed to the script in this situation. + + - Minor fixes to docs. + + - Added an example 'connect' that shows how the most common types of + signal can be connected to JS methods. + + +2003-07-29 Tuesday 17:34 rich + + Try make things work for jowenn + +2003-07-28 Monday 08:39 mueller + + unbreak compilation (gcc 3.4+) + +2003-07-28 Monday 08:38 mueller + + I don't know how this code is ever supposed to compile, but at least it + will produce the .moc files correctly. + +2003-07-27 Sunday 20:25 rich + + - Added d pointer to SlotUtils. Constructor and destructor no longer + inline, this should make compatibility easier. + + - More doc improvements. + + - Removed the overloaded openURL() method that takes a string as we + support KURL parameters now. + + - Started implementing support for connecting signals to Javascript + functions. The code for this is mostly in the SlotProxy class. + + - Modified the docviewer example to make use of the JS slot + support. This example now works pretty much the way it is intended + too! + + +2003-07-27 Sunday 18:00 mueller + + unbreak compilation (gcc 3.4+) + +2003-07-27 Sunday 18:00 mueller + + libkjs is not in my kdebindings + +2003-07-27 Sunday 16:19 rich + + - Fixed Makefile.am problem. + +2003-07-26 Saturday 22:32 rich + + - Removed the default value of 0 for the wparent of one of the + KJSEmbedPart constructors. This means that the defaults no longer + trigger the crash-on-exit bug. + + - Made createInterpreter() protected because calling it twice calls a + memory leak and there's no need for apps to use it anyway. + + - Added an accessor for the completion object of the last script. + + - Renamed executeScript() to runFile(), and loadScript() to loadFile() + to make the semantics clearer. + + - Replaces some overloaded methods with default arguments. + + - Fixed the 3 argument version of connect to match Qt, and tidied up + the way connect is processed. Matching changes for disconnect. + + - Added support for the slot signatures: + + - int,int,int,int,bool. + - QRect, bool + + +2003-07-26 Saturday 17:51 rich + + - Made the makefile put the changelog in the docs dir + +2003-07-26 Saturday 17:44 rich + + - Moved low-level slot handling into a standalone class SlotUtils that + JSObjectProxyImp inherits. This makes the code a lot easier to work + on as the JS glue and the Qt glue are no longer stuck together. + + +2003-07-26 Saturday 17:09 rich + + - Documentation updates + +2003-07-26 Saturday 16:49 rich + + - Added links to QSA and a tutorial on inheritence in JS. + +2003-07-26 Saturday 16:35 rich + + - Added some information about planned changes. + +2003-07-19 Saturday 16:47 rich + + - Removed kspy dependency + +2003-07-18 Friday 20:39 rich + + - Added constructors for the Painter object. + + - Added a new binding Pixmap that provides an interface to QPixmap. + + - Removed duplication of the BindingObject construction code. The + custom binding objects now use the same code as the classes defined + by QWidgetFactory. + + - Removed test signals and slots from the kpart. + + - Added support for widget classes to the script that generates the JS + API reference. This means the reference manual now includes every Qt + and KDE object available! + + - Started writing a JS documentation viewer. + + - Started adding support for custom methods: + + - jsobjectproxy.cpp Added insertItem method for QListBox + - jsobjectproxy_imp.cpp + - jsobjectproxy_imp.h + + - Cleanups + + - kjsembedpart.h Tidy the code up and document + - kjsembedpart_imp.cpp Added a new method constructors that + - returns an + array of constructors. + - kjsembedpart_imp.h + - pixmap_imp.cpp Added pixmap property + - pixmap_imp.h + + - Improved docs + + - docs/index.html Added link to mozilla js language page + + - Improved access to bindings + + - factory.cpp Added constructors() + - jsobjectproxy.h Added addBindingCustom() + + - Converted state -> exec for some more functions. + + - Added some custom bindings for useful widgets. This code needs + cleaning up more before it is ready for prime time. The methods + added are: + + QListBox::addItem() + KListView::addColumn() + QListView::addColumn() + KListView::insertItem() + QListView::insertItem() + + - Started writing a new example that provides a documentation browser + for KJSEmbed. + + +2003-07-11 Friday 21:43 rich + + - Added constructors for the Painter object. + + - Added a new binding Pixmap that provides an interface to QPixmap. + + - Removed duplication of the BindingObject construction code. The + custom binding objects now use the same code as the classes defined + by QWidgetFactory. + + - Removed test signals and slots from the kpart. + + - Added support for widget classes to the script that generates the JS + API reference. This means the reference manual now includes every Qt + and KDE object available! + + +2003-07-10 Thursday 20:35 rich + + - Added a document that describes the types used to pass data between + Qt and scripts. + + - Improved the documentation front page and stylesheet. + + +2003-07-10 Thursday 17:56 rich + + - Fixed links to examples. + + + - Minor doc changes. + + +2003-07-05 Saturday 20:43 rich + + - Added support for getting the values of rect, size and point + properties. The values are returned as arrays, the types are as + follows: QRect -> [x,y,w,h], QSize -> [w,h], QPoint -> [x,y] + + - Changed the prototypes of a couple of methods that extract values so + they take a KJS::ExecState parameter. This is required for us to + create arrays etc. in order to return complex values. + + - Began renaming the KJS::ExecState variables to 'exec' rather than + 'state' for consistency with KJS. + + - Split the dumpObject() method into two, one that dumps the JS + properties, and one for the Qt properties. + + +2003-07-04 Friday 21:34 rich + + - Added support for passing sizes to slots. A size is represented + either as an array with two elements [width,height], or as an object + with the properties 'width' and 'height'. + + - Improved slot publishing code so that overloaded slots are + supported. The first slot is published as before, subsequent slots + with the same name get the number of arguments they require + appended. + + - Removed the childAt() and findChild() methods from the JSObjectProxy + object. The child() method provides the same facilities via a + unified interface. + + - Added some type information to the dump output. + + +2003-07-04 Friday 16:33 rich + + - Renamed the ConstructXXX constants to NewXXX. + + - Added support for reading Color, Font and KeySequence types. + + +2003-07-02 Wednesday 20:13 rich + + - Made slots() list slots with all signatures not just those we can + use as methods because we can connect to a slot even if the + signature is not supported. + + - Added signals() to list the signals emitted by an object. + + - Added signals and slots sections to the dump() output and + regenerated the JS API documentation. + + +2003-07-02 Wednesday 19:19 rich + + - Fixed problem with XMLActionClient caused by one of the previous + renaming exercises. + + - Added the ability to connect signals to signals. This is handled + transparently to the script, so you can simply treat the signal you + want to emit indirectly like the slots we already + support. Internally, the code will try for a slot first then try for + signal if that fails. This is ok because you can't have a signal and + a slot with the same name and signature. + + - Added a test program for the above, test_connectsignal.js. + + - Minor fixes to the tutorial. + + +2003-06-28 Saturday 21:09 rich + + - Added support both 3 and 4 argument forms of connect and disconnect. + + - Added a couple more examples. + + - Added support for creating QObject and QTimer. + + - Added some scripts to the docs directory that build a reference + manual for the JS API. Added the results too. + + +2003-06-28 Saturday 15:13 rich + + - Added support for disconnect + +2003-06-28 Saturday 14:03 rich + + Added test script for connect + +2003-06-28 Saturday 13:58 rich + + - Support for connect + + - You can now connect a signal defined by one QObject, to a slot + defined in another. + + - Improved the dump function: + + - Now lists qt properties in their own section. + + +2003-06-28 Saturday 10:51 rich + + - Remove accidental change to Makefile.am + +2003-06-28 Saturday 10:47 rich + + - Simplified the slot handling by moving the slot signature into a + separate variable. + + - Fixed a bug in the handling of child lookup by name (we always got + the first child irrespective of the name). + + - Simplified the various child lookup functions to be handled in one + place. + + - More simplifications of the process of implanting parameter values. + + - Protected slot invocation against being called with the wrong number + of arguments. + + - Update copyright dates. + + - More work on DOM support: + - Boolean hasAttribute( name ) + - Value getAttribute( name ) + - Boolean setAttribute( name, value ) + + +2003-06-26 Thursday 20:09 rich + + - Make DOM the primary implementation + +2003-06-26 Thursday 19:56 rich + + - Actually adding the bindings is likely to improve the user + experience. :-) + + +2003-06-26 Thursday 19:22 rich + + - Started adding a DOM API to the object tree. For now we'll start + with getElementById() to keep pmax happy. :-) + + +2003-06-25 Wednesday 18:17 rich + + - Fixed a bug left over from the regexp code. + +2003-06-16 Monday 21:02 rich + + Oops + +2003-06-16 Monday 21:02 rich + + - Added utility methods for marshalling common types and used them to + simplify the slot invocation code. + + - Removed a bunch of extraneous QRegExps. + +2003-06-16 Monday 20:10 rich + + - Split the addition of bindings for object proxy. + + - Added a stub class for QObject binding classes (the stub for native + bindings will arrive soon). + + - Added support for QVariant return values. + + +2003-06-16 Monday 11:36 staikos + + handle QString returns properly + also be more debuggable + +2003-06-15 Sunday 22:14 rich + + - Split up the slot invocation code to make it easy to work on. + + - Added support for slot return values. The following types are + currently supported: + + - bool + - int + - QString + - const char * + + - Improved the self-documentation facilities. + + - Improved the output of the dump() method. + - Added a classes() method that lists the available classes. + + +2003-06-15 Sunday 17:45 rich + + - Fixed the additional slot invocation stuff. + + - Updated changelog. + +2003-06-14 Saturday 23:10 rich + + - Publish the JSEmbedPart as the global property 'part'. + + - Added the ability to run code with a specified 'this' object. + The default is now to run things with a null this. + + - Added an accessor for the XMLActionClient. + + - Added support for more slot signatures: + + - mySlot(const KURL &) + - mySlot(int,int,int,int) + + - Improved console widget + + - Use KLineEdit and a KCompletion rather than a combo. + - Added a prompt label with a keyboard accelerator. + - QTextEdit -> KTextEdit. + - Pass the console widget the part rather than the interpreter. + + - Provide access to the default execution context, and the ability to + change it. + +2003-06-09 Monday 03:51 staikos + + Add support for QObjects that can self-bind JS methods. + Rich: this is more or less just a demo. It's not the ideal way for this to work + but I have not been able to find an alternative approach in JS or in C++. We + might be stuck with it. Please review. We can back it out later if a better + solution is available. Meanwhile, it solves my problem with StringBundle. + + +2003-06-07 Saturday 22:53 rich + + Added an example that displays a graphical tree + +2003-06-06 Friday 13:21 staikos + + argh was not supposed to revert the last change + +2003-06-06 Friday 13:19 staikos + + revert the asserts .. if people want to do this, let it crash + +2003-06-06 Friday 13:09 staikos + + delete the part on exit + +2003-06-06 Friday 12:33 staikos + + deparentification + + (don't crash) + +2003-06-06 Friday 00:44 staikos + + assert() the crash case in here so that a developer knows it will happen before + he gets very far + +2003-06-06 Friday 00:30 staikos + + directions on how to keep it from crashing if you don't realise what it does + with double parent objects in the constructor + + +2003-05-22 Thursday 17:34 geiseri + + Some fixes for makefile.am + +2003-05-22 Thursday 16:56 rich + + + - Fixed some problems with KJS::Identifier support. + + - Added a very basic QPainter binding for drawing on QPixmaps. The following + drawing operations are supported: + + - void moveTo( int x, int y ); + - void lineTo( int x, int y ); + - void drawPoint( int x, int y ); + - void drawLine( int x1, int y1, int x2, int y2 ); + - void drawRect( int x, int y, int w, int h ); + - void drawRoundRect( int x, int y, int w, int h, int = 25, int = 25 ); + - void drawEllipse( int x, int y, int w, int h ); + - void drawText( int x, int y, const QString &txt ); + + - Fixed a problem with the --mainwin option. + + - Added another example script. + +2003-05-19 Monday 10:59 mueller + + CVS_SILENT compiler warnings + +2003-04-23 Wednesday 01:21 geiseri + + Added a close button so that it could close without hitting the kill + button. + +2003-04-03 Thursday 14:55 geiseri + + KJS is mostly ported to the new api. + +2003-04-03 Thursday 14:55 geiseri + + Start of DCOP support for new KJSEmbed. + +2003-02-21 Friday 10:36 pmk + + Updated for changes to KJS API - use Identifier instead of UString + +2003-02-04 Tuesday 17:50 rich + + - Added support for more QWidgets: + + QSplitter, QMainWindow, QProgressDialog. + + - Improved dump() function, now spits out a nice HTML table of the + properties etc. + + - Renamed JSObjectProxy::jscript() to interpreter() (for consistency). + + - KJSCmd can now create a KMainWindow (dunno how useful this is + without the other additions I'm planning though). + +2003-01-31 Friday 22:19 rich + + - Switched order of args to convertToVariant() to match everything + else. + + - Added a new global method 'dump(Object)' that returns information + about the specified object. The information returned depends on the + type of the object. + +2003-01-31 Friday 19:16 rich + + + - Renamed KJSEmbedPart::jscript() to KJSEmbedPart::interpreter() for + consistency. + + - Renamed publish() to addObject(), and publishStdBindings() to + addStdBindings(). This is more consistent with QSA, and makes the + API more familiar to developers familiar with the rest of KDE/Qt. + +2003-01-31 Friday 18:52 rich + + + - Moved loadScript(filename) from main.cpp into the KPart, and renamed + the existing loadXX() to executeXX() which is better anyway. + + - Added -DQT_CLEAN_NAMESPACE -DQT_NO_ASCII_CAST to the build flags. + + - Added a standalone factory class. This class is responsible for + creating the various objects, and for creating bindings. + + - Split the code that creates the standard bindings into individual + methods. + + - Moved bindings classes into their own namespace KJSEmbed::Bindings, + this has affected the Bind_Image, Bind_TextStream, and the XXImp + classes. + + - Renamed SecurityPolicy to JSSecurityPolicy, and ActionData to + XMLActionData. + +2003-01-14 Tuesday 22:35 rich + + - Remove messagelog + +2003-01-14 Tuesday 22:34 rich + + + - Created a KJSEmbedPartImp class which replaces the internal + MethodImp and ConstructorImp classes used before. This makes the + public header files a lot cleaner, and makes the code easier to + follow. + + - Created a JSObjectProxyImp class which does the same for + JSObjectProxy. + + - Removed the legacy isAllowed(...) methods from JSObjectProxy, use + the SecurityPolicy class instead. + + - Merged the reduntant class MessageLogWidget into JSConsoleWidget. + + - Moved Bind_Image and Bind_TextStream to their own files. + + - Moved the KJS::Value <-> QVariant functions to jsbinding. + + - Improved the JSObjectProxy + + - Tidied up the code for registering and calling slots. + + - The slots(), properties() and children() methods now return + Arrays. + +2003-01-14 Tuesday 15:56 rich + + - Made QVariant <-> KJS::Value conversions standalone methods. + + - Made the argument ordering of the create() methods consistant + throughout. + + - Added accessor to allow you to get the QObject a proxy is bound to. + + - Now defines constructors for all the widgets supported by the + QWidgetFactory. This change is very important as it eliminates what + was the single most noticable difference between the C++ and + Javascript objects. Using constructors properly has the added bonus + that the Javascript interpreter can now correctly determine the + class of the objects. + + - Supported Qt Widgets: + + QPushButton, QToolButton, QCheckBox, QRadioButton, + QGroupBox, QButtonGroup, QIconView, QTable, + QListBox, QListView, QLineEdit, QSpinBox, + QMultiLineEdit, QLabel, TextLabel, PixmapLabel, + QLayoutWidget, QTabWidget, QComboBox, + QWidget, QDialog, QWizard, QLCDNumber, + QProgressBar, QTextView, QTextBrowser, + QDial, QSlider, QFrame, Line, QTextEdit, + QDateEdit, QTimeEdit, QDateTimeEdit, QScrollBar, + QPopupMenu, QWidgetStack, QMainWindow, + QDataTable, QDataBrowser, QDataView, + QVBox, QHBox, QGrid + + - Supported KDE Widgets: + + KActiveLabel, KCharSelect, KColorButton, KColorCombo, + KComboBox, KCModule, KDateWidget, KDatePicker, KDialog, + KDualColorButton, KEditListBox, KFontCombo, KGradientSelector, + KHistoryCombo, KHSSelector, KLed, KListBox, KListView, + KLineEdit, KPasswordEdit, KProgress, KPushButton, + KRestrictedLine, KIconButton, KIntSpinBox, KRuler, + KSqueezedTextLabel, KTextBrowser, KTextEdit, + KURLLabel, KURLRequester, + KIntNumInput, KDoubleNumInput, KDoubleSpinBox + + - Added constructors for the custom builtin objects Image and + TextStream. + +2003-01-11 Saturday 21:50 rich + + - Added a binding to QImage::smoothScale(w,h,ScaleMin). This should + really be handled by the enum property support, but as that doesn't + exist yet we'll do it the hard way. + + - Added a readFile(name) method to the global JS object. It returns + the file contents as a string, or null if the file could not be + read. + + - Added README files to some of the examples. + + - Added a println() method to the global object. The old print() + method has been changed so it no longer appends a newline. + + - Added an example that generates an image gallery. + + - Thumbnails of the images are created automatically. + + - Descriptions of the images are inserted in the generated page if + there is a file called <imgname>.htm. + + - Automatically skips its own thumbnails. + + - Files that aren't understood are ignored so you can just pass '*' + when you call it from the command line. + + - Includes an example shellscript that ensures the images are sorted + by their modification time. + + - Updated copyright info. + +2003-01-10 Friday 23:54 rich + + - Added Image binding. + + - Provides a binding to some basic QImage and QImageIO operations. + - Added example that prints info about an image. + - Added an example that scales an image and writes it in a specified + - format. + + - Added support for (int, int) slots. I really need to make this code + handle the args generically. + + - kjscmd now makes args following the script name available to JS as + application.args[]. + + - Strip #! line that contains kjscmd from the script so the scripts + can be run just by making them executable. + +2003-01-06 Monday 18:23 rich + + - Added the tutorial i am working on so people can see how to use this stuff + +2003-01-06 Monday 17:38 rich + + - Add link to tutorial devel site + +2003-01-06 Monday 17:09 rich + + KJSEmbed 0.2 + ============ + + Massively updated and improved version of KJSEmbed. Still a few things + to go though, including the tutorial. + + - Fixed i18n of js console widget + + - Fixed text spacing in console widget + + - Fixed design flaw in security model + + The old model was flawed because sub-proxies would always revert + to the default policy rather than using the custom policy defined + by a subclass. The policy is now a standalone object, so the problem + is fixed. + + - Added lots of documentation and a Doxygen config file. + + - Extended factory class to create the following types: + + - Any QWidget sub-class + - KAction + - KToggleAction + + - Added a command line tool for invoking js scripts + + - Improved JSObjectProxy Massively + + - Create child widgets from a script + - Create KActions and KToggleActions from a script + - Call slots from scripts + + - Added support for additional property types + +2002-11-29 Friday 12:28 mueller + + backport install dir fix + +2002-11-29 Friday 12:28 mueller + + install in the right path + +2002-11-07 Thursday 15:30 coolo + + little cleanup + +2002-03-08 Friday 13:53 rich + + kdoc fixes + +2002-03-08 Friday 12:43 rich + + Updates for kjs changes in HEAD + +2001-11-16 Friday 04:59 faure + + Let $(all_includes) be last otherwise my script gets unhappy ;) + +2001-11-15 Thursday 14:19 mueller + + ignore + +2001-11-13 Tuesday 18:38 rich + + Added an example of how to use the example. :-) + +2001-11-13 Tuesday 17:12 wgreven + + Fix compililation for builddir != srcdir. + +2001-11-13 Tuesday 15:56 rich + + A library for embedding kjs with transparent bindings to QObjects and + their properties, a dialog loader and a hook loader for client apps. + diff --git a/kjsembed/docs/Makefile.am b/kjsembed/docs/Makefile.am new file mode 100644 index 00000000..a485debe --- /dev/null +++ b/kjsembed/docs/Makefile.am @@ -0,0 +1 @@ +SUBDIRS=embedding diff --git a/kjsembed/docs/TODO b/kjsembed/docs/TODO new file mode 100644 index 00000000..06cfb0e4 --- /dev/null +++ b/kjsembed/docs/TODO @@ -0,0 +1,81 @@ + Planned Changes + =============== + +Core +==== + +- Handle non-standard signatures (that are combinations of supported + types). [Working, but variant support is incomplete] + +- The factory class needs to become responsible for the bindings as + well as the creation of the objects themselves. [Partially working] + +- At the moment a lot of the standard bindings etc. are rebound for + each proxy. This is ridiculous and totally unnecessary. + +- When a proxy is created, it should use create-on-first-use semantics + to define the JS object defining its class. This object can then be + used to store the method and property wrappers. In addition, by + setting the prototype correctly for the created instance we can get + inheritence working properly. + +- Extend the type handling code in slotutils.cpp to support opaque pointer + types properly. + +- Enable emission of signals from JS that can be connected in C++ + +- DOM Level 2 support. + +- Clean up slot handeling code. + +- Clean up opaque proxy so the pointers can be GCed. + +- Clear up ownership issues with respects to objects generated from + applications that embed KJSEmbed and wrap internal objects with + opaque proxies. + +Bind Wizard +=========== + +- Missing arg types: + - QColorGroup & + - QPainter * + +Bindings +======== + +- Add more Bind_XXX classes. + +- Move to the same pattern as the KJS/DOM bindings for better + inheritence support. + +- Support for QSignal + +- A generic wrapper for QStyle so you can write styles in JS. + +License Clarification +===================== + +<kupid> I talked to Matthias and we'll have to explictly state somewhere in the license that you're not +allowed to create the widgets with it. They way he saw it is that there should be any problem because +if you write a script and it's internal and you don't redistribute it then it can be whatever you want, if you +do redistribute it then it's a script and the code is right there so you might as well make it explicit that +it's gpl or lgpl +<richmoore> i don't quite follow +<richmoore> are you saying that if you use the widget factory then the license degrades from LGPL to +GPL? +<richmoore> (this would make sense btw) +<kupid> Yes, that's the thing, we just can't allow people to use GPL licensed Qt classes under LGPL +<richmoore> that's fair enough +<richmoore> i was aware of that +<richmoore> i think the easiest solution is to allow a script to specify a license and use that to +determine the available bindings (and to provide a pure-LGPL build target with no qt support) +<richmoore> a 'check-license' mode is also a good idea +<richmoore> the same situation will apply when i add bindings for Kalle's charting library +<richmoore> this is one of the reasons why i want the bindings to be dynamically loaded +<richmoore> thanks for checking this, it is good to know the trolls opinion here +<kupid> That sounds great (sorry for having a slow response time but I'm running around the labs) +<richmoore> no problem + + + diff --git a/kjsembed/docs/build-docs.js b/kjsembed/docs/build-docs.js new file mode 100644 index 00000000..04f276c1 --- /dev/null +++ b/kjsembed/docs/build-docs.js @@ -0,0 +1,230 @@ +#!/usr/bin/env kjscmd + +function write_page( name, body ) +{ + var markUp = ""; + + markUp += '<html>\n'; + + markUp += '<head>\n'; + markUp += '<title>' + name + '</title>\n'; + markUp += '<style type="text/css"><!--\n'; + markUp += 'h1 { text-align: center; background-color: #ccccff; }\n'; + markUp += 'h2 { background-color: #eeeeff; }\n'; + markUp += 'h3 { background-color: #eeeeff; }\n'; + markUp += 'th { background-color: #cccccc; }\n'; + markUp += 'td { background-color: #eeeeee; }\n'; + markUp += '--></style>\n'; + markUp += '</head>\n'; + + markUp += '<body>\n'; + markUp += '<a href="index.html">All Objects</a>'; + markUp += '| <a href="index-static.html">Statics</a>'; + markUp += '| <a href="index-objects.html">Objects</a>'; + markUp += '| <a href="index-kjsembedobjects.html">KJSEmbed Objects</a>'; + markUp += '| <a href="index-qtobjects.html">Qt Objects</a>'; + markUp += '| <a href="index-kdeobjects.html">KDE Objects</a>'; + markUp += '| <a href="index-exceptions.html">Exceptions</a>'; + markUp += '| <a href="index-nocreate.html">Uncreatable Objects</a>\n'; + markUp += '<h1>' + name + '</h1>\n'; + markUp += '<hr>\n'; + markUp += body; + markUp += '<hr>\n'; + markUp += '</body>\n'; + + markUp += '</html>\n'; + return markUp; +} + +function write_classlist( title, intro, classlist ) +{ + text = '<h3>'+title+'</h3>'; + text += intro; + text += '<ul>\n'; + + var hrefroot = ''; + for ( var i = 0; i < classlist.length; i++ ) + { + text += '<li>'; + var href = classlist[i].toLowerCase() + '.html'; + href = href.replace( /.*::/, '' ); + + var name = classlist[i]; + text += '<a href="' + hrefroot + href + '">' + name + '</a>\n'; + } + text += '</ul>\n'; + + return text; +} + +function write_classes( title, desc, sections ) +{ + var txt = desc; + for ( var i = 0; i < sections.length; i += 3 ) { + txt += write_classlist( sections[ i ], sections[ i+1 ], sections[ i+2 ] ); + } + + return write_page( title, txt ); +} + +function generate_docs_object( name, obj ) +{ + var fileText = write_page( name, + 'Bindings for the ' + name + ' class.<br />' + dump(obj) ); + System.writeFile("jsref/" + name.toLowerCase() + ".html", fileText); +} + +function generate_docs_nocreate( name ) +{ + var fileText = write_page( name, + 'Bindings for the ' + name + ' class.<br />' + + 'This class is understood by the interpreter, but cannot be created from scripts.' ); + + System.writeFile("jsref/" + name.toLowerCase() + ".html", fileText); +} + +// +// Document the static objects +// +function document_statics( statics ) +{ + for ( var idx = 0; idx < statics.length; idx++ ) { + var name = statics[idx]; + try + { + var obj = eval( name ); + var fileText = write_page( name, + 'Bindings for the static ' + name + ' object.' + dump(obj) ); + System.writeFile("jsref/" + name.toLowerCase() + ".html", fileText); + } + catch(x) + { + println("Error: " + x ); + } + } +} + +// +// Build script that will document the constructable objects +// + +function document_constructable( objects ) +{ + for ( var idx = 0; idx < objects.length; idx++ ) + { + println('Document class: ' + objects[idx] ); + + try { + generate_docs_object( objects[idx], Factory.createObject( objects[idx] )); + println(', Success'); + } + catch(x) { + println(', Error ' + x ); + generate_docs_nocreate( objects[idx] ); + nocreate.push( objects[idx] ); + } + } +} +//// +//// Main +//// + + +var statics = [ 'Factory', 'System', 'Global', 'StdDialog', + 'StdAction', 'StdDirs', 'StdIcons', 'Qt' ]; +qttps = []; +kdetps = []; +kjsetps = []; +other = []; +nocreate = []; +var expts = [ 'ReferenceError', 'EvalError', 'RangeError', 'TypeError' ]; +tps = Factory.types().sort(); + +statics.sort(); +expts.sort(); + +cons = Factory.constructors().sort(); +cons += 'Part'; + +for ( var i=0; i < tps.length; i++ ) { + + if ( /^Q/.test(tps[i]) ) { + qttps.push( tps[i] ); + } + else if ( /^KJSEmbed::/.test(tps[i]) ) { + if ( tps[i] != 'KJSEmbed::Bindings::JSDCOPInterface' ) { + kjsetps.push( tps[i] ); + } + } + else if ( /^K/.test(tps[i]) ) { + kdetps.push( tps[i] ); + } + else { + other.push( tps[i] ); + } +} + +// +// Generate object reference pages +// + +document_constructable( tps ); +document_statics( statics ); +document_statics( expts ); + +generate_docs_object( 'TextStream', System.stdin ); +generate_docs_object( 'Application', application ); +generate_docs_object( 'KJSEmbedPart', part ); +generate_docs_object( 'QListViewItem', new QListViewItem(new QListView()) ); +generate_docs_object( 'QCheckListItem', new QCheckListItem(new QListView()) ); +generate_docs_object( 'QCanvasText', new QCanvasText(new QCanvas()) ); + +other.push( 'Application' ); +other.sort(); + +// +// Generate index pages +// +index = [ 'Static Objects', + 'Statics that are available to scripts as JS objects.', + statics, + + 'Object Types', + 'The non-widget objects that are defined for scripts.', + other, + + 'KJSEmbed Objects', + 'KDE objects that are available to scripts as JS objects.', + kjsetps, + + 'Qt Objects', + 'Qt objects that are available to scripts as JS objects.', + qttps, + + 'KDE Objects', + 'KDE objects that are available to scripts as JS objects.', + kdetps, + + 'Exception Types', + 'Exceptions that are defined for scripts.', + expts, + + 'Unconstructable Types', + 'Known type that scripts cannot create.', + nocreate + ]; + +System.writeFile( "jsref/index.html", + write_classes( 'All Scriptable Objects', + 'The full set of objects that can be accessed by scripts.', + index ) ); + +System.writeFile( "jsref/index-static.html", write_classes( index[0], index[1], ['','',index[2]] ) ); +System.writeFile( "jsref/index-objects.html", write_classes( index[3], index[4], ['','',index[5]] ) ); +System.writeFile( "jsref/index-kjsembedobjects.html", write_classes( index[6], index[7], ['','',index[8]] ) ); +System.writeFile( "jsref/index-qtobjects.html", write_classes( index[9], index[10], ['','',index[11]] ) ); +System.writeFile( "jsref/index-kdeobjects.html", write_classes( index[12], index[13], ['','',index[14]] ) ); +System.writeFile( "jsref/index-exceptions.html", write_classes( index[15], index[16], ['','',index[17]] ) ); +System.writeFile( "jsref/index-nocreate.html", write_classes( index[18], index[19], ['','',index[20]] ) ); + +System.exit(0); diff --git a/kjsembed/docs/build-docs.sh b/kjsembed/docs/build-docs.sh new file mode 100755 index 00000000..815fead4 --- /dev/null +++ b/kjsembed/docs/build-docs.sh @@ -0,0 +1,87 @@ +#!/bin/sh -x + +# Settings +JS='../kjscmd --noexec' +REF='jsref' + +# Examples and changelog +(cd examples ; w3m -dump index.html > README) + +# Constructor Index +$JS write_classes.js > $REF/classes.html + +# Constructor Index +$JS write_widgets.js > $REF/widgets.html + +# Global Objects +$JS write_docs.js 'this' 'this' 'Default context scripts are executed in.' > $REF/this.html + +$JS write_docs.js 'Global' 'global' 'The global object.' > $REF/global.html +$JS write_docs.js 'Application' 'application' 'Global application object.' > $REF/application.html +$JS write_docs.js 'Part' 'part' 'Part used by the interpreter.' > $REF/part.html +$JS write_docs.js 'StdDirs' 'StdDirs' 'Provides access to KStandardDirs.' > $REF/stddirs.html +$JS write_docs.js 'StdIcons' 'StdIcons' 'Provides access to the KIconLoader.' > $REF/stdicons.html + +# Custom Objects +$JS write_docs.js 'Image' 'new Image()' 'Bindings to the QImage class.' > $REF/image.html +$JS write_docs.js 'Pixmap' 'new Pixmap()' 'Bindings to the QPixmap class.' > $REF/pixmap.html +$JS write_docs.js 'Painter' 'new Painter()' 'Bindings for painting on Pixmaps.' > $REF/painter.html +$JS write_docs.js 'NetAccess' 'new NetAccess()' 'Bindings for KIO::NetAccess.' > $REF/netaccess.html +$JS write_docs.js 'DCOPObject' 'new DCOPObject()' 'Provides support for DCOP.' > $REF/dcop.html +$JS write_docs.js 'SqlDatabase' 'new SqlDatabase()' 'Provides support for QtSQL Databases.' > $REF/sqldatabase.html +$JS write_docs.js 'SqlQuery' 'new SqlQuery()' 'Provides support for QtSQL Queries.' > $REF/sqlquery.html +$JS write_docs.js 'TextStream' 'System.stdin' 'Bindings for QTextSteam.' > $REF/textstream.html +$JS write_docs.js 'Config' 'new Config()' 'Bindings to the KConfig class.' > $REF/config.html + +# Qt Objects +OBJECTS="QPushButton QToolButton QCheckBox QRadioButton" +OBJECTS="$OBJECTS QGroupBox QButtonGroup QIconView QTable" +OBJECTS="$OBJECTS QListBox QListView QLineEdit QSpinBox" +OBJECTS="$OBJECTS QMultiLineEdit QLabel TextLabel PixmapLabel" +OBJECTS="$OBJECTS QLayoutWidget QTabWidget QComboBox" +OBJECTS="$OBJECTS QWidget QDialog QWizard QLCDNumber" +OBJECTS="$OBJECTS QProgressBar QTextView QTextBrowser" +OBJECTS="$OBJECTS QDial QSlider QFrame Line QTextEdit" +OBJECTS="$OBJECTS QDateEdit QTimeEdit QDateTimeEdit QScrollBar" +OBJECTS="$OBJECTS QPopupMenu QWidgetStack QMainWindow" +OBJECTS="$OBJECTS QDataTable QDataBrowser QDataView" +OBJECTS="$OBJECTS QVBox QHBox QGrid" + +for OBJ in $OBJECTS ; +do + FILENAME=`echo $OBJ | tr '[A-Z]' '[a-z]'` + $JS write_docs.js "$OBJ" "new $OBJ()" "Bindings for a $OBJ." > "$REF/$FILENAME.html" ; +done + +OBJECTS="" + +OBJECTS="$OBJECTS KActiveLabel KCharSelect KColorButton KColorCombo" +OBJECTS="$OBJECTS KComboBox KCModule KDateWidget KDatePicker KDialog" +OBJECTS="$OBJECTS KDualColorButton KEditListBox KFontCombo KGradientSelector" +OBJECTS="$OBJECTS KHistoryCombo KHSSelector KLed KListBox KListView" +OBJECTS="$OBJECTS KLineEdit KPasswordEdit KProgress KPushButton" +OBJECTS="$OBJECTS KRestrictedLine KIconButton KIntSpinBox KRuler" +OBJECTS="$OBJECTS KSqueezedTextLabel KTextBrowser KTextEdit" +OBJECTS="$OBJECTS KURLLabel KURLRequester" +OBJECTS="$OBJECTS KIntNumInput KDoubleNumInput KDoubleSpinBox" + +for OBJ in $OBJECTS ; +do + FILENAME=`echo $OBJ | tr '[A-Z]' '[a-z]'` + $JS write_docs.js "$OBJ" "new $OBJ()" "Bindings for a $OBJ." > "$REF/$FILENAME.html" ; +done + + +OBJECTS="$OBJECTS QSplitter" +OBJECTS="$OBJECTS QObject QTimer" + +OBJECTS="$OBJECTS KMainWindow KAction KToggleAction" + +for OBJ in $OBJECTS ; +do + FILENAME=`echo $OBJ | tr '[A-Z]' '[a-z]'` + $JS write_docs.js "$OBJ" "new $OBJ()" "Bindings for a $OBJ." > "$REF/$FILENAME.html" ; +done + + + diff --git a/kjsembed/docs/changes.html b/kjsembed/docs/changes.html new file mode 100644 index 00000000..853b71c2 --- /dev/null +++ b/kjsembed/docs/changes.html @@ -0,0 +1,11 @@ +<html> +<head> +<link href="kjsembed.css" rel="stylesheet" type="text/css"> +<title>KJSEmbed ChangeLog</title> +</head> +<body bgcolor="#eeeeee"> +<div align="right"><a href="ChangeLog">Change Log (text version)</a></div> +<h1>KJSEmbed ChangeLog</h1> +<embed src="ChangeLog" width="100%" height="90%"> +</body> +</html> diff --git a/kjsembed/docs/classdocs/dummy.txt b/kjsembed/docs/classdocs/dummy.txt new file mode 100644 index 00000000..8d1c8b69 --- /dev/null +++ b/kjsembed/docs/classdocs/dummy.txt @@ -0,0 +1 @@ + diff --git a/kjsembed/docs/conventions.html b/kjsembed/docs/conventions.html new file mode 100644 index 00000000..32d88440 --- /dev/null +++ b/kjsembed/docs/conventions.html @@ -0,0 +1,28 @@ +<html> +<head> +<link href="kjsembed.css" rel="stylesheet" type="text/css"> +<title>KJSEmbed Documentation Conventions</title> +</head> +<body> +<h1>KJSEmbed Documentation Conventions</h1> +<hr> +The conventions used by these documents are illustrated in the table +below. +<br><br> +<center> +<table> +<tr><th class="indextitle">Notation</th> +<th class="indextitle">Meaning</th></tr> +<tr><td class="indexkey">'a value'</td> +<td class="indexvalue">Indicates a String value.</td></tr> +<tr><td class="indexkey">[a,b..]</td> +<td class="indexvalue">Indicates an Array value.</td></tr> +<tr><td class="indexkey">obj.prop</td> +<td class="indexvalue">Indicates that a value will be taken from the +property 'prop' of the Object 'obj'.</td></tr> +</table> +</center> + +<hr> +</body> +</html> diff --git a/kjsembed/docs/embedding/Makefile.am b/kjsembed/docs/embedding/Makefile.am new file mode 100644 index 00000000..13c617f2 --- /dev/null +++ b/kjsembed/docs/embedding/Makefile.am @@ -0,0 +1,2 @@ + +SUBDIRS=simple-embed diff --git a/kjsembed/docs/embedding/qtembed/main.cpp b/kjsembed/docs/embedding/qtembed/main.cpp new file mode 100644 index 00000000..b2d7d3d1 --- /dev/null +++ b/kjsembed/docs/embedding/qtembed/main.cpp @@ -0,0 +1,18 @@ +// +// Author: Ian Reinhart Geiser <geiseri@kde.org>, (C) 2004 +// +// Copyright: See COPYING file that comes with this distribution +// +// + +#include <qapplication.h> +#include "posviewimp.h" + +int main ( int argc, char ** argv ) +{ + QApplication app( argc, argv ); + POSViewImp *view = new POSViewImp; + app.setMainWidget(view); + view->show(); + return app.exec(); +} diff --git a/kjsembed/docs/embedding/qtembed/posviewbase.ui b/kjsembed/docs/embedding/qtembed/posviewbase.ui new file mode 100755 index 00000000..9d8bad1a --- /dev/null +++ b/kjsembed/docs/embedding/qtembed/posviewbase.ui @@ -0,0 +1,183 @@ +<!DOCTYPE UI><UI version="3.3" stdsetdef="1"> +<class>POSViewBase</class> +<widget class="QDialog"> + <property name="name"> + <cstring>POSViewBase</cstring> + </property> + <property name="geometry"> + <rect> + <x>0</x> + <y>0</y> + <width>492</width> + <height>298</height> + </rect> + </property> + <property name="caption"> + <string>Point of Sale v1.0</string> + </property> + <property name="sizeGripEnabled"> + <bool>true</bool> + </property> + <vbox> + <property name="name"> + <cstring>unnamed</cstring> + </property> + <widget class="QLayoutWidget"> + <property name="name"> + <cstring>layout3</cstring> + </property> + <hbox> + <property name="name"> + <cstring>unnamed</cstring> + </property> + <widget class="QFrame"> + <property name="name"> + <cstring>appFrame</cstring> + </property> + <property name="sizePolicy"> + <sizepolicy> + <hsizetype>5</hsizetype> + <vsizetype>5</vsizetype> + <horstretch>1</horstretch> + <verstretch>1</verstretch> + </sizepolicy> + </property> + <property name="frameShape"> + <enum>StyledPanel</enum> + </property> + <property name="frameShadow"> + <enum>Raised</enum> + </property> + </widget> + <widget class="QLayoutWidget"> + <property name="name"> + <cstring>layout2</cstring> + </property> + <vbox> + <property name="name"> + <cstring>unnamed</cstring> + </property> + <widget class="QLabel"> + <property name="name"> + <cstring>textLabel2</cstring> + </property> + <property name="text"> + <string>Recipt</string> + </property> + </widget> + <widget class="QTextBrowser"> + <property name="name"> + <cstring>recipt</cstring> + </property> + <property name="sizePolicy"> + <sizepolicy> + <hsizetype>7</hsizetype> + <vsizetype>7</vsizetype> + <horstretch>1</horstretch> + <verstretch>1</verstretch> + </sizepolicy> + </property> + <property name="textFormat"> + <enum>LogText</enum> + </property> + </widget> + </vbox> + </widget> + </hbox> + </widget> + <widget class="QLayoutWidget"> + <property name="name"> + <cstring>Layout1</cstring> + </property> + <hbox> + <property name="name"> + <cstring>unnamed</cstring> + </property> + <property name="margin"> + <number>0</number> + </property> + <property name="spacing"> + <number>6</number> + </property> + <widget class="QPushButton"> + <property name="name"> + <cstring>buttonHelp</cstring> + </property> + <property name="text"> + <string>&Help</string> + </property> + <property name="accel"> + <string>F1</string> + </property> + <property name="autoDefault"> + <bool>true</bool> + </property> + </widget> + <spacer> + <property name="name"> + <cstring>Horizontal Spacing2</cstring> + </property> + <property name="orientation"> + <enum>Horizontal</enum> + </property> + <property name="sizeType"> + <enum>Expanding</enum> + </property> + <property name="sizeHint"> + <size> + <width>20</width> + <height>20</height> + </size> + </property> + </spacer> + <widget class="QPushButton"> + <property name="name"> + <cstring>buttonOk</cstring> + </property> + <property name="text"> + <string>&OK</string> + </property> + <property name="accel"> + <string></string> + </property> + <property name="autoDefault"> + <bool>true</bool> + </property> + <property name="default"> + <bool>true</bool> + </property> + </widget> + <widget class="QPushButton"> + <property name="name"> + <cstring>buttonCancel</cstring> + </property> + <property name="text"> + <string>&Cancel</string> + </property> + <property name="accel"> + <string></string> + </property> + <property name="autoDefault"> + <bool>true</bool> + </property> + </widget> + </hbox> + </widget> + </vbox> +</widget> +<connections> + <connection> + <sender>buttonOk</sender> + <signal>clicked()</signal> + <receiver>POSViewBase</receiver> + <slot>accept()</slot> + </connection> + <connection> + <sender>buttonCancel</sender> + <signal>clicked()</signal> + <receiver>POSViewBase</receiver> + <slot>reject()</slot> + </connection> +</connections> +<layoutdefaults spacing="6" margin="11"/> +</UI> diff --git a/kjsembed/docs/embedding/qtembed/posviewimp.cpp b/kjsembed/docs/embedding/qtembed/posviewimp.cpp new file mode 100644 index 00000000..7d4aebc9 --- /dev/null +++ b/kjsembed/docs/embedding/qtembed/posviewimp.cpp @@ -0,0 +1,30 @@ +// +// Author: Ian Reinhart Geiser <geiseri@kde.org>, (C) 2004 +// +// Copyright: See COPYING file that comes with this distribution +// +// +#include "posviewimp.h" + +#include <kjsembed/kjsembedpart.h> +#include <kjsembed/jsconsolewidget.h> +#include <kjsembed/jsbinding.h> + +#include <qgroupbox.h> +#include <qdatetime.h> +#include <qcolor.h> + +POSViewImp::POSViewImp(QWidget *parent, const char *name) + :POSViewBase(parent, name) +{ + m_part = new KJSEmbed::KJSEmbedPart(0, "kjsembed_part", this,"JSEmbed"); + m_part->addObject(appFrame, "appFrame"); + loadScript(); +} + +void POSViewImp::loadScript() +{ + m_part->runFile("test.js", m_part->globalObject() ); +} + + diff --git a/kjsembed/docs/embedding/qtembed/posviewimp.h b/kjsembed/docs/embedding/qtembed/posviewimp.h new file mode 100644 index 00000000..3fce0965 --- /dev/null +++ b/kjsembed/docs/embedding/qtembed/posviewimp.h @@ -0,0 +1,26 @@ +// +// Author: Ian Reinhart Geiser <geiseri@kde.org>, (C) 2004 +// +// Copyright: See COPYING file that comes with this distribution +// +// +#ifndef POSVIEWIMP_H +#define POSVIEWIMP_H + +#include "posviewbase.h" +namespace KJSEmbed { + class KJSEmbedPart; +}; + +class POSViewImp: public POSViewBase { + Q_OBJECT +public: + POSViewImp( QWidget *parent = 0, const char *name = 0 ); + +public slots: + void loadScript(); +private: + KJSEmbed::KJSEmbedPart *m_part; +}; + +#endif diff --git a/kjsembed/docs/embedding/qtembed/qtembed.pro b/kjsembed/docs/embedding/qtembed/qtembed.pro new file mode 100755 index 00000000..5b0f4c6b --- /dev/null +++ b/kjsembed/docs/embedding/qtembed/qtembed.pro @@ -0,0 +1,12 @@ +include( ../../../qjsembed.pri ) +TEMPLATE = app + +# Input +HEADERS += posviewimp.h +INTERFACES += posviewbase.ui +SOURCES += main.cpp posviewimp.cpp + + +LIBS += -L../../../bin -lqjsembed +INCLUDEPATH += ../../../.. ../../.. + diff --git a/kjsembed/docs/embedding/qtembed/test.js b/kjsembed/docs/embedding/qtembed/test.js new file mode 100644 index 00000000..7a5c3bc0 --- /dev/null +++ b/kjsembed/docs/embedding/qtembed/test.js @@ -0,0 +1,3 @@ +var vbox = new QVBoxLayout( appFrame ); +var view = Factory.loadui("view.ui", appFrame, appFrame ); +view.show();
\ No newline at end of file diff --git a/kjsembed/docs/embedding/qtembed/view.ui b/kjsembed/docs/embedding/qtembed/view.ui new file mode 100755 index 00000000..c714ff00 --- /dev/null +++ b/kjsembed/docs/embedding/qtembed/view.ui @@ -0,0 +1,85 @@ +<!DOCTYPE UI><UI version="3.3" stdsetdef="1"> +<class>view</class> +<widget class="QWidget"> + <property name="name"> + <cstring>view</cstring> + </property> + <property name="geometry"> + <rect> + <x>0</x> + <y>0</y> + <width>285</width> + <height>197</height> + </rect> + </property> + <vbox> + <property name="name"> + <cstring>unnamed</cstring> + </property> + <widget class="QLayoutWidget"> + <property name="name"> + <cstring>layout1</cstring> + </property> + <grid> + <property name="name"> + <cstring>unnamed</cstring> + </property> + <widget class="QLineEdit" row="1" column="1"> + <property name="name"> + <cstring>mSKU</cstring> + </property> + </widget> + <widget class="QLineEdit" row="2" column="1"> + <property name="name"> + <cstring>mPrice</cstring> + </property> + </widget> + <widget class="QLabel" row="1" column="0"> + <property name="name"> + <cstring>textLabel2</cstring> + </property> + <property name="text"> + <string>SKU:</string> + </property> + </widget> + <widget class="QLabel" row="2" column="0"> + <property name="name"> + <cstring>textLabel3</cstring> + </property> + <property name="text"> + <string>Price:</string> + </property> + </widget> + <widget class="QLabel" row="0" column="0"> + <property name="name"> + <cstring>textLabel1</cstring> + </property> + <property name="text"> + <string>Product:</string> + </property> + </widget> + <widget class="QComboBox" row="0" column="1"> + <property name="name"> + <cstring>mProduct</cstring> + </property> + <property name="autoCompletion"> + <bool>true</bool> + </property> + </widget> + </grid> + </widget> + <widget class="QLabel"> + <property name="name"> + <cstring>mImage</cstring> + </property> + <property name="text"> + <string></string> + </property> + <property name="scaledContents"> + <bool>true</bool> + </property> + </widget> + </vbox> +</widget> +<layoutdefaults spacing="6" margin="11"/> +</UI> diff --git a/kjsembed/docs/embedding/simple-embed/Makefile.am b/kjsembed/docs/embedding/simple-embed/Makefile.am new file mode 100644 index 00000000..44607f91 --- /dev/null +++ b/kjsembed/docs/embedding/simple-embed/Makefile.am @@ -0,0 +1,40 @@ +## Makefile.am for embedjs + +# this is the program that gets installed. it's name is used for all +# of the other Makefile.am variables +bin_PROGRAMS = embedjs + +# set the include path for X, qt and KDE +INCLUDES = -I$(top_srcdir) $(all_includes) + +# the library search path. +embedjs_LDFLAGS = $(KDE_RPATH) $(all_libraries) + +# the libraries to link against. +embedjs_LDADD = $(LIB_KFILE) $(LIB_KDEPRINT) -lkjs $(top_builddir)/kjsembed/libkjsembed.la + +# which sources should be compiled for embedjs +embedjs_SOURCES = main.cpp embedview.ui embedviewimp.cpp + +# these are the headers for your project + + +# client stuff + +# let automoc handle all of the meta source files (moc) +METASOURCES = AUTO + +messages: rc.cpp + $(XGETTEXT) *.cpp -o $(podir)/embedjs.pot + +KDE_ICON = embedjs + +# this is where the kdelnk file will go +kdelnkdir = $(kde_appsdir)/Utilities +kdelnk_DATA = embedjs.desktop + +# this is where the XML-GUI resource file goes +rcdir = $(kde_datadir)/embedjs +rc_DATA = embedjsui.rc +noinst_HEADERS = embedviewimp.h +noinst_DATA = test.js diff --git a/kjsembed/docs/embedding/simple-embed/README b/kjsembed/docs/embedding/simple-embed/README new file mode 100644 index 00000000..f04a5635 --- /dev/null +++ b/kjsembed/docs/embedding/simple-embed/README @@ -0,0 +1,81 @@ +----------------------------------------------- +Kde application framework template quickstart +Author: Thomas Nagy +Date: 2004-03-22 +----------------------------------------------- + +This README file explains you basic things for starting with +this application template. + + +** Building and installing ** + +* Build the configure script by "make -f Makefile.cvs" + +* To clean, use "make clean", and to clean everything +(remove the makefiles, etc), use "make distclean" + +* To distribute your program, try "make dist". +This will make a compact tarball archive of your release with the +necessary scripts inside. + +* Modifying the auto-tools scripts +for automake scripts there is an excellent tutorial there : +http://developer.kde.org/documentation/other/makefile_am_howto.html + +* Simplify your life : install the project in your home directory for +testing purposes. +./configure --prefix=/home/user/dummyfolder/ +In the end when you finished the development you can +rm -rf /home/user/dummyfolder/ +without fear. + + +** Technologies ** + +* Build the menus of your application easily +kde applications now use an xml file (*ui.rc file) to build the menus. +This allow a great customization of the application. However, when +programming the menu is shown only after a "make install" + +For more details, consult : +http://devel-home.kde.org/~larrosa/tutorial/p9.html +http://developer.kde.org/documentation/tutorials/xmlui/preface.html + +* Use KConfig XT to create your configuration dialogs and make +them more maintainable. + +For more details, consult : +http://developer.kde.org/documentation/tutorials/kconfigxt/kconfigxt.html + +* With KParts, you can embed other kde components in your program, or make your program +embeddable in other apps. For example, the kmplayer kpart can be called to play videos +in your app. + +For more details, consult : +http://www-106.ibm.com/developerworks/library/l-kparts/ +http://developer.kde.org/documentation/tutorials/dot/writing-plugins.html +http://developer.kde.org/documentation/tutorials/developing-a-plugin-structure/index.html + +* With dcop, you can control your app from other applications +Make sure to include K_DCOP and a kdcop: section in your .h file +http://developer.kde.org/documentation/tutorials/dot/dcopiface/dcop-interface.html + + +** Documentation ** + +* For the translations : +1. Download a patched gettext which can be found at: + http://public.kde.planetmirror.com/pub/kde/devel/gettext-kde/ +2. Install that gettext in ~/bin/ +3. cd ~/yourproject, export PATH=~/bin:$PATH, export +KDEDIR=/where_your_KDE3_is +4. make -f admin/Makefile.common package-messages +5. make package-messages +6. Translate the po files (not the pot!!) with kbabel or xemacs + +* Do not forget to write the documentation for your kde app +edit the documentation template index.docbook in doc/ + + + diff --git a/kjsembed/docs/embedding/simple-embed/demo.html b/kjsembed/docs/embedding/simple-embed/demo.html new file mode 100644 index 00000000..8b8f236e --- /dev/null +++ b/kjsembed/docs/embedding/simple-embed/demo.html @@ -0,0 +1,93 @@ +<html> +<head> +<link href="kjsembed.css" rel="stylesheet" type="text/css"> +<title>KJSEmbed Documentation</title> +</head> +<body> +<h1>KJSEmbed Documentation</h1> +<hr> + +<h3>Introduction</h3> + +The KJSEmbed library is an easy-to-use wrapper around the KDE +ECMAScript interpreter (kjs) that makes it easy to add scriptability +to an application. The kjsembed library is distributed in the +kdebindings module of KDE. This library provides a binding between +Qt/KDE applications and KJS. + +<h3>Discussion Forums</h3> + +There is now a KJSEmbed mailing list, see +<a href="http://mail.kde.org/mailman/listinfo/kjsembed">http://mail.kde.org/mailman/listinfo/kjsembed</a> +for more information about the list. In addition to the mailing list, +KJSEmbed is discussed on the #kaxul IRC channel (on the freenode IRC network). + +<h3>Learning KJSEmbed</h3> + +An introduction to KJSEmbed. The example scripts demonstrate the use +of all the major objects, and even provides some useful tools. The +tutorial provides a basic introduction to using KJSEmbed, though it is +a little out of date. + +<ul> + <li><b><a href="examples/index.html">Examples</a></b><br> + Example scripts showing how to use KJSEmbed.</li> + <li><b><a href="tutorial">Tutorial</a></b><br> + A tutorial for the library. NOTE: Some of the info here is out of date, see the + examples for cleaner ways to do things.</li> + <li><b><a href="ChangeLog">ChangeLog</a></b><br> + A log of the change history generated from CVS commit messages.</li> + <li><b><a href="TODO">TODO</a></b><br> + The todo list for KJSEmbed.</li> +</ul> + +<h3>Reference Information</h3> + +A reference manual for both the C++ and Javascript APIs defined by +KJSEmbed. The C++ API is of interest to developers looking to adding +scripting to support to their applications, the JS API is for people +who want to write scripts. + +<h4>JavaScript API</h4> +<ul> + <li><b><a href="types.html">KJSEmbed Type Reference</a></b><br> + Documents the custom data types KJSEmbed uses to represent complex types. + <li><b><a href="jsref/index.html">KJSEmbed Class Reference</a></b><br> + Documents the types of object scripts are allowed to create. + <li><b><a href="jsref">KJSEmbed Scripting Reference</a></b><br> + Partial reference to the API available to scripts.</li> +</ul> + +<h4>Host API</h4> +<ul> + <li><b><a href="classdocs/index.html">KJSEmbed Native API Reference</a> (C++)</b><br> + Reference manual for the C++ API of the KJSEmbed library.</li> +</ul> + +<h3>Appendices</h3> +<ul> + <li><b><a href="conventions.html">Document Conventions</a></b><br> + Explains the typographical conventions used by the documents.</li> + + <li><b><a href="kjsembed-qsa.html">KJSEmbed and QSA</a></b><br> + Discusses the differences between KJSEmbed and QSA.</li> +</ul> + +<h3>References</h3> +<ul> + <li><b><a href="http://www.mozilla.org/js/language/">Mozilla Javascript Resources</a></b><br> + Mozilla's Javascript resources page, includes links to the various + releases of the ECMA-262 specification that define the language. + </li> + <li><b><a href="http://www.kevlindev.com/tutorials/javascript/inheritance/">Inheritance in Javascript</a></b><br> + A tutorial on how to implement inheritence in JavaScript. + </li> + <li><b><a href="http://doc.trolltech.com/qsa/">Qt Script for Applications Documentation</a></b><br> + The documentation for QSA, this is Trolltech's ECMAScript binding + for Qt. + </li> +</ul> + +<hr> +</body> +</html> diff --git a/kjsembed/docs/embedding/simple-embed/embedjs.desktop b/kjsembed/docs/embedding/simple-embed/embedjs.desktop new file mode 100644 index 00000000..19629691 --- /dev/null +++ b/kjsembed/docs/embedding/simple-embed/embedjs.desktop @@ -0,0 +1,29 @@ +[Desktop Entry] +Name=EmbedJS +Name[xx]=xxEmbedJSxx +Exec=embedjs %i %m -caption "%c" +Icon=embedjs +Categories=Qt;KDE;Debugger;Development; +Type=Application +DocPath=embedjs/embedjs.html +Comment=A KDE KPart Application +Comment[ca]=Una aplicació KPart per a KDE +Comment[da]=Et KDE KPart program +Comment[de]=Eine KDE-Komponenten-Anwendung +Comment[el]=Μια εφαρμογή KPart του KDE +Comment[es]=Una aplicación KPart de KDE +Comment[et]=KDE KPart rakendus +Comment[fr]=Une application KPart pour KDE. +Comment[hu]=KPart-alapú KDE-alkalmazás +Comment[it]=Applicazione KPart di KDE +Comment[nl]=Een KDE KPart-toepassing +Comment[pt]=Uma aplicação KPart do KDE +Comment[pt_BR]=Um Aplicativo KPart do KDE +Comment[ru]=Приложение KPart для KDE +Comment[sl]=Program KPart za KDE +Comment[sr]=KDE KPart програм +Comment[sv]=Ett KDE Kpart-program +Comment[ta]=கெடி கெபார்ட் பயன்பாடு +Comment[xx]=xxA KDE KPart Applicationxx +Comment[zh_CN]=一个KDE KPart应用程序 +Terminal=false diff --git a/kjsembed/docs/embedding/simple-embed/embedjs.lsm b/kjsembed/docs/embedding/simple-embed/embedjs.lsm new file mode 100644 index 00000000..c4955cbd --- /dev/null +++ b/kjsembed/docs/embedding/simple-embed/embedjs.lsm @@ -0,0 +1,16 @@ +Begin3 +Title: EmbedJS -- Some description +Version: 0.1 +Entered-date: +Description: +Keywords: KDE Qt +Author: Richard Moore <rich@kde.org> +Maintained-by: Richard Moore <rich@kde.org> +Home-page: +Alternate-site: +Primary-site: ftp://ftp.kde.org/pub/kde/unstable/apps/utils + xxxxxx embedjs-0.1.tar.gz + xxx embedjs-0.1.lsm +Platform: Linux. Needs KDE +Copying-policy: LGPL +End diff --git a/kjsembed/docs/embedding/simple-embed/embedjsui.rc b/kjsembed/docs/embedding/simple-embed/embedjsui.rc new file mode 100644 index 00000000..b7138c3b --- /dev/null +++ b/kjsembed/docs/embedding/simple-embed/embedjsui.rc @@ -0,0 +1,14 @@ +<!DOCTYPE kpartgui SYSTEM "kpartgui.dtd"> +<kpartgui name="embedjs" version="1"> +<MenuBar> + <Menu name="tools"><text>&Tools</text> + <Action name="word_count" /> + </Menu> + <Menu name="settings"><text>&Settings</text> + <Action name="show_console" /> + </Menu> + <Menu name="custom"><text>C&ustom</text> + <Action name="custom_action" /> + </Menu> +</MenuBar> +</kpartgui> diff --git a/kjsembed/docs/embedding/simple-embed/embedview.ui b/kjsembed/docs/embedding/simple-embed/embedview.ui new file mode 100644 index 00000000..43be65ab --- /dev/null +++ b/kjsembed/docs/embedding/simple-embed/embedview.ui @@ -0,0 +1,183 @@ +<!DOCTYPE UI><UI version="3.3" stdsetdef="1"> +<class>EmbedView</class> +<widget class="QWidget"> + <property name="name"> + <cstring>Form1</cstring> + </property> + <property name="geometry"> + <rect> + <x>0</x> + <y>0</y> + <width>600</width> + <height>480</height> + </rect> + </property> + <vbox> + <property name="name"> + <cstring>unnamed</cstring> + </property> + <widget class="QLayoutWidget"> + <property name="name"> + <cstring>layout1</cstring> + </property> + <grid> + <property name="name"> + <cstring>unnamed</cstring> + </property> + <widget class="QLabel" row="2" column="0"> + <property name="name"> + <cstring>textLabel3</cstring> + </property> + <property name="text"> + <string>Title:</string> + </property> + </widget> + <widget class="KLineEdit" row="1" column="1"> + <property name="name"> + <cstring>m_dept</cstring> + </property> + </widget> + <widget class="KLineEdit" row="0" column="1"> + <property name="name"> + <cstring>m_name</cstring> + </property> + </widget> + <widget class="QLabel" row="1" column="0"> + <property name="name"> + <cstring>textLabel2</cstring> + </property> + <property name="text"> + <string>Department:</string> + </property> + </widget> + <widget class="QLabel" row="0" column="0"> + <property name="name"> + <cstring>textLabel1</cstring> + </property> + <property name="text"> + <string>Name:</string> + </property> + </widget> + <widget class="KLineEdit" row="2" column="1"> + <property name="name"> + <cstring>m_title</cstring> + </property> + </widget> + </grid> + </widget> + <widget class="QGroupBox"> + <property name="name"> + <cstring>m_customOptions</cstring> + </property> + <property name="sizePolicy"> + <sizepolicy> + <hsizetype>5</hsizetype> + <vsizetype>5</vsizetype> + <horstretch>1</horstretch> + <verstretch>1</verstretch> + </sizepolicy> + </property> + <property name="title"> + <string>Custom Options</string> + </property> + </widget> + <widget class="QLayoutWidget"> + <property name="name"> + <cstring>layout3</cstring> + </property> + <hbox> + <property name="name"> + <cstring>unnamed</cstring> + </property> + <widget class="KPushButton"> + <property name="name"> + <cstring>m_console</cstring> + </property> + <property name="text"> + <string>Console</string> + </property> + <property name="accel"> + <string></string> + </property> + <property name="stdItem" stdset="0"> + <number>0</number> + </property> + </widget> + <spacer> + <property name="name"> + <cstring>spacer1</cstring> + </property> + <property name="orientation"> + <enum>Horizontal</enum> + </property> + <property name="sizeType"> + <enum>Expanding</enum> + </property> + <property name="sizeHint"> + <size> + <width>280</width> + <height>20</height> + </size> + </property> + </spacer> + <widget class="KPushButton"> + <property name="name"> + <cstring>m_ok</cstring> + </property> + <property name="text"> + <string>&OK</string> + </property> + <property name="stdItem" stdset="0"> + <number>1</number> + </property> + </widget> + <widget class="KPushButton"> + <property name="name"> + <cstring>m_cancel</cstring> + </property> + <property name="text"> + <string>&Cancel</string> + </property> + <property name="stdItem" stdset="0"> + <number>2</number> + </property> + </widget> + </hbox> + </widget> + </vbox> +</widget> +<connections> + <connection> + <sender>m_ok</sender> + <signal>clicked()</signal> + <receiver>Form1</receiver> + <slot>okClicked()</slot> + </connection> + <connection> + <sender>m_cancel</sender> + <signal>clicked()</signal> + <receiver>Form1</receiver> + <slot>cancelClicked()</slot> + </connection> + <connection> + <sender>m_console</sender> + <signal>clicked()</signal> + <receiver>Form1</receiver> + <slot>consoleClicked()</slot> + </connection> +</connections> +<slots> + <slot>okClicked()</slot> + <slot>cancelClicked()</slot> + <slot>consoleClicked()</slot> +</slots> +<layoutdefaults spacing="6" margin="11"/> +<includehints> + <includehint>klineedit.h</includehint> + <includehint>klineedit.h</includehint> + <includehint>klineedit.h</includehint> + <includehint>kpushbutton.h</includehint> + <includehint>kpushbutton.h</includehint> + <includehint>kpushbutton.h</includehint> +</includehints> +</UI> diff --git a/kjsembed/docs/embedding/simple-embed/embedviewimp.cpp b/kjsembed/docs/embedding/simple-embed/embedviewimp.cpp new file mode 100644 index 00000000..a1355909 --- /dev/null +++ b/kjsembed/docs/embedding/simple-embed/embedviewimp.cpp @@ -0,0 +1,78 @@ +// +// Author: Ian Reinhart Geiser <geiseri@kde.org>, (C) 2004 +// +// Copyright: See COPYING file that comes with this distribution +// +// +#include <kjsembed/kjsembedpart.h> +#include <kjsembed/jsconsolewidget.h> +#include <kjsembed/jsbinding.h> + +#include "embedviewimp.h" +#include <klineedit.h> +#include <qgroupbox.h> + +#include <qdatetime.h> +#include <qcolor.h> + +EmbedViewImp::EmbedViewImp(QWidget *parent, const char *name) + :EmbedView(parent, name) +{ + m_part = new KJSEmbed::KJSEmbedPart(0, "kjsembed_part", this,"JSEmbed"); + m_part->addObject(m_name, "Name"); + m_part->addObject(m_dept, "Dept"); + m_part->addObject(m_title, "Title"); + m_part->addObject(m_customOptions, "CustomOptions"); + m_part->addObject(this, "EmbedInterface"); +} + +void EmbedViewImp::okClicked() +{ + KJS::List args; + KJS::Value val = m_part->callMethod("handleOk", args); + QMap<QString, QVariant> personalData = KJSEmbed::convertToVariant(m_part->globalExec(), val).toMap(); + QDate birthday = personalData["birthday"].toDate(); + QColor eyecolor = personalData["eyeColor"].toColor(); + QString notes = personalData["notes"].toString(); + + kdDebug() << "birthday: " << birthday << endl; + kdDebug() << "eyecolor: " << eyecolor << endl; + kdDebug() << "notes: " << notes << endl; + +} + +void EmbedViewImp::cancelClicked() +{ + m_name->setText(""); + m_title->setText(""); + m_dept->setText(""); +} + +void EmbedViewImp::consoleClicked() +{ + m_part->view()->setHidden(!m_part->view()->isHidden()); +} + +bool EmbedViewImp::runScript( const QString &file ) +{ + return m_part->runFile(file, m_part->globalObject() ); +} + +QVariant EmbedViewImp::someValue() const +{ + QMap<QString,QVariant> returnMap; + returnMap["name"] = m_name->text(); + returnMap["title"] = m_title->text(); + returnMap["dept"] = m_dept->text(); + return QVariant(returnMap); +} + +void EmbedViewImp::setSomeValue( const QVariant &val ) +{ + QMap<QString,QVariant> map = val.toMap(); + m_name->setText(map["name"].toString()); + m_title->setText(map["title"].toString()); + m_dept->setText(map["dept"].toString()); +} + +#include "embedviewimp.moc" diff --git a/kjsembed/docs/embedding/simple-embed/embedviewimp.h b/kjsembed/docs/embedding/simple-embed/embedviewimp.h new file mode 100644 index 00000000..c56f078c --- /dev/null +++ b/kjsembed/docs/embedding/simple-embed/embedviewimp.h @@ -0,0 +1,34 @@ +// +// Author: Ian Reinhart Geiser <geiseri@kde.org>, (C) 2004 +// +// Copyright: See COPYING file that comes with this distribution +// +// +#ifndef EMBEDVIEWIMP_H +#define EMBEDVIEWIMP_H + +#include "embedview.h" +namespace KJSEmbed { + class KJSEmbedPart; +} + +class EmbedViewImp: public EmbedView { + Q_OBJECT + +public: + EmbedViewImp( QWidget *parent = 0, const char *name = 0 ); + + bool runScript( const QString &file ); + +public slots: + virtual void cancelClicked(); + virtual void okClicked(); + virtual void consoleClicked(); + + QVariant someValue() const; + void setSomeValue( const QVariant &var ); +private: + KJSEmbed::KJSEmbedPart *m_part; +}; + +#endif diff --git a/kjsembed/docs/embedding/simple-embed/hi16-app-embedjs.png b/kjsembed/docs/embedding/simple-embed/hi16-app-embedjs.png Binary files differnew file mode 100644 index 00000000..4ed606c1 --- /dev/null +++ b/kjsembed/docs/embedding/simple-embed/hi16-app-embedjs.png diff --git a/kjsembed/docs/embedding/simple-embed/hi32-app-embedjs.png b/kjsembed/docs/embedding/simple-embed/hi32-app-embedjs.png Binary files differnew file mode 100644 index 00000000..45ae1a11 --- /dev/null +++ b/kjsembed/docs/embedding/simple-embed/hi32-app-embedjs.png diff --git a/kjsembed/docs/embedding/simple-embed/main.cpp b/kjsembed/docs/embedding/simple-embed/main.cpp new file mode 100644 index 00000000..74c5d241 --- /dev/null +++ b/kjsembed/docs/embedding/simple-embed/main.cpp @@ -0,0 +1,45 @@ +/*************************************************************************** + * Copyright (C) 2004 by Richard Moore * + * rich@kde.org * + * * + * This program 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. * + * * + * 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 Library 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. * + ***************************************************************************/ + +#include "embedviewimp.h" +#include <kapplication.h> +#include <kaboutdata.h> +#include <kcmdlineargs.h> +#include <klocale.h> + +static const char description[] = + I18N_NOOP("A KDE Application"); + +static const char version[] = "0.1"; + +int main(int argc, char **argv) +{ + KAboutData about("embedjs", I18N_NOOP("EmbedJS"), version, description, + KAboutData::License_LGPL, "(C) 2004 Ian Reinhart Geiser", 0, 0, "geiseri@kde.org"); + about.addAuthor( "Ian Reinhart Geiser", 0, "geiseri@kde.org" ); + KCmdLineArgs::init(argc, argv, &about); + KApplication app; + + EmbedViewImp *view = new EmbedViewImp; + app.setMainWidget(view); + view->show(); + view->runScript("test.js"); + return app.exec(); +} diff --git a/kjsembed/docs/embedding/simple-embed/test.js b/kjsembed/docs/embedding/simple-embed/test.js new file mode 100644 index 00000000..2511a465 --- /dev/null +++ b/kjsembed/docs/embedding/simple-embed/test.js @@ -0,0 +1,37 @@ +#!/usr/bin/env kjsembed + +CustomOptions.orientation = Qt.Vertical; +CustomOptions.columns = 1; + +var box = new QVBox(CustomOptions); +var row1 = new QHBox(box); +var dateLabel = new QLabel(row1); +dateLabel.text = "Birthday:"; +var birthday = new KDateWidget(row1); + +var row2 = new QHBox(box); +var eyeLabel = new QLabel(row2); +eyeLabel.text = "Eye color:"; +var eyeColor = new KColorButton(row2); + +var row3 = new QHBox(box); +var notes = new KTextEdit(row3); + +box.show(); + +function handleOk() +{ + var personelData = []; // make this an array so it will convert properly + personelData = {birthday:birthday.date, eyeColor:eyeColor.color, notes:notes.text }; +// personelData[birthday] = birthday.date; +// personelData[eyeColor] = eyeColor.color; +// personelData[notes] = notes.text; + return personelData; +} + +function handleCancel() +{ + notes.text = ""; +} + + diff --git a/kjsembed/docs/examples/README b/kjsembed/docs/examples/README new file mode 100644 index 00000000..db1e2e37 --- /dev/null +++ b/kjsembed/docs/examples/README @@ -0,0 +1,67 @@ +KJSEmbed Examples + +This directory contains a number of example files that illustrate the various +features of KJSEmbed. + +Demos + +This section contains examples that show how the features of KJSEmbed can be +combined to create useful tools. + +ButtonMaker An application for creating buttons for web sites. +EnvelopeMaker An application for creating printed envelopes. +xmlgui Creates a complete KDE GUI shell using XMLGUI and KStdAction. +readonlypart A simple web browser that embeds KHTMLPart. +readwritepart Shows how to embed a read-write KPart. +calc A simple calculator application. +grepdialog Loads .ui files to provide a GUI for grep. +docviewer KJSEmbed documentation browser. +SAX Demos that show how to use the SAX API from JS. +DCOP Using DCOP from scripts. +Command Line An interactive command-line prompt for KJSEmbed implemented as a + script. + +Advanced Demos + +This section contains examples that illustrate some of the more advanced +features of KJSEmbed. + +htmlinfo Reports information about an HTML file. +imageinfo Various scripts using the Image builtin object. +html2text Uses the KParts::Plugin to extend KWrite. +eventhandling Two demos that show off event handling, including the standard + scribble demo. +SQL Support Accessing SQL databases. + +Examples + +This section contains examples that illustrate particular KJSEmbed facilities. + +customwidget Creates a simple form directly from Javascript. +treeview Two examples that create a graphical tree. One from a JS + data structure, the other from the widget tree of a ui file. +qobject-dom Illustrates the QObject DOM API. +connect-cpp Connects a signal to slot. +connect Connects signals of various types to JS methods. +imageviewer Illustrates the use of QPixmap values. +netaccess Illustrates the bindings to KIO::NetAccess. +listview Creates a simple KListView. +frame Shows off QFrame support and the use of enums. +timer Creates a flashing LED using QTimer. +Actions A simple KAction demo. +Built-In Messages Demonstrates the built-in message dialogs. +Image Tweak Tweaking images. +Image Fun More fun with images +Space Invaders A space invaders game. +JS UIC An easy way to deal with UI files. +Multi-file Scripts Multi-file Scripts. +Opaque Values Opaque types. +Standard Icons Loading standard icons. +QComboBox A simple demo of QComboBox. +Embedding several Shows how to embed multiple parts in the same script. +KParts +Writing data Shows how to send data directly to a part, rather than +directly to a viewing a file. +KPart + +------------------------------------------------------------------------------- diff --git a/kjsembed/docs/examples/actions/simple-actions.js b/kjsembed/docs/examples/actions/simple-actions.js new file mode 100644 index 00000000..121c9d15 --- /dev/null +++ b/kjsembed/docs/examples/actions/simple-actions.js @@ -0,0 +1,19 @@ +#!/usr/bin/env kjscmd + +var mw = new KMainWindow(); + +var view = new KTextEdit(mw); +mw.setCentralWidget( view ); + +mw.open = function() { + System.err.println('open!!!!!!!!!!!!!!!!!!!!!!!!'); +} + +StdAction.quit( mw, 'close()', mw.actionCollection() ); +StdAction.open( 0, 0, mw.actionCollection() ); + + +mw.createGUI("kjscmdui.rc"); +mw.show(); + +application.exec(); diff --git a/kjsembed/docs/examples/builtins/messages.js b/kjsembed/docs/examples/builtins/messages.js new file mode 100755 index 00000000..4fba62bf --- /dev/null +++ b/kjsembed/docs/examples/builtins/messages.js @@ -0,0 +1,8 @@ +#!/usr/bin/env kjscmd + +var text = prompt("Enter some text.", "Some text"); +var cnf = confirm("Did you really mean to enter " + text ); +if ( cnf == 3) { + alert("Good job entering " + text ); +} else + alert("Maby you need to try harder next time."); diff --git a/kjsembed/docs/examples/buttonmaker/01.png b/kjsembed/docs/examples/buttonmaker/01.png Binary files differnew file mode 100644 index 00000000..8866be37 --- /dev/null +++ b/kjsembed/docs/examples/buttonmaker/01.png diff --git a/kjsembed/docs/examples/buttonmaker/02.png b/kjsembed/docs/examples/buttonmaker/02.png Binary files differnew file mode 100644 index 00000000..d531ab8b --- /dev/null +++ b/kjsembed/docs/examples/buttonmaker/02.png diff --git a/kjsembed/docs/examples/buttonmaker/03.png b/kjsembed/docs/examples/buttonmaker/03.png Binary files differnew file mode 100644 index 00000000..e83f9d61 --- /dev/null +++ b/kjsembed/docs/examples/buttonmaker/03.png diff --git a/kjsembed/docs/examples/buttonmaker/04.png b/kjsembed/docs/examples/buttonmaker/04.png Binary files differnew file mode 100644 index 00000000..2dae0228 --- /dev/null +++ b/kjsembed/docs/examples/buttonmaker/04.png diff --git a/kjsembed/docs/examples/buttonmaker/05.png b/kjsembed/docs/examples/buttonmaker/05.png Binary files differnew file mode 100644 index 00000000..1a7293e5 --- /dev/null +++ b/kjsembed/docs/examples/buttonmaker/05.png diff --git a/kjsembed/docs/examples/buttonmaker/06.png b/kjsembed/docs/examples/buttonmaker/06.png Binary files differnew file mode 100644 index 00000000..f5074bc7 --- /dev/null +++ b/kjsembed/docs/examples/buttonmaker/06.png diff --git a/kjsembed/docs/examples/buttonmaker/07.png b/kjsembed/docs/examples/buttonmaker/07.png Binary files differnew file mode 100644 index 00000000..861253d8 --- /dev/null +++ b/kjsembed/docs/examples/buttonmaker/07.png diff --git a/kjsembed/docs/examples/buttonmaker/08.png b/kjsembed/docs/examples/buttonmaker/08.png Binary files differnew file mode 100644 index 00000000..c48e10cf --- /dev/null +++ b/kjsembed/docs/examples/buttonmaker/08.png diff --git a/kjsembed/docs/examples/buttonmaker/09.png b/kjsembed/docs/examples/buttonmaker/09.png Binary files differnew file mode 100644 index 00000000..7ed0db8d --- /dev/null +++ b/kjsembed/docs/examples/buttonmaker/09.png diff --git a/kjsembed/docs/examples/buttonmaker/ButtonMakerUI.ui b/kjsembed/docs/examples/buttonmaker/ButtonMakerUI.ui new file mode 100644 index 00000000..23c30593 --- /dev/null +++ b/kjsembed/docs/examples/buttonmaker/ButtonMakerUI.ui @@ -0,0 +1,592 @@ +<!DOCTYPE UI><UI version="3.3" stdsetdef="1"> +<class>Form1</class> +<widget class="QWidget"> + <property name="name"> + <cstring>Form1</cstring> + </property> + <property name="geometry"> + <rect> + <x>0</x> + <y>0</y> + <width>646</width> + <height>456</height> + </rect> + </property> + <property name="sizePolicy"> + <sizepolicy> + <hsizetype>3</hsizetype> + <vsizetype>3</vsizetype> + <horstretch>0</horstretch> + <verstretch>0</verstretch> + </sizepolicy> + </property> + <vbox> + <property name="name"> + <cstring>unnamed</cstring> + </property> + <widget class="QGroupBox"> + <property name="name"> + <cstring>PreviewBox</cstring> + </property> + <property name="sizePolicy"> + <sizepolicy> + <hsizetype>5</hsizetype> + <vsizetype>5</vsizetype> + <horstretch>0</horstretch> + <verstretch>1</verstretch> + </sizepolicy> + </property> + <property name="title"> + <string>Preview</string> + </property> + <grid> + <property name="name"> + <cstring>unnamed</cstring> + </property> + <widget class="QLabel" row="0" column="0"> + <property name="name"> + <cstring>Preview</cstring> + </property> + <property name="text"> + <string>none</string> + </property> + <property name="alignment"> + <set>AlignCenter</set> + </property> + </widget> + </grid> + </widget> + <widget class="QLayoutWidget"> + <property name="name"> + <cstring>layout6</cstring> + </property> + <hbox> + <property name="name"> + <cstring>unnamed</cstring> + </property> + <widget class="QLabel"> + <property name="name"> + <cstring>textLabel1</cstring> + </property> + <property name="text"> + <string>Button text:</string> + </property> + <property name="buddy" stdset="0"> + <cstring>text</cstring> + </property> + </widget> + <widget class="KLineEdit"> + <property name="name"> + <cstring>Text</cstring> + </property> + </widget> + </hbox> + </widget> + <widget class="QButtonGroup"> + <property name="name"> + <cstring>Mode</cstring> + </property> + <property name="title"> + <string>Base Image</string> + </property> + <vbox> + <property name="name"> + <cstring>unnamed</cstring> + </property> + <widget class="QLayoutWidget"> + <property name="name"> + <cstring>layout15</cstring> + </property> + <vbox> + <property name="name"> + <cstring>unnamed</cstring> + </property> + <widget class="QLayoutWidget"> + <property name="name"> + <cstring>layout8</cstring> + </property> + <hbox> + <property name="name"> + <cstring>unnamed</cstring> + </property> + <widget class="QRadioButton"> + <property name="name"> + <cstring>Srcimg</cstring> + </property> + <property name="text"> + <string>Source &image:</string> + </property> + <property name="checked"> + <bool>true</bool> + </property> + </widget> + <widget class="KURLRequester"> + <property name="name"> + <cstring>BaseImage</cstring> + </property> + </widget> + </hbox> + </widget> + <widget class="QLayoutWidget"> + <property name="name"> + <cstring>layout14</cstring> + </property> + <hbox> + <property name="name"> + <cstring>unnamed</cstring> + </property> + <spacer> + <property name="name"> + <cstring>spacer7</cstring> + </property> + <property name="orientation"> + <enum>Horizontal</enum> + </property> + <property name="sizeType"> + <enum>Expanding</enum> + </property> + <property name="sizeHint"> + <size> + <width>81</width> + <height>20</height> + </size> + </property> + </spacer> + <widget class="QLayoutWidget"> + <property name="name"> + <cstring>layout13</cstring> + </property> + <hbox> + <property name="name"> + <cstring>unnamed</cstring> + </property> + <widget class="QLabel"> + <property name="name"> + <cstring>textLabel3_2</cstring> + </property> + <property name="text"> + <string>X scale:</string> + </property> + </widget> + <widget class="KIntSpinBox"> + <property name="name"> + <cstring>Xscale</cstring> + </property> + <property name="value"> + <number>1</number> + </property> + </widget> + </hbox> + </widget> + <widget class="QLayoutWidget"> + <property name="name"> + <cstring>layout12</cstring> + </property> + <hbox> + <property name="name"> + <cstring>unnamed</cstring> + </property> + <widget class="QLabel"> + <property name="name"> + <cstring>textLabel4_2</cstring> + </property> + <property name="text"> + <string>Y scale:</string> + </property> + </widget> + <widget class="KIntSpinBox"> + <property name="name"> + <cstring>Yscale</cstring> + </property> + <property name="value"> + <number>1</number> + </property> + </widget> + </hbox> + </widget> + </hbox> + </widget> + </vbox> + </widget> + <widget class="QLayoutWidget"> + <property name="name"> + <cstring>layout17</cstring> + </property> + <hbox> + <property name="name"> + <cstring>unnamed</cstring> + </property> + <widget class="QRadioButton"> + <property name="name"> + <cstring>Pillbox</cstring> + </property> + <property name="text"> + <string>Generate pillbox</string> + </property> + </widget> + <spacer> + <property name="name"> + <cstring>spacer6</cstring> + </property> + <property name="orientation"> + <enum>Horizontal</enum> + </property> + <property name="sizeType"> + <enum>Expanding</enum> + </property> + <property name="sizeHint"> + <size> + <width>16</width> + <height>20</height> + </size> + </property> + </spacer> + <widget class="QLayoutWidget"> + <property name="name"> + <cstring>layout9</cstring> + </property> + <hbox> + <property name="name"> + <cstring>unnamed</cstring> + </property> + <widget class="QLabel"> + <property name="name"> + <cstring>textLabel2</cstring> + </property> + <property name="text"> + <string>Width:</string> + </property> + </widget> + <widget class="KIntSpinBox"> + <property name="name"> + <cstring>Xsize</cstring> + </property> + <property name="enabled"> + <bool>false</bool> + </property> + <property name="maxValue"> + <number>512</number> + </property> + <property name="value"> + <number>128</number> + </property> + </widget> + </hbox> + </widget> + <widget class="QLayoutWidget"> + <property name="name"> + <cstring>layout10</cstring> + </property> + <hbox> + <property name="name"> + <cstring>unnamed</cstring> + </property> + <widget class="QLabel"> + <property name="name"> + <cstring>textLabel1_2</cstring> + </property> + <property name="text"> + <string>Height:</string> + </property> + </widget> + <widget class="KIntSpinBox"> + <property name="name"> + <cstring>Ysize</cstring> + </property> + <property name="enabled"> + <bool>false</bool> + </property> + <property name="maxValue"> + <number>512</number> + </property> + <property name="value"> + <number>32</number> + </property> + </widget> + </hbox> + </widget> + <spacer> + <property name="name"> + <cstring>spacer8</cstring> + </property> + <property name="orientation"> + <enum>Horizontal</enum> + </property> + <property name="sizeType"> + <enum>Expanding</enum> + </property> + <property name="sizeHint"> + <size> + <width>16</width> + <height>20</height> + </size> + </property> + </spacer> + <widget class="QLayoutWidget"> + <property name="name"> + <cstring>layout15</cstring> + </property> + <hbox> + <property name="name"> + <cstring>unnamed</cstring> + </property> + <widget class="QLabel"> + <property name="name"> + <cstring>textLabel1_3</cstring> + </property> + <property name="text"> + <string>Base color:</string> + </property> + </widget> + <widget class="KColorButton"> + <property name="name"> + <cstring>BaseColor</cstring> + </property> + <property name="enabled"> + <bool>false</bool> + </property> + <property name="text"> + <string></string> + </property> + <property name="color"> + <color> + <red>0</red> + <green>255</green> + <blue>255</blue> + </color> + </property> + </widget> + </hbox> + </widget> + </hbox> + </widget> + </vbox> + </widget> + <widget class="QGroupBox"> + <property name="name"> + <cstring>TextBox</cstring> + </property> + <property name="title"> + <string>Text Style</string> + </property> + <vbox> + <property name="name"> + <cstring>unnamed</cstring> + </property> + <widget class="QLabel"> + <property name="name"> + <cstring>textLabel3</cstring> + </property> + <property name="text"> + <string>Font style:</string> + </property> + <property name="buddy" stdset="0"> + <cstring>font</cstring> + </property> + </widget> + <widget class="KFontRequester"> + <property name="name"> + <cstring>Font</cstring> + </property> + <property name="preview"> + <bool>false</bool> + </property> + </widget> + <widget class="QLayoutWidget"> + <property name="name"> + <cstring>layout16</cstring> + </property> + <hbox> + <property name="name"> + <cstring>unnamed</cstring> + </property> + <widget class="QLabel"> + <property name="name"> + <cstring>textLabel2_2</cstring> + </property> + <property name="text"> + <string>Text X offset:</string> + </property> + </widget> + <widget class="KIntNumInput"> + <property name="name"> + <cstring>XOffset</cstring> + </property> + </widget> + <widget class="QLabel"> + <property name="name"> + <cstring>textLabel2_2_2</cstring> + </property> + <property name="text"> + <string>Text Y offset:</string> + </property> + </widget> + <widget class="KIntNumInput"> + <property name="name"> + <cstring>YOffset</cstring> + </property> + </widget> + <spacer> + <property name="name"> + <cstring>spacer6_2</cstring> + </property> + <property name="orientation"> + <enum>Horizontal</enum> + </property> + <property name="sizeType"> + <enum>Expanding</enum> + </property> + <property name="sizeHint"> + <size> + <width>31</width> + <height>20</height> + </size> + </property> + </spacer> + </hbox> + </widget> + <widget class="QLayoutWidget"> + <property name="name"> + <cstring>layout10</cstring> + </property> + <hbox> + <property name="name"> + <cstring>unnamed</cstring> + </property> + <widget class="QLayoutWidget"> + <property name="name"> + <cstring>layout7</cstring> + </property> + <hbox> + <property name="name"> + <cstring>unnamed</cstring> + </property> + <widget class="QLabel"> + <property name="name"> + <cstring>textLabel4</cstring> + </property> + <property name="text"> + <string>Text colors:</string> + </property> + <property name="buddy" stdset="0"> + <cstring>textColors</cstring> + </property> + </widget> + <widget class="KDualColorButton"> + <property name="name"> + <cstring>TextColors</cstring> + </property> + </widget> + </hbox> + </widget> + <spacer> + <property name="name"> + <cstring>spacer4</cstring> + </property> + <property name="orientation"> + <enum>Horizontal</enum> + </property> + <property name="sizeType"> + <enum>Expanding</enum> + </property> + <property name="sizeHint"> + <size> + <width>40</width> + <height>20</height> + </size> + </property> + </spacer> + <widget class="QLayoutWidget"> + <property name="name"> + <cstring>layout8</cstring> + </property> + <hbox> + <property name="name"> + <cstring>unnamed</cstring> + </property> + <widget class="QLabel"> + <property name="name"> + <cstring>textLabel5</cstring> + </property> + <property name="text"> + <string>Shadow offset:</string> + </property> + <property name="buddy" stdset="0"> + <cstring>offset</cstring> + </property> + </widget> + <widget class="KIntNumInput"> + <property name="name"> + <cstring>Offset</cstring> + </property> + <property name="value"> + <number>1</number> + </property> + </widget> + </hbox> + </widget> + </hbox> + </widget> + </vbox> + </widget> + </vbox> +</widget> +<connections> + <connection> + <sender>Srcimg</sender> + <signal>toggled(bool)</signal> + <receiver>BaseImage</receiver> + <slot>setEnabled(bool)</slot> + </connection> + <connection> + <sender>Srcimg</sender> + <signal>toggled(bool)</signal> + <receiver>Xscale</receiver> + <slot>setEnabled(bool)</slot> + </connection> + <connection> + <sender>Srcimg</sender> + <signal>toggled(bool)</signal> + <receiver>Yscale</receiver> + <slot>setEnabled(bool)</slot> + </connection> + <connection> + <sender>Pillbox</sender> + <signal>toggled(bool)</signal> + <receiver>Ysize</receiver> + <slot>setEnabled(bool)</slot> + </connection> + <connection> + <sender>Pillbox</sender> + <signal>toggled(bool)</signal> + <receiver>Xsize</receiver> + <slot>setEnabled(bool)</slot> + </connection> + <connection> + <sender>Pillbox</sender> + <signal>toggled(bool)</signal> + <receiver>BaseColor</receiver> + <slot>setEnabled(bool)</slot> + </connection> +</connections> +<layoutdefaults spacing="6" margin="11"/> +<includehints> + <includehint>klineedit.h</includehint> + <includehint>kurlrequester.h</includehint> + <includehint>klineedit.h</includehint> + <includehint>kpushbutton.h</includehint> + <includehint>knuminput.h</includehint> + <includehint>knuminput.h</includehint> + <includehint>knuminput.h</includehint> + <includehint>knuminput.h</includehint> + <includehint>kcolorbutton.h</includehint> + <includehint>kfontrequester.h</includehint> + <includehint>knuminput.h</includehint> + <includehint>knuminput.h</includehint> + <includehint>knuminput.h</includehint> + <includehint>knuminput.h</includehint> + <includehint>kdualcolorbutton.h</includehint> + <includehint>knuminput.h</includehint> + <includehint>knuminput.h</includehint> +</includehints> +</UI> diff --git a/kjsembed/docs/examples/buttonmaker/buttonmaker.desktop b/kjsembed/docs/examples/buttonmaker/buttonmaker.desktop new file mode 100644 index 00000000..0e6deaa4 --- /dev/null +++ b/kjsembed/docs/examples/buttonmaker/buttonmaker.desktop @@ -0,0 +1,10 @@ +[Desktop Entry] +Exec=kjscmd `kde-config --prefix`/share/apps/buttonmaker/buttonmaker.js +GenericName=Webpage Button Maker +Icon=exec +MimeType= +Name=ButtonMaker +StartupNotify=true +Terminal=false +Type=Application +X-KDE-SubstituteUID=false diff --git a/kjsembed/docs/examples/buttonmaker/buttonmaker.js b/kjsembed/docs/examples/buttonmaker/buttonmaker.js new file mode 100755 index 00000000..ac85b878 --- /dev/null +++ b/kjsembed/docs/examples/buttonmaker/buttonmaker.js @@ -0,0 +1,266 @@ +#!/usr/bin/env kjscmd + +StdDirs.addResourceType("buttonmaker", StdDirs.kde_default("data") + "/buttonmaker"); + +var imgfx = new ImageFX(); +var win = new KMainWindow(this); + +try { +//var view = Factory.loadui(StdDirs.findResource("buttonmaker", "ButtonMakerUI.ui"), this, win); + var view = Factory.loadui("ButtonMakerUI.ui", this, win); +} +catch(err) +{ + alert( err ); + exit(); +} + +var quitAction = StdAction.quit( 0, 0, win.actionCollection() ); +var saveAction = StdAction.save( 0, 0, win.actionCollection() ); +var newAction = StdAction.fileNew( 0, 0, win.actionCollection() ); + +win.connect( quitAction, 'activated()', this, 'exit'); +win.connect( saveAction, 'activated()', this, 'saveImage'); +win.connect( newAction, 'activated()', this, 'resetView'); + + +win.connect(view.TextBox.Font, 'fontSelected(const QFont&)', this, 'updateUI' ); +win.connect(view.TextBox.TextColors, 'fgChanged(const QColor&)', this, 'updateUI' ); +win.connect(view.TextBox.TextColors, 'bgChanged(const QColor&)', this, 'updateUI' ); +win.connect(view.TextBox.Offset, 'valueChanged(int)', this, 'updateUI' ); +win.connect(view.TextBox.YOffset, 'valueChanged(int)', this, 'updateUI' ); +win.connect(view.TextBox.XOffset, 'valueChanged(int)', this, 'updateUI' ); + +win.connect(view.Text, 'returnPressed(const QString&)', this, 'updateUI'); + +win.connect(view.Mode, 'released(int)', this, 'changeMode'); +win.connect(view.Mode.Xsize, 'valueChanged(int)', this, 'updatePillBox' ); +win.connect(view.Mode.Ysize, 'valueChanged(int)', this, 'updatePillBox' ); +win.connect(view.Mode.BaseColor, 'changed(const QColor&)', this, 'updatePillBox' ); +win.connect(view.Mode.BaseImage, 'urlSelected(const QString&)', this, 'loadImage'); + +win.connect(view.Mode.Xscale, 'valueChanged(int)', this, 'updateUI' ); +win.connect(view.Mode.Yscale, 'valueChanged(int)', this, 'updateUI' ); + +var bgimage = new Pixmap(); +bgimage.resize(16,32); +bgimage.fill("blue"); + +resetView(); + +win.createGUI("buttonmaker.rc"); +win.setCentralWidget(view); +win.setCaption("ButtonMaker"); +win.show(); +application.exec(); + +function CustomPillBox() +{ + this.a = new Image(); + this.b = new Image(); + this.c = new Image(); + this.d = new Image(); + this.e = new Image(); + this.f = new Image(); + this.g = new Image(); + this.h = new Image(); + this.i = new Image(); + + this.height = function() { + return this.a.height() + this.d.height() + this.g.height(); + } + + this.width = function() { + return this.a.width() + this.b.width() + this.c.width(); + } + + this.loadImages = function() { + return ( + this.a.load(StdDirs.findResource("buttonmaker", "01.png")) && + this.b.load(StdDirs.findResource("buttonmaker", "02.png")) && + this.c.load(StdDirs.findResource("buttonmaker", "03.png")) && + this.d.load(StdDirs.findResource("buttonmaker", "04.png")) && + this.e.load(StdDirs.findResource("buttonmaker", "05.png")) && + this.f.load(StdDirs.findResource("buttonmaker", "06.png")) && + this.g.load(StdDirs.findResource("buttonmaker", "07.png")) && + this.h.load(StdDirs.findResource("buttonmaker", "08.png")) && + this.i.load(StdDirs.findResource("buttonmaker", "09.png"))); + } + + this.colorize = function( color ) { + var percent = 0.55; + this.a = imgfx.blendColor( color, this.a, percent); + this.b = imgfx.blendColor( color, this.b, percent); + this.c = imgfx.blendColor( color, this.c, percent); + this.d = imgfx.blendColor( color, this.d, percent); + this.e = imgfx.blendColor( color, this.e, percent); + this.f = imgfx.blendColor( color, this.f, percent); + this.g = imgfx.blendColor( color, this.g, percent); + this.h = imgfx.blendColor( color, this.h, percent); + this.i = imgfx.blendColor( color, this.i, percent); + } + + this.resize = function( newW, newH ) { + + this.b.smoothScale( newW - ( this.a.width() + this.c.width() ), this.b.height() ); + this.h.smoothScale( newW - ( this.g.width() + this.i.width() ), this.h.height() ); + + this.d.smoothScale( this.d.width(), newH - ( this.a.height() + this.g.height() ) ); + this.f.smoothScale( this.f.width(), newH - ( this.c.height() + this.i.height() ) ); + + this.e.smoothScale( newW - ( this.a.width() + this.c.width() ), + newH - ( this.c.height() + this.i.height() ) ); + } + + this.pixmap = function(width, height){ + this.resize(width, height); + var pix = new Pixmap(); + pix.resize(width, height); + pix.fill("white"); + + var painter = new Painter(); + try { + if( painter.begin(pix) ) + { + //painter.drawRect(0,0,this.width(), this.height()); + painter.drawImage(0, 0, this.a, 0, 0, -1, -1, 0); + painter.drawImage(0, this.a.height(), this.d, 0, 0, -1, -1, 0); + painter.drawImage(0, ( this.height() - this.g.height() ) ,this.g, 0, 0, -1, -1, 0); + + painter.drawImage(this.a.width(), 0, this.b, 0, 0, -1, -1, 0); + painter.drawImage(this.d.width(), this.b.height(), this.e, 0, 0, -1, -1, 0); + painter.drawImage(this.g.width(), ( this.height() - this.h.height() ) ,this.h, 0, 0, -1, -1, 0); + + painter.drawImage(this.a.width() + this.b.width(), 0, this.c, 0, 0, -1, -1, 0); + painter.drawImage(this.d.width() + this.e.width(), this.c.height(), this.f, 0, 0, -1, -1, 0); + painter.drawImage(this.g.width() + this.h.width(), ( this.height() - this.i.height() ) ,this.i, 0, 0, -1, -1, 0); + if( painter.end() ) + pix = painter.pixmap(); + } + else + alert("Could not paint to the pixmap."); + } catch (err) { alert(err); } + return pix; + } + +} + +function render(txt, bgimg, font, offset, fgColor, bgColor, xOffset, yOffset) +{ + var h = bgimg.height(); + var w = bgimg.width(); + var fg = new Pen(); + var bg = new Pen(); + fg.setColor(fgColor); + bg.setColor(bgColor); + + var painter = new Painter(); + try { + if (painter.begin(bgimg)) + { + painter.scale( view.Mode.Xscale.value, view.Mode.Yscale.value ); + painter.setPen(bg); + painter.setFont(font); + var box = painter.textBox(txt); + var txtX = (w/2) - (box.width()/2) + xOffset; + var txtY = (h/2) + (box.height()/2) + yOffset; + painter.drawText(txtX+offset,txtY+offset,txt); + painter.setPen(fg); + painter.drawText(txtX,txtY,txt); + painter.end() + return painter.pixmap(); + } + else + alert("Could not paint to the pixmap."); + } catch (err) { alert(err); } + return new Pixmap(); +} + +function changeMode(mode) +{ + if( mode == 0) + { + loadImage(view.Mode.BaseImage.url); + } + else + { + var pb = new CustomPillBox(); + if ( !pb.loadImages() ) + alert("Error Loading Resources!"); + else + { + pb.colorize(view.Mode.BaseColor.color); + bgimage = pb.pixmap(view.Mode.Xsize.value,view.Mode.Ysize.value); + } + updateUI(); + } +} + +function updatePillBox() +{ + var pb = new CustomPillBox(); + if ( !pb.loadImages() ) + alert("Error Loading Resources!"); + else + { + pb.colorize(view.Mode.BaseColor.color); + bgimage = pb.pixmap(view.Mode.Xsize.value,view.Mode.Ysize.value); + } + updateUI(); +} + +function updateUI() +{ + view.PreviewBox.Preview.pixmap = render(view.Text.text, + bgimage, + view.TextBox.Font.font, + view.TextBox.Offset.value, + view.TextBox.TextColors.foreground, + view.TextBox.TextColors.background, + view.TextBox.XOffset.value, + view.TextBox.YOffset.value); + win.adjustSize(); +} + +function saveImage() +{ + var img = new Image(this); + var fileName = StdDialog.getSaveFileName(); + if( fileName != "") + { + var pixmap = render(view.Text.text, + bgimage, + view.TextBox.Font.font, + view.TextBox.Offset.value, + view.TextBox.TextColors.foreground, + view.TextBox.TextColors.background, + view.TextBox.XOffset.value, + view.TextBox.YOffset.value); + img.setPixmap(pixmap); + img.save(fileName); + } +} + +function resetView() +{ + view.TextBox.Offset.value = 1; + if ( application.args.length > 0 ) + view.Text.text = application.args[0]; + else + view.Text.text = ""; + view.TextBox.Font.font = ""; + view.TextBox.TextColors.foreground = "black"; + view.TextBox.TextColors.background = "white"; + view.Mode.BaseImage.url = StdDirs.findResource("buttonmaker", "default.png"); + loadImage(view.Mode.BaseImage.url); +} + +function loadImage(file) +{ + var img = new Image(this); + if (img.load(file) ) + { + bgimage = img.pixmap(); + updateUI(); + } +} diff --git a/kjsembed/docs/examples/buttonmaker/default.png b/kjsembed/docs/examples/buttonmaker/default.png Binary files differnew file mode 100644 index 00000000..6a113a17 --- /dev/null +++ b/kjsembed/docs/examples/buttonmaker/default.png diff --git a/kjsembed/docs/examples/buttonmaker/gray.png b/kjsembed/docs/examples/buttonmaker/gray.png Binary files differnew file mode 100644 index 00000000..16dc6281 --- /dev/null +++ b/kjsembed/docs/examples/buttonmaker/gray.png diff --git a/kjsembed/docs/examples/buttonmaker/package.sh b/kjsembed/docs/examples/buttonmaker/package.sh new file mode 100644 index 00000000..e8563b9a --- /dev/null +++ b/kjsembed/docs/examples/buttonmaker/package.sh @@ -0,0 +1,14 @@ +#!/bin/sh + +mkdir -p share/applnk/Scripts +mkdir -p share/apps/buttonmaker +mkdir -p share/apps/kjsembed + +RCSC="01.png 02.png 03.png 04.png 05.png 06.png 07.png 08.png 09.png default.png" + +cp buttonmaker.js $RCSC ButtonMakerUI.ui share/apps/buttonmaker +cp buttonmaker.desktop share/applnk/Scripts +cp kjsuic.js share/apps/kjsembed + +shar -M -z -X share > buttonmaker.sh +rm -rf share diff --git a/kjsembed/docs/examples/buttonmaker/pillbox.js b/kjsembed/docs/examples/buttonmaker/pillbox.js new file mode 100755 index 00000000..25c50ae1 --- /dev/null +++ b/kjsembed/docs/examples/buttonmaker/pillbox.js @@ -0,0 +1,172 @@ +#!/usr/bin/env kjscmd + +function BaseImage() +{ + this.a = new Image(this); + this.b = new Image(this); + this.c = new Image(this); + this.d = new Image(this); + this.e = new Image(this); + this.f = new Image(this); + this.g = new Image(this); + this.h = new Image(this); + this.i = new Image(this); + + this.height = function() { + return this.a.height() + this.d.height() + this.g.height(); + } + + this.width = function() { + return this.a.width() + this.b.width() + this.c.width(); + } + + this.loadImages = function() { + return ( + this.a.load("01.png") && + this.b.load("02.png") && + this.c.load("03.png") && + this.d.load("04.png") && + this.e.load("05.png") && + this.f.load("06.png") && + this.g.load("07.png") && + this.h.load("08.png") && + this.i.load("09.png") ); + } + + this.colorize = function( color ) { + var percent = 0.55; + var imgfx = new ImageFX(); + + this.a = imgfx.blendColor( color, this.a, percent); + this.b = imgfx.blendColor( color, this.b, percent); + this.c = imgfx.blendColor( color, this.c, percent); + this.d = imgfx.blendColor( color, this.d, percent); + this.e = imgfx.blendColor( color, this.e, percent); + this.f = imgfx.blendColor( color, this.f, percent); + this.g = imgfx.blendColor( color, this.g, percent); + this.h = imgfx.blendColor( color, this.h, percent); + this.i = imgfx.blendColor( color, this.i, percent); + } + + this.resize = function( newW, newH ) { + + this.b.smoothScale( newW - ( this.a.width() + this.c.width() ), this.b.height() ); + this.h.smoothScale( newW - ( this.g.width() + this.i.width() ), this.h.height() ); + + this.d.smoothScale( this.d.width(), newH - ( this.a.height() + this.g.height() ) ); + this.f.smoothScale( this.f.width(), newH - ( this.c.height() + this.i.height() ) ); + + this.e.smoothScale( newW - ( this.a.width() + this.c.width() ), + newH - ( this.c.height() + this.i.height() ) ); + } + + this.test = function( parent ) { + var box = new QHBox(parent); + var vbox1 = new QVBox(box); + var vbox2 = new QVBox(box); + var vbox3 = new QVBox(box); + var l1 = new QLabel(vbox1); + l1.pixmap = this.a.pixmap(); + + var l2 = new QLabel(vbox1); + l2.pixmap = this.d.pixmap(); + + var l3 = new QLabel(vbox1); + l3.pixmap = this.g.pixmap(); + + var l4 = new QLabel(vbox2); + l4.pixmap = this.b.pixmap(); + + var l5 = new QLabel(vbox2); + l5.pixmap = this.e.pixmap(); + + var l6 = new QLabel(vbox2); + l6.pixmap = this.h.pixmap(); + + var l7 = new QLabel(vbox3); + l7.pixmap = this.c.pixmap(); + + var l8 = new QLabel(vbox3); + l8.pixmap = this.f.pixmap(); + + var l9 = new QLabel(vbox3); + l9.pixmap = this.i.pixmap(); + } + + this.pixmap = function(width, height){ + var pix = new Pixmap(this); + pix.resize(width,height); + pix.fill("white"); + var painter = new Painter(this); + if( painter.begin(pix) ) + { + this.paint(painter); + if( painter.end() ) + return painter.pixmap(); + } + return pix; + } + + this.paint = function(painter){ + + painter.drawRect(0,0,this.width(), this.height()); + + painter.drawImage(0, 0, this.a, 0, 0, -1, -1, 0); + painter.drawImage(0, this.a.height(), this.d, 0, 0, -1, -1, 0); + painter.drawImage(0, ( this.height() - this.g.height() ) ,this.g, 0, 0, -1, -1, 0); + + painter.drawImage(this.a.width(), 0, this.b, 0, 0, -1, -1, 0); + painter.drawImage(this.d.width(), this.b.height(), this.e, 0, 0, -1, -1, 0); + painter.drawImage(this.g.width(), ( this.height() - this.h.height() ) ,this.h, 0, 0, -1, -1, 0); + + painter.drawImage(this.a.width() + this.b.width(), 0, this.c, 0, 0, -1, -1, 0); + painter.drawImage(this.d.width() + this.e.width(), this.c.height(), this.f, 0, 0, -1, -1, 0); + painter.drawImage(this.g.width() + this.h.width(), ( this.height() - this.i.height() ) ,this.i, 0, 0, -1, -1, 0); + } + + this.widget = function(canvas) { + var painter = new Painter(this); + if( painter.begin(canvas) ) + { + this.paint(painter); + if( painter.end() ) + return true; + } + return false; + } +} + + +var base = new BaseImage(); +var label = new QLabel(this); + + +if ( !base.loadImages() ) + alert("Error Loading Resources!"); + +base.colorize("blue"); +var H = 128; +var W = 128; + +base.resize(W,H); + +var box = new QHBox(this); +var label = new QLabel(box); +label.resize(W,H); +label.paintEvent = function(ev) +{ + println("paint..."); + base.widget(label); +} + +var label2 = new QLabel(box); +label2.pixmap = base.pixmap(W,H); + +base.test(box); + +box.show(); +box.resize(W*3, H) + +application.exec(); + +//img.load("cl.png"); img.blendColor( "blue", 0.20); img.smoothScale(16,128); lab.pixmap = img.pixmap diff --git a/kjsembed/docs/examples/calc/calc.js b/kjsembed/docs/examples/calc/calc.js new file mode 100755 index 00000000..8ff7a403 --- /dev/null +++ b/kjsembed/docs/examples/calc/calc.js @@ -0,0 +1,65 @@ +#!/usr/bin/env kjscmd + + +function Calculator(ui) +{ + // Setup entry functions + var display = ui.child('display'); + this.display = display; + + this.one = function() { display.intValue = display.intValue*10+1; } + this.two = function() { display.intValue = display.intValue*10+2; } + this.three = function() { display.intValue = display.intValue*10+3; } + this.four = function() { display.intValue = display.intValue*10+4; } + this.five = function() { display.intValue = display.intValue*10+5; } + this.six = function() { display.intValue = display.intValue*10+6; } + this.seven = function() { display.intValue = display.intValue*10+7; } + this.eight = function() { display.intValue = display.intValue*10+8; } + this.nine = function() { display.intValue = display.intValue*10+9; } + this.zero = function() { display.intValue = display.intValue*10+0; } + + ui.connect( ui.child('one'), 'clicked()', this, 'one' ); + ui.connect( ui.child('two'), 'clicked()', this, 'two' ); + ui.connect( ui.child('three'), 'clicked()', this, 'three' ); + ui.connect( ui.child('four'), 'clicked()', this, 'four' ); + ui.connect( ui.child('five'), 'clicked()', this, 'five' ); + ui.connect( ui.child('six'), 'clicked()', this, 'six' ); + ui.connect( ui.child('seven'), 'clicked()', this, 'seven' ); + ui.connect( ui.child('eight'), 'clicked()', this, 'eight' ); + ui.connect( ui.child('nine'), 'clicked()', this, 'nine' ); + ui.connect( ui.child('zero'), 'clicked()', this, 'zero' ); + + this.val = 0; + this.lastop = function() {} + + this.plus = function() + { + this.val = display.intValue+this.val; + display.intValue = 0; + this.lastop=this.plus + } + + this.minus = function() + { + this.val = display.intValue-this.val; + display.intValue = 0; + this.lastop=this.minus; + } + + + ui.connect( ui.child('plus'), 'clicked()', this, 'plus' ); + ui.connect( ui.child('minus'), 'clicked()', this, 'minus' ); + + this.equals = function() { this.lastop(); display.intValue = this.val; } + this.clear = function() { this.lastop=function(){}; display.intValue = 0; this.val = 0; } + + ui.connect( ui.child('equals'), 'clicked()', this, 'equals' ); + ui.connect( ui.child('clear'), 'clicked()', this, 'clear' ); +} + +var ui = Factory.loadui('calc.ui'); +var calc = new Calculator(ui); + +ui.show(); +application.exec(); + diff --git a/kjsembed/docs/examples/calc/calc.ui b/kjsembed/docs/examples/calc/calc.ui new file mode 100644 index 00000000..773ea848 --- /dev/null +++ b/kjsembed/docs/examples/calc/calc.ui @@ -0,0 +1,258 @@ +<!DOCTYPE UI><UI version="3.3" stdsetdef="1"> +<class>calc</class> +<widget class="QWidget"> + <property name="name"> + <cstring>calc</cstring> + </property> + <property name="geometry"> + <rect> + <x>0</x> + <y>0</y> + <width>237</width> + <height>159</height> + </rect> + </property> + <property name="caption"> + <string>JS Calculator</string> + </property> + <vbox> + <property name="name"> + <cstring>unnamed</cstring> + </property> + <widget class="QLCDNumber"> + <property name="name"> + <cstring>display</cstring> + </property> + <property name="numDigits"> + <number>18</number> + </property> + </widget> + <widget class="QLayoutWidget"> + <property name="name"> + <cstring>layout2</cstring> + </property> + <grid> + <property name="name"> + <cstring>unnamed</cstring> + </property> + <widget class="QPushButton" row="1" column="3"> + <property name="name"> + <cstring>plus</cstring> + </property> + <property name="text"> + <string>+</string> + </property> + </widget> + <widget class="QPushButton" row="0" column="4"> + <property name="name"> + <cstring>all_clear</cstring> + </property> + <property name="text"> + <string>AC</string> + </property> + </widget> + <widget class="QPushButton" row="2" column="3"> + <property name="name"> + <cstring>minus</cstring> + </property> + <property name="text"> + <string>-</string> + </property> + </widget> + <widget class="QPushButton" row="3" column="2" rowspan="1" colspan="2"> + <property name="name"> + <cstring>equals</cstring> + </property> + <property name="text"> + <string>=</string> + </property> + </widget> + <widget class="QPushButton" row="1" column="4"> + <property name="name"> + <cstring>clear</cstring> + </property> + <property name="text"> + <string>CL</string> + </property> + </widget> + <widget class="QPushButton" row="3" column="1"> + <property name="name"> + <cstring>zero</cstring> + </property> + <property name="text"> + <string>0</string> + </property> + </widget> + <widget class="QPushButton" row="1" column="0"> + <property name="name"> + <cstring>four</cstring> + </property> + <property name="text"> + <string>4</string> + </property> + </widget> + <widget class="QPushButton" row="0" column="1"> + <property name="name"> + <cstring>two</cstring> + </property> + <property name="text"> + <string>2</string> + </property> + </widget> + <widget class="QPushButton" row="1" column="1"> + <property name="name"> + <cstring>five</cstring> + </property> + <property name="text"> + <string>5</string> + </property> + </widget> + <widget class="QPushButton" row="0" column="2"> + <property name="name"> + <cstring>three</cstring> + </property> + <property name="text"> + <string>3</string> + </property> + </widget> + <widget class="QPushButton" row="2" column="0"> + <property name="name"> + <cstring>seven</cstring> + </property> + <property name="text"> + <string>7</string> + </property> + </widget> + <widget class="QPushButton" row="1" column="2"> + <property name="name"> + <cstring>six</cstring> + </property> + <property name="text"> + <string>6</string> + </property> + </widget> + <widget class="QPushButton" row="2" column="1"> + <property name="name"> + <cstring>eight</cstring> + </property> + <property name="text"> + <string>8</string> + </property> + </widget> + <widget class="QPushButton" row="2" column="2"> + <property name="name"> + <cstring>nine</cstring> + </property> + <property name="text"> + <string>9</string> + </property> + </widget> + <widget class="QPushButton" row="0" column="0"> + <property name="name"> + <cstring>one</cstring> + </property> + <property name="text"> + <string>1</string> + </property> + </widget> + </grid> + </widget> + </vbox> +</widget> +<connections> + <connection> + <sender>plus</sender> + <signal>clicked()</signal> + <receiver>calc</receiver> + <slot>plus()</slot> + </connection> + <connection> + <sender>minus</sender> + <signal>clicked()</signal> + <receiver>calc</receiver> + <slot>minus()</slot> + </connection> + <connection> + <sender>equals</sender> + <signal>clicked()</signal> + <receiver>calc</receiver> + <slot>equals()</slot> + </connection> + <connection> + <sender>zero</sender> + <signal>clicked()</signal> + <receiver>calc</receiver> + <slot>zero()</slot> + </connection> + <connection> + <sender>four</sender> + <signal>clicked()</signal> + <receiver>calc</receiver> + <slot>four()</slot> + </connection> + <connection> + <sender>two</sender> + <signal>clicked()</signal> + <receiver>calc</receiver> + <slot>two()</slot> + </connection> + <connection> + <sender>five</sender> + <signal>clicked()</signal> + <receiver>calc</receiver> + <slot>five()</slot> + </connection> + <connection> + <sender>three</sender> + <signal>clicked()</signal> + <receiver>calc</receiver> + <slot>three()</slot> + </connection> + <connection> + <sender>seven</sender> + <signal>clicked()</signal> + <receiver>calc</receiver> + <slot>seven()</slot> + </connection> + <connection> + <sender>six</sender> + <signal>clicked()</signal> + <receiver>calc</receiver> + <slot>six()</slot> + </connection> + <connection> + <sender>eight</sender> + <signal>clicked()</signal> + <receiver>calc</receiver> + <slot>eight()</slot> + </connection> + <connection> + <sender>nine</sender> + <signal>clicked()</signal> + <receiver>calc</receiver> + <slot>nine()</slot> + </connection> + <connection> + <sender>one</sender> + <signal>clicked()</signal> + <receiver>calc</receiver> + <slot>one()</slot> + </connection> +</connections> +<slots> + <slot>one()</slot> + <slot>two()</slot> + <slot>three()</slot> + <slot>four()</slot> + <slot>five()</slot> + <slot>six()</slot> + <slot>seven()</slot> + <slot>eight()</slot> + <slot>nine()</slot> + <slot>zero()</slot> + <slot>plus()</slot> + <slot>minus()</slot> + <slot>equals()</slot> +</slots> +<layoutdefaults spacing="6" margin="11"/> +</UI> diff --git a/kjsembed/docs/examples/cmdline/cmdline.js b/kjsembed/docs/examples/cmdline/cmdline.js new file mode 100755 index 00000000..9c96c6cb --- /dev/null +++ b/kjsembed/docs/examples/cmdline/cmdline.js @@ -0,0 +1,78 @@ +#!/usr/bin/env kjscmd + +function list(obj) +{ + println( obj ); + + for ( var i in obj ) { + try { + tp = typeof obj[i]; + + count = 20 - i.length; + spc = ''; + for ( var s=0; s < count; s++ ) + spc = spc + ' '; + + println( ' ' + i + spc + tp ); + } + catch(err) { + println( ' ' + i + spc + 'Error, ' + err ); + } + } +} + +function help() +{ + println(); + println( 'KJSCmd ' + part.versionString + ' Prompt' ); + println( '=======' + '===' + '=======' ); + println(); + println( "Type 'quit' to exit, and 'help' for this text. Anything else" ); + println( 'is evaluated by the KJSCmd engine and the result displayed.' ); + println(); +} + +function cmd_prompt() +{ + System.stdout.print( 'kjscmd> ' ); + return System.stdin.readLine(); +} + +// +// Main +// + +println( "KJSCmd " + part.versionString + " (type 'help' for more information)" ); +done = false; + +do { + + line = cmd_prompt(); + + if ( line == 'quit' ) { + done = true; + } + else if ( line == 'help' ) { + help(); + } + else if ( line == '' ) { + // DO NOTHING + } + else if ( line == null ) { + done = true; + } + else { + try { + output = eval( line ); + + if ( typeof(output) != 'undefined' ) + println( output ); + } + catch(err) { + println( 'Error: ' + err ); + } + } + +} while ( !done ); + +System.exit(0); diff --git a/kjsembed/docs/examples/combobox/combo.js b/kjsembed/docs/examples/combobox/combo.js new file mode 100644 index 00000000..3ac40491 --- /dev/null +++ b/kjsembed/docs/examples/combobox/combo.js @@ -0,0 +1,17 @@ +#!/usr/bin/env kjscmd + +// Example that uses QComboBox + +var hbox = new QHBox(); + +var l = new QLabel( hbox ); +l.text = 'Combo test'; + +var cb = new QComboBox( hbox ); +cb.insertItem( 'test 1' ); +cb.insertItem( 'test 2' ); +cb.insertItem( 'test 3' ); +cb.insertItem( 'test 4' ); + +hbox.show(); +application.exec(); diff --git a/kjsembed/docs/examples/connect-cpp/connect-cpp.js b/kjsembed/docs/examples/connect-cpp/connect-cpp.js new file mode 100644 index 00000000..c79d1dea --- /dev/null +++ b/kjsembed/docs/examples/connect-cpp/connect-cpp.js @@ -0,0 +1,36 @@ +#!/usr/bin/env kjscmd + +function item( parent ) +{ + var hbox = new QHBox( parent ); + + var led = new KLed( hbox ); + var btn = new QCheckBox( hbox ); + btn.checked = true; + btn.text = 'Toggle LED'; + + var r = Math.random(); + if ((r > 0.5)&&(r < 0.7)) + led.color = 'red'; + else if (r >= 0.7) + led.color = 'blue'; + + led.connect( btn, 'toggled(bool)', 'toggle()' ); +} + +var vbox = new QVBox( 'test' ); +vbox.margin = 6; +vbox.spacing = 4; + +var ttl = new QLabel( vbox ); +ttl.text = '<h1>Connections</h1>'; + +for ( var i = 0 ; i < 10 ; i++ ) + item( vbox ); + +var quit = new QPushButton( vbox ); +quit.text = '&Quit'; +vbox.connect( quit, 'clicked()', 'close()' ); + +vbox.show(); +application.exec(); diff --git a/kjsembed/docs/examples/connect/connect.js b/kjsembed/docs/examples/connect/connect.js new file mode 100644 index 00000000..aa56a366 --- /dev/null +++ b/kjsembed/docs/examples/connect/connect.js @@ -0,0 +1,45 @@ +#!/usr/bin/env kjscmd + +// +// Demo that connects C++ signals to JS slots of various types. +// + +// Load the demo gui +var top = Factory.loadui( 'connect.ui' ); + +// Util func to print a msg +function msg(s) +{ + top.child('output').append(s); +} + +// JS object we connect to +function DemoObj() +{ + this.func_void = function() { msg('void'); } + this.func_bool = function(b) { msg(b); } + this.func_int = function(i) { msg(i); } + this.func_string = function(s) { msg(s); } + this.func_double = function(d) { msg(d); } +} + +// +// Main +// + +var obj = new DemoObj(); + +var ve = top.child('v'); +var be = top.child('b'); +var ie = top.child('i'); +var se = top.child('s'); +var de = top.child('d'); + +top.connect( ve, 'clicked()', obj, 'func_void' ); +top.connect( be, 'toggled(bool)', obj, 'func_bool' ); +top.connect( ie, 'valueChanged(int)', obj, 'func_int' ); +top.connect( se, 'textChanged(const QString&)', obj, 'func_string' ); +top.connect( de, 'valueChanged(double)', obj, 'func_double' ); + +top.show(); +application.exec(); diff --git a/kjsembed/docs/examples/connect/connect.ui b/kjsembed/docs/examples/connect/connect.ui new file mode 100644 index 00000000..5b172a8d --- /dev/null +++ b/kjsembed/docs/examples/connect/connect.ui @@ -0,0 +1,160 @@ +<!DOCTYPE UI><UI version="3.1" stdsetdef="1"> +<class>demo</class> +<widget class="QWidget"> + <property name="name"> + <cstring>demo</cstring> + </property> + <property name="geometry"> + <rect> + <x>0</x> + <y>0</y> + <width>434</width> + <height>348</height> + </rect> + </property> + <property name="caption"> + <string>Connect Demo</string> + </property> + <grid> + <property name="name"> + <cstring>unnamed</cstring> + </property> + <widget class="KLineEdit" row="3" column="1"> + <property name="name"> + <cstring>s</cstring> + </property> + </widget> + <widget class="QLabel" row="0" column="2"> + <property name="name"> + <cstring>textLabel2_2</cstring> + </property> + <property name="paletteBackgroundColor"> + <color> + <red>160</red> + <green>239</green> + <blue>139</blue> + </color> + </property> + <property name="frameShape"> + <enum>Box</enum> + </property> + <property name="text"> + <string>Slot Output</string> + </property> + <property name="alignment"> + <set>AlignCenter</set> + </property> + </widget> + <widget class="KDoubleNumInput" row="5" column="1"> + <property name="name"> + <cstring>d</cstring> + </property> + </widget> + <widget class="QSpinBox" row="4" column="1"> + <property name="name"> + <cstring>i</cstring> + </property> + </widget> + <widget class="QLabel" row="0" column="0" rowspan="1" colspan="2"> + <property name="name"> + <cstring>textLabel1_2</cstring> + </property> + <property name="paletteBackgroundColor"> + <color> + <red>160</red> + <green>239</green> + <blue>139</blue> + </color> + </property> + <property name="frameShape"> + <enum>Box</enum> + </property> + <property name="frameShadow"> + <enum>Plain</enum> + </property> + <property name="text"> + <string>Signal Source</string> + </property> + <property name="alignment"> + <set>AlignCenter</set> + </property> + </widget> + <widget class="QCheckBox" row="2" column="0" rowspan="1" colspan="2"> + <property name="name"> + <cstring>b</cstring> + </property> + <property name="text"> + <string>Bool</string> + </property> + </widget> + <widget class="QPushButton" row="1" column="0" rowspan="1" colspan="2"> + <property name="name"> + <cstring>v</cstring> + </property> + <property name="text"> + <string>Void</string> + </property> + </widget> + <widget class="QLabel" row="5" column="0"> + <property name="name"> + <cstring>textLabel3</cstring> + </property> + <property name="text"> + <string>Double:</string> + </property> + </widget> + <widget class="QLabel" row="4" column="0"> + <property name="name"> + <cstring>textLabel2</cstring> + </property> + <property name="text"> + <string>Int:</string> + </property> + </widget> + <widget class="QLabel" row="3" column="0"> + <property name="name"> + <cstring>textLabel1</cstring> + </property> + <property name="text"> + <string>String:</string> + </property> + </widget> + <widget class="KTextBrowser" row="1" column="2" rowspan="6" colspan="1"> + <property name="name"> + <cstring>output</cstring> + </property> + <property name="sizePolicy"> + <sizepolicy> + <hsizetype>7</hsizetype> + <vsizetype>7</vsizetype> + <horstretch>1</horstretch> + <verstretch>0</verstretch> + </sizepolicy> + </property> + </widget> + <spacer row="6" column="1"> + <property name="name"> + <cstring>spacer1</cstring> + </property> + <property name="orientation"> + <enum>Vertical</enum> + </property> + <property name="sizeType"> + <enum>Expanding</enum> + </property> + <property name="sizeHint"> + <size> + <width>20</width> + <height>31</height> + </size> + </property> + </spacer> + </grid> +</widget> +<layoutdefaults spacing="6" margin="11"/> +<includehints> + <includehint>klineedit.h</includehint> + <includehint>knuminput.h</includehint> + <includehint>ktextbrowser.h</includehint> +</includehints> +</UI> diff --git a/kjsembed/docs/examples/customwidget/README b/kjsembed/docs/examples/customwidget/README new file mode 100644 index 00000000..6100357d --- /dev/null +++ b/kjsembed/docs/examples/customwidget/README @@ -0,0 +1,2 @@ +This example shows how scripts can create widgets directly. It creates +and displays the window shown in customwidget.png. diff --git a/kjsembed/docs/examples/customwidget/custom_widget.js b/kjsembed/docs/examples/customwidget/custom_widget.js new file mode 100755 index 00000000..dbab2d8f --- /dev/null +++ b/kjsembed/docs/examples/customwidget/custom_widget.js @@ -0,0 +1,57 @@ +#!/usr/bin/env kjscmd + +// +// Script demonstrating how to create a custom widget. +// + +function createField( parent ) +{ + var hbox = new QHBox( box, 'hb' ); + + var label = new QLabel( hbox ); + label.text = 'Filename:'; + var ed = new QLineEdit( hbox, 'lineed' ); + ed.text = './my_file.txt'; + var pb = new QPushButton( hbox, 'button' ); + pb.text = 'Br&owse'; + var led = new KLed( hbox, 'led' ); +} + +function createGroup( parent ) +{ + var grp = new QGroupBox( box, 'grp' ); + grp.columns = 1; + grp.title = 'A QGroupBox'; + + var cb1 = new QCheckBox( grp, 'check1' ); + var cb2 = new QCheckBox( grp, 'check2' ); + cb1.text = 'Check Box One'; + cb2.text = 'Check Box Two'; + + return grp; +} + +// Outer layout +var box = new QVBox(); +box.margin = 6; + +// Title +var ttl = new QLabel( box, 'title' ); +ttl.text = '<qt><center><h3>KJSEmbed Object Creation Demo</h3></center><hr></qt>'; + +// Named field +createField( box ); + +// Text editor +var l = new QLabel( box, 'tl' ); +l.txt = 'Editable Text Widget:'; +var txt = new QTextEdit( box, 'text_edit' ); +txt.text = '<qt>This is an editable text widget created from <i>Javascript</i> using the ' + + '<b>KJSEmbed</b> library. As you can see, the facilities are powerful enough ' + + 'for many useful applications to be found.</qt>'; + +// Group of check boxes +var grp = createGroup( box ); + +box.show(); +application.exec(); diff --git a/kjsembed/docs/examples/dcop/interface.js b/kjsembed/docs/examples/dcop/interface.js new file mode 100755 index 00000000..ed699768 --- /dev/null +++ b/kjsembed/docs/examples/dcop/interface.js @@ -0,0 +1,17 @@ +#!/usr/bin/env kjscmd + +function someInterface( foo ) +{ + println("Foo happend with " + foo ); +} + +function anotherInterface( bar ) +{ + return "Bar " + bar; +} + +var dcop = new DCOPInterface(this, "someInterface"); +dcop.publish("void someInterface(QString)"); +dcop.publish("QString anotherInterface(QString)"); + +application.exec(); diff --git a/kjsembed/docs/examples/dcop/rss.js b/kjsembed/docs/examples/dcop/rss.js new file mode 100755 index 00000000..c1eb3882 --- /dev/null +++ b/kjsembed/docs/examples/dcop/rss.js @@ -0,0 +1,39 @@ +#!/usr/bin/env kjscmd + +function newArticles( articles ) +{ + + var box = new QVBox(main); + var count = articles.call("count()"); + var label = new QLabel(box); + var list = new KListBox(box); + + + label.text = count + " articles for " + articles.call("title()"); + for( var idx = 0; idx < count; ++idx) + { + var article = articles.call("article(int)", idx); + list.insertItem( article.call( "title()" )); + } + box.show(); + return true; +} + +var main = new QHBox(this) +var dcop = new DCOPInterface(this, "news"); +dcop.publish("void newArticles(DCOPRef)"); + +var client = new DCOPClient(this); +var feeds = client.call( "rssservice", "RSSService", "list()" ); + +for( var idx = 0; idx < feeds.length; ++idx) +{ + var doc = client.call( "rssservice", "RSSService", "add(QString)", feeds[idx] ); + client.connectDCOPSignal("rssservice", doc.obj(), "documentUpdated(DCOPRef)", + "news","newArticles(DCOPRef)"); + doc.call("refresh()"); +} +main.show(); + +application.exec(); + diff --git a/kjsembed/docs/examples/dcop/signalslot.js b/kjsembed/docs/examples/dcop/signalslot.js new file mode 100755 index 00000000..884faa29 --- /dev/null +++ b/kjsembed/docs/examples/dcop/signalslot.js @@ -0,0 +1,25 @@ +#!/usr/bin/env kjscmd + +function newWeather( station ) +{ + var temp = client.call("KWeatherService", "WeatherService", "temperature(QString)", "KMKE"); + var name = client.call("KWeatherService", "WeatherService", "stationName(QString)", "KMKE"); + var label = new QLabel(this); + label.text = "The temperature at " + name + " is " + temp; + label.show(); +} + +var client = new DCOPClient(this); +if ( client.attach() ) +{ + var dcop = new DCOPInterface(this, "weather"); + dcop.publish("void newWeather(QString)"); + + client.connectDCOPSignal("KWeatherService", "WeatherService", "fileUpdate(QString)", + "weather","newWeather(QString)"); + + + client.send("KWeatherService", "WeatherService", "update(QString)", "KMKE"); + + application.exec(); +} diff --git a/kjsembed/docs/examples/dcop/weather.js b/kjsembed/docs/examples/dcop/weather.js new file mode 100755 index 00000000..8d8a59c3 --- /dev/null +++ b/kjsembed/docs/examples/dcop/weather.js @@ -0,0 +1,25 @@ +#!/usr/bin/env kjscmd + +var dcop = new DCOPClient(this); +var box = new QHBox(this); +var go = new KPushButton(box); +var loc = new KLineEdit(box); + +go.pixmap = StdIcons.DesktopIcon("go",32); +go.connect(go, "clicked()", this, "getWeather"); + +dcop.attach(); +box.show(); + +function getWeather() +{ + if ( dcop.isAttached() ) + { + var icn = new Image(this); + icn.pixmap = dcop.call("KWeatherService","WeatherService","icon(QString)", loc.text); + icn.smoothScale(32,32); + go.pixmap = icn.pixmap; + } +} + +application.exec(); diff --git a/kjsembed/docs/examples/docviewer/docviewer.js b/kjsembed/docs/examples/docviewer/docviewer.js new file mode 100644 index 00000000..56ccfa0e --- /dev/null +++ b/kjsembed/docs/examples/docviewer/docviewer.js @@ -0,0 +1,223 @@ +#!/usr/bin/env kjscmd + +// Populates the sidebar listview +function setup_sidebar( builtins, special, qt, kde, all ) +{ + var qobjects = Factory.constructors().sort(); + + for ( var i=0; i < qobjects.length ; i++ ) { + all.insertItem( qobjects[i] ); + + if ( /^Q/.test(qobjects[i]) ) + qt.insertItem( qobjects[i] ); + else if ( /^K/.test(qobjects[i]) ) + kde.insertItem( qobjects[i] ); + else + special.insertItem( qobjects[i] ); + } + + qt.insertItem( 'Qt' ); + builtins.insertItem( 'System' ); + builtins.insertItem( 'StdIcons' ); + builtins.insertItem( 'Factory' ); + builtins.insertItem( 'StdDirs' ); + builtins.insertItem( 'StdAction' ); +} + +// +// Main +// + +// Create the UI +var mw = new KMainWindow(this); +var ac = mw.actionCollection(); + +var split = new QSplitter( mw ); +mw.setCentralWidget( split ); + +side = new QToolBox( split, 'sidebar' ); +view = new QTabWidget( split, 'mainview' ); + +// Load the view +jsview = Factory.createROPart( "text/html", view, "js" ); +cppview = Factory.createROPart( "text/html", view, "cpp" ); + +js = view.child(4); +cpp = view.child(6); + +view.addTab( js, '&Javascript' ); +view.addTab( cpp, '&C++' ); + +view.set_class = function( clazz ) +{ + var nm; + + clazz = clazz.replace( '^[^QK]*', '' ); + + if ( /^Q/.test(clazz) ) + nm = 'http://doc.trolltech.com/3.2/' + clazz.toLowerCase() + '.html'; + else if ( /^K/.test(clazz) ) + nm = 'http://developer.kde.org/documentation/library/cvs-api/kdeui/html/class' + clazz + '.html'; + + + cppview.openURL( nm ); + + // JS docs + jsview.openStream( 'text/html', 'file:///index.html' ); + jsview.writeStream( '<html>' ); + jsview.writeStream( '<head>' ); + jsview.writeStream( '<style type="text/css"><!--' ); + jsview.writeStream( 'h1 { text-align: center; background-color: #ccccff; }' ); + jsview.writeStream( 'h2 { background-color: #eeeeff; }' ); + jsview.writeStream( 'h3 { background-color: #eeeeff; }' ); + jsview.writeStream( 'th { background-color: #cccccc; }' ); + jsview.writeStream( 'td { background-color: #eeeeee; }' ); + jsview.writeStream( 'table { font-family: sans-serif; font-size: 8pt }' ); + jsview.writeStream( '--></style>' ); + jsview.writeStream( '</head>' ); + jsview.writeStream( '<body>' ); + jsview.writeStream( '<h1>' + clazz + '</h1>' ); + + try { + var obj = eval('new '+clazz+'(this)'); + jsview.writeStream( dump(obj) ); + } + catch ( err ) { + try { + var obj = eval(clazz); + jsview.writeStream( dump(obj) ); + } + catch ( err2 ) { + jsview.writeStream( '<font color="red">Error dumping object: ' + err + '<hr>' + err2 + '</font>' ); + } + } + + jsview.writeStream( '</body>' ); + jsview.writeStream( '</html>' ); + jsview.closeStream(); +} + +view.setup = function() +{ + // JS docs + jsview.openStream( 'text/html', 'file:///index.html' ); + jsview.writeStream( '<html>' ); + jsview.writeStream( '<head>' ); + jsview.writeStream( '<style type="text/css"><!--' ); + jsview.writeStream( 'h1 { text-align: center; background-color: #ccccff; }' ); + jsview.writeStream( 'h2 { background-color: #eeeeff; }' ); + jsview.writeStream( 'h3 { background-color: #eeeeff; }' ); + jsview.writeStream( 'table { font-family: sans-serif; font-size: 8pt }' ); + jsview.writeStream( '--></style>' ); + jsview.writeStream( '</head>' ); + jsview.writeStream( '<body>' ); + jsview.writeStream( '<h1>Script Reference</h1>' ); + jsview.writeStream( '</body>' ); + jsview.writeStream( '</html>' ); + jsview.closeStream(); + + // C++ docs + cppview.openStream( 'text/html', 'file:///index.html' ); + cppview.writeStream( '<html>' ); + cppview.writeStream( '<head>' ); + cppview.writeStream( '<style type="text/css"><!--' ); + cppview.writeStream( 'h1 { text-align: center; background-color: #ccccff; }' ); + cppview.writeStream( 'h2 { background-color: #ccccff; }' ); + cppview.writeStream( 'h3 { background-color: #ddddff; }' ); + cppview.writeStream( 'table { font-family: sans-serif; font-size: 8pt }' ); + cppview.writeStream( '--></style>' ); + cppview.writeStream( '</head>' ); + cppview.writeStream( '<body>' ); + cppview.writeStream( '<h1>C++ Reference</h1>' ); + cppview.writeStream( '</body>' ); + cppview.writeStream( '</html>' ); + cppview.closeStream(); + + jsview.connect( jsview.child(0), 'openURLRequest(const KURL&,const KParts::URLArgs&)', 'openURL(const KURL&)' ); + cppview.connect( cppview.child(0), 'openURLRequest(const KURL&,const KParts::URLArgs&)', 'openURL(const KURL&)' ); +} + +// Setup the sidebar +builtinside = new KListView( side, 'builtinside' ); +builtinside.addColumn( 'Class' ); +builtinside.resizeMode = 2; // LastColumn + +builtinside.changed = function() +{ + var item = this.selectedItem(); + view.set_class( item.text(0) ); +} + +specialside = new KListView( side, 'specialsidebar' ); +specialside.addColumn( 'Class' ); +specialside.resizeMode = 2; // LastColumn + +specialside.changed = function() +{ + var item = this.selectedItem(); + view.set_class( item.text(0) ); +} + +qtside = new KListView( side, 'qtsidebar' ); +qtside.addColumn( 'Class' ); +qtside.resizeMode = 2; // LastColumn + +qtside.changed = function() +{ + var item = this.selectedItem(); + view.set_class( item.text(0) ); +} + +kdeside = new KListView( side, 'kdesidebar' ); +kdeside.addColumn( 'Class' ); +kdeside.resizeMode = 2; // LastColumn + +kdeside.changed = function() +{ + var item = this.selectedItem(); + view.set_class( item.text(0) ); +} + +allside = new KListView( side, 'allsidebar' ); +allside.addColumn( 'Class' ); +allside.resizeMode = 2; // LastColumn + +allside.changed = function() +{ + var item = this.selectedItem(); + view.set_class( item.text(0) ); +} + +side.addItem( builtinside, '&Builtins' ); +side.addItem( specialside, 'K&JSEmbed' ); +side.addItem( kdeside, '&KDE' ); +side.addItem( qtside, '&Qt' ); +side.addItem( allside, '&All' ); + +setup_sidebar( builtinside, specialside, qtside, kdeside, allside ); + +kdeside.connect( kdeside, 'selectionChanged()', kdeside, 'changed' ); +qtside.connect( qtside, 'selectionChanged()', qtside, 'changed' ); +specialside.connect( specialside, 'selectionChanged()', specialside, 'changed' ); +builtinside.connect( builtinside, 'selectionChanged()', builtinside, 'changed' ); +allside.connect( allside, 'selectionChanged()', allside, 'changed' ); + +// +// Activate XMLGUI and show the window +// +var quitAction = StdAction.quit( 0, 0, mw.actionCollection() ); +mw.connect( quitAction, 'activated()', this, 'exit'); + +mw.createGUI( 'stdactionsui.rc' ); +side.maximumWidth = 250; +mw.resize( 800, 550 ); + +mw.show(); + +// +// Connect together +// +view.setup(); + +application.exec(); + diff --git a/kjsembed/docs/examples/docviewer/docviewer.ui b/kjsembed/docs/examples/docviewer/docviewer.ui new file mode 100644 index 00000000..0cdb1930 --- /dev/null +++ b/kjsembed/docs/examples/docviewer/docviewer.ui @@ -0,0 +1,69 @@ +<!DOCTYPE UI><UI version="3.2" stdsetdef="1"> +<class>doc_viewer</class> +<widget class="QWidget"> + <property name="name"> + <cstring>doc_viewer</cstring> + </property> + <property name="geometry"> + <rect> + <x>0</x> + <y>0</y> + <width>166</width> + <height>132</height> + </rect> + </property> + <property name="sizePolicy"> + <sizepolicy> + <hsizetype>0</hsizetype> + <vsizetype>5</vsizetype> + <horstretch>0</horstretch> + <verstretch>0</verstretch> + </sizepolicy> + </property> + <property name="caption"> + <string>KJSEmbed Doc Viewer</string> + </property> + <grid> + <property name="name"> + <cstring>unnamed</cstring> + </property> + <widget class="QLabel" row="0" column="0"> + <property name="name"> + <cstring>textLabel1</cstring> + </property> + <property name="text"> + <string>&Search:</string> + </property> + <property name="buddy" stdset="0"> + <cstring>search_edit</cstring> + </property> + </widget> + <widget class="QLabel" row="1" column="0" rowspan="1" colspan="2"> + <property name="name"> + <cstring>textLabel1_2</cstring> + </property> + <property name="text"> + <string>Object types:</string> + </property> + </widget> + <widget class="KListBox" row="2" column="0" rowspan="1" colspan="2"> + <property name="name"> + <cstring>toc_view</cstring> + </property> + <property name="resizePolicy"> + <enum>AutoOne</enum> + </property> + </widget> + <widget class="KLineEdit" row="0" column="1"> + <property name="name"> + <cstring>search_edit</cstring> + </property> + </widget> + </grid> +</widget> +<layoutdefaults spacing="6" margin="11"/> +<includehints> + <includehint>klistbox.h</includehint> + <includehint>klineedit.h</includehint> +</includehints> +</UI> diff --git a/kjsembed/docs/examples/envelopemaker/EnvelopeMakerUI.ui b/kjsembed/docs/examples/envelopemaker/EnvelopeMakerUI.ui new file mode 100644 index 00000000..2e8658b3 --- /dev/null +++ b/kjsembed/docs/examples/envelopemaker/EnvelopeMakerUI.ui @@ -0,0 +1,568 @@ +<!DOCTYPE UI><UI version="3.2" stdsetdef="1"> +<class>Form1</class> +<widget class="QWidget"> + <property name="name"> + <cstring>Form1</cstring> + </property> + <property name="geometry"> + <rect> + <x>0</x> + <y>0</y> + <width>338</width> + <height>409</height> + </rect> + </property> + <vbox> + <property name="name"> + <cstring>unnamed</cstring> + </property> + <widget class="QGroupBox"> + <property name="name"> + <cstring>groupBox1_2</cstring> + </property> + <property name="sizePolicy"> + <sizepolicy> + <hsizetype>5</hsizetype> + <vsizetype>5</vsizetype> + <horstretch>0</horstretch> + <verstretch>1</verstretch> + </sizepolicy> + </property> + <property name="title"> + <string>From Address</string> + </property> + <vbox> + <property name="name"> + <cstring>unnamed</cstring> + </property> + <widget class="QLayoutWidget"> + <property name="name"> + <cstring>layout14_2</cstring> + </property> + <grid> + <property name="name"> + <cstring>unnamed</cstring> + </property> + <widget class="QLayoutWidget" row="0" column="1"> + <property name="name"> + <cstring>layout11_2</cstring> + </property> + <hbox> + <property name="name"> + <cstring>unnamed</cstring> + </property> + <spacer> + <property name="name"> + <cstring>spacer1_2</cstring> + </property> + <property name="orientation"> + <enum>Horizontal</enum> + </property> + <property name="sizeType"> + <enum>Expanding</enum> + </property> + <property name="sizeHint"> + <size> + <width>38</width> + <height>20</height> + </size> + </property> + </spacer> + <widget class="KLineEdit"> + <property name="name"> + <cstring>retAddress1</cstring> + </property> + <property name="sizePolicy"> + <sizepolicy> + <hsizetype>7</hsizetype> + <vsizetype>0</vsizetype> + <horstretch>1</horstretch> + <verstretch>0</verstretch> + </sizepolicy> + </property> + </widget> + </hbox> + </widget> + <widget class="QLabel" row="3" column="0"> + <property name="name"> + <cstring>textLabel1_4_2</cstring> + </property> + <property name="text"> + <string>City/state, zipcode:</string> + </property> + </widget> + <widget class="QLayoutWidget" row="1" column="1"> + <property name="name"> + <cstring>layout10_2</cstring> + </property> + <hbox> + <property name="name"> + <cstring>unnamed</cstring> + </property> + <spacer> + <property name="name"> + <cstring>spacer2_2</cstring> + </property> + <property name="orientation"> + <enum>Horizontal</enum> + </property> + <property name="sizeType"> + <enum>Expanding</enum> + </property> + <property name="sizeHint"> + <size> + <width>68</width> + <height>20</height> + </size> + </property> + </spacer> + <widget class="KLineEdit"> + <property name="name"> + <cstring>retAddress2</cstring> + </property> + <property name="sizePolicy"> + <sizepolicy> + <hsizetype>7</hsizetype> + <vsizetype>0</vsizetype> + <horstretch>1</horstretch> + <verstretch>0</verstretch> + </sizepolicy> + </property> + </widget> + </hbox> + </widget> + <widget class="QLabel" row="0" column="0"> + <property name="name"> + <cstring>textLabel1_3</cstring> + </property> + <property name="text"> + <string>Name:</string> + </property> + </widget> + <widget class="QLayoutWidget" row="2" column="1"> + <property name="name"> + <cstring>layout9_2</cstring> + </property> + <hbox> + <property name="name"> + <cstring>unnamed</cstring> + </property> + <spacer> + <property name="name"> + <cstring>spacer3_2</cstring> + </property> + <property name="orientation"> + <enum>Horizontal</enum> + </property> + <property name="sizeType"> + <enum>Expanding</enum> + </property> + <property name="sizeHint"> + <size> + <width>68</width> + <height>20</height> + </size> + </property> + </spacer> + <widget class="KLineEdit"> + <property name="name"> + <cstring>retAddress3</cstring> + </property> + <property name="sizePolicy"> + <sizepolicy> + <hsizetype>7</hsizetype> + <vsizetype>0</vsizetype> + <horstretch>1</horstretch> + <verstretch>0</verstretch> + </sizepolicy> + </property> + </widget> + </hbox> + </widget> + <widget class="QLayoutWidget" row="3" column="1"> + <property name="name"> + <cstring>layout8_2</cstring> + </property> + <hbox> + <property name="name"> + <cstring>unnamed</cstring> + </property> + <spacer> + <property name="name"> + <cstring>spacer4_2</cstring> + </property> + <property name="orientation"> + <enum>Horizontal</enum> + </property> + <property name="sizeType"> + <enum>Expanding</enum> + </property> + <property name="sizeHint"> + <size> + <width>70</width> + <height>20</height> + </size> + </property> + </spacer> + <widget class="KLineEdit"> + <property name="name"> + <cstring>retAddress4</cstring> + </property> + <property name="sizePolicy"> + <sizepolicy> + <hsizetype>7</hsizetype> + <vsizetype>5</vsizetype> + <horstretch>1</horstretch> + <verstretch>0</verstretch> + </sizepolicy> + </property> + </widget> + </hbox> + </widget> + <widget class="QLabel" row="2" column="0"> + <property name="name"> + <cstring>textLabel1_2_2_2</cstring> + </property> + <property name="text"> + <string>Address line 2:</string> + </property> + </widget> + <widget class="QLabel" row="1" column="0"> + <property name="name"> + <cstring>textLabel1_2_3</cstring> + </property> + <property name="text"> + <string>Address line 1:</string> + </property> + </widget> + </grid> + </widget> + </vbox> + </widget> + <widget class="QGroupBox"> + <property name="name"> + <cstring>groupBox1</cstring> + </property> + <property name="sizePolicy"> + <sizepolicy> + <hsizetype>5</hsizetype> + <vsizetype>5</vsizetype> + <horstretch>0</horstretch> + <verstretch>1</verstretch> + </sizepolicy> + </property> + <property name="title"> + <string>To Address</string> + </property> + <vbox> + <property name="name"> + <cstring>unnamed</cstring> + </property> + <widget class="QLayoutWidget"> + <property name="name"> + <cstring>layout14</cstring> + </property> + <grid> + <property name="name"> + <cstring>unnamed</cstring> + </property> + <widget class="QLayoutWidget" row="0" column="1"> + <property name="name"> + <cstring>layout11</cstring> + </property> + <hbox> + <property name="name"> + <cstring>unnamed</cstring> + </property> + <spacer> + <property name="name"> + <cstring>spacer1</cstring> + </property> + <property name="orientation"> + <enum>Horizontal</enum> + </property> + <property name="sizeType"> + <enum>Expanding</enum> + </property> + <property name="sizeHint"> + <size> + <width>38</width> + <height>20</height> + </size> + </property> + </spacer> + <widget class="KLineEdit"> + <property name="name"> + <cstring>mailAddress1</cstring> + </property> + <property name="sizePolicy"> + <sizepolicy> + <hsizetype>7</hsizetype> + <vsizetype>0</vsizetype> + <horstretch>1</horstretch> + <verstretch>0</verstretch> + </sizepolicy> + </property> + </widget> + </hbox> + </widget> + <widget class="QLabel" row="3" column="0"> + <property name="name"> + <cstring>textLabel1_4</cstring> + </property> + <property name="text"> + <string>City/state, zipcode:</string> + </property> + </widget> + <widget class="QLayoutWidget" row="1" column="1"> + <property name="name"> + <cstring>layout10</cstring> + </property> + <hbox> + <property name="name"> + <cstring>unnamed</cstring> + </property> + <spacer> + <property name="name"> + <cstring>spacer2</cstring> + </property> + <property name="orientation"> + <enum>Horizontal</enum> + </property> + <property name="sizeType"> + <enum>Expanding</enum> + </property> + <property name="sizeHint"> + <size> + <width>68</width> + <height>20</height> + </size> + </property> + </spacer> + <widget class="KLineEdit"> + <property name="name"> + <cstring>mailAddress2</cstring> + </property> + <property name="sizePolicy"> + <sizepolicy> + <hsizetype>7</hsizetype> + <vsizetype>0</vsizetype> + <horstretch>1</horstretch> + <verstretch>0</verstretch> + </sizepolicy> + </property> + </widget> + </hbox> + </widget> + <widget class="QLabel" row="0" column="0"> + <property name="name"> + <cstring>textLabel1</cstring> + </property> + <property name="text"> + <string>Name:</string> + </property> + </widget> + <widget class="QLayoutWidget" row="2" column="1"> + <property name="name"> + <cstring>layout9</cstring> + </property> + <hbox> + <property name="name"> + <cstring>unnamed</cstring> + </property> + <spacer> + <property name="name"> + <cstring>spacer3</cstring> + </property> + <property name="orientation"> + <enum>Horizontal</enum> + </property> + <property name="sizeType"> + <enum>Expanding</enum> + </property> + <property name="sizeHint"> + <size> + <width>68</width> + <height>20</height> + </size> + </property> + </spacer> + <widget class="KLineEdit"> + <property name="name"> + <cstring>mailAddress3</cstring> + </property> + <property name="sizePolicy"> + <sizepolicy> + <hsizetype>7</hsizetype> + <vsizetype>0</vsizetype> + <horstretch>1</horstretch> + <verstretch>0</verstretch> + </sizepolicy> + </property> + </widget> + </hbox> + </widget> + <widget class="QLayoutWidget" row="3" column="1"> + <property name="name"> + <cstring>layout8</cstring> + </property> + <hbox> + <property name="name"> + <cstring>unnamed</cstring> + </property> + <spacer> + <property name="name"> + <cstring>spacer4</cstring> + </property> + <property name="orientation"> + <enum>Horizontal</enum> + </property> + <property name="sizeType"> + <enum>Expanding</enum> + </property> + <property name="sizeHint"> + <size> + <width>70</width> + <height>20</height> + </size> + </property> + </spacer> + <widget class="KLineEdit"> + <property name="name"> + <cstring>mailAddress4</cstring> + </property> + <property name="sizePolicy"> + <sizepolicy> + <hsizetype>7</hsizetype> + <vsizetype>5</vsizetype> + <horstretch>1</horstretch> + <verstretch>0</verstretch> + </sizepolicy> + </property> + </widget> + </hbox> + </widget> + <widget class="QLabel" row="2" column="0"> + <property name="name"> + <cstring>textLabel1_2_2</cstring> + </property> + <property name="text"> + <string>Address line 2:</string> + </property> + </widget> + <widget class="QLabel" row="1" column="0"> + <property name="name"> + <cstring>textLabel1_2</cstring> + </property> + <property name="text"> + <string>Address line 1:</string> + </property> + </widget> + </grid> + </widget> + <spacer> + <property name="name"> + <cstring>spacer10</cstring> + </property> + <property name="orientation"> + <enum>Horizontal</enum> + </property> + <property name="sizeType"> + <enum>Expanding</enum> + </property> + <property name="sizeHint"> + <size> + <width>151</width> + <height>20</height> + </size> + </property> + </spacer> + <widget class="QCheckBox"> + <property name="name"> + <cstring>barcode</cstring> + </property> + <property name="text"> + <string>Generate PostNet bar code</string> + </property> + </widget> + </vbox> + </widget> + <widget class="KFontRequester"> + <property name="name"> + <cstring>font</cstring> + </property> + </widget> + <widget class="QLayoutWidget"> + <property name="name"> + <cstring>layout12</cstring> + </property> + <hbox> + <property name="name"> + <cstring>unnamed</cstring> + </property> + <widget class="KPushButton"> + <property name="name"> + <cstring>exit</cstring> + </property> + <property name="text"> + <string>&Quit</string> + </property> + </widget> + <spacer> + <property name="name"> + <cstring>spacer9</cstring> + </property> + <property name="orientation"> + <enum>Horizontal</enum> + </property> + <property name="sizeType"> + <enum>Expanding</enum> + </property> + <property name="sizeHint"> + <size> + <width>90</width> + <height>20</height> + </size> + </property> + </spacer> + <widget class="KPushButton"> + <property name="name"> + <cstring>save</cstring> + </property> + <property name="text"> + <string>&Save</string> + </property> + </widget> + <widget class="KPushButton"> + <property name="name"> + <cstring>print</cstring> + </property> + <property name="text"> + <string>&Print</string> + </property> + <property name="autoDefault"> + <bool>true</bool> + </property> + </widget> + </hbox> + </widget> + </vbox> +</widget> +<customwidgets> +</customwidgets> +<layoutdefaults spacing="6" margin="11"/> +<includehints> + <includehint>klineedit.h</includehint> + <includehint>klineedit.h</includehint> + <includehint>klineedit.h</includehint> + <includehint>klineedit.h</includehint> + <includehint>klineedit.h</includehint> + <includehint>klineedit.h</includehint> + <includehint>klineedit.h</includehint> + <includehint>klineedit.h</includehint> + <includehint>kfontrequester.h</includehint> + <includehint>kpushbutton.h</includehint> + <includehint>kpushbutton.h</includehint> + <includehint>kpushbutton.h</includehint> +</includehints> +</UI> diff --git a/kjsembed/docs/examples/envelopemaker/README b/kjsembed/docs/examples/envelopemaker/README new file mode 100644 index 00000000..3df8d4fd --- /dev/null +++ b/kjsembed/docs/examples/envelopemaker/README @@ -0,0 +1,6 @@ +#To install +>unshar -d $YOURKDEDIR envelopemaker.sh + +#To package +>sh -x package.sh +from inside of this directory. diff --git a/kjsembed/docs/examples/envelopemaker/env.js b/kjsembed/docs/examples/envelopemaker/env.js new file mode 100755 index 00000000..4d26c295 --- /dev/null +++ b/kjsembed/docs/examples/envelopemaker/env.js @@ -0,0 +1,253 @@ +#!/usr/bin/env kjscmd + +StdDirs.addResourceType("envelopemaker", StdDirs.kde_default("data") + "/envelopemaker"); + +var win = new KMainWindow(this); +var view = Factory.loadui(StdDirs.findResource("envelopemaker", "EnvelopeMakerUI.ui"), this, win); +//var view = Factory.loadui("EnvelopeMakerUI.ui", this, win); +var Print = view.child('print'); +var Save = view.child('save'); +var Exit = view.child('exit'); + +Print.connect(Print, 'clicked()', this, 'print'); +Save.connect(Save, 'clicked()', this, 'save'); +Exit.connect(Exit, 'clicked()', this, 'exit'); + +var env = new envelope(); +env.init(); + +win.setCentralWidget(view); +win.setCaption("EnvelopeMaker"); +win.show(); +application.exec(); + +function setupEnvelope() +{ + var fontName = /(.+)[,](.+)[,](.+)[,](.+)[,](.+)[,](.+)[,](.+)[,](.+)[,](.+)[,](.+)/.exec(view.child('font').font); + + env.returnfont = fontName[1]; + env.returnpointsize = fontName[2]; + env.mailfont = fontName[1]; + env.mailpointsize = fontName[2]; + env.retAddress[0] = view.child('retAddress1').text; + env.retAddress[1] = view.child('retAddress2').text; + env.retAddress[2] = view.child('retAddress3').text; + env.retAddress[3] = view.child('retAddress4').text; + env.mailAddress[0] = view.child('mailAddress1').text; + env.mailAddress[1] = view.child('mailAddress2').text; + env.mailAddress[2] = view.child('mailAddress3').text; + env.mailAddress[3] = view.child('mailAddress4').text; + if ( view.child('barcode').checked ) + { + if( env.getZip() == "" ) + { + alert("You must enter a valid 9 digit Zipcode"); + return false; + } + } + return true; +} + +function print() +{ + if (setupEnvelope() ) + { + var dcop = new DCOPClient(); + if( dcop.attach() ) + { + var ps = env.header(); + ps += env.returnAddress(); + ps += env.mailingAddress(); + if( view.child('barcode').checked ) + ps += env.barcode(); + ps += env.footer(); + if ( !dcop.send("kprinterservice", "printer", "printStream(const QString&)", ps ) ) + { + alert("There was an error talking to the KPrinterService, please check that it is running."); + } + + } + + } +} + +function save() +{ + if (setupEnvelope() ) + { + var ps = env.header(); + ps += env.returnAddress(); + ps += env.mailingAddress(); + if( view.child('barcode').checked ) + ps += env.barcode(); + ps += env.footer(); + var fileName = StdDialog.getSaveFileName(); + if( fileName != "") + { + System.writeFile(fileName, ps); + } + } +} + +function envelope() +{ + this.init = function() + { + + this.leftmargin = 0.30; + this.ewidth = 9.5; + this.eheight = 4.125; + this.linepos = 0; + this.normalpaper = 11; + this.normalwidth = 8.5; + + this.feedcenter = this.normalwidth/2 - this.eheight/2 + this.topmargin = 0.30 + this.feedcenter; + this.x0 = 0; + this.y0 = Math.round((this.normalpaper - this.ewidth) * 72); + this.xpos = Math.round(0.40*72*this.ewidth); + this.ypos = Math.round(-0.40*72*this.eheight); + this.xloc = Math.round(this.x0 + (this.topmargin * 72)); + this.yloc = Math.round(this.y0 + (this.leftmargin * 72)); + + this.returnfont = "Times-Roman"; + this.returnpointsize = 12; + this.mailfont = "Times-Roman"; + this.mailpointsize = 10; + this.retAddress = ["Ian Reinhart Geiser","601 Coach Hill Ct","West Chester PA, 19380"]; + this.mailAddress = ["SourceXtreme, Inc","1149 Broad Run Road","Coatesville, PA 39380-9176"]; + this.zipcode = "0"; + } + + this.getZip = function() + { + var mailAddress = /.+,[\s]*.{2,2}[\s]+([\d]{5,5})[-]*([\d]{4,4})/.exec(this.mailAddress); + if( mailAddress ) + return mailAddress[1] + mailAddress[2]; + else + return ""; + } + + this.header = function() + { + var ps = ""; + ps += "%!\n"; + ps += "% EnvelopeMaker\n"; + // Page size + // Comm #10 Envelope 297 x 684 + // C5 Envelope 461 x 648 + // DL Envelope 312 x 624 + ps += "newpath\n"; + return ps; + } + + this.returnAddress = function() + // Return address + { + var ps = this.xloc + " " + this.yloc + " translate\n"; + ps += "90 rotate"; + for ( var idx = 0; idx < this.retAddress.length; ++idx) + { + if( this.retAddress[idx] != "") + { + ps += "/" + this.returnfont + " findfont " + this.returnpointsize + " scalefont setfont\n"; + ps += "0 " + this.linepos + " moveto\n"; + ps += "(" + this.retAddress[idx] + ") show\n"; + this.linepos -= this.returnpointsize; + } + } + return ps; + } + + this.mailingAddress = function() + // Mailing Address + { + var ps = ""; + for ( var idx = 0; idx < this.mailAddress.length; ++idx) + { + if( this.mailAddress[idx] != "") + { + ps += "/" + this.mailfont + " findfont " + this.mailpointsize + " scalefont setfont\n"; + ps += this.xpos + " " + this.ypos + " moveto\n"; + ps += "(" + this.mailAddress[idx] + ") show\n"; + this.ypos -= this.mailpointsize; + } + } + return ps; + } + + this.footer = function() + { + return "showpage\n"; + } + + this.barcode = function() + { + this.zipcode = this.getZip(); + if( this.zipcode.length != 9) + return ""; + + var ps = ""; + + this.xpos = Math.round((this.ewidth - 3.875) * 72); + this.ypos = Math.round((-1 * this.eheight + 0.375) * 72); + + var code = [ [1, 1, 0, 0, 0], [0, 0, 0, 1, 1], [0, 0, 1, 0, 1], [0, 0, 1, 1, 0], + [0, 1, 0, 0, 1], [0, 1, 0, 1, 0], [0, 1, 1, 0, 0], [1, 0, 0, 0, 1], + [1, 0, 0, 1, 0],[1, 0, 1, 0, 0] ]; + var ziparray = new Array(10); + + var zipsum = 0; + for ( var idx = 0; idx < this.zipcode.length; ++idx) + { + ziparray[idx] = this.zipcode.substring(idx, idx+1); + zipsum += ziparray[idx]; + } + var correctcode = 10 - zipsum % 10; + if( correctcode == 10) + correctcode = 0; + ziparray[9] = correctcode; + + // Set our barcode dimensions to the POSTNET spec. + // Width = 0.02" + // Space between CL's (pitch) = 0.05" + // Height of 1's = 0.125" + // Height of 0's = 0.05" + + var pitch = 3.6; //points + var linewidth = 1.44; //points + var height = 0; + + var pos = 0; + ps += "newpath\n"; + ps += this.xpos + " " + this.ypos + " translate\n"; + ps += pos + " 0 moveto\n"; + ps += linewidth + " setlinewidth\n"; + + // Frame bar + var height = Math.round(0.125 * 72); + ps += "0 " + height + " rlineto\n"; + + // Actual barcode + for( var idx = 0; idx < ziparray.length; ++idx) + { + for (var idx2 = 0; idx2 < code[ ziparray[idx] ].length; ++idx2) + { + pos = Math.round(pos + pitch); + ps += pos + " 0 moveto\n"; + var line = code[ ziparray[idx] ][idx2]; + height = Math.round((0.05 + line * 0.075) * 72); + ps += "0 " + height + " rlineto\n"; + } + } + + // Frame bar + pos = Math.round(pos + pitch); + ps += pos + " 0 moveto\n"; + height = Math.round(0.125 * 72); + ps += "0 " + height + " rlineto\n"; + ps += "stroke\n"; + + return ps; + } +}
\ No newline at end of file diff --git a/kjsembed/docs/examples/envelopemaker/envelopemaker.desktop b/kjsembed/docs/examples/envelopemaker/envelopemaker.desktop new file mode 100644 index 00000000..ba71a225 --- /dev/null +++ b/kjsembed/docs/examples/envelopemaker/envelopemaker.desktop @@ -0,0 +1,10 @@ +[Desktop Entry] +Exec=kjscmd `kde-config --prefix`/share/apps/envelopemaker/env.js +GenericName=A #10 Envelope maker +Icon=exec +MimeType= +Name=Envelope Maker +StartupNotify=true +Terminal=false +Type=Application +X-KDE-SubstituteUID=false diff --git a/kjsembed/docs/examples/envelopemaker/package.sh b/kjsembed/docs/examples/envelopemaker/package.sh new file mode 100644 index 00000000..f83bcdc2 --- /dev/null +++ b/kjsembed/docs/examples/envelopemaker/package.sh @@ -0,0 +1,10 @@ +#!/bin/sh + +mkdir -p share/applnk/Scripts +mkdir -p share/apps/envelopemaker + +cp env.js EnvelopeMakerUI.ui share/apps/envelopemaker +cp envelopemaker.desktop share/applnk/Scripts + +shar -M -z -X share > envelopemaker.sh +rm -rf share diff --git a/kjsembed/docs/examples/eventhandling/jsboard.js b/kjsembed/docs/examples/eventhandling/jsboard.js new file mode 100644 index 00000000..91e9a0f2 --- /dev/null +++ b/kjsembed/docs/examples/eventhandling/jsboard.js @@ -0,0 +1,89 @@ +#!/usr/bin/env kjscmd + +// Globals +var frame = new QFrame(this); +var labels = new Array(); +var startPos = new Point(0,0); +var lastPos = new Point(0,0); + +frame.resize(300,300); +frame.paletteBackgroundColor = "blue"; + +var target = new Target(frame,"Target"); +for( var idx = 0; idx < 3; ++idx) + labels[idx] = new Block(frame, "Label " + idx); + +frame.show(); +application.exec(); + +function Target( parent, text) +{ + var x = Math.floor( Math.random() * parent.width ); + var y = Math.floor( Math.random() * parent.height ); + var w = 100; + var h = 100; + + this.label = new QLabel(parent); + this.text = text; + this.label.paletteBackgroundColor = "green"; + this.label.geometry = new Rect(x,y,w,h); + + this.checkInside = function( objectRect ) + { + return this.label.geometry.contains(objectRect); + } + +} + +function Block(parent,text) +{ + this.label = new QLabel(parent); + var x = Math.floor( Math.random() * parent.width ); + var y = Math.floor( Math.random() * parent.height ); + var w = 25; + var h = 25; + this.label.text = text; + this.label.geometry = new Rect(x,y,w,h); + this.label.frameShape = QFrame.WinPanel; + this.label.frameShadow = QFrame.Plain; + this.label.paletteBackgroundColor = "white"; + this.label.setMouseTracking(true); + this.label.adjustSize(); + + // Event handlers + this.label.mousePressEvent = function(ev) + { + //println("Press: " + this.text); + startPos = this.pos; + lastPos = ev.globalPos; + println("Start: " + startPos.x() + "," + startPos.y()); + + } + + this.label.mouseReleaseEvent = function(ev) + { + if( target.checkInside(this.geometry) ) + alert( "You got " + this.text + " on target!" ); + else + { + println("Reset: " + startPos.x() + "," + startPos.y()); + this.pos = startPos; + } + } + + this.label.mouseMoveEvent = function(ev) + { + if( ev.state == 1) + { + var xDelta = ev.globalX - lastPos.x(); + var yDelta = ev.globalY - lastPos.y(); + this.move( this.x + xDelta, this.y + yDelta ); + lastPos = ev.globalPos; + } + } +} + + + + + diff --git a/kjsembed/docs/examples/eventhandling/mousetrack.js b/kjsembed/docs/examples/eventhandling/mousetrack.js new file mode 100644 index 00000000..9c970c42 --- /dev/null +++ b/kjsembed/docs/examples/eventhandling/mousetrack.js @@ -0,0 +1,21 @@ +#!/usr/bin/env kjscmd + +// +// The standard 'scribble' application coded using kjsembed +// + + +var mousetrack = new QWidget(this); +mousetrack.setMouseTracking(true); +x=0; +y=0; + +mousetrack.mouseMoveEvent = function(ev) +{ + this.drawLine(x,y,ev.x,ev.y); + x = ev.x; + y = ev.y; +} + +mousetrack.show(); +application.exec(); diff --git a/kjsembed/docs/examples/eventhandling/scribble.js b/kjsembed/docs/examples/eventhandling/scribble.js new file mode 100644 index 00000000..0ffcdb07 --- /dev/null +++ b/kjsembed/docs/examples/eventhandling/scribble.js @@ -0,0 +1,34 @@ +#!/usr/bin/env kjscmd + +// +// The standard 'scribble' application coded using kjsembed +// + + +var scribble = new QWidget(this); +scribble.line=false; +var x=0; +var y=0; + +scribble.mousePressEvent = function(ev) +{ + if ( ev.button == 2 ) { + this.drawText(ev.x,ev.y,'KJSEmbed!'); + } + else { + x = ev.x; + y = ev.y; + line=true; + } +} + +scribble.mouseReleaseEvent = function(ev) +{ + if ( line ) + this.drawLine(x,y,ev.x,ev.y); + line = false; +} + +scribble.show(); +application.exec(); + diff --git a/kjsembed/docs/examples/frame/frame.js b/kjsembed/docs/examples/frame/frame.js new file mode 100644 index 00000000..d19fc4de --- /dev/null +++ b/kjsembed/docs/examples/frame/frame.js @@ -0,0 +1,28 @@ +#!/usr/bin/env kjscmd + +// Demo of QFrame and enum support + +function add_frame( parent ) +{ + var v = new QVBox( parent ); + v.margin = 6; + + return new QFrame( v ); +} + +var top = new QVBox(); +var hbox = new QHBox( top ); + +var f = add_frame( hbox ); +f.frameShape = QFrame.Box; + +f = add_frame( hbox ); +f.frameShape = QFrame.WinPanel | QFrame.Sunken; + +f = add_frame( hbox ); +f.frameShape = QFrame.PopupPanel; + +top.resize(300,200); + +top.show(); +application.exec(); diff --git a/kjsembed/docs/examples/grepdialog/README b/kjsembed/docs/examples/grepdialog/README new file mode 100644 index 00000000..e126113f --- /dev/null +++ b/kjsembed/docs/examples/grepdialog/README @@ -0,0 +1,6 @@ +Illustrates a number of useful facilities: + +- Creating dialogs from .ui files. +- Reading files from stdin and parsing them with JS regexps. +- Displaying formatted text using QML. +- Using shell scripts with kjscmd. diff --git a/kjsembed/docs/examples/grepdialog/grepdlg.js b/kjsembed/docs/examples/grepdialog/grepdlg.js new file mode 100644 index 00000000..2df87d98 --- /dev/null +++ b/kjsembed/docs/examples/grepdialog/grepdlg.js @@ -0,0 +1,23 @@ +// Create and show the dialog +var dlg = Factory.loadui('grepdlg.ui'); +dlg.exec(); + +// Extract the parameters +var search = dlg.child('search_edit').text; +var files = dlg.child('files_edit').text; +var matchcase = dlg.child('case_check').checked; +var shownumbers = dlg.child('shownumbers_check').checked; + +// Build the command line +var options = ''; +if ( !matchcase ) { + options += '-i '; +} +if ( shownumbers ) { + options += '-n '; +} + +cmd = 'grep -H '+options+"'"+search+"' "+files; + +// Print the command line +print( cmd ); diff --git a/kjsembed/docs/examples/grepdialog/grepdlg.ui b/kjsembed/docs/examples/grepdialog/grepdlg.ui new file mode 100644 index 00000000..53a169bd --- /dev/null +++ b/kjsembed/docs/examples/grepdialog/grepdlg.ui @@ -0,0 +1,199 @@ +<!DOCTYPE UI><UI version="3.1" stdsetdef="1"> +<class>GrepDialog</class> +<widget class="QDialog"> + <property name="name"> + <cstring>GrepDialog</cstring> + </property> + <property name="geometry"> + <rect> + <x>0</x> + <y>0</y> + <width>319</width> + <height>213</height> + </rect> + </property> + <property name="caption"> + <string>Grep Dialog</string> + </property> + <property name="sizeGripEnabled"> + <bool>true</bool> + </property> + <grid> + <property name="name"> + <cstring>unnamed</cstring> + </property> + <property name="margin"> + <number>11</number> + </property> + <property name="spacing"> + <number>6</number> + </property> + <widget class="QLineEdit" row="2" column="1"> + <property name="name"> + <cstring>search_edit</cstring> + </property> + <property name="text"> + <string>KJSEmbed</string> + </property> + </widget> + <widget class="QLabel" row="2" column="0"> + <property name="name"> + <cstring>TextLabel2</cstring> + </property> + <property name="text"> + <string>&Search for:</string> + </property> + <property name="buddy" stdset="0"> + <cstring>search_edit</cstring> + </property> + </widget> + <widget class="QLabel" row="3" column="0"> + <property name="name"> + <cstring>TextLabel3</cstring> + </property> + <property name="text"> + <string>In &files:</string> + </property> + <property name="buddy" stdset="0"> + <cstring>files_edit</cstring> + </property> + </widget> + <widget class="QLineEdit" row="3" column="1"> + <property name="name"> + <cstring>files_edit</cstring> + </property> + <property name="text"> + <string>*</string> + </property> + </widget> + <spacer row="4" column="1"> + <property name="name"> + <cstring>Spacer5</cstring> + </property> + <property name="orientation"> + <enum>Horizontal</enum> + </property> + <property name="sizeType"> + <enum>Expanding</enum> + </property> + <property name="sizeHint"> + <size> + <width>20</width> + <height>20</height> + </size> + </property> + </spacer> + <widget class="QCheckBox" row="5" column="1"> + <property name="name"> + <cstring>case_check</cstring> + </property> + <property name="text"> + <string>Match &case</string> + </property> + </widget> + <widget class="QLabel" row="4" column="0"> + <property name="name"> + <cstring>TextLabel3_2</cstring> + </property> + <property name="text"> + <string>Options:</string> + </property> + </widget> + <widget class="QLabel" row="0" column="0" rowspan="1" colspan="2"> + <property name="name"> + <cstring>TextLabel1</cstring> + </property> + <property name="font"> + <font> + <pointsize>12</pointsize> + <bold>1</bold> + </font> + </property> + <property name="text"> + <string>Grep Dialog</string> + </property> + </widget> + <widget class="Line" row="1" column="0" rowspan="1" colspan="2"> + <property name="name"> + <cstring>Line1</cstring> + </property> + <property name="frameShape"> + <enum>HLine</enum> + </property> + <property name="frameShadow"> + <enum>Sunken</enum> + </property> + <property name="orientation"> + <enum>Horizontal</enum> + </property> + </widget> + <widget class="QCheckBox" row="6" column="1"> + <property name="name"> + <cstring>shownumbers_check</cstring> + </property> + <property name="text"> + <string>Show line &numbers</string> + </property> + <property name="checked"> + <bool>true</bool> + </property> + </widget> + <widget class="QLayoutWidget" row="7" column="0" rowspan="1" colspan="2"> + <property name="name"> + <cstring>Layout1</cstring> + </property> + <hbox> + <property name="name"> + <cstring>unnamed</cstring> + </property> + <property name="margin"> + <number>0</number> + </property> + <property name="spacing"> + <number>6</number> + </property> + <spacer> + <property name="name"> + <cstring>Horizontal Spacing2</cstring> + </property> + <property name="orientation"> + <enum>Horizontal</enum> + </property> + <property name="sizeType"> + <enum>Expanding</enum> + </property> + <property name="sizeHint"> + <size> + <width>20</width> + <height>20</height> + </size> + </property> + </spacer> + <widget class="QPushButton"> + <property name="name"> + <cstring>buttonOk</cstring> + </property> + <property name="text"> + <string>&OK</string> + </property> + <property name="autoDefault"> + <bool>true</bool> + </property> + <property name="default"> + <bool>true</bool> + </property> + </widget> + </hbox> + </widget> + </grid> +</widget> +<connections> + <connection> + <sender>buttonOk</sender> + <signal>clicked()</signal> + <receiver>GrepDialog</receiver> + <slot>accept()</slot> + </connection> +</connections> +<layoutdefaults spacing="6" margin="11"/> +</UI> diff --git a/kjsembed/docs/examples/grepdialog/grepresults.js b/kjsembed/docs/examples/grepdialog/grepresults.js new file mode 100644 index 00000000..99a698cd --- /dev/null +++ b/kjsembed/docs/examples/grepdialog/grepresults.js @@ -0,0 +1,36 @@ +// Create the dialog +var dlg = Factory.loadui('grepresults.ui'); +var text = dlg.child('results_text'); + +function build_row( file, line, text ) +{ + file = file.replace( /:$/, "" ); + line = line.replace( /:$/, "" ); + return '<tr bgcolor="#eeeeff">' + +'<td><b><font color="blue">'+file+'</font></b></td>' + +'<td align="center"><b><font color="red">'+line+'</font></b></td>' + +'<td>'+text+'</td></tr>'; +} + +var s = '<table cellspacing="2"><tr bgcolor="#cccccc">'; +s += '<th><b>File</b></th>'; +s += '<th align="center"><b>Line</b></th>'; +s += '<th><b>Text</b></th></tr>'; + +var line = readLine(); +while ( line != null ) { + line.replace( /&/g,"&"); + line = line.replace( /"/g,"""); + line = line.replace( /</g,"<"); + + fields = line.match( /^([^:]+:)(\d+:)?(.*)/ ); + + s += build_row( fields[1], fields[2], fields[3] ); + line = readLine(); +} + +s += '</table>'; +text.text = s; + +// Show dialog +dlg.exec(); diff --git a/kjsembed/docs/examples/grepdialog/grepresults.ui b/kjsembed/docs/examples/grepdialog/grepresults.ui new file mode 100644 index 00000000..4bec43f4 --- /dev/null +++ b/kjsembed/docs/examples/grepdialog/grepresults.ui @@ -0,0 +1,131 @@ +<!DOCTYPE UI><UI version="3.1" stdsetdef="1"> +<class>GrepResults</class> +<widget class="QDialog"> + <property name="name"> + <cstring>GrepResults</cstring> + </property> + <property name="geometry"> + <rect> + <x>0</x> + <y>0</y> + <width>578</width> + <height>324</height> + </rect> + </property> + <property name="caption"> + <string>Grep Results</string> + </property> + <vbox> + <property name="name"> + <cstring>unnamed</cstring> + </property> + <widget class="QLabel"> + <property name="name"> + <cstring>TextLabel1</cstring> + </property> + <property name="font"> + <font> + <pointsize>12</pointsize> + <bold>1</bold> + </font> + </property> + <property name="text"> + <string>Grep Results</string> + </property> + </widget> + <widget class="Line"> + <property name="name"> + <cstring>Line1</cstring> + </property> + <property name="frameShape"> + <enum>HLine</enum> + </property> + <property name="frameShadow"> + <enum>Sunken</enum> + </property> + <property name="orientation"> + <enum>Horizontal</enum> + </property> + </widget> + <widget class="QTextEdit"> + <property name="name"> + <cstring>results_text</cstring> + </property> + <property name="frameShape"> + <enum>Box</enum> + </property> + <property name="frameShadow"> + <enum>Plain</enum> + </property> + <property name="lineWidth"> + <number>1</number> + </property> + <property name="textFormat"> + <enum>RichText</enum> + </property> + <property name="readOnly"> + <bool>true</bool> + </property> + <property name="undoRedoEnabled"> + <bool>false</bool> + </property> + </widget> + <widget class="QLayoutWidget"> + <property name="name"> + <cstring>Layout1</cstring> + </property> + <hbox> + <property name="name"> + <cstring>unnamed</cstring> + </property> + <property name="margin"> + <number>0</number> + </property> + <property name="spacing"> + <number>6</number> + </property> + <spacer> + <property name="name"> + <cstring>Horizontal Spacing2</cstring> + </property> + <property name="orientation"> + <enum>Horizontal</enum> + </property> + <property name="sizeType"> + <enum>Expanding</enum> + </property> + <property name="sizeHint"> + <size> + <width>20</width> + <height>20</height> + </size> + </property> + </spacer> + <widget class="QPushButton"> + <property name="name"> + <cstring>buttonOk</cstring> + </property> + <property name="text"> + <string>&Dismiss</string> + </property> + <property name="autoDefault"> + <bool>true</bool> + </property> + <property name="default"> + <bool>true</bool> + </property> + </widget> + </hbox> + </widget> + </vbox> +</widget> +<connections> + <connection> + <sender>buttonOk</sender> + <signal>clicked()</signal> + <receiver>GrepResults</receiver> + <slot>accept()</slot> + </connection> +</connections> +<layoutdefaults spacing="6" margin="11"/> +</UI> diff --git a/kjsembed/docs/examples/grepdialog/guigrep b/kjsembed/docs/examples/grepdialog/guigrep new file mode 100755 index 00000000..490e4676 --- /dev/null +++ b/kjsembed/docs/examples/grepdialog/guigrep @@ -0,0 +1,6 @@ +#!/bin/sh + +KJSCMD="`which kjscmd`" +GREP_CMD=`$KJSCMD grepdlg.js` +VIEW_CMD="$KJSCMD grepresults.js" +eval $GREP_CMD | $VIEW_CMD diff --git a/kjsembed/docs/examples/html2text/html2text.js b/kjsembed/docs/examples/html2text/html2text.js new file mode 100644 index 00000000..a8d6dd9a --- /dev/null +++ b/kjsembed/docs/examples/html2text/html2text.js @@ -0,0 +1,7 @@ +Factory.load('html2text_plugin.js'); + +var line = readLine(); +while ( line != null ) { + print( html2text(line) ); + line = readLine(); +} diff --git a/kjsembed/docs/examples/html2text/html2text_plugin.js b/kjsembed/docs/examples/html2text/html2text_plugin.js new file mode 100644 index 00000000..61146537 --- /dev/null +++ b/kjsembed/docs/examples/html2text/html2text_plugin.js @@ -0,0 +1,19 @@ + +function html2text( html ) +{ + var text = html.replace( /<[^>]*>/g, '' ); + text = text.replace( /"/g, '"' ); + text = text.replace( /</g, '<' ); + text = text.replace( /&/g, '&' ); + + return text; +} + +function text2html( text ) +{ + var html = text.replace( /&/g,"&"); + html = html.replace( /"/g,"""); + html = html.replace( /</g,"<"); + + return html; +} diff --git a/kjsembed/docs/examples/html2text/html2text_plugin.xml b/kjsembed/docs/examples/html2text/html2text_plugin.xml new file mode 100644 index 00000000..634b88cd --- /dev/null +++ b/kjsembed/docs/examples/html2text/html2text_plugin.xml @@ -0,0 +1,24 @@ +<!DOCTYPE actionset> +<actionset> +<header> + <name>html2text_actions</name> + <label>HTML To Text Actions</label> + <script type="js" src="html2text_plugin.js"></script> +</header> +<action> + <name>html_to_text</name> + <type>KAction</type> + <icons>text</icons> + <label><text>Convert HTML To Text</text></label> + <statustext>Converts the selected text from HTML to text.</statustext> + <script type="js">kpart.selectedText = html2text( kpart.selectedText )</script> +</action> +<action> + <name>text_to_html</name> + <type>KAction</type> + <icons>html</icons> + <label><text>Quote For HTML</text></label> + <statustext>Quotes the selected text for inclusion in an HTML document.</statustext> + <script type="js">kpart.selectedText = text2html( kpart.selectedText )</script> +</action> +</actionset> diff --git a/kjsembed/docs/examples/html2text/html2text_pluginui.rc b/kjsembed/docs/examples/html2text/html2text_pluginui.rc new file mode 100644 index 00000000..7738100c --- /dev/null +++ b/kjsembed/docs/examples/html2text/html2text_pluginui.rc @@ -0,0 +1,10 @@ +<!DOCTYPE kpartgui>
+<kpartplugin name="html2text_plugin" library="libkjsembedplugin">
+<MenuBar>
+ <Menu name="tools"><Text>&Tools</Text>
+ <Action name="html_to_text"/>
+ <Action name="text_to_html"/>
+ <Action name="jsconsole"/>
+ </Menu>
+</MenuBar>
+</kpartplugin>
diff --git a/kjsembed/docs/examples/html2text/test.htm b/kjsembed/docs/examples/html2text/test.htm new file mode 100644 index 00000000..457327d0 --- /dev/null +++ b/kjsembed/docs/examples/html2text/test.htm @@ -0,0 +1,208 @@ +<html> +<head> +<style type="text/css"> +<!-- +h1 { + background-color: #ccccee; + text-align: center; +} +h3 { + background-color: #ccccee; +} +li { + padding: 4px; +} +pre { + background-color: #CCCCCC; + margin-right: 16px; + margin-left: 16px; + padding: 6px; +} +.imgcaption { + font-weight: bold; + text-align: center; +} +.precaption { + font-weight: bold; + text-align: center; +} +--> +</style> +</head> +<body> +<h1> KJSEmbed</h1> +<h3>Introduction</h3> +<p>KJSEmbed is a library for embedding the KJS Javascript (ECMAScript) interpreter + in KDE applications. It provides developers with an easy way to allow users + to extend application, and can even be used with applications that have not + been designed with this in mind thanks to a KParts plugin. In addition, KJSEmbed + provides a command line tool for running scripts so users can easily create + simple applications of their own in Javascript. KJSEmbed scripts are surprisingly + powerful because they access the properties and slots of QObjects, and can even + load widgets and dialogs created with Qt's graphical dialog editor.</p> +<h3>Features</h3> +<p>To give you an idea of what KJSEmbed provides, here is a brief summary of the + more interesting features:</p> +<ul> + <li>KParts plugin for extending existing KDE applications with scripts. </li> + <li>KPart for embedding Javascript in your own applications.</li> + <li>Console dialog that can be used to execute Javascript interactively.</li> + <li>Command line tool for running scripts (this can even operate without an + X server if you don't need to display a GUI).</li> + <li>Define new KActions using XML.</li> + <li>Scripts can access the properties and slots of QObjects as if they were + normal Javascript properties and methods.</li> + <li>Scripts can load dialogs and widgets created with Qt Designer.</li> + <li>Scripts can create instances of anu QWidget subclass supported by QWidgetFactory.</li> + <li>Making your own QObjects/QWidgets available for scripting is one-liner.</li> + <li>Scripts can traverse the widget tree, so your entire application can be + made scriptable without explicitly binding every object.</li> +</ul> +<h3>First Steps - The Console Dialog</h3> +<p>The quickest way to see what KJSEmbed can do is with kjscmd, a tool for running + scripts from the command line. To begin, we'll run kjscmd without any parameters + which brings up the KJSEmbed console dialog. The console provides an easy way + to run short (one line) scripts, as you can see in figure 1 the scripts have + full access to the core Javascript language, and to standard objects such as + Math. In addition to the standard Javascript operations, this screenshot also + demonstrates the global function print() provided by KJSEmbed.</p> +<pre> +-- Enter a JS expression and press enter -- +kjs> 10+20 +30 +kjs> print(&quot;Hello World!&quot;) +Hello World! +undefined +kjs> Math.sin(0) +0 +kjs> Math.cos(0) +1 +</pre> +<p class="imgcaption">Figure 1: The KJSEmbed Console Dialog</p> +<p>Things get more interesting when you realise that we also have access to the + widgets that make up the dialog, as you can in figure 2:</p> +<pre> +kjs> console +JSConsoleWidget (KJSEmbed::JSConsoleWidget) +kjs> console.childCount() +4 +kjs> console.childAt(1) +CmdEdit (QComboBox) +kjs> console.childAt(2) +RunButton (QPushButton) +kjs> console.child(&quot;RunButton&quot;) +RunButton (QPushButton) +kjs> console.child(&quot;RunButton&quot;).text = &quot;Go!&quot; +Go! +kjs> console.caption = &quot;Different Title&quot; +Different Title +kjs&gt; console.child(&quot;Title&quot;).hide() +undefined +</pre> +<p class="imgcaption">Figure 2: Modifying the Console Dialog</p> +<p>As you can see, the console dialog has been made available to scripts as the + global variable 'console'. We can access the child widgets that make up the + dialog either by index using the childCount() and childAt() methods, or by name + using the child() method. As well as being able to see the widgets, we can modify + them by setting properties - in this example, we modify the caption property + of the widget 'console' (changing the window title) and the text property of + the widget 'RunButton' (changing the label it displays). For the sake of completeness, + the final command illustrates the other way of modifying widgets available to + us - it calls hide() slot of the widget 'Title' (what this does is left as an + exercise for the reader).</p> +<h3>Displaying A Grep Dialog</h3> +<p>Now that we've seen how to use kjscmd interactively, lets take a look at a + more complex example that displays a dialog for running grep. The complete script + is shown in listing 1 and as you'll see, is very simple. Loading and displaying + the dialog takes only two lines of code because KJSEmbed provides a built-in + Factory object that supports Designer files, most of the work is getting the + values out of the dialog and building the command line.</p> +<pre> +// Create and show the dialog +var dlg = Factory.loadui('grepdlg.ui'); +dlg.exec(); + +// Extract the parameters +var search = dlg.child('search_edit').text; +var files = dlg.child('files_edit').text; +var matchcase = dlg.child('case_check').checked; +var invert = dlg.child('invert_check').checked; + +// Build the command line +var options; +if ( matchcase ) { + options = '-i'; +} +if ( invert ) { + options += ' -v'; +} + +cmd = 'grep '+options+&quot;'&quot;+search+&quot;' &quot;+files; + +// Print the command line +print( cmd ); +</pre> +<p class="precaption">Listing 1: A Script That Displays the Grep Dialog</p> +<p>In order to find out what the user asked us to search for we need to extract + the contents of the various fields in our dialog. We know that the field for + entering the text to be searched for is a QLineEdit called 'search_edit', so + we can use the child() method to get hold of it (this method searches through + the children of an object until it finds one with a matching name). Once we've + found the right object getting hold of the text is easy because all QLineEdits + make their contents available as a property called 'text'. The code that gets + the value of the check boxes is almost identical, except that these are QCheckBoxes + so it's the 'checked' property we're interested in.</p> +<p align="center"><img src="grepdlg.png" alt="Grep Dialog Screenshot" width="327" height="241"></p> +<p class="imgcaption">Figure 3: The Grep Dialog</p> +<p>When this script is run you'll see a dialog like the one shown in figure 3.</p> +<h3>Extending Applications with Javascript Plugins</h3> +<p>As its name implies KJSEmbed is not just a tool for writing standalone Javascript + tools, it also provides facilities for extending existing applications, these + facilities being with a KParts plugin for running scripts. The next example + uses the plugin to add a simple HTML-to-text action to Kate, the standard KDE + editor. </p> +<pre> +function html2text( html ) +{ + var text = html.replace( /&lt;[^&gt;]*&gt;/g, '' ); + text = text.replace( /&amp;quot;/g, '&quot;' ); + text = text.replace( /&amp;lt;/g, '&lt;' ); + text = text.replace( /&amp;amp;/g, '&amp;' ); + return text; +} + +function text2html( text ) +{ + var html = text.replace( /&amp;/g,&quot;&amp;amp;&quot;); + html = html.replace( /&quot;/g,&quot;&amp;quot;&quot;); + html = html.replace( /&lt;/g,&quot;&amp;lt;&quot;); + return html; +} +</pre> +<p>The details...</p> +<pre>&lt;!DOCTYPE actionset&gt;<br>&lt;actionset&gt;<br>&lt;header&gt;<br> &lt;name&gt;html2text_actions&lt;/name&gt;<br> &lt;label&gt;HTML To Text Actions&lt;/label&gt;<br> &lt;script type=&quot;js&quot; src=&quot;html2text_plugin.js&quot;&gt;&lt;/script&gt;<br>&lt;/header&gt;<br>&lt;action&gt;<br> &lt;name&gt;html_to_text&lt;/name&gt;<br> &lt;type&gt;KAction&lt;/type&gt;<br> &lt;icons&gt;text&lt;/icons&gt;<br> &lt;label&gt;&lt;text&gt;Convert HTML To Text&lt;/text&gt;&lt;/label&gt;<br> &lt;statustext&gt;Converts the selected text from HTML to text.&lt;/statustext&gt;<br> &lt;script type=&quot;js&quot;&gt;kpart.selectedText = html2text( kpart.selectedText )&lt;/script&gt;<br>&lt;/action&gt;<br>&lt;action&gt;<br> &lt;name&gt;text_to_html&lt;/name&gt;<br> &lt;type&gt;KAction&lt;/type&gt;<br> &lt;icons&gt;html&lt;/icons&gt;<br> &lt;label&gt;&lt;text&gt;Quote For HTML&lt;/text&gt;&lt;/label&gt;<br> &lt;statustext&gt;Quotes the selected text for inclusion in an HTML document.&lt;/statustext&gt;<br> &lt;script type=&quot;js&quot;&gt;kpart.selectedText = text2html( kpart.selectedText )&lt;/script&gt;<br>&lt;/action&gt;<br>&lt;/actionset&gt;<br></pre> +<p><br> + The xmlgui:</p> +<pre> +&lt;!DOCTYPE kpartgui&gt;<br>&lt;kpartplugin name=&quot;html2text_plugin&quot; library=&quot;libkjsembedplugin&quot;&gt;<br>&lt;MenuBar&gt;<br> &lt;Menu name=&quot;tools&quot;&gt;&lt;Text&gt;&amp;amp;Tools&lt;/Text&gt;<br> &lt;Action name=&quot;html_to_text&quot;/&gt;<br> &lt;Action name=&quot;text_to_html&quot;/&gt;<br> &lt;Action name=&quot;jsconsole&quot;/&gt;<br> &lt;/Menu&gt;<br>&lt;/MenuBar&gt;<br>&lt;/kpartplugin&gt;<br> </pre> +<h3>Missing</h3> +<ul> + <li>XMLActions</li> + <li>Plugin</li> + <li>MainWindow</li> +</ul> +<h3>References</h3> +<dl> + <dt><a href="http://www.mozilla.org/js/language/">http://www.mozilla.org/js/language/</a></dt> + <dd>Javascript (ECMAScript) language information.</dd> +</dl> +<h3>To Do</h3> +<ul> + <li>Replace figures 1 and 2 with images</li> + <li></li> +</ul> +<p>&nbsp;</p> +<p>&nbsp;</p> +<p>&nbsp;</p> +</body> +</html> diff --git a/kjsembed/docs/examples/html2text/text2html.js b/kjsembed/docs/examples/html2text/text2html.js new file mode 100755 index 00000000..7e4311ca --- /dev/null +++ b/kjsembed/docs/examples/html2text/text2html.js @@ -0,0 +1,9 @@ +#!/usr/bin/env kjscmd + +Factory.load('html2text_plugin.js'); + +var line = readLine(); +while ( line != null ) { + print( text2html(line) ); + line = readLine(); +} diff --git a/kjsembed/docs/examples/htmlinfo/htmlinfo.js b/kjsembed/docs/examples/htmlinfo/htmlinfo.js new file mode 100755 index 00000000..6b5609ca --- /dev/null +++ b/kjsembed/docs/examples/htmlinfo/htmlinfo.js @@ -0,0 +1,63 @@ +#!/usr/bin/env kjscmd + +// +// Script to report info about an HTML file. +// + +function parse_attrs( src ) +{ + var attrs = new Array(); + var attr_name; + var attr_value; + + while ( src.length > 0 ) { + // Attr name + var am = src.match( /^\s*(\w+)\s*(=?)\s*/ ); + attr_name = am[1]; + src = src.slice( am[0].length ); + + // If attr has a value + if ( am[2] == '=' ) { + + if ( src.charAt(0) == '"' ) { + vm = src.match( /(\"[^\"]*\")\s*/ ); + attr_value = vm[1]; + src = src.slice( vm[0].length ); + } + else { + vm = src.match( /(\S+)\s*/ ); + attr_value = vm[1]; + src = src.slice( vm[0].length ); + } + + } + else { + attr_value = null; + } + src.replace( /^\s*/m, '' ); + + attrs.push( [ attr_name, attr_value ] ); + } + + return attrs; +} + +function process_tag_img( src ) +{ + var tag = src.match( /<\s*(img)\s*([^>]*)\s*>/i ); + var elem = tag[1]; + var attrs = parse_attrs( tag[2] ); + + warn( 'Element: '+elem ); + for ( var i=0 ; i < attrs.length; i++ ) { + warn( '\t '+attrs[i][0]+' = '+attrs[i][1] ); + } +} + +var file = application.args[0]; +var text = System.readFile( file ); +var imgs = text.match( /<\s*img\s*[^>]*\s*>/ig ); + +for ( var i=0 ; i < imgs.length ; i++ ) { + process_tag_img( imgs[i] ); +} diff --git a/kjsembed/docs/examples/imagefun/base.png b/kjsembed/docs/examples/imagefun/base.png Binary files differnew file mode 100644 index 00000000..46e60196 --- /dev/null +++ b/kjsembed/docs/examples/imagefun/base.png diff --git a/kjsembed/docs/examples/imagefun/bump.js b/kjsembed/docs/examples/imagefun/bump.js new file mode 100755 index 00000000..f6a0ded6 --- /dev/null +++ b/kjsembed/docs/examples/imagefun/bump.js @@ -0,0 +1,87 @@ +#!/usr/bin/env kjscmd + +function makeShape() +{ + var img = new Pixmap(this); + var mask = new Pixmap(this); + var painter = new Painter(this); + + var brush = new Brush(this); + brush.setColor("black"); + brush.setStyle(Brush.SolidBrush); + var pen = new Pen(this); + pen.setColor("black"); + + mask.resize(128,64); + img.resize(128,64); + img.fill("white"); + + + if( painter.begin( img ) ) + { + painter.setPen(pen); + painter.setBrush(brush); + painter.drawRoundRect( 2,2,126,62, 25, 25 ); + if( painter.end() ) + img = painter.pixmap(); + } + + img.setMask( img.createHeuristicMask(true) ); + return img; +} + +function makeGradient(size) +{ + var img = new Image(); + img.gradient(size, "white", "black", img.PyramidGradient, 0); + return img; + +} + +function bump() +{ + var img1 = new Image(); + var map = new Image(); + var mask = new Pixmap(); + + img1.load( img1Loc ); + map.load( img2Loc ); + if ( !img1.isOk() && !map.isOk() ) { + var pix = makeShape(); + img1.setPixmap(pix); + map = makeGradient( pix.size() ); + mask = pix.mask(); + } + + println("Size 1: " + img1.width() + "x" + img1.height() ); + println("Size 2: " + map.width() + "x" + map.height() ); + var azmiuth = ui.child('azimuth').value; //135.0; + var elevation = ui.child('elevation').value; //45; + var depth = ui.child('depth').value; //3; + var xofs = ui.child('xofs').value; //5; + var yofs = ui.child('yofs').value; //5; + var waterlevel = ui.child('waterlevel').value; //0; + var ambient = ui.child('ambient').value; //0; + var compensate = ui.child('compensate').checked; //false; + var invert = ui.child('invert').checked; //false; + var type= ui.child('type').currentItem; //Image.Linear; + var tiled = ui.child('tiled').checked; //false; + img1.bumpmap(map, azmiuth, elevation, depth, xofs, yofs, waterlevel, ambient, compensate, invert, type, tiled); + var pix = img1.pixmap(); +// var pix = map.pixmap(); +// pix.setMask(mask); + view.pixmap = pix; +} + + var img1Loc = application.args[0]; + var img2Loc = application.args[1]; + + var ui = Factory.loadui('bump.ui'); + var go = ui.child('go'); + var view = ui.child('view'); + + go.connect(go, "clicked()", this, "bump"); + + ui.show(); + + application.exec(); diff --git a/kjsembed/docs/examples/imagefun/bump.ui b/kjsembed/docs/examples/imagefun/bump.ui new file mode 100644 index 00000000..90c5cc95 --- /dev/null +++ b/kjsembed/docs/examples/imagefun/bump.ui @@ -0,0 +1,327 @@ +<!DOCTYPE UI><UI version="3.2" stdsetdef="1"> +<class>Form1</class> +<widget class="QWidget"> + <property name="name"> + <cstring>Form1</cstring> + </property> + <property name="geometry"> + <rect> + <x>0</x> + <y>0</y> + <width>524</width> + <height>445</height> + </rect> + </property> + <grid> + <property name="name"> + <cstring>unnamed</cstring> + </property> + <widget class="QLayoutWidget" row="5" column="0" rowspan="1" colspan="6"> + <property name="name"> + <cstring>layout1</cstring> + </property> + <hbox> + <property name="name"> + <cstring>unnamed</cstring> + </property> + <spacer> + <property name="name"> + <cstring>spacer1</cstring> + </property> + <property name="orientation"> + <enum>Horizontal</enum> + </property> + <property name="sizeType"> + <enum>Expanding</enum> + </property> + <property name="sizeHint"> + <size> + <width>121</width> + <height>20</height> + </size> + </property> + </spacer> + <widget class="QPushButton"> + <property name="name"> + <cstring>go</cstring> + </property> + <property name="text"> + <string>Go</string> + </property> + </widget> + </hbox> + </widget> + <widget class="QLabel" row="0" column="0" rowspan="1" colspan="6"> + <property name="name"> + <cstring>view</cstring> + </property> + <property name="sizePolicy"> + <sizepolicy> + <hsizetype>5</hsizetype> + <vsizetype>5</vsizetype> + <horstretch>2</horstretch> + <verstretch>2</verstretch> + </sizepolicy> + </property> + <property name="text"> + <string></string> + </property> + </widget> + <widget class="QLayoutWidget" row="2" column="0"> + <property name="name"> + <cstring>layout5</cstring> + </property> + <hbox> + <property name="name"> + <cstring>unnamed</cstring> + </property> + <widget class="QLabel"> + <property name="name"> + <cstring>textLabel3</cstring> + </property> + <property name="text"> + <string>Depth:</string> + </property> + </widget> + <widget class="KIntSpinBox"> + <property name="name"> + <cstring>depth</cstring> + </property> + <property name="value"> + <number>3</number> + </property> + </widget> + </hbox> + </widget> + <widget class="QLayoutWidget" row="3" column="4" rowspan="1" colspan="2"> + <property name="name"> + <cstring>layout9</cstring> + </property> + <hbox> + <property name="name"> + <cstring>unnamed</cstring> + </property> + <widget class="QLabel"> + <property name="name"> + <cstring>textLabel9</cstring> + </property> + <property name="text"> + <string>Type:</string> + </property> + </widget> + <widget class="QComboBox"> + <item> + <property name="text"> + <string>Linear</string> + </property> + </item> + <item> + <property name="text"> + <string>Spherical</string> + </property> + </item> + <item> + <property name="text"> + <string>Sinuosidal</string> + </property> + </item> + <property name="name"> + <cstring>type</cstring> + </property> + </widget> + </hbox> + </widget> + <widget class="QLayoutWidget" row="2" column="3" rowspan="1" colspan="2"> + <property name="name"> + <cstring>layout3</cstring> + </property> + <hbox> + <property name="name"> + <cstring>unnamed</cstring> + </property> + <widget class="QLabel"> + <property name="name"> + <cstring>textLabel5</cstring> + </property> + <property name="text"> + <string>Y offset:</string> + </property> + </widget> + <widget class="KIntSpinBox"> + <property name="name"> + <cstring>yofs</cstring> + </property> + <property name="minValue"> + <number>0</number> + </property> + </widget> + </hbox> + </widget> + <widget class="QLayoutWidget" row="1" column="2" rowspan="1" colspan="2"> + <property name="name"> + <cstring>layout6</cstring> + </property> + <hbox> + <property name="name"> + <cstring>unnamed</cstring> + </property> + <widget class="QLabel"> + <property name="name"> + <cstring>textLabel2</cstring> + </property> + <property name="text"> + <string>Elevation:</string> + </property> + </widget> + <widget class="KDoubleNumInput"> + <property name="name"> + <cstring>elevation</cstring> + </property> + <property name="value"> + <number>45</number> + </property> + </widget> + </hbox> + </widget> + <widget class="QLayoutWidget" row="3" column="2" rowspan="1" colspan="2"> + <property name="name"> + <cstring>layout8</cstring> + </property> + <hbox> + <property name="name"> + <cstring>unnamed</cstring> + </property> + <widget class="QLabel"> + <property name="name"> + <cstring>textLabel7</cstring> + </property> + <property name="text"> + <string>Ambient:</string> + </property> + </widget> + <widget class="KIntSpinBox"> + <property name="name"> + <cstring>ambient</cstring> + </property> + </widget> + </hbox> + </widget> + <widget class="QLayoutWidget" row="2" column="1" rowspan="1" colspan="2"> + <property name="name"> + <cstring>layout4</cstring> + </property> + <hbox> + <property name="name"> + <cstring>unnamed</cstring> + </property> + <widget class="QLabel"> + <property name="name"> + <cstring>textLabel4</cstring> + </property> + <property name="text"> + <string>X offset:</string> + </property> + </widget> + <widget class="KIntSpinBox"> + <property name="name"> + <cstring>xofs</cstring> + </property> + <property name="minValue"> + <number>0</number> + </property> + </widget> + </hbox> + </widget> + <widget class="QLayoutWidget" row="1" column="0" rowspan="1" colspan="2"> + <property name="name"> + <cstring>layout7</cstring> + </property> + <hbox> + <property name="name"> + <cstring>unnamed</cstring> + </property> + <widget class="QLabel"> + <property name="name"> + <cstring>textLabel1</cstring> + </property> + <property name="text"> + <string>Azimuth:</string> + </property> + </widget> + <widget class="KDoubleNumInput"> + <property name="name"> + <cstring>azimuth</cstring> + </property> + <property name="value"> + <number>135</number> + </property> + </widget> + </hbox> + </widget> + <widget class="QLayoutWidget" row="3" column="0" rowspan="1" colspan="2"> + <property name="name"> + <cstring>layout2</cstring> + </property> + <hbox> + <property name="name"> + <cstring>unnamed</cstring> + </property> + <widget class="QLabel"> + <property name="name"> + <cstring>textLabel6</cstring> + </property> + <property name="text"> + <string>Water level:</string> + </property> + </widget> + <widget class="KIntSpinBox"> + <property name="name"> + <cstring>waterlevel</cstring> + </property> + </widget> + </hbox> + </widget> + <widget class="QCheckBox" row="4" column="5"> + <property name="name"> + <cstring>tiled</cstring> + </property> + <property name="text"> + <string>Tiled</string> + </property> + </widget> + <widget class="QCheckBox" row="4" column="2" rowspan="1" colspan="2"> + <property name="name"> + <cstring>invert</cstring> + </property> + <property name="text"> + <string>Invert</string> + </property> + </widget> + <widget class="QCheckBox" row="4" column="0"> + <property name="name"> + <cstring>compensate</cstring> + </property> + <property name="text"> + <string>Compensate</string> + </property> + <property name="checked"> + <bool>true</bool> + </property> + </widget> + </grid> +</widget> +<customwidgets> +</customwidgets> +<layoutdefaults spacing="6" margin="11"/> +<includehints> + <includehint>knuminput.h</includehint> + <includehint>knuminput.h</includehint> + <includehint>knuminput.h</includehint> + <includehint>knuminput.h</includehint> + <includehint>knuminput.h</includehint> + <includehint>knuminput.h</includehint> + <includehint>knuminput.h</includehint> + <includehint>knuminput.h</includehint> + <includehint>knuminput.h</includehint> +</includehints> +</UI> diff --git a/kjsembed/docs/examples/imagefun/bumptest.png b/kjsembed/docs/examples/imagefun/bumptest.png Binary files differnew file mode 100644 index 00000000..b6954838 --- /dev/null +++ b/kjsembed/docs/examples/imagefun/bumptest.png diff --git a/kjsembed/docs/examples/imagefun/mask-gradient.png b/kjsembed/docs/examples/imagefun/mask-gradient.png Binary files differnew file mode 100644 index 00000000..67fe031f --- /dev/null +++ b/kjsembed/docs/examples/imagefun/mask-gradient.png diff --git a/kjsembed/docs/examples/imagefun/mask-noise.png b/kjsembed/docs/examples/imagefun/mask-noise.png Binary files differnew file mode 100644 index 00000000..c7d8bb72 --- /dev/null +++ b/kjsembed/docs/examples/imagefun/mask-noise.png diff --git a/kjsembed/docs/examples/imagefun/rotate.js b/kjsembed/docs/examples/imagefun/rotate.js new file mode 100755 index 00000000..c7869017 --- /dev/null +++ b/kjsembed/docs/examples/imagefun/rotate.js @@ -0,0 +1,26 @@ +#!/usr/bin/env kjscmd + +// Applies a rotate of 90 degrees to the image +function apply_rotate( img ) +{ + var foo = img.Rotate90; + println(foo); + img.rotate(foo); + return img; +} + +if ( application.args.length == 0 ) { + throw 'Usage:\n\timageviewer imgfile ...'; +} +else { + var loc = application.args[0]; + var img = new Image(); + img.load( loc ); + if ( !img.isOk() ) { + throw 'Failed to load image ' + loc; + } + + img = apply_rotate( img ); + + img.save( loc ); +} diff --git a/kjsembed/docs/examples/imagefun/title.js b/kjsembed/docs/examples/imagefun/title.js new file mode 100755 index 00000000..749899be --- /dev/null +++ b/kjsembed/docs/examples/imagefun/title.js @@ -0,0 +1,36 @@ +#!/usr/bin/env kjscmd + +var textlayer = new Pixmap(); +var painter = new Painter(); + +var w = 100; +var h = 100; +var test = "This is a test"; +var pn = new Pen(this); +var bsh = new Brush(this); + +bsh.setColor("red"); + +pn.setWidth(2); +pn.setColor("red"); + +textlayer.resize( w,h); +textlayer.fill("white"); +if (painter.begin(textlayer) ) +{ + painter.setPen(pn); + painter.setBrush(bsh); + painter.drawRoundRect( 5, 5, w-5, h-5, 25, 25 ); + if( painter.end() ) + { + var lbl = new QLabel(); + var img = new Image(this); + img.setPixmap( painter.pixmap() ); + + img.emboss(0,1); + lbl.pixmap=img.pixmap(); + lbl.show(); + application.exec(); + + } +} diff --git a/kjsembed/docs/examples/imageinfo/README b/kjsembed/docs/examples/imageinfo/README new file mode 100644 index 00000000..3940153a --- /dev/null +++ b/kjsembed/docs/examples/imageinfo/README @@ -0,0 +1,22 @@ +A number of utilities showing the facilties for dealing with image +files. The scripts here are independent from each other. + +imageinfo.js Prints the width, height, depth and format of + images that are in a supported format. This script + is a good example of how to process arguments + passed on the command line. + +imagescale.js Loads an image, scales it to the specified size, + then saves using the specified name and format. + +imagegallery.js Creates an image gallery from a list of images + specified on the command line. This script brings + together the facilities used in the other examples + to create a tool that is useful in the real world. + +imagegallery.sh Creates a gallery sorted by the timestamps of the + image files. This is a very simplistic example of + how you can combine kjscmd with shell scripts. + +example* thumb-* Example output from the image gallery script. + diff --git a/kjsembed/docs/examples/imageinfo/example.html b/kjsembed/docs/examples/imageinfo/example.html new file mode 100644 index 00000000..c5b5fd69 --- /dev/null +++ b/kjsembed/docs/examples/imageinfo/example.html @@ -0,0 +1,44 @@ +<html> +<head> +<title>Image Gallery</title> +</head> +<body> +<h1 align="center">Image Gallery</h1> +<hr> +<p>Here are some images, the larger ones have been scaled down to ensure this page loads quickly. Click on an image or filename to see it full size.</p> +<table border=0 width="90%" cellpadding="12" cellspacing="1"> +<tr> +<td align="center"><a href="example1.png"><img border=0 width=197 height=160 src=thumb-example1.png></a></td> +<td width="60%" valign="top" align="justify"><b><a href="example1.png">example1.png</a></b> (848x686)<p>This image shows the results of running the imagegallery script. As you can +see the script automatically creates thumbnails (using QImage::smoothScale() +for quality) and includes image descriptions if present. The descriptions can +include HTML markup <b>like</b> <i>this</i>, and even +<a href="http://xmelegance.org/kjsembed/">links</a>. + +</p> +</td> +</tr> +<tr> +<td align="center"><a href="example2.png"><img border=0 width=217 height=160 src=thumb-example2.png></a></td> +<td width="60%" valign="top" align="justify"><b><a href="example2.png">example2.png</a></b> (340x250)<p>This image shows +<a href="http://developer.kde.org/documentation/library/cvs-api/classref/kdeui/KPassivePopup.html">KPassivePopup</a> +telling a user they have new mail. The popup is adject to the source of the +message (in this example that is <a href="http://kmail.kde.org/">KMail</a>) and +<i>does not steal the focus</i>, or otherwise interfere with whatever the user is +currently doing. The dialog is automatically hidden after a timeout (or if the +user clicks on it). +</p> +</td> +</tr> +<tr> +<td align="center"><a href="example3.png"><img border=0 width=203 height=160 src=thumb-example3.png></a></td> +<td width="60%" valign="top" align="justify"><b><a href="example3.png">example3.png</a></b> (274x215)<p><i>No Description</i></p> +</td> +</tr> +<tr> +<td align="center"><a href="example4.png"><img border=0 width=158 height=160 src=thumb-example4.png></a></td> +<td width="60%" valign="top" align="justify"><b><a href="example4.png">example4.png</a></b> (560x567)<p><i>No Description</i></p> +</td> +</tr> +</table> +</body></html> diff --git a/kjsembed/docs/examples/imageinfo/example1.htm b/kjsembed/docs/examples/imageinfo/example1.htm new file mode 100644 index 00000000..b18ff23c --- /dev/null +++ b/kjsembed/docs/examples/imageinfo/example1.htm @@ -0,0 +1,6 @@ +This image shows the results of running the imagegallery script. As you can +see the script automatically creates thumbnails (using QImage::smoothScale() +for quality) and includes image descriptions if present. The descriptions can +include HTML markup <b>like</b> <i>this</i>, and even +<a href="http://xmelegance.org/kjsembed/">links</a>. + diff --git a/kjsembed/docs/examples/imageinfo/example1.png b/kjsembed/docs/examples/imageinfo/example1.png Binary files differnew file mode 100644 index 00000000..53408e63 --- /dev/null +++ b/kjsembed/docs/examples/imageinfo/example1.png diff --git a/kjsembed/docs/examples/imageinfo/example2.htm b/kjsembed/docs/examples/imageinfo/example2.htm new file mode 100644 index 00000000..651048b3 --- /dev/null +++ b/kjsembed/docs/examples/imageinfo/example2.htm @@ -0,0 +1,7 @@ +This image shows +<a href="http://developer.kde.org/documentation/library/cvs-api/classref/kdeui/KPassivePopup.html">KPassivePopup</a> +telling a user they have new mail. The popup is adject to the source of the +message (in this example that is <a href="http://kmail.kde.org/">KMail</a>) and +<i>does not steal the focus</i>, or otherwise interfere with whatever the user is +currently doing. The dialog is automatically hidden after a timeout (or if the +user clicks on it). diff --git a/kjsembed/docs/examples/imageinfo/example2.png b/kjsembed/docs/examples/imageinfo/example2.png Binary files differnew file mode 100644 index 00000000..902af717 --- /dev/null +++ b/kjsembed/docs/examples/imageinfo/example2.png diff --git a/kjsembed/docs/examples/imageinfo/example3.png b/kjsembed/docs/examples/imageinfo/example3.png Binary files differnew file mode 100644 index 00000000..c2b98665 --- /dev/null +++ b/kjsembed/docs/examples/imageinfo/example3.png diff --git a/kjsembed/docs/examples/imageinfo/example4.png b/kjsembed/docs/examples/imageinfo/example4.png Binary files differnew file mode 100644 index 00000000..9c2d9ae3 --- /dev/null +++ b/kjsembed/docs/examples/imageinfo/example4.png diff --git a/kjsembed/docs/examples/imageinfo/imagegallery.js b/kjsembed/docs/examples/imageinfo/imagegallery.js new file mode 100755 index 00000000..4cc5bc2d --- /dev/null +++ b/kjsembed/docs/examples/imageinfo/imagegallery.js @@ -0,0 +1,113 @@ +#!/usr/bin/env kjscmd + +// +// Script to create an image gallery for a set of images. +// + +var default_title = 'Image Gallery'; +var default_intro = 'Here are some images, the larger ones have been scaled down to ' + + 'ensure this page loads quickly. Click on an image or filename ' + + 'to see it full size.'; +var default_width = 250; +var default_height = 160; + +function write_header( title, intro ) +{ + println( '<html>' ); + println( '<head>' ); + println( '<title>'+title+'</title>' ); + println( '</head>' ); + println( '<body>' ); + println( '<h1 align="center">'+title+'</h1>' ); + println( '<hr>' ); + println( '<p>'+intro+'</p>' ); + println( '<table border=0 width="90%" cellpadding="12" cellspacing="1">' ); +} + +function write_footer() +{ + println( '</table>' ); + println( '</body></html>' ); +} + +function write_image( name, w, h, thumb, tw, th, desc ) +{ + println( '<tr>' ); + + print( '<td align="center">' ); + print( '<a href="'+name+'">' ); + print( '<img border=0 width='+tw+' height='+th+' src="'+thumb+'">' ); + print( '</a>' ); + println( '</td>' ); + + print( '<td width="60%" valign="top" align="justify">' ); + print( '<b><a href="'+name+'">'+name+'</a></b>'+' ('+w+'x'+h+')' ); +// println( '<hr>' ); + println( '<p>'+desc+'</p>' ); + println( '</td>' ); + + println( '</tr>' ); +} + +// Create a thumbnail and write the img tag. +function process_image( name, desc ) +{ + var img = new Image(); + img.load( name ); + if ( !img.isOk() ) { + warn( 'Failed to load image '+name); + return null; + } + + var w = img.width(); + var h = img.height(); + + if ( (w > default_width) || (h > default_height) ) { + img.smoothScaleMin( default_width, default_height ); + } + + var tw = img.width(); + var th = img.height(); + + var thumb = 'thumb-'+name; + img.save( thumb ); + + if ( !img.isOk() ) { + warn( 'Failed to save thumbnail '+thumb); + return null; + } + + write_image( name, w, h, thumb, tw, th, desc ); +} + +if ( application.args.length == 0 ) { + System.stderr.println( 'Usage:' ); + System.stderr.println( '\timagegallery imgfile ...' ); +} +else { + write_header( default_title, default_intro ); + + for ( var i = 0 ; i < application.args.length ; i++ ) { + var name = application.args[i]; + if ( name.match( /^thumb-/ ) ) { + // Ignore thumbnails + } + else { + + var desc_file = name.replace( /\.[^\.]+$/, '.htm' ); + var desc; + try { + desc = System.readFile( desc_file ); + } + catch(x) { + desc = '<i>No Description</i>'; + } + process_image( name, desc ); + } + } + + write_footer(); +} + + + diff --git a/kjsembed/docs/examples/imageinfo/imagegallery.sh b/kjsembed/docs/examples/imageinfo/imagegallery.sh new file mode 100755 index 00000000..cf3952c4 --- /dev/null +++ b/kjsembed/docs/examples/imageinfo/imagegallery.sh @@ -0,0 +1,8 @@ +#!/bin/sh + +# +# Uses imagegallery.js to create a thumbnail page where the newest +# images are shown first. +# + +./imagegallery.js `ls --color=never -1 -t $* | xargs echo -n` diff --git a/kjsembed/docs/examples/imageinfo/imageinfo.js b/kjsembed/docs/examples/imageinfo/imageinfo.js new file mode 100755 index 00000000..957b1a49 --- /dev/null +++ b/kjsembed/docs/examples/imageinfo/imageinfo.js @@ -0,0 +1,37 @@ +#!/usr/bin/env kjscmd + +// +// Script to load an image and report some info about it. +// + +function image_info( name ) +{ + var img = new Image(); + img.load( name ); + if ( !img.isOk() ) { + return null; + } + + return img.width()+' x '+img.height()+' x '+img.depth()+ '\t'+img.format(); +} + +if ( application.args.length == 0 ) { + System.err.println( 'Usage:' ); + System.err.println( '\timageinfo imgfile ...' ); +} +else { + for ( var i = 0 ; i < application.args.length ; i++ ) { + var prefix = ''; + if ( application.args.length > 1 ) { + prefix = application.args[i] + ':\t'; + } + + var msg = image_info( application.args[i] ); + if ( msg ) { + System.err.println( prefix + msg ); + } + } +} + + + diff --git a/kjsembed/docs/examples/imageinfo/imagescale.js b/kjsembed/docs/examples/imageinfo/imagescale.js new file mode 100755 index 00000000..51ead9b5 --- /dev/null +++ b/kjsembed/docs/examples/imageinfo/imagescale.js @@ -0,0 +1,28 @@ +#!/opt/kde3/bin/kjscmd + +// +// Load an image, scale it, and save it in the specified format. +// + +if ( application.args.length >= 3 ) { + var infile = application.args[0]; + var outfile = application.args[1]; + var scale = application.args[2]; + + var img = new Image(); + img.load( infile ); + if ( img.isOk() ) { + if ( application.args.length > 3 ) { + img.format = application.args[3]; + } + + img.smoothScale( img.width*(scale/100.0), img.height*(scale/100.0) ); + img.save( outfile ); + } +} +else { + System.out.println( 'Usage:' ); + System.err.println( '\timagescale imgfile outfile percent [format]' ); +} + + diff --git a/kjsembed/docs/examples/imageinfo/thumb-example1.png b/kjsembed/docs/examples/imageinfo/thumb-example1.png Binary files differnew file mode 100644 index 00000000..79eca5d7 --- /dev/null +++ b/kjsembed/docs/examples/imageinfo/thumb-example1.png diff --git a/kjsembed/docs/examples/imageinfo/thumb-example2.png b/kjsembed/docs/examples/imageinfo/thumb-example2.png Binary files differnew file mode 100644 index 00000000..f4c805e7 --- /dev/null +++ b/kjsembed/docs/examples/imageinfo/thumb-example2.png diff --git a/kjsembed/docs/examples/imageinfo/thumb-example3.png b/kjsembed/docs/examples/imageinfo/thumb-example3.png Binary files differnew file mode 100644 index 00000000..7a449b6c --- /dev/null +++ b/kjsembed/docs/examples/imageinfo/thumb-example3.png diff --git a/kjsembed/docs/examples/imageinfo/thumb-example4.png b/kjsembed/docs/examples/imageinfo/thumb-example4.png Binary files differnew file mode 100644 index 00000000..42fb6022 --- /dev/null +++ b/kjsembed/docs/examples/imageinfo/thumb-example4.png diff --git a/kjsembed/docs/examples/imageinfo/thumbs.html b/kjsembed/docs/examples/imageinfo/thumbs.html new file mode 100644 index 00000000..674dcfe5 --- /dev/null +++ b/kjsembed/docs/examples/imageinfo/thumbs.html @@ -0,0 +1,44 @@ +<html> +<head> +<title>Image Gallery</title> +</head> +<body> +<h1 align="center">Image Gallery</h1> +<hr> +<p>Here are some images, the larger ones have been scaled down to ensure this page loads quickly. Click on an image or filename to see it full size.</p> +<table border=0 width="90%" cellpadding="12" cellspacing="1"> +<tr> +<td align="center"><a href="example1.png"><img border=0 width=197 height=160 src="thumb-example1.png"></a></td> +<td width="60%" valign="top" align="justify"><b><a href="example1.png">example1.png</a></b> (848x686)<p>This image shows the results of running the imagegallery script. As you can +see the script automatically creates thumbnails (using QImage::smoothScale() +for quality) and includes image descriptions if present. The descriptions can +include HTML markup <b>like</b> <i>this</i>, and even +<a href="http://xmelegance.org/kjsembed/">links</a>. + +</p> +</td> +</tr> +<tr> +<td align="center"><a href="example2.png"><img border=0 width=217 height=160 src="thumb-example2.png"></a></td> +<td width="60%" valign="top" align="justify"><b><a href="example2.png">example2.png</a></b> (340x250)<p>This image shows +<a href="http://developer.kde.org/documentation/library/cvs-api/classref/kdeui/KPassivePopup.html">KPassivePopup</a> +telling a user they have new mail. The popup is adject to the source of the +message (in this example that is <a href="http://kmail.kde.org/">KMail</a>) and +<i>does not steal the focus</i>, or otherwise interfere with whatever the user is +currently doing. The dialog is automatically hidden after a timeout (or if the +user clicks on it). +</p> +</td> +</tr> +<tr> +<td align="center"><a href="example3.png"><img border=0 width=203 height=160 src="thumb-example3.png"></a></td> +<td width="60%" valign="top" align="justify"><b><a href="example3.png">example3.png</a></b> (274x215)<p><i>No Description</i></p> +</td> +</tr> +<tr> +<td align="center"><a href="example4.png"><img border=0 width=158 height=160 src="thumb-example4.png"></a></td> +<td width="60%" valign="top" align="justify"><b><a href="example4.png">example4.png</a></b> (560x567)<p><i>No Description</i></p> +</td> +</tr> +</table> +</body></html> diff --git a/kjsembed/docs/examples/imagetweak/example1.png b/kjsembed/docs/examples/imagetweak/example1.png Binary files differnew file mode 100644 index 00000000..53408e63 --- /dev/null +++ b/kjsembed/docs/examples/imagetweak/example1.png diff --git a/kjsembed/docs/examples/imagetweak/example2.png b/kjsembed/docs/examples/imagetweak/example2.png Binary files differnew file mode 100644 index 00000000..902af717 --- /dev/null +++ b/kjsembed/docs/examples/imagetweak/example2.png diff --git a/kjsembed/docs/examples/imagetweak/example3.png b/kjsembed/docs/examples/imagetweak/example3.png Binary files differnew file mode 100644 index 00000000..c2b98665 --- /dev/null +++ b/kjsembed/docs/examples/imagetweak/example3.png diff --git a/kjsembed/docs/examples/imagetweak/example4.png b/kjsembed/docs/examples/imagetweak/example4.png Binary files differnew file mode 100644 index 00000000..9c2d9ae3 --- /dev/null +++ b/kjsembed/docs/examples/imagetweak/example4.png diff --git a/kjsembed/docs/examples/imagetweak/imagetweak.js b/kjsembed/docs/examples/imagetweak/imagetweak.js new file mode 100755 index 00000000..df7c86f9 --- /dev/null +++ b/kjsembed/docs/examples/imagetweak/imagetweak.js @@ -0,0 +1,76 @@ +#!/usr/bin/env kjscmd + +if ( application.args.length == 0 ) { + throw 'Usage:\n\timagetweak imgfile ...'; +} + +// +// Setup main window +// +var mw = new KMainWindow(); +var view = new QScrollView( mw, 'view' ); +mw.setCentralWidget( view ); + +var lbl = new QLabel( view, 'view' ); +view.addChild( lbl ); + +// +// Load image +// +var loc = application.args[0]; +var img = new Image(); + +img.load( loc ); +if ( !img.isOk() ) { + throw 'Failed to load image ' + loc; +} + +lbl.pixmap=img.pixmap(); + +// +// Actions +// +var ac = mw.actionCollection(); + +// +// Create the quit action and connect it to a C++ slot +// +StdAction.quit( application, 'quit()', ac ); + +// +// We'll wire the file open action up to a JS function +// + +mw.openFile = function() { + var filename = StdDialog.getOpenFileName( '.', '*' ); + if ( filename.length > 0 ) { + view.text = System.readFile( filename ); + } +} + +var open_action = StdAction.open( null, '', ac ); +open_action.connect( open_action, 'activated()', mw, 'openFile' ); + +// +// We'll just accept the default for the rest of the actions +// + +StdAction.aboutApp( null, '', ac ); +StdAction.aboutKDE( null, '', ac ); +StdAction.help( null, '', ac ); +StdAction.helpContents( null, '', ac ); +StdAction.openRecent( null, '', ac ); +StdAction.save( null, '', ac ); +StdAction.saveAs( null, '', ac ); +StdAction.showMenubar( null, '', ac ); +StdAction.showStatusbar( null, '', ac ); +StdAction.showToolbar( null, '', ac ); + +// +// Activate XMLGUI and show the window +// +mw.createGUI( 'stdactionsui.rc' ); +mw.resize( 500, 350 ); +mw.show(); + +application.exec(); diff --git a/kjsembed/docs/examples/imageviewer/imageviewer.js b/kjsembed/docs/examples/imageviewer/imageviewer.js new file mode 100644 index 00000000..f69d63c3 --- /dev/null +++ b/kjsembed/docs/examples/imageviewer/imageviewer.js @@ -0,0 +1,61 @@ +#!/usr/bin/env kjscmd + +// Applies a water color effect filter to the image +function apply_watercolor( img ) +{ + var imgfx = new ImageFX(); + img = imgfx.contrast(img, 200); + img = imgfx.despeckle(img); + img = imgfx.despeckle(img); + img = imgfx.despeckle(img); + img = imgfx.sharpen(img); + return img; +} + +if ( application.args.length == 0 ) { + throw 'Usage:\n\timageviewer imgfile ...'; +} +else { + var loc = application.args[0]; + var lbl = new QLabel(); + + var img = new Image(); + img.load( loc ); + if ( !img.isOk() ) { + throw 'Failed to load image ' + loc; + } + + println(img.isOk()); + img = apply_watercolor( img ); + + lbl.pixmap = img.pixmap(); + lbl.resize(img.width(), img.height()); + lbl.show(); + application.exec(); +} + +/* +int watercolor(imgdes *srcimg, imgdes *resimg) +{ + imgdes tmpsrc; + int cols, rows, rcode; + double gamma = 0.7; + + cols = CALC_WIDTH(srcimg); + rows = CALC_HEIGHT(srcimg); + + allocimage(&tmpsrc, cols, rows, srcimg->bmh->biBitCount); + copyimage(srcimg, &tmpsrc); + + gammabrighten(gamma, &tmpsrc, &tmpsrc); + removenoise(&tmpsrc, &tmpsrc); + removenoise(&tmpsrc, &tmpsrc); + removenoise(&tmpsrc, &tmpsrc); + sharpen(&tmpsrc, &tmpsrc); + + rcode = copyimage(&tmpsrc, resimg); + + freeimage(&tmpsrc); + + +*/ diff --git a/kjsembed/docs/examples/imunge/effectbrowser.ui b/kjsembed/docs/examples/imunge/effectbrowser.ui new file mode 100644 index 00000000..b3ee2255 --- /dev/null +++ b/kjsembed/docs/examples/imunge/effectbrowser.ui @@ -0,0 +1,151 @@ +<!DOCTYPE UI><UI version="3.2" stdsetdef="1"> +<class>EffectBrowser</class> +<widget class="QWidget"> + <property name="name"> + <cstring>EffectBrowser</cstring> + </property> + <property name="geometry"> + <rect> + <x>0</x> + <y>0</y> + <width>353</width> + <height>240</height> + </rect> + </property> + <property name="caption"> + <string>Image Effects Browser</string> + </property> + <grid> + <property name="name"> + <cstring>unnamed</cstring> + </property> + <widget class="QGroupBox" row="3" column="1"> + <property name="name"> + <cstring>settings_group</cstring> + </property> + <property name="sizePolicy"> + <sizepolicy> + <hsizetype>5</hsizetype> + <vsizetype>1</vsizetype> + <horstretch>0</horstretch> + <verstretch>0</verstretch> + </sizepolicy> + </property> + <property name="title"> + <string>Settings</string> + </property> + </widget> + <widget class="QLabel" row="2" column="1"> + <property name="name"> + <cstring>preview</cstring> + </property> + <property name="sizePolicy"> + <sizepolicy> + <hsizetype>7</hsizetype> + <vsizetype>5</vsizetype> + <horstretch>0</horstretch> + <verstretch>0</verstretch> + </sizepolicy> + </property> + <property name="backgroundMode"> + <enum>PaletteDark</enum> + </property> + <property name="frameShape"> + <enum>Panel</enum> + </property> + <property name="frameShadow"> + <enum>Sunken</enum> + </property> + <property name="pixmap"> + <pixmap>image0</pixmap> + </property> + <property name="scaledContents"> + <bool>false</bool> + </property> + <property name="alignment"> + <set>AlignCenter</set> + </property> + </widget> + <widget class="QLabel" row="0" column="0" rowspan="1" colspan="2"> + <property name="name"> + <cstring>textLabel1</cstring> + </property> + <property name="sizePolicy"> + <sizepolicy> + <hsizetype>1</hsizetype> + <vsizetype>0</vsizetype> + <horstretch>0</horstretch> + <verstretch>0</verstretch> + </sizepolicy> + </property> + <property name="text"> + <string><h3>Image Effects Browser</h3></string> + </property> + <property name="alignment"> + <set>AlignVCenter</set> + </property> + </widget> + <widget class="KListView" row="2" column="0" rowspan="2" colspan="1"> + <column> + <property name="text"> + <string>Effect Name</string> + </property> + <property name="clickable"> + <bool>true</bool> + </property> + <property name="resizable"> + <bool>false</bool> + </property> + </column> + <property name="name"> + <cstring>effects</cstring> + </property> + <property name="sizePolicy"> + <sizepolicy> + <hsizetype>5</hsizetype> + <vsizetype>7</vsizetype> + <horstretch>0</horstretch> + <verstretch>0</verstretch> + </sizepolicy> + </property> + <property name="resizeMode"> + <enum>LastColumn</enum> + </property> + <property name="fullWidth"> + <bool>true</bool> + </property> + </widget> + <widget class="Line" row="1" column="0" rowspan="1" colspan="2"> + <property name="name"> + <cstring>line1</cstring> + </property> + <property name="sizePolicy"> + <sizepolicy> + <hsizetype>7</hsizetype> + <vsizetype>0</vsizetype> + <horstretch>0</horstretch> + <verstretch>0</verstretch> + </sizepolicy> + </property> + <property name="frameShape"> + <enum>HLine</enum> + </property> + <property name="frameShadow"> + <enum>Sunken</enum> + </property> + <property name="orientation"> + <enum>Horizontal</enum> + </property> + </widget> + </grid> +</widget> +<images> + <image name="image0"> + <data format="XPM.GZ" length="55092">789cccbd47b7eb38b2ef397f9fa2d6e5ecae5e7cf266d0035266cb6da7ed77af1ed07b2f1aa9bf7c83883f704c56d5cd7c75bb5f95d6c9ca5f8a22114044202200f0fccffffcdbe7d3fddffef37ffe8fea625c02eb6f966f947ffb4fbb4e92ebfff57fff9fffcffff88fe160f0b7fecf68389bfe6df41fffc7fff80febf96fd6df9401ff5fcff64232ffde36244f7a762ac953fefd56f29cf35cf2a267f3072ff9f733c906e7836493f35eb2c59fd74ab6797b1f243bfcfb46b2cb7fef0a1e72799c5af2907f7f94cce5732cc963fefd483297cf3a8387d43f992999ffde0c25f3dfb79a64de5f662099dfcfe924cf386f24f3fe4a44ff0fd17e5b327f9e772799dfcfb8078fa87d662499cbebbb9249de6fc9bcbd9d2f99dab795ccc7b31a48e6e3b71a4ae6e315ed25f3f1b04f82a93f0dc1636a9ff32999daf32599f757a54ae6fde17e48e6fae23892b97e78a2bd63ea1f438cef849e97e892f9f7652b99b76f3d91cce53763f0947e6f08fd9c1137b664de5e43c83fc7f53bf0022cf475499c8be719c4f113d824de5cc01671fd0eb6895dbaff50d8ab174ae6f2ad3ac9a47f63c924df4832d73f732a99f777f324998fb73993ccfb5f7f96ccc7df3a49e6e3514592b9bd3aa664ae1fd6bd646eaf9a2b98f4ddf52573fdb58e60d89f6d49e6df9b13c97c3c1d45326fbf634826ffb2934cfee40086fdf88164de7ff65232d9eb9b646e1fa607867e9bbe641a8f816092cf14f2423f4d070c7d8b9f25f3e7bbaf60e89fb791ccfb3b15df43ffe22f30f42f13f240ffea1b18fab716bf877ee967b043dc92bf1f0ea16fdd9af3a8f740bc3dbe64f2f70bc9bcbfcd2fc9bcbfbd4432f90b4730f5cff55e3297bfc9c0187f732899f4772099c6e35b321f7f6b0fc6f8daa6649aff7692f9f3724d32d7f7cb4932ef6ffb4e32e9b302c6f86723c9dcdefc50326f9ff32e99f7975382a10fd75c32d7e795906742fdd3bd49e6df67a2bdd09ff20886beb89164fefcd54932ef9ffa2c98fca72bda0b7d6a9f25f3feb0c4f842bf9a07b0d02fd13fd0afe2090cffd6c660e85b24ae87be05a40f63e1df8277c9bc7debab643e5e575732efef6e2799cb1bfcf89ecbdbed2573fd5cfd781e1fcf952d98fa3b91cf277f74cd24f3fe0f3ec08807ba8d64ae9fc54232e98f27993faff9f13df787ae680ff4d57995cce57103c95c7fac3bc97c7c7c5f308d67b8028bf9f72299cbd3dc49e6f2981f92797fd69664de5f7e2499dbb33b92ccdb6f2dc1d067772099fca72e99b7ff6a49a6f946f437f4b9bd48267934b0d0ef77c9bc7dad68df9cee9fee25f3fe69447fcc31df88f1843eaf6e92f9f3da89649a0fee25f3f1cb85be41ff0331bed07f5f8ca7f0a7d43f13a1df9d2a99f777f32899dfffea80111faeae92b93cee41f090f7effa0c463ce77f48a6f9ee51321fafeb4930f547bb01433fecb164fe7cff5b321f2f2f92ccfb3f93d793bd745b30f421ae2593bfd94be6fd1b2692b93cde4e32b79fda164ced8ddec1d017e74332f9dbb564de5e772899e299140c7dcaa692b93db8df92797fe61d18fe3117e303fd59b792e979b164de3f8918ff05f5cf46f40ff4c715e301fdb9bd80e13f57f792797fad4a30fce906bf17f3f51ae331c4fc19a13d43f89780e693a9f0a7ed028cebfd4e321fafe6198c7cc00b2473f9bc77c95cdf4a4ff0908fc75a5c8f78bfb52553fcf02999ebbfdf08a6f10e5ec1c2bfdc49a6f97c2b99e6ff27c9642f3fbee7fab416f2407fc299643efe912f99ec692099cbd3b492b9bc9ab8ff94c63711fd0bfdb2a792c93e2ac9140f689229df5125f3feed5660e85ffd2a99fce34432efdfee00867e5e14c9941f8ec0d0bfcc904cf9572a99b7a76e25f3fe73c760a1afaa646ebf99e85fe86f2ec61bfaea0b79e11f0ba12f2eda8bfb4b7d267b98897c64dd81a1cfeb503297afbd934cf1d45e30fc93f81ef363b896ccefbf3a4a26793dc1149fae7d30f247ff2a99ea1d3fbee7fed68b05a31eb1924cf9c2083ca5f6076bc9542fd948e6fa900e2473fdbbbc09463d630246be1a6692f9f84481643edef95532b73f5df01cfd7993ccdb7be92453beb5924cf3c14432efbf5cfc7e01fffa2999e6bfb1646e5f9b022ce2cba364de3e37114cfec132c0d047f74d32f9e37b30f26b2f05431f5763c9bc7f42c1d04797e6cf99d0c71be41fc21fa52a18fe24207d9f0bfd5a1d04d3f8570fe009d573dca3642e7fbb054f697ca237c1246f3a944cf53a5b32c5a72f60f81bd796ccaf4f2bc994af2d2593be6f2453bea682e7345eed4e32d5ff14c9bcbf2f57c95cff7dd15ef8a35097ccdb93cd25537e2bfa6b3124fffd055ec2bfcc24537c548045fe518331decda7647ebd2eda6ba37fc478c01f6d44ffb8d43e1ded17e3af3960cc97f5022cf481e257a6dd149fd96bf08cc6ffe64aa6f92604c35eec4032b7efab2799e2375b30e94b2aae5f50ff58aa642e6fe148a67ce1065e927fb80d2553bd2494cc9fdf3e49a6fc45c863c07e1dc97cfcd3a3606a5f7d05633e887682497faf4bb08df8e2030cfb2bc9de17a2ff4bf49f886762f4cf10f666bd80618f3e8dff92f5177f5e914be6ed2f36e005c91b5f24533cf22598ecafeec04be467ae64f28757b041bfaf5f040f29fe68c0268d9726da63917e14a2bdd0c7f424998f5f44fdb314fd91bf83a18f8105467fdc4660e86783e789fee94a30e215e3118c78a3a0f9dc60fd45fa34072f491fc329d8a0f685a964aae7dfc0265d5f2f05537f568f60d86bb091ccfbe36248e6fad988dfbba85f8e24533e48f66f88fe892b30fa67634ba6f97508467f6d1cb0a827435ed11f35fa6388f9c9a7f8c814f157fd065e92fe5f6e6083e42f5cb0897ac417d8227dca3fc036f55fb305431fba77c1747f3b02bba4df3ad9ab29e42f669229df46fb647fe460d8d3aa0243fecd2758d4bbefc0a21eb403a33f2a8a772c263f6fff35055ba827d1f85aa2bf2f1a58f4f70a8cfb252a18febdf1c0f02701f58f2dda7f5d48a6fe9b8071fff21d2cfc83603caf51c1b87fb106433f4b1a1f87fd17eebf1b17ec903efbd43e46b0f71a0c79cb2d58c4e72d18cf2f1bb078be0dc6f3339abf5cd11f8906c6f5de1a8cf846e3f6c1cbe724df068cf6548964ae3f1b130c7f9096608c7f7603a3bde90e8ce7bb2f60b4d77e00c39f075c9f98f639e47fa34832d7e7f84c2c9eb7ba80216ffb08c6f3cc042cd64f1a30e42f9760d88fe382d19e1ced19c11e42aebf0cf17cd306435ecb04a33d610e16f20b16f1470a16ed3981457cf9443c82bdae2660e19f79bc341c8be7d70e18cfd71ec022df8ac178feaa05e379d72bf108e3df70ff369cc8fe1d8345bc9c81d1fe60452cfaeb7a03c3be74ba7e2adbd382f1fbcb3b18e3910dc1689f4df24e657fd4603cafb2c168bffb0cc6f32b1ebf0c67e2fe01e9d34cdcef1283e12faa6f30ee67f860e1ffe660a1efdc7f0ee7e2fed58c58b6e70cc6ef8d002cd6173db0a83f2dc0d0b78edbf77021e5bd078bf6aec1f87d41fabd14f2155bb0f8fd108cdfeb2330da93de83f1fc8ac6d310f2ac1a309ed772ff3734c5fdb48d64ee0fb72e58d4e75ec0f87d7202a33f0d713df4a5237bb7e4782a60b11ee681d15eed112cee1782a1cf158f4f86b6b8bf6581c5fa2af5a733823f762d30eed7d2efdd11f2efcd1d18d76bdc5e468311f2a3c007e379f5082cea75f760e8fbfa8d782cf49dfba3d150fcbebc030b7bdc83a17f099faf472371ffe64c2ceed73460e883cefb6b3416f7ab4fc463e10f2c30e46b8927e279b94b2cee6f6cc1d087ec092cec4930c6f342f24f85fc46442caef75660e8cf85fb93d18cfd9ec783f1162ceaa37cfe19cdc5fd3ceabfb990d79d80d13eeb152cd64fe9fa85f8de7c05a33df9188cf66cbec0d0c7f50d0c7df3b8ff1f2d85bcce002ce227078ceb1d0f2cfca54e3c41fb6f74bd21ef5780f17c5d058bf53beeaf46e618ebd77a2299c77f5bba9f25c6b7f4c1c2bfbd80d19eeb07f104fda1933cb678de2603e37eba01c6ef6f57b0a8ff71ff3d72c6a8b7e8d47faee88fb507c6effd188cdf3bdc1ec67d38c739e2e3c5a63393e21723269e60fde4f22c99d677b93e307577285eb7b8fd8f27ecfe9cf50e0c7d8a79ff8ca7ec7bfefb6b412cc627db81c57e823730ead9eb1158d43fb8bce399b8fe7a0716eb5d7330c663c3fb733c67eda1fa484d2cc6c39a83a11fed193ca57a651282b13e16f3f96ebc9860bdc8d880c5fe810c2cf21bae8fe3e544d4cb23c93c5ed30a30ea071b170cff92d0f81813d443d71730eaed9a07c6f53eb7b7b1c9bee7fa117c49a6f5024b30c5b3760cb6b19ec9e3adb13331e8face93ccfbaf3883f13c23013ba8a72e05d3fd0d1b8c7c734df23b53d8df86facf9da03e7e1b80f1fc82f7e76430813e6d63e229fa3be5e333194e4cd40b52b04ded31b8fe4e4653110ff2fa0a73a736f28d9a788afd67fa180cfd6a1db0588fe3fe7f32610accfb77c3f59721f2c77c493cc5fe0aaf00e37eb731788afa4e059ed1f8361f60d48f6dde1f93d914ebc7460a46bd2fe4fd37994fc7940f6cbec1e89f98cf5f93a578def5013c433d86da6f4c51bf09b9bd4dcce982f2b39cebcbc49a22fff6b83e4dec29ea15d95932adb704c433acffebf43c776ad1fd039d7886f5d315bf3f5356f09acf77d3d1d4a5fa65734f3cc3fe035d134cf7372c30ec355b824dc413dc3fb0e9906574dcdf79c4e2f74501c6fa5b74104cdfb73c3e9d4ea6d6887f7fdb10b3e791bef1f9940ddf1ceb078fe005f5b7c5e7e3e96c86f58f8d0246fd3a76c1f311f9b377b043e31bf07c693a9fa1de19df816dec07f804bb584fa3fe5accc47a86069e517b82002cd6f775b043f39bc6e3dde9923d8eeb7332035bd47f3705ec60ff824d3cc7fecf84ebefd498c19e2faf609bfa2be6f9f0d49c2d51cff5c016e5fb2b176c8f78fb8b15d8a5fa99c9e7d7a93543fdab1b831dfafde6287844f5d10e8cf1af49bfac39c63bff024f499e98ee6fb3fb937f7d023bd4fed407bb435aafb124d37e2d5d30b53f03cf87d43eeb0d8cf5dd7803c67cb7e1f63d75587f707df1e9fece7c30a2fd5d7b30f6b3469f9269fdc792cce5594dc1587fba52ffb84c1edebecd5e326f7f41faebceb19f2cda8271bfa6133ca2e727e0118d4fb2164cfa9c2892f978af4c30eca1f1c19321d7bf2bff7e3660e34ff5e53bb043cfaf5dc174bf6c0076a97fdb929805acfcfb6d0446bdbee4ed9f0d857eddd660f89b6e2298da5f05c4ac3f687e6bc0c311ad87e07a263f9f0fda77f094da537f8067245fc5f569369a1963d29f2b31eb5fdabfe20ba6e7a777e0d188ff3eb9815906c29fa78227d04f053ca3f6b65c3f6663260fd553a93d2cfca4fec91bc95cfeea041e517f5fb8fece2662fcdd023c86ff33c1d31167cd06cf21cf5c308d679d8017d41f0df72fb3e9cc1ef3ebab14ec8c69bfc05432ed47d38885fe5d4cc9b4fe37028fc8fecb37c9649f25784cf6ebbf82e7f47dbc042fe87e05f5cf4ce8936b82e7f4fb36113ca6f17a002fe8f986b8de80fe8bef4dd28fc292cce52fa68269fc4d1effb0db2f49decd0c0c7fdc92fe2ce6131a3f6d2d98fcb7bf02cf49bf370330d68fea5a30fdde38831dfabea3fe59b2fea178b0009bd41e4f03db23aeff37713decb5f00593fc2df5a7c1ee47eb6f2330eadd17156c8ea87ff7609bfc45590b267f78d5c02e714bfa6ab2f1207ff80136c87ef22918f34dfe06c67cd186c48b018dafcee3cd99c5ee47faa48217647f99609bf4c7a0f1b2160392afa3f6da6cfc68bcd69279ff949f6093daef4ec1f067f5817831a4e76de8f70ebb9ece177c806d6abfb3235ec0dfba2bc9b4df9bc6d7ed1376ae5f5c3fe703263f6f4f520a1e53fc99102f66d4be8cf7cf7cc8e4e3d7673e784c7cdd82a7d4de5a03c3fe751e9f3265c2fca09be009d94fc2e397394b87c99f186bf08cfa4fe3fd3b9fb0e7717dacc792e97c0b8f5f58f8bb20d6793d613e5f2cc7b49fc5005bd49e35b56fb1c4fcecf1fe9e2fd9f7743dfdde582ca83f8267b049ed59f3f9686eb2eb69fd782699d62fa83de67244f67de1fa3eb79643b237ef2698f4ab9e8347d4feb0008fc99e1c6a8fbd70d05f4762261e6f9f46e3e730a6f3160618fdbbe6f9c6dc5d0ea8bd0df5bf6b88f89aebdfa25f00a5f8ff4e32edd749c0636aff66019ee17939780e7de2f92a73f643e8bb031e537b7c133c237bf5dec073ba7f44f71f1a225ea3e78f447f79dfe011ddcfe3f22dc68c29feff06e379ba0e9ed2ef0b1effb1747d44f3b1fd0d5ed2f78d0236c65cdf367c7e5fb0009858bf07cfd15f7bf082f4a3492473f96f19d8257b6df8f82e66cb05f55fbe223630ff6f797cbc98b3f67079527afe82319d17e1f6b7581a03fafdc693ccc7d7a0fb194b97da7bbb111b63f2af1bae9f0bd31810eb7cbd61612d1dd2bf94da671943c8cfe7af856d8c69be6e0563be594f2573fdd7b8bd2c1c763ded0f53c01392c7bb4ae6fdd3717d5db8c684fa4bbb134cdfa767f094e28180fba3e5c080fff15fc0b309f5ef9764d24ff13dfc43cae7a3e5d0807d6cf8782d47acbdfcfeed0b783ea1fad50ebca0ef6f3ed82079a32f30f2c5644f6c627f5acce7df655fd0e1e3930460a662dc3f1cc14beaaf40133ca178a8069bf47cdf90ccc74ff3c10e8de78dfa676c8afd09b564daff5982b1ff36a6f64c58ffd2fed40b7836a1fac504bc9c50fd6101c6fc97abc426e2b3700fc67911f3018cf33ac99d643e1edd198cf3176e07463da4fa0063bf8826be47bd53e7fe773965e345fded806db217eb1d8c78f29612b3f6923ea9603cbffb0663bf4949d7b38083c663b3022f68fceb7bb043f6118682a9ff8c02ec92bfcbe9fe7dba49f5c30d18fb636c9e2f2ce7ecf7144f2a6097e4bbe5c4ecf7140fcdc0b0b734018bfde03a784af3c53504cfb15f47dc0ffb0bbb8160ecbffc002fa95e58edc1d8bf1a4dc1163d2f36c1a8575495609c5f1a4aa6f3a134febd83e2ed2f376093faafa3e72fcc01f1f50b3c217ddd5660ac37ad63f00cfe5407cf69beef5230ea35c6026c60bfe55532e55b39d8a4eb6f73b0d8df20ee6f637fe04a32cdff03b043fd757b904cf9d9168c7ae7ed2299ce7b3692697fc898d8c2f99ddb128cf3b317f49f85fa6348f75f1a06d9afb604c37ff817b04dfa1c0ec10ee9bb4ef22ecd015d7fdd8047345eb5079e907e598e60d2d7b40363ffe3762598e2d5750e16e703d692297ffc128cf35768af897afb36108cfaee5c32d56b0f9269fe2e24f3f61731d880ff5125d37ed80558ac974c25d37ec09d64de7fe64132f73fea27d8a2f15732c9b4bea008a6f655a23fb1dfb28c24d3fe470d8c7ae1ed5132e95b2099cf8fa6e82fd4e3c32fc9b4bee3125b38ef7723ff641816d99b7d03dbe48fc22bd8a1f9f95a825d9adf4af28706eb1ede5eaf060fe97aaf133ca1fc5605237e6d8ee009e5bbd5198cf58b4efc1efb6fb71730f67bae66e025c5df8a09c6fecae020998fafd248a6f3ba909fd93b6f4f71025bb0af52329ddf9849e6cf533fc036e993924ba6f96726993f2fcec00ef57ff12e99e2c34a32ed7f0cc1f017d5bb649aef7cc9bc3f22f13c97fa4fc3f859388f5a6d25f3f69443c1d86f3b06e37c4be54ae6edd354c9bc7dd791643aefdc4aa67acf2b18e7f134f13dced325a4ef26d3379affc95f9826e2cb952a99c6f7153ca57835fd0463ff691108267fb579028b78c2001b34dee14532bf7f62814df88b4832d52f2ab085f59d0118eba3752899ecff2699eae307c9b43fb405431f9454329d2fbb97ccdb938cc02ee95b2adaebd2f8b590dfc279e448974ce3f12998e67b4d30ce074713c934ff403e0be72d2dba9fc5e607defeca014fc85f5413f094e2313b954cfea0114cfe467901233fd41792a99e6a49a6f527c198afd71bc9549fb9822dea8fba944cf9502799dad782b17e6d7592c9be6782495fea42321fdff8c7f77cbcb477b043fa1deb9229ff4904e37cc697641a7f0decd27828aa647abfc45032ade7b982495f13b25fcbc2fb0c944032d9cb93606abf5949a6f314cf60bc4fc00a24f3f6b79960d29f5a914cf11dfa53d87bf82999d6df303e16ceb755a4cf369b3fc8ff7660ec3f57de04933ff0f760ac5f665bc114df2b67c1a44f57156c507f5f1cc9b49ff3198cfdc69bab60aac7ac4f601be7fd22c1781fc95132ddaf95ccdbabd492b93e794f60e883229e87fd9ef959326fbf3a964cf9e00318fe5d9d4be6fda192fed916ce83a92f92a93dbe64ca8fd11f229e4c6f92f9f3938164ca1f4f82b1fe994ae6df871f60acf79a6bc9bc7f62f49785f3b1b75230d95775914cf30bfacfc279b22df90f47c413a621995f9f7be011f99b6d2b98e2136d021e4f683d63059e4cb83e7ae2fa19dd4f3b83e734df943118f581f22099cba33c8397549f592dc026d69b8f9279fb6f9f60e453d6156c537f5a63c9644f8160aa47695330fc8dee0aa6e7c5b964f28791648a6fe692297e580aa6fa6628da8bf8c3bc974cf9642118fa38954cf58f89649acf1692e93c27e9936361ffbdd149e6df2b9e609c1f7d96ccf549ad24d37974e887d0676721998f8fba924cf1fa9364b247713df687754f92e9fc672399ea45a23d581f35af92f9f7b9f81eef13885ac1181f4b32d5dfa10f16f6a3044bc974dee9158cfd3f892399fcbb2d993fff26fa6786fd3ba23f711ef146d7bbcc7e283f7b944ce7995ec0639aafab25784af671db0a9e52feb200cfc9fe320f2cec650f5e52beae7d49a6f319e2fe4bd457766083f453bf80b11fa878154cf6b2adc1585f37c4fde0af235530f251717fc45b9e90d7c17ca848a67add5530ad1f74a160aa8f76e279c8e7c34630f97f3b174cf2379a645abf247fe35a781f90ff2818f3c1443297571d49a67cfd4930cd87da1b58e8ff5630ece74b32cd1fa564aaef7982697dc87900633f73694ae6faa0be4aa6fd789a648aa724637fd25a32ed3f79924ceb3d3330f6f325ad64de1fd98364927f2598facbd42553fd3594ccafcf311e16cecbdf22c95c5e652a99de7f267e8ff3c9e1bb641a6f4732bf3efb008bfd812f92297eb32473794b31bec87fa30a2ccea3ee0493ff30f79269bfe23718f53e6b2099ea0377609c7f34be2453fc7b914cf91c1f2f63c0e6478a0fb6e019d58be207c1538aff8fe039e503712b99e6eb5c3297a750c04b1afff22618fb1922c1347fc73bc9b47f4630f2f9eda360b2efab2e98fcd1ea158cfd83452598f47f6b48e6cf8feec1a8b7a40bc1f05f3bc9bcffb61918f596f85d32d5e3447fbaa48ff94030f6ffdc24737bf267c416f6a7ac3f2453fe580bc67e99122cceeb9c24533d6b2299f4ad108cfce30773fd500cc9341f7792a9fe6b0ba6f5da6b2399ce372ec1d85f1d9d25f3efd59b60f89f3bc9bc3fd4a364f22f6f60ec97543792797fa8a960d8c74d32f9932918f61ed49269ff832d99e44d24f3f61a23c1d43f96fc1ef1fe1c8cf763448e645a3f16cfc3fe3d632899e2955832cdafd01f0be7d5ad4a32ad9f3792b9fcc64030ced3d792b93e9723c9b41feb02c6fe67732b99f68b7c4aa6faa3180f9c17f6499ffa032dc46bf098ec5d8f24d3fe08133ca1f530ed049e527eb7f50593ffb83c48a6fd570a7846f7d36b30e6fff25b32d5ab73c1145f28ef82299ed1e660d473b64f92a9def92698fcdd5a3cdf46fd24914cfbcd74c9b43e21e445fda611f7437cb1fe124cf65edcc02edd3f7225d3fb001e05d3fc5ebd108b7879bb93ccfbc72f05937e66a9605abf538e92493f56e021d99f6249a6fa5b2b98fc9f72914cedc3785a789f52f12698e42943c964ef17c9e40fe792697e1849e6f2648e60ac470660bc9f243b4aa6fd3fa1647ebda20826f9d24c32ef0ff55e32d5d7447f60fe2f9f25933f5a4aa6f8e62c18f9502299f40ffa61e1fd4b4a2899f6279492495ed19e29e297028cf795048d64dedef05530e29137c9e47fe4efb19f740cc6fed152134ced0f55c9fcfb488c17dedf74b9934cf64dfa3c326754ffab0cc1643f510ac67a78ba04633e77466083ecb309c026cdffa921998f476582b19fa7ba0aa6f93e5e0ba6fca6188051bf4b447bb1bf4aff00237ff60f92e9fd41f792e9bc7d2599e6f717c1d8cf247e8f7a5d160ba6fecf23c1b4bf21a0f86264e13c72f82499f2fd57c1f06727c954bfcec098df755b30d9ef7a2e98ecdf78974cf54cb447d47b3d5330e2cb0fc9b4df47dc0ffbd12ea9647a9fec1e2cde07f92e99f60b1c05239e3e4ba6f9df974cf9d74932ed9ffff17b2e5f70014f90ef288261df8664b25f5332bd6f0ae36be1fc4ef92499f22d4b3297ff593c0fefb7525dc9e4df3c30de5fa53a9229feb12553bc2ec66f46f2565f92c97f37609ca7b4df25d37e825a32adff89fba39eaafb92293fea24f3ebb7627cb13ebbfd944cfbadbf2453fe37154cf287a664d257d15e715e80fa6fcce673f2af117846f94076075e503d2188c1d88f9a9b82c91f2457c954cf38832df2279ba9647adfe70a8cfaecf62098e2ef6e2699ce27ed04533cb2d5c0d8efaa3c09a6fa46f12199ec5d3c0feba51dcd9f63517f5dbd0886bd3f4be6d76f7f30d59b62c164afde5432d5271f2453bdf0118c7abd77124ced4f1ac914afae2553bd5edc0ff3b9f32498ec6d1308a6f66c55c9341fdd83313f9ba23da8ef46a564dabf664aa6fd21f27b8a37e291643abfe249a6f9ce174cfb13a2028cf78b25b9647a1fd4a364f20fdf92c97f0c25d37a512599d607a03f22bf375ac994ffa49229ff78944cf94a2618fe48fe1ef59e4632bd3f270163becf2ac994bf8beb71fe4b0d2453bd27964cf552d13fa807da2f9269ff612499e627d13ed40f424330b55f13d763bfc6ed4332c50f37c1f0f78a64daff3d964cfb43c578637daf7a138cfd39429f719e6745fa30314df21f590ec6fedd32134cfbb10c5d30f98bcb8b64da2f3c01dbd87fbc174cf5c92001e37c4d25eee760fff1b7605a0fc8b792e9fc81b8bf43f149740263ff68fe2a989eb722fb9c8878201849a6f75f9e25d3f37cc974fee15532bdaf752898ecdd0904d37a475080512faf7e30e9432e18e7f56e82914f5482c91e0bf13ce4ff7e2698c627fb924cebcfe2f7d8ff1b3e80719eaa934cfaee3992491e717ff80f6f2699f22ff13dcecfa753c9e4bf0e92293f394aa6fd139660b2cfc8904cf9df4230e68b4a32add78bf1c0feda740ec6fbebcab3648a8f2792c95fd492299e1848a67ccd164cf25b2d58f887ab64f2379d64de3fea4132bd6f4efc7e8e7827944cfb7f1e2553bd4f134cfa6c799269ffb6781eea8df14432b57f2718ebe591645a2f8b05231f15bfc77e0f652699e229f13cbc7faa9a4ba6f361427fb03f5013fa8cf5e2c495ccbfd73dc924af180fec0fd33e24737922f17c9c6f6cc91ea626f69b5e13f082fccfe64d32d547bfc0385f565ec0886fba1cecd07a663394ccfb237b05633d627b144cf6779949a6f75fd682c93f06349f4dc5fa433d154cfaace982697d721b4aa6f3c11918f585742299fce5bd64aa67958229be5ac560ac27ac12c178bfd79b64da0ff1e37b7adf95fc3dcef70592a95ebb174cfe3a10cf47fda01c08c67e1b5f32bdcfb0134cfde12a92493ed17f585fc81f25d378dc49a6f8e253308d57249e3f417c7a904cfbcd7e30c5d382b11e982592797f24df82b1de954ba67aa6907f4af69baec138af6c8d24533d692f99ea733bc1e4ff3c0b2cde37be944cfe712499f2b1b964b2675732c52bd0670bfb45d54832e58fba64da0fb301e3fd8d4a2499d67f857ee0fc72f82d99be5f81713e3e194aa6fd49e27e588fb89ec1884fae13c9d4ffa27fb0bff0229e67537fae481f66e612fb2d776083ec3debc026eaa53618f18a3b0323fe580f04d3f5c98b64da7f63825df217852e99ce77907c33113f6c4dc134df6f1f24d37c9982b17ee04f05537b9a77c9148f88dfa3deb07a92ccfb7f73168cf365778229be48bf25537d19f28bf501e55e309d4fc94f92c97fcec158cf2b12c1e41fbb4fc9b43e3d104cf3f7f6158cf87ebb170cffe448267942c1e47fba05187f1f455049a6f5614330f4ff0d8cf3b88ab83fde3770d94ba6fafc12bca0f6a557c1c80f6dc9644fb964aa7f1492a99eb1934cf3f718bc44fd632199f2ab67c914bfd782518f16e389f78346a23dd8bfa58c25d379ba4030c95b5f2453fc5c824deacfec2299f6eb6c25d37ae74630e2b94632ad170bf9b13fb87b964cf514713df61bd4aa643a9f0f7bb31cecbf10fa28f6e3f89269bd83e2adb9399f52bd33032fa6fcfef9086cd07e8d95f81eeb1b97a964b2bf0dd8a2f958ff02dbb41fbbbb825d9a3f2eb5608a3fe28560caafb6141fcd45fdb11a83b11e180f05d37e5c5f114cfe669d8051ef6f3dc1a40fab108cf3d9e55a30ce3b1a60d4d78bab649a5fe5f7645f978364dededbb360f247452899ea616730d6e7d6779269fdfb4330f9bbd4148cf8e7058cf5b8e44932bdffe25e30f6835c24d3f9d1b964b27f713decdd16ed9b937fd2f792a99ed2082679a247b0380f33964cf3ab18af05c52f57d1df381f5baf2453bcff0046fcacfe60daaf6a4aa6f9ed4b30ce7fce25d3fedd1918f65f8af1c37e6d4f954cf9cf5a32c927fa17fbede254326faf22aec77c1bd582a9fd971d58ecef3524d3fe5ea1bfd84f97d1f82ec47a83be124cf5c8ca07dba4efbab8de9df2dffba44f0b51afeb5cc1747d32154cf61eecc043ccf74f9269ffd3098cf7495c1e25d3f9c14a30ad9f281f92693de2001ee3bcf34430e94f71114cfe259883f17ef6b52599de2f36144cfaa23c4aa6fafd188cfa79d60a267de832c1345f1786649a3f7e30cd97a2bdc86ff55232c54fb9648a6fc4f367e44fbaa1649a5f669269ffb7f87e4ef6915f2453beaf4ba6f9443c1feb655a2c99e47b944cfb532493ff6bef25d3f86ec1e2bc532318ef1712fa82f3cdc55e32b5ff1b0c7b5acd25d3df9fa04ba67ac25e32bd0f44b4cfc0f95ad13f787f759c08c6fb8f34c9141f6e2453fee80b46fe22fac7c2fbafef24933f17fa8efdf9590dc6fb8d4a8a079626ceb3d513b04bfa5a527cb664f645eb65067848f359fd8369bfec063cc27ae45532d5e31f25f3f15c3d83315f5d12c9544f740553fe1e6592a93f3dc158bfb88127145ffb9560b2873a96cce5d75f25537ce90ba6fa62f283a95e2ae49bd2f82b0f82c93ef385645a6f17ed453d39984aa6fac04c32fdfd5607c1a42ff14a30cdb7b74232e5a76f60e483fe5132cdafb960c4fb5f60c4aba52218ebaf7b30d69fb6e27b9c1f0ceec1d82f962b92c95f1d24537da7148cf93d05239f534f92e9bc8bb81fcefb1547c9544fabc1383fe68af1c67e92f807d3fe43213ff6af7662fcb19fdaa37cc410f5ebfc5e30cd1f6b07ecd2f85a347e06332faa8f1cc0d0efdb17784cf6e91a82499ff44ff004eb318f92693fdebd649adf5f05937efa67c1347fe91618e7bb6e7782112faa60ac8736a1601a8fac00a31ee98c05e37d155bc1347ff8aa647a1fc009bca0f1f21682c99f9ae2fe0b6acf360763fd62bb168cfcb0148cf7790879f1be9ad4954cf53cd17fd8bfe49f24533db1164cfdbd7d07e33cd346fc1efb17b789643a4f300423bf303760bcdfec42f669b27885ee47f38169e1bc977e124cf18d3706e3fd11fa163c22fdda9482a7b43e7805c3ff058660ba9f2b9e87f364d14632d5fb4792e9ef37fe02e33cd926028bf364efe039c9b712f747fdd9ad24d3f58231fee58b601affdb9b648a6f7230dedfe12d25d3fa760a467d3817f218145fd99f9269bda1924cefdf93df23fe7e009b349f98623c2c1a5ffb2298ee97d8609c3f32e6609c3f8b2cc9646f0bc914cf3f4aa6786607c6fe958ee20f8bcdafb43f81e20b165e93fe5c3e25d37e30f13dea3ddd093cc27ede2d18f5983804e3fd1d9a25989ed7168269ff61fa089e223f9e8167d47f862699d6f39e25d3fe68152ce2b70318e7c9ec67c9f4fe12138cf70f252918f1932b9e67507caf08f9f1be9938069b648fc15e308dbf32108cf7df88e7637f627c150cff7a0163ff42f000c6f99c88ec9b4d37a867d1fc62b3f1a3fd3c743f5b8c5ff102463cb2da82117fb4df9269bde12498ec510f25d3fef01c8cfcb8b425d37eaa5232bd5f2506235ed85a9269bda4154ce31d89f6cef17ea8037841f76b447b17d84fb6012fa9fd6b211fea49978b608a4f0c156c423f3bc9b49f3602c31e6f7bc1d0bf4a32c50fe44f6c1bfb3be22918e7e93a6287d907adb70ec063eacfd51b784afdb3d1c0c85f8a5232cd97afe0398ddf652d99fcf75130e5879d09c67c961482c97eae7bb049f74b3ac9349e86649a4f2692b93cb978be8df749b88229be509660eca7f39f24d3f922713dd6afaedf8269bcd690c7c6f9d755001e52bc5b533ceb5a63d29fab2199ce63edc1139a9f82083c25f9f5068cf745dd2cf082c6238d25d3fb1d378229bf503ec178dfce6a0946fce9bd0aa6fe5ccf04e37d0af27aca77ac1bd8a2e747df9229fe2dc136f98ffc4530e9f34a934cf9f10fa6e78be739387f48fde9daa8f7273c3e310716f67b260f9269ffde1318efefb91e24537dcd06e3fd79f6156ca0deb1904cf6a080d1fe6a2199e67b5f303d4fbb801dd8fb0a8cf8f9a611db78ff5dac8211df745f60d413133e7e2c389be17ccc183c27ff97459279ffac4b30de27947e0826f94c4532bd7f5d032fa9fd6d2a784af58e21d8a0f9e1aa48a6f53f5b30d58ffd6730de5f94ad89ed01d9ef86eb2b0b2eb0feac6fc04b92af7525d3fbcd8f6093fccde64532d9cb4d30c57fe1128cfd33eb77c1a41feb028cf7355a1f82e9f9ee1cec62ffea9b60f227892918e785f0bd8dfdafe9b3601a4f270463fda81980f17ea59adbbf3966fd41ef472dc14bf2075b1b6c60fdec4132d50f0bc9944f1cc126c693dad7bf5e9ff2075c6f63bd6b45fd33b1e6549fb8adc0580fdc7682c97fdd5ab035a5f74309c67961e50bec523c1de2f736eaf7f11c3ca4feaba8bfa6d664467fffdc080c7f53b492a97e6f08a6f686776013fab4964cf69982717ed224ff30b5b15fe81608c6fbd3ce60c48b2d8dd78cdd8ff2eb5430c5839b5730f2dff60086be74a4af33d6ff148fdd8391ff6a74bf390b30693de808b6917f64c436ce8fdf1230f6bfb7345e0b6b3a27fbe9c0f319bdaf8bfcc782a5f7e43f0f60cc4705f99f256b3fedf71c826d92ef3625b627349f68dcdf9b2c9f9b927f237d3458ffd1fc5b8327f007241f530f1aaf6b00467cad51ffb2f8674efd41fed5b6711ed0e4fac192cf39b57733022fe97ecf977feda32abf7d8c9f3e26ffa7827fa74fcf0afb9da5daaac3fe58ff6a0be8f3df21cb2f72b9ecf3bb5c0afe9b90afff77f7df5116d62247f5d81ffad87ddba87590cbfd87bfb3f1f9779605f20899fa6be8cfffb79fff167b71e9f393743ffadc1663f4e33aa96fbdedf8eccf3f18b9ffff65e16dfbc90e6009240d1fa9bf2b3bc9439ee0df4d1661eb3f64f9313a3f24f3e4e717cbfa7791e5379fecfefa91d758f05a8e94457a8a7f2b590235542335561335553335570b364ea55aa917b5669f86e951ab76ec7365b2de544dd5d99f15ff9dc67eb1fe379365a3aed827652391a85bf6b963d2ecd43dfbec982c07464726dd91fdfb4e3da9f74cce7bf5817d0c76e53ff4daff5b6479e43dfdc446e699fddb597d515fb94ebda9efea87faa906ec9a9449f8c524f85607ea501da96375a24ed5993a67d2fc1bc9c25a7a5637ec9f91ba607f02d8fd92c9f2cafe6929aafaa4284cc7be15431d2ba662b18fad380af31a8aa7f8ff3d92fcf7cc954aa0844aa4c44aa2a44aa6e44ccf5ca63d2dfbf4b6622a059b45064aa954ca45a9954669954eb92a3745537465a5acffe8b5ff37cab251b6ca9db253cf8aa2ec95036bf1513929f7ca83f2a83c29cfca5979515e9537e55df9503e952ff6dfbf9581325446ca589928d37f23596c65a6cc9505d3b393b26413cd83f261288661b044c0b00dc7700dcff08dc0088dc8888dc4488dccc88dc2288dcab8a87746fddf23c99f9345b58ca6ff23a390df6677a3353ae36adc0ccdd08d95b13636c6d6b83376c69efd391847e364dcb3cf897d8e8c1fd8e7d178329e8db3f162bc1a6fc6bbf1c1b4b0cf02685e757f9b797f9aadfe999ff8af6561527c1a5feccfb7313086c6c818315fd4186363624c8d194b9916c6b2370ad3304dd3326de3683aa68b8fc73ebe19b04f684666c465eaa53a9a31936a6726666a66666e16666956e6c5accdc66ccdcebc9a375333757365aecdcd2f33b1f2eb1cfcd764311a736bde3169becd9db9e7b21ccc8379344fe6bdf9603e9a4fe6b379365fcc57f3cd7c373fcc4ff38b7dbecd8139c467648ed967c23e63736aceccb9b960992a3334e3de322cd3b22cdb722cd7f22cdf0aacd08aacd84aacd4caacdc2aac12b9dc2f91c5ffaa2c56655dac4b3f2e566d0cad5a3d5b8dd55a9d75b56e9666e9d6ca5a5b1bd6d3f7ccd96ead3bd6522689b5b3f61677bfd6019f2393666a9dac7beb817d1ead27ebd93ab351da592fd6abf566bd5b1fd6274b98bf5884b0601e3d61b3e9c0faeea3cf1fd1d1bfa2634cb31a8bfe82f001fff74a89aca135b2c6d6c49a5a336b6e2d7acdb196cc74fa4a9ed18f85b5b34d48f2439643bf4c614e6ddb766cd77ab03ddbb7033bb42326cfc178b4633bb1533bb37336abda766197ea935dd997de92fecce74fc932307756cdc6646055aa67d77663b776675fed9badd9ba71303fec95bdb6376c249ef9676fed9924625414662bcc5e602bf766681bf6d6beb377f6de3eb0cfde3eda27fb9e8debde7eb01fed27fbd93eb319d7b35fec57656fbfb1d1b07efffcafc9f27cb16a66274cb78cc6f8b4df992c1ff6a7fd657fdb037bc8faf3c47a7864bbe6dc1edb137b6a2db924bb7e64fab161ff9cb1f6ce85fd9b91bdb0972c485698ddcc1dc3311d662c8eed384cd2bde33a9ee33b8113b218f5dd89545df17fcdecfe155954d7183ab113333bb1edda499cd4c9ec2f27778a5e0ea7640ff0ed3d6b55653d3b17361acf4cc706cc6216dc6ed8ff3b356b6be3b44ca6b9d3998173756e8e66f7938feeac9cb5b3b1b7ecf78eb365d21c8d9d73e7ec9cbd73708ecec9b9771e7ec9107ecb7a7eb6a03f234b2f09f3c683fe7ecea3f3e43c3b67e7c58cadb33db1ced6b33d6656cc3ece2b6b5dc5dab5c0a7f765ec63cfe9e374f8bc39efbd24f6d20e9d0f66fd47e7d3f9ea7fe954ce379366dffff5f6cec8e9ff5acca933b3eb9fe4f8576599ab9db3b05f9c25fba1e21a6ce2b08c23f34accd3bab6ebb8aebd702a73e17ab66b1f5d9ff9a8931b981fccdacfaca5f76ec86c2ae673e6d18ddcd84d98bde0e3746e6a7acc73b02b594fbcd93336be67377373b7704bb7722f6e6d176e63356e6b358ae67656f3afe8987a70afaaeddeecd6d55cdd5db96b3626cfeec6dd9a43f7ceddb97b3622dbde86dd837bb4576e6031ed331df7e4debb0feea3fbe43e1b817b765fdc472195fbeabeb9efec5707f7c3f9703fdd2ff7db1db84377c474f1c0fe7dec4edca93b73e7eec25daabd2f6091b8a7aa81f70fbdda9f91c533d8f46d79b6e778ae937b9e71b2179eef055ec8e4601fdbf0222ff612e6030eb6d1eb8c977a99977b85577a9577f16aaff15aaff3aedecdd33cdd5b796b36e7c7c6c9db785befce7a70471ebb0b1b5d9dfd3ff36fde8e59cec1db7b07efe89dbc7bb5f01e58467af31ebcc71f5af5bb1ff853b23c79cfded97bf15ebd37a730637362dbde3bd32f2e099368cbe6f229b39ae7de76bd0fefd3fbf2bebd8137f446ded89b78536fe6cdbd85b76441d7a3aff8866ffa966ffb8e71f45ddfb31e7c9ff9e8ad6df8811ff663e547ee8069e4831ffb899ffa198bd6be51bffd523c9189fe75599e2f7eee177ee957fec5af0d6603e6d46f7a49fc967d3aff6acead27ffd6cf77bee6ebfeca5ffb1b7febdff93b7fef1ffca37f62f966a2bef8f78aea3ff88ffe93ffec9ffd17ffd57ff3df8da3bdf03ffc4fff8bf9f485bd30c74ee57ffb037fe88f8cbd3ff627fed49ff9737fa1382c27fd6679f70f597ea97dfc99d8d25f066aa004060b112da65f6aff97c0f7fae5b7811d38fe3570cd0fe31478811f04411844411c24411a64411e14411954c14509839a7d1afb3d68838ee59af3e06a3f07b7400bf460c5fc48ef0d9560ddeb99ad30d906f6c27a0e36ecaedbe02ed8057ba50e0e4a191c8353708f0af54f35ab3f2d8b1d3c048fc153f01c9ccdd829ad73f012bcf6da15bc05ef81137c049fccf38c83afe03b1804c360148c8309fb330d66c19c49b47016c1325443253442d3188416fbc39c71e8865ee88741188651c86cc73a8709f3cb4698f29881c50f61d6fbfc300f8bb00cabf012d661e32fd421d3b41fb2387f94e5e77af6cf63d25f1db661175ec39b19875aa8b3bbafac636f27e13a5c33795e8c7b2f0d37e136bc0b77e13e3c84c7f014de870fe163f8143e8767f52d7c095fc337ab08dfc38ff033fc62d2982c22f6d97ff90e07e1301c8563e3184ed82cb40dd6e1943d63e6ee99fd7c9b53f6dfe7e1225c466aa428456444e68fcacdaf5a46b288ff862c28f1d4c8525fd5d7c88e1c7f19b9e673e41987c8376751c02375a61351c8e2f7cf88e524511c25511a65c62dca8347ab65f369cafe3c4645f01895aa1255d125aaa3266a5910d345d7e8166966678ccc75d4467ab48ad6d126da4677c629da452c82f0039ef778d68ecdb40bf6bc7d74888ed129ba77d2e8217aecefcdabed866af4d1eeaff6f2932c068fb043b77516ca2e7a8a9ea373f4629ea357f6a437e6750d16a79ca37773c2e6e8aad7eae823fa8cbea2ef68a0ce153f1a2aea8f2a2c7f9e1b8da27134096d2b8ca6d1cc8aa379b48896b11a2b56111b319bac629b85166eccbc3d9f73962c7f93b29843e33ef6e3200ea3fb388ae3f081f554cadbcafc5a1f25fe2c0b7ff68f7131d4f8f9e22cd4f73889d3388bf3b888cbb86277bcb0f87111d7d6dedd5b4f7c2639b959dcc46ddcc557ff515dfdb4f662cb3bbaca5875e25bacc5ba3f8b57f13adec4dbf82edec57ba5890fea323ec6a7f83e7e881fe327e3143fb3d866c9bc7380b86e689de373fc120ce2d76011bfc5effd88736b3055a38fdeff992c0ad34726cb6b9cb8adba8a3f4c23fe649db7641ec6b09ee3da665ed3fc0c33f6dcaff83b1ec4c378a456eaca7e51ee94713c862c3c1eecff9dfdb7493c55f57816cfe345bc4c54e3c17e4894c448ccc44aecc449dcc44bfc24484263efde9b3e8bd8d887e7a42c3b65f3d6d17c4da2244e92244db2a84872b1baf07765b1c886f8155b36bbb2fe65914fa2b8499194e69b71f26fd69e8dc9d9b998dff6c13ad953e39054c925a99326d6d5f7beea9db4ccca52f40d55c1d97d95bb385332bb4abae49adc12cd38252ceb4956c93ad924dbe42eba26bb641f1c9243724cd82c657a8ec272014364d94c9b4b2f4dee9387e4d158264f09b34ab146d2e722ff4c96e499f5e198e50e2bf6efe7e4257935dfad3e3f3f276f56ff8afa7df26ece8dfb709c7c249fc957f29d0c143d192a8b64c4abe3bdc7b4fbac8dc9c264b2df93713231de9269324be6c63159d8c76469c6a99a2aa9919aa995daa9e3dfa76eeaa5bef1603a2cbfe1b2f45910cb54b769601cd3308dd2384dd294cbc2d76dfa7cc4180aaff6932c96b0fe3453466e6b97cc8e9d344f8bb4343fd22a4c98f75a5afdfe8687f4621becee75daa46ddaa5d7d451f4a04b6fa996ea91c9fd3f978549c3644957e93adda4dbf42eddb15fedd3837d4c8fe9c9d8a7f7e943fa18fae953642b7a344c9fd373fa92bed2c8902c2ca7db4681719fbea5efe947fa997ef5feb197a56f7f9f5bfd2acb8f91e17a78607dbb5412ff2139a7dfce9069eb673ae86da5f7c54ee5fa696f8f553a4ac7e9249da6b3a4b50b65c3f42c5177fe23ef31361a7d0edad724d379ba4897999a29c63163f971b4efb3e3ccecb3e2649559999d39ea57ea0475e6665ee66781e9fa81a3a06ab0eb675096e1c5599845599c25ce23b3172e8b6af5b9d52fb2889a9add3f99d14efd4a064ccf952c553eb2cc74cc2fe61b077dcecbf477613d982316e37efaeb2ccf8aaccc2a61e7e45b98b34db24b56678d5dc763f53b6bb32ebb662c62f343d6df6ff6c2fd66de9c652c99661ce3a74ccf56d93adb306bd3b36d76e74efa5999c53363a603cf76bfcd8445369691edb23d93e5901db313d31d85db7491ddff268bf28b2ca67a973d3032b24743c99eb82ccc37f67d642ebcc4661146f69c9db397ec357bcbde852c1855577d4bdaec23fb8c9e93419a655fd97736c8d8e866a36cec8eb24936355da7cc66d9bcf7ebacbf17d93257734509552b377233b7723b77d8377d3d6dc29edad74398b7cedddccbfdec900779a828ff4496be024a7dabf8bd36f63edacc23c330ee982cbd97efed70c024619219f7799c27fe364ff32c3c30597eac4172bf95e779919779a556f925aff3266f8d63dee5d75eb7dc613f1ef9cdfdeeb3e25cb316f153aee7ab7cad9eed32dfe4dbfcced67396c1b09879c8729a4bafd9feb7719f29f93e3fe4c73cc88e4c9b1392c52afe812cbd0f559209d332db2ed5263f1926f32baed05ca6678eed5877ecbfbce6f7fe5dfe104cf347a3fd690d92d97afe943f671725cecff94bfe9abfe5ef7dd4937ff49909af719cddaf6cca73628dcd8871fe997fe5dff9404d9cc833f3613ecac7f1579ff1997dbc4c51b4cfee30c9a7f92cc9988e1d59a699f47e377c0bdffe200bb75792259fab7b854d65ea77be302c63cfd2fb1dd5bc481673943bf9b2500b8545f5b3e8814547b6dcabc0575793b1fa919f0ba33059b7d9ac557d2cbfe8f312ebaeb7e4c2e96b1785cb62ad53e1157e111461112923d52ee22229d22233f67d5ec365611ac6aecdd98cb92f8aa22caa3c2459faf6b398f5f597f9e5375958c6b34f6fcc62be8b0b7be4ce74a97227646177ae8ba6688b2e288a6b714bf25f7684303d53fc645268855eac8ab5710835e7b597a5d8b06cabaf6a7ef4d5be60cd243916dbe2aed815fbe2a0d8c5317b284ec57df1503c16cc3efa1a279764614e0b268f7128cec54bf15abcfd248b1aaa7f57164fcab22bde59fe742a3ed894b5efa33c5420875c9645f1597c15dfc5a01806398ba2c90bffd8555114a3625c4c8a692f4931ebd72c989ea8c5bc8f467b5b6677e03163b12cd5ecbb544287c540d7d250c2d22cadd22e9dd2354ebc22c2ae36c7f6a1f498cdc6a55f06e1ae64290dd731f7efc822d654c40cf3adb665c472b053191b2ecbef852cfb5e16f3cb3a9749999659996749745f163f564a7824669465599597b22e9b5e92b2cd34661b565f3b6371dc985bb4e10ffaaca7ecca6b79b3be4acd0a4a9d8d67c4a45995eb72536e992cbabdeda326368e5bebbecf64cabb7257ee7b591425cd7a6d28b552fb45961fd13ef773ea8dcd103b75c56439183e1bebc81c5b7d3d2cb0674e63cfcb63792aefcb87f2b17c6271ce86e527a398c594ca9d5d97cfe5b97c295fcbb7f29d79d12eef32adafee9bb3bebec13f337b5f7eb079bc2c3fcbaff2bb1c985d392c47e5b89c94d3c42d67e5bc5c944be3c45c7d156a7c4c0f665f1939564a655466d06746a7e0d4ef2ab2aadf62fedefb3059d8b7663f36c8d834bbaa2c26cbbd19b2deec97483a264b6b06c6a1b22bc79bc5e3a00996e5c4dc562e538ba86236cfa29545e5574115329fca66bb3ea736471513d73a313946fd9a4515dbdb2aa9d22aabf2aaa84a2bacaaea52d55553b5556745c1b1ba062b362e5ba7a355b57ebda3aff254b74aabf42467b21c83a36ad9f51f641151a5cf6571d488e9e246bd315559556b264bc4662c268b193269f64c96a37bf65a6fae2e2387e9eb5bb5a9b6d55db5abf6cab53a54c7ea54f575e17be6c717d681c5d5233e26a3fe2ebd3d570f4c96c7eaa97af646d5b97ab1aaead5dc556fd57bf5517d565ff128afabef5e966ac07ac2e5f5cf678bddb11a56a36a9ce4ce23c6c5339adf627e4bca6270efba60d1ee539ac5a36a524db98e912c51af654c965335f33a8f656bca3c34ccae9a87af9eaac6ac3f17d5f2a26637f7f5a25cb81fb615f38349d17f26b406c3ee7570377d7e75312fd6c5be38e1cbc5bd78179f8d897f092e6134b8449798c9d2b91fccbadefb159cde673059946a7449823e47f6d9c7fea32ca859283c96225912f549bdbfa4ec9e593fc6fdfa9c6df523d4af3d18a774e75d2fb9925e8ad0c8eefbbcfd525eaacbe5525f9a4b6b9c2edde56a6fcdd1e5165f98bd93244764f10773e445d68e5da55df4cbeab2b6c2cbe6b2bddc5d7655a7b697fde57039ba2fbd2c173633b1d8cde27fd5d684fde2fef27079e4b2a0adfd5add3f95256071f24d29c2faf27479eeb585d61bfb95a07ecd81e9d8a377f35545b3df7975c88ca6feec72bebc5c5ecdc4383afae58daf136d8235f75dbd7e8db92c7c3d96f5f196c5dd5333bebc5f3e2e9f97afcb777cbcf06a13d388e16578195dc66c869ddb6c66cd466c967db5ee7adbbf4c2ed3cb8ccba2f0bcc2fe5d16392f4096545373b5cdcf97f9657159f6eb90bdcdb2d8b85fd50accc08d8c83a7298f8a1fb4c620fca8d55a49b6b5519bc98ac9f9565bb56def1cc38bfaf99ecd8d336ef74cc7b8341e9b3146e6dcdef82cdeac9ddaadbddaaf83484b46e9ad0eeba88eeb84e5ca9fcce3796c6e9db008f4c9dd32590e755a67756e325990875bfd0aeaeff9cbcfb2287eaa2b6e5dd4a5f25557c68149c0bc0fb3dfa8978569716cc69eee2b6aa9cc422bfc8caa9a4590ec7f0d6b5beb7eb84347cdaf2c63af9cd73063f67faa22f6ebdeaff7d27875c746f9cbfc626d5cd6d7fa566bb55eafea35d36ca77c8af27a536fcdd8b9b23cdceb6318d6239bdec2eabb7a57efcb3d932515759e3fe695d8112074cc55efd44370523ae5b13e184cb3597e7f6fdbbc12cfda581f599b4ff57dfde0b6a1556d13b77eac9fea67e3549feb17a65b8bfab59f159cd728b02d1691ceeb37bfb1b7fe376fd994b220ca89acbdfb5abfd71ff56738a8bfeaef7a500fcba01e992ed3c27db17077aec3f29881cb324b63578feb493de5b2507ef20f7264f6a797a59ffb13f6ff0d9bfda7f5ac9ed70b9657b2fc8bc52e5b7b592f9d779bcdc98dda288de13f5a35f3ca1f8dd958c64363db47f6d9374e3f438693be6ed3fbb2c665ff34a2d0def09a9af1cb1ae0d074eb5be3357e1334a1f3d4444ddc244dcafae291e54977eeaec9ac2dfb158b429bbc299ab2a9b8bdd09ca8f42b763fcb42732397c5e4b364aa8cd2cc99c77a7369eaa6316377c3eefb7039352d0b8359d6e186c6aee99a6b738badd0b48a466b74fbc18c9b557aecc7c57c6fd64cdfc76c2c3efa5cbdd9345bebdcdcb9dbbe8283d53fac9c9b5ebfb3a4d935fbe6604d9a63736aee9b0726c363f3d43c3799bbeb6be64c2fe3e6dcbc34afcd9b948559c51f65a1d95ecaa2f1959bb5faa138cd7bf3c1a22ac7ff609e89d973bfa6686f9b4fe3e0dbcd57f31dbae167ad3483669828d60b7bde283359ae356bc66c961b46611f41369366dacc9ab971b296eeb6e1e3815566167d9b9ed3354b63efad5bb5555aa3355bcbe8ebd581396efb15c45d9f2b87ba71689dd66dbdd6ef63181e7719aadfaf09ff365752a5cfa4bdc2fdfa937a8bc76de03dc65d1b1afd4afdb658703fbbed6dba8d8c531bb7499b865ef5de666d9e9fdaa22ddbcad8370fed85595585fce4beaddba66ddbaebd5e5876dfded8bcf3ddd70ee4eabfefed5aaddf1de36baddeaeda755bb35f6dda6df0dede056f5ec89eb7734a63d7eedb437b6c4f52163f38fd41161bd97abff39945bc2c951e313ddbe5b9a2b7f7ed43fbc8b4f7686ffa9d05b5d53ef55adf326fdf9edb97f6d518861f4e5c44ed5bb269df59ccb3cf3b7bc9645ef5f949fbd17eb65fed773b6887eda865b3068b697aed123b19f67e906bf6b69db0acf8d44edb593b6751cb397875ed76d12e3bb59fdbeace38754a67746667c571922779af472c8e39fe4116e75759d84c99a94967770e93e6dab99d67192cd770d89cb063be56ef7c7b5b9f7d3753baa00bbba8da767197746997b1b0b8e8ca7e6dc8db75157bfea5abbbc6df756dd775d7eed6699ddeadfaac8e723b5ec95b326b687b8fe2fb4e65dce75db7ee36eeaedb76776c02d875fbe6397aef0eddb13b75f7dd43f7f8ab2cbfc563b40fdae2fbb87b59fabdb76ef7d43de7cfddb97be95e6bc738b9ae7de8ff1a4166c38eb3eddeba77964f9cba8feeb3fbeabe9d85fad80dba6137eac6d19d195b0b33f6b56ed24dbb5937ef16ddf2aa5e95ab71358d9dfbca7763f9bd1ce6d00ffa99fd6ad97bc7bada4cbe73b7bb322bb18ee1cadd5d5deffdea3109dfaffe35b886d7280fa302b66ffe1d1d13eb0b72bf196a7fdcef5de36b52b2d65d53ebe19ab119ef6c9dddcf7eb5f79ab3ff5a5ccb6bc5e29897ebe55a5bfeb5b9b6d7ee7acd27d7db55bb321d5533b30bdf8da69c5c57d7f57573dde6937efe655aa8f4750ce623a2be06c6f7638dd87c74ecfd38d515ade7de5aaa8171bcde5d77d7bdda3847b5edab2c5993353c07367f9c07f8afd7f89ca7ebe17a8cd953afa7eb3d3dddbf998b6641d1eef5e1fa787dba3e5fcfd797eb6bad3069deaeefd78febe7f5ebfa5d75d74139bc0eafa3eb987d26d7e975769d7b6bd60b8bcccccceb92dba2f5f327f2dd7d73c7fc1c27ebcc52c3a79b7263f955348c4c36f3b9aa6dbf33591cbebef31764b99937eb66df1cd6379ecb66877edf8bad140b2fb9b139d0b8f7b51b0b346f8152ddc25b748bd5db2db9a5b7ec96df8a68d025e15755df4a7377ab6e97f0e3c626c65b5bac6e9db1ef772df0fd16d6af1f5eafb0d86cc4246aee7236b3dcaeb7db4d4bc6d133cb2d44fefb87ddf3ffb52ce6e34dbfad6eeb86c5860d1b0d663515f3f8ecff6d8fc5eecc9fe593dbe6b6bdddd5a5fa62d7cae2b65386b7fdeda0d4ea58dd869f55773bde4eb7fbcbddede1f6787bba3ddfce51623f180fb71733643e7af24759983454afa4fbbfdede54f7f67efb48068a226ac97f7d7d3f2a6e9fb7afdbf76dc02b565f2cb35c58776c86d89a73162f6d6e43e3741bddc6b7c96d9abab759eadce6f1241ef77bf56f8bc80a5fa2eab6d4d4a8d394a85202f5ac199aa9599aadb1b16e5acdedade4e78fbbef3396c82759cc58f3345f0bb4508bf242d1d20ce3f287d3597fc25e1eb5584bb454cbfad981dd7b617e7a119385f624cdedad96f733a75668a5566917ad564325615ed0b65fe289b25322add15aadd3aedacdf84c1dd573979aa6e9da4a5b6b1b7ba16da99af0ebc8b03f2a8bb1ad7667dada9db653bba0b9bddbef2c7f37642dcfa1f8f22fc8926a7beda01db59376af3db008efce9cfa1f2c3bda71eb6451633568f92e43ed517bd29eb5b3f6a2bd46b935d2de8c85f61e4fb40f36269f2c216e94246ccb2767e999da97f6ad0d3436a6edeeefd98bf5dcee2c35f2b59136d6260a8bd955d72eed525db37111f562ef2fcbf2a84db59936d716da52578d7da8318f79673d9993b86e6fecb363518056b6bac26c79a71bbad92a9dab5bc64db77527327457c97596ee844e7fe622ce597e32d4033dd4233dd6133dedc7e0d74f98f5b2447e2f95bbd7333dcfebb2d20bf6fbfe0c84266b797c86ff2b3a16157aa957fa45aff5466ff5aedf11c3f2de39af8f322fa45ffb798faffbfaa6ebbe66817ed3355dd757fa5adfe85bfdcef850bff59dbe77c6d5413fe847fda4dfeb0ffaa3fe14bd07aece722db28dde4ef86e0bf3e78fe9e8e764adbfe8af4aa36ead86cdca34abf4f6eff075c43fbd8724c9f537fdbdb8ea1ffaa7fea57febcc07588affed6ed3ca56a3f7beea637afd3a561f4733895c33d687fa888dd0589fe8537da6cff585be5ca92b6565accc95e5eddd3c7ded778d38d5ca5e39b6e1eec90f0b0ff68b2cae7170dc95bbf2567e3c535f56415f310a4e2cdeea57df6a5a7bfb73b2048fab701505b355bc4a56e92a5be5ed78555807166b6efa5ccb3afe248bc9b28265dee5ceed8565b4b755b9aa5697555dcd568d3e5ab5b1c7f7c23129dcddaaeb76abab395e752c5bbbe3f66e626ef955166f7533e3b261f9d270a5b1f178e335567efeafaf2afd9571311f57fa6ab55a6bb362b8daacb6abbbcbc76ad75767d2a05f79b0b67d0ecf64796372ec983c0adfc570cff7819ef85efea3d8cf6bdcbbdf76e87ff8cd6abf3aac8ead1d7cb84edffa7e9e679aa6b63b6627bfcae2af4eab7b9643ad570fcdfbea919fce727f3a052c4f69fca971795a3dafceab176db67ad5ebd5dbea7df5b1fa8cbff26ef595f615a31fbbddf98749f7c177bc0f9d57f6795b7daf06d17e35147b2cfbbdbccd9339ee7739b58bd5a8d72e173b9358e3acdf65b1ceab717d67ec5693d574355bcd51c3b7708ec1fdf3314c92af16abe55a5d2b6b439badcdb5b5b6d7ceda5d7bc69e45cffb1f7bdefb489eaffb32097a7b62b3105fc7e3fba9f9beea7e36627e6318266b7f1dacc3c0091cbecb91452c6431bd17f85d967e7473dbd8d7efeb681dab77e20c2d9745f9b16be9cff8b1f03198af933c5d5bc1789daeb375be2ed6e5ba5a5fd6b5b5b437741601fbf7fbd5b30fbe57a25f6bb15a16fc34ceba757416dfb3e83e9ce9d77ecd807df6ebceefd6cc62bc50c8d2eeb411f366bfd90bd7d26374b7beadb53573e4b2fee5fed5793f628aba5eaf37ebedfa6ebd5befd787f5717d5adfaf1fd68feba790c5fdd69eef5ac1b8b04fbf9ef76a7e704b3e584bbedb9f5950bffba8f7e2eb7e97fcb1df83b63eaf5f02d736cc28effa73246c8e1feb193f73d2e7373edfafe4b23c69bb7e5dbf35cafa7dfdc1e617c8f2f7f78ffdf38ff3283f69566595d196e7f5e7fa6bfdbd1eac87eb11d335bea38c568b980e4db0afbf8fa6c6acc7cffc04c6b2dfadd7cbe90f7a7bea77569a43967505d5e0a69a713e6171d79d36d1f3f5b8f776eb49bfa3b61f93cb389f38de7aba9eade7eabdd8d32b674be7afc8f2d3d9621ecf798f6a11dcaf179774bdcc5f36ea46d9181bb37faead164ebf368979c230a77db5439cb4602336661ab91436d3dc39174ba1fd0a2caa7f6511e4ae0f0b36569fdfacc6cce59f8ce3c6c9271b77e36dfc4d607da94f56f35b9bfed2b8fc7eb6381a2a9ee2da55972acd26dc449b78936cd24db6c9f9aa0bcb6eac27ffdbf68bbc782effdf76ae6549552488eee733a6f615fdba7dbb6356a899203e5a6db51f3b4444f0c14b1489987f9faa8202a4bd37b457331113b9d010943a661645669d93b6d9e37b5a6207f5ce54d90a7b630ee6244ed8f3c2d4532060d9afca32ad349d280e4d481246103617866ae8b10a11c3b2b36c86248e1fe983506f36cb7bd7f59cde1344592e9dd23decc91c0e90c0115250a0014d680104cf80a691efb672cf7c667bc1191af13a6a6c8d2ed758790ea8a041fba8a546ca6681e23a2c67047dffd9b4a1130fb9e20cbad0833e2ce34747a706bc2c0e85fef98baee722bfd4f4404187dc51957668dcd0c2d0b660004318c12b8c61025378f3347fb13bb0acbe5df0f8ab3a31cdd0e01d3ee0136ee036e9c2ddb1ed7437f7e95459c13d7169c0bcfd003fe0117eb2bb700a4ff08c94def1b9eef5e9337dca1557dfc052a8ea8aefae6ed98c216b9d45ef4ffa485524aebeeaa181333471eeaa5edbb7f71bff47100423b4421517519a70a1686ff7106f632dbe471b97ebe0a027b3a4874ec8a276354cdffc603e255ca59dee228325a4b8c2354b719e8d29bbca113774bcb961e319c8f15c1f6327bd3884873ca043ee1bdcda7dce35430f7d0c30740718e10e636fed2f7ddd7f0cc2861b3aa1161991827b3cecfa8d66ec6112bce2115354f693204dfadb96d559cd6ccab25f967cd21655d61b3627a2d61336b0892d72a03dc20e53978ef868d8fa229f5faee75a7fe935c07eb745b764495b08ec7d0311d5f514356ca3bffd70224ff774bfb3f1822818bb5ad8461d3bd8c5de6e837df6fe0507fb088787258ef015c7d68bd0fa1a7cc79ef3f0a8623d21573237714a0f6bb636061dba66de58d0211dac1b76bfe293ef6039b59ad281736c393795d713791dceebf80ee712f96e3009ddd07544a5d179e13613e6e4967d435ca3ec245389a0cad56bfd58aad7bf7aee9fc122ff178e852391e3f3ba9c7d9399eff23a234758aeb7d96b869def6fe7fb0f468e60216ac18678a2378b9890bd31a42ee18c42f1d27b720dcf09969c1fb0909d7904e76ec356026184f0baafc89d66956e3da5fecbf6f6f369d67545d6b5c5d924df135a7ec542cb5e26e49a7cbfc201afa191da8093df3604f79408ae9ab0ad576031ca9ca3caca1635c83935653d22cfb448ce3bcf6adc752c32e62a9eb9443352aa19aaaae7e288acea1ab4729f2cb50e052bf5d4871cf952b02732ae47d9db635ea9689b453c57bc2062244752ad5f5e84c592fcc3e1ee4c949995795bc152fdbea830d827ffc84c20e9088f91d2fb395e4b665b520152c3422492ebf27dce3a1163b10a2cc60916c11710bad85b6ed69a7320cdc09db863ceee0a1533e20c1ccef6c814cd995eb334f9fc9ecf4b7ebda988b5c23b67b1108e04dff03d63da7fc32f8b9a5f4caeec2fc7c9c7e6f5bc5e154b795ce2e596e3679fca7dd222b624e3bc58134fe3a1e0bbcd199677fcb81c4b3d6a7ea7d6aeb0fb7e71ceb9a3f5738b7cbeda2ba7de3ba79caf57e52fff15fb1fcbbfd3fefcfbaf3ffe0193cc32fd</data> + </image> +</images> +<layoutdefaults spacing="6" margin="11"/> +<includehints> + <includehint>klistview.h</includehint> +</includehints> +</UI> diff --git a/kjsembed/docs/examples/imunge/imageeffect.png b/kjsembed/docs/examples/imunge/imageeffect.png Binary files differnew file mode 100644 index 00000000..1a976ab7 --- /dev/null +++ b/kjsembed/docs/examples/imunge/imageeffect.png diff --git a/kjsembed/docs/examples/imunge/imunge.js b/kjsembed/docs/examples/imunge/imunge.js new file mode 100755 index 00000000..72de2c5c --- /dev/null +++ b/kjsembed/docs/examples/imunge/imunge.js @@ -0,0 +1,239 @@ +#!/usr/bin/env kjscmd + +// +// Setup main window +// +mw = new KMainWindow(); +ac = mw.actionCollection(); +mb = mw.menuBar(); +sb = mw.statusBar(); +mw.setStandardToolBarMenuEnabled( true ); + +view = new QScrollView( mw, 'view' ); + +lbl = new QLabel( view, 'view' ); +lbl.alignment = Qt.AlignCenter; +lbl.text = 'No Content'; + +view.addChild( lbl ); + +mw.setCentralWidget( view ); + +/////////////////////////////////////////////////////////////////////////////////////// + +// +// Center the image in the view +// +mw.update_layout = function() +{ + var x = 0; + var y = 0; + + if ( lbl.width < view.width ) + x = Math.floor( (view.width - lbl.width) / 2 ); + if ( lbl.height < view.height ) + y = Math.floor( (view.height - lbl.height) / 2 ); + + view.addChild( lbl, x, y ); +} + +mw.resizeEvent = function(ev) +{ + this.update_layout(); +} + +mw.update_view = function() +{ + lbl.pixmap = this.img.pixmap(); + + lbl.adjustSize(); + this.update_layout(); +} + +// +// Load the specified image +// +mw.load = function( filename ) +{ + if ( /^\w+:/.test( filename ) ) + filename = filename.replace( /^\w+:/, '' ); + + this.img = new Image(); + this.img.load( filename ); + + if ( !this.img.isOk() ) { + throw 'Failed to load image ' + filename; + } + + sb.message( filename ); + this.imgfile = filename; + this.update_view(); +} + +// +// Save the specified image +// +mw.save = function( filename ) +{ + var ok = this.img.save( filename ); + + if ( !ok ) { + throw 'Failed to save image ' + filename; + } +} + +// +// Open an image file. +// +mw.openFile = function() +{ + var filename = StdDialog.getOpenFileName( '.' ); + + if ( filename.length > 0 ) { + this.load( filename ); + openrecent_action.addURL( filename ); + openrecent_action.saveEntries( System.KJSConfig.kconfig(), 'test' ); + System.KJSConfig.sync(); + } +} + +// +// Save an image file. +// +mw.saveFile = function() +{ + this.save( this.imgfile ); +} + +// +// Save an image file. +// +mw.saveFileAs = function() +{ + var filename = StdDialog.getSaveFileName( '.' ); + + if ( filename.length > 0 ) { + if ( this.save( filename ) ) { + sb.message( filename ); + this.imgfile = filename; + openrecent_action.addURL( filename ); + openrecent_action.saveEntries( System.KJSConfig.kconfig(), 'test' ); + System.KJSConfig.sync(); + } + } +} + +mw.saveCopyAs = function() +{ + var filename = StdDialog.getSaveFileName( '.' ); + + if ( filename.length > 0 ) { + this.save( filename ); + } +} + +mw.fileProperties = function() +{ + var net = new NetAccess( null, 'net' ); + net.propertiesDialog( 'file:' + this.imgfile ); +} + +mw.run_ksnapshot = function() +{ + shell( 'ksnapshot' ); +} + +// +// Setup the actions +// +mw.setup_actions = function() +{ + // File menu + open_action = StdAction.open( null, '', ac ); + open_action.connect( open_action, 'activated()', this, 'openFile' ); + + openrecent_action = StdAction.openRecent( null, '', ac ); + openrecent_action.connect( openrecent_action, 'urlSelected(const KURL&)', this, 'load' ); + openrecent_action.loadEntries( System.KJSConfig.kconfig(), 'test' ); + + save_action = StdAction.save( null, '', ac ); + save_action.connect( save_action, 'activated()', this, 'saveFile' ); + + saveas_action = StdAction.saveAs( null, '', ac ); + saveas_action.connect( saveas_action, 'activated()', this, 'saveFileAs' ); + + savecopyas_action = new KAction( ac, 'save_copy_as_action' ); + savecopyas_action.text = 'Save Copy As...'; + savecopyas_action.icon = 'filesaveas'; + savecopyas_action.connect( savecopyas_action, 'activated()', this, 'saveCopyAs' ); + + fileproperties_action = new KAction( ac, 'file_properties_action' ); + fileproperties_action.text = 'Properties...'; + fileproperties_action.connect( fileproperties_action, 'activated()', this, 'fileProperties' ); + + StdAction.quit( application, 'quit()', ac ); + + // View menu +// StdAction.fitToPage( null, '', ac ); +// StdAction.fitToWidth( null, '', ac ); +// StdAction.fitToHeight( null, '', ac ); +// StdAction.actualSize( null, '', ac ); + +// StdAction.zoomIn( null, '', ac ); +// StdAction.zoomOut( null, '', ac ); +// StdAction.zoom( null, '', ac ); + +// StdAction.redisplay( null, '', ac ); + + // Effects + browseeffects_action = new KAction( ac, 'browseeffects_action' ); + browseeffects_action.text = 'Browse Effects...'; + browseeffects_action.shortcut = 'Ctrl+E'; + browseeffects_action.connect( browseeffects_action, 'activated()', this, 'browse_effects' ); + + this.create_effect_browser(); + this.create_all_effects( mw, ac ); + this.create_image_operations( mw, ac ); + + // Tools + ksnapshot_action = new KAction( ac, 'ksnapshot_action' ); + ksnapshot_action.text = 'KSnapshot'; + ksnapshot_action.icon = 'ksnapshot'; + ksnapshot_action.connect( ksnapshot_action, 'activated()', this, 'run_ksnapshot' ); + + scriptconsole_action = new KToggleAction( ac, 'scriptconsole_action' ); + scriptconsole_action.text = 'Script Console'; + scriptconsole_action.icon = 'konsole'; + scriptconsole_action.connect( scriptconsole_action, 'toggled(bool)', part.view(), 'setShown(bool)' ); + + // Settings + showmenubar_action = StdAction.showMenubar( null, '', ac ); + showmenubar_action.connect( showmenubar_action, 'toggled(bool)', mb, 'setShown(bool)' ); + + showstatusbar_action = StdAction.showStatusbar( null, '', ac ); + showstatusbar_action.connect( showstatusbar_action, 'toggled(bool)', sb, 'setShown(bool)' ); + + // Help + StdAction.aboutApp( null, '', ac ); + StdAction.aboutKDE( null, '', ac ); + StdAction.help( null, '', ac ); + StdAction.helpContents( null, '', ac ); +} + +// +// Activate XMLGUI and show the window +// +load( 'imunge_actions.js' ); +mw.setup_actions(); + +cwd = (new QDir()).absPath(); +mw.createGUI( cwd + '/imungeui.rc' ); +mw.resize( 700, 500 ); + +if ( application.args.length ) + mw.load( application.args[0] ); + +mw.show(); +mw.update_layout(); + +application.exec(); diff --git a/kjsembed/docs/examples/imunge/imunge_actions.js b/kjsembed/docs/examples/imunge/imunge_actions.js new file mode 100755 index 00000000..586641d9 --- /dev/null +++ b/kjsembed/docs/examples/imunge/imunge_actions.js @@ -0,0 +1,320 @@ + +// +// Effect Browser +// + +mw.create_effect_browser = function() +{ + this.effectsdlg = new QDialog( this ); + var vb = new QVBoxLayout( this.effectsdlg ); + + this.effects = Factory.loadui( 'effectbrowser.ui', null, this.effectsdlg ); + vb.addWidget( this.effects ); +} + +mw.add_action = function( act ) +{ + var lv = this.effects.child( 'effects' ); + var txt = act.text.replace( /&/g, '' ); + + lv.insertItem( txt ); +} + +mw.browse_effects = function() +{ + this.effects.child('preview').pixmap = lbl.pixmap; + + this.effectsdlg.exec(); +} + +/** + * Creates the actions for the image effects and defines the functions that + * provide the implementations. + */ +mw.create_all_effects = function( mw, ac ) +{ + this.imgfx = new ImageFX(); + + // + // Water color + // + var action = new KAction( ac, 'watercolor_action' ); + action.text = '&Water Color'; + action.icon = 'imageeffect'; + + mw.apply_watercolor = function() + { + this.img.setPixmap( lbl.pixmap ); + + this.img = this.imgfx.contrast(this.img, 200); + this.img = this.imgfx.despeckle(this.img); + this.img = this.imgfx.despeckle(this.img); + this.img = this.imgfx.despeckle(this.img); + this.img = this.imgfx.sharpen(this.img); + + this.update_view(); + } + + action.connect( action, 'activated()', mw, 'apply_watercolor' ); + this.add_action( action ); + + // + // To Gray + // + action = new KAction( ac, 'togray_action' ); + action.text = '&Grayscale'; + action.icon = 'imageeffect'; + + mw.apply_togray = function() + { + this.img = this.imgfx.toGray(this.img, false); + this.update_view(); + } + + action.connect( action, 'activated()', mw, 'apply_togray' ); + this.add_action( action ); + + // + // Charcoal + // + action = new KAction( ac, 'charcoal_action' ); + action.text = '&Charcoal'; + action.icon = 'imageeffect'; + + mw.apply_charcoal = function() + { + this.img = this.imgfx.charcoal(this.img, 0.2); + this.update_view(); + } + + action.connect( action, 'activated()', mw, 'apply_charcoal' ); + this.add_action( action ); + + // + // Implode + // + var action = new KAction( ac, 'implode_action' ); + action.text = '&Implode'; + action.icon = 'imageeffect'; + + mw.apply_implode = function() + { + this.img = this.imgfx.implode(this.img, 30, 'white'); + this.update_view(); + } + + action.connect( action, 'activated()', mw, 'apply_implode' ); + this.add_action( action ); + + // + // Emboss + // + action = new KAction( ac, 'emboss_action' ); + action.text = '&Emboss'; + action.icon = 'imageeffect'; + + mw.apply_emboss = function() + { + this.img = this.imgfx.emboss(this.img); + this.update_view(); + } + + action.connect( action, 'activated()', mw, 'apply_emboss' ); + this.add_action( action ); + + // + // Normalize + // + action = new KAction( ac, 'normalize_action' ); + action.text = '&Normalize'; + action.icon = 'imageeffect'; + + mw.apply_normalize = function() + { + this.img = this.imgfx.normalize(this.img); + this.update_view(); + } + + action.connect( action, 'activated()', mw, 'apply_normalize' ); + this.add_action( action ); + + // + // Equalize + // + action = new KAction( ac, 'equalize_action' ); + action.text = 'Equa&lize'; + action.icon = 'imageeffect'; + + mw.apply_equalize = function() + { + this.img = this.imgfx.equalize(this.img); + this.update_view(); + } + + action.connect( action, 'activated()', mw, 'apply_equalize' ); + this.add_action( action ); + + // + // Despeckle + // + action = new KAction( ac, 'despeckle_action' ); + action.text = '&Despeckle'; + action.icon = 'imageeffect'; + + mw.apply_despeckle = function() + { + this.img = this.imgfx.despeckle(this.img); + this.update_view(); + } + + action.connect( action, 'activated()', mw, 'apply_despeckle' ); + this.add_action( action ); +} + +mw.create_image_operations = function( mw, ac ) +{ + var action; + + // + // Crop + // + action = new KAction( ac, 'crop_action' ); + action.text = 'Crop...'; + action.icon = 'crop'; + + mw.crop_image = function() + { + lbl.mousePressEvent = function(ev) + { + lbl.startx = ev.x; + lbl.starty = ev.y; + lbl.lastx = ev.x; + lbl.lasty = ev.y; + } + + lbl.mouseMoveEvent = function(ev) + { + if ( + ( Math.abs( lbl.lastx - ev.x ) > 2 ) + || ( Math.abs( lbl.lasty - ev.y ) > 2 ) + ) { + this.repaint4( Math.min( lbl.lastx, lbl.startx ), + Math.min( lbl.lasty, lbl.starty ), + Math.abs( lbl.lastx - lbl.startx ), + Math.abs( lbl.lasty - lbl.starty ) ); + + this.drawLine( ev.x, ev.y, ev.x, lbl.starty ); + this.drawLine( ev.x, lbl.starty, lbl.startx, lbl.starty ); + this.drawLine( lbl.startx, lbl.starty, lbl.startx, ev.y ); + this.drawLine( lbl.startx, ev.y, ev.x, ev.y ); + lbl.lastx = ev.x; + lbl.lasty = ev.y; + } + } + + lbl.mouseReleaseEvent = function(ev) + { + lbl.mousePressEvent = function(ev) {}; + lbl.mouseMoveEvent = function(ev) {}; + lbl.mouseReleaseEvent = function(ev) {}; + + var pix = new Pixmap(); + var w = Math.abs( ev.x - lbl.startx ); + var h = Math.abs( ev.y - lbl.starty ); + pix.resize( w, h ); + +// var p = new Painter(); +// p.setDevice( lbl ); +// p.drawRect( w/2, h/2, w/4, h/4 ); + + mw.img.setPixmap( pix ); + mw.update_view(); + +// var pix = lbl.pixmap; +// pix.resize( Math.abs( ev.x - lbl.startx ), Math.abs( ev.y - lbl.starty ) ); +// mw.img.setPixmap( pix ); +// mw.update_view(); + } + + } + + action.connect( action, 'activated()', this, 'crop_image' ); + + // + // Resize + // + action = new KAction( ac, 'resize_action' ); + action.text = 'Resize...'; + action.icon = 'transform'; + + mw.resize_image = function() + { + var dlg = Factory.loadui( 'resizeparams.ui', null, this ); + if ( !dlg.exec() ) { + return; + } + this.img.smoothScale( dlg.child('width_input').value, + dlg.child('height_input').value ); + this.update_view(); + } + + action.connect( action, 'activated()', this, 'resize_image' ); + + // + // Rotate right + // + action = new KAction( ac, 'rotate_right_action' ); + action.text = 'Rotate &Right'; + action.icon = 'rotate_cw'; + + mw.apply_rotate_right = function() + { + this.img = this.imgfx.rotate( this.img, this.imgfx.Rotate90 ); + this.update_view(); + } + + action.connect( action, 'activated()', mw, 'apply_rotate_right' ); + + // + // Rotate left + // + action = new KAction( ac, 'rotate_left_action' ); + action.text = 'Rotate &Left'; + action.icon = 'rotate'; + + mw.apply_rotate_left = function() + { + this.img = this.imgfx.rotate( this.img, this.imgfx.Rotate90 ); + this.update_view(); + } + + action.connect( action, 'activated()', mw, 'apply_rotate_left' ); + + // + // Mirror Vertical + // + action = new KAction( ac, 'mirror_vertical_action' ); + action.text = 'Mirror &Vertical'; + + mw.apply_mirror_vertical = function() + { + this.img.mirror( false, true ); + this.update_view(); + } + + action.connect( action, 'activated()', mw, 'apply_mirror_vertical' ); + + // + // Mirror Horizontal + // + action = new KAction( ac, 'mirror_horizontal_action' ); + action.text = 'Mirror &Horizontal'; + + mw.apply_mirror_horizontal = function() + { + this.img.mirror( true, false ); + this.update_view(); + } + + action.connect( action, 'activated()', mw, 'apply_mirror_horizontal' ); +} diff --git a/kjsembed/docs/examples/imunge/imungeui.rc b/kjsembed/docs/examples/imunge/imungeui.rc new file mode 100644 index 00000000..4e1fc916 --- /dev/null +++ b/kjsembed/docs/examples/imunge/imungeui.rc @@ -0,0 +1,58 @@ +<!DOCTYPE kpartgui SYSTEM "kpartgui.dtd"> +<kpartgui name="imunge" version="1"> +<MenuBar> + <Menu name="file"><text>&File</text> + <Action name="save_copy_as_action" append="save_merge" /> + <Action name="file_properties_action" /> + </Menu> + <Menu name="image"><text>&Image</text> + <Action name="resize_action" /> + <Action name="crop_action" /> + <Action name="rotate_left_action" /> + <Action name="rotate_right_action" /> + <Action name="mirror_vertical_action" /> + <Action name="mirror_horizontal_action" /> + </Menu> + <Menu name="effects"><text>&Effects</text> + <Action name="browseeffects_action" /> + <Separator/> + <Action name="watercolor_action" /> + <Action name="charcoal_action" /> + <Action name="implode_action" /> + <Action name="emboss_action" /> + <Action name="normalize_action" /> + <Action name="equalize_action" /> + <Action name="despeckle_action" /> + <Action name="togray_action" /> + </Menu> + <Menu name="tools"><text>&Tools</text> + <Action name="scriptconsole_action" /> + </Menu> +</MenuBar> +<!-- +<ToolBar name="view"><text>View Toolbar</text> + <Action name="view_zoom_in"/> + <Action name="view_zoom_out"/> + <Action name="view_zoom"/> + <Separator/> + <Action name="view_actual_size"/> + <Action name="view_fit_to_page"/> +</ToolBar> +--> +<ToolBar name="operations" position="left" iconText="icontextright"><text>Operations</text> + <Action name="resize_action" /> + <Action name="crop_action" /> + <Action name="rotate_left_action" /> + <Action name="rotate_right_action" /> +</ToolBar> +<ToolBar name="effects" position="left" iconText="icontextright"><text>Effects</text> + <Action name="watercolor_action" /> + <Action name="charcoal_action" /> + <Action name="implode_action" /> + <Action name="emboss_action" /> + <Action name="normalize_action" /> + <Action name="equalize_action" /> + <Action name="despeckle_action" /> + <Action name="togray_action" /> +</ToolBar> +</kpartgui> diff --git a/kjsembed/docs/examples/imunge/resizeparams.ui b/kjsembed/docs/examples/imunge/resizeparams.ui new file mode 100644 index 00000000..fe66f437 --- /dev/null +++ b/kjsembed/docs/examples/imunge/resizeparams.ui @@ -0,0 +1,193 @@ +<!DOCTYPE UI><UI version="3.2" stdsetdef="1"> +<class>ResizeParams</class> +<widget class="QDialog"> + <property name="name"> + <cstring>ResizeParams</cstring> + </property> + <property name="geometry"> + <rect> + <x>0</x> + <y>0</y> + <width>371</width> + <height>200</height> + </rect> + </property> + <property name="caption"> + <string>Resize Image</string> + </property> + <property name="sizeGripEnabled"> + <bool>true</bool> + </property> + <grid> + <property name="name"> + <cstring>unnamed</cstring> + </property> + <widget class="KIntNumInput" row="3" column="1"> + <property name="name"> + <cstring>height_input</cstring> + </property> + </widget> + <widget class="QLabel" row="2" column="0"> + <property name="name"> + <cstring>textLabel3</cstring> + </property> + <property name="text"> + <string>Width:</string> + </property> + </widget> + <widget class="KIntNumInput" row="2" column="1"> + <property name="name"> + <cstring>width_input</cstring> + </property> + </widget> + <widget class="QLabel" row="3" column="0"> + <property name="name"> + <cstring>textLabel4</cstring> + </property> + <property name="text"> + <string>Height:</string> + </property> + </widget> + <widget class="QLabel" row="0" column="0" rowspan="1" colspan="2"> + <property name="name"> + <cstring>textLabel1</cstring> + </property> + <property name="sizePolicy"> + <sizepolicy> + <hsizetype>1</hsizetype> + <vsizetype>0</vsizetype> + <horstretch>0</horstretch> + <verstretch>0</verstretch> + </sizepolicy> + </property> + <property name="text"> + <string><h3>Resize Image</h3></string> + </property> + <property name="alignment"> + <set>AlignVCenter</set> + </property> + </widget> + <widget class="Line" row="1" column="0" rowspan="1" colspan="2"> + <property name="name"> + <cstring>line1</cstring> + </property> + <property name="sizePolicy"> + <sizepolicy> + <hsizetype>7</hsizetype> + <vsizetype>0</vsizetype> + <horstretch>0</horstretch> + <verstretch>0</verstretch> + </sizepolicy> + </property> + <property name="frameShape"> + <enum>HLine</enum> + </property> + <property name="frameShadow"> + <enum>Sunken</enum> + </property> + <property name="orientation"> + <enum>Horizontal</enum> + </property> + </widget> + <widget class="QLayoutWidget" row="4" column="0" rowspan="1" colspan="2"> + <property name="name"> + <cstring>Layout1</cstring> + </property> + <hbox> + <property name="name"> + <cstring>unnamed</cstring> + </property> + <property name="margin"> + <number>0</number> + </property> + <property name="spacing"> + <number>6</number> + </property> + <widget class="QPushButton"> + <property name="name"> + <cstring>buttonHelp</cstring> + </property> + <property name="text"> + <string>&Help</string> + </property> + <property name="accel"> + <string>F1</string> + </property> + <property name="autoDefault"> + <bool>true</bool> + </property> + </widget> + <spacer> + <property name="name"> + <cstring>Horizontal Spacing2</cstring> + </property> + <property name="orientation"> + <enum>Horizontal</enum> + </property> + <property name="sizeType"> + <enum>Expanding</enum> + </property> + <property name="sizeHint"> + <size> + <width>20</width> + <height>20</height> + </size> + </property> + </spacer> + <widget class="QPushButton"> + <property name="name"> + <cstring>buttonOk</cstring> + </property> + <property name="text"> + <string>&OK</string> + </property> + <property name="accel"> + <string></string> + </property> + <property name="autoDefault"> + <bool>true</bool> + </property> + <property name="default"> + <bool>true</bool> + </property> + </widget> + <widget class="QPushButton"> + <property name="name"> + <cstring>buttonCancel</cstring> + </property> + <property name="text"> + <string>&Cancel</string> + </property> + <property name="accel"> + <string></string> + </property> + <property name="autoDefault"> + <bool>true</bool> + </property> + </widget> + </hbox> + </widget> + </grid> +</widget> +<connections> + <connection> + <sender>buttonOk</sender> + <signal>clicked()</signal> + <receiver>ResizeParams</receiver> + <slot>accept()</slot> + </connection> + <connection> + <sender>buttonCancel</sender> + <signal>clicked()</signal> + <receiver>ResizeParams</receiver> + <slot>reject()</slot> + </connection> +</connections> +<layoutdefaults spacing="6" margin="11"/> +<includehints> + <includehint>knuminput.h</includehint> + <includehint>knuminput.h</includehint> + <includehint>knuminput.h</includehint> + <includehint>knuminput.h</includehint> +</includehints> +</UI> diff --git a/kjsembed/docs/examples/imunge/transform.png b/kjsembed/docs/examples/imunge/transform.png Binary files differnew file mode 100644 index 00000000..3a5ca2b3 --- /dev/null +++ b/kjsembed/docs/examples/imunge/transform.png diff --git a/kjsembed/docs/examples/index.html b/kjsembed/docs/examples/index.html new file mode 100644 index 00000000..bed4b787 --- /dev/null +++ b/kjsembed/docs/examples/index.html @@ -0,0 +1,121 @@ +<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN"> +<html> +<head><meta http-equiv="Content-Type" content="text/html;charset=iso-8859-1"> +<title>KJSEmbed Examples</title> +<link href="../kjsembed.css" rel="stylesheet" type="text/css"> +</head> +<body> +<h1>KJSEmbed Examples</h1> +This directory contains a number of example files that illustrate the +various features of KJSEmbed. + +<h3>Demos</h3> +<p> +This section contains examples that show how the features of KJSEmbed +can be combined to create useful tools. +</p> +<center> +<table> +<tr><td><a href="buttonmaker">ButtonMaker</a></td> +<td>An application for creating buttons for web sites.</td></tr> +<tr><td><a href="envelopemaker">EnvelopeMaker</a></td> +<td>An application for creating printed envelopes.</td></tr> +<tr><td><a href="xmlgui">xmlgui</a></td> +<td>Creates a complete KDE GUI shell using XMLGUI and KStdAction.</td></tr> +<tr><td><a href="readonlypart">readonlypart</a></td> +<td>A simple web browser that embeds KHTMLPart.</td></tr> +<tr><td><a href="readwritepart">readwritepart</a></td> +<td>Shows how to embed a read-write KPart.</td></tr> +<tr><td><a href="calc">calc</a></td> +<td>A simple calculator application.</td></tr> +<tr><td><a href="grepdialog">grepdialog</a></td> +<td>Loads .ui files to provide a GUI for grep.</td></tr> +<tr><td><a href="docviewer">docviewer</a></td> +<td>KJSEmbed documentation browser.</td></tr> +<tr><td><a href="sax">SAX</a></td> +<td>Demos that show how to use the SAX API from JS.</td></tr> +<tr><td><a href="dcop">DCOP</a></td> +<td>Using DCOP from scripts.</td></tr> +<tr><td><a href="cmdline">Command Line</a></td> +<td>An interactive command-line prompt for KJSEmbed implemented as a script.</td></tr> +</table> +</center> + +<h3>Advanced Demos</h3> +<p> +This section contains examples that illustrate some of the more +advanced features of KJSEmbed. +</p> +<center> +<table> +<tr><td><a href="htmlinfo">htmlinfo</a></td> +<td>Reports information about an HTML file.</td></tr> +<tr><td><a href="imageinfo">imageinfo</a></td> +<td>Various scripts using the Image builtin object.</td></tr> +<tr><td><a href="html2text">html2text</a></td> +<td>Uses the KParts::Plugin to extend KWrite.</td></tr> +<tr><td><a href="eventhandling">eventhandling</a></td> +<td>Two demos that show off event handling, including +the standard scribble demo.</td></tr> +<tr><td><a href="sql">SQL Support</a></td> +<td>Accessing SQL databases.</td></tr> +</table> +</center> + +<h3>Examples</h3> +<p> +This section contains examples that illustrate particular KJSEmbed +facilities. +</p> +<center> +<table> +<tr><td><a href="customwidget">customwidget</a></td> +<td>Creates a simple form directly from Javascript.</td></tr> +<tr><td><a href="treeview">treeview</a></td> +<td>Two examples that create a graphical tree. One +from a JS data structure, the other from the widget tree of a ui file.</td></tr> +<tr><td><a href="qobject-dom">qobject-dom</a></td> +<td>Illustrates the QObject DOM API.</td></tr> +<tr><td><a href="connect-cpp">connect-cpp</a></td> +<td>Connects a signal to slot.</td></tr> +<tr><td><a href="connect">connect</a></td> +<td>Connects signals of various types to JS methods.</td></tr> +<tr><td><a href="imageviewer">imageviewer</a></td> +<td>Illustrates the use of QPixmap values.</td></tr> +<tr><td><a href="netaccess">netaccess</a></td> +<td>Illustrates the bindings to KIO::NetAccess.</td></tr> +<tr><td><a href="listview">listview</a></td> +<td>Creates a simple KListView.</td></tr> +<tr><td><a href="frame">frame</a></td> +<td>Shows off QFrame support and the use of enums.</td></tr> +<tr><td><a href="timer">timer</a></td> +<td>Creates a flashing LED using QTimer.</td></tr> +<tr><td><a href="actions">Actions</a></td> +<td>A simple KAction demo.</td></tr> +<tr><td><a href="builtins">Built-In Messages</a></td> +<td>Demonstrates the built-in message dialogs.</td></tr> +<tr><td><a href="imagetweak">Image Tweak</a></td> +<td>Tweaking images.</td></tr> +<tr><td><a href="imagefun">Image Fun</a></td> +<td>More fun with images</td></tr> +<tr><td><a href="invaders">Space Invaders</a></td> +<td>A space invaders game.</td></tr> +<tr><td><a href="kjsuic">JS UIC</a></td> +<td>An easy way to deal with UI files.</td></tr> +<tr><td><a href="multifile">Multi-file Scripts</a></td> +<td>Multi-file Scripts.</td></tr> +<tr><td><a href="opaquevalues">Opaque Values</a></td> +<td>Opaque types.</td></tr> +<tr><td><a href="stdicons">Standard Icons</a></td> +<td>Loading standard icons.</td></tr> +<tr><td><a href="combobox">QComboBox</a></td> +<td>A simple demo of QComboBox.</td></tr> +<tr><td><a href="multipart">Embedding several KParts</a></td> +<td>Shows how to embed multiple parts in the same script.</td></tr> +<tr><td><a href="livedata">Writing data directly to a KPart</a></td> +<td>Shows how to send data directly to a part, rather than viewing a file.</td></tr> +</table> +</center> +<hr> +</body> +</html> diff --git a/kjsembed/docs/examples/invaders/invaders.js b/kjsembed/docs/examples/invaders/invaders.js new file mode 100755 index 00000000..55531258 --- /dev/null +++ b/kjsembed/docs/examples/invaders/invaders.js @@ -0,0 +1,282 @@ +#!/usr/bin/env kjscmd + +/* Classic space invaders. + By Ian Reinhart Geiser + + Based off of the Web based JS by Sam Dodge (nancied@mac.com) +*/ +var patno = 1; +var cr = "\r\n"; +var spcf1 = ""; +var spcf2 = ""; +var spcf3 = ""; +var hitflag = 0; +var score = 0; +var selec = 0; +var rsmiss = ""; +var timer = new QTimer(this); +timer.connect(timer, "timeout()", this, "doTurn"); + +var win = new KMainWindow(this); +var box = new QVBox(win); +var view = new QLabel(box); +//view.setMouseTracking(true); + +view.font = "courier,12,-1,5,75,0,0,0,0,0" + view.paletteBackgroundColor = "black"; +view.paletteForegroundColor = "green"; + +win.setCentralWidget(box); +win.show(); +restarter(); +view.focusPolicy = 1; +view.setFocus(); + + +view.mousePressEvent = function(ev) +{ + fire(); +} + +view.keyPressEvent = function(ev) +{ + if (ev.key == 4116) + gormax(); + if (ev.key == 4114) + golmax(); + if (ev.key == 32) + fire(); +} + +application.exec(); + +function gameBoard(arn) +{ + this.length = arn; + for (var ar1 = 0; ar1 <= arn; ar1++) { + this[ar1] = 1; + } + return this; +} + +function init() +{ + blankx = new gameBoard(63); + for (var makeblank = 0; makeblank < 63; makeblank++) { + blankx[makeblank] = ""; + for (var addBlank = 0; addBlank < makeblank; addBlank++) { + blankx[makeblank] = blankx[makeblank] + " "; + } + } + faker = new gameBoard(24); + face = new gameBoard(2); + face[1] = " <OvO> "; + face[2] = " <oVo> "; + mestotal = new gameBoard(4); + doTurn(); +} + +function restarter() +{ + inplay = 0; + blankno = 0; + totalblank = ""; + lr = 1; + lowerlf = ""; + downlf = ""; + downno = 0; + missilex = 99; + missiley = 99; + mychrx = 1; + myblank = ""; + mymove = 0; + selec = 1; + starter(); +} + +function starter() +{ + view.text = cr + cr + cr + cr + cr + cr + cr + cr + cr + cr + + " Control the ship and stop the enemy invasion!" + cr + + cr + cr + " Click to begin!"; + selec = 1; +} + +function goleft() +{ + mymove = 0; + mychrx = mychrx - 1; + if (mychrx <= 0) { + mychrx = 1; + } +} + +function goright() +{ + mymove = mychrx = mychrx + 1; + if (mychrx >= 56) { + mychrx = 55; + } +} + +function golmax() +{ + if (inplay == 1) { + mymove = -1; + } +} + +function gormax() +{ + if (inplay == 1) { + mymove = 1; + } +} + +function fire() +{ + if (inplay == 0) { + if (selec == 1) { + selec = 9; + inplay = 1; + init(); + } + } else { + if (missiley == 99) { + missiley = 18; + missilex = mychrx + 3; + } + } +} + +function gameover() +{ + score = 0; + for (var enerme = 1; enerme < 25; enerme++) { + if (faker[enerme] == 1) { + score = score + 1; + } + } + if (score == 0) { + view.text = cr + cr + cr + cr + cr + cr + cr + cr + + " Congratulations!" + cr + cr + + " YOU STOPPED THE ENEMY SQUAD!!"; + } else { + view.text = cr + cr + cr + cr + cr + cr + cr + cr + + " GAME OVER" + cr + cr + + " " + score + " INVADERS GOT THROUGH"; + } + inplay = 0; +} + +function doTurn() +{ + if (missiley != 99) { + missiley = missiley - 1; + } + if (missiley < 0) { + missiley = 99; + } + mychrx = mychrx + mymove; + if (mychrx <= 0) { + mychrx = 1; + } + if (mychrx >= 56) { + mychrx = 55; + } + blankno = blankno + lr; + totalblank = blankx[blankno]; + if (blankno >= 20) { + lr = -1; + downno = downno + 1; + blankno = 20; + } + if (blankno <= 0) { + lr = 1; + downno = downno + 1; + blankno = 0; + } + if (downno >= 12) { + gameover(); + } + downlf = ""; + for (var upperspc = 0; upperspc < downno; upperspc++) { + if (missiley == upperspc) { + downlf = downlf + blankx[missilex] + "^" + cr; + } else { + downlf = downlf + cr; + } + } + if (inplay == 1) { + patno = patno + 1; + if (patno >= 3) { + patno = 1; + } + for (var addline = 1; addline < 5; addline++) { + mestotal[addline] = totalblank; + rsmiss = ""; + if (missiley == (downno + addline * 2 - 2)) { + if (blankno <= missilex) { + hitflag = parseInt((missilex - blankno) / 7, 10); + if (hitflag < 6) { + if ((missilex - blankno - (hitflag * 7)) >= 1) { + if ((missilex - blankno - (hitflag * 7)) <= 5) { + if (faker[(addline * 6) + hitflag - 5] == + 1) { + faker[(addline * 6) + hitflag - 5] = 0; + missiley = 99; + } + } + } + } else { + if (missilex > (blankno + 42)) { + rsmiss = blankx[missilex - blankno - 42] + "^"; + } + } + } else { + mestotal[addline] = blankx[missilex] + "^"; + if (missilex < (blankno - 1)) { + mestotal[addline] = + mestotal[addline] + blankx[blankno - 1 - + missilex]; + } + } + } + for (var addfaker = 1; addfaker < 7; addfaker++) { + if (faker[(addline * 6) + addfaker - 6] == 1) { + mestotal[addline] = mestotal[addline] + face[patno]; + } else { + mestotal[addline] = mestotal[addline] + " "; + } + } + mestotal[addline] = mestotal[addline] + rsmiss; + } + spcf1 = cr; + spcf2 = cr; + spcf3 = cr; + if (missiley == (downno + 1)) { + spcf1 = blankx[missilex] + "^" + cr; + } + if (missiley == (downno + 3)) { + spcf2 = blankx[missilex] + "^" + cr; + } + if (missiley == (downno + 5)) { + spcf3 = blankx[missilex] + "^" + cr; + } + lowerlf = ""; + + for (var lowerspc = 0; lowerspc < (11 - downno); lowerspc++) { + if (missiley == (downno + 7 + lowerspc)) { + lowerlf = lowerlf + blankx[missilex] + "^" + cr; + } else { + lowerlf = lowerlf + cr; + } + } + myblank = blankx[mychrx]; + view.text = downlf + mestotal[1] + cr + spcf1 + + mestotal[2] + cr + spcf2 + mestotal[3] + cr + spcf3 + + mestotal[4] + + cr + lowerlf + myblank + "" + cr + myblank + "-<!>-"; + timer.start(250, true); + } +} diff --git a/kjsembed/docs/examples/kjsuic/kjsuic.js b/kjsembed/docs/examples/kjsuic/kjsuic.js new file mode 100644 index 00000000..f95aa5ee --- /dev/null +++ b/kjsembed/docs/examples/kjsuic/kjsuic.js @@ -0,0 +1,47 @@ +/* +* To use this fuction provide the ui file name, the parent +* that will handle the slots of the form, and the parent +* widget that will handle the UI portion. +* +* var form = kjsuic("EnvelopeMakerUI.ui", this, this); +* println(dump(form)); +* +* This will then return you a widget object that has properties +* that are the main child widgets in the UI file. So if you have +* a KLineEdit called "myLineEdit" in the UI file then there would +* be a member of the form called myLineEdit. (ex: form.myLineEdit ) +* +* If there are container widgets present then the children will show +* up as properties of those widgets. So if you have a groupbox called +* "Group" and a KLineEdit inside of it called "editor" you would address +* this as "Group.editor". +* +* An important note: Take care when using UI files with this that have +* widget names that do not conflict with current Qt properties as the Qt +* properties will take precident over the added widgets. +*/ + +function kjsuic(uifile, slotParent, parent) +{ + var widget = Factory.loadui(uifile, slotParent, parent); + var lst = widget.children(); + addChildren( widget ) + return widget; +} + +function addChildren( widget ) +{ + var lst = widget.children(); + for( var idx = 0; idx < lst.length; ++idx) + { + var str = "widget." + lst[idx] + " = widget.child('" + lst[idx] + "');"; + eval(str); + var typeName = widget.child(lst[idx]).className(); + + if( typeName == "QGroupBox" || typeName == "QButtonGroup" || typeName == "QFrame") + { + eval("addChildren( widget." + lst[idx] + ");"); + } + } +} + diff --git a/kjsembed/docs/examples/listview/listview.js b/kjsembed/docs/examples/listview/listview.js new file mode 100644 index 00000000..5bca90c5 --- /dev/null +++ b/kjsembed/docs/examples/listview/listview.js @@ -0,0 +1,22 @@ +#!/usr/bin/env kjscmd + +// Create main view +var mw = new KMainWindow(); +var box = new QVBox( mw ); +mw.setCentralWidget(box); + +var lv = new KListView( box ); + +lv.addColumn('Pix'); +lv.addColumn('One'); +lv.addColumn('Two'); +lv.addColumn('Three'); + +lv.insertItem( StdIcons.BarIcon("no"), 'Something', "Nothing", "Thing" ); +lv.insertItem( StdIcons.BarIcon("no"), 'Something', "Nothing", "Thing" ); +lv.insertItem( StdIcons.BarIcon("no"), 'Something', "Nothing", "Thing" ); +lv.insertItem( StdIcons.BarIcon("no"), 'Something', "Nothing", "Thing" ); + + +mw.show(); +application.exec(); diff --git a/kjsembed/docs/examples/livedata/livepartdata.js b/kjsembed/docs/examples/livedata/livepartdata.js new file mode 100644 index 00000000..345e84e9 --- /dev/null +++ b/kjsembed/docs/examples/livedata/livepartdata.js @@ -0,0 +1,25 @@ +#!/usr/bin/env kjscmd + +// Create the UI +var mw = new KParts_MainWindow(); +var ac = mw.actionCollection(); + +var split = new QSplitter( mw ); +mw.setCentralWidget( split ); + +var view = Factory.createROPart( "text/html", split, "html" ); + +view.openStream( 'text/html', 'file:///index.html' ); +view.writeStream( '<html><body><h1>Inserting Data Directly</h1>This shows how ' ); +view.writeStream( 'you can send data to a part directly from a script. </body></html>' ); +view.closeStream(); + +// +// Activate XMLGUI and show the window +// +StdAction.quit( mw, 'close()', mw.actionCollection() ); + +mw.resize( 700, 500 ); + +mw.show(); +application.exec(); diff --git a/kjsembed/docs/examples/madminute/configdialog.ui b/kjsembed/docs/examples/madminute/configdialog.ui new file mode 100644 index 00000000..3760c11d --- /dev/null +++ b/kjsembed/docs/examples/madminute/configdialog.ui @@ -0,0 +1,274 @@ +<!DOCTYPE UI><UI version="3.3" stdsetdef="1"> +<class>configDialog</class> +<widget class="QDialog"> + <property name="name"> + <cstring>configDialog</cstring> + </property> + <property name="geometry"> + <rect> + <x>0</x> + <y>0</y> + <width>258</width> + <height>204</height> + </rect> + </property> + <property name="caption"> + <string>Configure Mad Minute</string> + </property> + <property name="sizeGripEnabled"> + <bool>true</bool> + </property> + <property name="modal"> + <bool>true</bool> + </property> + <grid> + <property name="name"> + <cstring>unnamed</cstring> + </property> + <widget class="QLabel" row="0" column="0"> + <property name="name"> + <cstring>textLabel1</cstring> + </property> + <property name="sizePolicy"> + <sizepolicy> + <hsizetype>5</hsizetype> + <vsizetype>3</vsizetype> + <horstretch>0</horstretch> + <verstretch>0</verstretch> + </sizepolicy> + </property> + <property name="text"> + <string><H2>General Settings</H2></string> + </property> + </widget> + <widget class="Line" row="1" column="0"> + <property name="name"> + <cstring>line2</cstring> + </property> + <property name="frameShape"> + <enum>HLine</enum> + </property> + <property name="frameShadow"> + <enum>Sunken</enum> + </property> + <property name="orientation"> + <enum>Horizontal</enum> + </property> + </widget> + <widget class="QLayoutWidget" row="2" column="0"> + <property name="name"> + <cstring>layout10</cstring> + </property> + <hbox> + <property name="name"> + <cstring>unnamed</cstring> + </property> + <widget class="QLabel"> + <property name="name"> + <cstring>textLabel2</cstring> + </property> + <property name="text"> + <string>Operations:</string> + </property> + </widget> + <widget class="QCheckBox"> + <property name="name"> + <cstring>addition</cstring> + </property> + <property name="text"> + <string>Addition</string> + </property> + </widget> + <widget class="QCheckBox"> + <property name="name"> + <cstring>subtraction</cstring> + </property> + <property name="text"> + <string>Subtraction</string> + </property> + </widget> + </hbox> + </widget> + <widget class="QLayoutWidget" row="3" column="0"> + <property name="name"> + <cstring>layout11</cstring> + </property> + <hbox> + <property name="name"> + <cstring>unnamed</cstring> + </property> + <widget class="QLabel"> + <property name="name"> + <cstring>textLabel3</cstring> + </property> + <property name="text"> + <string>Time:</string> + </property> + </widget> + <widget class="QSpinBox"> + <property name="name"> + <cstring>time</cstring> + </property> + <property name="suffix"> + <string> seconds</string> + </property> + <property name="maxValue"> + <number>120</number> + </property> + <property name="minValue"> + <number>30</number> + </property> + <property name="value"> + <number>30</number> + </property> + </widget> + </hbox> + </widget> + <widget class="QLayoutWidget" row="6" column="0"> + <property name="name"> + <cstring>Layout1</cstring> + </property> + <hbox> + <property name="name"> + <cstring>unnamed</cstring> + </property> + <property name="margin"> + <number>0</number> + </property> + <property name="spacing"> + <number>6</number> + </property> + <widget class="QPushButton"> + <property name="name"> + <cstring>buttonHelp</cstring> + </property> + <property name="text"> + <string>&Help</string> + </property> + <property name="accel"> + <string>F1</string> + </property> + <property name="autoDefault"> + <bool>true</bool> + </property> + </widget> + <spacer> + <property name="name"> + <cstring>Horizontal Spacing2</cstring> + </property> + <property name="orientation"> + <enum>Horizontal</enum> + </property> + <property name="sizeType"> + <enum>Expanding</enum> + </property> + <property name="sizeHint"> + <size> + <width>20</width> + <height>20</height> + </size> + </property> + </spacer> + <widget class="QPushButton"> + <property name="name"> + <cstring>buttonOk</cstring> + </property> + <property name="text"> + <string>&OK</string> + </property> + <property name="accel"> + <string></string> + </property> + <property name="autoDefault"> + <bool>true</bool> + </property> + <property name="default"> + <bool>true</bool> + </property> + </widget> + <widget class="QPushButton"> + <property name="name"> + <cstring>buttonCancel</cstring> + </property> + <property name="text"> + <string>&Cancel</string> + </property> + <property name="accel"> + <string></string> + </property> + <property name="autoDefault"> + <bool>true</bool> + </property> + </widget> + </hbox> + </widget> + <widget class="QLayoutWidget" row="4" column="0"> + <property name="name"> + <cstring>layout10</cstring> + </property> + <hbox> + <property name="name"> + <cstring>unnamed</cstring> + </property> + </hbox> + </widget> + <widget class="QLayoutWidget" row="5" column="0"> + <property name="name"> + <cstring>layout11</cstring> + </property> + <hbox> + <property name="name"> + <cstring>unnamed</cstring> + </property> + <widget class="QLabel"> + <property name="name"> + <cstring>textLabel1_2_2</cstring> + </property> + <property name="text"> + <string>Maximum Value</string> + </property> + <property name="toolTip" stdset="0"> + <string>the maximum value the number will reach</string> + </property> + </widget> + <widget class="KIntNumInput"> + <property name="name"> + <cstring>maximum</cstring> + </property> + <property name="value"> + <number>20</number> + </property> + <property name="minValue"> + <number>5</number> + </property> + <property name="maxValue"> + <number>1000</number> + </property> + <property name="toolTip" stdset="0"> + <string>the maximum value the number will reach</string> + </property> + </widget> + </hbox> + </widget> + </grid> +</widget> +<connections> + <connection> + <sender>buttonOk</sender> + <signal>clicked()</signal> + <receiver>configDialog</receiver> + <slot>accept()</slot> + </connection> + <connection> + <sender>buttonCancel</sender> + <signal>clicked()</signal> + <receiver>configDialog</receiver> + <slot>reject()</slot> + </connection> +</connections> +<layoutdefaults spacing="6" margin="11"/> +<includehints> + <includehint>knuminput.h</includehint> + <includehint>knuminput.h</includehint> +</includehints> +</UI> diff --git a/kjsembed/docs/examples/madminute/helpdialog.ui b/kjsembed/docs/examples/madminute/helpdialog.ui new file mode 100644 index 00000000..baa1a4e4 --- /dev/null +++ b/kjsembed/docs/examples/madminute/helpdialog.ui @@ -0,0 +1,85 @@ +<!DOCTYPE UI><UI version="3.3" stdsetdef="1"> +<class>helpDialog</class> +<widget class="QDialog"> + <property name="name"> + <cstring>helpDialog</cstring> + </property> + <property name="geometry"> + <rect> + <x>0</x> + <y>0</y> + <width>343</width> + <height>398</height> + </rect> + </property> + <property name="caption"> + <string>Help Using MadMinute</string> + </property> + <property name="sizeGripEnabled"> + <bool>true</bool> + </property> + <property name="modal"> + <bool>true</bool> + </property> + <vbox> + <property name="name"> + <cstring>unnamed</cstring> + </property> + <widget class="QTextBrowser"> + <property name="name"> + <cstring>helpText</cstring> + </property> + <property name="text"> + <string><h2>Mad Minute</h2> +This is a small mathdrill program to help students become faster at simple addition and subtraction. To configure the application select the "<b>Preferences</b>" and set the time of the drill and the types of problems that are covered. Currently addition and subtraction are covered. + +Once the application is configured the student can start the drill by pressing the "<b>Go</b>" button or "<tt>Ctrl+G</tt>". Once the drill is started the student may answer the questions as fast as they can and press the "<tt>Enter</tt> key to submit the answer. The drill will notify the student when it is complete.</string> + </property> + </widget> + <widget class="QLayoutWidget"> + <property name="name"> + <cstring>layout9</cstring> + </property> + <hbox> + <property name="name"> + <cstring>unnamed</cstring> + </property> + <spacer> + <property name="name"> + <cstring>spacer4</cstring> + </property> + <property name="orientation"> + <enum>Horizontal</enum> + </property> + <property name="sizeType"> + <enum>Expanding</enum> + </property> + <property name="sizeHint"> + <size> + <width>221</width> + <height>20</height> + </size> + </property> + </spacer> + <widget class="QPushButton"> + <property name="name"> + <cstring>pushButton7</cstring> + </property> + <property name="text"> + <string>&OK</string> + </property> + </widget> + </hbox> + </widget> + </vbox> +</widget> +<connections> + <connection> + <sender>pushButton7</sender> + <signal>clicked()</signal> + <receiver>helpDialog</receiver> + <slot>accept()</slot> + </connection> +</connections> +<layoutdefaults spacing="6" margin="11"/> +</UI> diff --git a/kjsembed/docs/examples/madminute/madminute.js b/kjsembed/docs/examples/madminute/madminute.js new file mode 100755 index 00000000..a2762cde --- /dev/null +++ b/kjsembed/docs/examples/madminute/madminute.js @@ -0,0 +1,161 @@ +#!/usr/bin/env kjscmd + +StdDirs.addResourceType("madminute", StdDirs.kde_default("data") + "/madminute"); +try { + //var view = Factory.loadui( StdDirs.findResource("madminute", "madminute.ui"), this, mw ); + var view = Factory.loadui( "madminute.ui" ); + +} catch( err ) { + alert( err ); + exit(0); +} +var Addition = 1; +var Subtraction = 2; + +var config = new Config("madminute"); +config.setGroup("Game Options"); +// Timer +var timer = new QTimer(this); +// Current Argument 1 +var arg1 = 0; +// Current Argument 2 +var arg2 = 0; +// Current Operation +var operation = Addition; +// Acceptable operations 1 = Addition 2 = Subtraction 3 = Both +var operations = config.readNumEntry("Operations", Addition); +// Time to run the drill +var drillTime = config.readNumEntry("Drill Time", 60); +// maxInput is maximum value for the numbers in the question +var maxInput = config.readNumEntry("Maximum Input", 10); +var total = 0; + +view.connect(view.fileExitAction, 'activated()', application, 'quit()'); +view.connect(view.fileGoAction, 'activated()', this, 'start'); +view.connect(view.editPreferencesAction, 'activated()', this, 'configure'); +view.connect(view.helpAboutAction, 'activated()', this, 'about'); +view.connect(view.helpHelpAction, 'activated()', this, 'helpDialog'); + + +view.connect( view.qt_central_widget.answer, 'returnPressed()', this, 'checkAnswer' ); +view.connect( timer, 'timeout()', this, 'countdown'); + +view.qt_central_widget.answer.enabled = false; + +view.show(); +// Run the main event loop. +application.exec(); + +function configure() +{ + //var configUI = Factory.loadui( StdDirs.findResource("madminute", "configdialog.ui"), this, mw ); + var configUI = Factory.loadui( "configdialog.ui" ); + configUI.connect( configUI.buttonHelp, 'clicked()', this, 'helpDialog'); + configUI.addition.checked = false; + configUI.subtraction.checked == false; + configUI.time.value = drillTime; + configUI.maximum.value = maxInput; + if( operations == 1 ) + configUI.addition.checked = true; + if( operations == 2 ) + configUI.subtraction.checked = true; + if( operations == 3 ) + { + configUI.addition.checked = true; + configUI.subtraction.checked = true; + } + + if ( configUI.exec() == 1 ) + { + operations = 0; + if( configUI.addition.checked == true ) + operations += 1; + if( configUI.subtraction.checked == true ) + operations += 2; + drillTime = configUI.time.value; + maxInput = configUI.maximum.value; + config.setGroup("Game Options"); + config.writeNumEntry("Operations",operations); + config.writeNumEntry("Drill Time", drillTime ); + config.writeNumEntry("Maximum Input", maxInput ); + config.sync(); + } +} + +function about() +{ + alert("<h2>MadMinute 1.0</h2>A math tutoring drill to help students master basic math skills.<br>Copyright 2004 Ian Reinhart Geiser <a href='mailto:geiseri@kde.org'>geiseri@kde.org</a>"); +} + +function helpDialog() +{ + //var helpUI = Factory.loadui( StdDirs.findResource("madminute", "helpdialog.ui"), this, mw ); + var helpUI = Factory.loadui( "helpdialog.ui" ); + helpUI.exec(); +} + +function askQuestion() +{ + arg1 = Math.floor( Math.random() * maxInput ); + arg2 = Math.floor( Math.random() * maxInput ); + if( operations == 3 ) + operation = Math.floor( (Math.random() * 2)+1); + else + operation = operations; + + var operationText = ""; + if( operation == Addition ) + operationText = " + "; + else if( operation == Subtraction ) + { + operationText = " - "; + if( arg1 < arg2 ) + { + var arg = arg1; + arg1 = arg2; + arg2 = arg; + } + } + view.qt_central_widget.question.text = "<h2>" + arg1 + operationText + arg2 + "=</h2>"; +} + +function checkAnswer( ) +{ + var answer = 0; + if( operation == Addition ) + answer = (arg1 + arg2) ; + else if( operation == Subtraction ) + answer = (arg1 - arg2) ; + if( view.qt_central_widget.answer.text == answer ) + { + view.qt_central_widget.correct.value++; + } + total++; + askQuestion(); + view.qt_central_widget.answer.text = ""; +} + +function start() +{ + askQuestion(); + total = 0; + timer.start(1000); + view.fileGoAction.enabled = false; + view.qt_central_widget.answer.enabled = true; + view.qt_central_widget.answer.setFocus(); + view.qt_central_widget.timeleft.progress = drillTime; + view.qt_central_widget.correct.value = 0; +} + +function countdown() +{ + view.qt_central_widget.timeleft.progress--; + if( view.qt_central_widget.timeleft.progress == 0 ) + { + timer.stop(); + view.fileGoAction.enabled = true; + view.qt_central_widget.answer.enabled = false; + alert( "<h1>Times Up!</h1>You got " + view.qt_central_widget.correct.value + " out of " + total + " questions correct." ); + } +} + diff --git a/kjsembed/docs/examples/madminute/madminute.ui b/kjsembed/docs/examples/madminute/madminute.ui new file mode 100644 index 00000000..dadab4d8 --- /dev/null +++ b/kjsembed/docs/examples/madminute/madminute.ui @@ -0,0 +1,361 @@ +<!DOCTYPE UI><UI version="3.3" stdsetdef="1"> +<class>MainWindow</class> +<author>Ian Reinhart Geiser <geiseri@kde.org></author> +<widget class="QMainWindow"> + <property name="name"> + <cstring>MadMinute</cstring> + </property> + <property name="geometry"> + <rect> + <x>0</x> + <y>0</y> + <width>362</width> + <height>212</height> + </rect> + </property> + <property name="caption"> + <string>Mad Minute</string> + </property> + <vbox> + <property name="name"> + <cstring>unnamed</cstring> + </property> + <property name="margin"> + <number>3</number> + </property> + <widget class="QLayoutWidget"> + <property name="name"> + <cstring>layout8</cstring> + </property> + <hbox> + <property name="name"> + <cstring>unnamed</cstring> + </property> + <widget class="QLabel"> + <property name="name"> + <cstring>textLabel3</cstring> + </property> + <property name="sizePolicy"> + <sizepolicy> + <hsizetype>5</hsizetype> + <vsizetype>5</vsizetype> + <horstretch>1</horstretch> + <verstretch>0</verstretch> + </sizepolicy> + </property> + <property name="text"> + <string><h1>Question:</h1></string> + </property> + </widget> + </hbox> + </widget> + <widget class="Line"> + <property name="name"> + <cstring>line1</cstring> + </property> + <property name="frameShape"> + <enum>HLine</enum> + </property> + <property name="frameShadow"> + <enum>Sunken</enum> + </property> + <property name="orientation"> + <enum>Horizontal</enum> + </property> + </widget> + <widget class="QLayoutWidget"> + <property name="name"> + <cstring>layout7</cstring> + </property> + <hbox> + <property name="name"> + <cstring>unnamed</cstring> + </property> + <widget class="QLayoutWidget"> + <property name="name"> + <cstring>layout6</cstring> + </property> + <vbox> + <property name="name"> + <cstring>unnamed</cstring> + </property> + <widget class="QLayoutWidget"> + <property name="name"> + <cstring>layout5</cstring> + </property> + <hbox> + <property name="name"> + <cstring>unnamed</cstring> + </property> + <widget class="QLabel"> + <property name="name"> + <cstring>question</cstring> + </property> + <property name="sizePolicy"> + <sizepolicy> + <hsizetype>5</hsizetype> + <vsizetype>5</vsizetype> + <horstretch>1</horstretch> + <verstretch>0</verstretch> + </sizepolicy> + </property> + <property name="minimumSize"> + <size> + <width>128</width> + <height>0</height> + </size> + </property> + </widget> + <widget class="QLineEdit"> + <property name="name"> + <cstring>answer</cstring> + </property> + <property name="minimumSize"> + <size> + <width>64</width> + <height>0</height> + </size> + </property> + <property name="maxLength"> + <number>4</number> + </property> + <property name="trapEnterKeyEvent" stdset="0"> + <bool>true</bool> + </property> + </widget> + </hbox> + </widget> + <widget class="QLayoutWidget"> + <property name="name"> + <cstring>layout3</cstring> + </property> + <hbox> + <property name="name"> + <cstring>unnamed</cstring> + </property> + <widget class="QLabel"> + <property name="name"> + <cstring>textLabel1</cstring> + </property> + <property name="text"> + <string><h2>Time left:</h2></string> + </property> + <property name="alignment"> + <set>AlignVCenter</set> + </property> + </widget> + <widget class="QProgressBar"> + <property name="name"> + <cstring>timeleft</cstring> + </property> + <property name="sizePolicy"> + <sizepolicy> + <hsizetype>7</hsizetype> + <vsizetype>0</vsizetype> + <horstretch>1</horstretch> + <verstretch>0</verstretch> + </sizepolicy> + </property> + <property name="minimumSize"> + <size> + <width>256</width> + <height>0</height> + </size> + </property> + <property name="totalSteps"> + <number>60</number> + </property> + </widget> + </hbox> + </widget> + </vbox> + </widget> + </hbox> + </widget> + <widget class="QLayoutWidget"> + <property name="name"> + <cstring>layout6_2</cstring> + </property> + <hbox> + <property name="name"> + <cstring>unnamed</cstring> + </property> + <widget class="QLabel"> + <property name="name"> + <cstring>textLabel1_2</cstring> + </property> + <property name="text"> + <string><h2>Correct answers:</h2></string> + </property> + <property name="alignment"> + <set>AlignVCenter</set> + </property> + </widget> + <spacer> + <property name="name"> + <cstring>spacer1</cstring> + </property> + <property name="orientation"> + <enum>Horizontal</enum> + </property> + <property name="sizeType"> + <enum>Expanding</enum> + </property> + <property name="sizeHint"> + <size> + <width>51</width> + <height>20</height> + </size> + </property> + </spacer> + <widget class="QLCDNumber"> + <property name="name"> + <cstring>correct</cstring> + </property> + <property name="frameShadow"> + <enum>Plain</enum> + </property> + <property name="lineWidth"> + <number>0</number> + </property> + <property name="numDigits"> + <number>2</number> + </property> + <property name="segmentStyle"> + <enum>Flat</enum> + </property> + </widget> + </hbox> + </widget> + </vbox> +</widget> +<menubar> + <property name="name"> + <cstring>MenuBar</cstring> + </property> + <item text="&File" name="fileMenu"> + <action name="fileGoAction"/> + <separator/> + <action name="fileExitAction"/> + </item> + <item text="&Edit" name="Edit"> + <action name="editPreferencesAction"/> + </item> + <item text="&Help" name="helpMenu"> + <action name="helpHelpAction"/> + <separator/> + <action name="helpAboutAction"/> + </item> +</menubar> +<toolbars> + <toolbar dock="2"> + <property name="name"> + <cstring>toolBar</cstring> + </property> + <property name="label"> + <string>Tools</string> + </property> + <action name="fileGoAction"/> + <action name="fileExitAction"/> + </toolbar> +</toolbars> +<actions> + <action> + <property name="name"> + <cstring>fileGoAction</cstring> + </property> + <property name="iconSet"> + <iconset>image0</iconset> + </property> + <property name="text"> + <string>Go...</string> + </property> + <property name="menuText"> + <string>&Go...</string> + </property> + <property name="accel"> + <string>Ctrl+G</string> + </property> + </action> + <action> + <property name="name"> + <cstring>fileExitAction</cstring> + </property> + <property name="iconSet"> + <iconset>image1</iconset> + </property> + <property name="text"> + <string>Exit</string> + </property> + <property name="menuText"> + <string>E&xit</string> + </property> + <property name="accel"> + <string>Ctrl+Q</string> + </property> + </action> + <action> + <property name="name"> + <cstring>helpHelpAction</cstring> + </property> + <property name="iconSet"> + <iconset>image2</iconset> + </property> + <property name="text"> + <string>Help...</string> + </property> + <property name="menuText"> + <string>&Help...</string> + </property> + <property name="accel"> + <string>Ctrl+H</string> + </property> + </action> + <action> + <property name="name"> + <cstring>helpAboutAction</cstring> + </property> + <property name="text"> + <string>About</string> + </property> + <property name="menuText"> + <string>&About</string> + </property> + <property name="accel"> + <string></string> + </property> + </action> + <action> + <property name="name"> + <cstring>editPreferencesAction</cstring> + </property> + <property name="iconSet"> + <iconset>image3</iconset> + </property> + <property name="text"> + <string>&Preferences...</string> + </property> + <property name="menuText"> + <string>&Preferences...</string> + </property> + <property name="toolTip"> + <string>Preferences...</string> + </property> + </action> +</actions> +<images> + <image name="image0"> + <data format="PNG" length="1197">89504e470d0a1a0a0000000d4948445200000016000000160806000000c4b46c3b0000047449444154388d85954d881c4518869fe954c7eaa447a7704752eaae6925c2b0041dff60050dee4554f09083889780ab8778080a8a821ea3b9683cede610c82d5efc3dad62400f4bb2c2c68c1174c4153bb84baadd8ca9d6b4a97252997898cd269a44bfcb4bd55bf5f4cbd7dd5535fea3da3bbf8b75aa9aa6424bc906ef0d5a6a67bc2fa4742bf3ef8ef7afb5b7f61fd009504f81bd1ba1c60876234243c8cf825e02731cd407edb0fbf081fd07ceff2f78e2959377f8cabea853fd8c13b2d1ba3589903099810f507a389203951b748bd249c161aa7cf7643a3bffe6bb6f86ab82db3b4fde06761f327bacbdd933f58842371cd96882739024e01c1060fe84e35827e1a36f72bca72b43fe6a9b0f3f9dd93f1300d65d9e34f4ed74b6297bf4f1fb93da6b4f248c36a0797dccdb9fc0b63bc155900888fb90dd14d3ba05b25b143f9c64c4a3ee2bfacd633bb68d2ecf7d3577610ddcbcebd93dc8ece9c936b51d0fc69cea3b92f53145e978622266f727967b6e4f284a07514cfe87a3be214648c7961bebb5b91f7a37fa818a533f7b68e2de8973eb862df87a42a7a37bb68cd5e5d44331651f9a22a6fa031031ea0678783ce1b9fd30d98a31d5253f163141407a9d6271d96feec9d671d59fcfa3f6ceaf63d04f39caeb1fdf0a45652140b7e7b001f29e5d7b070777c11b1f73852f01951a5443d67de5b797b41a9196ba09feeeecd62cf2804491f74092acaafac757737017bc7368d52fc0148ae92fe148aeb141453acdc62d7a2c32de689063307c72b7584d5c9855b5fcbb0eee82e939c82b98ed3af21e747b8004e38d46e8b1484abd016137660db596b0a8a021f4aaaa2bc017e19d1c20c1035a0ee7659a25045b8fbc3780a6dbb370063ac66081ee298bb3f051d75d157c119e572001e387ea2b0342459196da11fc5950cc97e0bca6b30879a9985d0642724df0e45ba053f0805c552d952798bf2253990258eaf61cd643b704ef212f879b8dbf369400a6022918523d98caac24c82292a95c01735c8b64908861020464e9f02fbbd8bb2b92caa19f3556d7a540700399ca1f1ba163a2e1d1a73e30e5f7bfcb00e0d8945ea6e29f3d9e9a7164abf39b1a97d69595055ffe49d93dd410f674043011de3e2c857adf96965623414968e9a1b6472ef5f8e5030cfd14da97f94a800be07dfec564a3730438b30e60e1d8c285e6d6ed3ffb10b74a6f6e7b6024ad55f490a24ec0f0f0d63abbdf336b63adea546e38ae826171390c8ae5ee518dd947bff39d409c593b84a6b6e9df967c76d4d31c5f2ecde62d37dd8e486054d5f9fcdba1d62e805675ac87d17a9d133dc7a902ba27f3a3edf54b7b46c2170bcdb4d9db3bbdf7fc1a78eeabb90b4fde2b4e17fdb453f66fdeb0b86236fbb3627d1814b54c29cab396469a602a4369030b3f1583c55f42756265f1333d58da9786d9058158d93bbdf71c5ce50679fda5d7235bd98d9d746ad27bbf5dcb6cdc78af1b2332a13224427b53fa1599ba1f65d53df460da39622bfbab4a5579cd1be462bdf0fc0b358f5f5fd26ad8a0c7907a8c60eb081511cc5f09b290a16336097bdae3cf48a49bd93f33b89cf1376f8d272940ee2b7c0000000049454e44ae426082</data> + </image> + <image name="image1"> + <data format="PNG" length="1290">89504e470d0a1a0a0000000d4948445200000016000000160806000000c4b46c3b000004d149444154388dad95c18b1cc715c67fdd5b0bd5a637a98e6760ca48ce1644c42d2c875d64889428209dec0d092822979890201d0c91738a6fc644b6ff053be0837d11f6c1b0ca21201f1c5660c752b08c56b0e016ec921a7616aad10e9e22db680aa999f2a1676d27b9a62e4555bdfaea7bef7daf1e742391b0c0ff61cc7192e41018881795fc8911bca895320e1ecdf7d1802374d7da801612db06a490d086a8918b2e786b036fbfebc3a787c00910dfecc93faf3d65aea8f3bf8952789083046f4119fe63ce35d65b4c6e08de2295c67a1b8ba00837ae27d777ea2b2f8dc36b09c01f94fce90b4f9b4fca5f5f9e55f546d4f5044bc0088915605ab06d6000d4024c5ee00468240e30025c2e290289fdf066babe539f5900f8a5126fac5dbafca3eafee64c6ded2fb4d127fdef88d4febb490714e9e2638ba979662d6d9ed0e989232b693b1ea6593a4d5d9ba4e67b47d2f0a0490ad94bf72533f3b849b7ef6d0901a073f5a4171e5d3b6ce6a3c965627da01c18e4f98b14277f0e1914f38464072fe33e5fc77cf43ed60f31522536d4d1088913012de593298083389003a6044c4f263604564eaea15f5da738d3813299c2a68529b004faec05f41fd729974f7561536582901835c0411487aab0de920989f59e72b9a4f8ed652860ba7d87f0e1fb54c30a932b5c1b289f5a217bfe12688dfcc50b98ab16d758b494d87a0890a487fa33cae0040c728d3eff0af4355477f057dfc2dddde0f4f93fa15f7f8f72658dfa9fd799fcf51d3880eca8419f5a43e7ba4ba45a8616d2439d5a6f512d0425e1d9e3004cfef60e555d9129cd444c01a84540f634d5ce2df8c77ac7eae4055c3b99e30cd1cc81dd9c3121503e7dae331e4df03b15e591151c50e4a6f32c5fc6b6600625936ae3eb722b8f9dfee6fc1098396304d830e9d88e2b20609b1a0d4c1adbd935c34eb78d0360baef6011ea03074262fd10f96d6093ebb9f83500c5a0c449d97922a05073c66a1990e89ec1898cacafe11198bee93ccf07c07fc5d848891ddeec5ed205e50f56b1e30a291593a606c0353548891d571c2f4f75b62d7c31dac4e419d6db6fc5b80d98dc802cc8bc85ea4ec7faf95730474a6ce329a4eade930adb7856ca73f0e30b1df0ce065a0e4048746eb084eeab3cd753bfd73fec2f2fcd421c3d08695e8fc89e390dba40f47a148da7babb81dcdaa6dabdc5896757c87ef63bf86ec674dfd1def880d12cb08489a37b1fa7f65fe36157206d884669366b8f1994f87a88fcfb35b2e72e911d5b255b5ea568a6505714cb2f7795083081ecf30d262d185d62f72d5a69427babab3c8d4cacb718c0fa3a9a5c259bb7af51ba0acefc8ae2c469283228560f73cd646b03b979131b02461aec818b5a40b56731422602c005bf5b04052a605a99b8e0a3e9ad24616ce1a36b7cf1c9358e9767a1a9410d98da4d4012da80d1251cb8785c97c964eb066adfe15a7617004a21c647bdbb987d5fb32fc24c43740f7d5c9232ba5988fd87216eef6e46be74717baf8a4b24d1cddab8949a387a308a196dac76efc5706323a98775f259135e5a0092dba1dd5d7d18c8c793b347fbc712d93649f1582f1ddddf4b8de8a5ed782feda7836e3dcbd3b05ba55923d2d1cec769df87b4b97b3be1f66749bde7d3eacbf6ca6bf79babffdbf3242f6a298d6d7924054968e9624f402209040cdff4bcd08668845c746db0aee5edbf8cbb9ef715f3313f39c80fcae40000000049454e44ae426082</data> + </image> + <image name="image2"> + <data format="PNG" length="1007">89504e470d0a1a0a0000000d4948445200000016000000160806000000c4b46c3b000003b649444154388d8d953d681c4714c77f7bec89397bc5ed9215dc1611b790e6440acba4c885a4f0419a54c2e9ae9555b870a5ca10630c6e84102e4c70714e6975318210a7085c29a508da26f80409ec2104bbe01337426bef200d6c8ad9b53e1239996678efddfce777f33ed6e23f567fad10b1c4c7c54142e090c59249b46ea90f9db3ae0a741f142eb084a607cc034d00a539c2661fcd10d88ad62df9bf846fad158ecae8872eab52d1eeb6a953c7faa20d49066818fe4981e6343a608cc386926c8e9e58d995c2b71e144d058f84cd4aa7c5b5e5af4038b0d082d729840ec4192cf8b0fd176c47f0728f77523140f370f4d43afa877049fab8e373b71332b3fca5210c04080d8d003805ea308d41f8104b485378fc1327293c43f2dde8a921af55c22aa32f6cee840133cb9f9b439e0dc22d4531a2005e080a7369cb87d5af99118a3b40bfd2ab55890a5d56439febb73f8391040f087c68d40d697e6c48392dc567cdc59e80860bb76f701d586ddf2fdcf3c44b4946bbd78178020248d419e13483e11ec41a7efcfd5c523cd84dcdefa9832b682bc91240adbf560834bd9b2dea4a1b8a510a8173767eb877e6f76c202f03c7e68d5fec80ca01415d38f4da770b61c7121f984f145657409442cb81577fc06266c45cdbf83b3e84ad1c1a0d00b6c7f06a6488d30c3c8115a7cc0b1bbf868b03343b3e8c2646a4da877ba6222abbd786f063239abc811f7620744d22431784497653691c5b4d8c239e40c785ed29346c88a6d0b28dedd9b07823873923fa3a868d5f40298831c471d97faadc6ba1cbb1d21c79024665dd4e33704bdbb3c19d8585f08cf4fb5f4d35601bd26a571a84c311705c8b2587d8ecef4e28c0fcedf7bb362481037999b017bf19d2a46ce0242bab2883a9a25019fbc0612d5ab7149a616073aa7449c04592288174023f47e6b2ca2fce133b20334e85c3301d58aaaae3add184b1d2305520044c357484b1d1b07b90130890f9a5b836769442ae18ab8cadf70d12ad5b12878d64c2dbd033efb7300752c042008b217cdb6d70b303fdeea5f81ca02051bc559a8d7460c6e8d9ac906c4ac5f3971127ae369d27e60c71e8425eb6722c219c2be31ec46f7276c69c2429cf81cd4aefc2d8ecdc2b9ab83c72352bdf7cca35d180d037c5dffda44c9832890d040c471049de25070c84c3c3f1937f199bd56adf2b1ca0df80d5964fbbe34feb41e859429b048d929c44368ae8203f4d6463ac341bc0663af8c0a0bf70c1fdc245b284434f65cc0b87a692a64e55c6be7018aa8cadea4d2faf2b85abd55a2984b0f94869664bd73170980e3efc31fd1b46ffa51cb01b5f6d0000000049454e44ae426082</data> + </image> + <image name="image3"> + <data format="PNG" length="919">89504e470d0a1a0a0000000d4948445200000016000000160806000000c4b46c3b0000035e49444154388da5d44f681c6518c7f16fea56de815978a7a430537621532874da0ab341a18d14760b1e62f06229825ea2e2a182f4d22292830d45a4e45082b908896b21a71a8dc89a43211921261121c922c62d1e76722899c52ebb832e9d173b301e26a5cd1fc95a7f976767e6e133ef3c0f6c0fbbb2b1bcb56e64842bfb0cfc468481a2dd505fa2337a7ae0d8e6eefeae53f96ea9dcaa3f4c76e4ef2499bfbb9aac2ed4879f190698b9335f6efdbe0b4f9264e3ee56b234572ffe2f7cfa76a5bcf54b6b0f3e7dbbe27705ccdf592d4f7e5e71f77b363955996dd577c2f59f5bc9bff53f9d43c15fc1b089e54d8c4fef689e189f761d6117456f94de789496762644c646f140d8b66c8606fb659fb4bdb19b293e7673da75f2056f60f094d4b21a44c0612002bbd7c6eff8f240b816f8908753e76c696179374627871d697bce594b6240bb1d81f6a42effba8c8aadcd83e08c8c8d9007483b67110d4a69dd93e50b2ff683041e80a16b3b2a6d81ead40e849fcb9fe83f993b9a77e3e7638e9b5944af207b4423680564f52c41ab4d56d7f0ff08507fc6284dd1a9c7eec41bebdaa74347ef7d32d754fb8ec214e6e817b3df842216444db084b15dad27d70d2014b41b0a5bb7289d9c73ed13f62d62bc8753851df34e924402f400bcffde988bc07bf7b58b5298604b1bbfe363eb69b532267ed34f17b7721527f6089b01d6799bb54555b5a174e4c35af8f40b7a1eff18b93ce9fa1dff56a1af505442e19836b5fb352c61f26a69009933a87957710eafa105ebe90e3ac00b03048b7e155d948e5d590ff7c08ff3faa5913e81d5a7088a027e5020cf9985f280bb200bb187ca041842000a1044b142cb5b2c78546d281dbf919e7c0fbc5f66ae15ae5f38637d6c64d7a0574047812ed213eb405381eef09bd7a8a2533a3d520bbb82373e72a41fe30d9570d123901a84a4e36846291e02b1c6f71e550b4a5dc100aba38ef443bc8baf982eb93045ef2b20025f4116c8001d87af571adf760d032c7d909efcadb3b89c17d068a77810a6a3510af292b5458343ff057ef9b35a68e994a67ea44a55a69f9fdb0633db4d0202a2ee96b73b95b71db919e3bd73a6ed6a39052fd950f5d33fab18167eb2ba5bde7e99b9ecc84688f7a6db760d3d04292054ac6d9aacdcd7469f190618bbe4481e31eb64298699364219a11f337eedabdaf57f008dc09ee67a81bacc0000000049454e44ae426082</data> + </image> +</images> +<layoutdefaults spacing="6" margin="11"/> +</UI> diff --git a/kjsembed/docs/examples/multifile/multifile.js b/kjsembed/docs/examples/multifile/multifile.js new file mode 100755 index 00000000..03d7c10e --- /dev/null +++ b/kjsembed/docs/examples/multifile/multifile.js @@ -0,0 +1,10 @@ +#!/usr/bin/env kjscmd + +// Shows you how to use multiple script files. + +var a = ':-)'; + +println( 'multifile: Starting...' ); +load( 'otherfile.js' ); +println( 'multifile: Ending, ' + a ); + diff --git a/kjsembed/docs/examples/multifile/otherfile.js b/kjsembed/docs/examples/multifile/otherfile.js new file mode 100644 index 00000000..577f6598 --- /dev/null +++ b/kjsembed/docs/examples/multifile/otherfile.js @@ -0,0 +1,5 @@ +#!/usr/bin/env kjscmd + +println( 'otherfile: Hello!' ); +println( 'otherfile: ' + a ); +println( 'otherfile: Goodbye' ); diff --git a/kjsembed/docs/examples/multipart/multipart.js b/kjsembed/docs/examples/multipart/multipart.js new file mode 100644 index 00000000..89402f79 --- /dev/null +++ b/kjsembed/docs/examples/multipart/multipart.js @@ -0,0 +1,56 @@ +#!/usr/bin/env kjscmd + +// +// Example of loading several parts from a script +// + +// +// Main +// +var qd = new QDir(); + +var dir = 'file://' + qd.path() + '/../'; +var file = dir + 'index.html'; + +// Create the UI +var mw = new KParts_MainWindow(); +var ac = mw.actionCollection(); + +var split = new QSplitter( mw ); +mw.setCentralWidget( split ); + +// +// Load the sidebar +// +var side = Factory.createROPart( "inode/directory", split, "sidebar" ); + +// +// Load the views +// +var views = new QSplitter( split ); +views.orientation = 1; + +var top = Factory.createROPart( "text/html", views, "html" ); + +var bottom = Factory.createROPart( "text/plain", views, "source" ); + +// +// Glue it together +// +top.connect(side.child(0), 'openURLRequest(const KURL&,const KParts::URLArgs&)', 'openURL(const KURL&)' ) +bottom.connect(side.child(0), 'openURLRequest(const KURL&,const KParts::URLArgs&)', 'openURL(const KURL&)' ) + +side.openURL( dir ); +top.openURL( file ); +bottom.openURL( file ); + +// +// Activate XMLGUI and show the window +// +StdAction.quit( mw, 'close()', mw.actionCollection() ); + +mw.resize( 700, 500 ); +split.child(1).maximumWidth = 200; + +mw.show(); +application.exec(); diff --git a/kjsembed/docs/examples/netaccess/net.js b/kjsembed/docs/examples/netaccess/net.js new file mode 100755 index 00000000..c406d79b --- /dev/null +++ b/kjsembed/docs/examples/netaccess/net.js @@ -0,0 +1,24 @@ +#!/usr/bin/env kjscmd + +var net = new NetAccess( null, 'net' ); + +var loc = '/tmp/test.jpg'; + +var ret = net.download( 'http://www.kde.org/media/images/kde_logo.jpg', loc ); + +if ( ret ) { + var mime = net.mimetype( loc ); + print( "Mimetype = " + mime + '\n' ); + var img = new Image(); + img.load( loc ); + if ( !img.isOk() ) { + warn( 'Failed to load image '+loc); + } else { + print( 'Image ' + loc + ' is OK \n' ); + var lbl = new QLabel(); + lbl.pixmap = img.pixmap(); + lbl.show(); + application.exec(); + } +} +net.del( loc ); diff --git a/kjsembed/docs/examples/opaquevalues/opaque.js b/kjsembed/docs/examples/opaquevalues/opaque.js new file mode 100755 index 00000000..f92fb6f2 --- /dev/null +++ b/kjsembed/docs/examples/opaquevalues/opaque.js @@ -0,0 +1,26 @@ +#!/usr/bin/env kjscmd + +// Usage: kjscmd --noexec opaque.js 2>/dev/null + +// +// Test QVariant support +// + +var w = new QLabel(); +w.text = 'Test'; + +var sp = w.sizePolicy; +println(sp); + +var cr = w.childrenRegion; +println(cr); + +// +// Test void * support +// + +var view = part.view(); +println(view); +println(dump(view)); + +application.quit(); diff --git a/kjsembed/docs/examples/qdocviewer/docviewer.ui b/kjsembed/docs/examples/qdocviewer/docviewer.ui new file mode 100755 index 00000000..33db5ff2 --- /dev/null +++ b/kjsembed/docs/examples/qdocviewer/docviewer.ui @@ -0,0 +1,523 @@ +<!DOCTYPE UI><UI version="3.3" stdsetdef="1"> +<class>HelpUI</class> +<widget class="QMainWindow"> + <property name="name"> + <cstring>Form1</cstring> + </property> + <property name="geometry"> + <rect> + <x>0</x> + <y>0</y> + <width>760</width> + <height>471</height> + </rect> + </property> + <grid> + <property name="name"> + <cstring>unnamed</cstring> + </property> + <property name="margin"> + <number>3</number> + </property> + <property name="spacing"> + <number>2</number> + </property> + <widget class="QLayoutWidget" row="0" column="0"> + <property name="name"> + <cstring>layout1</cstring> + </property> + <hbox> + <property name="name"> + <cstring>unnamed</cstring> + </property> + <widget class="QToolBox"> + <property name="name"> + <cstring>Navbar</cstring> + </property> + <property name="currentIndex"> + <number>5</number> + </property> + <widget class="QWidget"> + <property name="name"> + <cstring>StaticObjects</cstring> + </property> + <property name="backgroundMode"> + <enum>PaletteBackground</enum> + </property> + <attribute name="label"> + <string>Static Objects</string> + </attribute> + <grid> + <property name="name"> + <cstring>unnamed</cstring> + </property> + <property name="margin"> + <number>1</number> + </property> + <property name="spacing"> + <number>1</number> + </property> + <widget class="QListBox" row="0" column="0"> + <item> + <property name="text"> + <string>New Item</string> + </property> + </item> + <property name="name"> + <cstring>StaticObjectList</cstring> + </property> + </widget> + </grid> + </widget> + <widget class="QWidget"> + <property name="name"> + <cstring>ObjectTypes</cstring> + </property> + <property name="backgroundMode"> + <enum>PaletteBackground</enum> + </property> + <attribute name="label"> + <string>Object Types</string> + </attribute> + <grid> + <property name="name"> + <cstring>unnamed</cstring> + </property> + <property name="margin"> + <number>1</number> + </property> + <property name="spacing"> + <number>1</number> + </property> + <widget class="QListBox" row="0" column="0"> + <item> + <property name="text"> + <string>New Item</string> + </property> + </item> + <property name="name"> + <cstring>ObjectTypeList</cstring> + </property> + </widget> + </grid> + </widget> + <widget class="QWidget"> + <property name="name"> + <cstring>KJSEmbedObjects</cstring> + </property> + <property name="backgroundMode"> + <enum>PaletteBackground</enum> + </property> + <attribute name="label"> + <string>KJSEmbed Objects</string> + </attribute> + <grid> + <property name="name"> + <cstring>unnamed</cstring> + </property> + <property name="margin"> + <number>1</number> + </property> + <property name="spacing"> + <number>1</number> + </property> + <widget class="QListBox" row="0" column="0"> + <item> + <property name="text"> + <string>New Item</string> + </property> + </item> + <property name="name"> + <cstring>KJSEmbedObjectList</cstring> + </property> + </widget> + </grid> + </widget> + <widget class="QWidget"> + <property name="name"> + <cstring>QtObjects</cstring> + </property> + <property name="backgroundMode"> + <enum>PaletteBackground</enum> + </property> + <attribute name="label"> + <string>Qt Objects</string> + </attribute> + <grid> + <property name="name"> + <cstring>unnamed</cstring> + </property> + <property name="margin"> + <number>1</number> + </property> + <property name="spacing"> + <number>1</number> + </property> + <widget class="QListBox" row="0" column="0"> + <item> + <property name="text"> + <string>New Item</string> + </property> + </item> + <property name="name"> + <cstring>QtObjectList</cstring> + </property> + </widget> + </grid> + </widget> + <widget class="QWidget"> + <property name="name"> + <cstring>KDEObjects</cstring> + </property> + <property name="backgroundMode"> + <enum>PaletteBackground</enum> + </property> + <attribute name="label"> + <string>KDE Objects</string> + </attribute> + <grid> + <property name="name"> + <cstring>unnamed</cstring> + </property> + <property name="margin"> + <number>1</number> + </property> + <property name="spacing"> + <number>1</number> + </property> + <widget class="QListBox" row="0" column="0"> + <item> + <property name="text"> + <string>New Item</string> + </property> + </item> + <property name="name"> + <cstring>KDEObjectList</cstring> + </property> + </widget> + </grid> + </widget> + <widget class="QWidget"> + <property name="name"> + <cstring>ExceptionTypes</cstring> + </property> + <property name="backgroundMode"> + <enum>PaletteBackground</enum> + </property> + <attribute name="label"> + <string>Exception Types</string> + </attribute> + <grid> + <property name="name"> + <cstring>unnamed</cstring> + </property> + <property name="margin"> + <number>1</number> + </property> + <property name="spacing"> + <number>1</number> + </property> + <widget class="QListBox" row="0" column="0"> + <item> + <property name="text"> + <string>New Item</string> + </property> + </item> + <property name="name"> + <cstring>ExceptionTypeList</cstring> + </property> + </widget> + </grid> + </widget> + <widget class="QWidget"> + <property name="name"> + <cstring>UnconstructableTypes</cstring> + </property> + <property name="backgroundMode"> + <enum>PaletteBackground</enum> + </property> + <attribute name="label"> + <string>Unconstructable Types</string> + </attribute> + <grid> + <property name="name"> + <cstring>unnamed</cstring> + </property> + <property name="margin"> + <number>1</number> + </property> + <property name="spacing"> + <number>1</number> + </property> + <widget class="QListBox" row="0" column="0"> + <item> + <property name="text"> + <string>New Item</string> + </property> + </item> + <property name="name"> + <cstring>UnconstructableTypeList</cstring> + </property> + </widget> + </grid> + </widget> + <widget class="QWidget"> + <property name="name"> + <cstring>Search</cstring> + </property> + <property name="backgroundMode"> + <enum>PaletteBackground</enum> + </property> + <attribute name="label"> + <string>Search</string> + </attribute> + <vbox> + <property name="name"> + <cstring>unnamed</cstring> + </property> + <property name="margin"> + <number>4</number> + </property> + <property name="spacing"> + <number>2</number> + </property> + <widget class="QLayoutWidget"> + <property name="name"> + <cstring>layout2</cstring> + </property> + <hbox> + <property name="name"> + <cstring>unnamed</cstring> + </property> + <widget class="QLineEdit"> + <property name="name"> + <cstring>SearchLine</cstring> + </property> + <property name="sizePolicy"> + <sizepolicy> + <hsizetype>7</hsizetype> + <vsizetype>0</vsizetype> + <horstretch>1</horstretch> + <verstretch>0</verstretch> + </sizepolicy> + </property> + </widget> + <widget class="QPushButton"> + <property name="name"> + <cstring>Search</cstring> + </property> + <property name="text"> + <string>Search</string> + </property> + </widget> + </hbox> + </widget> + <widget class="QListBox"> + <item> + <property name="text"> + <string>New Item</string> + </property> + </item> + <property name="name"> + <cstring>SearchResults</cstring> + </property> + <property name="sizePolicy"> + <sizepolicy> + <hsizetype>7</hsizetype> + <vsizetype>7</vsizetype> + <horstretch>0</horstretch> + <verstretch>1</verstretch> + </sizepolicy> + </property> + </widget> + </vbox> + </widget> + </widget> + <widget class="QTextBrowser"> + <property name="name"> + <cstring>HelpPage</cstring> + </property> + <property name="sizePolicy"> + <sizepolicy> + <hsizetype>7</hsizetype> + <vsizetype>7</vsizetype> + <horstretch>1</horstretch> + <verstretch>1</verstretch> + </sizepolicy> + </property> + <property name="textFormat"> + <enum>RichText</enum> + </property> + </widget> + </hbox> + </widget> + </grid> +</widget> +<menubar> + <property name="name"> + <cstring>MenuBar</cstring> + </property> + <item text="&File" name="fileMenu"> + <action name="fileSaveAction"/> + <separator/> + <action name="fileExitAction"/> + </item> + <item text="&Edit" name="editMenu"> + <separator/> + <action name="editCopyAction"/> + <action name="editPasteAction"/> + <separator/> + <action name="editFindAction"/> + </item> + <item text="&Help" name="helpMenu"> + <separator/> + <action name="helpAboutAction"/> + </item> +</menubar> +<toolbars> + <toolbar dock="2"> + <property name="name"> + <cstring>toolBar</cstring> + </property> + <property name="label"> + <string>Tools</string> + </property> + <action name="fileExitAction"/> + <action name="editCopyAction"/> + </toolbar> +</toolbars> +<actions> + <action> + <property name="name"> + <cstring>fileSaveAction</cstring> + </property> + <property name="iconSet"> + <iconset>image0</iconset> + </property> + <property name="text"> + <string>Save</string> + </property> + <property name="menuText"> + <string>&Save</string> + </property> + <property name="accel"> + <string>Ctrl+S</string> + </property> + </action> + <action> + <property name="name"> + <cstring>fileExitAction</cstring> + </property> + <property name="text"> + <string>Exit</string> + </property> + <property name="menuText"> + <string>E&xit</string> + </property> + <property name="accel"> + <string></string> + </property> + </action> + <action> + <property name="name"> + <cstring>editCopyAction</cstring> + </property> + <property name="iconSet"> + <iconset>image1</iconset> + </property> + <property name="text"> + <string>Copy</string> + </property> + <property name="menuText"> + <string>&Copy</string> + </property> + <property name="accel"> + <string>Ctrl+C</string> + </property> + </action> + <action> + <property name="name"> + <cstring>editPasteAction</cstring> + </property> + <property name="iconSet"> + <iconset>image2</iconset> + </property> + <property name="text"> + <string>Paste</string> + </property> + <property name="menuText"> + <string>&Paste</string> + </property> + <property name="accel"> + <string>Ctrl+V</string> + </property> + </action> + <action> + <property name="name"> + <cstring>editFindAction</cstring> + </property> + <property name="iconSet"> + <iconset>image3</iconset> + </property> + <property name="text"> + <string>Find</string> + </property> + <property name="menuText"> + <string>&Find...</string> + </property> + <property name="accel"> + <string>Ctrl+F</string> + </property> + </action> + <action> + <property name="name"> + <cstring>helpAboutAction</cstring> + </property> + <property name="text"> + <string>About</string> + </property> + <property name="menuText"> + <string>&About</string> + </property> + <property name="accel"> + <string></string> + </property> + </action> +</actions> +<images> + <image name="image0"> + <data format="PNG" length="217">89504e470d0a1a0a0000000d4948445200000016000000160806000000c4b46c3b000000a049444154789cd5954d0a802010859fd14668e18de662d222bc98376a21b4ac451992c66469e0b7f187f1f11c47052a218e762daddbfb9e99f6568f80b5364b8588ce35440400e80a398ce8f99034d2292cc37c8ebd530feb583a05e954341f8a027b2a7d3a1f09bf854dc5d5d953aa396e4f38cab199e2d2e108abe156f82e30977fcb4d8ff942d75dbebed2e143953a93f6caad3d6111f44b7d4f820ff9c0069bb51ecd122066740000000049454e44ae426082</data> + </image> + <image name="image1"> + <data format="PNG" length="248">89504e470d0a1a0a0000000d4948445200000016000000160806000000c4b46c3b000000bf49444154789cd593410a83301045df488ee51dbc8c3ba98bf46a9eabd385350d266362444a3f0c4266fcf3f824f06f12402b66da8c55f3de2212cf9d92cb98c0ba2d7c4544cf9a07638bbad53c4491235ecf7cc1623697a92540c11ff4fda75275015d24a9389e7d6f53df4fe4ccab323eea0f03c0c4b2a0712ce6add89b59b7661c3be095985f261679ee4ebcc22c9788551fe6a2cbc4969a894bcb6f23ee361aab62e252c57294dfbfb610bbf2c897b8a46cc6677eaa519571fa087ea83762da9aba45b637520000000049454e44ae426082</data> + </image> + <image name="image2"> + <data format="PNG" length="270">89504e470d0a1a0a0000000d4948445200000016000000160806000000c4b46c3b000000d549444154789cc5955d0a84300c8427e2a90a9e6c8b0f4b3dd982d7ca3e58d7fe4cd0ba5d7640024df265da0a057e2439c9eb8d9eaa8841a0c9aad8c82ab32f9c425be1e30e0dcf00c00308f0b3a7a07410a9d7142e00b42c5a5fab696b979b1c837fc0c316b6e4165b64f78d716359919bdc4570de47c04732dd5e5bcc35f0c97762ae787936dccf7513577e79f48c4b27aa0f1327b240f5117fcbe348aa33b6e0224b054d0746b8025e2e3b3e73cde0dd1c97f02e8ed9d0af1db381224bdf33eee698a934a0f617b45540d00bcf4ca08fc0dff406e325c198b16b67fb0000000049454e44ae426082</data> + </image> + <image name="image3"> + <data format="PNG" length="662">89504e470d0a1a0a0000000d4948445200000016000000160806000000c4b46c3b0000025d49444154789cd593a172db4010863f670a56ecc42278d0653693a0c21c68d6c2e60df21a818111349499c254a8329b55f0e089ddb15ba602b79d6692d699b6d399fee86e67e7db7f77efe07fd3e2c74bd775b3730eef3d5115002382b5166b2d5757578b1729bf02b76d3b0f8703b92d58aed7600400ef1ce3c70306a8aa8aebebeb57c117dfa06ddb525dd754efb600a82a49138a123532ec3ac42b9bcde655ce2ffabe9f87c340fde13dcb4d8daaa24e48ee12c6823808c107969b1a8a9ce3f1f8aa515c38e7c8ada5aa6b00c45f129c67d223938c88e6c860d118b1d592d139baae9bcf83a78965b5465134801b1d2e1f4945c0e350096408ea154490c2e0bd3fef5853c2e486a0019f4d84f58418418362b0408e8b23c924501093314dd359f01b809814112025144015f1964c0bbc1b484b07e4688880c029ebd78e4141f5b434fd76864c053f1e084b0f8580265440634044ce838bbcc03987a61350a3a2285e1d5a4414d0708aa598082162ad3d0fb6d6e287cfa498508d274050447370428c91af8d10fd4481608c390b5e00dcddddcd8e80a9de420248e804840856f03e02907d729465c9ba5ae3468731e6a79fe50260b55a6102c4ee40a6894c33f2cb0cb106512814f8f899b22cb9b9b959b8d1f1f8f848d334b46dfbe29bfe5eadeffbf9783c323a871881ecb4200d1151a8eb9aed76bb00188661eeba8efd7e8f3186ed76cb6ab57ae2fe591b5dd7cdde7b628c8808799e63ada5aaaa67b9bbdd6e6e9a06ef3d755d3f29fec7eafb7ebebdbd9dadb5735996f3fdfdfdfca2e3dfd5c3c3c3dc340dd334b1d96cfe1e184e63dceff7a494fe26f61fe90bbc4c5e59b8ac895e0000000049454e44ae426082</data> + </image> +</images> +<connections> + <connection> + <sender>fileExitAction</sender> + <signal>activated()</signal> + <receiver>Form1</receiver> + <slot>close()</slot> + </connection> +</connections> +<tabstops> + <tabstop>SearchLine</tabstop> + <tabstop>Search</tabstop> + <tabstop>SearchResults</tabstop> + <tabstop>HelpPage</tabstop> + <tabstop>StaticObjectList</tabstop> + <tabstop>ObjectTypeList</tabstop> + <tabstop>KJSEmbedObjectList</tabstop> + <tabstop>QtObjectList</tabstop> + <tabstop>KDEObjectList</tabstop> + <tabstop>ExceptionTypeList</tabstop> + <tabstop>UnconstructableTypeList</tabstop> +</tabstops> +<layoutdefaults spacing="2" margin="3"/> +</UI> diff --git a/kjsembed/docs/examples/qdocviewer/qdocviewer.js b/kjsembed/docs/examples/qdocviewer/qdocviewer.js new file mode 100644 index 00000000..41ae2835 --- /dev/null +++ b/kjsembed/docs/examples/qdocviewer/qdocviewer.js @@ -0,0 +1,201 @@ +#!/usr/bin/env qjscmd +// Populates the sidebar listview +function setup_sidebar( special, qt, all ) +{ + var qobjects = Factory.constructors().sort(); + + for ( var i=0; i < qobjects.length ; i++ ) { + all.insertItem( qobjects[i] ); + + if ( /^Q/.test(qobjects[i]) ) + qt.insertItem( qobjects[i] ); + else + special.insertItem( qobjects[i] ); + } +} + +function documentStaticObject( type ) +{ + HelpPage.text ="<h1>" + type + "</h1><HR>"; + try{ + var obj = eval( type ); + HelpPage.text += dump(obj); + } + catch (error) + { + HelpPage.text += "This object is not supported by this version of KJSEmbed"; + } +} + +function documentConstructableObject( type ) +{ + HelpPage.text ="<h1>" + type + "</h1><HR>"; + if ( type!= 'TextStream' ) + { + try { + HelpPage.text += dump(Factory.createObject( type )); + } + catch(x) { + HelpPage.text +='Bindings for the ' + type + ' class.<br /> This class is understood by the interpreter, but cannot be created from scripts.' + } + } +} + +function populateStaticObjects() +{ + StaticObjectList.clear(); + var statics = [ 'Factory', 'System', 'Global', 'StdDialog', + 'StdAction', 'StdDirs', 'StdIcons', 'Qt' ]; + for ( var idx = 0; idx < statics.length; idx++ ) + { + StaticObjectList.insertItem(statics[idx]); + } +} + +function populateExceptions() +{ + var expts = [ 'ReferenceError', 'EvalError', 'RangeError', 'TypeError' ]; + for ( var idx = 0; idx < expts.length; idx++ ) + { + ExceptionTypeList.insertItem(expts[idx]); + } +} + +function populateObjects() +{ + var tps = Factory.types().sort(); + QtObjectList.clear(); + KJSEmbedObjectList.clear(); + KDEObjectList.clear(); + ObjectTypeList.clear(); + + cons = Factory.constructors().sort(); + cons += 'Part'; + + for ( var i=0; i < tps.length; i++ ) { + + if ( /^Q/.test(tps[i]) ) { + QtObjectList.insertItem( tps[i] ); + } + else if ( /^KJSEmbed::/.test(tps[i]) ) { + if ( tps[i] != 'KJSEmbed::Bindings::JSDCOPInterface' ) { + KJSEmbedObjectList.insertItem( tps[i] ); + } + } + else if ( /^K/.test(tps[i]) ) { + KDEObjectList.insertItem( tps[i] ); + } + else { + ObjectTypeList.insertItem( tps[i] ); + } + } +} +// +// Main +// + +// Create the UI +var mw = Factory.loadui("docviewer.ui"); +//mw.qt_central_widget.HelpPage.text = dump(mw.qt_central_widget.Navbar.StaticObjects.StaticObjectList); +var HelpPage = mw.qt_central_widget.HelpPage; +var StaticObjectList = mw.qt_central_widget.Navbar.StaticObjects.StaticObjectList; +var ExceptionTypeList = mw.qt_central_widget.Navbar.ExceptionTypes.ExceptionTypeList; +var KDEObjectList = mw.qt_central_widget.Navbar.KDEObjects.KDEObjectList; +var QtObjectList = mw.qt_central_widget.Navbar.QtObjects.QtObjectList; +var KJSEmbedObjectList = mw.qt_central_widget.Navbar.KJSEmbedObjects.KJSEmbedObjectList; +var ObjectTypeList = mw.qt_central_widget.Navbar.ObjectTypes.ObjectTypeList; + +populateStaticObjects(); +populateExceptions(); +populateObjects(); + +mw.connect( StaticObjectList, 'highlighted(const QString&)', this, 'documentStaticObject' ); +mw.connect( ExceptionTypeList, 'highlighted(const QString&)', this, 'documentStaticObject' ); +mw.connect( KDEObjectList, 'highlighted(const QString&)', this, 'documentConstructableObject' ); +mw.connect( QtObjectList, 'highlighted(const QString&)', this, 'documentConstructableObject' ); +mw.connect( KJSEmbedObjectList, 'highlighted(const QString&)', this, 'documentConstructableObject' ); +mw.connect( ObjectTypeList, 'highlighted(const QString&)', this, 'documentConstructableObject' ); + + +mw.show(); +application.exec(); +/* + +side = new QTabWidget( split, 'sidebar' ); +view = new QTabWidget( split, 'mainview' ); + +// Load the view +js = new QTextEdit( view, 'js' ); +js.setReadOnly( true ); + +view.addTab( js, '&Javascript' ); + +view.set_class = function( clazz ) +{ + clazz = clazz.replace( '^[^QK]*', '' ); + + // JS docs + var s = ''; + + s = s + '<html>'; + s = s + '<body>'; + s = s + '<h1>' + clazz + '</h1>'; + + try { + var obj = eval('new '+clazz+'()'); + s = s + dump(obj); + } + catch ( err ) { + s = s + '<font color="red">Error dumping object: ' + err + '</font>'; + } + + s = s + '</body>'; + s = s + '</html>'; + + js.text = s; +} + +view.setup = function() +{ + // JS docs + var s = ''; + s = s + '<html>'; + s = s + '<body>'; + s = s + '<h1>Script Reference</h1>'; + s = s + '</body>'; + s = s + '</html>'; + + js.text = s; +} + +// Setup the sidebar +specialside = new QListBox( side, 'specialsidebar' ); +qtside = new QListBox( side, 'qtsidebar' ); +allside = new QListBox( side, 'allsidebar' ); + +side.addTab( specialside, '&Special' ); +side.addTab( qtside, '&Qt' ); +side.addTab( allside, '&All' ); + +setup_sidebar( specialside, qtside, allside ); + +qtside.connect( qtside, 'highlighted(const QString&)', view, 'set_class' ); +specialside.connect( specialside, 'highlighted(const QString&)', view, 'set_class' ); +allside.connect( allside, 'highlighted(const QString&)', view, 'set_class' ); + +// +// Show the window +// + +side.maximumWidth = 250; +mw.resize( 800, 550 ); + +mw.show(); + +// +// Connect together +// +view.setup(); + +application.exec(); +*/ diff --git a/kjsembed/docs/examples/qobject-dom/qobject-dom.js b/kjsembed/docs/examples/qobject-dom/qobject-dom.js new file mode 100644 index 00000000..db9d381d --- /dev/null +++ b/kjsembed/docs/examples/qobject-dom/qobject-dom.js @@ -0,0 +1,24 @@ +#!/usr/bin/env kjscmd + +// +// Tests the DOM methods +// + +var box = console.getElementById('cmd_box'); +var btn = box.child('run_button'); + +print('Button: '); +println(btn); + +println( 'Property: enabled' ); +print( 'hasAttribute: ' ); +println( btn.hasAttribute('enabled') ); +print( 'getAttribute: ' ); +println( btn.getAttribute('enabled') ); +print( 'setAttribute: ' ); +println( btn.setAttribute('enabled', false) ); +print( 'getAttribute: ' ); +println( btn.getAttribute('enabled') ); + +println(); +println( 'Now the console will be displayed with button disabled' ); diff --git a/kjsembed/docs/examples/readonlypart/README b/kjsembed/docs/examples/readonlypart/README new file mode 100644 index 00000000..41a5cf1a --- /dev/null +++ b/kjsembed/docs/examples/readonlypart/README @@ -0,0 +1,3 @@ +Shows how to load read only parts from a script. The example will load +the URL specified on the command line into a KHTML part. If no URL is +specified then www.kde.org is loaded. diff --git a/kjsembed/docs/examples/readonlypart/readonlypart.js b/kjsembed/docs/examples/readonlypart/readonlypart.js new file mode 100755 index 00000000..0f57b763 --- /dev/null +++ b/kjsembed/docs/examples/readonlypart/readonlypart.js @@ -0,0 +1,24 @@ +#!/usr/bin/env kjscmd + +// Example that provides a basic HTML browser + +// Get URL to load +var url = 'http://www.kde.org/'; +if ( application.args.length ) + url = application.args[0]; + +// Create the UI +var mw = new KMainWindow(); +var box = new QHBox( mw ); +mw.setCentralWidget(box); + +// Create the view +var view = Factory.createROPart( "text/html", box, "view" ); +view.connect(view.child(0), 'openURLRequest(const KURL&,const KParts::URLArgs&)', 'openURL(const KURL&)' ) +view.openURL( url ); + +// Show the GUI +mw.resize(650,500); +mw.show(); + +application.exec(); diff --git a/kjsembed/docs/examples/readwritepart/README b/kjsembed/docs/examples/readwritepart/README new file mode 100644 index 00000000..41a5cf1a --- /dev/null +++ b/kjsembed/docs/examples/readwritepart/README @@ -0,0 +1,3 @@ +Shows how to load read only parts from a script. The example will load +the URL specified on the command line into a KHTML part. If no URL is +specified then www.kde.org is loaded. diff --git a/kjsembed/docs/examples/readwritepart/readwritepart.js b/kjsembed/docs/examples/readwritepart/readwritepart.js new file mode 100755 index 00000000..3cc9c18c --- /dev/null +++ b/kjsembed/docs/examples/readwritepart/readwritepart.js @@ -0,0 +1,25 @@ +#!/usr/bin/env kjscmd + +// Example that embeds a read-write kpart + +// Get URL to load +var url = 'http://www.kde.org/'; +if ( application.args.length ) + url = application.args[0]; + +// Create the UI +var mw = new KMainWindow(); +var box = new QHBox( mw ); +mw.setCentralWidget(box); + +// Create the view +var view = Factory.createRWPart( "text/plain", box, "view" ); + +// Open the file +view.openURL( url ); + +// Show the GUI +mw.resize(650,500); +mw.show(); + +application.exec(); diff --git a/kjsembed/docs/examples/sax/saxdefaults.js b/kjsembed/docs/examples/sax/saxdefaults.js new file mode 100644 index 00000000..f4a7d3da --- /dev/null +++ b/kjsembed/docs/examples/sax/saxdefaults.js @@ -0,0 +1,37 @@ +#!/usr/bin/env kjscmd + +sax = new Object(); + +// This method is not implemented, so we rely on the default +//sax.startDocument = function() { +// println( "start document" ); +// return true; +//} + +sax.startElement = function( namespace, localname, qualifiedname ) { + println( "start: '" + namespace + "', '" + localname + "', '" + qualifiedname + "'" ); + return true; +} + +sax.endElement = function( namespace, localname, qualifiedname ) { + println( "end: '" + namespace + "', '" + localname + "', '" + qualifiedname + "'" ); + return true; +} + +sax.characters = function( chars ) { + println( "characters: '" + chars + "'" ); + return true; +} + +sax.endDocument = function() { + println( "end document" ); + return true; +} + +try { + saxLoadFile( sax, application.args[0] ); +} +catch( theErr ) +{ + println(theErr); +} diff --git a/kjsembed/docs/examples/sax/saxdemo.js b/kjsembed/docs/examples/sax/saxdemo.js new file mode 100644 index 00000000..c39ac619 --- /dev/null +++ b/kjsembed/docs/examples/sax/saxdemo.js @@ -0,0 +1,36 @@ +#!/usr/bin/env kjscmd + +sax = new Object(); + +sax.startDocument = function() { + println( "start document" ); + return true; +} + +sax.startElement = function( namespace, localname, qualifiedname ) { + println( "start: '" + namespace + "', '" + localname + "', '" + qualifiedname + "'" ); + return true; +} + +sax.endElement = function( namespace, localname, qualifiedname ) { + println( "end: '" + namespace + "', '" + localname + "', '" + qualifiedname + "'" ); + return true; +} + +sax.characters = function( chars ) { + println( "characters: '" + chars + "'" ); + return true; +} + +sax.endDocument = function() { + println( "end document" ); + return true; +} + +try { + saxLoadFile( sax, application.args[0] ); +} +catch( theErr ) +{ + println(theErr); +} diff --git a/kjsembed/docs/examples/sax/saxerror.xml b/kjsembed/docs/examples/sax/saxerror.xml new file mode 100644 index 00000000..5ebe78a1 --- /dev/null +++ b/kjsembed/docs/examples/sax/saxerror.xml @@ -0,0 +1,3 @@ +<atag> + <tag2>some text</error> +</atag> diff --git a/kjsembed/docs/examples/sax/saxnamespace.xml b/kjsembed/docs/examples/sax/saxnamespace.xml new file mode 100644 index 00000000..2c74ab3c --- /dev/null +++ b/kjsembed/docs/examples/sax/saxnamespace.xml @@ -0,0 +1,3 @@ +<space:outer> + <container:tag>this tag is in the namespace container</container:tag> +</space:outer> diff --git a/kjsembed/docs/examples/sax/saxtest.xml b/kjsembed/docs/examples/sax/saxtest.xml new file mode 100644 index 00000000..a74dd479 --- /dev/null +++ b/kjsembed/docs/examples/sax/saxtest.xml @@ -0,0 +1,9 @@ +<atag> + <tag2>some text</tag2> + <tag2>some text</tag2> + <tag2>some text</tag2> + <tag2>some text</tag2> + <nesting> + <one><two><three/></two></one> + </nesting> +</atag> diff --git a/kjsembed/docs/examples/sql/sql.js b/kjsembed/docs/examples/sql/sql.js new file mode 100755 index 00000000..5ef568de --- /dev/null +++ b/kjsembed/docs/examples/sql/sql.js @@ -0,0 +1,57 @@ +#!/usr/bin/env kjscmd + +var db = new SqlDatabase(); +var mw = new KMainWindow(); +var box = new QVBox( mw ); +mw.setCentralWidget(box); + +if ( db.addDatabase("QMYSQL3", "test" )) +{ + db.databaseName = "XXXX"; + db.userName = "XXXX"; + db.password = "XXXX"; + db.hostName = "XXXX"; + db.port = 3306; + println("Database Name:" + db.databaseName); + println("User Name:" + db.userName); + println("Password:" + db.password); + println("Host Name:" + db.hostName); + println("Port:" + db.port); + println("Driver Name:" + db.driverName); + var list = new KListView(box); + list.addColumn('One'); + list.addColumn('Two'); + list.addColumn('Three'); + if( db.open() ) + { + var query = db.exec("select * from tasks" ); + println(query.size + " Results returned"); + if (query.active) + { + println(query.size + " Results returned"); + if( query.first() ) + { + while( query.next()) + { + println(query.value(0).toString() + " " + + query.value(1).toString() + " " + + query.value(2).toString()); + + list.insertItem(query.value(0).toString(), + query.value(1).toString(), + query.value(2).toString()); + } + } + else + println("Query Error: " + query.lastError); + } + else + println("Database Connection Error: " + db.lastError); + + } + else + println("Database Open Error: " + db.lastError); +} +else + println("Database Connection Error: " + db.lastError); +mw.show(); diff --git a/kjsembed/docs/examples/stdicons/stdicons.js b/kjsembed/docs/examples/stdicons/stdicons.js new file mode 100755 index 00000000..e01c96ec --- /dev/null +++ b/kjsembed/docs/examples/stdicons/stdicons.js @@ -0,0 +1,17 @@ +#!/usr/bin/env kjscmd + +var mainBox = new QVBox(this); +var Icon1 = new QLabel(mainBox); +var Icon2 = new QLabel(mainBox); +var Icon3 = new QLabel(mainBox); +var Icon4 = new QLabel(mainBox); +var Icon5 = new QLabel(mainBox); + +Icon1.pixmap = StdIcons.BarIcon("openterm"); +Icon2.pixmap = StdIcons.DesktopIcon("folder"); +Icon3.pixmap = StdIcons.SmallIcon("folder"); +Icon4.pixmap = StdIcons.MainBarIcon("fileclose"); +Icon5.pixmap = StdIcons.UserIcon("ftp"); + +mainBox.show(); +application.exec(); diff --git a/kjsembed/docs/examples/systemtray/kjstray.png b/kjsembed/docs/examples/systemtray/kjstray.png Binary files differnew file mode 100644 index 00000000..f77ae150 --- /dev/null +++ b/kjsembed/docs/examples/systemtray/kjstray.png diff --git a/kjsembed/docs/examples/systemtray/systemtray.js b/kjsembed/docs/examples/systemtray/systemtray.js new file mode 100755 index 00000000..5ecc55f0 --- /dev/null +++ b/kjsembed/docs/examples/systemtray/systemtray.js @@ -0,0 +1,30 @@ +#!/usr/bin/env kjscmd + +// +// Example that uses KSystemTray +// + +// Create the main window +mainwin = new QTextEdit(this); +mainwin.text = '<qt>This is the main window for a script that illustrates ' + + 'the use of the <i>System Tray</i>.'; + +// Create the tray icon +trayicon = new KSystemTray( mainwin ); + +// Set the pixmap of the tray icon (we force it to be loaded from the cwd here) +cwd = (new QDir()).absPath(); +trayicon.pixmap = trayicon.loadIcon( cwd + '/kjstray.png' ); + +// Ensure we quit when you choose the option from the tray item's menu +application.connect( trayicon, 'quitSelected()', 'quit()' ); + +// Get the context menu +var menu = trayicon.contextMenu(); +menu.insertItem("My Item"); + +// Show both the main window and the icon +trayicon.show(); +mainwin.show(); + +application.exec(); diff --git a/kjsembed/docs/examples/timer/timer.js b/kjsembed/docs/examples/timer/timer.js new file mode 100644 index 00000000..fabb669f --- /dev/null +++ b/kjsembed/docs/examples/timer/timer.js @@ -0,0 +1,10 @@ +#!/usr/bin/env kjscmd + +var led = new KLed(); +var timer = new QTimer(); +led.connect( timer, 'timeout()', 'toggle()' ); + +timer.start( 500 ); + +led.show(); +application.exec(); diff --git a/kjsembed/docs/examples/treeview/showtree.js b/kjsembed/docs/examples/treeview/showtree.js new file mode 100644 index 00000000..76872d35 --- /dev/null +++ b/kjsembed/docs/examples/treeview/showtree.js @@ -0,0 +1,68 @@ +#!/usr/bin/env kjscmd + +function buildViewNode( node, parent ) +{ + var l = new QLabel( parent, 'node' ); + l.text = '<center><table cellspacing=0>' + + '<tr><th bgcolor="#aaaaee"><b>' + node.text + '</b></th></tr>' + + '<tr><td bgcolor="#ccccee">' + node.text + '</td></tr>' + + '<tr><td bgcolor="#ccccee">' + node.text + '</td></tr>' + + '</table></center>'; + + return l; +} + +function buildView( node, parent ) +{ + // No children + if ( node.children.length == 0 ) { + return buildViewNode( node, parent ); + } + + // Create container node + var vbox = new QVBox( parent, 'subtree' ); + vbox.margin = 8; + vbox.spacing = 6; + + var vnode = buildViewNode( node, vbox ); + + // Create children + var hbox = new QHBox( vbox, 'child_nodes' ); + hbox.spacing = 6; + + for ( var i = 0 ; i < node.children.length ; i++ ) { + buildView( node.children[i], hbox ); + } + + return vbox; +} + +function buildNode( ttl ) +{ + var node = new Object(); + node.text = ttl; + node.children = []; + return node; +} + +// Create Tree Model +var root = buildNode( 'Root' ); + +root.children = [ buildNode('One'), buildNode('Two'), buildNode('Three') ]; +root.children[0].children = [ buildNode('One'), buildNode('Two') ]; +root.children[0].children = [ buildNode('One'), buildNode('Two') ]; +root.children[1].children = [ buildNode('One'), buildNode('Two') ]; +root.children[1].children = [ buildNode('One'), buildNode('Two'), buildNode('Three') ]; +root.children[2].children = [ buildNode('One') ]; +root.children[2].children = [ buildNode('One'), buildNode('Two'), buildNode('Three') ]; + +// Create View +var box = new QVBox( 'tree_view' ); +box.margin = 6; + +var view = buildView( root, box ); +var spacer = new QLabel( box ); + +box.show(); + + diff --git a/kjsembed/docs/examples/treeview/showtree.png b/kjsembed/docs/examples/treeview/showtree.png Binary files differnew file mode 100644 index 00000000..8806d46d --- /dev/null +++ b/kjsembed/docs/examples/treeview/showtree.png diff --git a/kjsembed/docs/examples/treeview/tree2.js b/kjsembed/docs/examples/treeview/tree2.js new file mode 100644 index 00000000..d8b8e09d --- /dev/null +++ b/kjsembed/docs/examples/treeview/tree2.js @@ -0,0 +1,56 @@ +#!/usr/bin/env kjscmd + +// Demo that creates a tree from a ui file using QHBox and QBox. + +function create_item( node, parent ) +{ + var l = new QLabel( parent ); + l.paletteBackgroundColor = '#aaaaee'; + l.frameShape = 1; + l.frameWidth = 1; + l.alignment = 0x44; + + l.text = node.name; + return l; +} + +function create_subtree_layout( parent ) +{ + var vb = new QVBox( parent ); + vb.margin = 12; + + return vb; +} + +function create_child_layout( parent ) +{ + var hb = new QHBox( parent ); + hb.margin = 6; + + return hb; +} + +function create_tree( node, parent ) +{ + var outer = create_subtree_layout( parent ); + + create_item( node, outer ); + + var inner = create_child_layout( outer ); + + for ( var i = 0 ; i < node.childCount() ; i++ ) { + var child = node.child(i); + if ( child.isWidgetType() ) + create_tree( child, inner ); + } + + return outer; +} + +var ui = Factory.loadui( 'treetest.ui' ); +var top = new QHBox(); +create_tree( ui, top ); + +top.show(); + + diff --git a/kjsembed/docs/examples/treeview/treetest.ui b/kjsembed/docs/examples/treeview/treetest.ui new file mode 100644 index 00000000..c645e9c2 --- /dev/null +++ b/kjsembed/docs/examples/treeview/treetest.ui @@ -0,0 +1,111 @@ +<!DOCTYPE UI><UI version="3.1" stdsetdef="1"> +<class>Form1</class> +<widget class="QWidget"> + <property name="name"> + <cstring>Form1</cstring> + </property> + <property name="geometry"> + <rect> + <x>0</x> + <y>0</y> + <width>291</width> + <height>116</height> + </rect> + </property> + <widget class="QSplitter"> + <property name="name"> + <cstring>splitter1</cstring> + </property> + <property name="geometry"> + <rect> + <x>12</x> + <y>12</y> + <width>269</width> + <height>92</height> + </rect> + </property> + <property name="orientation"> + <enum>Horizontal</enum> + </property> + <widget class="QLayoutWidget"> + <property name="name"> + <cstring>layout1</cstring> + </property> + <vbox> + <property name="name"> + <cstring>unnamed</cstring> + </property> + <widget class="QPushButton"> + <property name="name"> + <cstring>pushButton1</cstring> + </property> + <property name="text"> + <string>pushButton1</string> + </property> + </widget> + <widget class="QPushButton"> + <property name="name"> + <cstring>pushButton2</cstring> + </property> + <property name="text"> + <string>pushButton2</string> + </property> + </widget> + <widget class="QPushButton"> + <property name="name"> + <cstring>pushButton3</cstring> + </property> + <property name="text"> + <string>pushButton3</string> + </property> + </widget> + </vbox> + </widget> + <widget class="QLayoutWidget"> + <property name="name"> + <cstring>layout3</cstring> + </property> + <vbox> + <property name="name"> + <cstring>unnamed</cstring> + </property> + <widget class="QLayoutWidget"> + <property name="name"> + <cstring>layout2</cstring> + </property> + <hbox> + <property name="name"> + <cstring>unnamed</cstring> + </property> + <widget class="QPushButton"> + <property name="name"> + <cstring>pushButton4</cstring> + </property> + <property name="text"> + <string>pushButton4</string> + </property> + </widget> + <widget class="QPushButton"> + <property name="name"> + <cstring>pushButton5</cstring> + </property> + <property name="text"> + <string>pushButton5</string> + </property> + </widget> + </hbox> + </widget> + <widget class="QPushButton"> + <property name="name"> + <cstring>pushButton6</cstring> + </property> + <property name="text"> + <string>pushButton6</string> + </property> + </widget> + </vbox> + </widget> + </widget> +</widget> +<layoutdefaults spacing="6" margin="11"/> +</UI> diff --git a/kjsembed/docs/examples/xmlgui/xmlgui.js b/kjsembed/docs/examples/xmlgui/xmlgui.js new file mode 100755 index 00000000..ac0f7113 --- /dev/null +++ b/kjsembed/docs/examples/xmlgui/xmlgui.js @@ -0,0 +1,113 @@ +#!/usr/bin/env kjscmd + +// +// Setup main window +// +var mw = new KMainWindow(); + +var view = new QTextEdit( mw, 'view' ); +view.text = '<h1>Hello World</h1>' + + '<p>This application is written entirely in Javascript and works ' + + 'thanks to KJSEmbed</p>'; + +mw.setCentralWidget( view ); + +// +// Actions +// +var ac = mw.actionCollection(); + +// +// Create the quit action and connect it to a C++ slot +// +StdAction.quit( application, 'quit()', ac ); + +// +// We'll wire the file open action up to a JS function +// + +mw.openFile = function() { + var filename = StdDialog.getOpenFileName( '.', '*' ); + if ( filename.length > 0 ) { + view.text = System.readFile( filename ); + } +} + +var open_action = StdAction.open( null, '', ac ); +open_action.connect( open_action, 'activated()', mw, 'openFile' ); + +// +// We'll just accept the default for the rest of the actions +// + +StdAction.aboutApp( null, '', ac ); +StdAction.aboutKDE( null, '', ac ); +StdAction.actualSize( null, '', ac ); +StdAction.addBookmark( null, '', ac ); +StdAction.back( null, '', ac ); +StdAction.close( null, '', ac ); +StdAction.configureNotifications( null, '', ac ); +StdAction.configureToolbars( null, '', ac ); +StdAction.copy( null, '', ac ); +StdAction.cut( null, '', ac ); +StdAction.deselect( null, '', ac ); +StdAction.editBookmarks( null, '', ac ); +StdAction.fileNew( null, '', ac ); +StdAction.find( null, '', ac ); +StdAction.findNext( null, '', ac ); +StdAction.findPrev( null, '', ac ); +StdAction.fitToHeight( null, '', ac ); +StdAction.fitToPage( null, '', ac ); +StdAction.fitToWidth( null, '', ac ); +StdAction.forward( null, '', ac ); +StdAction.help( null, '', ac ); +StdAction.helpContents( null, '', ac ); +StdAction.home( null, '', ac ); +StdAction.keyBindings( null, '', ac ); +StdAction.mail( null, '', ac ); +StdAction.openRecent( null, '', ac ); +StdAction.paste( null, '', ac ); +StdAction.preferences( null, '', ac ); +StdAction.print( null, '', ac ); +StdAction.printPreview( null, '', ac ); +StdAction.redisplay( null, '', ac ); +StdAction.redo( null, '', ac ); +StdAction.replace( null, '', ac ); +StdAction.reportBug( null, '', ac ); +StdAction.revert( null, '', ac ); +StdAction.save( null, '', ac ); +StdAction.saveAs( null, '', ac ); +StdAction.saveOptions( null, '', ac ); +StdAction.selectAll( null, '', ac ); +StdAction.showMenubar( null, '', ac ); +StdAction.showStatusbar( null, '', ac ); +StdAction.showToolbar( null, '', ac ); +StdAction.spelling( null, '', ac ); +StdAction.tipofDay( null, '', ac ); +StdAction.undo( null, '', ac ); +StdAction.up( null, '', ac ); +StdAction.whatsThis( null, '', ac ); +StdAction.zoom( null, '', ac ); +StdAction.zoomIn( null, '', ac ); +StdAction.zoomOut( null, '', ac ); + +// +// There are two different Go menus define in XMLGUI, and we're using +// the browser oriented one, so we don't use these actions. +// + +//StdAction.firstPage( null, '', ac ); +//StdAction.goGoto( null, '', ac ); +//StdAction.gotoLine( null, '', ac ); +//StdAction.gotoPage( null, '', ac ); +//StdAction.lastPage( null, '', ac ); +//StdAction.next( null, '', ac ); +//StdAction.prior( null, '', ac ); + +// +// Activate XMLGUI and show the window +// +mw.createGUI( 'stdactionsui.rc' ); +mw.resize( 500, 350 ); +mw.show(); +application.exec(); diff --git a/kjsembed/docs/features.html b/kjsembed/docs/features.html new file mode 100644 index 00000000..676b4a51 --- /dev/null +++ b/kjsembed/docs/features.html @@ -0,0 +1,38 @@ +<html> +<head> +<link href="kjsembed.css" rel="stylesheet" type="text/css"> +<title>KJSEmbed Features</title> +</head> +<body> +<h1>KJSEmbed Features</h1> +<hr> +<h2>Introduction</h2> + +This document is a high-level summary of the feature set of KJSEmbed. + +<h2>Qt Integration</h2> +<ul> +<li>Generic proxy class providing access to any QObject. +<li>Call slots from scripts as if they are JS methods. +<li>Connect signals to JS methods as if they are slots. +<li>Navigate the QObject tree using a DOM compatible API. +<li>Load designer's UI files to dynamically load dialogs and widgets. +<li>Create any QWidget supported by QWidgetFactory. +<li>Custom factory for creating QObjects (such as QTimer). +<li>An opaque wrapper handling any QVariant value and any pointer. +</ul> + +<h2>KDE Integration</h2> +<ul> +<li>Create KParts from scripts (including KHTMLPart). +<li>Create KAction classes. +<li>Support for KDE's XMLGUI framework. +<li>Create any KDE widget supported by the KDE designer plugin (and a few +extras). + +</ul> + + +<hr> +</body> +</html> diff --git a/kjsembed/docs/images/embedjs.png b/kjsembed/docs/images/embedjs.png Binary files differnew file mode 100644 index 00000000..eb18347a --- /dev/null +++ b/kjsembed/docs/images/embedjs.png diff --git a/kjsembed/docs/images/jscalc.png b/kjsembed/docs/images/jscalc.png Binary files differnew file mode 100644 index 00000000..097b3f7c --- /dev/null +++ b/kjsembed/docs/images/jscalc.png diff --git a/kjsembed/docs/index.html b/kjsembed/docs/index.html new file mode 100644 index 00000000..3c86c42d --- /dev/null +++ b/kjsembed/docs/index.html @@ -0,0 +1,98 @@ +<html> +<head> +<link href="kjsembed.css" rel="stylesheet" type="text/css"> +<title>KJSEmbed Documentation</title> +</head> +<body> +<h1>KJSEmbed Documentation</h1> +<hr> + +<h3>Introduction</h3> + +The KJSEmbed library is an easy-to-use wrapper around the KDE +ECMAScript interpreter (kjs) that makes it easy to add scriptability +to an application. The kjsembed library is distributed in the +kdebindings module of KDE. This library provides a binding between +Qt/KDE applications and KJS. As well as working in its native KDE environment, +the library supports a Qt-only build that has no KDE dependencies. + +<h3>Discussion Forums</h3> + +There is now a KJSEmbed mailing list, see +<a href="http://mail.kde.org/mailman/listinfo/kjsembed">http://mail.kde.org/mailman/listinfo/kjsembed</a> +for more information about the list. In addition to the mailing list, +KJSEmbed is discussed on the #kaxul IRC channel (on the freenode IRC network). + +<h3>Learning KJSEmbed</h3> + +An introduction to KJSEmbed. The example scripts demonstrate the use +of all the major objects, and even provides some useful tools. The +tutorial provides a basic introduction to using KJSEmbed, though it is +a little out of date. + +<ul> + <li><b><a href="examples/index.html">Examples</a></b><br> + Example scripts showing how to use KJSEmbed.</li> + <li><b><a href="tutorial">Tutorial</a></b><br> + A tutorial for the library. NOTE: Some of the info here is out of date, see the + examples for cleaner ways to do things.</li> + <li><b><a href="changes.html">ChangeLog</a></b><br> + A log of the change history generated from CVS commit messages.</li> + <li><b><a href="TODO">TODO</a></b><br> + The todo list for KJSEmbed.</li> +</ul> + +<h3>Reference Information</h3> + +A reference manual for both the C++ and Javascript APIs defined by +KJSEmbed. The C++ API is of interest to developers looking to adding +scripting to support to their applications, the JS API is for people +who want to write scripts. + +<h4>JavaScript API</h4> +<ul> + <li><b><a href="types.html">Type Reference</a></b><br> + Documents the custom data types KJSEmbed uses to represent complex types. + <li><b><a href="jsref/index.html">Object Reference</a></b><br> + Documents the types of object scripts are allowed to create. +</ul> + +<h4>Host API</h4> +<ul> + <li><b><a href="classdocs/index.html">C++ API Reference</a> (C++)</b><br> + Reference manual for the C++ API of the KJSEmbed library.</li> + <li><b><a + href="http://webcvs.kde.org/kdebindings/kjsembed/kjscmd.cpp?view=markup">Example of embedding</a></b><br> + KJSCmd is a simple example of embedding the interpreter. +</ul> + +<h3>Appendices</h3> +<ul> + <li><b><a href="qtonly.html">Qt Only Mode</a></b><br> + How to build KJSEmbed with no KDE dependency.</li> + + <li><b><a href="conventions.html">Document Conventions</a></b><br> + Explains the typographical conventions used by the documents.</li> + + <li><b><a href="kjsembed-qsa.html">KJSEmbed and QSA</a></b><br> + Discusses the differences between KJSEmbed and QSA.</li> +</ul> + +<h3>References</h3> +<ul> + <li><b><a href="http://www.mozilla.org/js/language/">Mozilla Javascript Resources</a></b><br> + Mozilla's Javascript resources page, includes links to the various + releases of the ECMA-262 specification that define the language. + </li> + <li><b><a href="http://www.kevlindev.com/tutorials/javascript/inheritance/">Inheritance in Javascript</a></b><br> + A tutorial on how to implement inheritence in JavaScript. + </li> + <li><b><a href="http://doc.trolltech.com/qsa/">Qt Script for Applications Documentation</a></b><br> + The documentation for QSA, this is Trolltech's ECMAScript binding + for Qt. + </li> +</ul> + +<hr> +</body> +</html> diff --git a/kjsembed/docs/jsref/dummy.txt b/kjsembed/docs/jsref/dummy.txt new file mode 100644 index 00000000..e69de29b --- /dev/null +++ b/kjsembed/docs/jsref/dummy.txt diff --git a/kjsembed/docs/kjsembed-qsa.html b/kjsembed/docs/kjsembed-qsa.html new file mode 100644 index 00000000..2de920d8 --- /dev/null +++ b/kjsembed/docs/kjsembed-qsa.html @@ -0,0 +1,43 @@ +<html> +<head> +<link href="kjsembed.css" rel="stylesheet" type="text/css"> +<title>KJSEmbed and QSA</title> +</head> +<body> +<h1>KJSEmbed and QSA</h1> +<hr> + +<h3>Introduction</h3> + +There are a lot of similarities between QSA and KJSEmbed, and this has +led to some confusion. This document aims to shed some light on the +differences between the two libraries. + +<h3>The Differences</h3> + +<ul> + <li>QSA has a nice built in script editor which kjsembed does not, + but kjsembed can load designers ui files anyway and it would be easy + to add.</li> + + <li>KJSEmbed has facilities for working with KActions and can even + load them from XML files.</li> + + <li>KJSEmbed makes it easier to operate with Qt types than QSA. Take + a look at the <a href="types.html">types documentation</a> for more details.</li> + + <li>KJSEmbed has support for KDE specific types such as KURL. QSA + does not support these types by default, but does provide facilities + for adding support yourself.</li> + + <li>KJSEmbed can access the DOM from a KHTML part so it can work + nicely with HTML and XML documents. Note that this binding is only + available if the host application chooses to publish the DOM to the + interpreter.</li> + + <li>KJSEmbed is LGPL while QAS is GPL.</li> +</ul> + +<hr> +</body> +</html> diff --git a/kjsembed/docs/kjsembed.css b/kjsembed/docs/kjsembed.css new file mode 100644 index 00000000..34568f34 --- /dev/null +++ b/kjsembed/docs/kjsembed.css @@ -0,0 +1,47 @@ +h1 { text-align: center; background-color: #ccccff; } +h2 { background-color: #eeeeff; } +h3 { background-color: #eeeeff; } +h4 { background-color: #eeeeff; } + +A { text-decoration: none; font-weight: bold } + +table { width: 80%; } + +th { + background-color: #ccccff; + font-weight: bold; + padding-right : 10px; + padding-top : 2px; + padding-left : 10px; + padding-bottom : 2px; + margin-left : 0px; + margin-right : 0px; + margin-top : 2px; + margin-bottom : 2px +} + +td { + background-color: #ddddff; + font-weight: bold; + padding-right : 10px; + padding-top : 2px; + padding-left : 10px; + padding-bottom : 2px; + margin-left : 0px; + margin-right : 0px; + margin-top : 2px; + margin-bottom : 2px +} + +td.indexvalue { + background-color: #ddddff; + font-style: italic; + padding-right : 10px; + padding-top : 2px; + padding-left : 10px; + padding-bottom : 2px; + margin-left : 0px; + margin-right : 0px; + margin-top : 2px; + margin-bottom : 2px +} diff --git a/kjsembed/docs/qtonly.html b/kjsembed/docs/qtonly.html new file mode 100644 index 00000000..dbfd8ab6 --- /dev/null +++ b/kjsembed/docs/qtonly.html @@ -0,0 +1,21 @@ +<html> +<head> +<link href="kjsembed.css" rel="stylesheet" type="text/css"> +<title>KJSEmbed Qt-Only Mode</title> +</head> +<body> +<h1>KJSEmbed Qt-Only Mode</h1> +<hr> +KJSEmbed supports a Qt-only mode that has no KDE dependency. You can build +it in this mode as follows: +<ul> +<li>Checkout kjsembed as normal +<li>cd into the kjsembed directory +<li>Set your CVSROOT to point to the KDE CVS repository +<li>Run ./setup_qtonly <i>(this will build both the qt-only library and +qjscmd, a KDE-free tool for running scripts)</i> +</ul> + +<hr> +</body> +</html> diff --git a/kjsembed/docs/tutorial/grepdlg.png b/kjsembed/docs/tutorial/grepdlg.png Binary files differnew file mode 100644 index 00000000..b61bc511 --- /dev/null +++ b/kjsembed/docs/tutorial/grepdlg.png diff --git a/kjsembed/docs/tutorial/kjsembed.html b/kjsembed/docs/tutorial/kjsembed.html new file mode 100644 index 00000000..a304c3de --- /dev/null +++ b/kjsembed/docs/tutorial/kjsembed.html @@ -0,0 +1,213 @@ +<html> +<head> +<style type="text/css"> +<!-- +h1 { + background-color: #ccccee; + text-align: center; +} +h3 { + background-color: #ccccee; +} +li { + padding: 4px; +} +pre { + background-color: #CCCCCC; + margin-right: 16px; + margin-left: 16px; + padding: 6px; +} +.imgcaption { + font-weight: bold; + text-align: center; +} +.precaption { + font-weight: bold; + text-align: center; +} +--> +</style> +</head> +<body> +<h1> KJSEmbed</h1> +<h3>Introduction</h3> +<p>KJSEmbed is a library for embedding the KJS Javascript (ECMAScript) interpreter + in KDE applications. It provides developers with an easy way to allow users + to extend application, and can even be used with applications that have not + been designed with this in mind thanks to a KParts plugin. In addition, KJSEmbed + provides a command line tool for running scripts so users can easily create + simple applications of their own in Javascript. KJSEmbed scripts are surprisingly + powerful because they access the properties and slots of QObjects, and can even + load widgets and dialogs created with Qt's graphical dialog editor.</p> +<h3>Features</h3> +<p>To give you an idea of what KJSEmbed provides, here is a brief summary of the + more interesting features:</p> +<ul> + <li>KParts plugin for extending existing KDE applications with scripts. </li> + <li>KPart for embedding Javascript in your own applications.</li> + <li>Console dialog that can be used to execute Javascript interactively.</li> + <li>Command line tool for running scripts (this can even operate without an + X server if you don't need to display a GUI).</li> + <li>Define new KActions using XML.</li> + <li>Scripts can connect signals to slots.</li> + <li>Scripts can access the properties and slots of QObjects as if they were + normal Javascript properties and methods.</li> + <li>Scripts can load dialogs and widgets created with Qt Designer.</li> + <li>Scripts can create instances of anu QWidget subclass supported by QWidgetFactory.</li> + <li>Making your own QObjects/QWidgets available for scripting is one-liner.</li> + <li>Scripts can traverse the widget tree, so your entire application can be + made scriptable without explicitly binding every object.</li> +</ul> +<h3>First Steps - The Console Dialog</h3> +<p>The quickest way to see what KJSEmbed can do is with kjscmd, a tool for running + scripts from the command line. To begin, we'll run kjscmd without any parameters + which brings up the KJSEmbed console dialog. The console provides an easy way + to run short (one line) scripts, as you can see in figure 1 the scripts have + full access to the core Javascript language, and to standard objects such as + Math. In addition to the standard Javascript operations, this screenshot also + demonstrates the global function print() provided by KJSEmbed.</p> +<pre> +-- Enter a JS expression and press enter -- +kjs> 10+20 +30 +kjs> print("Hello World!") +Hello World! +undefined +kjs> Math.sin(0) +0 +kjs> Math.cos(0) +1 +</pre> +<p class="imgcaption">Figure 1: The KJSEmbed Console Dialog</p> +<p>Things get more interesting when you realise that we also have access to the + widgets that make up the dialog, as you can in figure 2:</p> +<pre> +kjs> console +JSConsoleWidget (KJSEmbed::JSConsoleWidget) +kjs> console.childCount() +4 +kjs> console.child(1) +CmdEdit (QComboBox) +kjs> console.child(2) +RunButton (QPushButton) +kjs> console.child("RunButton") +RunButton (QPushButton) +kjs> console.child("RunButton").text = "Go!" +Go! +kjs> console.caption = "Different Title" +Different Title +kjs> console.child("Title").hide() +undefined +</pre> +<p class="imgcaption">Figure 2: Modifying the Console Dialog</p> +<p>As you can see, the console dialog has been made available to scripts as the + global variable 'console'. We can access the child widgets that make up the + dialog either by index using the childCount() and child() methods, or by name + using the child() method (you can also use getElementById() if you + want a DOM-style API. As well as being able to see the widgets, we can modify + them by setting properties - in this example, we modify the caption property + of the widget 'console' (changing the window title) and the text property of + the widget 'RunButton' (changing the label it displays). Again, + there is a DOM-like way to do this - the setAttribute() and + getAttribute() methods. For the sake of completeness, the final + command illustrates the other way of modifying widgets available to + us - it calls hide() slot of the widget 'Title' (what this does is + left as an exercise for the reader).</p> +<h3>Displaying A Grep Dialog</h3> +<p>Now that we've seen how to use kjscmd interactively, lets take a look at a + more complex example that displays a dialog for running grep. The complete script + is shown in listing 1 and as you'll see, is very simple. Loading and displaying + the dialog takes only two lines of code because KJSEmbed provides a built-in + Factory object that supports Designer files, most of the work is getting the + values out of the dialog and building the command line.</p> +<pre> +// Create and show the dialog +var dlg = Factory.loadui('grepdlg.ui'); +dlg.exec(); + +// Extract the parameters +var search = dlg.child('search_edit').text; +var files = dlg.child('files_edit').text; +var matchcase = dlg.child('case_check').checked; +var invert = dlg.child('invert_check').checked; + +// Build the command line +var options; +if ( matchcase ) { + options = '-i'; +} +if ( invert ) { + options += ' -v'; +} + +cmd = 'grep '+options+"'"+search+"' "+files; + +// Print the command line +print( cmd ); +</pre> +<p class="precaption">Listing 1: A Script That Displays the Grep Dialog</p> +<p>In order to find out what the user asked us to search for we need to extract + the contents of the various fields in our dialog. We know that the field for + entering the text to be searched for is a QLineEdit called 'search_edit', so + we can use the child() method to get hold of it (this method searches through + the children of an object until it finds one with a matching name). Once we've + found the right object getting hold of the text is easy because all QLineEdits + make their contents available as a property called 'text'. The code that gets + the value of the check boxes is almost identical, except that these are QCheckBoxes + so it's the 'checked' property we're interested in.</p> +<p align="center"><img src="grepdlg.png" alt="Grep Dialog Screenshot" width="327" height="241"></p> +<p class="imgcaption">Figure 3: The Grep Dialog</p> +<p>When this script is run you'll see a dialog like the one shown in figure 3.</p> +<h3>Extending Applications with Javascript Plugins</h3> +<p>As its name implies KJSEmbed is not just a tool for writing standalone Javascript + tools, it also provides facilities for extending existing applications, these + facilities being with a KParts plugin for running scripts. The next example + uses the plugin to add a simple HTML-to-text action to Kate, the standard KDE + editor. </p> +<pre> +function html2text( html ) +{ + var text = html.replace( /<[^>]*>/g, '' ); + text = text.replace( /&quot;/g, '"' ); + text = text.replace( /&lt;/g, '<' ); + text = text.replace( /&amp;/g, '&' ); + return text; +} + +function text2html( text ) +{ + var html = text.replace( /&/g,"&amp;"); + html = html.replace( /"/g,"&quot;"); + html = html.replace( /</g,"&lt;"); + return html; +} +</pre> +<p>The details...</p> +<pre><!DOCTYPE actionset><br><actionset><br><header><br> <name>html2text_actions</name><br> <label>HTML To Text Actions</label><br> <script type="js" src="html2text_plugin.js"></script><br></header><br><action><br> <name>html_to_text</name><br> <type>KAction</type><br> <icons>text</icons><br> <label><text>Convert HTML To Text</text></label><br> <statustext>Converts the selected text from HTML to text.</statustext><br> <script type="js">kpart.selectedText = html2text( kpart.selectedText )</script><br></action><br><action><br> <name>text_to_html</name><br> <type>KAction</type><br> <icons>html</icons><br> <label><text>Quote For HTML</text></label><br> <statustext>Quotes the selected text for inclusion in an HTML document.</statustext><br> <script type="js">kpart.selectedText = text2html( kpart.selectedText )</script><br></action><br></actionset><br></pre> +<p><br> + The xmlgui:</p> +<pre> +<!DOCTYPE kpartgui><br><kpartplugin name="html2text_plugin" library="libkjsembedplugin"><br><MenuBar><br> <Menu name="tools"><Text>&amp;Tools</Text><br> <Action name="html_to_text"/><br> <Action name="text_to_html"/><br> <Action name="jsconsole"/><br> </Menu><br></MenuBar><br></kpartplugin><br> </pre> +<h3>Missing</h3> +<ul> + <li>XMLActions</li> + <li>Plugin</li> + <li>MainWindow</li> +</ul> +<h3>References</h3> +<dl> + <dt><a href="http://www.mozilla.org/js/language/">http://www.mozilla.org/js/language/</a></dt> + <dd>Javascript (ECMAScript) language information.</dd> +</dl> +<h3>To Do</h3> +<ul> + <li>Replace figures 1 and 2 with images</li> + <li></li> +</ul> +<p> </p> +<p> </p> +<p> </p> +</body> +</html> + diff --git a/kjsembed/docs/tutorial/passwordfileviewdlg.ui b/kjsembed/docs/tutorial/passwordfileviewdlg.ui new file mode 100644 index 00000000..5ff8c59c --- /dev/null +++ b/kjsembed/docs/tutorial/passwordfileviewdlg.ui @@ -0,0 +1,205 @@ +<!DOCTYPE UI><UI> +<class>password_viewer</class> +<widget> + <class>QDialog</class> + <property stdset="1"> + <name>name</name> + <cstring>password_viewer</cstring> + </property> + <property> + <name>geometry</name> + <rect> + <x>0</x> + <y>0</y> + <width>493</width> + <height>357</height> + </rect> + </property> + <property> + <name>caption</name> + <string>Password File Viewer</string> + </property> + <property> + <name>sizeGripEnabled</name> + <bool>true</bool> + </property> + <grid> + <property> + <name>margin</name> + <number>11</number> + </property> + <property> + <name>spacing</name> + <number>6</number> + </property> + <widget row="0" column="0" rowspan="1" colspan="2" > + <class>QLabel</class> + <property stdset="1"> + <name>name</name> + <cstring>TextLabel1</cstring> + </property> + <property> + <name>font</name> + <font> + <pointsize>12</pointsize> + <bold>1</bold> + </font> + </property> + <property> + <name>text</name> + <string>Password File Viewer</string> + </property> + </widget> + <widget row="1" column="0" rowspan="1" colspan="2" > + <class>Line</class> + <property stdset="1"> + <name>name</name> + <cstring>Line1</cstring> + </property> + <property> + <name>orientation</name> + <enum>Horizontal</enum> + </property> + </widget> + <spacer row="3" column="0" > + <property> + <name>name</name> + <cstring>Spacer2</cstring> + </property> + <property> + <name>orientation</name> + <enum>Horizontal</enum> + </property> + <property> + <name>sizeType</name> + <enum>Expanding</enum> + </property> + <property> + <name>sizeHint</name> + <size> + <width>20</width> + <height>20</height> + </size> + </property> + </spacer> + <widget row="3" column="1" > + <class>QPushButton</class> + <property stdset="1"> + <name>name</name> + <cstring>PushButton5</cstring> + </property> + <property> + <name>text</name> + <string>&Dismiss</string> + </property> + </widget> + <widget row="2" column="0" rowspan="1" colspan="2" > + <class>QListView</class> + <column> + <property> + <name>text</name> + <string>User Name</string> + </property> + <property> + <name>clickable</name> + <bool>true</bool> + </property> + <property> + <name>resizeable</name> + <bool>true</bool> + </property> + </column> + <column> + <property> + <name>text</name> + <string>Password</string> + </property> + <property> + <name>clickable</name> + <bool>true</bool> + </property> + <property> + <name>resizeable</name> + <bool>true</bool> + </property> + </column> + <column> + <property> + <name>text</name> + <string>User Id</string> + </property> + <property> + <name>clickable</name> + <bool>true</bool> + </property> + <property> + <name>resizeable</name> + <bool>true</bool> + </property> + </column> + <column> + <property> + <name>text</name> + <string>Group Id</string> + </property> + <property> + <name>clickable</name> + <bool>true</bool> + </property> + <property> + <name>resizeable</name> + <bool>true</bool> + </property> + </column> + <column> + <property> + <name>text</name> + <string>Real Name</string> + </property> + <property> + <name>clickable</name> + <bool>true</bool> + </property> + <property> + <name>resizeable</name> + <bool>true</bool> + </property> + </column> + <column> + <property> + <name>text</name> + <string>Home Directory</string> + </property> + <property> + <name>clickable</name> + <bool>true</bool> + </property> + <property> + <name>resizeable</name> + <bool>true</bool> + </property> + </column> + <column> + <property> + <name>text</name> + <string>Shell</string> + </property> + <property> + <name>clickable</name> + <bool>true</bool> + </property> + <property> + <name>resizeable</name> + <bool>true</bool> + </property> + </column> + <property stdset="1"> + <name>name</name> + <cstring>view</cstring> + </property> + </widget> + </grid> +</widget> +<connections> +</connections> +</UI> diff --git a/kjsembed/docs/types.html b/kjsembed/docs/types.html new file mode 100644 index 00000000..1b3f2120 --- /dev/null +++ b/kjsembed/docs/types.html @@ -0,0 +1,124 @@ +<html> +<head> +<link href="kjsembed.css" rel="stylesheet" type="text/css"> +<title>KJSEmbed Types</title> +</head> +<body> +<h1>KJSEmbed Types</h1> +<hr> +<h2>Introduction</h2> + +KJSEmbed adds a number of custom types to those defined by ECMA in +addition to the objects themselves. These types are used to pass +complex datatypes between scripts and the C++ code that is hosting the +script. This document describes the representations used to pass +information in each direction. + +<p> + +It should be noted that currently only a single representation is +available to scripts accessing native types. Scripts should not rely +on this behaviour as the restriction may be removed in a future +release of KJSEmbed so this, though the current script API will +continue to be supported. + +<h2>Fundamental Types</h2> + +<h3>Numbers</h3> +<ul> +<li>int -> Number +<li>uint -> Number +<li>float -> Number +<li>double -> Number +<li>Number -> int +<li>Number -> uint +<li>Number -> float +<li>Number -> double +</ul> + +<h3>Strings</h3> +<ul> +<li>QString -> String +<li>QCString -> String +<li>const char * -> String +<li>String -> QString +<li>String -> QCString +<li>String -> const char * +</ul> + +<h2>Qt Object Types</h2> + +<h3>QColor</h3> +Represents a color, possibly including an alpha channel. +<ul> +<li>QColor -> '#rrggbb' +<li>'#rrggbb' -> QColor +<li>'#rrggbbaa' -> QColor +</ul> + +<h3>QPoint</h3> +Represents a point. +<ul> +<li>QPoint -> [x,y] +<li>[x,y] -> QPoint +<li>obj.x obj.y -> QPoint +</ul> + +<h3>QSize</h3> +Represents a size. +<ul> +<li>QSize -> [w,h] +<li>[w,h] -> QSize +<li>obj.w obj.h -> QSize +</ul> + +<h3>QRect</h3> +Represents a rectangle. +<ul> +<li>QRect -> [x,y,w,h] +<li>[x,y,w,h] -> QRect +<li>obj.x obj.y obj.w obj.h -> QRect +</ul> + +<h3>QDate</h3> +Represents a date. +<ul> +<li>QDate -> '' +</ul> + +<h3>QTime</h3> +Represents a time. +<ul> +<li>QTime -> '' +</ul> + +<h3>QDateTime</h3> +Represents a date/time pair. +<ul> +<li>QDateTime -> '' +</ul> + +<h3>QKeySequence</h3> +Represents a sequence of keys, eg. it is used for accelerators. +<ul> +<li>QKeySequence -> '' +</ul> + +<h3>QFont</h3> +Represents a font. +<ul> +<li>QFont -> '' +</ul> + +<h2>KDE Object Types</h2> + +<h3>KURL</h3> +Represents a URL. +<ul> +<li>KURL -> '' +<li>'' -> KURL +</ul> + +<hr> +</body> +</html> diff --git a/kjsembed/docs/write_classes.js b/kjsembed/docs/write_classes.js new file mode 100644 index 00000000..ed47578c --- /dev/null +++ b/kjsembed/docs/write_classes.js @@ -0,0 +1,36 @@ + +text = ''; + + +text += '<html>\n'; + +text += '<head>\n'; +text += '<title>Constructors</title>\n'; +text += '<link href="../kjsembed.css" rel="stylesheet" type="text/css">\n'; +text += '</head>\n'; + +text += '<body>\n'; +text += '<h1>Constructors</h1>\n'; +text += '<hr>\n'; + +text += 'Object that scripts can create. This list includes objects\n'; +text += 'defined by QWidgetFactory as well as those with custom bindings.\n'; +text += '<ul>\n'; + + +var hrefroot = 'jsref/'; +var cons = constructors().sort(); +for ( var i = 0; i < cons.length; i++ ) { + text += '<li>'; + var href = cons[i].toLowerCase() + '.html'; + var name = cons[i]; + text += '<a href="' + hrefroot + href + '">' + name + '</a>\n'; +} +text += '</ul>\n'; +text += '<hr>\n'; +text += '</body>\n'; + +text += '</html>'; + +println( text ); + diff --git a/kjsembed/docs/write_docs.js b/kjsembed/docs/write_docs.js new file mode 100644 index 00000000..91e7c7a6 --- /dev/null +++ b/kjsembed/docs/write_docs.js @@ -0,0 +1,26 @@ + +var name = application.args[0]; +var src = application.args[1]; +var desc = application.args[2]; +var obj = eval(src); + +println( '<html>' ); + +println( '<head>' ); +println( '<title>' + name + '</title>' ); +println( '<link href="../kjsembed.css" rel="stylesheet" type="text/css">' ); +println( '</head>' ); + +println( '<body>' ); +println( '<h1>' + name + '</h1>' ); +println( '<hr>' ); + +println( desc ); +println( dump(obj) ); +println( '<hr>' ); +println( '</body>' ); + +println( '</html>' ); + +application.quit(); + diff --git a/kjsembed/doxygen_fakes.h b/kjsembed/doxygen_fakes.h new file mode 100644 index 00000000..653f0ec4 --- /dev/null +++ b/kjsembed/doxygen_fakes.h @@ -0,0 +1,25 @@ + +/** An object that supports signals and slots. */ +class QObject {}; +/** Base-class of all widgets. */ +class QWidget : public QObject {}; +/** A widget that has a frame. */ +class QFrame : public QWidget {}; + +/** Namespace for the KParts framework. */ +namespace KParts { + /** A base-class for plugins that extend a KPart. */ + class Plugin : public QObject, public XMLGUIClient {}; + /** A base-class for KParts. */ + class Part : public QObject, public XMLGUIClient {}; + /** A base-class for KParts that provide a read-only view. */ + class ReadOnlyPart : public Part {}; +}; + +/** Namespace for the KJS interpreter library. */ +namespace KJS { + /** Provides the implementation for a KJS object. */ + class ObjectImp {}; +}; + + diff --git a/kjsembed/global.cpp b/kjsembed/global.cpp new file mode 100644 index 00000000..1f424dcd --- /dev/null +++ b/kjsembed/global.cpp @@ -0,0 +1,178 @@ +/*************************************************************************** + * Copyright (C) 2004 by Richard Moore * + * rich@kde.org * + * * + * This program 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. * + * * + * 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 Library 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. * + ***************************************************************************/ + +# include "global.h" + +#ifdef QT_ONLY +# include <qobject.h> +# include <cstdio> +# ifdef _WIN32 +# include <windows.h> +# include <fcntl.h> +# include <io.h> +# include <iostream.h> +# include <qfile.h> +# endif +#endif + +static QTextStream *kjsembed_err = 0L; +static QTextStream *kjsembed_in = 0L; +static QTextStream *kjsembed_out = 0L; + +#ifndef _WIN32 +char *itoa(int num, char *str, int radix) +{ + int k; + char c, flag, *ostr; + + if (num < 0) { + num = -num; + *str++ = '-'; + } + k = 10000; + ostr = str; + flag = 0; + while (k) { + c = num / k; + if (c || k == 1 || flag) { + num %= k; + c += '0'; + *str++ = c; + flag = 1; + } + k /= 10; + } + *str = '\0'; + return ostr; +} + +#endif + +#ifdef _WIN32 +static QFile win32_stdin; +static QFile win32_stdout; +static QFile win32_stderr; + +static const WORD MAX_CONSOLE_LINES = 500; + +void RedirectIOToConsole() { + int hConHandle; + long lStdHandle; + CONSOLE_SCREEN_BUFFER_INFO coninfo; + AllocConsole(); + GetConsoleScreenBufferInfo(GetStdHandle(STD_OUTPUT_HANDLE), &coninfo); + coninfo.dwSize.Y = MAX_CONSOLE_LINES; + SetConsoleScreenBufferSize(GetStdHandle(STD_OUTPUT_HANDLE), coninfo.dwSize); + + lStdHandle = (long)GetStdHandle(STD_INPUT_HANDLE); + hConHandle = _open_osfhandle(lStdHandle, _O_TEXT); + win32_stdin.open(IO_ReadOnly,hConHandle); + + lStdHandle = (long)GetStdHandle(STD_OUTPUT_HANDLE); + hConHandle = _open_osfhandle(lStdHandle, _O_TEXT); + win32_stdout.open(IO_WriteOnly,hConHandle ); + + lStdHandle = (long)GetStdHandle(STD_ERROR_HANDLE); + hConHandle = _open_osfhandle(lStdHandle, _O_TEXT); + win32_stderr.open(IO_WriteOnly,hConHandle); + + ios::sync_with_stdio(); + +} + + + +#endif + + +QTextStream &consoleOut( ) +{ + return *KJSEmbed::conout(); +} + +QTextStream &consoleError( ) +{ + return *KJSEmbed::conerr(); +} + +QTextStream &consoleIn( ) +{ + return *KJSEmbed::conin(); +} + +#ifdef QT_ONLY +QTextStream &kdDebug( int area ) +{ +#ifndef QT_DEBUG + return consoleError() << "DEBUG: (" << area << ") "; +#else + return consoleOut(); +#endif + +} + +QTextStream &kdWarning( int area ) +{ + return consoleOut() << "WARNING: (" << area << ") "; +} + +QString i18n( const char *string ) +{ + return QObject::tr( string, "qjsembed string"); +} + +#endif + +QTextStream *KJSEmbed::conin() +{ + if ( !kjsembed_in ) { +#ifdef _WIN32 + kjsembed_in = new QTextStream( &win32_stdin ); +#else + kjsembed_in = new QTextStream( stdin, IO_ReadOnly ); +#endif + } + return kjsembed_in; +} + +QTextStream *KJSEmbed::conout() +{ + if ( !kjsembed_out ) { +#ifdef _WIN32 + kjsembed_out = new QTextStream( &win32_stdout ); +#else + kjsembed_out = new QTextStream( stdout, IO_WriteOnly ); +#endif + } + return kjsembed_out; + +} + +QTextStream *KJSEmbed::conerr() +{ + if ( !kjsembed_err ) { +#ifdef _WIN32 + kjsembed_err = new QTextStream( &win32_stderr ); +#else + kjsembed_err = new QTextStream( stderr, IO_WriteOnly ); +#endif + } + return kjsembed_err; +} diff --git a/kjsembed/global.h b/kjsembed/global.h new file mode 100644 index 00000000..fe9447a1 --- /dev/null +++ b/kjsembed/global.h @@ -0,0 +1,90 @@ +// -*- c++ -*- +/*************************************************************************** + * Copyright (C) 2004 by Richard Moore * + * rich@kde.org * + * * + * This program 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. * + * * + * 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 Library 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. * + ***************************************************************************/ + +#ifndef KJSEMBED_GLOBAL_H +#define KJSEMBED_GLOBAL_H + +#include <kdemacros.h> + +#ifdef WIN32 +# ifdef KJSEMBED_DLL +# ifdef KJSEMBED_MAKE_DLL +# define KJSEMBED_EXPORT __declspec(dllexport) +# else +# define KJSEMBED_EXPORT __declspec(dllimport) +# endif // KJSEMBED_MAKE_DLL +# else +# define KJSEMBED_EXPORT +# endif // KJSEMBED_DLL +#else +# ifdef KDE_EXPORT +# define KJSEMBED_EXPORT KDE_EXPORT +# else +# define KJSEMBED_EXPORT +# endif +#endif // WIN32 + +#ifdef WIN32 +#include <stdlib.h> +KJSEMBED_EXPORT void RedirectIOToConsole(); +#endif + +#ifndef WIN32 +#include <ctype.h> +#include <stdlib.h> +char *itoa(int num, char *str, int radix = 10); +#endif + +#include <qtextstream.h> +namespace KJSEmbed { +KJSEMBED_EXPORT QTextStream *conin(); +KJSEMBED_EXPORT QTextStream *conout(); +KJSEMBED_EXPORT QTextStream *conerr(); +} + +#ifndef QT_ONLY + +/* + * These are the normal definitions used when KDE is available. + */ + +#include <kdebug.h> +#include <klocale.h> + +#else // QT_ONLY + +/* + * These are the custom definitions used when we only have Qt. + */ + +KJSEMBED_EXPORT QTextStream &kdDebug( int area=0 ); +KJSEMBED_EXPORT QTextStream &kdWarning( int area=0 ); + +#ifndef NO_I18N +KJSEMBED_EXPORT QString i18n( const char *string ); +#else +#define i18n(x) QString(x) +#endif // NO_I18N + +#endif // QT_ONLY + +#endif // KJSEMBED_GLOBAL_H + diff --git a/kjsembed/jsbinding.cpp b/kjsembed/jsbinding.cpp new file mode 100644 index 00000000..df34caf7 --- /dev/null +++ b/kjsembed/jsbinding.cpp @@ -0,0 +1,789 @@ +#include <qmetaobject.h> +#include <private/qucom_p.h> + +#include <qpen.h> +#include <qpixmap.h> +#include <qimage.h> +#include <qvariant.h> +#include <qdatetime.h> +#include <qsize.h> + +#include <kjs/interpreter.h> +#include <kjs/ustring.h> +#include <kjs/types.h> +#include <kjs/value.h> + +#include "global.h" +#include "jsbinding.h" +#include "jsobjectproxy.h" +#include "jsfactory.h" +#include "jsvalueproxy.h" +#include "jsopaqueproxy.h" +#include "jsbuiltinproxy.h" +#include "kjsembedpart.h" + +#include "bindings/pen_imp.h" +#include "bindings/image_imp.h" +#include "bindings/pixmap_imp.h" +#include "bindings/painter_imp.h" +#include "bindings/brush_imp.h" +#include "bindings/size_imp.h" +#include "bindings/point_imp.h" +#include "bindings/rect_imp.h" + +#include <stdlib.h> + +namespace KJSEmbed { + + // + // + // Supported + // ========= + // + // Bool, Double, CString, String, StringList, Int, UInt, Date, Time, DateTime, + // Rect, Size, Point, Pixmap, Image, Brush, Pen, Size, Rect, Point, QValueList<QVariant> + // + // Opqaue + // ====== + // + // Invalid, Map, List, Palette, ColorGroup, + // IconSet, PointArray, Region, Bitmap, Cursor, SizePolicy, + // ByteArray, BitArray + // + + KJS::Value convertToValue( KJS::ExecState *exec, const QVariant &val ) { + if ( !val.isValid() ) + return KJS::Undefined(); + + kdDebug( 80001 ) << "Convert a " << val.typeName() << " to a value" << endl; + KJS::List items; + uint type = val.type(); + + switch( type ) + { + case QVariant::String: + case QVariant::CString: + return KJS::String( val.toString() ); + break; + case QVariant::Int: + return KJS::Number( val.toInt() ); + break; + case QVariant::UInt: + return KJS::Number( val.toUInt() ); + break; + case QVariant::Double: + return KJS::Number( val.toDouble() ); + break; + case QVariant::Bool: + return KJS::Boolean( val.toBool() ); + break; + case QVariant::Rect: + { + JSValueProxy * prx = new JSValueProxy( ); + prx->setValue( val ); + KJS::Object proxyObj( prx ); + Bindings::Rect::addBindings( exec, proxyObj ); + return proxyObj; + break; + } + case QVariant::Date: + case QVariant::DateTime: + case QVariant::Time: + { + QDateTime dt = QDateTime::currentDateTime(); + if ( type == QVariant::Date ) + dt.setDate( val.toDate() ); + else if ( type == QVariant::Time ) + dt.setTime( val.toTime() ); + else + dt = val.toDateTime(); + items.append( KJS::Number( dt.date().year() ) ); + items.append( KJS::Number( dt.date().month() - 1 ) ); + items.append( KJS::Number( dt.date().day() ) ); + items.append( KJS::Number( dt.time().hour() ) ); + items.append( KJS::Number( dt.time().minute() ) ); + items.append( KJS::Number( dt.time().second() ) ); + items.append( KJS::Number( dt.time().msec() ) ); + return KJS::Object( exec->interpreter() ->builtinDate().construct( exec, items ) ); + break; + } + case QVariant::Point: + { + JSValueProxy * prx = new JSValueProxy( ); + prx->setValue( val ); + KJS::Object proxyObj( prx ); + Bindings::Point::addBindings( exec, proxyObj ); + return proxyObj; + break; + } + case QVariant::StringList: + { + QStringList lst = val.toStringList(); + QStringList::Iterator idx = lst.begin(); + for ( ; idx != lst.end(); ++idx ) + items.append( KJS::String( ( *idx ) ) ); + return KJS::Object( exec->interpreter() ->builtinArray().construct( exec, items ) ); + break; + } + case QVariant::List: +// case QVariant::StringList: +// This will cause an extra conversion step for a QStrinList so use the above case. + { + QValueList<QVariant> lst = val.toList(); + QValueList<QVariant>::Iterator idx = lst.begin(); + for ( ; idx != lst.end(); ++idx ) + items.append( convertToValue( exec, ( *idx ) ) ); + return KJS::Object( exec->interpreter() ->builtinArray().construct( exec, items ) ); + break; + } + case QVariant::Map: + { + QMap<QString,QVariant> map = val.toMap(); + QMap<QString,QVariant>::Iterator idx = map.begin(); + KJS::Object array( exec->interpreter() ->builtinArray().construct( exec, 0 ) ); + for ( ; idx != map.end(); ++idx ) + array.put(exec, KJS::Identifier(idx.key().latin1()), convertToValue( exec, idx.data() ) ); + return array; + break; + } + case QVariant::Pixmap: + { + JSValueProxy * prx = new JSValueProxy( ); + prx->setValue( val ); + KJS::Object proxyObj( prx ); + Bindings::Pixmap::addBindings( exec, proxyObj ); + return proxyObj; + break; + } + case QVariant::Brush: + { + JSValueProxy * prx = new JSValueProxy( ); + prx->setValue( val ); + KJS::Object proxyObj( prx ); + Bindings::BrushImp::addBindings( exec, proxyObj ); + return proxyObj; + } + case QVariant::Image: + { + JSValueProxy * prx = new JSValueProxy( ); + prx->setValue( val ); + KJS::Object proxyObj( prx ); + Bindings::ImageImp::addBindings( exec, proxyObj ); + return proxyObj; + break; + } + case QVariant::Pen: + { + JSValueProxy * prx = new JSValueProxy( ); + prx->setValue( val ); + KJS::Object proxyObj( prx ); + Bindings::Pen::addBindings( exec, proxyObj ); + return proxyObj; + break; + } + case QVariant::Size: + { + JSValueProxy * prx = new JSValueProxy( ); + prx->setValue( val ); + KJS::Object proxyObj( prx ); + Bindings::Size::addBindings( exec, proxyObj ); + return proxyObj; + break; + } + default: + { + if ( val.canCast( QVariant::String ) ) + return KJS::String( val.toString() ); + else + { + kdDebug( 80001 ) << "convertToValue() Creating value, type wrapper for " << val.typeName() << endl; + + JSValueProxy *valproxy = new JSValueProxy(); + KJS::Object obj = KJS::Object( valproxy ); + valproxy->addBindings( exec, obj ); + valproxy->setValue( val ); + + return obj; + } + } + } + } + + QVariant convertToVariant( KJS::ExecState *exec, const KJS::Value &v ) { + QVariant val; + KJS::Type type = v.type(); + kdDebug( 80001 ) << "Convert a value of type " << type << " to a variant" << endl; + switch( type ) + { + case KJS::StringType: + val = v.toString( exec ).qstring(); + break; + case KJS::NumberType: + val = v.toNumber( exec ); + break; + case KJS::BooleanType: + val = v.toBoolean( exec ); + break; + case KJS::ObjectType: + { + KJS::Object obj = v.toObject( exec ); + kdDebug( 80001 ) << "convertToVariant() got an " << obj.className().qstring() << endl; + if ( obj.className().qstring() == "Array" ) { + if ( checkArray( exec, v ) == List ) + val = convertArrayToList( exec, v ); + else + val = convertArrayToMap(exec, v); + } else if ( obj.className().qstring() == "Date" ) { + val = convertDateToDateTime( exec, v ); + } else if ( obj.className().qstring() == "Function" ) { + /* val = obj.className().qstring();*/ + } else { + //JSObjectProxy *prx = JSProxy::toObjectProxy( obj.imp() ); + JSValueProxy *vprx = JSProxy::toValueProxy(obj.imp() ); + //JSOpaqueProxy *oprx = JSProxy::toOpaqueProxy( obj.imp() ); + JSProxy *prxy = dynamic_cast<JSProxy*>(obj.imp()); + /* + kdDebug(80001) << "Type " << obj.imp()->dispatchType() << endl; + + kdDebug(80001) << "Object proxy: " << prx << " Value Proxy: " << vprx << " Opaque Proxy " << oprx << " Proxy " << prxy << endl; + kdDebug(80001) << "Object prototype valid " << obj.prototype().isValid() << endl; + kdDebug(80001) << "Prototype name: " << obj.prototype().toString(exec).ascii() << endl; + kdDebug(80001) << "Proxy imp " << dynamic_cast<JSProxyImp*>(obj.imp()) << endl; + kdDebug(80001) << "Builtin " << dynamic_cast<JSBuiltinProxy*>(obj.imp()) << endl; + */ + /*if ( prx ) { + + QObject * o = prx->object(); + QCString cs( o ? o->className() : "" ); + if ( obj.implementsConstruct() ) + val = QString( "new %1();" ).arg( obj.className().qstring() ); + else if ( obj.implementsCall() ) + val = QString( "%1(...);" ).arg( obj.className().qstring() ); + kdDebug( 80001 ) << "convertToVariant() got a JSObjectProxy" << endl; + } else */if ( vprx ) { + kdDebug( 80001 ) << "convertToVariant() got a variant JSValueProxy" << endl; + val = vprx->toVariant(); + } else if ( prxy ) { + /* kdDebug( 80001 ) << "convertToVariant() got a JSProxy" << endl; + val = prxy->typeName(); + */ + } else { // Last resort map the object to a QMap<QString,QVariant> + kdDebug( 80001 ) << "convertToVariant() map to struct." << endl; + val = convertArrayToMap(exec, v); + } + } + break; + } + default: + { + QString msg = i18n( "Unsupported KJS::Value, type %1" ).arg( ( int ) v.type() ); + throwError(exec, msg); + val = msg; + break; + } + } + kdDebug(80001) << "Returning a " << val.typeName() << endl; + return val; + } + + QStringList dumpCompletion( KJS::ExecState *exec, KJS::Object &obj ) { + QStringList returnList; + if ( !obj.isValid() ) { + return returnList; + } + + KJS::ReferenceList l = obj.propList( exec ); + KJS::ReferenceListIterator propIt = l.begin(); + while ( propIt != l.end() ) { + + KJS::Identifier name = propIt->getPropertyName( exec ); + if ( obj.hasProperty( exec, name ) ) { + KJS::Value v = obj.get( exec, name ); + KJS::Object vobj = v.toObject( exec ); + QString nm( name.ustring().qstring() ); + QString vl; + + if ( vobj.implementsConstruct() ) { + if ( vobj.prototype().toString( exec ).qstring() == "[function]" ) + returnList << QString( "%1(...)" ).arg( nm ); + } else if ( vobj.implementsCall() ) { + returnList << QString( "%1(...)" ).arg( nm ); + } else { + QVariant val = convertToVariant( exec, v ); + vl = val.toString(); + returnList << nm; + } + } + + propIt++; + } + + JSObjectProxy *proxy = JSProxy::toObjectProxy( obj.imp() ); + QObject *qo = proxy ? proxy->object() : 0; + QMetaObject *mo = qo ? qo->metaObject() : 0; + + // QObject + if ( proxy ) { + + // QProperties + QStrList propList( mo->propertyNames( true ) ); + for ( QStrListIterator iter1( propList ); iter1.current(); ++iter1 ) { + + QCString name = iter1.current(); + int propid = mo->findProperty( name.data(), true ); + if ( propid == -1 ) + continue; + returnList << name; + } + + // Slots + KJS::List items; + QStrList slotList( mo->slotNames( true ) ); + + for ( QStrListIterator iter2( slotList ); iter2.current(); ++iter2 ) { + QCString name = iter2.current(); + QString nm( name ); + + int slotid = mo->findSlot( name.data(), true ); + if ( slotid != -1 ) { + returnList << nm; + } + } + } + return returnList; + } + + QString dumpObject( KJS::ExecState *exec, KJS::Object &obj ) { + if ( !obj.isValid() ) + return QString( "Invalid object\n" ); + + QStringList properties; + QStringList methods; + + KJS::ReferenceList l = obj.propList( exec, true ); + KJS::ReferenceListIterator propIt = l.begin(); + + while ( propIt != l.end() ) { + + KJS::Identifier name = propIt->getPropertyName( exec ); + + if ( obj.hasProperty( exec, name ) ) { + + KJS::Value v = obj.get( exec, name ); + KJS::Object vobj = v.toObject( exec ); + QString nm( name.ustring().qstring() ); + + kdDebug( 80001 ) << "Getting: " << name.ustring().qstring() << " " + << vobj.prototype().toString( exec ).qstring() << endl; + + if ( vobj.implementsConstruct() ) { + // Do nothing + kdDebug( 80001 ) << "implementsConstruct: " << nm << endl; + if ( vobj.prototype().toString( exec ).qstring() == "[function]" ) + methods += nm; + } else if ( vobj.implementsCall() ) { + kdDebug( 80001 ) << "implementsCall: " << nm << endl; + methods += nm; + } else { + properties += nm; + } + } + + propIt++; + } + + QString s; + + // JS properties + s += QString( "<h2>Properties</h2>\n" ); + + if ( !properties.isEmpty() ) { + s += "<table width=\"90%\">\n"; + s += "<tr><th>Type</th><th>Name</th><th>Value</th></tr>\n"; + + properties.sort(); + for ( QStringList::Iterator iter = properties.begin(); iter != properties.end(); ++iter ) { + KJS::Value v = obj.get( exec, KJS::Identifier( KJS::UString( *iter ) ) ); + QVariant val = convertToVariant( exec, v ); + + s += QString( "<tr><td align=\"center\">%1</td><td><b>%2</b></td><td align=\"center\">%3</td></tr>\n" ) + .arg( val.typeName() ).arg( *iter ).arg( val.toString() ); + } + + s += "</table>\n"; + } else + s += "<i>None</i>\n"; + + // Methods + s += QString( "<h2>Methods</h2>\n" ); + + if ( !methods.isEmpty() ) { + s += "<table width=\"90%\">"; + methods.sort(); + for ( QStringList::Iterator iter = methods.begin(); iter != methods.end(); ++iter ) { + s += "<tr><td><b>"; + s += *iter; + s += "(...)</b></td></tr>"; + } + s += "</table>"; + } else + s += "<i>None</i>\n"; + + s += dumpQObject( exec, obj ); + return s; + } + + QString dumpQObject( KJS::ExecState * /*exec*/, KJS::Object &obj ) { + if ( !obj.isValid() ) + return QString( "Invalid object\n" ); + + QString s( "" ); + JSObjectProxy *proxy = JSProxy::toObjectProxy( obj.imp() ); + QObject *qo = proxy ? proxy->object() : 0; + QMetaObject *mo = qo ? qo->metaObject() : 0; + + // QObject + if ( proxy ) { + + // QProperties + s += QString( "<h2>Qt Properties</h2>\n" ); + + QStrList propList( mo->propertyNames( true ) ); + + if ( !propList.isEmpty() ) { + + s += "<table width=\"90%\">\n"; + s += "<tr><th>Type</th><th>Name</th><th>Value</th></tr>\n"; + + propList.sort(); + for ( QStrListIterator iter( propList ); iter.current(); ++iter ) { + + QCString name = iter.current(); + int propid = mo->findProperty( name.data(), true ); + if ( propid == -1 ) + continue; + + QVariant vl = qo->property( name.data() ); + s += QString( "<tr><td align=\"center\">%1</td><td><b>%2</b></td><td align=\"center\">%3</td></tr>\n" ) + .arg( mo->property( propid, true ) ->type() ).arg( name ).arg( vl.toString() ); + } + + s += "</table>\n"; + } else { + s += "<i>None</i>"; + } + + // Signals + s += QString( "<h2>Qt Signals</h2>\n" ); + s += "<table width=\"90%\">"; + + QStrList signalList( mo->signalNames( true ) ); + signalList.sort(); + + for ( QStrListIterator iter1( signalList ); iter1.current(); ++iter1 ) { + + QCString name = iter1.current(); + QString nm( name ); + + int signalid = mo->findSignal( name.data(), true ); + if ( signalid != -1 ) + s += QString( "<tr><td><b>%1</b></td></tr>\n" ).arg( nm ); + } + + s += "</table>"; + if ( signalList.isEmpty() ) + s += "<i>None</i>"; + + // Slots + s += QString( "<h2>Qt Slots</h2>\n" ); + s += "<table width=\"90%\">"; + + KJS::List items; + QStrList slotList( mo->slotNames( true ) ); + slotList.sort(); + + for ( QStrListIterator iter2( slotList ); iter2.current(); ++iter2 ) { + + QCString name = iter2.current(); + QString nm( name ); + + int slotid = mo->findSlot( name.data(), true ); + if ( slotid != -1 ) { + const QMetaData * md = mo->slot( slotid, true ); + const QUMethod *method = md->method; + if ( method->count && ( method->parameters->inOut == QUParameter::Out ) ) { + QCString typenm( method->parameters->type->desc() ); + if ( typenm == "ptr" ) { + s += QString( "<tr><td>%1</td><td><b>%2</b></td></tr>\n" ) + .arg( ( const char * ) method->parameters->typeExtra ).arg( nm ); + } else { + s += QString( "<tr><td>%1</td><td><b>%2</b></td></tr>\n" ) + .arg( typenm.data() ).arg( nm ); + } + } else + s += QString( "<tr><td>void</td><td><b>%1</b></td></tr>\n" ).arg( nm ); + } + } + + s += "</table>"; + if ( slotList.isEmpty() ) + s += "<i>None</i>"; + } + + return s; + } + + + + QPen extractQPen( KJS::ExecState *exec, const KJS::List &args, int idx ) { + return ( args.size() > idx ) ? convertToVariant( exec, args[ idx ] ).toPen() : QPen(); + } + + QBrush extractQBrush( KJS::ExecState *exec, const KJS::List &args, int idx ) { + return ( args.size() > idx ) ? convertToVariant( exec, args[ idx ] ).toBrush() : QBrush(); + } + + QFont extractQFont( KJS::ExecState *exec, const KJS::List &args, int idx ) { + return ( args.size() > idx ) ? convertToVariant( exec, args[ idx ] ).toFont() : QFont(); + } + + QPixmap extractQPixmap( KJS::ExecState *exec, const KJS::List &args, int idx ) { + return ( args.size() > idx ) ? convertToVariant( exec, args[ idx ] ).toPixmap() : QPixmap(); + } + + QImage extractQImage( KJS::ExecState *exec, const KJS::List &args, int idx ) { + return ( args.size() > idx ) ? convertToVariant( exec, args[ idx ] ).toImage() : QImage(); + } + + QPalette extractQPalette( KJS::ExecState *exec, const KJS::List &args, int idx ) { + return ( args.size() > idx ) ? convertToVariant( exec, args[ idx ] ).toPalette() : QPalette(); + } + + QString extractQString( KJS::ExecState *exec, const KJS::List &args, int idx ) { + return ( args.size() > idx ) ? args[ idx ].toString( exec ).qstring() : QString::null; + } + + int extractInt( KJS::ExecState *exec, const KJS::List &args, int idx ) { + return ( args.size() > idx ) ? args[ idx ].toInteger( exec ) : 0; + } + + QColor extractQColor( KJS::ExecState *exec, const KJS::List &args, int idx ) { + return ( args.size() > idx ) ? convertToVariant( exec, args[ idx ] ).toColor() : QColor(); + } + + QSize extractQSize( KJS::ExecState *exec, const KJS::List &args, int idx ) { + return ( args.size() > idx ) ? convertToVariant( exec, args[ idx ] ).toSize() : QSize(); + } + + bool extractBool( KJS::ExecState *exec, const KJS::List &args, int idx ) { + return ( args.size() > idx ) ? args[ idx ].toBoolean( exec ) : false; + } + + double extractDouble( KJS::ExecState *exec, const KJS::List &args, int idx ) { + return ( args.size() > idx ) ? args[ idx ].toNumber( exec ) : 0.0; + } + + uint extractUInt( KJS::ExecState *exec, const KJS::List &args, int idx ) { + return ( args.size() > idx ) ? args[ idx ].toUInt32( exec ) : 0; + } + + QStringList extractQStringList( KJS::ExecState *exec, const KJS::List &args, int idx ) { + return ( args.size() > idx ) ? convertArrayToStringList( exec, args[ idx ] ) : QStringList(); + } + + /** + * This will return if the value is a list, associative array or neither + * @return + */ + + JavaScriptArrayType checkArray( KJS::ExecState *exec, const KJS::Value &val ) { + KJS::Object obj = val.toObject( exec ); + kdDebug( 80001 ) << "Object type: " << obj.className().qstring() << endl; + if ( obj.className().qstring() == "Array" ) { + //KJS::ReferenceList lst = obj.propList( exec, true ); + KJS::Value len = obj.get(exec, KJS::Identifier("length")); + kdDebug(80001) << "Array length: " << len.toNumber(exec) << endl; + kdDebug(80001) << "Object type: " << len.type() << endl; + char buff[4]; + if( !obj.hasProperty(exec, KJS::Identifier("length")) ) + return Map; + else if( !obj.hasProperty(exec, KJS::Identifier( itoa((len.toNumber(exec) - 1), buff, 10 ) ) ) ) + return Map; + /* + if( obj.get(exec, KJS::Identifier("length")).toInteger(exec) == 0 ) + return List; + int offset = 0; + KJS::ReferenceListIterator idx = lst.begin(); + for ( ; idx != lst.end(); idx++ ) { + if ( idx->getPropertyName( exec ).qstring().toInt() != offset ) + return Map; + offset++; + kdDebug( 80001 ) << "Property Name: " << idx->getPropertyName( exec ).qstring() << endl; + kdDebug( 80001 ) << "Property Value: " << idx->getValue( exec ).toString( exec ).qstring() << endl; + } + */ + else + return List; + } else + return None; + } + + QMap<QString, QVariant> convertArrayToMap( KJS::ExecState *exec, const KJS::Value &value ) { + QMap<QString, QVariant> returnMap; + KJS::Object obj = value.toObject(exec); +// if( obj.className().qstring() == "Array" ) { + KJS::ReferenceList lst = obj.propList(exec,false); + KJS::ReferenceListIterator idx = lst.begin(); + for( ; idx != lst.end(); idx++ ) + { + KJS::Identifier id = idx->getPropertyName(exec); + KJS::Value val = idx->getValue(exec); + returnMap.insert(id.qstring(),convertToVariant(exec,val)); + } +// } + return returnMap; + } + + QValueList<QVariant> convertArrayToList( KJS::ExecState *exec, const KJS::Value &value ) { + QValueList<QVariant> returnList; + KJS::Object obj = value.toObject( exec ); + if ( obj.className().qstring() == "Array" ) { + int length = obj.get( exec, KJS::Identifier( "length" ) ).toInteger( exec ); + for ( int index = 0; index < length; ++index ) { + char buff[4]; + KJS::Value val = obj.get(exec, KJS::Identifier( itoa( index, buff, 10 ) ) ); + if( val.isValid() ) + returnList += convertToVariant(exec, val ); + else + returnList += ""; + } + } + return returnList; + } + + QStringList convertArrayToStringList( KJS::ExecState *exec, const KJS::Value &value ) { + QStringList returnList; + KJS::Object obj = value.toObject( exec ); + if ( obj.className().qstring() == "Array" ) { + int length = obj.get( exec, KJS::Identifier( "length" ) ).toInteger( exec ); + for ( int index = 0; index < length; ++index ) { + char buff[4]; + KJS::Value val = obj.get(exec, KJS::Identifier( itoa( index, buff, 10 ) ) ); + + if( val.isValid() ) + returnList += val.toString(exec).qstring(); + else + returnList += ""; + } + } + return returnList; + } +/* + QStringList convertArrayToStringList( KJS::ExecState *exec, const KJS::Value &value ) { + QStringList returnList; + KJS::Object obj = value.toObject( exec ); + + if ( obj.className().qstring() == "Array" ) { + int length = obj.get( exec, KJS::Identifier( "length" ) ).toInteger( exec ); + for ( int index = 0; index < length; ++index ) { + returnList << obj.get( exec, KJS::Identifier( KJS::UString::from( index ) ) ).toString( exec ).qstring(); + } + } + + return returnList; + } +*/ + QDateTime convertDateToDateTime( KJS::ExecState *exec, const KJS::Value &value ) { + KJS::List args; + QDateTime returnDateTime; + KJS::Object obj = value.toObject( exec ); + + if ( obj.className().qstring() == "Date" ) { + int seconds = obj.get( exec, KJS::Identifier( "getSeconds" ) ).toObject( exec ).call( exec, obj, args ).toInteger( exec ); + int minutes = obj.get( exec, KJS::Identifier( "getMinutes" ) ).toObject( exec ).call( exec, obj, args ).toInteger( exec ); + int hours = obj.get( exec, KJS::Identifier( "getHours" ) ).toObject( exec ).call( exec, obj, args ).toInteger( exec ); + int month = obj.get( exec, KJS::Identifier( "getMonth" ) ).toObject( exec ).call( exec, obj, args ).toInteger( exec ); + int day = obj.get( exec, KJS::Identifier( "getDate" ) ).toObject( exec ).call( exec, obj, args ).toInteger( exec ); + int year = obj.get( exec, KJS::Identifier( "getFullYear" ) ).toObject( exec ).call( exec, obj, args ).toInteger( exec ); + + returnDateTime.setDate( QDate( year, month + 1, day ) ); + returnDateTime.setTime( QTime( hours, minutes, seconds ) ); + } else { + kdWarning() << "convertDateToDateTime() received a " << obj.className().qstring() << " instead of a Date" << endl; + } + + return returnDateTime; + } + + QDateTime extractQDateTime( KJS::ExecState * exec, const KJS::List & args, int idx ) { + return ( args.size() > idx ) ? convertDateToDateTime( exec, args[ idx ] ) : QDateTime(); + } + + QDate extractQDate( KJS::ExecState * exec, const KJS::List & args, int idx ) { + return ( args.size() > idx ) ? convertDateToDateTime( exec, args[ idx ] ).date() : QDate(); + } + + QTime extractQTime( KJS::ExecState * exec, const KJS::List & args, int idx ) { + return ( args.size() > idx ) ? convertDateToDateTime( exec, args[ idx ] ).time() : QTime(); + } + + QRect extractQRect( KJS::ExecState * exec, const KJS::List & args, int idx ) { + return ( args.size() > idx ) ? convertToVariant( exec, args[ idx ] ).toRect() : QRect(); + } + + QPoint extractQPoint( KJS::ExecState * exec, const KJS::List & args, int idx ) { + return ( args.size() > idx ) ? convertToVariant( exec, args[ idx ] ).toPoint() : QPoint(); + } + + QStrList extractQStrList( KJS::ExecState *exec, const KJS::List &args, int idx ) { + return ( args.size() > idx ) ? convertArrayToStrList( exec, args[ idx ] ) : QStrList(); + } + + QStrList convertArrayToStrList( KJS::ExecState *exec, const KJS::Value &value ) { + QStrList returnList; + KJS::Object obj = value.toObject( exec ); + + if ( obj.className().qstring() == "Array" ) { + int length = obj.get( exec, KJS::Identifier( "length" ) ).toInteger( exec ); + for ( int index = 0; index < length; ++index ) { + returnList.append( obj.get( exec, KJS::Identifier( KJS::UString::from( index ) ) ).toString( exec ).qstring().latin1() ); + } + } + + return returnList; + } + + QObject *extractQObject( KJS::ExecState *exec, const KJS::List &args, int idx ) { + KJS::Object obj = args[ idx ].toObject( exec ); + JSObjectProxy *proxy = JSProxy::toObjectProxy( obj.imp() ); + if ( !proxy ) + return 0L; + return proxy->object(); + + } + + QWidget *extractQWidget( KJS::ExecState *exec, const KJS::List &args, int idx ) { + KJS::Object obj = args[ idx ].toObject( exec ); + JSObjectProxy *proxy = JSProxy::toObjectProxy( obj.imp() ); + if ( !proxy ) + return 0L; + return proxy->widget(); + } + + JSOpaqueProxy *extractOpaqueProxy( KJS::ExecState *exec, const KJS::List &args, int idx ) { + KJS::Object obj = args[ idx ].toObject( exec ); + return JSProxy::toOpaqueProxy( obj.imp() ); + } + + KJS::Object throwError( KJS::ExecState *exec, const QString &error, KJS::ErrorType type ) + { + int sourceId = exec->context().sourceId(); + int startLine = exec->context().curStmtFirstLine(); + + KJS::Object retValue = KJS::Error::create( exec, type, error.utf8(), startLine, sourceId ); + kdWarning(80001) << error << endl; + exec->setException( retValue ); + return retValue; + } +} // namespace KJSEmbed + diff --git a/kjsembed/jsbinding.h b/kjsembed/jsbinding.h new file mode 100644 index 00000000..40e2f11e --- /dev/null +++ b/kjsembed/jsbinding.h @@ -0,0 +1,138 @@ +// -*- c++ -*- + +/* + * Copyright (C) 2001-2002, Richard J. Moore <rich@kde.org> + * + * This 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. + * + * This 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 this library; see the file COPYING.LIB. If not, write to + * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, + * Boston, MA 02110-1301, USA. + */ + +#ifndef KJSEMBEDJSBINDING_H +#define KJSEMBEDJSBINDING_H +#include "global.h" +#include <qstring.h> +#include <qvariant.h> +#include <qwidget.h> + +#include <kjs/interpreter.h> +#include <kjs/object.h> +#include <kjs/types.h> + +/** + * Implement QString-KJS::UString conversion methods. These methods are declared + * by KJS, but libkjs doesn't actually contain their implementations. + * + * @version $Id$ + */ +namespace KJS { + + inline UString::UString( const QString &d ) + { + uint len = d.length(); + UChar *dat = new UChar[len]; + memcpy( dat, d.unicode(), len * sizeof(UChar) ); + rep = UString::Rep::create(dat, len); + } + + inline QString UString::qstring() const + { + return QString((QChar*) data(), size()); + } + + inline QConstString UString::qconststring() const + { + return QConstString((QChar*) data(), size()); + } + + inline QString Identifier::qstring() const + { + return QString((QChar*) data(), size()); + } + +} + +namespace KJSEmbed { + class JSObjectProxy; + class JSOpaqueProxy; + + enum JavaScriptArrayType { None, List, Map }; + + KJSEMBED_EXPORT JavaScriptArrayType checkArray( KJS::ExecState *exec, const KJS::Value &val ); + + /** Converts a QVariant to the closest possible KJS::Value. */ + KJSEMBED_EXPORT KJS::Value convertToValue( KJS::ExecState *exec, const QVariant &val); + + /** Converts a KJS::Value to the closest possible QVariant. */ + KJSEMBED_EXPORT QVariant convertToVariant( KJS::ExecState *exec, const KJS::Value &v ); + + /** Returns HTML that documents the specified object. */ + KJSEMBED_EXPORT QString dumpObject( KJS::ExecState *exec, KJS::Object &obj ); + + /** Returns HTML that documents the QObject facilities of the specified object. */ + KJSEMBED_EXPORT QString dumpQObject( KJS::ExecState *exec, KJS::Object &obj ); + + /** Returns a QStringList that contains all possible properties, + * methods and slots for use with a completion object + */ + KJSEMBED_EXPORT QStringList dumpCompletion( KJS::ExecState *exec, KJS::Object &obj); + + KJSEMBED_EXPORT QPen extractQPen(KJS::ExecState *exec, const KJS::List &args, int idx); + KJSEMBED_EXPORT QFont extractQFont(KJS::ExecState *exec, const KJS::List &args, int idx); + KJSEMBED_EXPORT QBrush extractQBrush(KJS::ExecState *exec, const KJS::List &args, int idx); + KJSEMBED_EXPORT QPalette extractQPalette(KJS::ExecState *exec, const KJS::List &args, int idx); + KJSEMBED_EXPORT QPixmap extractQPixmap( KJS::ExecState *exec, const KJS::List &args, int idx); + KJSEMBED_EXPORT QImage extractQImage( KJS::ExecState *exec, const KJS::List &args, int idx); + KJSEMBED_EXPORT QString extractQString( KJS::ExecState *exec, const KJS::List &args, int idx); + KJSEMBED_EXPORT int extractInt( KJS::ExecState *exec, const KJS::List &args, int idx); + KJSEMBED_EXPORT QColor extractQColor(KJS::ExecState *exec, const KJS::List &args, int idx); + KJSEMBED_EXPORT QSize extractQSize(KJS::ExecState *exec, const KJS::List &args, int idx); + KJSEMBED_EXPORT bool extractBool(KJS::ExecState *exec, const KJS::List &args, int idx); + KJSEMBED_EXPORT double extractDouble(KJS::ExecState *exec, const KJS::List &args, int idx); + KJSEMBED_EXPORT uint extractUInt(KJS::ExecState *exec, const KJS::List &args, int idx); + KJSEMBED_EXPORT QStringList extractQStringList(KJS::ExecState *exec, const KJS::List &args, int idx); + + KJSEMBED_EXPORT QDateTime extractQDateTime(KJS::ExecState *exec, const KJS::List &args, int idx); + KJSEMBED_EXPORT QDate extractQDate(KJS::ExecState *exec, const KJS::List &args, int idx); + KJSEMBED_EXPORT QTime extractQTime(KJS::ExecState *exec, const KJS::List &args, int idx); + KJSEMBED_EXPORT QRect extractQRect(KJS::ExecState *exec, const KJS::List &args, int idx); + KJSEMBED_EXPORT QPoint extractQPoint(KJS::ExecState *exec, const KJS::List &args, int idx); + + KJSEMBED_EXPORT QFont extractQFont(KJS::ExecState *exec, const KJS::List &args, int idx); + KJSEMBED_EXPORT QStrList extractQStrList(KJS::ExecState *exec, const KJS::List &args, int idx); + + KJSEMBED_EXPORT QObject *extractQObject( KJS::ExecState *exec, const KJS::List &args, int idx ); + KJSEMBED_EXPORT QWidget *extractQWidget( KJS::ExecState *exec, const KJS::List &args, int idx ); + + KJSEMBED_EXPORT JSOpaqueProxy *extractOpaqueProxy( KJS::ExecState *exec, const KJS::List &args, int idx ); + + // Helpers for Variant conversions.... + KJSEMBED_EXPORT QStrList convertArrayToStrList( KJS::ExecState *exec, const KJS::Value &value); + KJSEMBED_EXPORT QStringList convertArrayToStringList( KJS::ExecState *exec, const KJS::Value &value); + KJSEMBED_EXPORT QDateTime convertDateToDateTime(KJS::ExecState *exec, const KJS::Value &value); + KJSEMBED_EXPORT QValueList<QVariant> convertArrayToList( KJS::ExecState *exec, const KJS::Value &value ); + KJSEMBED_EXPORT QMap<QString, QVariant> convertArrayToMap( KJS::ExecState *exec, const KJS::Value &value ); + + /** + * This will throw an exception with the error string. + * @returns An error object. + */ + KJS::Object throwError( KJS::ExecState *exec, const QString &error, KJS::ErrorType type = KJS::GeneralError ); +} + +#endif // KJSEMBEDJSBINDING_H + +// Local Variables: +// c-basic-offset: 4 +// End: diff --git a/kjsembed/jsbindingbase.h b/kjsembed/jsbindingbase.h new file mode 100644 index 00000000..20ed0490 --- /dev/null +++ b/kjsembed/jsbindingbase.h @@ -0,0 +1,59 @@ +// -*- c++ -*- + +/* + * Copyright (C) 2001-2003, Richard J. Moore <rich@kde.org> + * + * This 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. + * + * This 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 this library; see the file COPYING.LIB. If not, write to + * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, + * Boston, MA 02110-1301, USA. + */ +#ifndef KJSEMBED_BINDINGSBINDINGBASE_H +#define KJSEMBED_BINDINGSBINDINGBASE_H + +#include <kjs/interpreter.h> +#include <kjs/identifier.h> +#include <kjs/types.h> + +namespace KJSEmbed { +class KJSEmbedPart; + namespace Bindings { + + /** + Baseclass for adding bindings at runtime. + + @author ian reinhart geiser <geiseri@kde.org> + */ + class JSBindingBase { + public: + /** + * This method is called by the KJSFactory to bootstrap the plugin. + * Plugin developers will want to use this method to create their QObject binding, + * or call their addBindings() method in their JSOpaque proxy or JSValueProxy. + * + * The value returned from ths function is the KJS::Object that represents the + * proxy arround the added object. + */ + virtual KJS::Object createBinding( KJSEmbedPart *jspart, KJS::ExecState *exec, const KJS::List &args ) const = 0; + /** + * Adds bindings to a specific object. This is useful if you wish to add bindings to a proxy + * that has been created elsewhere. + */ + virtual void addBindings( KJSEmbedPart *jspart, KJS::ExecState *exec, KJS::Object &proxy ) const = 0; + }; + + } + +} + +#endif diff --git a/kjsembed/jsbindingplugin.cpp b/kjsembed/jsbindingplugin.cpp new file mode 100644 index 00000000..f81bde4d --- /dev/null +++ b/kjsembed/jsbindingplugin.cpp @@ -0,0 +1,39 @@ +// -*- c++ -*- + +/* + * Copyright (C) 2001-2003, Richard J. Moore <rich@kde.org> + * + * This 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. + * + * This 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 this library; see the file COPYING.LIB. If not, write to + * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, + * Boston, MA 02110-1301, USA. + */ +#include "jsbindingplugin.h" +#ifndef QT_ONLY +#include "jsbindingplugin.moc" +#endif // QT_ONLY + +namespace KJSEmbed { +namespace Bindings { + +JSBindingPlugin::JSBindingPlugin( QObject *parent, const char *name, const QStringList &/*args*/ ): QObject(parent,name) +{ + +} + +JSBindingPlugin::~JSBindingPlugin() +{ + +} +} // Bindings +} // KJSEmbed diff --git a/kjsembed/jsbindingplugin.h b/kjsembed/jsbindingplugin.h new file mode 100644 index 00000000..6755621b --- /dev/null +++ b/kjsembed/jsbindingplugin.h @@ -0,0 +1,66 @@ +// -*- c++ -*- + +/* + * Copyright (C) 2001-2003, Richard J. Moore <rich@kde.org> + * + * This 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. + * + * This 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 this library; see the file COPYING.LIB. If not, write to + * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, + * Boston, MA 02110-1301, USA. + */ + +#ifndef KJSEMBEDBINDINGPLUGIN_H +#define KJSEMBEDBINDINGPLUGIN_H +#include <qobject.h> +#include <kjs/interpreter.h> +#include <kjs/identifier.h> +#include <kjs/types.h> + +#include <kjsembed/global.h> + +namespace KJSEmbed { + + class KJSEmbedPart; + + namespace Bindings { + /** + * Interface for KJSBindings that can be added as plugins. + * + * @author Ian Reinhart Geiser, geiseri@kde.org + * @version $Id$ + */ + class KJSEMBED_EXPORT JSBindingPlugin : public QObject { + Q_OBJECT + public: + JSBindingPlugin( QObject *parent, const char *name, const QStringList &args ); + virtual ~JSBindingPlugin(); + /** + * This method is called by the KJSFactory to bootstrap the plugin. + * Plugin developers will want to use this method to create their QObject binding, + * or call their addBindings() method in their JSOpaque proxy or JSValueProxy. + * + * The value returned from ths function is the KJS::Object that represents the + * proxy arround the added object. + */ + virtual KJS::Object createBinding( KJSEmbedPart *jspart, KJS::ExecState *exec, const KJS::List &args ) const = 0; + + /** + * add bindings to an object (eg an qobject returned by a slot + */ + virtual void addBindings( KJS::ExecState * /*exec*/, KJS::Object & /*target*/ ) const {} + ; + }; + } // Bindings +} // KJSEmbed + +#endif diff --git a/kjsembed/jsbuiltin.cpp b/kjsembed/jsbuiltin.cpp new file mode 100644 index 00000000..04680116 --- /dev/null +++ b/kjsembed/jsbuiltin.cpp @@ -0,0 +1,189 @@ +/* + * Copyright (C) 2001-2004, Richard J. Moore <rich@kde.org> + * + * This 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. + * + * This 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 this library; see the file COPYING.LIB. If not, write to + * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, + * Boston, MA 02110-1301, USA. + */ +#include <global.h> +#include <kjs/interpreter.h> +#include <kjsembed/kjsembedpart.h> + +#include "builtins/stddialog_imp.h" +#include "qtbindings/qt_imp.h" + +#ifndef QT_ONLY +#include "builtins/stdaction_imp.h" +#include "builtins/resources.h" +#endif // QT_ONLY + +#include "bindings/kconfig_imp.h" + +#include "jsfactory_imp.h" +#include "jsbuiltinproxy.h" + +#include "jsbuiltin_imp.h" +#include "jsbuiltin.h" + +namespace KJSEmbed { + +typedef Bindings::JSBuiltInImp JSBuiltInImp; +typedef Bindings::JSFactoryImp JSFactoryImp; +typedef JSProxy::MethodTable MethodTable; +typedef Bindings::Config Config; + +JSBuiltIn::JSBuiltIn( KJSEmbedPart *part ) + : jspart(part) +{ + init( jspart->globalExec() ); +} + +JSBuiltIn::~JSBuiltIn() +{ +} + +void JSBuiltIn::init( KJS::ExecState *exec ) +{ + JSFactory *jsfact = jspart->factory(); + + // + // Setup the Factory object + // + factory = KJS::Object(new JSBuiltinProxy("Factory") ); + + MethodTable factoryMethods[] = { + { JSFactoryImp::MethodCreateObject, "createObject" }, + { JSFactoryImp::MethodCreateROPart, "createROPart" }, + { JSFactoryImp::MethodLoadUI, "loadui" }, + { JSFactoryImp::MethodWidgets, "widgets" }, + { JSFactoryImp::MethodConstructors, "constructors" }, + { JSFactoryImp::MethodIsSupported, "isSupported" }, + { JSFactoryImp::MethodTypes, "types" }, + { JSFactoryImp::MethodListPlugins, "listBindingPlugins" }, + { JSFactoryImp::MethodCreateRWPart, "createRWPart" }, + { 0, 0 } + }; + + int i = 0; + do { + JSFactoryImp *obj = new JSFactoryImp( exec, jsfact, + factoryMethods[i].id, factoryMethods[i].name ); + factory.put( exec , obj->name(), KJS::Object(obj), KJS::Function ); + i++; + } while( factoryMethods[i].id ); + + // + // Setup the System object + // + system = KJS::Object(new JSBuiltinProxy("System") ); + MethodTable systemMethods[] = { + { JSBuiltInImp::MethodOpenFile, "openFile" }, + { JSBuiltInImp::MethodReadFile, "readFile" }, + { JSBuiltInImp::MethodWriteFile, "writeFile" }, + { JSBuiltInImp::MethodExit, "exit" }, + { 0, 0 } + }; + + i = 0; + do { + JSBuiltInImp *obj = new JSBuiltInImp( this, systemMethods[i].id, systemMethods[i].name ); + system.put( exec , obj->name(), KJS::Object(obj), KJS::Function ); + i++; + } while( systemMethods[i].id ); + + // The stdio streams + system.put( exec ,"stdin", jsfact->createProxy( exec, KJSEmbed::conin() ), KJS::Function ); + system.put( exec ,"stdout", jsfact->createProxy( exec, KJSEmbed::conout() ), KJS::Function ); + system.put( exec ,"stderr", jsfact->createProxy( exec, KJSEmbed::conerr() ), KJS::Function ); + + // Qt namespace object + qt = KJS::Object(new JSBuiltinProxy("Qt") ); + QtImp::addStaticBindings( exec, qt ); + QtImp::addBindings( exec, qt ); + + // The global config object + Config *scriptCfg = new Config( jspart ); + + system.put( exec, "KJSConfig", jsfact->createProxy( exec, scriptCfg ) ); + + // + // Setup builtin KDE objects + // + stddialog = KJS::Object(new JSBuiltinProxy("StdDialog") ); + BuiltIns::StdDialogImp::addBindings( exec, stddialog ); + +#ifndef QT_ONLY + stdaction = KJS::Object(new JSBuiltinProxy("StdAction") ); + BuiltIns::StdActionImp::addBindings( jsfact, exec, stdaction ); + + stddrs = KJS::Object(new JSBuiltinProxy("StdDirs") ); + BuiltIns::StdDirsImp::addBindings( exec, stddrs ); + + stdicns = KJS::Object(new JSBuiltinProxy("StdAction") ); + BuiltIns::StdIconsImp::addBindings( jsfact, exec, stdicns ); +#endif // QT_ONLY +} + +void JSBuiltIn::add( KJS::ExecState *exec, KJS::Object &parent ) +{ + // Add the static objects + parent.put( exec, "Factory", builtinFactory() ); + parent.put( exec, "System", builtinSystem() ); + parent.put( exec, "StdDialog", builtinStdDialog() ); + parent.put( exec, "Qt", builtinQt() ); +#ifndef QT_ONLY + parent.put( exec, "StdAction", builtinStdAction() ); + parent.put( exec, "StdDirs", builtinStdDirs() ); + parent.put( exec, "StdIcons", builtinStdIcons() ); +#endif // QT_ONLY + + // Redundant, and will break things, use dump(this) instead + //parent.put( exec, "Global", exec->interpreter()->globalObject() ); + + // Add the global functions + addGlobals( exec, parent ); +} + +void JSBuiltIn::addGlobals( KJS::ExecState *exec, KJS::Object &parent ) +{ + MethodTable methods[] = { + { JSBuiltInImp::MethodLoadScript,"load" }, + { JSBuiltInImp::MethodDumpObject,"dump" }, + { JSBuiltInImp::MethodRunKSpy,"run_kspy" }, + { JSBuiltInImp::MethodPrint,"print" }, + { JSBuiltInImp::MethodPrintLn, "println" }, + { JSBuiltInImp::MethodWarn,"warn" }, + { JSBuiltInImp::MethodReadLine,"readLine" }, + { JSBuiltInImp::MethodExit,"exit" }, + { JSBuiltInImp::MethodDumpCompletion,"dumpCompletion" }, + { JSBuiltInImp::MethodSaxLoadFile,"saxLoadFile" }, + { JSBuiltInImp::MethodAlert,"alert" }, + { JSBuiltInImp::MethodConfirm,"confirm" }, + { JSBuiltInImp::MethodPrompt,"prompt" }, + { JSBuiltInImp::MethodI18n,"i18n" }, + { JSBuiltInImp::MethodImport,"include" }, + { JSBuiltInImp::MethodShell, "shell" }, + //{ JSBuiltInImp::MethodImport,"import" }, reserved keyword + { 0, 0 } + }; + int i = 0; + do { + JSBuiltInImp *obj = new JSBuiltInImp( this, methods[i].id, methods[i].name ); + parent.put( exec , obj->name(), KJS::Object(obj), KJS::Function ); + i++; + } while( methods[i].id ); +} + +} // namespace KJSEmbed + diff --git a/kjsembed/jsbuiltin.h b/kjsembed/jsbuiltin.h new file mode 100644 index 00000000..26f82bdf --- /dev/null +++ b/kjsembed/jsbuiltin.h @@ -0,0 +1,99 @@ +// -*- c++ -*- + +/* + * Copyright (C) 2001-2003, Richard J. Moore <rich@kde.org> + * + * This 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. + * + * This 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 this library; see the file COPYING.LIB. If not, write to + * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, + * Boston, MA 02110-1301, USA. + */ + +#ifndef KJSEMBED_JSBUILTIN_H +#define KJSEMBED_JSBUILTIN_H +#include "global.h" +#include <kjs/object.h> + +namespace KJSEmbed { + +namespace Bindings { class JSBuiltInImp; } + +class KJSEmbedPart; + +/** + * Container class for the built-in objects of KJSEmbed. + * + * @author Richard Moore, rich@kde.org + */ +class KJSEMBED_EXPORT JSBuiltIn +{ +public: + /** Create builtin objects for the specified KJSEmbedPart. */ + JSBuiltIn( KJSEmbedPart *part ); + + /** Cleans up. */ + ~JSBuiltIn(); + + void add( KJS::ExecState *exec, KJS::Object &parent ); + + /** Adds the global functions to the specified parent object. */ + void addGlobals( KJS::ExecState *exec, KJS::Object &parent ); + + /** Returns the builtin Factory object. */ + KJS::Object builtinFactory() const { return factory; } + + /** Returns the builtin System object. */ + KJS::Object builtinSystem() const { return system; } + + /** Returns the builtin StdDialog object. */ + KJS::Object builtinStdDialog() const { return stddialog; } + + /** Returns the builtin StdAction object. */ + KJS::Object builtinStdAction() const { return stdaction; } + + /** Returns the builtin main config object */ + KJS::Object builtinConfig() const { return config; } + + /** Returns the builtin standard directories object */ + KJS::Object builtinStdDirs() const { return stddrs; } + + /** Returns the builtin icon loader object */ + KJS::Object builtinStdIcons() const { return stdicns; } + + /** Returns the builtin Qt object. */ + KJS::Object builtinQt() const { return qt; } + + /** Returns the part the builtins are using. */ + KJSEmbedPart *part() const { return jspart; } + +private: + /** Creates the objects and methods for the builtin types. */ + void init( KJS::ExecState *exec ); + +private: + KJSEmbedPart *jspart; + + KJS::Object factory; + KJS::Object system; + KJS::Object stddialog; + KJS::Object stdaction; + KJS::Object config; + KJS::Object stddrs; + KJS::Object stdicns; + KJS::Object qt; + class JSBuiltInPrivate *d; +}; + +} + +#endif // KJSEMBED_JSBUILTIN_H diff --git a/kjsembed/jsbuiltin_imp.cpp b/kjsembed/jsbuiltin_imp.cpp new file mode 100644 index 00000000..c916a986 --- /dev/null +++ b/kjsembed/jsbuiltin_imp.cpp @@ -0,0 +1,281 @@ +/* + * Copyright (C) 2001-2003, Richard J. Moore <rich@kde.org> + * + * This 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. + * + * This 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 this library; see the file COPYING.LIB. If not, write to + * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, + * Boston, MA 02110-1301, USA. + */ + +// #define HAVE_KSPY 1 +#include <stdio.h> + +#include <qobject.h> +#include <qfile.h> +#include <qtextstream.h> + +#ifndef QT_ONLY + +#include "global.h" +#include <klocale.h> +#include <kinputdialog.h> +#include <kmessagebox.h> +#include <kstddirs.h> +#include "ksimpleprocess.h" + +#else + +#include <qinputdialog.h> +#include <qmessagebox.h> + +#endif // QT_ONLY + +#include <kjs/object.h> + +#ifdef HAVE_KSPY +#include <kspy.h> +#endif + +#include "global.h" +#include "jsfactory.h" +#include "jsobjectproxy.h" +#include "kjsembedpart.h" + +#include "builtins/saxhandler.h" + +#include "jsbuiltin_imp.h" + +// +// KJSEmbedPart Bindings +// +namespace KJSEmbed { +namespace Bindings { + +JSBuiltInImp::JSBuiltInImp( JSBuiltIn *builtin, int mid, const QString &p ) + : JSProxyImp(builtin->part()->globalExec()), part(builtin->part()), id(mid), param(p) +{ + setName( KJS::Identifier( KJS::UString(param) ) ); +} + +JSBuiltInImp::~JSBuiltInImp() {} + +KJS::Value JSBuiltInImp::call( KJS::ExecState *exec, KJS::Object &self, const KJS::List &args ) +{ + QString arg0 = (args.size() > 0) ? args[0].toString(exec).qstring() : QString::null; + QString arg1 = (args.size() > 1) ? args[1].toString(exec).qstring() : QString::null; + + if ( id == MethodLoadScript ) { + + if ( args.size() == 1 ) { + bool ok = part->runFile( arg0 ); + return KJS::Boolean( ok ); + } + else if ( args.size() == 2 ) { + bool ok = part->runFile( arg0, args[1] ); + return KJS::Boolean( ok ); + } + else { + QString msg = i18n( "Method requires 1 or 2 arguments, received %1." ).arg( args.size() ); + return throwError(exec, msg); + } + } + else if ( id == MethodPrint ) { + + (*conout()) << arg0; + + return KJS::Boolean( true ); + } + else if ( id == MethodPrintLn ) { + + (*conout()) << arg0 << endl; + + return KJS::Boolean( true ); + } + else if ( id == MethodWarn ) { + + (*conerr()) << arg0 << endl; + + return KJS::Boolean( true ); + } + else if ( id == MethodReadLine ) { + + QString line = conin()->readLine(); + if ( !line.isNull() ) + return KJS::String( line ); + + } + else if ( id == MethodOpenFile ) { +// #warning "This is leaked!!!!!" +// QFile *f=new QFile( arg0 ); +// int mode = 0; +// if ( arg1 == QString("ro") ) +// mode = IO_ReadOnly; +// else if ( arg1 == QString("wo") ) +// mode = IO_WriteOnly; + +// if ( !f->open( mode ) ) +// return KJS::Boolean(false); + +// Bindings::TextStream *ts = new Bindings::TextStream( part, "file", new QTextStream(f) ); + +// return KJS::Object( ts ); + return KJS::Null(); + } + else if ( id == MethodReadFile ) { + + QFile f( arg0 ); + if ( !f.open( IO_ReadOnly ) ) { + QString msg = i18n( "Could not open file '%1'." ).arg(arg0); + return throwError(exec, msg); + } + + QString s = f.readAll(); + return KJS::String( s ); + } + else if ( id == MethodWriteFile ) { + QFile f( arg0 ); + if ( !f.open( IO_WriteOnly ) ) + return KJS::Boolean( false ); + + QTextStream ts( &f ); + ts << arg1; + + return KJS::Boolean( true ); + } + else if ( id == MethodDumpObject ) { + if ( args.size() == 1 ) { + KJS::Object ob = args[0].toObject(exec); + return KJS::String( dumpObject( exec, ob ) ); + } + return KJS::String( dumpObject( exec, self ) ); + } + else if ( id == MethodRunKSpy ) { +#ifdef HAVE_KSPY + KSpy::invoke(); +#endif + return KJS::Undefined(); + } + else if ( id == MethodExit ) { + int status = args.size() ? args[0].toInteger( exec ) : 0; + ::exit( status ); + } + else if ( id == MethodSaxLoadFile ) { + if ( args.size() != 2 ) { + QString msg = i18n( "Method requires 2 arguments, received %1." ).arg( args.size() ); + return throwError(exec, msg); + } + + BuiltIns::SaxHandler sax( exec ); + sax.setHandler( args[0].toObject(exec) ); + + QFile f( arg1 ); + QXmlInputSource src( &f ); + QXmlSimpleReader reader; + reader.setContentHandler( &sax ); + + bool ok = reader.parse( src ); + if ( !ok ) { + return throwError(exec, sax.errorString().utf8()); + } + + return KJS::Boolean( true ); + } + else if ( id == MethodDumpCompletion ) { + KJS::Object obj = obj.isValid() ? args[0].toObject(exec) : KJS::Object(); + if ( !obj.isValid() ) { + QString msg = i18n( "Method requires an object." ); + return throwError(exec, msg,KJS::TypeError); + } + + QVariant v = dumpCompletion( exec, obj ); + return convertToValue( exec, v ); // FIXME: This will crash if the type is wrong + } + else if ( id == MethodAlert ) { + +#ifndef QT_ONLY + KMessageBox::information( 0L, arg0 ); +#else // QT_ONLY + QMessageBox::information( 0L, i18n("Information"), arg0 ); +#endif // QT_ONLY + + return KJS::Undefined(); + } + else if ( id == MethodConfirm ) { + + int answer; +#ifndef QT_ONLY + answer = KMessageBox::questionYesNo( 0L, arg0 ); +#else // QT_ONLY + answer = QMessageBox::question(0L, i18n("Question"), arg0 ); +#endif // QT_ONLY + + return KJS::Number( answer ); + } + else if ( id == MethodPrompt ) { + + QString text; +#ifndef QT_ONLY + text = KInputDialog::getText( arg0, arg0, arg1 ); +#else // QT_ONLY + text = QInputDialog::getText( arg0, arg0, QLineEdit::Normal, arg1 ); +#endif // QT_ONLY + + return KJS::String( text ); + } + else if ( id == MethodI18n ) { + QString retString(i18n(arg0.latin1())); + return KJS::String( retString ); + } + else if ( id == MethodImport ) { + +#ifndef QT_ONLY + // Scan $KDEDIRS/share/apps/$APPNAME/ + // Scan $KDEDIRS/share/apps/kjsembed/ + KGlobal::dirs()->addResourceType("kjsembed", KStandardDirs::kde_default("data") +"/kjsembed/"); + QString fname = KGlobal::dirs ()->findResource ("kjsembed", QString(arg0)); + + kdDebug(80001) << "Loading: " << fname << endl; + + //QString code = part->loadFile(fname); + + return KJS::Boolean( part->runFile(fname, part->globalObject())); +#else // QT_ONLY + return KJS::Boolean( false ); +#endif // QT_ONLY + + } + else if ( id == MethodShell ) { + +#ifndef QT_ONLY + // return default data + kdDebug( 80001 ) << "Run: " << arg0 << endl; + return KJS::String(KSimpleProcess::exec( arg0 )); +#else // QT_ONLY + return KJS::String(); +#endif // QT_ONLY + + } + else { + kdWarning() << "JSBuiltInImp has no method " << id << endl; + } + + QString msg = i18n( "JSBuiltInImp has no method with id '%1'." ).arg( id ); + return throwError(exec, msg,KJS::ReferenceError); +} + +} // namespace KJSEmbed::Bindings +} // namespace KJSEmbed + +// Local Variables: +// c-basic-offset: 4 +// End: diff --git a/kjsembed/jsbuiltin_imp.h b/kjsembed/jsbuiltin_imp.h new file mode 100644 index 00000000..e94588b2 --- /dev/null +++ b/kjsembed/jsbuiltin_imp.h @@ -0,0 +1,83 @@ +// -*- c++ -*- + +/* + * Copyright (C) 2001-2003, Richard J. Moore <rich@kde.org> + * + * This 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. + * + * This 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 this library; see the file COPYING.LIB. If not, write to + * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, + * Boston, MA 02110-1301, USA. + */ + +#ifndef KJSEMBEDBUILTINIMP_H +#define KJSEMBEDBUILTINIMP_H + +#include <kjsembed/jsproxy_imp.h> + +#include <kjsembed/jsbuiltin.h> + +/** + * Namespace containing the KJSEmbed library. + */ +namespace KJSEmbed { + +class KJSEmbedPart; + +namespace Bindings { + +/** + * Implements KJS bindings for JSBuiltIn. + * + * @author Richard Moore, rich@kde.org + */ +class JSBuiltInImp : public JSProxyImp +{ +public: + /** Identifiers for the various methods. */ + enum MethodId { + MethodInternalError, + + MethodPrint, MethodPrintLn, MethodWarn, + MethodReadLine, MethodOpenFile, MethodReadFile, MethodWriteFile, + MethodLoadScript, MethodDumpObject, MethodRunKSpy, + MethodExit, MethodDumpCompletion, MethodSaxLoadFile, + MethodAlert, MethodConfirm, MethodPrompt, MethodI18n, MethodImport, + MethodShell,CustomMethod=0x1000 + }; + + JSBuiltInImp( JSBuiltIn *builtin, int id, const QString ¶m=QString::null ); + ~JSBuiltInImp(); + + QString parameter() const { return param; } + + /** Returns true iff this object implements the call function. */ + virtual bool implementsCall() const { return true; } + + /** Invokes the call function. */ + virtual KJS::Value call( KJS::ExecState *exec, KJS::Object &self, const KJS::List &args ); + +private: + KJSEmbedPart *part; + uint id; + QString param; + class JSBuiltInImpPrivate *d; +}; + +} // namespace KJSEmbed::Bindings +} // namespace KJSEmbed + +#endif // KJSEMBEDBUILTINIMP_H + +// Local Variables: +// c-basic-offset: 4 +// End: diff --git a/kjsembed/jsbuiltinproxy.cpp b/kjsembed/jsbuiltinproxy.cpp new file mode 100644 index 00000000..9df97214 --- /dev/null +++ b/kjsembed/jsbuiltinproxy.cpp @@ -0,0 +1,48 @@ +/* + * Copyright (C) 2001-2004, Ian Reinhart Geiser <geiseri@kde.org> + * + * This 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. + * + * This 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 this library; see the file COPYING.LIB. If not, write to + * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, + * Boston, MA 02110-1301, USA. + */ +#include "jsbuiltinproxy.h" +namespace KJSEmbed { +JSBuiltinProxy::JSBuiltinProxy( const QString &name ) : JSProxy( JSProxy::BuiltinProxy ), m_name(name) +{ + +} + +JSBuiltinProxy::~JSBuiltinProxy() +{ + +} + +QString JSBuiltinProxy::typeName() const +{ + return m_name; +} + +bool JSBuiltinProxy::inherits( const char *clazz ) +{ + if( m_name == clazz ) return true; + return false; +} + +KJS::UString JSBuiltinProxy::toString( KJS::ExecState */*exec*/ ) const +{ + QString s( "%1 (%2)" ); + return KJS::UString( s.arg("JSBuiltinProxy").arg(m_name).latin1() ); +} + +} diff --git a/kjsembed/jsbuiltinproxy.h b/kjsembed/jsbuiltinproxy.h new file mode 100644 index 00000000..e143f868 --- /dev/null +++ b/kjsembed/jsbuiltinproxy.h @@ -0,0 +1,57 @@ +// -*- c++ -*- + +/* + * Copyright (C) 2001-2004, Ian Reinhart Geiser <geiseri@kde.org> + * + * This 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. + * + * This 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 this library; see the file COPYING.LIB. If not, write to + * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, + * Boston, MA 02110-1301, USA. + */ + +#ifndef BUILTINJSPROXY_H +#define BUILTINJSPROXY_H + +#include <kjsembed/jsproxy.h> +#include <kjsembed/global.h> + +namespace KJSEmbed { + +/** + * Class for builtin global objects objects. + * + * @author Ian Reinhart Geiser <geiseri@kde.org> + */ +class KJSEMBED_EXPORT JSBuiltinProxy : public JSProxy +{ +public: + JSBuiltinProxy( const QString &name ); + virtual ~JSBuiltinProxy(); + + + virtual QString typeName() const; + + virtual bool inherits( const char *clazz ); + + bool implementsCall() const { return true; } + + bool implementsConstruct() const { return false; } + + /** Reimplemented to return the name and class of the target. */ + virtual KJS::UString toString( KJS::ExecState *exec ) const; +private: + QString m_name; +}; + +} // namespace KJSEmbed +#endif diff --git a/kjsembed/jsconsolewidget.cpp b/kjsembed/jsconsolewidget.cpp new file mode 100644 index 00000000..4816e335 --- /dev/null +++ b/kjsembed/jsconsolewidget.cpp @@ -0,0 +1,242 @@ +/* + * Copyright (C) 2001-2003, Richard J. Moore <rich@kde.org> + * + * This 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. + * + * This 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 this library; see the file COPYING.LIB. If not, write to + * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, + * Boston, MA 02110-1301, USA. + */ + +#include <qfile.h> +#include <qhbox.h> +#include <qlabel.h> +#include <qlayout.h> +#include <qpushbutton.h> + +#include <kdebug.h> +#include <kdialog.h> +#include <kglobal.h> +#include <kiconloader.h> +#include <klineedit.h> +#include <klocale.h> +#include <kpopupmenu.h> +#include <kprocess.h> +#include <ktextedit.h> +#include <kwin.h> + +#include <kjs/interpreter.h> +#include <kjs/ustring.h> +#include <kjs/types.h> + +#include "jsbinding.h" +#include "kjsembedpart.h" + +#include "jsconsolewidget.h" +#include "jsconsolewidget.moc" + +namespace KJSEmbed { + +class JSConsoleWidgetPrivate +{ +}; + +JSConsoleWidget::JSConsoleWidget( KJSEmbedPart *jspart, QWidget *parent, const char *name ) + : QFrame( parent, name ? name : "jsconsole_widget" ), + js(jspart), proc(0), d(0) +{ + setFocusPolicy( QWidget::StrongFocus ); + createView(); +} + +JSConsoleWidget::~JSConsoleWidget() +{ +} + +void JSConsoleWidget::createView() +{ + QPixmap px( KGlobal::iconLoader()->loadIcon("konsole", KIcon::NoGroup, KIcon::SizeSmall) ); + QPixmap pxl( KGlobal::iconLoader()->loadIcon("konsole", KIcon::NoGroup, KIcon::SizeLarge) ); + setIcon( px ); + KWin::setIcons( winId(), pxl, px ); + + ttl = new KPopupTitle( this, "title" ); + ttl->setText( i18n("JavaScript Console") ); + ttl->setIcon( px ); + + log = new KTextEdit( this, "log_widget" ); + log->setReadOnly( true ); + log->setUndoRedoEnabled( false ); + log->setTextFormat( Qt::RichText ); + log->setWrapPolicy( QTextEdit::Anywhere ); + log->setText( "<qt><pre>" ); + log->setFocusPolicy( QWidget::NoFocus ); + + // Command entry section + cmdBox = new QHBox( this, "cmd_box" ); + cmdBox->setSpacing( KDialog::spacingHint() ); + + QLabel *prompt = new QLabel( i18n("&KJS>"), cmdBox, "prompt" ); + cmd = new KLineEdit( cmdBox, "cmd_edit" ); + cmd->setFocusPolicy( QWidget::StrongFocus ); + cmd->setFocus(); + prompt->setBuddy( cmd ); + + go = new QPushButton( i18n("&Run"), cmdBox, "run_button" ); + go->setFixedSize( go->sizeHint() ); + + connect( cmd, SIGNAL(returnPressed(const QString&)), go, SLOT( animateClick() ) ); + connect( go, SIGNAL( clicked() ), SLOT( invoke() ) ); + + // Setup completion + KCompletion *comp = cmd->completionObject(); + connect( cmd, SIGNAL(returnPressed(const QString&)), comp, SLOT(addItem(const QString&)) ); + + // Layout + QVBoxLayout *vert = new QVBoxLayout( this, KDialog::marginHint(), KDialog::spacingHint() ); + vert->addWidget( ttl ); + vert->addWidget( log ); + vert->addWidget( cmdBox ); +} + +void JSConsoleWidget::invoke() +{ + QString code( cmd->text() ); + println( QString( "<b><font color=\"#888888\">KJS></font> %1</b>" ).arg( code ) ); + execute( code ); +} + +bool JSConsoleWidget::execute( const QString &cmd ) +{ + return execute( cmd, KJS::Null() ); +} + +bool JSConsoleWidget::execute( const QString &cmd, const KJS::Value &self ) +{ + KJS::Completion jsres; + bool ok = js->execute( jsres, cmd, self ); + + // Executed ok + if ( ok ) { + + // No return value + if ( !jsres.isValueCompletion() ) + return ok; + + // Return value + KJS::Value ret = jsres.value(); + KJS::UString s = ret.toString( js->globalExec() ); + + if ( s.isNull() ) { + warn( i18n("Success, but return value cannot be displayed") ); + return ok; + } + + QString txt = s.qstring(); + txt = txt.replace( QChar('\n'), "<br>" ); + println( txt ); + + return ok; + } + + // Handle errors + KJS::ComplType ct = jsres.complType(); + if ( (ct == KJS::Throw) || (ct == KJS::Break) || ct == KJS::Continue ) { + + KJS::UString s = jsres.value().toString( js->globalExec() ); + if ( !s.isNull() ) + warn( s.qstring() ); + else + warn( i18n("Unspecified error") ); + } + else { + kdDebug(80001) << "jsconsolewidget: Unknown completion error, " << ct << endl; + warn( i18n("Unknown error returned, completion type %1").arg(ct) ); + } + + return ok; +} + +void JSConsoleWidget::println( const QString &msg ) +{ + log->append( msg ); + log->scrollToBottom(); +} + +void JSConsoleWidget::warn( const QString &msg ) +{ + QString err( "<font color=\"red\"><b>%1</b></font>" ); + println( err.arg(msg) ); +} + +// +// Process Handling +// + +bool JSConsoleWidget::run( const QString &cmd ) +{ + kdDebug(80001) << "JSConsoleWidget::run(" << cmd << ")" << endl; + + if ( proc ) + return false; + + proc = new KShellProcess("/bin/sh"); + *proc << cmd; + + connect( proc, SIGNAL( processExited(KProcess *) ), SLOT( childExited() ) ); + connect( proc, SIGNAL( receivedStdout(KProcess *, char *, int) ), + this, SLOT( receivedStdOutput(KProcess *, char *, int) ) ); + connect( proc, SIGNAL( receivedStderr(KProcess *, char *, int) ), + this, SLOT( receivedStdError(KProcess *, char *, int) ) ); + + return proc->start( KProcess::NotifyOnExit, + KProcess::Communication( KProcess::Stdout|KProcess::Stderr )); +} + + +void JSConsoleWidget::childExited() +{ + QString s; + if ( proc->normalExit() ) { + if ( proc->exitStatus() ) + s = i18n( "<b>[Exited with status %1]</b>\n" ).arg( proc->exitStatus() ); + else + s = i18n( "<b>[Finished]</b>\n" ); + println( s ); + } + else { + s = i18n("[Aborted]\n"); + warn( s ); + } + + delete proc; + proc = 0; +} + +void JSConsoleWidget::receivedStdOutput( KProcess *, char *buffer, int buflen ) +{ + QCString buf = QCString( buffer, buflen+1 ); + println( QString(buf) ); +} + +void JSConsoleWidget::receivedStdError( KProcess *, char *buffer, int buflen ) +{ + QCString buf = QCString( buffer, buflen+1 ); + warn( QString(buf) ); +} + + +} // namespace KJSEmbed + +// Local Variables: +// c-basic-offset: 4 +// End: diff --git a/kjsembed/jsconsolewidget.h b/kjsembed/jsconsolewidget.h new file mode 100644 index 00000000..cd173080 --- /dev/null +++ b/kjsembed/jsconsolewidget.h @@ -0,0 +1,153 @@ +// -*- c++ -*- + +/* + * Copyright (C) 2001-2003, Richard J. Moore <rich@kde.org> + * + * This 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. + * + * This 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 this library; see the file COPYING.LIB. If not, write to + * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, + * Boston, MA 02110-1301, USA. + */ + +#ifndef KJSEMBEDJSCONSOLEWIDGET_H +#define KJSEMBEDJSCONSOLEWIDGET_H + +#include <qframe.h> +#include <kjsembed/global.h> + +class QPushButton; +class QHBox; + +class KLineEdit; +class KPopupTitle; +class KProcess; +class KShellProcess; +class KTextEdit; + +namespace KJS { + class Value; +} + +namespace KJSEmbed { + +class KJSEmbedPart; + +/** + * A QWidget that provides a console for executing Javascript commands. Creating + * a JS console is easy, as you can see below: + * + * <pre> + * KJS::Object global( new KJS::ObjectImp() ); + * KJS::Interpreter *js = new KJS::Interpreter( global ); + * KJSEmbed::JSConsoleWidget *win = new KJSEmbed::JSConsoleWidget( js ); + * win->addBindings( js->globalExec(), global ); + * </pre> + * + * This example creates a console for a JS interpreter and adds a print function + * to the interpreter. + * + * @version $Id$ + * @author Richard Moore, rich@kde.org + */ +class KJSEMBED_EXPORT JSConsoleWidget : public QFrame +{ + Q_OBJECT + +public: + JSConsoleWidget( KJSEmbedPart *js, QWidget *parent=0, const char *name=0 ); + virtual ~JSConsoleWidget(); + +public slots: + /** Returns the KJSEmbedPart the console is using. */ + KJSEmbed::KJSEmbedPart *jscript() const { return js; } + + /** Returns the message widget. */ + KTextEdit *messages() const { return log; } + + /** Returns the title widget. */ + KPopupTitle *title() const { return ttl; } + + /** + * Returns the QHBox used to layout the entry part of the console. This + * can be used by clients to hide and show the interactive parts of the + * console, or to add new buttons etc. + */ + QHBox *commandBox() const { return cmdBox; } + + /** Invokes the content of the command entry field. */ + void invoke(); + + /** Invokes the specified command string. */ + virtual bool execute( const QString &cmd ); + + bool execute( const QString &cmd, const KJS::Value &self ); + + /** Prints the specified string to the console. */ + virtual void println( const QString &text ); + + /** + * Prints the specified string to the console as a warning, the default + * implementation prints the text in red. + */ + virtual void warn( const QString &text ); + + /** + * Runs the specified command using KShellProcess. The output of the + * command is displayed in the console. Any output sent to stdout is + * displayed as normal text, anything sent to stderr is displayed as + * a warning. Once the command has finished the exit status is printed + * if it is non-zero. + * + * Note that there is no extra layer of security to prevent this method + * being called from a script because in general a script that can + * access this object can also write content to a file then execute the + * file. If you intend to run untrusted scripts, it is your responsibility + * to ensure that you only expose safe objects and methods to the + * interpreter. + */ + virtual bool run( const QString &shellCmd ); + +protected: + /** Creates the console view. */ + void createView(); + +protected slots: + /** Called when the process exits. */ + void childExited(); + + /** Called when the process sends message to stdout. */ + void receivedStdOutput(KProcess *, char *, int); + + /** Called when the process sends message to stderr. */ + void receivedStdError(KProcess *, char *, int); + +private: + KJSEmbedPart *js; + KShellProcess *proc; + + KTextEdit *log; + QHBox *cmdBox; + KLineEdit *cmd; + QPushButton *go; + KPopupTitle *ttl; + + class JSConsoleWidgetPrivate *d; +}; + +} // namespace KJSEmbed + +#endif // KJSEMBEDJSCONSOLEWIDGET_H + +// Local Variables: +// c-basic-offset: 4 +// End: diff --git a/kjsembed/jseventmapper.cpp b/kjsembed/jseventmapper.cpp new file mode 100644 index 00000000..eaa2aab7 --- /dev/null +++ b/kjsembed/jseventmapper.cpp @@ -0,0 +1,99 @@ +/* + * Copyright (C) 2001-2003, Richard J. Moore <rich@kde.org> + * + * This 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. + * + * This 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 this library; see the file COPYING.LIB. If not, write to + * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, + * Boston, MA 02110-1301, USA. + */ + +#include "global.h" +#include "jseventmapper.h" +#include <qevent.h> +namespace KJSEmbed { + +/** Used internally for the event handler table. */ +struct EventType +{ + EventType( KJS::Identifier _id, QEvent::Type _type ) : + id(_id), type(_type) {;} + + const KJS::Identifier id; + const QEvent::Type type; +}; + +static EventType events[] = { + EventType(KJS::Identifier("timerEvent"), QEvent::Timer), + +#ifdef ENABLE_CHILDEVENTS + EventType( KJS::Identifier("childInsertEvent"), QEvent::ChildInserted ), + EventType( KJS::Identifier("childRemoveEvent"), QEvent::ChildRemoved ), +#endif + + EventType( KJS::Identifier("mouseReleaseEvent"), QEvent::MouseButtonRelease ), + EventType( KJS::Identifier("mouseMoveEvent"), QEvent::MouseMove ), + EventType( KJS::Identifier("mouseDoubleClickEvent"), QEvent::MouseButtonDblClick ), + EventType( KJS::Identifier("mousePressEvent"), QEvent::MouseButtonPress ), + + EventType( KJS::Identifier("keyPressEvent"), QEvent::KeyPress ), + EventType( KJS::Identifier("keyReleaseEvent"), QEvent::KeyRelease ), + + EventType( KJS::Identifier("paintEvent"), QEvent::Paint ), + + EventType( KJS::Identifier("moveEvent"), QEvent::Move ), + EventType( KJS::Identifier("resizeEvent"), QEvent::Resize ), + + EventType( KJS::Identifier("closeEvent"), QEvent::Close ), + + EventType( KJS::Identifier("showEvent"), QEvent::Show ), + EventType( KJS::Identifier("hideEvent"), QEvent::Hide ), + + EventType( KJS::Identifier("dragEnterEvent"), QEvent::DragEnter ), + EventType( KJS::Identifier("dragMoveEvent"), QEvent::DragMove ), + EventType( KJS::Identifier("dragLeaveEvent"), QEvent::DragLeave ), + EventType( KJS::Identifier("dragResponseEvent"), QEvent::DragResponse ), + EventType( KJS::Identifier("dropEvent"), QEvent::Drop ), + + EventType( KJS::Identifier(), QEvent::None ) +}; + +JSEventMapper::JSEventMapper() +{ + int i = 0; + do { + addEvent( events[i].id, events[i].type ); + i++; + } while( events[i].type != QEvent::None ); +} + +JSEventMapper::~JSEventMapper() +{ +} + +void JSEventMapper::addEvent( const KJS::Identifier &name, QEvent::Type t ) +{ + handlerToEvent.insert( name.qstring(), (const uint *) t ); + eventToHandler.insert( (long) t, &name ); +} + +QEvent::Type JSEventMapper::findEventType( const KJS::Identifier &name ) const +{ + uint evt = (uint)(long)handlerToEvent[ name.qstring() ]; + return static_cast<QEvent::Type>( evt ); +} + +} // namespace KJSEmbed + +// Local Variables: +// c-basic-offset: 4 +// End: diff --git a/kjsembed/jseventmapper.h b/kjsembed/jseventmapper.h new file mode 100644 index 00000000..cdcb4630 --- /dev/null +++ b/kjsembed/jseventmapper.h @@ -0,0 +1,71 @@ +// -*- c++ -*- + +/* + * Copyright (C) 2001-2003, Richard J. Moore <rich@kde.org> + * + * This 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. + * + * This 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 this library; see the file COPYING.LIB. If not, write to + * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, + * Boston, MA 02110-1301, USA. + */ + +#ifndef JSEVENTMAPPER_H +#define JSEVENTMAPPER_H + +#include <qdict.h> +#include <qevent.h> +#include <qintdict.h> + +#include <kjs/identifier.h> +#include <kjsembed/jsbinding.h> + +namespace KJSEmbed { + +/** + * Maintains a map between the types of QEvent and the names of their event + * handlers. + * + * @author Richard Moore, rich@kde.org + */ +class JSEventMapper +{ +public: + JSEventMapper(); + virtual ~JSEventMapper(); + + /** + * Adds an event to the map. The event handler has the specified name, and + * the event has the specified type. + */ + void addEvent( const KJS::Identifier &name, QEvent::Type t ); + + /** Returns true iff the specified name is the identifier for an event handler. */ + bool isEventHandler( const KJS::Identifier &name ) const { + return handlerToEvent.find( name.qstring() ) ? true : false; + } + + /** Returns the type of the events handled by the specified handler. */ + QEvent::Type findEventType( const KJS::Identifier &name ) const; + + KJS::Identifier *findEventHandler( QEvent::Type t ) const { return eventToHandler.find(t); } + +private: + QDict<uint> handlerToEvent; + QIntDict<KJS::Identifier> eventToHandler; + class JSEventMapperPrivate *d; +}; + +} // namespace KJSEmbed + +#endif // JSEVENTMAPPER_H + diff --git a/kjsembed/jseventutils.cpp b/kjsembed/jseventutils.cpp new file mode 100644 index 00000000..0c53ebe9 --- /dev/null +++ b/kjsembed/jseventutils.cpp @@ -0,0 +1,226 @@ +/* + * Copyright (C) 2003, Richard J. Moore <rich@kde.org> + * + * This 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. + * + * This 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 this library; see the file COPYING.LIB. If not, write to + * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, + * Boston, MA 02110-1301, USA. + */ + +#include "kjsembedpart.h" +#include "jsfactory.h" +#include "jsobjectproxy.h" +#include "jsopaqueproxy.h" +#include "jsbinding.h" + +#include "jseventutils.h" + +namespace KJSEmbed { + +JSFactory *JSEventUtils::factory( const JSObjectProxy *prx ) +{ + return prx->part()->factory(); +} + +KJS::Object JSEventUtils::convertEvent( KJS::ExecState *exec, + const QMouseEvent *ev, const JSObjectProxy *context ) +{ + KJS::Object mev = convertEvent( exec, (QEvent *)ev, context); + + mev.put( exec, "pos", convertToValue( exec, QVariant(ev->pos()) ) ); + mev.put( exec, "x", KJS::Number(ev->x()) ); + mev.put( exec, "y", KJS::Number(ev->y()) ); + + mev.put( exec, "globalPos", convertToValue( exec, QVariant(ev->globalPos()) ) ); + mev.put( exec, "globalX", KJS::Number(ev->globalX()) ); + mev.put( exec, "globalY", KJS::Number(ev->globalY()) ); + + mev.put( exec, "button", KJS::Number(ev->button()) ); + mev.put( exec, "state", KJS::Number(ev->state()) ); + mev.put( exec, "stateAfter", KJS::Number(ev->stateAfter()) ); + + return mev; +} + +KJS::Object JSEventUtils::convertEvent( KJS::ExecState *exec, + const QPaintEvent *ev, const JSObjectProxy *context ) +{ + KJS::Object pev = convertEvent( exec, (QEvent *)ev, context); + + pev.put( exec, "rect", convertToValue( exec, QVariant(ev->rect()) ) ); + pev.put( exec, "erased", convertToValue( exec, QVariant(ev->erased()) ) ); + return pev; +} + +KJS::Object JSEventUtils::convertEvent( KJS::ExecState *exec, + const QKeyEvent *ev, const JSObjectProxy *context ) +{ + KJS::Object kev = convertEvent( exec, (QEvent *)ev, context); + + kev.put( exec, "key", KJS::Number(ev->key()) ); + kev.put( exec, "ascii", KJS::Number(ev->ascii()) ); + kev.put( exec, "state", KJS::Number(ev->state()) ); + kev.put( exec, "stateAfter", KJS::Number(ev->stateAfter()) ); + kev.put( exec, "isAccepted", KJS::Boolean(ev->isAccepted()) ); + kev.put( exec, "text", KJS::String(ev->text())); + kev.put( exec, "isAutoRepeat", KJS::Boolean(ev->isAutoRepeat()) ); + kev.put( exec, "count", KJS::Number( ev->count()) ); + //kev.put( exec, "accept", KJS::Void( exec, QVariant(ev->accept()), context ) ); + //kev.put( exec, "ignore", KJS::Void( exec, QVariant(ev->ignore()), context ) ); + return kev; +} +KJS::Object JSEventUtils::convertEvent( KJS::ExecState *exec, + const QIMEvent *ev, const JSObjectProxy *context ) +{ + KJS::Object qev = convertEvent( exec, (QEvent *)ev, context); + + qev.put( exec, "text", KJS::String(ev->text()) ); + qev.put( exec, "cursorPos", KJS::Number(ev->cursorPos()) ); + qev.put( exec, "isAccepted", KJS::Boolean(ev->isAccepted()) ); + //qev.put( exec, "accept", KJS::Void( exec, QVariant(ev->accept()), context ) ); + //qev.put( exec, "ignore", KJS::Void( exec, QVariant(ev->ignore()), context ) ); + return qev; +} + +KJS::Object JSEventUtils::convertEvent( KJS::ExecState *exec, + const QResizeEvent *ev, const JSObjectProxy *context ) +{ + KJS::Object rev = convertEvent( exec, (QEvent *)ev, context); + + rev.put( exec, "size", convertToValue( exec, QVariant(ev->size()) )); + rev.put( exec, "oldSize", convertToValue( exec, QVariant(ev->oldSize()) )); + return rev; +} + +KJS::Object JSEventUtils::convertEvent( KJS::ExecState *exec, + const QFocusEvent *ev, const JSObjectProxy *context ) +{ + KJS::Object fev = convertEvent( exec, (QEvent *)ev, context); + + fev.put( exec, "gotFocus", KJS::Boolean(ev->gotFocus()) ); + fev.put( exec, "lostFocus", KJS::Boolean(ev->lostFocus()) ); + return fev; +} + +KJS::Object JSEventUtils::convertEvent( KJS::ExecState *exec, + const QCloseEvent *ev, const JSObjectProxy *context ) +{ + KJS::Object cev = convertEvent( exec, (QEvent *)ev, context); + + cev.put( exec, "isAccepted", KJS::Boolean(ev->isAccepted()) ); + //cev.put( exec, "accept", KJS::Void( exec, QVariant(ev->accept()), context ) ); + //cev.put( exec, "ignore", KJS::Void( exec, QVariant(ev->ignore()), context ) ); + return cev; +} + +#ifdef ENABLE_CHILDEVENTS +KJS::Object JSEventUtils::convertEvent( KJS::ExecState *exec, + const QChildEvent *ev, const JSObjectProxy *context ) +{ + KJS::Object cev = convertEvent( exec, (QEvent *)ev, context); + + cev.put( exec, "inserted", KJS::Boolean(ev->inserted()) ); + cev.put( exec, "removed", KJS::Boolean(ev->removed()) ); + cev.put( exec, "child", factory(context)->createProxy( exec, ev->child(), context ) ); + + return cev; +} +#endif + +KJS::Object JSEventUtils::convertEvent( KJS::ExecState *exec, + const QMoveEvent *ev, const JSObjectProxy *context ) +{ + KJS::Object mev = convertEvent( exec, (QEvent *)ev, context); + + mev.put( exec, "pos", convertToValue( exec, QVariant(ev->pos()) )); + mev.put( exec, "oldPos", convertToValue( exec, QVariant(ev->oldPos()) )); + return mev; +} + +KJS::Object JSEventUtils::convertEvent( KJS::ExecState *exec, + const QWheelEvent *ev, const JSObjectProxy *context ) +{ + KJS::Object wev = convertEvent( exec, (QEvent *)ev, context); + + wev.put( exec, "delta", KJS::Number(ev->delta()) ); + wev.put( exec, "pos", convertToValue( exec, QVariant(ev->pos()) ) ); + wev.put( exec, "globalPos", convertToValue( exec, QVariant(ev->globalPos()) ) ); + wev.put( exec, "x", KJS::Number(ev->x()) ); + wev.put( exec, "y", KJS::Number(ev->y()) ); + wev.put( exec, "globalX", KJS::Number(ev->globalX()) ); + wev.put( exec, "globalY", KJS::Number(ev->globalY()) ); + + wev.put( exec, "state", KJS::Number(ev->state()) ); + wev.put( exec, "orientation", KJS::Number(ev->orientation()) ); + wev.put( exec, "isAccepted", KJS::Boolean(ev->isAccepted()) ); + //wev.put( exec, "accept", KJS::Void( exec, QVariant(ev->accept()), context ) ); + //wev.put( exec, "ignore", KJS::Void( exec, QVariant(ev->ignore()), context ) ); + return wev; +} + +KJS::Object JSEventUtils::convertEvent( KJS::ExecState *exec, + const QEvent *ev, const JSObjectProxy * /*context*/) +{ + KJS::Object evnt( new JSOpaqueProxy(ev) ); + evnt.put( exec, "type", KJS::Number( (int) ev->type()) ); + evnt.put( exec, "spontaneous", KJS::Boolean(ev->spontaneous()) ); + return evnt; +} + +KJS::Object JSEventUtils::convertEvent( KJS::ExecState * exec, const QDropEvent * ev, const JSObjectProxy * context ) +{ + KJS::Object dev = convertEvent( exec, (QEvent *)ev, context); + dev.put( exec, "pos", convertToValue( exec, QVariant(ev->pos()) ) ); + dev.put( exec, "isAccepted", KJS::Boolean(ev->isAccepted()) ); + dev.put( exec, "isActionAccepted", KJS::Boolean(ev->isActionAccepted()) ); + dev.put( exec, "source", factory(context)->createProxy(exec, ev->source(), context) ); + dev.put( exec, "action", KJS::Number( (int)(ev->action()) ) ); + return dev; +} + +KJS::Object JSEventUtils::convertEvent( KJS::ExecState *exec, + const QDragMoveEvent *ev, const JSObjectProxy *context ) +{ + KJS::Object mev = convertEvent(exec, (QDropEvent *)ev, context); + mev.put( exec, "answerRect", convertToValue( exec, QVariant(ev->answerRect()) ) ); + return mev; +} + +KJS::Object JSEventUtils::convertEvent( KJS::ExecState *exec, + const QTimerEvent *ev, const JSObjectProxy *context ) +{ + KJS::Object dev = convertEvent( exec, (QEvent *)ev, context); + dev.put( exec, "timerId", KJS::Number(ev->timerId()) ); + return dev; +} + +KJS::Object JSEventUtils::convertEvent( KJS::ExecState *exec, + const QContextMenuEvent *ev, const JSObjectProxy *context ) +{ + KJS::Object cxev = convertEvent( exec, (QEvent *)ev, context); + cxev.put( exec, "x", KJS::Number(ev->x()) ); + cxev.put( exec, "y", KJS::Number(ev->y()) ); + cxev.put( exec, "globalX", KJS::Number(ev->globalX()) ); + cxev.put( exec, "globalY", KJS::Number(ev->globalY()) ); + cxev.put( exec, "pos",convertToValue( exec, QVariant(ev->pos()) ) ); + cxev.put( exec, "globalPos", convertToValue( exec, QVariant(ev->globalPos()) ) ); + cxev.put( exec, "state", KJS::Number( (int) ev->state()) ); + cxev.put( exec, "isAccepted", KJS::Boolean(ev->isAccepted()) ); + cxev.put( exec, "isConsumed", KJS::Boolean(ev->isConsumed()) ); + cxev.put( exec, "reason", KJS::Number((int)ev->reason()) ); + return cxev; +} + + + +}// namespace KJSEmbed diff --git a/kjsembed/jseventutils.h b/kjsembed/jseventutils.h new file mode 100644 index 00000000..f736478b --- /dev/null +++ b/kjsembed/jseventutils.h @@ -0,0 +1,101 @@ +// -*- c++ -*- + +/* + * Copyright (C) 2003, Richard J. Moore <rich@kde.org> + * + * This 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. + * + * This 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 this library; see the file COPYING.LIB. If not, write to + * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, + * Boston, MA 02110-1301, USA. + */ + +#ifndef KJSEMBED_JSEVENTUTILS_H +#define KJSEMBED_JSEVENTUTILS_H +#include "global.h" +#include <qevent.h> +#include <kjs/object.h> + +namespace KJSEmbed { + +class JSObjectProxy; +class JSFactory; + +/** + * Utility class that contains the methods for converting event types to JS. + */ +class KJSEMBED_EXPORT JSEventUtils +{ +public: + static KJS::Object convertEvent( KJS::ExecState *exec, + const QMouseEvent *ev, const JSObjectProxy *context ); + + static KJS::Object convertEvent( KJS::ExecState *exec, + const QPaintEvent *ev, const JSObjectProxy *context ); + + static KJS::Object convertEvent( KJS::ExecState *exec, + const QKeyEvent *ev, const JSObjectProxy *context ); + + static KJS::Object convertEvent( KJS::ExecState *exec, + const QIMEvent *ev, const JSObjectProxy *context ); + + static KJS::Object convertEvent( KJS::ExecState *exec, + const QResizeEvent *ev, const JSObjectProxy *context ); + + static KJS::Object convertEvent( KJS::ExecState *exec, + const QFocusEvent *ev, const JSObjectProxy *context ); + + static KJS::Object convertEvent( KJS::ExecState *exec, + const QCloseEvent *ev, const JSObjectProxy *context ); + +#ifdef ENABLE_CHILDEVENTS + static KJS::Object convertEvent( KJS::ExecState *exec, + const QChildEvent *ev, const JSObjectProxy *context ); +#endif + + static KJS::Object convertEvent( KJS::ExecState *exec, + const QMoveEvent *ev, const JSObjectProxy *context ); + + static KJS::Object convertEvent( KJS::ExecState *exec, + const QWheelEvent *ev, const JSObjectProxy *context ); + + static KJS::Object convertEvent( KJS::ExecState *exec, + const QEvent *ev, const JSObjectProxy *context ); + + static KJS::Object convertEvent( KJS::ExecState *exec, + const QDropEvent *ev, const JSObjectProxy *context ); + + static KJS::Object convertEvent( KJS::ExecState *exec, + const QDragMoveEvent *ev, const JSObjectProxy *context ); + + static KJS::Object convertEvent( KJS::ExecState *exec, + const QTimerEvent *ev, const JSObjectProxy *context ); + + static KJS::Object convertEvent( KJS::ExecState *exec, + const QContextMenuEvent *ev, const JSObjectProxy *context ); + + + + + + + +private: + JSEventUtils() {} + ~JSEventUtils() {} + + static JSFactory *factory( const JSObjectProxy *prx ); +}; + +} // KJSEmbed + +#endif // KJSEMBED_JSEVENTUTILS_H diff --git a/kjsembed/jsfactory.cpp b/kjsembed/jsfactory.cpp new file mode 100644 index 00000000..ff298b43 --- /dev/null +++ b/kjsembed/jsfactory.cpp @@ -0,0 +1,1132 @@ +/* +* Copyright (C) 2001-2004, Richard J. Moore <rich@kde.org> +* +* This 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. +* +* This 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 this library; see the file COPYING.LIB. If not, write to +* the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, +* Boston, MA 02110-1301, USA. +*/ + +#include <stdio.h> +#include <string.h> +#include <errno.h> + +#include <qobject.h> +#include <qcombobox.h> +#include <qdialog.h> +#include <qdir.h> +#include <qfile.h> +#include <qimage.h> +#include <qlistview.h> +#include <qmainwindow.h> +//#include <qpainter.h> +#include <qprogressdialog.h> +#include <qtextstream.h> +#include <qtimer.h> +#include <qwidget.h> +#include <qwidgetfactory.h> +#include <qsplitter.h> +#include <qscrollview.h> +#include <qcanvas.h> +#include <qlayout.h> +#include <qsplashscreen.h> + +#ifndef QT_ONLY + +#include <kapplication.h> +#include <dcopref.h> +#include <dcopclient.h> +#include <kaction.h> +#include <klibloader.h> +#include <klocale.h> +#include <kmainwindow.h> +#include <kservice.h> +#include <ksystemtray.h> +#include <ktrader.h> + +#include <kparts/part.h> +#include <kparts/mainwindow.h> +#include <kparts/componentfactory.h> + +#endif // QT_ONLY + +#include <kjs/interpreter.h> +#include <kjs/identifier.h> +#include <kjs/types.h> + +#include "jsbinding.h" +#include "jsbindingbase.h" +#include "jsobjectproxy.h" +#include "jsopaqueproxy.h" +#include "jsvalueproxy.h" +#include "jsconsolewidget.h" +#include "jseventmapper.h" +#include "jseventutils.h" +#include "kjsembedpart.h" +#include "customobject_imp.h" + +#include "builtins/stddialog_imp.h" +#include "builtins/textstream_imp.h" +#include "builtins/qdir_imp.h" + +#include "qtbindings/qcombobox_imp.h" +#include "qtbindings/qpopupmenu_imp.h" +#include "qtbindings/qlistviewitem_imp.h" +#include "qtbindings/qchecklistitem_imp.h" +#include "qtbindings/qcanvasellipse_imp.h" +#include "qtbindings/qcanvas_imp.h" +#include "qtbindings/qcanvasitem_imp.h" +#include "qtbindings/qcanvasitemlist_imp.h" +#include "qtbindings/qcanvasline_imp.h" +#include "qtbindings/qcanvaspixmaparray_imp.h" +#include "qtbindings/qcanvaspixmap_imp.h" +#include "qtbindings/qcanvaspolygonalitem_imp.h" +#include "qtbindings/qcanvaspolygon_imp.h" +#include "qtbindings/qcanvasrectangle_imp.h" +#include "qtbindings/qcanvasspline_imp.h" +#include "qtbindings/qcanvassprite_imp.h" +#include "qtbindings/qcanvastext_imp.h" +#include "qtbindings/qcanvasview_imp.h" + + +#ifndef QT_ONLY + +#include "builtins/stdaction_imp.h" + +#include "bindings/dcop_imp.h" +#include "bindings/netaccess_imp.h" +#endif // QT_ONLY + +#include "bindings/image_imp.h" +#include "bindings/pen_imp.h" +#include "bindings/pixmap_imp.h" +#include "bindings/painter_imp.h" +#include "bindings/movie_imp.h" +#include "bindings/sql_imp.h" +#include "bindings/kconfig_imp.h" +#include "bindings/brush_imp.h" +#include "bindings/size_imp.h" +#include "bindings/rect_imp.h" +#include "bindings/point_imp.h" + + +#include "global.h" +#include "jsbindingplugin.h" +#include "jsfactory_imp.h" +#include "jsfactory.h" + +// +// KPart Implementation +// +namespace KJSEmbed { + + typedef Bindings::JSFactoryImp JSFactoryImp; + typedef Bindings::CustomObjectImp CustomObjectImp; + typedef BuiltIns::StdDialogImp StdDialogImp; + typedef BuiltIns::TextStreamImp TextStreamImp; + + class JSFactoryPrivate { + public: + QDict<KJSEmbed::Bindings::JSBindingPlugin> plugins; + QDict<KJSEmbed::Bindings::JSBindingBase> opaqueTypes; + QDict<KJSEmbed::Bindings::JSBindingBase> objectTypes; + }; + + + JSFactory::JSFactory( KJSEmbedPart *part ) + : jspart( part ) { + evmapper = new JSEventMapper(); + d = new JSFactoryPrivate; + registerOpaqueType("QDir", new Bindings::QDirLoader()); + registerOpaqueType("QCheckListItem", new Bindings::QCheckListItemLoader()); + registerOpaqueType("QListViewItem", new Bindings::QListViewItemLoader()); + registerOpaqueType("Painter", new Bindings::PainterLoader()); + +#ifndef QT_ONLY + registerOpaqueType("DCOPClient", new Bindings::JSDCOPClientLoader()); + registerObjectType("DCOPInterface", new Bindings::JSDCOPInterfacerLoader()); + registerOpaqueType("DCOPRef", new Bindings::JSDCOPRefLoader()); +#endif + + } + + JSFactory::~JSFactory() { + delete evmapper; + } + + void JSFactory::addBindingPluginTypes( KJS::ExecState *exec, KJS::Object &parent ) { +#ifndef QT_ONLY + + // Get list of valid plugin types + KTrader::OfferList offers = KTrader::self() ->query( "JSBindingPlugin/Binding" ); + if ( !offers.count() ) + return ; + + KTrader::OfferListIterator itr = offers.begin(); + while ( itr != offers.end() ) { + QString classname = ( *itr ) ->name(); + JSFactoryImp *cons = new JSFactoryImp( exec, this, JSFactoryImp::NewInstance, classname ); + parent.put( exec, KJS::Identifier( cons->parameter() ), KJS::Object( cons ) ); + addType( classname, TypePlugin ); + ++itr; + } +#else + Q_UNUSED( exec ); + Q_UNUSED( parent ); +#endif // QT_ONLY + + } + + bool JSFactory::isBindingPlugin( const QString &classname ) const { + if ( !isSupported( classname ) ) + return false; + return ( objtypes[ classname ] & TypePlugin ); + } + + KJS::Object JSFactory::createBindingPlugin( KJS::ExecState *exec, const QString &classname, const KJS::List &args ) { +#ifndef QT_ONLY + + Bindings::JSBindingPlugin * plugin = d->plugins[ classname ]; + if ( plugin == 0L ) { + QString query = "JSBindingPlugin/Binding"; + QString constraint = "[Name] == '" + classname + "'"; + plugin = KParts::ComponentFactory::createInstanceFromQuery<Bindings::JSBindingPlugin>( query, constraint ); + if ( plugin != 0L ) + d->plugins.insert( classname, plugin ); + } + + if ( plugin != 0L ) + return plugin->createBinding( jspart, exec, args ); + +#else + + Q_UNUSED( exec ); + Q_UNUSED( args ); +#endif // QT_ONLY + + kdWarning( 80001 ) << "Unable to load binding " << classname << "." << endl; + + return KJS::Object(); + } + + KJS::Object JSFactory::create( KJS::ExecState *exec, const QString &classname, const KJS::List &args ) { + KJS::Object returnObject; + if ( !isSupported( classname ) ) { + QString msg = i18n( "Object of type '%1' is not supported." ).arg( classname ); + return throwError(exec, msg,KJS::TypeError); + } + if ( isQObject( classname ) ) { + // create via widget factory... + Bindings::JSBindingBase *factory = d->objectTypes.find(classname); + if( factory ) { + returnObject = factory->createBinding( jspart, exec, args ); + JSProxy::toProxy( returnObject.imp() ) ->setOwner( JSProxy::JavaScript ); + } else { + QObject *parent = extractQObject(exec, args, 0); + QString name = extractQString(exec, args, 1); + + QObject *obj = create( classname, parent, name.latin1() ); + if ( obj ) { + returnObject = createProxy( exec, obj ); + JSProxy::toProxy( returnObject.imp() ) ->setOwner( JSProxy::JavaScript ); + } else { + QString msg = i18n( "QObject of type '%1' could not be created." ).arg( classname ); + returnObject = throwError(exec, msg,KJS::TypeError); + } + } + } else if ( isOpaque( classname ) ) { + // Try to create from the registry + Bindings::JSBindingBase *factory = d->opaqueTypes.find(classname); + if( factory ) + returnObject = factory->createBinding( jspart, exec, args ); + else + returnObject = createOpaque( exec, classname, args ); + + if ( !returnObject.isValid() ) { + QString msg = i18n( "Opaque object of type '%1' could not be created." ).arg( classname ); + returnObject = throwError(exec, msg,KJS::TypeError); + } + } else if ( isValue( classname ) ) { + returnObject = createValue( exec, classname, args ); + if ( !returnObject.isValid() ) { + QString msg = i18n( "Value object of type '%1' could not be created." ).arg( classname ); + returnObject = throwError(exec, msg,KJS::TypeError); + } + } else if ( isBindingPlugin( classname ) ) { + returnObject = createBindingPlugin( exec, classname, args ); + if ( !returnObject.isValid() ) { + QString msg = i18n( "Plugin object of type '%1' could not be created." ).arg( classname ); + returnObject = throwError(exec, msg,KJS::TypeError); + } else + JSProxy::toProxy( returnObject.imp() ) ->setOwner( JSProxy::JavaScript ); + } else { + QString msg = i18n( "Could not create object of type '%1'." ).arg( classname ); + returnObject = throwError(exec, msg,KJS::TypeError); + } + return returnObject; + } + + KJS::Object JSFactory::createProxy( KJS::ExecState *exec, QObject *target, + const JSObjectProxy *ctx ) const { + kdDebug( 80001 ) << "JSFactory::createProxy: Target '" << target->name() + << "' type " << target->className() << endl; + + JSObjectProxy *prx; + if ( ctx ) + prx = new JSObjectProxy( jspart, target, ctx->rootObject(), ctx->securityPolicy() ); + else { + prx = new JSObjectProxy( jspart, target ); + + } + kdDebug( 80001 ) << "Proxy created" << endl; + + KJS::Object proxyObj( prx ); + prx->addBindings( exec, proxyObj ); + extendProxy( exec, proxyObj ); + prx->setOwner(JSProxy::Native); + + kdDebug( 80001 ) << "Returning object" << endl; + + return proxyObj; + } + + KJS::Object JSFactory::createProxy( KJS::ExecState *exec, + QTextStream *target, const JSObjectProxy *context ) const { + Q_UNUSED( context ) + kdDebug( 80001 ) << "TextStream proxy created" << endl; + + JSOpaqueProxy *prx = new JSOpaqueProxy( target ); + KJS::Object proxyObj( prx ); + prx->addBindings( exec, proxyObj ); + TextStreamImp::addBindings( exec, proxyObj ); + + return proxyObj; + } + + KJS::Object JSFactory::createProxy( KJS::ExecState *exec, + QEvent *target, const JSObjectProxy *context ) const { + switch ( target->type() ) { + case QEvent::MouseButtonPress: + case QEvent::MouseButtonRelease: + case QEvent::MouseMove: + case QEvent::MouseButtonDblClick: + return JSEventUtils::convertEvent( exec, ( QMouseEvent * ) target, context ); + break; + case QEvent::KeyPress: + case QEvent::KeyRelease: + case QEvent::Accel: + case QEvent::AccelOverride: + return JSEventUtils::convertEvent( exec, ( QKeyEvent * ) target, context ); + break; + case QEvent::IMStart: + case QEvent::IMCompose: + case QEvent::IMEnd: + return JSEventUtils::convertEvent( exec, ( QIMEvent * ) target, context ); + break; + case QEvent::Paint: + return JSEventUtils::convertEvent( exec, ( QPaintEvent * ) target, context ); + break; + case QEvent::Resize: + return JSEventUtils::convertEvent( exec, ( QResizeEvent * ) target, context ); + break; + case QEvent::FocusIn: + case QEvent::FocusOut: + return JSEventUtils::convertEvent( exec, ( QFocusEvent * ) target, context ); + break; + case QEvent::Close: + return JSEventUtils::convertEvent( exec, ( QCloseEvent * ) target, context ); + break; + case QEvent::ChildInserted: + case QEvent::ChildRemoved: + return JSEventUtils::convertEvent( exec, ( QChildEvent * ) target, context ); + break; + case QEvent::Move: + return JSEventUtils::convertEvent( exec, ( QMoveEvent * ) target, context ); + break; + case QEvent::Wheel: + return JSEventUtils::convertEvent( exec, ( QWheelEvent * ) target, context ); + break; + case QEvent::Timer: + return JSEventUtils::convertEvent( exec, ( QTimerEvent * ) target, context ); + break; + case QEvent::ContextMenu: + return JSEventUtils::convertEvent( exec, ( QContextMenuEvent * ) target, context ); + break; + case QEvent::DragMove: + case QEvent::DragEnter: + return JSEventUtils::convertEvent( exec, ( QDragMoveEvent * ) target, context ); + break; + case QEvent::Drop: + return JSEventUtils::convertEvent( exec, ( QDropEvent * ) target, context ); + break; + case QEvent::Enter: + case QEvent::Leave: + case QEvent::Clipboard: + case QEvent::DragLeave: + case QEvent::Show: + case QEvent::Hide: + return JSEventUtils::convertEvent( exec, ( QEvent * ) target, context ); + break; + default: + break; + } + + return JSEventUtils::convertEvent( exec, ( QEvent * ) target, context ); + } + + KJS::Object JSFactory::extendProxy( KJS::ExecState *exec, KJS::Object &target ) const { + CustomObjectImp::addBindings( exec, target ); + addBindingsPlugin( exec, target ); + return target; + } + + void JSFactory::addBindingsPlugin( KJS::ExecState *exec, KJS::Object &target ) const { + kdDebug( 800001 ) << "JSFactory::addBindingsPlugin" << endl; + JSObjectProxy *proxy = JSProxy::toObjectProxy( target.imp() ); + if ( !proxy ) + return ; + if ( !isBindingPlugin( proxy->object() ->className() ) ) + return ; + +#ifndef QT_ONLY + + Bindings::JSBindingPlugin *plugin = d->plugins[ proxy->object() ->className() ]; + if ( plugin == 0L ) { + QString query = "JSBindingPlugin/Binding"; + QString constraint = "[Name] == '" + QString::fromUtf8( proxy->object() ->className() ) + "'"; + plugin = KParts::ComponentFactory::createInstanceFromQuery<Bindings::JSBindingPlugin>( query, constraint ); + if ( plugin != 0L ) + d->plugins.insert( proxy->object() ->className(), plugin ); + } + + if ( plugin != 0L ) { + kdDebug( 800001 ) << "JSFactory::addBindingsPlugin: calling plugin function" << endl; + plugin->addBindings( exec, target ); + return ; + } +#else + Q_UNUSED( exec ); +#endif // QT_ONLY + + kdWarning( 80001 ) << "Unable to add bindings to " << proxy->object() ->className() << "." << endl; + return ; + + } + + + QObject *JSFactory::createBinding( const QString &cname, QObject *parent, const char *name ) { +#ifndef QT_ONLY + + // Bindings + /*if ( cname == "DCOPInterface" ) + return new Bindings::JSDCOPInterface( jspart->interpreter(), parent, name ); + else */if ( cname == "NetAccess" ) + return new Bindings::NetAccess( parent, name ); + else +#endif // QT_ONLY + if ( cname == "Movie" ) + return new Bindings::Movie( parent, name ); + else if ( cname == "SqlDatabase" ) + return new Bindings::SqlDatabase( parent, name ); + else if ( cname == "SqlQuery" ) + return new Bindings::SqlQuery( parent, name ); + else if ( cname == "Config" ) + return new Bindings::Config( parent, name ); + + return 0; + } + + QObject *JSFactory::createObject( const QString &cname, QObject *parent, const char *name ) { + + // QObjects defined by Qt + if ( cname == "QObject" ) + return new QObject( parent, name ); + else if ( cname == "QTimer" ) + return new QTimer( parent, name ); + else if ( cname == "QCanvas" ) + return new QCanvas( parent, name ); + +#ifndef QT_ONLY + // QObjects defined by KDE + else if ( cname == "KAction" ) + return new KAction( parent, name ); + else if ( cname == "KToggleAction" ) + return new KToggleAction( parent, name ); +#endif // QT_ONLY + + QWidget *w = dynamic_cast<QWidget *>( parent ); + if ( !w ) + return 0; + + if ( cname == "QHBoxLayout" ) + return new QHBoxLayout( w, 0, -1, name ); + else if ( cname == "QVBoxLayout" ) + return new QVBoxLayout( w, 0, -1, name ); + return 0; + } + + KJS::Object JSFactory::createOpaque( KJS::ExecState *exec, const QString &cname, const KJS::List &args ) { + + if ( cname == "QCanvasText" ) { + kdDebug( 80001 ) << "Creating canvas item, type is " << cname << endl; + + JSOpaqueProxy *prx = 0; + + if ( args.size() == 0 ) { + // FALL THRU + } else if ( args.size() == 1 ) { + + JSObjectProxy * arg0 = JSProxy::toObjectProxy( args[ 0 ].imp() ); + + if ( arg0 ) { + + QObject * obj0 = arg0->object(); + + if ( obj0->inherits( "QCanvas" ) ) { + QCanvas * parent = ( QCanvas * ) ( obj0 ); + prx = new JSOpaqueProxy( new QCanvasText( parent ), "QCanvasText" ); + + KJS::Object proxyObj( prx ); + QCanvasItemImp::addBindings( exec, proxyObj ); + QCanvasTextImp::addBindings( exec, proxyObj ); + return proxyObj; + } else { + kdDebug( 80001 ) << " canvas item create failed, arg0 is " << obj0->className() << endl; + return KJS::Object(); + } + } else { + kdDebug( 80001 ) << " canvas item create failed, arg0 is not an object" << endl; + return KJS::Object(); + } + + } else if ( args.size() == 2 ) { + + QString arg0 = args[ 0 ].toString( exec ).qstring(); + JSObjectProxy *arg1 = JSProxy::toObjectProxy( args[ 1 ].imp() ); + + if ( arg1 ) { + + QString arg0 = args[ 0 ].toString( exec ).qstring(); + QObject *obj1 = arg1->object(); + + if ( obj1->inherits( "QCanvas" ) ) { + QCanvas * parent = ( QCanvas * ) ( obj1 ); + prx = new JSOpaqueProxy( new QCanvasText( parent ), "QCanvasText" ); + + KJS::Object proxyObj( prx ); + QCanvasItemImp::addBindings( exec, proxyObj ); + QCanvasTextImp::addBindings( exec, proxyObj ); + return proxyObj; + } else { + kdDebug( 80001 ) << " canvas item create failed, arg0 is " << obj1->className() << endl; + return KJS::Object(); + } + } else { + kdDebug( 80001 ) << " canvas item create failed, arg1 is not an object" << endl; + return KJS::Object(); + } + } + } + + + return KJS::Object(); + } + + KJS::Object JSFactory::createValue( KJS::ExecState *exec, const QString &cname, const KJS::List & args ) { + if ( cname == "Image" ) { + QImage img = QImage(); + JSValueProxy *prx = new JSValueProxy( ); + prx->setValue( img ); + KJS::Object proxyObj( prx ); + Bindings::ImageImp::addBindings( exec, proxyObj ); + return proxyObj; + } + if ( cname == "Pixmap" ) { + QPixmap pix = QPixmap(); + JSValueProxy *prx = new JSValueProxy( ); + prx->setValue( pix ); + KJS::Object proxyObj( prx ); + Bindings::Pixmap::addBindings( exec, proxyObj ); + return proxyObj; + } + if ( cname == "Brush" ) { + QBrush brsh; + JSValueProxy *prx = new JSValueProxy( ); + prx->setValue( brsh ); + KJS::Object proxyObj( prx ); + Bindings::BrushImp::addBindings( exec, proxyObj ); + return proxyObj; + } + if ( cname == "Pen" ) { + QPen pen; + JSValueProxy *prx = new JSValueProxy( ); + prx->setValue( pen ); + KJS::Object proxyObj( prx ); + Bindings::Pen::addBindings( exec, proxyObj ); + return proxyObj; + } + if ( cname == "Rect" ) { + QRect rect; + if ( args.size() == 4 ) { + rect.setX( extractInt( exec, args, 0 ) ); + rect.setY( extractInt( exec, args, 1 ) ); + rect.setWidth( extractInt( exec, args, 2 ) ); + rect.setHeight( extractInt( exec, args, 3 ) ); + } + JSValueProxy *prx = new JSValueProxy( ); + prx->setValue( rect ); + KJS::Object proxyObj( prx ); + Bindings::Rect::addBindings( exec, proxyObj ); + return proxyObj; + } + if ( cname == "Point" ) { + QPoint point; + if ( args.size() == 2 ) { + point.setX( extractInt( exec, args, 0 ) ); + point.setY( extractInt( exec, args, 1 ) ); + } + JSValueProxy *prx = new JSValueProxy( ); + prx->setValue( point ); + KJS::Object proxyObj( prx ); + Bindings::Point::addBindings( exec, proxyObj ); + return proxyObj; + } + if ( cname == "Size" ) { + QSize size; + if ( args.size() == 2 ) { + size.setWidth( extractInt( exec, args, 0 ) ); + size.setHeight( extractInt( exec, args, 1 ) ); + } + JSValueProxy *prx = new JSValueProxy( ); + prx->setValue( size ); + KJS::Object proxyObj( prx ); + Bindings::Size::addBindings( exec, proxyObj ); + return proxyObj; + } + + + return KJS::Object(); + } + + QWidget *JSFactory::createWidget( const QString &cname, QWidget *pw, const char *name ) { + if ( cname == "QSplitter" ) + return new QSplitter( pw, name ); + else if ( cname == "QMainWindow" ) + return new QMainWindow( pw, name ); + else if ( cname == "QProgressDialog" ) + return new QProgressDialog( pw, name ); + else if ( cname == "QScrollView" ) + return new QScrollView( pw, name ); + else if ( cname == "QCanvasView" ) + return new QCanvasView( pw, name ); + else if ( cname == "QSplashScreen" ) { + QPixmap pix( 16, 16 ); + pix.fill(); + return new QSplashScreen( pix ); + } +#ifndef QT_ONLY + else if ( cname == "KMainWindow" ) + return new KMainWindow( pw, name ); + else if ( cname == "KParts_MainWindow" ) + return new KParts::MainWindow( pw, name ); + else if ( cname == "KSystemTray" ) + return new KSystemTray( pw, name ); +#endif // QT_ONLY + + return 0; + } + + QObject *JSFactory::create( const QString &cname, QObject *parent, const char *name ) { + kdDebug( 80001 ) << "KJSEmbedPart::create() name " << name << " class " << cname << endl; + + // Factory widgets + QWidgetFactory wf; + QWidget *pw = ( parent && parent->isWidgetType() ) ? static_cast<QWidget *>( parent ) : 0; + QWidget *w = wf.createWidget( cname, pw, name ); + if ( w ) { + kdDebug( 80001 ) << "Created from factory" << endl; + return w; + } + // Custom widgets + QObject *obj; + obj = createWidget( cname, pw, name ); + if ( obj ) { + if ( !isQObject( obj->className() ) ) + addType( obj->className() ); + kdDebug( 80001 ) << "Created from createWidget" << endl; + return obj; + } + + // Custom objects + obj = JSFactory::createObject( cname, parent, name ); + if ( obj ) { + if ( !isQObject( obj->className() ) ) + addType( obj->className() ); + kdDebug( 80001 ) << "Created from createObject" << endl; + return obj; + } + + // Binding objects + obj = JSFactory::createBinding( cname, parent, name ); + if ( obj ) { + if ( !isQObject( obj->className() ) ) + addType( obj->className() ); + kdDebug( 80001 ) << "Created from bindings" << endl; + return obj; + } + + kdDebug( 80001 ) << "Found nothing in :" << cname << ":" << endl; + return 0; + } + + KParts::ReadOnlyPart *JSFactory::createROPart( const QString &svc, QObject *parent, const char *name ) { + kdDebug( 80001 ) << "JSFactory::createROPart svc " << svc << " parent " << ( long ) parent << endl; + return createROPart( svc, "'KParts/ReadOnlyPart' in ServiceTypes", parent, name ); + } + + KParts::ReadOnlyPart *JSFactory::createROPart( const QString &svc, const QString &con, + QObject *parent, const char *name ) { + kdDebug( 80001 ) << "JSFactory::createROPart svc " << svc << " constraint " << con + << " parent " << ( long ) parent << endl; + + return createROPart( svc, con, parent, name, QStringList() ); + } + + KParts::ReadOnlyPart *JSFactory::createROPart( const QString &svc, const QString &con, + QObject *parent, const char *name, + const QStringList &args ) { +#ifndef QT_ONLY + kdDebug( 80001 ) << "JSFactory::createROPart svc " << svc << " constraint " << con + << " parent " << ( long ) parent + << " args: " << args << endl; + + KTrader::OfferList offers = KTrader::self() ->query( svc, con ); + if ( !offers.count() ) + return 0; + + KService::Ptr ptr = offers.first(); + KLibFactory *fact = KLibLoader::self() ->factory( ptr->library().ascii() ); + if ( !fact ) { + kdDebug( 80001 ) << "Unable to find a matching part" << endl; + return 0; + } + + QObject *obj = fact->create( parent, name, "KParts::ReadOnlyPart", args ); + addType( obj->className() ); + return static_cast<KParts::ReadOnlyPart *>( obj ); +#else // QT_ONLY + + Q_UNUSED( svc ); + Q_UNUSED( con ); + Q_UNUSED( parent ); + Q_UNUSED( name ); + Q_UNUSED( args ); + return 0; +#endif // QT_ONLY + + } + + KParts::ReadWritePart *JSFactory::createRWPart( const QString &svc, QObject *parent, const char *name ) { + kdDebug( 80001 ) << "JSFactory::createRWPart svc " << svc << " parent " << ( long ) parent << endl; + return createRWPart( svc, "'KParts/ReadWritePart' in ServiceTypes", parent, name ); + } + + KParts::ReadWritePart *JSFactory::createRWPart( const QString &svc, const QString &con, + QObject *parent, const char *name ) { + kdDebug( 80001 ) << "JSFactory::createRWPart svc " << svc << " constraint " << con + << " parent " << ( long ) parent << endl; + + return createRWPart( svc, con, parent, name, QStringList() ); + } + + KParts::ReadWritePart *JSFactory::createRWPart( const QString &svc, const QString &con, + QObject *parent, const char *name, + const QStringList &args ) { +#ifndef QT_ONLY + kdDebug( 80001 ) << "JSFactory::createRWPart svc " << svc << " constraint " << con + << " parent " << ( long ) parent + << " args: " << args << endl; + + KTrader::OfferList offers = KTrader::self() ->query( svc, con ); + if ( !offers.count() ) + return 0; + + KService::Ptr ptr = offers.first(); + KLibFactory *fact = KLibLoader::self() ->factory( ptr->library().ascii() ); + if ( !fact ) { + kdDebug( 80001 ) << "Unable to find a matching part" << endl; + return 0; + } + + QObject *obj = fact->create( parent, name, "KParts::ReadWritePart", args ); + addType( obj->className() ); + return static_cast<KParts::ReadWritePart *>( obj ); +#else // QT_ONLY + + Q_UNUSED( svc ); + Q_UNUSED( con ); + Q_UNUSED( parent ); + Q_UNUSED( name ); + Q_UNUSED( args ); + return 0; +#endif // QT_ONLY + + } + + QWidget *JSFactory::loadUI( const QString &uiFile, QObject *connector, QWidget *parent, const char *name ) { + return QWidgetFactory::create( uiFile, connector, parent, name ); + } + + QStringList JSFactory::listBindingPlugins( KJS::ExecState *exec, KJS::Object &self ) { + Q_UNUSED( exec ) + Q_UNUSED( self ) + QStringList pluginList; + QStringList allTypes = objtypes.keys(); + for ( uint idx = 0; idx < allTypes.count(); ++idx ) { + if ( objtypes[ allTypes[ idx ] ] & TypePlugin ) + pluginList.append( allTypes[ idx ] ); + } + return pluginList; + } + + bool JSFactory::isQObject( const QString &clazz ) const { + if ( !isSupported( clazz ) ) + return false; + + return ( objtypes[ clazz ] & TypeQObject ); + } + + bool JSFactory::isValue( const QString &clazz ) const { + if ( !isSupported( clazz ) ) + return false; + + return objtypes[ clazz ] == TypeValue; + } + + bool JSFactory::isOpaque( const QString &clazz ) const { + if ( !isSupported( clazz ) ) + return false; + return objtypes[ clazz ] == TypeOpaque; + } + + void JSFactory::addQObjectPlugin( const QString &classname, KJSEmbed::Bindings::JSBindingPlugin* plugin ) { + if ( plugin ) { + addType( classname, TypeQObjectPlugin ); + d->plugins.insert( classname, plugin ); + } + } + + void JSFactory::addType( const QString &clazz, uint prxtype ) { + if ( prxtype == TypeInvalid ) { + objtypes.remove( clazz ); + return ; + } + kdDebug() << "Add type " << clazz << endl; + objtypes[ clazz ] = prxtype; + } + + bool JSFactory::isSupported( const QString &clazz ) const { + kdDebug() << "Checking " << clazz << endl; + return objtypes.contains( clazz ); + } + + uint JSFactory::proxyType( const QString &clazz ) const { + if ( !isSupported( clazz ) ) + return TypeInvalid; + return objtypes[ clazz ]; + } + + void JSFactory::addTypes( KJS::ExecState *exec, KJS::Object &parent ) { + addWidgetFactoryTypes( exec, parent ); + addCustomTypes( exec, parent ); + addBindingTypes( exec, parent ); + addObjectTypes( exec, parent ); + addOpaqueTypes( exec, parent ); + addValueTypes( exec, parent ); + addBindingPluginTypes( exec, parent ); + } + + QStringList JSFactory::types() const { + return objtypes.keys(); + } + + void JSFactory::addWidgetFactoryTypes( KJS::ExecState *exec, KJS::Object &parent ) { + QStringList sl = QWidgetFactory::widgets(); + + for ( QStringList::Iterator it = sl.begin(); it != sl.end(); ++it ) { + JSFactoryImp *cons = new JSFactoryImp( exec, this, JSFactoryImp::NewInstance, *it ); + parent.put( exec, KJS::Identifier( KJS::UString( cons->parameter() ) ), KJS::Object( cons ) ); + addType( *it ); + } + } + + void JSFactory::addCustomTypes( KJS::ExecState *exec, KJS::Object &parent ) { + const char * classes[] = { + + "QSplitter", "QScrollView", "QCanvasView", "QCanvas", + "QObject", "QTimer", "QSplashScreen", "QProgressDialog", + "QLayout", "QBoxLayout", "QHBoxLayout", "QVBoxLayout", +#ifndef QT_ONLY + "KMainWindow", "KXMLGUIClient", "KSystemTray", + "KAction", "KToggleAction", + "KParts_MainWindow", +#endif // QT_ONLY + 0 + }; + + for ( int i = 0 ; classes[ i ] ; i++ ) { + JSFactoryImp *cons = new JSFactoryImp( exec, this, JSFactoryImp::NewInstance, classes[ i ] ); + parent.put( exec, KJS::Identifier( KJS::UString( cons->parameter() ) ), KJS::Object( cons ) ); + addType( classes[ i ] ); + } + } + + void JSFactory::addBindingTypes( KJS::ExecState *exec, KJS::Object &parent ) { + + + const char * bindings[] = { + "Pixmap", "KJSEmbed::Bindings::Pixmap", + "SqlDatabase", "KJSEmbed::Bindings::SqlDatabase", + "Movie", "KJSEmbed::Bindings::Movie", + "SqlQuery", "KJSEmbed::Bindings::SqlQuery", +#ifndef QT_ONLY + "NetAccess", "KJSEmbed::Bindings::NetAccess", + /*"DCOPInterface", "KJSEmbed::Bindings::JSDCOPInterface",*/ +#endif + "Config", "KJSEmbed::Bindings::Config", + 0, 0 + }; + + for ( int i = 0 ; bindings[ i ] ; i += 2 ) { + JSFactoryImp * cons = new JSFactoryImp( exec, this, JSFactoryImp::NewInstance, bindings[ i ] ); + parent.put( exec, KJS::Identifier( KJS::UString( cons->parameter() ) ), KJS::Object( cons ) ); + addType( bindings[ i ] ); + addType( bindings[ i + 1 ] ); + } + + + + } + + void JSFactory::addOpaqueTypes( KJS::ExecState *exec, KJS::Object &parent ) { + const char * classes[] = { + "QTextStream", + "TextStream", + "QCanvasItem", + "QCanvasText", + 0 + }; + + for ( int i = 0 ; classes[ i ] ; i++ ) { + JSFactoryImp *cons = new JSFactoryImp( exec, this, JSFactoryImp::NewInstance, classes[ i ] ); + parent.put( exec, KJS::Identifier( KJS::UString( cons->parameter() ) ), KJS::Object( cons ) ); + addType( classes[ i ], TypeOpaque ); + } + + // Create the custom added types. + QDictIterator<KJSEmbed::Bindings::JSBindingBase> idx( d->opaqueTypes ); + for( ; idx.current(); ++idx){ + JSFactoryImp *cons = new JSFactoryImp( exec, this, JSFactoryImp::NewInstance, idx.currentKey() ); + parent.put( exec, KJS::Identifier( KJS::UString( cons->parameter() ) ), KJS::Object( cons ) ); + addType( idx.currentKey(), TypeOpaque ); + } + + } + void JSFactory::addValueTypes( KJS::ExecState *exec, KJS::Object &parent ) { + const char * classes[] = { + "Image", + "Brush", + "Pixmap", + "Pen", + "Rect", + "Size", + "Point", + 0 + }; + + for ( int i = 0 ; classes[ i ] ; i++ ) { + JSFactoryImp *cons = new JSFactoryImp( exec, this, JSFactoryImp::NewInstance, classes[ i ] ); + parent.put( exec, KJS::Identifier( KJS::UString( cons->parameter() ) ), KJS::Object( cons ) ); + addType( classes[ i ], TypeValue ); + } + } + + + void JSFactory::addObjectTypes( KJS::ExecState *exec, KJS::Object & parent ) { + const char * classes[] = { + "QAccel", + "QAccessibleObject", + "QAction", + "QActionGroup", + "QApplication", + "QAquaStyle", + "QAssistantClient", + "QAxObject", + "QAxWidget", + "QButton", + "QCDEStyle", + "QClipboard", + "QColorDialog", + "QColorDrag", + "QComboBox", + "QCommonStyle", + "QCopChannel", + "QDataPump", + "QDateTimeEditBase", + "QDesktopWidget", + "QDns", + "QDockArea", + "QDockWindow", + "QDoubleValidator", + "QDragObject", + "QEditorFactory", + "QErrorMessage", + "QEventLoop", + "QFileDialog", + "QFileIconProvider", + "QFontDialog", + "QFtp", + "QGLWidget", + "QGridLayout", + "QGridView", + "QHButtonGroup", + "QHGroupBox", + "QHeader", + "QHttp", + "QIconDrag", + "QImageDrag", + "QInputDialog", + "QIntValidator", + "QLocalFs", + "QMacStyle", + "QMenuBar", + "QMessageBox", + "QMotif", + "QMotifDialog", + "QMotifPlusStyle", + "QMotifStyle", + "QMotifWidget", + "QNPInstance", + "QNPWidget", + "QNetworkOperation", + "QNetworkProtocol", + "QObjectCleanupHandler", + "QPlatinumStyle", + "QProcess", + "QPopupMenu", + "QProgressDialog", + "QRegExpValidator", + "QSGIStyle", + "QServerSocket", + "QSessionManager", + "QSignal", + "QSignalMapper", + "QSizeGrip", + "QSocket", + "QSocketNotifier", + "QSound", + "QSqlDatabase", + "QSqlDriver", + "QSqlEditorFactory", + "QSqlForm", + "QStatusBar", + "QStoredDrag", + "QStyle", + "QStyleSheet", + "QTabBar", + "QTabDialog", + "QTextDrag", + "QToolBar", + "QToolTipGroup", + "QTranslator", + "QUriDrag", + "QUrlOperator", + "QVButtonGroup", + "QVGroupBox", + "QValidator", + "QWSKeyboardHandler", + "QWindowsStyle", + "QWindowsXPStyle", + "QWorkspace", + "QXtWidget", + + 0 + }; + + for ( int i = 0 ; classes[ i ] ; i++ ) { + if ( !isSupported( classes[ i ] ) ) + addType( classes[ i ] ); + } + // Create the custom added types. + QDictIterator<KJSEmbed::Bindings::JSBindingBase> idx( d->objectTypes ); + for( ; idx.current(); ++idx){ + JSFactoryImp *cons = new JSFactoryImp( exec, this, JSFactoryImp::NewInstance, idx.currentKey() ); + parent.put( exec, KJS::Identifier( KJS::UString( cons->parameter() ) ), KJS::Object( cons ) ); + addType( idx.currentKey(), TypeQObject ); + } + } + + void JSFactory::registerOpaqueType( const QString & className, KJSEmbed::Bindings::JSBindingBase * bindingFactory ) + { + d->opaqueTypes.insert(className,bindingFactory); + } + + void JSFactory::unregisterOpaqueType( const QString & className ) + { + d->opaqueTypes.remove(className); + } + + void JSFactory::extendOpaqueProxy( KJS::ExecState * exec, KJS::Object &proxy ) const + { + JSOpaqueProxy *prx = JSProxy::toOpaqueProxy( proxy.imp() ); + if( prx ) + { + kdDebug() << "Looking for " << prx->typeName() << endl; + Bindings::JSBindingBase *bindingFactory = d->opaqueTypes.find( prx->typeName() ); + if( bindingFactory ) + { + kdDebug() << "Extending proxy" << endl; + bindingFactory->addBindings(jspart, exec, proxy ); + } + } + } + void JSFactory::registerObjectType( const QString & className, KJSEmbed::Bindings::JSBindingBase * bindingFactory ) + { + d->objectTypes.insert(className,bindingFactory); + } + + void JSFactory::unregisterObjectType( const QString & className ) + { + d->objectTypes.remove(className); + } + + void JSFactory::extendObjectProxy( KJS::ExecState * exec, KJS::Object &proxy ) const + { + JSObjectProxy *prx = JSProxy::toObjectProxy( proxy.imp() ); + if( prx ) + { + kdDebug() << "Looking for " << prx->typeName() << endl; + Bindings::JSBindingBase *bindingFactory = d->objectTypes.find( prx->typeName() ); + if( bindingFactory ) + { + kdDebug() << "Extending proxy" << endl; + bindingFactory->addBindings(jspart, exec, proxy ); + } + } + } + +}// namespace KJSEmbed + +// Local Variables: +// c-basic-offset: 4 +// End: diff --git a/kjsembed/jsfactory.h b/kjsembed/jsfactory.h new file mode 100644 index 00000000..d2c77cbd --- /dev/null +++ b/kjsembed/jsfactory.h @@ -0,0 +1,342 @@ +// -*- c++ -*- + +/* + * Copyright (C) 2001-2004, Richard J. Moore <rich@kde.org> + * + * This 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. + * + * This 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 this library; see the file COPYING.LIB. If not, write to + * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, + * Boston, MA 02110-1301, USA. + */ + +#ifndef KJSEMBEDFACTORY_H +#define KJSEMBEDFACTORY_H +#include "global.h" +#include <qmap.h> +#include <qdict.h> +#include <qstringlist.h> + +#include <kjs/interpreter.h> +#include <kjs/object.h> + +class QEvent; +class QObject; +class QWidget; +class QTextStream; + +namespace KParts { + class ReadOnlyPart; + class ReadWritePart; +} + +/** + * Namespace containing the KJSEmbed library. + */ +namespace KJSEmbed { + +namespace Bindings { + class JSFactoryImp; + class JSBindingPlugin; + class JSBindingBase; +} + +class KJSEmbedPart; +class JSEventMapper; +class JSOpaqueProxy; +class JSObjectProxy; + +/** + * Factory class for KJSEmbed. + * + * @author Richard Moore, rich@kde.org + */ +class KJSEMBED_EXPORT JSFactory +{ +public: + /** + * The types of proxy that can be associated with a class name. These are + * used when decoding the return values of slots. + */ + enum ProxyTypes { + TypeInvalid=0, + TypeQObject=1, + TypeValue=2, + TypeOpaque=4, + TypePlugin=8, + TypeQObjectPlugin=9 /*TypeObject|TypePlugin*/ + }; + + /** Creates a factory object for the specified part. */ + JSFactory( KJSEmbedPart *part ); + + /** Cleans up. */ + virtual ~JSFactory(); + + /** + * Returns the mapper that translates between event types and the names of + * the handler methods. + */ + JSEventMapper *eventMapper() const { return evmapper; } + + /** Returns the part that the factory is attached to. */ + KJSEmbedPart *part() const { return jspart; } + + // + // Methods for creating objects and wrappers. + // + + /** Creates an object of the specified class, then returns a proxy. */ + KJS::Object create( KJS::ExecState *exec, const QString &classname, const KJS::List &args ); + + /** Creates a proxy object for the specified target with the specified context. */ + KJS::Object createProxy( KJS::ExecState *exec, QObject *target, + const JSObjectProxy *context=0 ) const; + + /** Creates a proxy object for the specified target with the specified context. */ + KJS::Object createProxy( KJS::ExecState *exec, QTextStream *target, + const JSObjectProxy *context=0 ) const; + + /** Creates a proxy object for the specified target with the specified context. */ + KJS::Object createProxy( KJS::ExecState *exec, QEvent *target, + const JSObjectProxy *context ) const; + + + /** + * Registers an opaque proxy factory with the with the factory. + * To add an opaque type to the system you need to provide a factory based off of @ref KJSEmbed::Bindings::JSBindingBase + */ + void registerOpaqueType( const QString &className, KJSEmbed::Bindings::JSBindingBase *bindingFactory); + + /** + * Remove an opaque type from the system. + */ + void unregisterOpaqueType( const QString &className ); + + /** + * When passed an object for a type handled by an Opaque proxy this method + * will add the bindings for that opaque object to the proxy. If the object + * is not supported it is unmodified. + */ + void extendOpaqueProxy( KJS::ExecState *exec, KJS::Object &proxy) const; + + /** + * Registers a QObject proxy factory with the with the factory. + * To add an opaque type to the system you need to provide a factory based off of @ref KJSEmbed::Bindings::JSBindingBase + */ + void registerObjectType( const QString &className, KJSEmbed::Bindings::JSBindingBase *bindingFactory); + + /** + * Remove an opaque type from the system. + */ + void unregisterObjectType( const QString &className ); + + /** + * When passed an object for a type handled by an Opaque proxy this method + * will add the bindings for that opaque object to the proxy. If the object + * is not supported it is unmodified. + */ + void extendObjectProxy( KJS::ExecState *exec, KJS::Object &proxy) const; + + + // + // Methods for creating custom objects. + // + + /** + * Creates a ReadOnlyPart that views the specified service type. The + * service type will often be a MIME type like 'text/html'. The part + * created is the first offer returned by the trader, and will have the + * specified parent and name. + */ + KParts::ReadOnlyPart *createROPart( const QString &svc, QObject *parent=0, const char *name=0 ); + + /** + * Creates a ReadOnlyPart that views the specified service type and matches + * the specified constraint. + */ + KParts::ReadOnlyPart *createROPart( const QString &svc, const QString &constraint, + QObject *parent=0, const char *name=0 ); + + /** + * Creates a ReadOnlyPart that views the specified service type and matches + * the specified constraint. + */ + KParts::ReadOnlyPart *createROPart( const QString &svc, const QString &constraint, + QObject *parent, const char *name, + const QStringList &args ); + + /** + * Creates a ReadWritePart that edits the specified service type. The + * service type will often be a MIME type like 'text/plain'. The part + * created is the first offer returned by the trader, and will have the + * specified parent and name. + */ + KParts::ReadWritePart *createRWPart( const QString &svc, QObject *parent=0, const char *name=0 ); + + /** + * Creates a ReadWritePart that edits the specified service type and matches + * the specified constraint. + */ + KParts::ReadWritePart *createRWPart( const QString &svc, const QString &constraint, + QObject *parent=0, const char *name=0 ); + + /** + * Creates a ReadWritePart that edits the specified service type and matches + * the specified constraint. + */ + KParts::ReadWritePart *createRWPart( const QString &svc, const QString &constraint, + QObject *parent, const char *name, + const QStringList &args ); + + /** + * Loads the widget defined in the specified .ui file. If the widget + * cannot be created then 0 is returned. + */ + QWidget *loadUI( const QString &uiFile, QObject *connector=0, QWidget *parent=0, const char *name=0 ); + + /** + * Queries KTrader for a plugin that provides the asked for object binding. + *If the binding was added the object is returned, otherwise a KJS::Null is. + */ + QStringList listBindingPlugins( KJS::ExecState *exec, KJS::Object &self); + // + // Methods that tell the factory how to handle different classes. + // + /** + * Adds a binding plugin type to the list of available types the factory can create. + */ + void addBindingPluginTypes(KJS::ExecState *exec, KJS::Object &parent); + bool isBindingPlugin(const QString &classname) const; + /** + * Creates the actual object from the binding plugin. + */ + KJS::Object createBindingPlugin(KJS::ExecState *exec, const QString &classname, const KJS::List &args ); + /** + * Returns true iff the factory knows the type of proxy to use for the + * class with the name specified. + */ + bool isSupported( const QString &clazz ) const; + + /** + * Returns true iff the class with the specified name is handled with the + * QObject proxy type. + */ + bool isQObject( const QString &clazz ) const; + + /** + * Returns true iff the class with the specified name is handled with the + * value proxy type. + */ + bool isValue( const QString &clazz ) const; + + /** + * Returns true iff the class with the specified name is handled with the + * opaque proxy type. + */ + bool isOpaque( const QString &clazz ) const; + + /** + * Returns the ProxyType of the class with the specified name. If the + * named class is not known to the interpreter then TypeInvalid is + * returned. + */ + uint proxyType( const QString &clazz ) const; + + + /** + *Allows adding of an already loaded binding plugin for a certain class type + * + */ + void addQObjectPlugin(const QString &classname, KJSEmbed::Bindings::JSBindingPlugin* plugin); + + void addBindingsPlugin(KJS::ExecState *exec, KJS::Object &target) const; + + /** + * Tells the factory the specified type of proxy to use for the named + * class. Note that you can remove support for a type by using this method + * with TypeInvalid. + */ + void addType( const QString &clazz, uint proxytype=JSFactory::TypeQObject ); + + /** Adds the types defined by the factory to the specified parent. */ + void addTypes( KJS::ExecState *exec, KJS::Object &parent ); + + QStringList types() const; + +protected: + /** Adds custom bindings to the specified proxy object. */ + KJS::Object extendProxy( KJS::ExecState *exec, KJS::Object &target ) const; + + /** Creates an instance of the named class and returns it in a JSValueProxy. */ + KJS::Object createValue( KJS::ExecState *exec, const QString &cname, const KJS::List &args ); + + /** + * Creates an instance of a QObject subclass. If the instance cannot be + * created then 0 is returned. + */ + QObject *create( const QString &classname, QObject *parent=0, const char *name=0 ); + + /** Creates an instance of the named class and returns it in a JSOpaqueProxy. */ + KJS::Object createOpaque( KJS::ExecState *exec, const QString &cname, const KJS::List &args ); + + + /** Creates an instance of the named binding QObject. */ + QObject *createBinding( const QString &cname, QObject *parent, const char *name ); + + /** + * Creates an instance of the named QObject. This method is only used for + * non-widget objects. + */ + QObject *createObject( const QString &cname, QObject *parent, const char *name ); + + /** + * Creates an instance of the named QWidget. Note that this method is only + * used to create widgets that are not supported by QWidgetFactory. + */ + QWidget *createWidget( const QString &cname, QWidget *parent, const char *name ); + +private: + + /** Adds the types defined by QWidgetFactory to the specified parent. */ + void addWidgetFactoryTypes( KJS::ExecState *exec, KJS::Object &parent ); + + /** Adds support for custom QObject types to the specified parent. */ + void addCustomTypes( KJS::ExecState *exec, KJS::Object &parent ); + + /** Adds support for QObject binding types to the specified parent. */ + void addBindingTypes( KJS::ExecState *exec, KJS::Object &parent ); + + /** + * Adds support for any QObject types that are known about, but have no + * custom support (and no constructor). + */ + void addObjectTypes( KJS::ExecState *exec, KJS::Object &parent ); + + void addOpaqueTypes( KJS::ExecState *exec, KJS::Object &parent ); + + void addValueTypes( KJS::ExecState *exec, KJS::Object &parent ); + +private: + KJSEmbedPart *jspart; + JSEventMapper *evmapper; + QMap<QString,uint> objtypes; + class JSFactoryPrivate *d; +}; + +} // namespace KJSEmbed + +#endif // KJSEMBEDFACTORY_H + +// Local Variables: +// c-basic-offset: 4 +// End: diff --git a/kjsembed/jsfactory_imp.cpp b/kjsembed/jsfactory_imp.cpp new file mode 100644 index 00000000..c1f1f5b7 --- /dev/null +++ b/kjsembed/jsfactory_imp.cpp @@ -0,0 +1,301 @@ +/* + * Copyright (C) 2001-2004, Richard J. Moore <rich@kde.org> + * + * This 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. + * + * This 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 this library; see the file COPYING.LIB. If not, write to + * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, + * Boston, MA 02110-1301, USA. + */ + +#include <qwidget.h> +#include <qwidgetfactory.h> +#include <qobjectlist.h> +#include <qtoolbox.h> +#include <qtabwidget.h> +#include <qwizard.h> + +#include "global.h" +#include "jsproxy.h" +#include "jsobjectproxy.h" +#include "kjsembedpart.h" + +#include "jsfactory.h" +#include "jsfactory_imp.h" + +namespace KJSEmbed { +namespace Bindings { + +JSFactoryImp::JSFactoryImp( KJS::ExecState *exec, JSFactory *jsfact, int mid, const QString &p ) + : JSProxyImp(exec), fact(jsfact), id(mid), param(p), defaultVal() +{ + setName( KJS::Identifier(KJS::UString(param)) ); +} + +JSFactoryImp::~JSFactoryImp() +{ +} + +KJS::Object JSFactoryImp::construct( KJS::ExecState *exec, const KJS::List &args ) +{ + if ( id != NewInstance ) { + kdDebug(80001) << "JSFactoryImp has no such constructor, id " << id << endl; + + QString msg = i18n( "JSFactoryImp has no constructor with id '%1'." ).arg( id ); + return throwError(exec, msg,KJS::ReferenceError); + } + + return fact->create( exec, param, args ); +} + +void JSFactoryImp::setDefaultValue( const KJS::Value &value ) +{ + defaultVal = value; +} + +KJS::Value JSFactoryImp::defaultValue( KJS::ExecState *exec, KJS::Type hint ) const +{ + if ( defaultVal.isValid() ) + return defaultVal; + return JSProxyImp::defaultValue( exec, hint ); +} + +KJS::Value JSFactoryImp::call( KJS::ExecState *exec, KJS::Object &self, const KJS::List &args ) +{ + QString arg0 = (args.size() > 0) ? args[0].toString(exec).qstring() : QString::null; + QString arg1 = (args.size() > 1) ? args[1].toString(exec).qstring() : QString::null; + + kdDebug( 80001 ) << "JSFactoryImp::call() " << id << endl; + KJS::Object err; + + switch(id){ + case MethodLoadUI: + { + JSObjectProxy *cproxy = JSProxy::toObjectProxy( args[1].imp() ); + QObject *cqo = cproxy ? cproxy->object() : 0; + + JSObjectProxy *proxy = JSProxy::toObjectProxy( args[2].imp() ); + QWidget *qw = proxy ? proxy->widget() : 0; + QWidget *obj = fact->loadUI( arg0, cqo, qw, arg1.latin1() ); + if ( obj ) + { + KJS::Object parentObject = fact->createProxy( exec, obj ); + // Add properties for child widgets. + const QObjectList *lst = obj->children(); + if ( lst ) + { + QObjectListIt it( *lst ); + QObject *child; + while ( (child = it.current()) != 0 ) + { + publishChildren( child, parentObject); + ++it; + } + } + return parentObject; + } + + QString msg = i18n( "Unable to create ui from file '%1'." ).arg(arg0); + err = throwError(exec, msg,KJS::ReferenceError); + break; + } + case MethodCreateROPart: + { + + kdDebug(80001) << "MethodCreateROPart called, args.size is " << args.size() << endl; + QObject *qo = 0; + QObject *ropart = 0; + + if ( args.size() == 3 ) { + JSObjectProxy *proxy = JSProxy::toObjectProxy( args[1].imp() ); + qo = proxy ? proxy->object() : 0; + ropart = fact->createROPart( arg0, qo, args[2].toString(exec).ascii() ); + } + else if ( args.size() == 4 ) { + JSObjectProxy *proxy = JSProxy::toObjectProxy( args[2].imp() ); + qo = proxy ? proxy->object() : 0; + ropart = fact->createROPart( arg0, arg1, qo, args[3].toString(exec).ascii() ); + } + else if ( args.size() == 5 ) { + JSObjectProxy *proxy = JSProxy::toObjectProxy( args[2].imp() ); + qo = proxy ? proxy->object() : 0; + QStringList slist = extractQStringList( exec, args, 4 ); + ropart = fact->createROPart( arg0, arg1, qo, args[3].toString(exec).ascii(), slist ); + } + + if ( ropart ) { + kdDebug(80001) << "should be returning kpart type " << ropart->className() << endl; + } + else { + kdDebug(80001) << "could not create the kpart" << endl; + } + if ( ropart ) + return fact->createProxy( exec, ropart ); + + QString msg = i18n( "Unable to create read-only part for service '%1'." ).arg(arg0); + err = throwError(exec, msg,KJS::ReferenceError); + break; + } + case MethodConstructors: + { + kdDebug(80001) << "constructors called" << endl; + return fact->part()->constructors(); + break; + } + case MethodWidgets: + { + + KJS::List l; + QStringList widgets = QWidgetFactory::widgets(); + for ( QStringList::Iterator it = widgets.begin(); it != widgets.end(); ++it ) { + l.append( KJS::String( *it ) ); + } + + return KJS::Object( exec->interpreter()->builtinArray().construct( exec, l ) ); + break; + } + case MethodIsSupported: + { + return KJS::Boolean( fact->isSupported( arg0 ) ); + break; + } + case MethodIsQObject: + { + return KJS::Boolean( fact->isQObject( arg0 ) ); + break; + } + case MethodIsOpaque: + { + return KJS::Boolean( fact->isOpaque( arg0 ) ); + break; + } + case MethodIsValue: + { + return KJS::Boolean( fact->isValue( arg0 ) ); + break; + } + case MethodTypes: + { + KJS::List l; + QStringList types = fact->types(); + for ( QStringList::Iterator it = types.begin(); it != types.end(); ++it ) { + l.append( KJS::String( *it ) ); + } + + return KJS::Object( exec->interpreter()->builtinArray().construct( exec, l ) ); + break; + } + case MethodListPlugins: + { + return convertToValue( exec, fact->listBindingPlugins( exec, self) ); + break; + } + case MethodCreateRWPart: + { + + kdDebug(80001) << "MethodCreateRWPart called, args.size is " << args.size() << endl; + QObject *qo = 0; + QObject *rwpart = 0; + + if ( args.size() == 3 ) { + JSObjectProxy *proxy = JSProxy::toObjectProxy( args[1].imp() ); + qo = proxy ? proxy->object() : 0; + rwpart = fact->createRWPart( arg0, qo, args[2].toString(exec).ascii() ); + } + else if ( args.size() == 4 ) { + JSObjectProxy *proxy = JSProxy::toObjectProxy( args[2].imp() ); + qo = proxy ? proxy->object() : 0; + rwpart = fact->createRWPart( arg0, arg1, qo, args[3].toString(exec).ascii() ); + } + + if ( rwpart ) { + kdDebug(80001) << "should be returning kpart type " << rwpart->className() << endl; + } + else { + kdDebug(80001) << "could not create the kpart" << endl; + } + if ( rwpart ) + return fact->createProxy( exec, rwpart ); + + QString msg = i18n( "Unable to create read-write part for service '%1'." ).arg(arg0); + err = throwError(exec, msg,KJS::ReferenceError); + break; + } + case MethodCreateObject: + { + // Trim first argument from the list and forward the rest on. + KJS::List objectArgs; + if( args.size() > 1 ) + { + for( int idx = 1; idx < args.size(); idx++) + objectArgs.append(args[idx]); + } + return fact->create(exec,arg0, objectArgs); + break; + } + default: + { + kdWarning() << "JSBuiltInImp has no method " << id << endl; + QString msg = i18n( "JSFactoryImp has no method with id '%1'." ).arg( id ); + err = throwError(exec, msg,KJS::ReferenceError); + } + } + return err; +} + + +void JSFactoryImp::publishChildren(QObject *obj, KJS::Object &parent) +{ + QString name = obj->name(); + name.remove(":"); + name.remove(" "); + name.remove("<"); + name.remove(")"); + KJS::Object newParent = fact->part()->addObject( obj, parent, name.latin1() ); + JSProxy::toProxy( newParent.imp() ) ->setOwner( JSProxy::JavaScript ); + + // Hack to publish QToolBoxes children + QToolBox *box = dynamic_cast<QToolBox*>(obj); + QTabWidget *tab = dynamic_cast<QTabWidget*>(obj); + QWizard *wiz = dynamic_cast<QWizard*>(obj); + + if( box ) { + int count = box->count(); + for( int idx = 0; idx < count; ++idx) + publishChildren(box->item(idx),newParent); + } else if ( tab ) { + int count = tab->count(); + for( int idx = 0; idx < count; ++idx) + publishChildren(tab->page(idx),newParent); + } else if ( wiz ) { + int count = wiz->pageCount(); + for( int idx = 0; idx < count; ++idx) + publishChildren(wiz->page(idx),newParent); + } else { + const QObjectList *lst = obj->children(); + if ( lst ) { + QObjectListIt it( *lst ); + QObject *child; + while ( (child = it.current()) != 0 ) { + publishChildren( child, newParent); + ++it; + } + } + } +} + +} // namespace KJSEmbed::Bindings +} // namespace KJSEmbed + +// Local Variables: +// c-basic-offset: 4 +// End: diff --git a/kjsembed/jsfactory_imp.h b/kjsembed/jsfactory_imp.h new file mode 100644 index 00000000..a576aa03 --- /dev/null +++ b/kjsembed/jsfactory_imp.h @@ -0,0 +1,101 @@ +// -*- c++ -*- + +/* + * Copyright (C) 2001-2004, Richard J. Moore <rich@kde.org> + * + * This 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. + * + * This 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 this library; see the file COPYING.LIB. If not, write to + * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, + * Boston, MA 02110-1301, USA. + */ + +#ifndef KJSEMBED_JSFACTORYIMP_H +#define KJSEMBED_JSFACTORYIMP_H + +#include <kjsembed/jsproxy_imp.h> + +/** + * Namespace containing the KJSEmbed library. + */ +namespace KJSEmbed { + +class JSFactory; + +namespace Bindings { + +/** + * Implements KJS bindings for JSFactory. + * + * @author Richard Moore, rich@kde.org + */ +class JSFactoryImp : public JSProxyImp +{ +public: + /** Identifiers for the various methods. */ + enum MethodId { + MethodInternalError, + + NewInstance, + MethodLoadUI, + MethodCreateROPart, + MethodConstructors, + MethodWidgets, + MethodTypes, + MethodIsSupported, + MethodIsQObject, + MethodIsValue, + MethodIsOpaque, + MethodListPlugins, + MethodCreateRWPart, + MethodCreateObject + }; + + JSFactoryImp( KJS::ExecState *exec, JSFactory *fact, int id, const QString ¶m=QString::null ); + ~JSFactoryImp(); + + QString parameter() const { return param; } + + /** Returns true iff this object implements the construct function. */ + virtual bool implementsConstruct() const { return true; } + + /** Invokes the construct function. */ + virtual KJS::Object construct( KJS::ExecState *exec, const KJS::List &args ); + + void setDefaultValue( const KJS::Value &value ); + virtual KJS::Value defaultValue( KJS::ExecState *exec, KJS::Type hint ) const; + + /** Returns true iff this object implements the call function. */ + virtual bool implementsCall() const { return true; } + + KJS::Value call( KJS::ExecState *exec, KJS::Object &self, const KJS::List &args ); + + /** Returns the JSFactory for which this is the implementation. */ + JSFactory *factory() const { return fact; } + +private: + void publishChildren(QObject *obj, KJS::Object &parent); + JSFactory *fact; + uint id; + QString param; + KJS::Value defaultVal; + class JSFactoryImpPrivate *d; +}; + +} // namespace KJSEmbed::Bindings +} // namespace KJSEmbed + +#endif // KJSEMBED_JSFACTORYIMP_H + +// Local Variables: +// c-basic-offset: 4 +// End: diff --git a/kjsembed/jsobjecteventproxy.cpp b/kjsembed/jsobjecteventproxy.cpp new file mode 100644 index 00000000..ad29608f --- /dev/null +++ b/kjsembed/jsobjecteventproxy.cpp @@ -0,0 +1,126 @@ +/* + * Copyright (C) 2003-2004, Richard J. Moore <rich@kde.org> + * + * This 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. + * + * This 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 this library; see the file COPYING.LIB. If not, write to + * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, + * Boston, MA 02110-1301, USA. + */ + +#include <qvariant.h> +#include "global.h" + +#include "jsfactory.h" +#include "jseventmapper.h" +#include "jsobjectproxy.h" +#include "kjsembedpart.h" +#include "jsbinding.h" + +#include "jsobjecteventproxy.h" +#ifndef QT_ONLY +#include "jsobjecteventproxy.moc" +#endif // QT_ONLY + +namespace KJSEmbed { + +// We'll need to increase this if we need to support any custom events +static const QEvent::Type QEVENT_TYPE_MAX = QEvent::TabletRelease; + +JSObjectEventProxy::JSObjectEventProxy( JSObjectProxy *parent, const char *name ) + : QObject( parent->object(), name ? name : "jsobjecteventproxy" ), + proxy( parent ), eventMask( QEVENT_TYPE_MAX ), refcount(0) +{ + eventMask.fill( false ); +} + +JSObjectEventProxy::~JSObjectEventProxy() +{ +} + +bool JSObjectEventProxy::isFiltered( QEvent::Type t ) const +{ + return eventMask.testBit( t ); +} + +void JSObjectEventProxy::addFilter( QEvent::Type t ) +{ + if ( !refcount ) + proxy->object()->installEventFilter( this ); + + if ( !eventMask.testBit(t) ) { + refcount++; + eventMask.setBit( t ); + } + + kdDebug(80001) << "JSObjectEventProxy::addFilter done" << endl; +} + +void JSObjectEventProxy::removeFilter( QEvent::Type t ) +{ + eventMask.clearBit( t ); + refcount--; + if ( !refcount ) { + proxy->object()->removeEventFilter( this ); + deleteLater(); + } + + kdDebug(80001) << "JSObjectEventProxy::removeFilter done" << endl; +} + +bool JSObjectEventProxy::eventFilter( QObject * /*watched*/, QEvent *e ) +{ + if ( isFiltered(e->type()) ) + callHandler( e ); + + return false; +} + +KJS::Value JSObjectEventProxy::callHandler( QEvent *e ) +{ +// Be careful enabling this as if there are a lot of events then the event loop times +// out and the app crashes with 'Alarm Clock'. +// kdDebug(80001) << "JSObjectEventProxy::callHandler() event type " << e->type() << endl; + + KJS::ExecState *exec = proxy->interpreter()->globalExec(); + KJS::Identifier *id = proxy->part()->factory()->eventMapper()->findEventHandler( e->type() ); + + KJS::Object jsobj( proxy ); + KJS::Object fun = jsobj.get(exec, *id ).toObject( exec ); + + if ( !fun.implementsCall() ) { + QString msg = i18n( "Bad event handler: Object %1 Identifier %2 Method %3 Type: %4." ) + .arg(jsobj.className().ascii()).arg(id->ascii()).arg(fun.className().ascii()).arg(e->type()); + return throwError(exec, msg, KJS::TypeError ); + } + + // Process args + KJS::List args; + KJS::Object obj = proxy->part()->factory()->createProxy( exec, e, proxy ); + args.append( obj ); + + // Call handler + KJS::Value result = fun.call( exec, jsobj, args ); + + if ( exec->hadException() ) { + kdWarning( 80001 ) << "Exception in event handler '" << id->qstring() << "', " + << exec->exception().toString(exec).qstring() << endl; + + exec->clearException(); + } + + return result; +} + +} // KJSEmbed + + diff --git a/kjsembed/jsobjecteventproxy.h b/kjsembed/jsobjecteventproxy.h new file mode 100644 index 00000000..de9f2e11 --- /dev/null +++ b/kjsembed/jsobjecteventproxy.h @@ -0,0 +1,76 @@ +// -*- c++ -*- + +/* + * Copyright (C) 2003, Richard J. Moore <rich@kde.org> + * + * This 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. + * + * This 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 this library; see the file COPYING.LIB. If not, write to + * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, + * Boston, MA 02110-1301, USA. + */ + +#ifndef KJSEMBED_JSOBJECTEVENTPROXY_H +#define KJSEMBED_JSOBJECTEVENTPROXY_H + +#include <qbitarray.h> +#include <qobject.h> +#include <kjs/object.h> +#include <global.h> + +namespace KJSEmbed { + +class JSObjectProxy; + +/** + * Filters events for a QObject and forwards them to a JS handler. + * + * @version $Id$ + * @author Richard Moore, rich@kde.org + */ +class KJSEMBED_EXPORT JSObjectEventProxy : public QObject +{ + Q_OBJECT + +public: + JSObjectEventProxy( JSObjectProxy *parent, const char *name=0 ); + virtual ~JSObjectEventProxy(); + + /** Returns true iff we forward the event type to JS. */ + bool isFiltered( QEvent::Type t ) const; + + /** Adds an event type to those we forward to JS. */ + void addFilter( QEvent::Type t ); + + /** + * Removes an event type from those we forward to JS. If there are no + * event types left to forward then we self-destruct. + */ + void removeFilter( QEvent::Type t ); + + /** Reimplemented to forward events to JS. */ + bool eventFilter ( QObject *watched, QEvent *e ); + +protected: + KJS::Value callHandler( QEvent *e ); + +private: + JSObjectProxy *proxy; + QBitArray eventMask; + uint refcount; + class JSObjectEventProxyPrivate *d; +}; + +} // KJSEmbed + +#endif // KJSEMBED_JSOBJECTEVENTPROXY_H + diff --git a/kjsembed/jsobjectproxy.cpp b/kjsembed/jsobjectproxy.cpp new file mode 100644 index 00000000..c8b43a5d --- /dev/null +++ b/kjsembed/jsobjectproxy.cpp @@ -0,0 +1,306 @@ +/* +* Copyright (C) 2001-2003, Richard J. Moore <rich@kde.org> +* +* This 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. +* +* This 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 this library; see the file COPYING.LIB. If not, write to +* the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, +* Boston, MA 02110-1301, USA. +*/ + +#include <qobject.h> +#include <qobjectlist.h> +#include <qmetaobject.h> +#include <qregexp.h> +#include <qsignal.h> +#include <qstrlist.h> +#include <qvariant.h> + +#include <private/qucomextra_p.h> + +#include <kjs/interpreter.h> +#include <kjs/types.h> +#include <kjs/ustring.h> + +#include "kjsembedpart.h" +#include "jssecuritypolicy.h" +#include "jsfactory.h" +#include "global.h" + +#include "jsobjectproxy.h" +#include "jsobjectproxy_imp.h" +#include "jsobjecteventproxy.h" +#include "jseventmapper.h" +#include "slotutils.h" + +#include "bindings/bindingobject.h" + +//#include "kjsembedpart_imp.h" +#include "jsfactory_imp.h" + +using namespace KJS; + +namespace KJSEmbed { + + typedef Bindings::JSObjectProxyImp JSObjectProxyImp; + + JSObjectProxy::JSObjectProxy( KJSEmbedPart *part, QObject *target, QObject *r, const JSSecurityPolicy *sp ) + : JSProxy( JSProxy::ObjectProxy ), + jspart( part ), js( part->interpreter() ), obj( target ), root( r ) { + policy = sp ? sp : JSSecurityPolicy::defaultPolicy(); + } + + JSObjectProxy::JSObjectProxy( KJSEmbedPart *part, QObject *target, QObject *r ) + : JSProxy( JSProxy::ObjectProxy ), + jspart( part ), js( part->interpreter() ), obj( target ), root( r ) { + policy = JSSecurityPolicy::defaultPolicy(); + } + + JSObjectProxy::JSObjectProxy( KJSEmbedPart *part, QObject *target ) + : JSProxy( JSProxy::ObjectProxy ), + jspart( part ), js( part->interpreter() ), obj( target ), root( target ) { + policy = JSSecurityPolicy::defaultPolicy(); + } + JSObjectProxy::~JSObjectProxy() { + if ( owner() == JavaScript && obj->parent() == 0 ) + delete obj; + } + + void JSObjectProxy::setSecurityPolicy( const JSSecurityPolicy *pol ) { + policy = pol ? pol : new JSSecurityPolicy(); + } + + bool JSObjectProxy::isAllowed( KJS::Interpreter *js ) const { + return policy->isInterpreterAllowed( this, js ); + } + + KJS::UString JSObjectProxy::toString( KJS::ExecState *exec ) const { + if ( !exec ) { + kdWarning() << "JS toString with null state, ignoring" << endl; + return KJS::UString(); + } + if ( !isAllowed( exec->interpreter() ) ) { + kdWarning() << "JS toString request from unknown interpreter, ignoring" << endl; + return KJS::UString(); + } + + QString s( "%1 (%2)" ); + s = s.arg( obj ? obj->name() : "Dead Object" ); + s = s.arg( obj ? obj->className() : "" ); + return KJS::UString( s ); + } + + KJS::Value JSObjectProxy::get( KJS::ExecState *exec, const KJS::Identifier &p ) const { + if ( !isAllowed( exec->interpreter() ) ) { + kdWarning() << "JS get request from unknown interpreter, ignoring" << endl; + return KJS::Null(); + } + + if ( !policy->isPropertyAllowed( this, obj, p.ascii() ) ) + return ObjectImp::get( exec, p ); + + if ( !obj ) { + kdDebug( 80001 ) << "JS getting '" << p.ustring().qstring() << "' but qobj has died" << endl; + return ObjectImp::get( exec, p ); + } + kdDebug( 80001 ) << "JS getting '" << p.ascii() << endl; + + // Properties + QString prop = p.ustring().qstring(); + QMetaObject *meta = obj->metaObject(); + + if ( meta->findProperty( p.ascii(), true ) != -1 ) { + QVariant val = obj->property( prop.ascii() ); + kdDebug( 80001 ) << "JS getting '" << p.ascii() << "' ( " << val.typeName() << ")" << endl; + + return convertToValue( exec, val ); + } + + return ObjectImp::get + ( exec, p ); + } + + void JSObjectProxy::put( KJS::ExecState *exec, + const KJS::Identifier &p, const KJS::Value &v, + int attr ) { + if ( !isAllowed( exec->interpreter() ) ) { + kdWarning() << "JS put request from unknown interpreter, ignoring" << endl; + return ; + } + + if ( !policy->hasCapability( JSSecurityPolicy::CapabilitySetProperties ) ) { + ObjectImp::put( exec, p, v, attr ); + return ; + } + + if ( !obj ) { + kdDebug( 80001 ) << "JS setting '" << p.ascii() << "' but qobj has died" << endl; + ObjectImp::put( exec, p, v, attr ); + return ; + } + + // Properties + QMetaObject *meta = obj->metaObject(); + int propIndex = meta->findProperty( p.ascii(), true ); + if ( propIndex != -1 ) { + QVariant val = convertToVariant( exec, v ); + if ( meta->property(propIndex, true)->isEnumType() ) { + obj->setProperty( p.ascii(), val.toUInt() ); + } else if ( val.isValid() ) { + obj->setProperty( p.ascii(), val ); + } else { + kdWarning(80001) << "Error setting value." << endl; + } + } else { + ObjectImp::put( exec, p, v, attr ); + } + + if ( jspart->factory() ->eventMapper() ->isEventHandler( p ) ) { + if ( evproxy.isNull() ) + evproxy = new KJSEmbed::JSObjectEventProxy( this ); + evproxy->addFilter( jspart->factory() ->eventMapper() ->findEventType( p ) ); + kdDebug( 80001 ) << "Adding event handler " << p.ascii() << endl; + } + } + + // + // Implementation of JS Method Bindings + // + + void JSObjectProxy::addBindings( KJS::ExecState *exec, KJS::Object &object ) { + kdDebug( 80001 ) << "JSObjectProxy::addBindings() " << ( obj->name() ? obj->name() : "dunno" ) + << ", class " << obj->className() << endl; + + if ( policy->hasCapability( JSSecurityPolicy::CapabilityGetProperties | JSSecurityPolicy::CapabilitySetProperties ) ) { + object.put( exec, "properties", KJS::Object( new JSObjectProxyImp( exec, JSObjectProxyImp::MethodProps, this ) ) ); + } + + if ( policy->hasCapability( JSSecurityPolicy::CapabilityTree ) ) { + JSObjectProxyImp::addBindingsTree( exec, object, this ); + JSObjectProxyImp::addBindingsDOM( exec, object, this ); + } + + if ( policy->hasCapability( JSSecurityPolicy::CapabilitySlots ) ) { + addBindingsSlots( exec, object ); + JSObjectProxyImp::addBindingsConnect( exec, object, this ); + } + + addBindingsClass( exec, object ); + } + + void JSObjectProxy::addBindingsClass( KJS::ExecState *exec, KJS::Object & /*object*/ ) { + KJS::Identifier clazzid; + QObject *o = obj; + Bindings::BindingObject *bo = dynamic_cast<Bindings::BindingObject *>( o ); + if ( bo ) { + clazzid = KJS::Identifier( bo->jsClassName() ? bo->jsClassName() : obj->className() ); + } else { + clazzid = KJS::Identifier( obj->className() ); + } + + KJS::Object global = js->globalObject(); + if ( global.hasProperty( exec, clazzid ) ) { + kdDebug( 80001 ) << "addBindingsClass() " << clazzid.qstring() << " already known" << endl; + + KJS::Object clazz = global.get( exec, clazzid ).toObject( exec ); + Bindings::JSFactoryImp *imp = dynamic_cast<Bindings::JSFactoryImp *>( clazz.imp() ); + if ( !imp ) { + kdWarning() << "addBindingsClass() Class was not created by normal means" << endl; + return ; + } + + kdDebug( 80001 ) << "addBindingsClass() Adding enums" << endl; + imp->setDefaultValue( js->builtinObject().construct( exec, KJS::List() ) ); + addBindingsEnum( exec, clazz ); + } else { + kdWarning() << "addBindingsClass() " << clazzid.qstring() << " not known" << endl; + } + } + + void JSObjectProxy::addBindingsEnum( KJS::ExecState *exec, KJS::Object &object ) { + QMetaObject * mo = obj->metaObject(); + QStrList enumList = mo->enumeratorNames( true ); + + for ( QStrListIterator iter( enumList ); iter.current(); ++iter ) { + + const QMetaEnum *me = mo->enumerator( iter.current(), true ); + for ( uint i = 0 ; i < me->count ; i++ ) { + QCString key( ( me->items ) [ i ].key ); + int val = ( me->items ) [ i ].value; + object.put( exec, key.data(), KJS::Number( val ), KJS::ReadOnly ); + } + } + } + + void JSObjectProxy::addBindingsSlots( KJS::ExecState *exec, KJS::Object &object ) { + // Publish slots with supported signatures as methods. + QMetaObject * mo = obj->metaObject(); + QStrList slotList( mo->slotNames( true ) ); + for ( QStrListIterator iter( slotList ); iter.current(); ++iter ) { + addSlotBinding( iter.current(), exec, object ); + } + } + + void JSObjectProxy::addSlotBinding( const QCString &name, KJS::ExecState *exec, KJS::Object &object ) { + // Lookup and bind slot + QMetaObject * mo = obj->metaObject(); + int slotid = mo->findSlot( name.data(), true ); + if ( slotid == -1 ) + return ; + + const QMetaData *md = mo->slot( slotid, true ); + if ( md->access != QMetaData::Public ) + return ; + + // Find signature + int id = Bindings::JSSlotUtils::findSignature( name ); + // kdDebug( 80001 )<<"JSObjectProxy::addSlotBinding()::slot:"<<name<<" id:"<<id<<endl; + if ( id < 0 ) + return ; + + QCString jsname = name; + jsname.detach(); + jsname.replace( QRegExp( "\\([^\\)]*\\)" ), "" ); + + // Find the return type, we only care if it is a pointer type + const QUMethod *m = md->method; + const char *retclass = 0; + QCString ptr( "ptr" ); + + if ( m->count && ( m->parameters->inOut == QUParameter::Out ) + && ( ptr == m->parameters->type->desc() ) ) { + retclass = ( const char * ) m->parameters->typeExtra; + // kdDebug(80001) << "Return type is a pointer, type " << retclass << endl; + } + + // Create the Imp + JSObjectProxyImp *imp = new JSObjectProxyImp( exec, JSObjectProxyImp::MethodSlot, + retclass ? retclass : "", id, name, this ); + + if ( !object.hasProperty( exec, KJS::Identifier( jsname ) ) ) { + // The identifier is unused + object.put( exec, KJS::Identifier( jsname.data() ), KJS::Object( imp ) ); + } else { + // The identifier has already been used + QString s( name ); + QCString cs = QString( "%1%2" ).arg( jsname ).arg( s.contains( ',' ) + 1 ).ascii(); + //kdDebug(80001) << "Method " << jsname << " exists, using " << cs << " for " << s << endl; + object.put( exec, KJS::Identifier( cs.data() ), KJS::Object( imp ) ); + } + } + +} // namespace KJSEmbed + +// Local Variables: +// c-basic-offset: 4 +// End: + diff --git a/kjsembed/jsobjectproxy.h b/kjsembed/jsobjectproxy.h new file mode 100644 index 00000000..b302d4ad --- /dev/null +++ b/kjsembed/jsobjectproxy.h @@ -0,0 +1,202 @@ +// -*- c++ -*- + +/* + * Copyright (C) 2001-2003, Richard J. Moore <rich@kde.org> + * + * This 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. + * + * This 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 this library; see the file COPYING.LIB. If not, write to + * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, + * Boston, MA 02110-1301, USA. + */ + +#ifndef KJSEMBEDJSOBJECTPROXY_H +#define KJSEMBEDJSOBJECTPROXY_H +#include "global.h" +#include <qguardedptr.h> +#include <qcstring.h> +#include <qwidget.h> + +#include <kjs/object.h> +#include <kjsembed/jsproxy.h> +#include <kjsembed/jsbinding.h> + +namespace KJS { class Interpreter; } + +namespace KJSEmbed { + +namespace Bindings { class JSObjectProxyImp; } + +class JSSecurityPolicy; +class KJSEmbedPart; +class JSObjectEventProxy; + +/** + * A JS object that provides a binding to a QObject. + * <h3>Introduction</h3> + * This class defines a @ref KJS::ObjectImp that allows scripts to access + * the properties of a QObject. The scripts can also create child objects, + * load dialogs from .ui files created by Designer and navigate the object + * tree in a similar manner to the DCOP/QObject bridge. + * <h3>Example Usage</h3> + * The following example creates a @ref KJS::ObjectImp that provides + * a binding to the properties of a @ref QLineEdit . This binding is + * then used to create a property 'edit' for the object 'jsparent'. + * <pre> + * + * QLineEdit *edit = new QLineEdit(); + * KJSEmbed::JSObjectProxy *proxy = new KJSEmbed::JSObjectProxy( js, edit ); + * jsparent.put( js->globalExec(), "edit", proxy ); + * + * </pre> + * + * <h3>Security Facilities</h3> + * In order to ensure scripts don't run amok and to ensure the script + * interpreter used by KHTML remains secure, JSObjectProxy applies a + * security policy. Every time a script tries to access an object or + * property the following tests are performed: + * <ul> + * <li>Does this request come from the correct @ref KJS::Interpreter? + * <li>Is the script allowed to access the specified QObject? + * <li>Is the script allowed to access the specified property? + * </ul> + * The @ref KJSEmbed::JSSecurityPolicy class decides if the request should + * be granted. The security policy is automatically inherited by any child + * proxies created using the object tree accessor methods. + * + * @see KJSEmbed::JSFactory + * @author Richard Moore, rich@kde.org + * $Id$ + */ +class KJSEMBED_EXPORT JSObjectProxy : public JSProxy +{ +public: + /** + * Create a JS binding to the target object. The binding will allow scripts to + * access any QObject that is descended the target and no others. + */ + JSObjectProxy( KJSEmbedPart *part, QObject *target ); + + /** + * Create a JS binding to the target object. The binding will allow scripts to + * access any QObject that is descended from the specified root. If the specified + * root is 0 then access is granted to all objects. + */ + JSObjectProxy( KJSEmbedPart *part, QObject *target, QObject *root ); + + /** + * Create a JS binding to the target object. The binding will allow scripts to + * access any QObject that is descended from the specified root, according to + * the specified @ref JSSecurityPolicy . If the specified root is 0 then access + * is granted to all objects. + */ + JSObjectProxy( KJSEmbedPart *part, QObject *target, QObject *root, const JSSecurityPolicy *sp ); + + virtual ~JSObjectProxy(); + + /** Returns the KJSEmbedPart in which this proxy lives. */ + KJSEmbedPart *part() const { return jspart; } + + /** Returns the interpreter in which this proxy lives. */ + KJS::Interpreter *interpreter() const { return js; } + + /** Returns the root object that defines the limit of the scope of this proxy. */ + QObject *rootObject() const { return root; } + + /** Returns the QObject the proxy is attached to. */ + QObject *object() const { return obj; } + + /** Returns the className of the proxied object */ + QString typeName() const { return obj->className(); } + + /** Returns the associated QWidget, or 0 if the object is not a widget. */ + QWidget *widget() const + { + QObject *w = obj; + return (w && w->isWidgetType()) ? static_cast<QWidget *>(w) : 0; + } + + //void *toVoidStar() { return obj; } + //template<class T> + //T *toNative(){ return dynamic_cast<QObject*>(obj); } + + /** Returns true iff the content of this proxy inherits the specified base-class. */ + bool inherits( const char *clazz ) { return obj->isA( clazz ); } + + /** Returns the @ref JSSecurityPolicy of the proxy. */ + const JSSecurityPolicy *securityPolicy() const { return policy; } + + /** + * Specifies the @ref JSSecurityPolicy that should be applied to this proxy. + * Setting the policy to 0 restores the default policy. + */ + void setSecurityPolicy( const JSSecurityPolicy *sp ); + + /** Reimplemented to return the value of the specified property if present. */ + virtual KJS::Value get( KJS::ExecState *exec, const KJS::Identifier &p ) const; + + /** Reimplemented to set the value of the specified property if possible. */ + virtual void put( KJS::ExecState *exec, const KJS::Identifier &p, + const KJS::Value &v, int attr = KJS::None ); + + /** Reimplemented to return the name and class of the target. */ + virtual KJS::UString toString( KJS::ExecState *exec ) const; + + /** + * Adds methods for traversing the QObject tree to the specified + * @ref KJS::Object . Only QObjects descended from the root specified + * in the constructor can be reached through JS proxies created with + * these bindings. + * <ul> + * <li>properties() + * <li>create(...) + * </ul> + */ + virtual void addBindings( KJS::ExecState *exec, KJS::Object &object ); + +protected: + void addBindingsClass( KJS::ExecState *exec, KJS::Object &object ); + + /** + * Adds bindings for the constants defined by enums of the target. + */ + void addBindingsEnum( KJS::ExecState *exec, KJS::Object &object ); + + /** + * Adds bindings for slots defined by the target of the proxy. + */ + void addBindingsSlots( KJS::ExecState *exec, KJS::Object &object ); + + +private: + bool isAllowed( KJS::Interpreter *js ) const; + + void addSlotBinding( const QCString &name, KJS::ExecState *exec, KJS::Object &object ); + +private: + KJSEmbedPart *jspart; + KJS::Interpreter *js; + QGuardedPtr<QObject> obj; + QGuardedPtr<QObject> root; + QGuardedPtr<JSObjectEventProxy> evproxy; + const JSSecurityPolicy *policy; + class JSObjectProxyPrivate *d; + friend class Bindings::JSObjectProxyImp; +}; + +} // namespace KJSEmbed + +#endif // KJSEMBEDJSOBJECTPROXY_H + +// Local Variables: +// c-basic-offset: 4 +// End: diff --git a/kjsembed/jsobjectproxy_imp.cpp b/kjsembed/jsobjectproxy_imp.cpp new file mode 100644 index 00000000..a17190b5 --- /dev/null +++ b/kjsembed/jsobjectproxy_imp.cpp @@ -0,0 +1,638 @@ +/* + * Copyright (C) 2001-2003, Richard J. Moore <rich@kde.org> + * + * This 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. + * + * This 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 this library; see the file COPYING.LIB. If not, write to + * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, + * Boston, MA 02110-1301, USA. + */ + +#include <qobject.h> +#include <qobjectlist.h> +#include <qdialog.h> +#include <qlistbox.h> +#include <qlistview.h> +#include <qmetaobject.h> +#include <qregexp.h> +#include <qsignal.h> +#include <qstrlist.h> +#include <qtabwidget.h> +#include <qtimer.h> +#include <qvariant.h> + +#include <private/qucom_p.h> +#include <private/qucomextra_p.h> + +#include <kjs/interpreter.h> +#include <kjs/types.h> +#include <kjs/ustring.h> + +#include "kjsembedpart.h" +#include "jssecuritypolicy.h" + +#include "global.h" +#include "jsfactory.h" +#include "slotproxy.h" +#include "slotutils.h" +#include "jsobjectproxy.h" +#include "jsobjectproxy_imp.h" + +using namespace KJS; + +namespace KJSEmbed { +namespace Bindings { + +typedef JSProxy::MethodTable MethodTable; + +// +// Factory methods that add the bindings. +// + +void JSObjectProxyImp::addBindingsTree( KJS::ExecState *exec, KJS::Object &object, JSObjectProxy *proxy ) +{ + MethodTable methods[] = { + { MethodParent, "parent" }, + { MethodChildCount, "childCount" }, + { MethodChild, "child" }, + { MethodChildren, "children" }, + { MethodIsWidgetType, "isWidgetType" }, + { MethodClassName, "className" }, + { MethodSuperClassName, "superClassName" }, + { 0, 0 } + }; + + int i = 0; + do { + JSObjectProxyImp *obj = new JSObjectProxyImp( exec, methods[i].id, proxy ); + obj->setName( KJS::Identifier( methods[i].name ) ); + object.put( exec, methods[i].name, KJS::Object(obj) ); + i++; + } while( methods[i].id ); +} + +void JSObjectProxyImp::addBindingsDOM( KJS::ExecState *exec, KJS::Object &object, JSObjectProxy *proxy ) +{ + MethodTable methods[] = { + { MethodGetParentNode, "getParentNode" }, + { MethodGetElementById, "getElementById" }, + { MethodHasAttribute, "hasAttribute" }, + { MethodGetAttribute, "getAttribute" }, + { MethodSetAttribute, "setAttribute" }, + { 0, 0 } + }; + + int i = 0; + do { + JSObjectProxyImp *obj = new JSObjectProxyImp( exec, methods[i].id, proxy ); + obj->setName( KJS::Identifier( methods[i].name ) ); + object.put( exec, methods[i].name, KJS::Object(obj) ); + i++; + } while( methods[i].id ); +} + +void JSObjectProxyImp::addBindingsConnect( KJS::ExecState *exec, KJS::Object &object, JSObjectProxy *proxy ) +{ + MethodTable methods[] = { + { MethodConnect, "connect" }, + { MethodDisconnect, "disconnect" }, + { MethodSignals, "signals" }, + { MethodSlots, "slots" }, + { 0, 0 } + }; + + int i = 0; + do { + JSObjectProxyImp *obj = new JSObjectProxyImp( exec, methods[i].id, proxy ); + obj->setName( KJS::Identifier( methods[i].name ) ); + object.put( exec, methods[i].name, KJS::Object(obj) ); + i++; + } while( methods[i].id ); +} + +// +// The real implementation +// + +JSObjectProxyImp::JSObjectProxyImp( KJS::ExecState *exec, int mid, JSObjectProxy *parent ) + : JSProxyImp(exec), id(mid), proxy(parent), obj(parent->obj) +{ +} + +JSObjectProxyImp::JSObjectProxyImp( KJS::ExecState *exec, + int mid, const QCString &name, JSObjectProxy *parent ) + : JSProxyImp(exec), id(mid), slotname(name), proxy(parent), obj(parent->obj) +{ +} + +JSObjectProxyImp::JSObjectProxyImp( KJS::ExecState *exec, + int mid, int sid, const QCString &name, JSObjectProxy *parent ) + : JSProxyImp(exec), id(mid), sigid(sid), slotname(name), proxy(parent), obj(parent->obj) +{ +} + +JSObjectProxyImp::JSObjectProxyImp( KJS::ExecState *exec, + int mid, const char *ret, int sid, const QCString &name, + JSObjectProxy *parent ) + : JSProxyImp(exec), id(mid), rettype(ret), sigid(sid), slotname(name), proxy(parent), obj(parent->obj) +{ +} + +// +// Custom methods. +// + +KJS::Value JSObjectProxyImp::children( KJS::ExecState *exec, KJS::Object &, const KJS::List & ) +{ + KJS::List items; + const QObjectList *kids = obj->children(); + if ( kids ) { + QObjectList l( *kids ); + + for ( uint i = 0 ; i < l.count() ; i++ ) { + QObject *child = l.at( i ); + QCString nm = ( child ? child->name() : "<null>" ); + items.append( KJS::String( QString(nm) ) ); + } + } + + return KJS::Object( proxy->js->builtinArray().construct( exec, items ) ); +} + +KJS::Value JSObjectProxyImp::properties( KJS::ExecState *exec, KJS::Object &, const KJS::List & ) +{ + KJS::List items; + QMetaObject *mo = obj->metaObject(); + QStrList propList( mo->propertyNames( true ) ); + + for ( QStrListIterator iter(propList); iter.current(); ++iter ) { + + QCString name = iter.current(); + int propid = mo->findProperty( name.data(), true ); + if ( propid != -1 ) { + items.append( KJS::String( QString(name) ) ); + } + } + + return KJS::Object( proxy->js->builtinArray().construct( exec, items ) ); +} + +KJS::Value JSObjectProxyImp::callCustomSlot( KJS::ExecState *, KJS::Object &, const KJS::List & ) +{ + return KJS::Null(); +} + +// +// Invoke a slot or method. +// + +KJS::Value JSObjectProxyImp::callSlot( KJS::ExecState *exec, KJS::Object &self, const KJS::List &args ) +{ + return JSSlotUtils::invokeSlot( exec, self, args, this ); +} + +KJS::Value JSObjectProxyImp::call( KJS::ExecState *exec, KJS::Object &self, const KJS::List &args ) +{ + if ( !proxy->isAllowed(exec->interpreter()) ) { + kdWarning() << "JSObjectProxy::Method call from unknown interpreter!" << endl; + return KJS::Null(); + } + + if (obj.isNull()) { + kdWarning() << "JSObjectProxy::Method call on null object"<<endl; + return KJS::Null(); + } + + switch( id ) { + case MethodParent: + { + QObject *po = obj->parent(); + if ( po && proxy->securityPolicy()->isObjectAllowed( proxy, po ) ) + return proxy->part()->factory()->createProxy( exec, po, proxy ); + + return KJS::Null(); + } + break; + case MethodChildCount: + { + const QObjectList *kids = obj->children(); + return kids ? KJS::Number( kids->count() ) : KJS::Number(0); + } + break; + case MethodIsWidgetType: + { + return KJS::Boolean( obj->isWidgetType() ); + } + break; + case MethodClassName: + { + return KJS::String( obj->className() ); + } + break; + case MethodSuperClassName: + { + return KJS::String( obj->metaObject()->superClassName() ); + } + break; + case MethodChildren: + return children( exec, self, args ); + break; + case MethodProps: + return properties( exec, self, args ); + break; + case MethodSlot: + return callSlot( exec, self, args ); + break; + case MethodChild: + case MethodGetElementById: + return getElementById( exec, self, args ); + break; + case MethodGetParentNode: + return getParentNode( exec, self, args ); + break; + case MethodHasAttribute: + return hasAttribute( exec, self, args ); + break; + case MethodGetAttribute: + return getAttribute( exec, self, args ); + break; + case MethodSetAttribute: + return setAttribute( exec, self, args ); + break; + case MethodGetElementsByTagName: + return getElementsByTagName( exec, self, args ); + break; + case MethodSignals: + return signalz( exec, self, args ); + break; + case MethodSlots: + return slotz( exec, self, args ); + break; + case MethodConnect: + return connect( exec, self, args ); + case MethodDisconnect: + return disconnect( exec, self, args ); + default: + break; + } + + return ObjectImp::call( exec, self, args ); +} + +// +// Connections +// + +KJS::Value JSObjectProxyImp::signalz( KJS::ExecState *exec, KJS::Object &, const KJS::List & ) +{ + KJS::List items; + QMetaObject *mo = obj->metaObject(); + QStrList signalList( mo->signalNames( true ) ); + + for ( QStrListIterator iter(signalList); iter.current(); ++iter ) { + + QCString name = iter.current(); + QString nm( name ); + + int signalid = mo->findSignal( name.data(), true ); + if ( (signalid != -1) && (mo->signal( signalid, true )->access == QMetaData::Public) ) + items.append( KJS::String(nm) ); + } + + return KJS::Object( proxy->js->builtinArray().construct( exec, items ) ); +} + +KJS::Value JSObjectProxyImp::slotz( KJS::ExecState *exec, KJS::Object &, const KJS::List & ) +{ + KJS::List items; + QMetaObject *mo = obj->metaObject(); + QStrList slotList( mo->slotNames( true ) ); + + for ( QStrListIterator iter(slotList); iter.current(); ++iter ) { + + QCString name = iter.current(); + QString nm( name ); + + int slotid = mo->findSlot( name.data(), true ); + if ( (slotid != -1) && (mo->slot( slotid, true )->access == QMetaData::Public) ) + items.append( KJS::String(nm) ); + } + + return KJS::Object( proxy->js->builtinArray().construct( exec, items ) ); +} + +KJS::Boolean JSObjectProxyImp::connect( KJS::ExecState *exec, + const KJS::Object &self, const KJS::List &args ) +{ + // connect sender, sig, slot + // connect sender, sig, recv, method + + if ( (args.size() != 3) && (args.size() != 4) ) + return KJS::Boolean(false); + + // Source object and signal + JSObjectProxy *sendproxy = JSProxy::toObjectProxy( args[0].imp() ); + QObject *sender = sendproxy ? sendproxy->object() : 0; + QString sig = args[1].toString(exec).qstring(); + kdDebug( 80001 ) << "connecting C++ signal" << sig << endl; + // Receiver and slot/signal + KJS::Object recvObj; + QString dest; + if ( args.size() == 3 ) { + recvObj = self.toObject(exec); + dest = args[2].toString(exec).qstring(); + } + else if ( args.size() == 4 ) { + recvObj = args[2].toObject(exec); + dest = args[3].toString(exec).qstring(); + } + + // Try to connect to C++ slot + JSObjectProxy *recvproxy = JSProxy::toObjectProxy( recvObj.imp() ); + if ( recvproxy ) { + QObject *recv = recvproxy ? recvproxy->object() : 0; + bool ok = JSSlotUtils::connect( sender, sig.ascii(), recv, dest.ascii() ); + if ( ok ) + return KJS::Boolean(true); + } + + return connect( sender, sig.ascii(), recvObj, dest ); +} + +KJS::Boolean JSObjectProxyImp::connect( QObject *sender, const char *sig, + const KJS::Object &recv, const QString &dest ) +{ + kdDebug(80001) << "Trying signature '" << sig << "'." << endl; + // Try to connect to JS method + JSSlotProxy *slotp = new JSSlotProxy( sender ); + slotp->setInterpreter( proxy->interpreter() ); + slotp->setProxy( proxy ); + slotp->setObject( recv ); + slotp->setMethod( dest ); + + int id = JSSlotUtils::findSignature( sig ); + if ( id == JSSlotUtils::SignatureNotSupported ) { + kdWarning(80001) << "Connect with unknown signature '" << sig << "' failed" << endl; + return KJS::Boolean( false ); + } + + bool ok; + switch ( id ) { + case JSSlotUtils::SignatureNone: + ok = JSSlotUtils::connect( sender, sig, slotp, "slot_void()" ); + break; + case JSSlotUtils::SignatureInt: + ok = JSSlotUtils::connect( sender, sig, slotp, "slot_int(int)" ); + break; + case JSSlotUtils::SignatureUInt: + ok = JSSlotUtils::connect( sender, sig, slotp, "slot_uint(uint)" ); + break; + case JSSlotUtils::SignatureLong: + ok = JSSlotUtils::connect( sender, sig, slotp, "slot_long(long)" ); + break; + case JSSlotUtils::SignatureULong: + ok = JSSlotUtils::connect( sender, sig, slotp, "slot_ulong(ulong)" ); + break; + case JSSlotUtils::SignatureBool: + ok = JSSlotUtils::connect( sender, sig, slotp, "slot_bool(bool)" ); + break; + case JSSlotUtils::SignatureDouble: + ok = JSSlotUtils::connect( sender, sig, slotp, "slot_double(double)" ); + break; + case JSSlotUtils::SignatureString: + ok = JSSlotUtils::connect( sender, sig, slotp, "slot_string(const QString&)" ); + break; + case JSSlotUtils::SignatureCString: + ok = JSSlotUtils::connect( sender, sig, slotp, "slot_charstar(const char*)" ); + break; + case JSSlotUtils::SignatureColor: + ok = JSSlotUtils::connect( sender, sig, slotp, "slot_color(const QColor&)" ); + break; + case JSSlotUtils::SignatureFont: + ok = JSSlotUtils::connect( sender, sig, slotp, "slot_font(const QFont&)" ); + break; + case JSSlotUtils::SignaturePoint: + ok = JSSlotUtils::connect( sender, sig, slotp, "slot_point(const QPoint&)" ); + break; + case JSSlotUtils::SignatureRect: + ok = JSSlotUtils::connect( sender, sig, slotp, "slot_rect(const QRect&)" ); + break; + case JSSlotUtils::SignatureSize: + ok = JSSlotUtils::connect( sender, sig, slotp, "slot_size(const QSize&)" ); + break; + case JSSlotUtils::SignaturePixmap: + ok = JSSlotUtils::connect( sender, sig, slotp, "slot_pixmap(const QPixmap&)" ); + break; + case JSSlotUtils::SignatureURL: + ok = JSSlotUtils::connect( sender, sig, slotp, "slot_url(const KURL&)" ); + break; + case JSSlotUtils::SignatureIntInt: + ok = JSSlotUtils::connect( sender, sig, slotp, "slot_intint(int, int)" ); + break; + case JSSlotUtils::SignatureIntBool: + ok = JSSlotUtils::connect( sender, sig, slotp, "slot_intbool(int, bool)" ); + break; + case JSSlotUtils::SignatureIntIntIntInt: + ok = JSSlotUtils::connect( sender, sig, slotp, "slot_intintint(int, int, int)" ); + break; + + case JSSlotUtils::SignatureDate: + ok = JSSlotUtils::connect( sender, sig, slotp, "slot_date(const QDate&)" ); + break; + case JSSlotUtils::SignatureTime: + ok = JSSlotUtils::connect( sender, sig, slotp, "slot_time(const QTime&)" ); + break; + case JSSlotUtils::SignatureDateTime: + ok = JSSlotUtils::connect( sender, sig, slotp, "slot_datetime(const QDateTime&)" ); + break; + case JSSlotUtils::SignatureImage: + ok = JSSlotUtils::connect( sender, sig, slotp, "slot_image(const QImage&)" ); + break; + case JSSlotUtils::SignatureQWidget: + ok = JSSlotUtils::connect( sender, sig, slotp, "slot_widget(QWidget*)" ); + break; + case JSSlotUtils::SignatureDateDate: + ok = JSSlotUtils::connect( sender, sig, slotp, "slot_datedate(const QDate&, const QDate& )" ); + break; + case JSSlotUtils::SignatureColorString: + ok = JSSlotUtils::connect( sender, sig, slotp, "slot_colorstring(const QColor&, const QString&)" ); + break; + case JSSlotUtils::SignatureCustom: + { + QString mangledSig = sig; + mangledSig.remove(' ') + .remove("const") + .remove('&') + .remove('*'); + mangledSig = mangledSig.lower(); + + kdDebug(80001) << "Custom slot signature: " << mangledSig << endl; + break; + } + default: + kdWarning(80001) << "Unsupported signature '" << sig << "' connected with no args" << endl; + ok = JSSlotUtils::connect( sender, sig, slotp, "slot_none()" ); + break; + } + + if ( !ok ) { + kdDebug(80001) << "Error connecting '" << sig << "'" << endl; + } + + return KJS::Boolean(ok); +} + +KJS::Boolean JSObjectProxyImp::disconnect( KJS::ExecState *exec, KJS::Object &self, const KJS::List &args ) +{ + // disconnect sender, sig, slot + // disconnect sender, sig, recv, method + + if ( (args.size() != 3) && (args.size() != 4) ) + return KJS::Boolean(false); + + // Source object and signal + JSObjectProxy *sendproxy = JSProxy::toObjectProxy( args[0].imp() ); + QObject *sender = sendproxy ? sendproxy->object() : 0; + QString sig = args[1].toString(exec).qstring(); + + // Receiver and slot/signal + QObject *recv=0; + QString dest; + if ( args.size() == 3 ) { + JSObjectProxy *recvproxy = JSProxy::toObjectProxy( self.imp() ); + recv = recvproxy ? recvproxy->object() : 0; + dest = args[2].toString(exec).qstring(); + } + else if ( args.size() == 4 ) { + JSObjectProxy *recvproxy = JSProxy::toObjectProxy( args[2].imp() ); + recv = recvproxy ? recvproxy->object() : 0; + dest = args[3].toString(exec).qstring(); + } + + return JSSlotUtils::disconnect( exec, self, sender, sig.ascii(), recv, dest.ascii() ); +} + +// +// DOM methods +// + +KJS::Value JSObjectProxyImp::getParentNode( KJS::ExecState *exec, KJS::Object &, const KJS::List &args ) +{ + if ( args.size()) + return KJS::Null(); + + QObject *parent = obj->parent(); + if ( parent && proxy->securityPolicy()->isObjectAllowed( proxy, parent ) ) + return proxy->part()->factory()->createProxy( exec, parent, proxy ); + + return KJS::Null(); +} + +KJS::Value JSObjectProxyImp::getElementById( KJS::ExecState *exec, KJS::Object &, const KJS::List &args ) +{ + if ( !args.size() ) + return KJS::Null(); + + const QObjectList *kids = obj->children(); + if ( !kids ) + return KJS::Null(); + + QObjectList l( *kids ); + QObject *child = 0; + + if ( args[0].isA( KJS::NumberType ) ) { + uint i = args[0].toUInt32( exec ); + + if ( i >= l.count() ) + return KJS::Null(); + + child = l.at( i ); + } + else { + QString s = args[0].toString( exec ).qstring(); + child = obj->child( s.ascii() ); + } + + if ( child && proxy->securityPolicy()->isObjectAllowed( proxy, child ) ) { + kdDebug(80001) << "Creating subproxy for child " << child->className() << endl; + return proxy->part()->factory()->createProxy( exec, child, proxy ); + } + + return KJS::Null(); +} + +KJS::Value JSObjectProxyImp::getElementsByTagName( KJS::ExecState *, KJS::Object &, const KJS::List & ) +{ + return KJS::Null(); +} + +KJS::Value JSObjectProxyImp::hasAttribute( KJS::ExecState *exec, KJS::Object &, const KJS::List &args ) +{ + if ( !args.size() ) + return KJS::Null(); + + QMetaObject *meta = obj->metaObject(); + QString s = args[0].toString(exec).qstring(); + if ( meta->findProperty( s.ascii(), true ) != -1 ) + return KJS::Boolean(true); + else + return KJS::Boolean(false); +} + +KJS::Value JSObjectProxyImp::getAttribute( KJS::ExecState *exec, KJS::Object &, const KJS::List &args ) +{ + if ( !args.size() ) + { + QString msg = i18n( "No property was defined." ); + return throwError(exec, msg); + } + + QMetaObject *meta = obj->metaObject(); + QString s = args[0].toString(exec).qstring(); + kdDebug(80001) << "Get property " << s << " from " << obj->name() << endl; + if ( meta->findProperty( s.ascii(), true ) == -1 ) + { + QString msg = i18n( "Property '%1' could not be found." ).arg( s ); + return throwError(exec, msg,KJS::ReferenceError); + } + + QVariant val = obj->property( s.ascii() ); + return convertToValue( exec, val ); +} + +KJS::Value JSObjectProxyImp::setAttribute( KJS::ExecState *exec, KJS::Object &, const KJS::List &args ) +{ + if ( args.size() != 2 ) + return KJS::Boolean(false); + + QMetaObject *meta = obj->metaObject(); + QString s = args[0].toString(exec).qstring(); + + if ( meta->findProperty( s.ascii(), true ) == -1 ) + { + QString msg = i18n( "Property '%1' could not be found." ).arg( s ); + return throwError(exec, msg,KJS::GeneralError); + } + kdDebug(80001) << "Set property " << s << " from " << obj->name() << endl; + QVariant val = convertToVariant( exec, args[1] ); + bool ok = obj->setProperty( s.ascii(), val ); + + return KJS::Boolean(ok); +} + +} // namespace KJSEmbed::Bindings +} // namespace KJSEmbed + +// Local Variables: +// c-basic-offset: 4 +// End: + diff --git a/kjsembed/jsobjectproxy_imp.h b/kjsembed/jsobjectproxy_imp.h new file mode 100644 index 00000000..b967c362 --- /dev/null +++ b/kjsembed/jsobjectproxy_imp.h @@ -0,0 +1,189 @@ +// -*- c++ -*- + +/* + * Copyright (C) 2001-2003, Richard J. Moore <rich@kde.org> + * + * This 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. + * + * This 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 this library; see the file COPYING.LIB. If not, write to + * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, + * Boston, MA 02110-1301, USA. + */ + +#ifndef KJSEMBEDJSOBJECTPROXYIMP_H +#define KJSEMBEDJSOBJECTPROXYIMP_H + +#include <qguardedptr.h> + +#include <kjs/interpreter.h> +#include <kjsembed/jsproxy_imp.h> +#include <kjsembed/jsfactory.h> + +namespace KJSEmbed { +namespace Bindings { + +/** + * Implements the JS methods of KJSEmbed::ObjectProxy. + * + * @author Richard Moore, rich@kde.org + * @version $Id$ + */ +class JSObjectProxyImp : public JSProxyImp +{ +public: + /** Identifiers for the method implementations available. */ + enum MethodId { + /** Indicates an error, usually an supported signature. */ + MethodInternalError, + + /** Meta info about the object. */ + /* { */ + MethodProps, + MethodIsWidgetType, MethodClassName, MethodSuperClassName, + /* } */ + + /** Methods for accessing the object tree. */ + /* { */ + MethodChildren, MethodParent, MethodChild, MethodChildCount, + /* } */ + + /** Fast slot signature. */ + MethodSlot, + + /** Custom slot signature. */ + MethodCustomSlot, + + /** Connections. */ + /* { */ + MethodSignals, MethodSlots, + MethodConnect, MethodDisconnect, + /* } */ + + /** DOM methods. */ + /* { */ + MethodGetParentNode, MethodGetElementById, MethodGetElementsByTagName, + MethodHasAttribute, MethodGetAttribute, MethodSetAttribute, + /* } */ + + /** Custom method. */ + MethodCustom = 0x1000 + }; + + /** + * Adds the tree bindings to the proxy. + * <ul> + * <li>parent() + * <li>childAt(int index) + * <li>childCount() + * <li>findChild(string name) + * <li>child(string name) + * <li>child(int index) + * </ul> + */ + static void addBindingsTree( KJS::ExecState *exec, KJS::Object &object, JSObjectProxy *proxy ); + + /** + * Adds the DOM bindings to the proxy. + * <ul> + * <li>getElementById(name) + * <li>hasAttribute(name) + * <li>getAttribute(name) + * <li>setAttribute(name,value) + * </ul> + */ + static void addBindingsDOM( KJS::ExecState *exec, KJS::Object &object, JSObjectProxy *proxy ); + + /** + * Adds the connect bindings to the proxy. + * <ul> + * <li>connect(signal,receiver,slot) + * <li>disconnect(signal,receiver,slot) + * </ul> + */ + static void addBindingsConnect( KJS::ExecState *exec, KJS::Object &object, JSObjectProxy *proxy ); + + + JSObjectProxyImp( KJS::ExecState *exec, + int id, JSObjectProxy *parent ); + JSObjectProxyImp( KJS::ExecState *exec, + int id, const QCString &name, JSObjectProxy *parent ); + JSObjectProxyImp( KJS::ExecState *exec, + int id, int sigid, const QCString &name, JSObjectProxy *parent ); + JSObjectProxyImp( KJS::ExecState *exec, + int id, const char *ret, int sig, const QCString &name, JSObjectProxy *parent ); + ~JSObjectProxyImp() {} + + /** Implements the object tree interface. */ + /*{*/ + KJS::Value childAt( KJS::ExecState *exec, KJS::Object &self, const KJS::List &args ); + KJS::Value findChild( KJS::ExecState *exec, KJS::Object &self, const KJS::List &args ); + + KJS::Value children( KJS::ExecState *exec, KJS::Object &self, const KJS::List &args ); + KJS::Value properties( KJS::ExecState *exec, KJS::Object &self, const KJS::List &args ); + /*}*/ + + /** Implements the DOM interface. */ + /*{*/ + KJS::Value getParentNode( KJS::ExecState *exec, KJS::Object &self, const KJS::List &args ); + KJS::Value getElementById( KJS::ExecState *exec, KJS::Object &self, const KJS::List &args ); + KJS::Value getElementsByTagName( KJS::ExecState *exec, KJS::Object &self, const KJS::List &args ); + + KJS::Value hasAttribute( KJS::ExecState *exec, KJS::Object &self, const KJS::List &args ); + KJS::Value getAttribute( KJS::ExecState *exec, KJS::Object &self, const KJS::List &args ); + KJS::Value setAttribute( KJS::ExecState *exec, KJS::Object &self, const KJS::List &args ); + /*}*/ + + /** Calls the slots. */ + KJS::Value callSlot( KJS::ExecState *exec, KJS::Object &self, const KJS::List &args ); + + /** Implements signal-slot support. */ + /*{*/ + KJS::Value signalz( KJS::ExecState *exec, KJS::Object &self, const KJS::List &args ); + KJS::Value slotz( KJS::ExecState *exec, KJS::Object &self, const KJS::List &args ); + + KJS::Boolean connect( KJS::ExecState *exec, const KJS::Object &self, const KJS::List &args ); + KJS::Boolean disconnect( KJS::ExecState *exec, KJS::Object &self, const KJS::List &args ); + + KJS::Boolean connect( QObject *sender, const char *sig, const KJS::Object &recv, const QString &dest ); + /*}*/ + + virtual bool implementsCall() const { return true; } + virtual KJS::Value call( KJS::ExecState *exec, KJS::Object &self, const KJS::List &args ); + + const char *returnType() const { return rettype; } + const char *slotName() const { return slotname; } + int signature() const { return sigid; } + JSObjectProxy *objectProxy() const { return proxy; } + +protected: + /** Calls a slot that has a custom signature. */ + KJS::Value callCustomSlot( KJS::ExecState *exec, KJS::Object &self, const KJS::List &args ); + +private: + int id; + QCString rettype; // return type + int sigid; // signatureid + int slotid; + QCString slotname; + JSObjectProxy *proxy; + QGuardedPtr<QObject> obj; + class JSObjectProxyImpPrivate *d; +}; + +} // namespace KJSEmbed::Bindings +} // namespace KJSEmbed + +#endif // KJSEMBEDJSOBJECTPROXYIMP_H + +// Local Variables: +// c-basic-offset: 4 +// End: diff --git a/kjsembed/jsopaqueproxy.cpp b/kjsembed/jsopaqueproxy.cpp new file mode 100644 index 00000000..c5c2600d --- /dev/null +++ b/kjsembed/jsopaqueproxy.cpp @@ -0,0 +1,137 @@ +/* + * Copyright (C) 2001-2003, Richard J. Moore <rich@kde.org> + * + * This 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. + * + * This 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 this library; see the file COPYING.LIB. If not, write to + * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, + * Boston, MA 02110-1301, USA. + */ + +#include <qevent.h> +#include <qtextstream.h> + +#include "global.h" + +#include <kjs/interpreter.h> +#include <kjs/types.h> +#include <kjs/ustring.h> + +#include "jsbinding.h" +#include "jsobjectproxy.h" +#include "jsobjectproxy_imp.h" +#include "jsvalueproxy_imp.h" + +#include "jsopaqueproxy_imp.h" +#include "jsopaqueproxy.h" + +namespace KJSEmbed { + +typedef Bindings::JSOpaqueProxyImp JSOpaqueProxyImp; + +JSOpaqueProxy::JSOpaqueProxy() + : JSProxy( JSProxy::OpaqueProxy ), ptr(0) +{ +} + +JSOpaqueProxy::JSOpaqueProxy( QTextStream *ts ) + : JSProxy( JSProxy::OpaqueProxy ), ptr(0) +{ + setValue( ts ); +} + +JSOpaqueProxy::JSOpaqueProxy( const QEvent *ev ) + : JSProxy( JSProxy::OpaqueProxy ), ptr(0) +{ + setValue( ev ); +} + +JSOpaqueProxy::~JSOpaqueProxy() +{ + kdDebug() << "Delete JSOpaqueProxy " << endl; + + if( ptr ) { + if(owner() == JavaScript + && ptr->type() != typeid(void) ) ptr->cleanup(); + delete ptr; + } +} + +QString JSOpaqueProxy::typeName() const +{ + return ptrtype; +} + +bool JSOpaqueProxy::inherits( const char *clazz ) +{ + return (ptrtype == clazz); +} + +void JSOpaqueProxy::setValue( QTextStream *ts ) +{ + if( ptr ) { + if(owner() == JavaScript) ptr->cleanup(); + delete ptr; + } + ptr = new Pointer<QTextStream>(ts); + ptrtype = "QTextStream"; +} + +void JSOpaqueProxy::setValue( const QEvent *ev ) +{ + if( ptr ) { + if(owner() == JavaScript) ptr->cleanup(); + delete ptr; + } + ptr = new Pointer<const QEvent>(ev); + ptrtype = "QEvent"; +} + +QTextStream *JSOpaqueProxy::toTextStream() +{ + return toNative<QTextStream>(); +} + +const QEvent *JSOpaqueProxy::toEvent() +{ + return toNative<QEvent>(); +} + +void JSOpaqueProxy::addBindings( KJS::ExecState *exec, KJS::Object &object ) +{ + MethodTable methods[] = { + { JSOpaqueProxyImp::MethodTypeName, "typeName" }, + { 0, 0 } + }; + + int i = 0; + do { + JSOpaqueProxyImp *obj = new JSOpaqueProxyImp( exec, methods[i].id, this ); + obj->setName( KJS::Identifier( methods[i].name ) ); + object.put( exec , obj->name(), KJS::Object(obj) ); + i++; + } while( methods[i].id ); +} + +KJS::UString JSOpaqueProxy::toString( KJS::ExecState */*exec*/ ) const +{ + QString s( "%1 (%2)" ); + return KJS::UString( s.arg("JSOpaqueProxy").arg(ptrtype) ); +} + + +} // namespace KJSEmbed + +// Local Variables: +// c-basic-offset: 4 +// End: + diff --git a/kjsembed/jsopaqueproxy.h b/kjsembed/jsopaqueproxy.h new file mode 100644 index 00000000..f29458cf --- /dev/null +++ b/kjsembed/jsopaqueproxy.h @@ -0,0 +1,172 @@ +// -*- c++ -*- + +/* + * Copyright (C) 2001-2003, Richard J. Moore <rich@kde.org> + * + * This 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. + * + * This 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 this library; see the file COPYING.LIB. If not, write to + * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, + * Boston, MA 02110-1301, USA. + */ + +#ifndef KJSEMBEDJSOPAQUEPROXY_H +#define KJSEMBEDJSOPAQUEPROXY_H + +#include <qcstring.h> +#include <qevent.h> + +#include <kjs/object.h> +#include <kjsembed/jsproxy.h> + +#include <algorithm> +#include <typeinfo> + +class QTextStream; + +namespace KJSEmbed { + +/** + * Provides a binding to an opaque pointer value. This class stores a pointer + * without interpreting its type, it also stores the name of the type allowing + * it to retain type-safety. + * + * @author Richard Moore, rich@kde.org + */ +class KJSEMBED_EXPORT JSOpaqueProxy : public JSProxy +{ +public: + /** Creates an opaque proxy. */ + JSOpaqueProxy(); + + /** Creates an opaque proxy. */ + template<typename T> + JSOpaqueProxy( T *nptr, const char *ptype ) + : JSProxy( JSProxy::OpaqueProxy ), ptrtype(ptype), ptr(new Pointer<T>(nptr)) + { + + } + + /** Creates an opaque proxy. */ + JSOpaqueProxy( QTextStream *ts ); + + /** Creates an opaque proxy. */ + JSOpaqueProxy( const QEvent *ev ); + + /** Cleans up. */ + virtual ~JSOpaqueProxy(); + + /** Returns the type of the wrapped object.*/ + QString typeName() const; + + /** Sets the value of the proxy and its type. */ + template<typename T> + void setValue( T *nptr, const char *ptype ) { + if( ptr ) { + if(owner() == JavaScript) ptr->cleanup(); + delete ptr; + } + ptr = new Pointer<T>(nptr); + ptrtype = ptype ? ptype : "void"; + } + + /** Sets the value of the proxy to a QTextStream. */ + void setValue( QTextStream *ts ); + + /** Sets the value of the proxy to a QEvent. */ + void setValue( const QEvent *ev ); + + /** Returns the proxy value as a pointer. */ + template<typename T> + T *toNative() { + if( !ptr ) return 0L; // empty + T *value = 0L; + return (T*)ptr->voidStar(); // Hack for now + return value; // return real value + } + + /** Returns true iff the content of this proxy inherits the specified base-class. */ + bool inherits( const char *clazz ); + + /** + * Returns the QTextStream stored in the proxy. If proxy does not contain + * a value of type QTextStream then 0 is returned. + */ + QTextStream *toTextStream(); + + const QEvent *toEvent(); + + /** Adds the bindings for the opaque proxy to the specified js object. */ + virtual void addBindings( KJS::ExecState *state, KJS::Object &object ); + + /** Reimplemented to return the name and class of the target. */ + virtual KJS::UString toString( KJS::ExecState *exec ) const; + +private: + + QTextStream *textstream; + const QEvent *event; + QCString ptrtype; + + class JSOpaqueProxyPrivate *d; + + // container objects + class PointerBase + { + public: + virtual ~PointerBase() {}; + virtual void cleanup() = 0; + virtual const std::type_info &type() const = 0; + virtual void *voidStar() = 0; + //template<typename ValueType> + //virtual void castTo(ValueType *& val) = 0L; + }; + + template<typename ValueType> + class Pointer : public PointerBase + { + public: + Pointer( ValueType *value) : ptr(value) {} + ~Pointer( ) {} + void cleanup() + { + delete ptr; + ptr=0L; + } + const std::type_info &type() const + { + return typeid(ValueType); + } + + void *voidStar() + { + return (void*)ptr; + } + //template<typename type> + //virtual void castTo(type *& val) + //{ + // val = dynamic_cast<type*>(ptr); + // kdDebug() << "Type " << val << endl; + //} + ValueType *ptr; + }; + + PointerBase *ptr; +}; + +} // namespace KJSEmbed + +#endif // KJSEMBEDJSOPAQUEPROXYIMP_H + +// Local Variables: +// c-basic-offset: 4 +// End: diff --git a/kjsembed/jsopaqueproxy_imp.cpp b/kjsembed/jsopaqueproxy_imp.cpp new file mode 100644 index 00000000..65ff14cc --- /dev/null +++ b/kjsembed/jsopaqueproxy_imp.cpp @@ -0,0 +1,65 @@ +/* + * Copyright (C) 2001-2003, Richard J. Moore <rich@kde.org> + * + * This 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. + * + * This 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 this library; see the file COPYING.LIB. If not, write to + * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, + * Boston, MA 02110-1301, USA. + */ + +#include <qvariant.h> +#include "global.h" + +#include <kjs/interpreter.h> +#include <kjs/types.h> +#include <kjs/ustring.h> + +#include "jsobjectproxy.h" +#include "jsobjectproxy_imp.h" + +#include "jsopaqueproxy.h" +#include "jsopaqueproxy_imp.h" + +using namespace KJS; +namespace KJSEmbed { +namespace Bindings { + +JSOpaqueProxyImp::JSOpaqueProxyImp( KJS::ExecState *exec, int mid, const JSOpaqueProxy *parent ) + : JSProxyImp(exec), id(mid), proxy(parent) +{ +} + +JSOpaqueProxyImp::~JSOpaqueProxyImp() +{ +} + +KJS::Value JSOpaqueProxyImp::call( KJS::ExecState *exec, KJS::Object &self, const KJS::List &args ) +{ + switch( id ) { + case MethodTypeName: + { + return KJS::String( proxy->typeName() ); + } + break; + } + + return ObjectImp::call( exec, self, args ); +} + +} // namespace Bindings +} // namespace KJSEmbed + +// Local Variables: +// c-basic-offset: 4 +// End: + diff --git a/kjsembed/jsopaqueproxy_imp.h b/kjsembed/jsopaqueproxy_imp.h new file mode 100644 index 00000000..b6dda2f1 --- /dev/null +++ b/kjsembed/jsopaqueproxy_imp.h @@ -0,0 +1,66 @@ +// -*- c++ -*- + +/* + * Copyright (C) 2001-2003, Richard J. Moore <rich@kde.org> + * + * This 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. + * + * This 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 this library; see the file COPYING.LIB. If not, write to + * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, + * Boston, MA 02110-1301, USA. + */ + +#ifndef KJSEMBEDJSOPAQUEPROXYIMP_H +#define KJSEMBEDJSOPAQUEPROXYIMP_H + +#include <qcstring.h> +#include <kjs/object.h> +#include <kjsembed/jsproxy_imp.h> + +namespace KJSEmbed { class JSOpaqueProxy; } + +namespace KJSEmbed { +namespace Bindings { + +/** + * Provides a binding to an opaque value. + * + * @author Richard Moore, rich@kde.org + */ +class JSOpaqueProxyImp : public JSProxyImp +{ +public: + enum Methods { + MethodInternalError, + MethodTypeName + }; + + JSOpaqueProxyImp( KJS::ExecState *exec, int id, const JSOpaqueProxy *parent ); + virtual ~JSOpaqueProxyImp(); + + virtual bool implementsCall() const { return true; } + virtual KJS::Value call( KJS::ExecState *exec, KJS::Object &self, const KJS::List &args ); + +private: + int id; + const JSOpaqueProxy *proxy; + class JSOpaqueProxyImpPrivate *d; +}; + +} // namespace KJSEmbed::Bindings +} // namespace KJSEmbed + +#endif // KJSEMBEDJSOPAQUEPROXYIMP_H + +// Local Variables: +// c-basic-offset: 4 +// End: diff --git a/kjsembed/jsproxy.cpp b/kjsembed/jsproxy.cpp new file mode 100644 index 00000000..838cbd65 --- /dev/null +++ b/kjsembed/jsproxy.cpp @@ -0,0 +1,122 @@ + + +/* + * Copyright (C) 2001-2004, Richard J. Moore <rich@kde.org> + * + * This 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. + * + * This 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 this library; see the file COPYING.LIB. If not, write to + * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, + * Boston, MA 02110-1301, USA. + */ + +#include "global.h" + +#include "jsobjectproxy.h" +#include "jsvalueproxy.h" +#include "jsopaqueproxy.h" + +#include "jsproxy.h" + +namespace KJSEmbed { + +JSProxy::JSProxy( int type ) + : KJS::ObjectImp(), ownership(Native), + proxytype(type) +{ +} + +JSProxy::~JSProxy() +{ + if( ownership == Native ) + kdDebug() << "C++ JSProxy " << proxytype << " going away" << endl; + else + kdDebug() << "JS JSProxy " << proxytype << " going away" << endl; +} + +JSObjectProxy *JSProxy::toObjectProxy() +{ + return dynamic_cast<JSObjectProxy *>( this ); +} + +JSValueProxy *JSProxy::toValueProxy() +{ + return dynamic_cast<JSValueProxy *>( this ); +} + +JSOpaqueProxy *JSProxy::toOpaqueProxy() +{ + return dynamic_cast<JSOpaqueProxy *>( this ); +} +void JSProxy::setOwner( Owner state ) +{ + kdDebug(80001) << "Set ownership for " << typeName() << " to " << state << endl; + ownership = state; +} + + +JSProxy::Owner JSProxy::owner( ) const +{ return ownership; } + +bool JSProxy::checkType( const KJS::Object &object, ProxyType prxyType, const QString & classname ) +{ + JSProxy *prxy = toProxy(object.imp()); + if( !prxy ) + return false; + if( prxy->proxyType() != prxyType ) + return false; + if( prxy->typeName() != classname ) + return false; + return true; +} + + +// +// Static conversion methods +// +JSProxy *JSProxy::toProxy( KJS::ValueImp *imp ) +{ + return dynamic_cast<JSProxy *>( imp ); +} + +JSObjectProxy *JSProxy::toObjectProxy( KJS::ValueImp *imp ) +{ + return dynamic_cast<JSObjectProxy *>( imp ); +} + +JSValueProxy *JSProxy::toValueProxy( KJS::ValueImp *imp ) +{ + return dynamic_cast<JSValueProxy *>( imp ); +} + +JSOpaqueProxy *JSProxy::toOpaqueProxy( KJS::ValueImp *imp ) +{ + return dynamic_cast<JSOpaqueProxy *>( imp ); +} + +void JSProxy::addEnums( KJS::ExecState * exec, EnumTable * table, KJS::Object & object ) +{ + int enumidx = 0; + if( !table[enumidx].id ) return; // check for empty list + do { + object.put( exec, table[enumidx].id, KJS::Number(table[enumidx].val), KJS::ReadOnly ); + ++enumidx; + } while( table[enumidx].id ); +} + +} + + // namespace KJSEmbed + +// Local Variables: +// c-basic-offset: 4 +// End: diff --git a/kjsembed/jsproxy.h b/kjsembed/jsproxy.h new file mode 100644 index 00000000..df7615eb --- /dev/null +++ b/kjsembed/jsproxy.h @@ -0,0 +1,184 @@ +// -*- c++ -*- + +/* + * Copyright (C) 2001-2004, Richard J. Moore <rich@kde.org> + * + * This 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. + * + * This 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 this library; see the file COPYING.LIB. If not, write to + * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, + * Boston, MA 02110-1301, USA. + */ + +#ifndef KJSEMBEDJSPROXY_H +#define KJSEMBEDJSPROXY_H + +#include <kjs/object.h> +#include "global.h" + +namespace KJSEmbed { + +class JSObjectProxy; +class JSValueProxy; +class JSOpaqueProxy; + +/** + * Base class for all proxy objects. + * + * @version $Id$ + * @author Richard Moore, rich@kde.org + */ +class KJSEMBED_EXPORT JSProxy : public KJS::ObjectImp +{ +public: + /** Identifiers for the various types of proxy. */ + enum ProxyType { + UnknownProxy, + ObjectProxy, + ValueProxy, + OpaqueProxy, + BuiltinProxy + }; + + /** Identifies the owner of the currently wrapped pointer */ + enum Owner { Native, /** This is a C++ pointer and it will not be deleted by the garbage collector */ + JavaScript /** This pointer is owned by Javascript and it will be deleted by the garbage collector */ + }; + /** + * Structure to store information about a method. + */ + struct MethodTable { + int id; + const char *name; + }; + + /** + * Adds a @ref MethodTable of methods to an object. + * Note: The method table MUST end in a {0,0} entry. + */ + template< class T > + static void addMethods( KJS::ExecState *exec, MethodTable *table, KJS::Object &object ) + { + int idx = 0; + if( !table[idx].name ) return; // check for empty list + do { + T *meth = new T( exec, table[idx].id ); + object.put( exec , table[idx].name, KJS::Object(meth), KJS::Function ); + ++idx; + } while( table[idx].name ); + } + + /** + * Structure to store information about enums. + */ + struct EnumTable { + const char *id; + int val; + }; + + /** + * Adds a @ref EnumTable of static values to an object. + * Note: The method table MUST end in a {0,0} entry. + */ + static void addEnums( KJS::ExecState *exec, EnumTable *table, KJS::Object &object ); + + /** + * Checks to see if an object is a desired type. + * @param object - the object you want to test. + * @param prxyType - the type of prxy you want. + * @param classname - the name of the class you want. + * @returns if the two above conditions are met. + */ + static bool checkType( const KJS::Object &object, ProxyType prxyType, const QString &classname); + + + JSProxy( int type ); + virtual ~JSProxy(); + + /** Returns the string value of the class name **/ + virtual QString typeName() const = 0; + /** Returns true iff the content of this proxy inherits the specified base-class. */ + virtual bool inherits( const char *clazz ) = 0; + /** Returns the type of the proxy. */ + int proxyType() const { return proxytype; } + + /** Returns true iff this is a JSObjectProxy. */ + bool isObjectProxy() const { return proxytype == ObjectProxy; } + + /** Returns true iff this is a JSValueProxy. */ + bool isValueProxy() const { return proxytype == ValueProxy; } + + /** Returns true iff this is a JSOpaqueProxy. */ + bool isOpaqueProxy() const { return proxytype == OpaqueProxy; } + + /** Returns this object as a JSObjectProxy or 0 if the type is wrong. */ + JSObjectProxy *toObjectProxy(); + + /** Returns this object as a JSValueProxy or 0 if the type is wrong. */ + JSValueProxy *toValueProxy(); + + /** Returns this object as a JSOpaqueProxy or 0 if the type is wrong. */ + JSOpaqueProxy *toOpaqueProxy(); + + /** + * Converts the specified ValueImp to a JSProxy if possible, if the + * ValueImp is not a JSProxy then 0 is returned. + */ + static JSProxy *toProxy( KJS::ValueImp *imp ); + + /** + * Converts the specified ValueImp to a JSObjectProxy if possible, if the + * ValueImp is not a JSObjectProxy then 0 is returned. + */ + static JSObjectProxy *toObjectProxy( KJS::ValueImp *imp ); + + /** + * Converts the specified ValueImp to a JSValueProxy if possible, if the + * ValueImp is not a JSValueProxy then 0 is returned. + */ + static JSValueProxy *toValueProxy( KJS::ValueImp *imp ); + + /** + * Converts the specified ValueImp to a JSOpaqueProxy if possible, if the + * ValueImp is not a JSOpaqueProxy then 0 is returned. + */ + static JSOpaqueProxy *toOpaqueProxy( KJS::ValueImp *imp ); + + /** + * Transfers ownership of the contained pointer to C++ or Javascript. + * JavaScript - Javascript GC will delete the pointer + * Native - Javascript will not delete the pointer, but just the proxy. + */ + void setOwner( Owner state = Native ); + + /** + * Returns the current ownership. + */ + Owner owner() const; + +protected: + /** + * Who really owns the current pointer + */ + Owner ownership; +private: + int proxytype; + class JSProxyPrivate *d; +}; + +} // namespace KJSEmbed + +#endif // KJSEMBEDJSPROXYIMP_H + +// Local Variables: +// c-basic-offset: 4 +// End: diff --git a/kjsembed/jsproxy_imp.cpp b/kjsembed/jsproxy_imp.cpp new file mode 100644 index 00000000..9af07152 --- /dev/null +++ b/kjsembed/jsproxy_imp.cpp @@ -0,0 +1,42 @@ +/* + * Copyright (C) 2001-2003, Richard J. Moore <rich@kde.org> + * + * This 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. + * + * This 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 this library; see the file COPYING.LIB. If not, write to + * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, + * Boston, MA 02110-1301, USA. + */ + +#include <kjs/interpreter.h> + +#include "jsproxy_imp.h" + +namespace KJSEmbed { +//namespace Bindings { + +JSProxyImp::JSProxyImp( KJS::ExecState *exec ) + : KJS::InternalFunctionImp( exec ) +{ +} + +JSProxyImp::~JSProxyImp() +{ +} + +//} // namespace Bindings +} // namespace KJSEmbed + +// Local Variables: +// c-basic-offset: 4 +// End: + diff --git a/kjsembed/jsproxy_imp.h b/kjsembed/jsproxy_imp.h new file mode 100644 index 00000000..e46391ad --- /dev/null +++ b/kjsembed/jsproxy_imp.h @@ -0,0 +1,53 @@ +// -*- c++ -*- + +/* + * Copyright (C) 2001-2003, Richard J. Moore <rich@kde.org> + * + * This 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. + * + * This 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 this library; see the file COPYING.LIB. If not, write to + * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, + * Boston, MA 02110-1301, USA. + */ + +#ifndef KJSEMBEDJSPROXYIMP_H +#define KJSEMBEDJSPROXYIMP_H + +#include <kjs/function.h> +#include <kjsembed/global.h> + +namespace KJSEmbed { + +/** + * Base class of custom KJS::FunctionImp classes. + * + * @author Richard Moore, rich@kde.org + */ +class KJSEMBED_EXPORT JSProxyImp : public KJS::InternalFunctionImp +{ +public: + /** Creates the function using the builtin function prototype of the interpreter. */ + JSProxyImp( KJS::ExecState *exec ); + /** Cleans up */ + virtual ~JSProxyImp(); + +private: + class JSProxyImpPrivate *d; +}; + +} // namespace KJSEmbed + +#endif // KJSEMBEDJSPROXYIMP_H + +// Local Variables: +// c-basic-offset: 4 +// End: diff --git a/kjsembed/jssecuritypolicy.cpp b/kjsembed/jssecuritypolicy.cpp new file mode 100644 index 00000000..8630c2c5 --- /dev/null +++ b/kjsembed/jssecuritypolicy.cpp @@ -0,0 +1,103 @@ +/* + * Copyright (C) 2001-2003, Richard J. Moore <rich@kde.org> + * + * This 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. + * + * This 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 this library; see the file COPYING.LIB. If not, write to + * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, + * Boston, MA 02110-1301, USA. + */ + +#include "jssecuritypolicy.h" + +namespace KJSEmbed { + +JSSecurityPolicy *JSSecurityPolicy::policy=0; + +JSSecurityPolicy::JSSecurityPolicy( uint capabilities ) + : caps( capabilities ) +{ +} + +JSSecurityPolicy::~JSSecurityPolicy() +{ +} + +JSSecurityPolicy *JSSecurityPolicy::defaultPolicy() +{ + if ( !policy ) + policy = new JSSecurityPolicy( CapabilityAll ); + return policy; +} + +void JSSecurityPolicy::setDefaultPolicy( JSSecurityPolicy *pol ) +{ + if ( policy ) + delete policy; + policy = pol ? pol : defaultPolicy(); +} + +void JSSecurityPolicy::setDefaultPolicy( uint caps ) +{ + if ( policy ) + delete policy; + policy = new JSSecurityPolicy( caps ); +} + +void JSSecurityPolicy::deleteDefaultPolicy() +{ + delete policy; + policy = 0; +} + +bool JSSecurityPolicy::isInterpreterAllowed( const JSObjectProxy *prx, const KJS::Interpreter *i ) const +{ + if ( !prx->interpreter() ) + return true; + else if ( prx->interpreter() == i ) + return true; + + return false; +} + +bool JSSecurityPolicy::isObjectAllowed( const JSObjectProxy *prx, const QObject *obj ) const +{ + if ( !obj ) + return false; + + do { + if ( obj == prx->rootObject() ) + return true; + } while( (obj = obj->parent()) ); + + return false; +} + +bool JSSecurityPolicy::isPropertyAllowed( const JSObjectProxy *prx, + const QObject *obj, const char * /*prop*/ ) const +{ + return hasCapability( CapabilityGetProperties|CapabilitySetProperties ) && isObjectAllowed( prx, obj ); +} + +bool JSSecurityPolicy::isCreateAllowed( const JSObjectProxy *prx, const QObject *parent, + const QString &/*clazz*/, const QString &/*name*/ ) const +{ + if ( hasCapability(CapabilityFactory) && isObjectAllowed( prx, parent ) ) + return true; + if ( hasCapability(CapabilityTopLevel) && (parent == 0) ) + return true; + return false; +} + +} // namespace KJSEmbed + + diff --git a/kjsembed/jssecuritypolicy.h b/kjsembed/jssecuritypolicy.h new file mode 100644 index 00000000..0709b214 --- /dev/null +++ b/kjsembed/jssecuritypolicy.h @@ -0,0 +1,153 @@ +// -*- c++ -*- + +/* + * Copyright (C) 2001-2003, Richard J. Moore <rich@kde.org> + * + * This 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. + * + * This 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 this library; see the file COPYING.LIB. If not, write to + * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, + * Boston, MA 02110-1301, USA. + */ + +#ifndef KJSEMBEDSECURITYPOLICY_H +#define KJSEMBEDSECURITYPOLICY_H +#include "global.h" +#include <kjsembed/jsobjectproxy.h> + +namespace KJSEmbed { + +class JSObjectProxy; + +/** + * Implements the default security policy. + * This class defines the interface for security policies, and provides + * a default implementation that should be sufficient for most situations. + * <h3>Security Checks</h3> + * A SecurityPolicy must define tests for the following situations: + * <ul> + * <li>Does this request come from the correct @ref KJS::Interpreter ? + * <li>Is the script allowed to access the specified QObject ? + * <li>Is the script allowed to access the specified property ? + * </ul> + * The various isAllowed() methods are called automatically by @ref JSObjectProxy + * when a script attempts to perform a controlled operation. + * + * <h3>Default Policy</h3> + * The security policy applied by default is as follows: + * <ul> + * <li>Only the interpreter specified when the initial binding was + * defined may access the proxy. + * <li>Scripts may only access QObjects that are children of the root + * object. The root object is specified when the embedding application + * creates the initial binding, and is automatically inherited by any + * sub-proxies that may be created by the script. + * <li>Scripts may access any properties of the objects they can access. + * </ul> + * Applications tjat want a custom policy should define a SecurityPolicy + * that re-implement the various isAllowed() methods, then use + * @ref JSObjectProxy::setSecurityPolicy() to apply the policy to a proxy. + * + * @see KJSEmbed::JSObjectProxy + * @author Richard Moore, rich@kde.org + * $Id$ + */ +class KJSEMBED_EXPORT JSSecurityPolicy +{ +public: + JSSecurityPolicy( uint capabilities = 0 ); + virtual ~JSSecurityPolicy(); + + /** + * Defines a set of flags that indicate if access to a given API + * should be allowed. + */ + enum Capabilities { + CapabilityTree = 0x0001, + CapabilityGetProperties = 0x0002, + CapabilitySetProperties = 0x0004, + CapabilitySlots = 0x0008, + CapabilityFactory = 0x0010, + CapabilityTopLevel = 0x0020, + CapabilityCustom = 0x4000, + + CapabilityNone = 0x0000, + CapabilityReadOnly = CapabilityTree | CapabilityGetProperties, + CapabilityReadWrite = CapabilityReadOnly | CapabilitySetProperties | CapabilitySlots, + CapabilityAll = 0xffff + }; + + /** + * Returns true if any of the specified capabilities are allowed. + */ + bool hasCapability( uint cap ) const { return (cap & caps) ? true : false; } + + /** + * Specifies that the passed capabilities are allowed. + */ + void setCapability( uint cap ) { caps = caps | cap; } + + /** + * Specifies that the passed capabilities are disallowed. + */ + void clearCapability( uint cap ) { caps = caps | (CapabilityAll & cap); } + + /** + * Returns true if the specified interpreter may access the proxy. + */ + virtual bool isInterpreterAllowed( const JSObjectProxy *prx, const KJS::Interpreter *interp ) const; + + /** + * Returns true if scripts are allowed to see the specified QObject. + */ + virtual bool isObjectAllowed( const JSObjectProxy *prx, const QObject *obj ) const; + + /** + * Returns true if scripts are allowed to see the specified property. + */ + virtual bool isPropertyAllowed( const JSObjectProxy *prx, const QObject *obj, const char *prop ) const; + + /** + * Returns true if scripts are allowed to create the specified child object. + */ + virtual bool isCreateAllowed( const JSObjectProxy *prx, const QObject *parent, + const QString &clazz, const QString &name ) const; + + /** + * Returns the default SecurityPolicy. + */ + static JSSecurityPolicy *defaultPolicy(); + + /** + * Sets the default SecurityPolicy. + */ + static void setDefaultPolicy( JSSecurityPolicy *pol ); + + /** + * Sets the default SecurityPolicy. + */ + static void setDefaultPolicy( uint capabilities ); + + /** + * Deletes the default SecurityPolicy. + */ + static void deleteDefaultPolicy(); + +private: + static JSSecurityPolicy *policy; + uint caps; + class JSSecurityPolicyPrivate *d; +}; + +} // namespace KJSEmbed + +#endif // KJSEMBEDSECURITYPOLICY_H diff --git a/kjsembed/jsvalueproxy.cpp b/kjsembed/jsvalueproxy.cpp new file mode 100644 index 00000000..2e440cbb --- /dev/null +++ b/kjsembed/jsvalueproxy.cpp @@ -0,0 +1,97 @@ +/* + * Copyright (C) 2001-2003, Richard J. Moore <rich@kde.org> + * + * This 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. + * + * This 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 this library; see the file COPYING.LIB. If not, write to + * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, + * Boston, MA 02110-1301, USA. + */ + +#include <qvariant.h> +#include "global.h" + +#include <kjs/interpreter.h> +#include <kjs/types.h> +#include <kjs/ustring.h> + +#include "jsbinding.h" +#include "jsobjectproxy.h" +#include "jsobjectproxy_imp.h" +#include "jsvalueproxy_imp.h" + +#include "jsvalueproxy.h" + +namespace KJSEmbed { + +typedef Bindings::JSValueProxyImp JSValueProxyImp; + +JSValueProxy::JSValueProxy() + : JSProxy( JSProxy::ValueProxy ) +{ +} + +JSValueProxy::~JSValueProxy() +{ +} + +QString JSValueProxy::typeName() const +{ + return val.typeName(); +} + +void JSValueProxy::setValue( const QVariant &var ) +{ + kdDebug(80001) << "JSValueProxy::setValue() variant, type is " << var.typeName() << endl; + val = var; +} + +QVariant JSValueProxy::toVariant() const +{ + kdDebug(80001) << "JSValueProxy::toVariant() variant, type is " << val.typeName() << endl; + return val; +} + +void JSValueProxy::addBindings( KJS::ExecState *exec, KJS::Object &object ) +{ + MethodTable methods[] = { + { JSValueProxyImp::MethodTypeName, "typeName" }, + { 0, 0 } + }; + int i = 0; + do { + JSValueProxyImp *obj = new JSValueProxyImp( exec, methods[i].id, this ); + obj->setName( KJS::Identifier( methods[i].name ) ); + object.put( exec , obj->name(), KJS::Object(obj) ); + i++; + } while( methods[i].id ); +} + +KJS::UString JSValueProxy::toString( KJS::ExecState * /*exec*/ ) const +{ + QString s( "%1 (%2)" ); + return KJS::UString( s.arg("JSValueProxy").arg(val.typeName()) ); +} + +bool JSValueProxy::inherits( const char * clazz ) +{ + return ( typeName() == clazz ); +} + +} + + // namespace KJSEmbed + +// Local Variables: +// c-basic-offset: 4 +// End: + diff --git a/kjsembed/jsvalueproxy.h b/kjsembed/jsvalueproxy.h new file mode 100644 index 00000000..fe85c7df --- /dev/null +++ b/kjsembed/jsvalueproxy.h @@ -0,0 +1,67 @@ +// -*- c++ -*- + +/* + * Copyright (C) 2001-2003, Richard J. Moore <rich@kde.org> + * + * This 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. + * + * This 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 this library; see the file COPYING.LIB. If not, write to + * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, + * Boston, MA 02110-1301, USA. + */ + +#ifndef KJSEMBEDJSVALUEPROXY_H +#define KJSEMBEDJSVALUEPROXY_H +#include "global.h" +#include <qcstring.h> +#include <qvariant.h> +#include <kjs/object.h> +#include <kjsembed/jsproxy.h> + +namespace KJSEmbed { + +/** + * Provides a binding to an opaque value. + * + * @author Richard Moore, rich@kde.org + */ +class KJSEMBED_EXPORT JSValueProxy : public JSProxy +{ +public: + JSValueProxy(); + virtual ~JSValueProxy(); + + QString typeName() const; + /** Returns true iff the content of this proxy inherits the specified base-class. */ + bool inherits( const char *clazz ); + + void setValue( const QVariant &var ); + + QVariant toVariant() const; + + virtual void addBindings( KJS::ExecState *state, KJS::Object &object ); + + /** Reimplemented to return the name and class of the target. */ + virtual KJS::UString toString( KJS::ExecState *exec ) const; + +private: + QVariant val; + class JSValueProxyPrivate *d; +}; + +} // namespace KJSEmbed + +#endif // KJSEMBEDJSVALUEPROXYIMP_H + +// Local Variables: +// c-basic-offset: 4 +// End: diff --git a/kjsembed/jsvalueproxy_imp.cpp b/kjsembed/jsvalueproxy_imp.cpp new file mode 100644 index 00000000..9159e160 --- /dev/null +++ b/kjsembed/jsvalueproxy_imp.cpp @@ -0,0 +1,66 @@ +/* + * Copyright (C) 2001-2003, Richard J. Moore <rich@kde.org> + * + * This 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. + * + * This 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 this library; see the file COPYING.LIB. If not, write to + * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, + * Boston, MA 02110-1301, USA. + */ + +#include <qvariant.h> +#include "global.h" + +#include <kjs/interpreter.h> +#include <kjs/types.h> +#include <kjs/ustring.h> + +#include "jsobjectproxy.h" +#include "jsobjectproxy_imp.h" + +#include "jsvalueproxy.h" +#include "jsvalueproxy_imp.h" + +using namespace KJS; + +namespace KJSEmbed { +namespace Bindings { + +JSValueProxyImp::JSValueProxyImp( KJS::ExecState *exec, int mid, const JSValueProxy *parent ) + : JSProxyImp(exec), id(mid), proxy(parent) +{ +} + +JSValueProxyImp::~JSValueProxyImp() +{ +} + +KJS::Value JSValueProxyImp::call( KJS::ExecState *exec, KJS::Object &self, const KJS::List &args ) +{ + switch( id ) { + case MethodTypeName: + { + return KJS::String( proxy->typeName() ); + } + break; + } + + return ObjectImp::call( exec, self, args ); +} + +} // namespace Bindings +} // namespace KJSEmbed + +// Local Variables: +// c-basic-offset: 4 +// End: + diff --git a/kjsembed/jsvalueproxy_imp.h b/kjsembed/jsvalueproxy_imp.h new file mode 100644 index 00000000..ad3c85ad --- /dev/null +++ b/kjsembed/jsvalueproxy_imp.h @@ -0,0 +1,66 @@ +// -*- c++ -*- + +/* + * Copyright (C) 2001-2003, Richard J. Moore <rich@kde.org> + * + * This 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. + * + * This 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 this library; see the file COPYING.LIB. If not, write to + * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, + * Boston, MA 02110-1301, USA. + */ + +#ifndef KJSEMBEDJSVALUEPROXYIMP_H +#define KJSEMBEDJSVALUEPROXYIMP_H + +#include <qcstring.h> +#include <kjs/object.h> +#include <kjsembed/jsproxy_imp.h> + +namespace KJSEmbed { class JSValueProxy; } + +namespace KJSEmbed { +namespace Bindings { + +/** + * Provides a binding to an opaque value. + * + * @author Richard Moore, rich@kde.org + */ +class JSValueProxyImp : public JSProxyImp +{ +public: + enum Methods { + MethodInternalError, + MethodTypeName + }; + + JSValueProxyImp( KJS::ExecState *exec, int id, const JSValueProxy *parent ); + virtual ~JSValueProxyImp(); + + virtual bool implementsCall() const { return true; } + virtual KJS::Value call( KJS::ExecState *exec, KJS::Object &self, const KJS::List &args ); + +private: + int id; + const JSValueProxy *proxy; + class JSValueProxyImpPrivate *d; +}; + +} // namespace KJSEmbed::Bindings +} // namespace KJSEmbed + +#endif // KJSEMBEDJSVALUEPROXYIMP_H + +// Local Variables: +// c-basic-offset: 4 +// End: diff --git a/kjsembed/kjs.pro b/kjsembed/kjs.pro new file mode 100644 index 00000000..e83e62a8 --- /dev/null +++ b/kjsembed/kjs.pro @@ -0,0 +1,87 @@ +# File generated by kdevelop's qmake manager. +# ------------------------------------------- +# Subdir relative project main directory: ./kjs +# Target is a library: + +INCLUDEPATH = ../kjs \ + .. +CONFIG += release \ + warn_on \ + staticlib +DEFINES = HAVE_FUNC_ISNAN +TEMPLATE = lib +HEADERS += array_instance.h \ + array_object.h \ + array_object.lut.h \ + bool_object.h \ + collector.h \ + completion.h \ + context.h \ + date_object.h \ + date_object.lut.h \ + debugger.h \ + dtoa.h \ + error_object.h \ + function.h \ + function_object.h \ + global.h \ + grammar.h \ + identifier.h \ + internal.h \ + interpreter.h \ + lexer.h \ + lexer.lut.h \ + list.h \ + lookup.h \ + math_object.h \ + math_object.lut.h \ + nodes.h \ + number_object.h \ + number_object.lut.h \ + object.h \ + object_object.h \ + operations.h \ + property_map.h \ + reference.h \ + reference_list.h \ + regexp.h \ + regexp_object.h \ + scope_chain.h \ + simple_number.h \ + string_object.h \ + string_object.lut.h \ + types.h \ + ustring.h \ + value.h +SOURCES += array_object.cpp \ + bool_object.cpp \ + collector.cpp \ + date_object.cpp \ + debugger.cpp \ + dtoa.cpp \ + error_object.cpp \ + function.cpp \ + function_object.cpp \ + grammar.cpp \ + identifier.cpp \ + internal.cpp \ + interpreter.cpp \ + lexer.cpp \ + list.cpp \ + lookup.cpp \ + math_object.cpp \ + nodes2string.cpp \ + nodes.cpp \ + number_object.cpp \ + object.cpp \ + object_object.cpp \ + operations.cpp \ + property_map.cpp \ + reference.cpp \ + reference_list.cpp \ + regexp.cpp \ + regexp_object.cpp \ + scope_chain.cpp \ + string_object.cpp \ + ustring.cpp \ + value.cpp diff --git a/kjsembed/kjscmd.1 b/kjsembed/kjscmd.1 new file mode 100644 index 00000000..8ae69c27 --- /dev/null +++ b/kjsembed/kjscmd.1 @@ -0,0 +1,34 @@ +.TH "kjscmd" 1 +.SH NAME +kjscmd \- A tool for running KJSEmbed scripts from the command line +.SH SYNOPSIS +.B kjscmd +kjscmd [Qt-options] [KDE-options] [options] [file] +.SH DESCRIPTION +kjscmd is a tool for launching KJSEmbed scripts from the command line, and +can also provide a console for running commands interactively. It will run +the named file using KJSEmbed (or read a file from stdin if '-' is +specified). +.SH OPTIONS +.TP +.B \-\-console \-c +Enables the graphical console. The console will not be visible unless the +script enters the event loop or the --exec parameter is used. If no script +was specified on the command line then the event loop is entered +automatically. +.TP +.B \-\-interactive \-i +Enables the interactive command line prompt. +.TP +.B \-\-exec +Tells kjscmd to enter the event loop after executing the script. This option +is rarely used, but it can be handy if you want to use the console to examine +the state of the interpreter after a non-graphical script has executed. +.TP +.B \-\-nogui +Tells kjscmd not to create an X connection. This allows you to use scripts +without needing an X server (though with reduced functionality). +.SH BUGS +There are probably lots of bugs. Use http://bugs.kde.org/ to report them. + + diff --git a/kjsembed/kjscmd.cpp b/kjsembed/kjscmd.cpp new file mode 100644 index 00000000..6caccdc3 --- /dev/null +++ b/kjsembed/kjscmd.cpp @@ -0,0 +1,194 @@ +/* + * Copyright (C) 2001-2003, Richard J. Moore <rich@kde.org> + * + * This 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. + * + * This 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 this library; see the file COPYING.LIB. If not, write to + * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, + * Boston, MA 02110-1301, USA. + */ + +#include <stdio.h> + +#include <errno.h> +#include <qstring.h> + +#include <qregexp.h> + +#include <kaboutdata.h> +#include <kapplication.h> +#include <kcmdlineargs.h> +#include <kdebug.h> +#include <kimageio.h> +#include <klocale.h> +#include <kmainwindow.h> + +#include <kjs/interpreter.h> +#include <kjs/ustring.h> + +#include "kjsembedpart.h" +#include "jsconsolewidget.h" +#include "jssecuritypolicy.h" + +static KCmdLineOptions options[] = +{ + { "c", 0, 0 }, + { "console", I18N_NOOP("Displays the KJSEmbed console"), 0 }, + { "i", 0, 0 }, + { "interactive", I18N_NOOP("Runs an interactive command line prompt"), 0 }, + { "exec", I18N_NOOP("Call application.exec() automatically after running the script"), 0 }, + { "nogui", I18N_NOOP("Disables all GUI facilities"), 0 }, + { "+[file]", I18N_NOOP("Script to execute, or '-' for stdin"), 0 }, + { 0, 0, 0 } +}; + +int main( int argc, char **argv ) +{ + bool nogui = false; + bool doexec = false; + QCString appName = "kjscmd"; + + // Set the name of the instance + for ( int i = 1 ; i < argc ; i++ ) { + QCString arg( argv[i] ); + if ( arg[0] != '-' ) { + appName = arg.mid( arg.findRev('/') ); + if ( !appName ) + appName = argv[1]; + else + argv[0] = appName.data(); + } + } + + // Clean app name + appName = appName.replace("/", ""); + appName = appName.replace(".js", ""); + + // Search for nogui option + for ( int i = 1 ; i < argc ; i++ ) { + if ( strcmp( argv[i], "--exec" ) == 0 ) + doexec = true; + if ( strcmp( argv[i], "--nogui" ) == 0 ) + nogui = true; + } + + // Cmd Line + KAboutData about( appName.data(), I18N_NOOP("KJSCmd"), KJSEMBED_VERSION_STRING, + I18N_NOOP("Runs KJS scripts from the command line."), + KAboutData::License_LGPL, I18N_NOOP("(c) 2001-2004 Richard Moore") ); + about.addAuthor( "Richard Moore", 0, "rich@kde.org" ); + about.addAuthor( "Ian Reinhart Geiser", 0, "geiser@kde.org" ); + + KCmdLineArgs::init( argc, argv, &about ); + KCmdLineArgs::addCmdLineOptions( options ); // Add our own options. + KCmdLineArgs *args = KCmdLineArgs::parsedArgs(); + + // Setup KApplication + KApplication *app; + if ( nogui ) { + app = new KApplication( false, false ); + } + else { + app = new KApplication; + app->connect( app, SIGNAL( lastWindowClosed() ), SLOT(quit()) ); + } + + // Setup the rest + KImageIO::registerFormats(); + + // Setup Interpreter + KJSEmbed::JSSecurityPolicy::setDefaultPolicy( KJSEmbed::JSSecurityPolicy::CapabilityAll ); + KJSEmbed::KJSEmbedPart *part = new KJSEmbed::KJSEmbedPart; + KJS::Interpreter *js = part->interpreter(); + KJS::ExecState *exec = js->globalExec(); + + // Publish bindings + KJS::Object appobj = part->addObject( app, "application" ); + + // Build args array + KJS::List l; + for ( int i = 1 ; i < args->count() ; i++ ) + l.append( KJS::String( args->arg(i) ) ); + + KJS::Object argobj( js->builtinArray().construct( exec, l ) ); + appobj.put( exec, "args", argobj ); + + bool showConsole = false; + + // Create Visible Console? + if ( args->isSet("console") + || ( !args->count() && !args->isSet("interactive") ) ) { + + if ( !nogui ) { + + KJSEmbed::JSConsoleWidget *console = part->view(); + console->resize( 600, 450 ); + console->show(); + part->addObject( console, "console" ); + + showConsole = true; + } + } + + if ( args->count() ) { + // Run script + bool ok = part->runFile( args->arg(0) ); + KJS::Completion jsres = part->completion(); + if ( jsres.complType() != KJS::Normal) { + QTextStream err( stderr, IO_WriteOnly ); + QTextStream out( stdout, IO_WriteOnly ); + + switch ( jsres.complType() ) { + case KJS::Break: + case KJS::Continue: + err << jsres.value().toString(exec).qstring() << endl; + return 1; + break; + case KJS::ReturnValue: + out << jsres.value().toString(exec).qstring() << endl; + return 0; + break; + case KJS::Throw: + { + + KJS::Object exception = jsres.value().toObject(exec); + int line = exception.get(exec,KJS::Identifier("line")).toNumber(exec); + QString type = exception.get(exec,KJS::Identifier("name")).toString(exec).qstring(); + QString message = exception.get(exec,KJS::Identifier("message")).toString(exec).qstring(); + + err << "Uncaught " << type << " exception at: " << line << endl; + err << message << endl; + return 1; + break; + } + default: + err << "Unknown error." << endl; + return 1; + break; + } + } + } + + int result = 0; + if ( !nogui && ( doexec || showConsole ) ) + result = app->exec(); + + if ( args->isSet( "interactive" ) ) { + part->execute( QString("include('cmdline.js');") ); + } + + return result; +} + +// Local Variables: +// c-basic-offset: 4 +// End: diff --git a/kjsembed/kjscmd.desktop b/kjsembed/kjscmd.desktop new file mode 100644 index 00000000..3de84bfe --- /dev/null +++ b/kjsembed/kjscmd.desktop @@ -0,0 +1,11 @@ +[Desktop Entry] +GenericName=JavaScript Console +Name=kjscmd +Type=Application +Exec=kjscmd --exec +Icon=konsole +Terminal=false +X-DCOP-ServiceType=Multi +Categories=Qt;KDE;Development;Debugger; +InitialPreference=10 + diff --git a/kjsembed/kjsembed/kjsembed.pro b/kjsembed/kjsembed/kjsembed.pro new file mode 100755 index 00000000..8ff841c5 --- /dev/null +++ b/kjsembed/kjsembed/kjsembed.pro @@ -0,0 +1,85 @@ +# File generated by kdevelop's qmake manager. +# ------------------------------------------- +# Subdir relative project main directory: ./kjsembed +# Target is a library: + +include(../qjsembed.pri) + +LIBS += -L../kjs -lkjs \ + -L../builtins -lbuiltins \ + -L../qtbindings -lqtbindings \ + -L../bindings -lbindings \ + -lqui + +win32:LIBS += -L../pcre -lpcre +unix:LIBS += -lpcreposix -lpcre + +HEADERS += ../kjsembedpart.h \ + ../kjsembedpart_imp.h \ + ../customobject_imp.h \ + ../design.h \ + ../jsbinding.h \ + ../jsbindingplugin.h \ + ../jsbuiltin.h \ + ../jsbuiltin_imp.h \ + ../jseventmapper.h \ + ../jseventutils.h \ + ../jsfactory.h \ + ../jsfactory_imp.h \ + ../jsobjecteventproxy.h \ + ../jsobjectproxy.h \ + ../jsobjectproxy_imp.h \ + ../jsopaqueproxy.h \ + ../jsopaqueproxy_imp.h \ + ../jsproxy.h \ + ../jsproxy_imp.h \ + ../jssecuritypolicy.h \ + ../jsvalueproxy.h \ + ../jsvalueproxy_imp.h \ + ../slotproxy.h \ + ../slotutils.h \ + ../global.h \ + ../qtstubs.h \ + ../jsbuiltinproxy.h + +SOURCES += ../jsobjectproxy.cpp \ + ../jsobjectproxy_imp.cpp \ + ../customobject_imp.cpp \ + ../jsbinding.cpp \ + ../jsbindingplugin.cpp \ + ../jsbuiltin.cpp \ + ../jsbuiltin_imp.cpp \ + ../jseventmapper.cpp \ + ../jseventutils.cpp \ + ../jsfactory.cpp \ + ../jsfactory_imp.cpp \ + ../jsobjecteventproxy.cpp \ + ../jsopaqueproxy.cpp \ + ../jsopaqueproxy_imp.cpp \ + ../jsproxy.cpp \ + ../jsproxy_imp.cpp \ + ../jssecuritypolicy.cpp \ + ../jsvalueproxy.cpp \ + ../jsvalueproxy_imp.cpp \ + ../slotproxy.cpp \ + ../slotutils.cpp \ + ../global.cpp \ + ../qtstubs.cpp \ + ../kjsembedpart.cpp \ + ../kjsembedpart_imp.cpp \ + ../jsbuiltinproxy.cpp + + +INCLUDEPATH += ../.. .. . + +win32:DEFINES += KJSEMBED_DLL KJSEMBED_MAKE_DLL + +CONFIG += qt + +win32:CONFIG += shared dll +unix:CONFIG += sharedlib + +TEMPLATE = lib +TARGET = qjsembed + +DESTDIR = ../bin diff --git a/kjsembed/kjsembedpart.cpp b/kjsembed/kjsembedpart.cpp new file mode 100644 index 00000000..319bfde8 --- /dev/null +++ b/kjsembed/kjsembedpart.cpp @@ -0,0 +1,449 @@ +/* + * Copyright (C) 2001-2003, Richard J. Moore <rich@kde.org> + * + * This 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. + * + * This 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 this library; see the file COPYING.LIB. If not, write to + * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, + * Boston, MA 02110-1301, USA. + */ + +#include <stdio.h> +#include <string.h> +#include <errno.h> + +#include <qobject.h> +#include <qdialog.h> +#include <qfile.h> +#include <qtextstream.h> +#include <qwidget.h> +#include <qwidgetfactory.h> + +#ifndef QT_ONLY +#include <kaction.h> +#endif // QT_ONLY + +#include <kjs/interpreter.h> +#include <kjs/object.h> +#include <kjs/ustring.h> +#include <kjs/types.h> +#include <kjs/value.h> + +#include "global.h" +#include "jsfactory.h" +#include "jsbinding.h" +#include "jsobjectproxy.h" +#include "jsconsolewidget.h" +#include "jsbuiltin.h" + +#ifndef QT_ONLY +#include "bindings/image_imp.h" +#endif // QT_ONLY + +#include "kjsembedpart_imp.h" +#include "kjsembedpart.h" + +#ifndef QT_ONLY + +#include "kjsembedpart.moc" + +namespace KJSEmbed { + +class KJSEmbedActionRunner : public XMLActionRunner +{ +public: + KJSEmbedActionRunner( KJSEmbedPart *jspart ) : XMLActionRunner(), part(jspart) {} + virtual ~KJSEmbedActionRunner() {} + + virtual bool run( XMLActionClient *client, const XMLActionClient::XMLActionScript &script ) { + if ( script.type == "js" ) + return part->runFile( script.src ); + else + return XMLActionRunner::run( client, script ); + } + +private: + KJSEmbedPart *part; +}; + +} // namespace KJSEmbed + +#else // QT_ONLY + +#include "qtstubs.h" + +#endif // QT_ONLY + +namespace KJSEmbed { + +// +// KPart +// + +KJSEmbedPart::KJSEmbedPart( QObject *parent, const char *name ) + : KParts::ReadOnlyPart( parent, name ? name : "kjsembed_part" ), + jsConsole(0), jsfactory(0), + widgetparent(0), widgetname(name ? name : "kjsembed_part"), deletejs(false) +{ + createInterpreter(); + createBuiltIn( js->globalExec(), js->globalObject() ); + createActionClient(); +} + +KJSEmbedPart::KJSEmbedPart( QWidget *wparent, const char *wname, QObject *parent, const char *name ) + : KParts::ReadOnlyPart( parent, name ? name : (wname?wname:"jsembed_part") ), + jsConsole(0), jsfactory(0), + widgetparent(wparent), widgetname(wname), deletejs(false) +{ + createInterpreter(); + createBuiltIn( js->globalExec(), js->globalObject() ); + createActionClient(); +} + +KJSEmbedPart::KJSEmbedPart( KJS::Interpreter *jsi, QWidget *wparent, const char *wname, + QObject *parent, const char *name ) + : KParts::ReadOnlyPart( parent, name ? name : (wname?wname:"jsembed_part") ), + jsConsole(0), jsfactory(0), builtins(0), + widgetparent(wparent), widgetname(wname), js(jsi), deletejs(false) +{ + if ( !js ) { + createInterpreter(); + createBuiltIn( js->globalExec(), js->globalObject() ); + } + createActionClient(); +} + +KJSEmbedPart::~KJSEmbedPart() +{ + if ( deletejs ) + delete js; + delete jsfactory; + delete builtins; +} + +void KJSEmbedPart::createInterpreter() +{ + deletejs = true; + js = new KJS::Interpreter(); + + jsfactory = new JSFactory( this ); + jsfactory->addType( className() ); + jsfactory->addTypes( js->globalExec(), js->globalObject() ); +} + +void KJSEmbedPart::createBuiltIn( KJS::ExecState *exec, KJS::Object &parent ) +{ + partobj = addObject( this, parent, "part" ); + + builtins = new JSBuiltIn( this ); + builtins->add( exec, parent ); +} + +void KJSEmbedPart::createActionClient() +{ +#ifndef QT_ONLY + xmlclient = new KJSEmbed::XMLActionClient( this ); + xmlclient->setActionCollection( actionCollection() ); + xmlclient->setRunner( new KJSEmbedActionRunner(this) ); +#endif // QT_ONLY +} + +JSConsoleWidget *KJSEmbedPart::view() +{ +#ifndef QT_ONLY + if ( !jsConsole ) { + QCString name = widgetname ? widgetname : QCString("jsembed_console"); + jsConsole = new JSConsoleWidget( this, widgetparent, name ); + setWidget( jsConsole ); + jsfactory->addType( jsConsole->className() ); + } + return jsConsole; +#endif // QT_ONLY +return 0L; +} + +QStringList KJSEmbedPart::constructorNames() const +{ + QStringList classes; + + KJS::List cons = constructorList(); + KJS::ListIterator it = cons.begin(); + while ( it != cons.end() ) { + KJS::Value v = *it; + classes += v.toString( js->globalExec() ).qstring(); + it++; + } + + return classes; +} + +KJS::Value KJSEmbedPart::constructors() const +{ + KJS::List items = constructorList(); + kdDebug(80001) << "KJSEmbedPart::constructors() returning " << items.size() << " items" << endl; + return KJS::Object( js->builtinArray().construct( js->globalExec(), items ) ); +} + +KJS::List KJSEmbedPart::constructorList() const +{ + KJS::List items; + + KJS::Object obj = js->globalObject(); + KJS::ExecState *exec = js->globalExec(); + + KJS::ReferenceList l = obj.propList( exec ); + KJS::ReferenceListIterator propIt = l.begin(); + while ( propIt != l.end() ) { + + KJS::Identifier name = propIt->getPropertyName( exec ); + + if ( obj.hasProperty( exec, name ) ) { + KJS::Value v = obj.get( exec, name ); + KJS::Object vobj = v.toObject( exec ); + + if ( vobj.implementsConstruct() ) + items.append( KJS::String( name.ustring() ) ); + } + + propIt++; + } + + return items; +} + +// +// Version information +// + +QCString KJSEmbedPart::versionString() const +{ + return QCString(KJSEMBED_VERSION_STRING); +} + +int KJSEmbedPart::versionMajor() const +{ + return KJSEMBED_VERSION_MAJOR; +} + +int KJSEmbedPart::versionMinor() const +{ + return KJSEMBED_VERSION_MINOR; +} + +// +// Execute a JS script. +// + +KJS::Value KJSEmbedPart::evaluate( const QString &script, const KJS::Value &self ) +{ + if ( execute( res, script, self ) ) + return res.value(); + + return KJS::Null(); +} + +bool KJSEmbedPart::execute( const QString &script, const KJS::Value &self ) +{ + return execute( res, script, self ); +} + +bool KJSEmbedPart::execute( KJS::Completion &result, const QString &script, const KJS::Value &self ) +{ + KJS::Value val( self ); + result = js->evaluate( script, self.isNull() ? partobj : val ); + return (result.complType() == KJS::Normal) || (result.complType() == KJS::ReturnValue); +} + +bool KJSEmbedPart::openURL( const KURL &url ) +{ + if ( url.protocol() == "javascript" ) { +// kdDebug(80001) << "KJSEmbedPart: openURL '" << url.url() << "' is javascript" << endl; + +#ifndef QT_ONLY + QString cmd = url.url(); +#else + QString cmd = url.toString(); +#endif + + QString js( "javascript:" ); + cmd = cmd.replace( 0, js.length(), QString("") ); + +// kdDebug(80001) << "KJSEmbedPart: JS command is '" << cmd << "'" << endl; + return execute( cmd ); + } + return false; +} + +// +// Invoke a script file. +// + +bool KJSEmbedPart::runFile( const QString &name, const KJS::Value &self ) +{ + kdDebug(80001) << "KJSEmbedPart::runFile(): file is '" << name << "'" << endl; + QString script = loadFile( name ); + return execute( script, self ); +} + +bool KJSEmbedPart::loadActionSet( const QString &file ) +{ +#ifndef QT_ONLY + return xmlclient->load( file ); +#else // QT_ONLY + Q_UNUSED( file ); + return false; +#endif // QT_ONLY +} + +QString KJSEmbedPart::loadFile( const QString &src ) +{ + QString script; + + if ( src == "-" ) { + QTextStream ts( stdin, IO_ReadOnly ); + script = ts.read(); + } + else { + QFile file( src ); + if ( file.open( IO_ReadOnly ) ) { + script = QString( file.readAll() ); + } + else { + kdWarning() << "Could not open file '" << src << "', " + << strerror( errno ) << endl; + return QString::null; + } + } + + if ( script.startsWith( "#!" ) ) { + int pos = script.find( "\n" ); + if ( pos > 0 ) + script = script.mid( pos ); + } + + return script; +} + +// +// Publishing objects. +// + +KJS::Object KJSEmbedPart::bind( QObject *obj ) +{ + KJS::Object jsobj = jsfactory->createProxy( js->globalExec(), obj ); + JSProxy::toObjectProxy(jsobj.imp() )->setOwner(JSProxy::Native); + return jsobj; +} + +KJS::Object KJSEmbedPart::addObject( QObject *obj, KJS::Object &parent, const char *name ) +{ + KJS::Object jsobj = bind( obj ); + parent.put( js->globalExec(), name ? name : obj->name(), jsobj ); + + return jsobj; +} + +KJS::Object KJSEmbedPart::addObject( QObject *obj, const char *name ) +{ + return addObject( obj, js->globalObject(), name ); +} + +void KJSEmbedPart::virtual_hook( int /*id*/, void * /*data*/ ) +{ + +} + +static KJS::Object scopeWalker( KJS::ExecState *exec, const KJS::Object &root, const QString &objectString ) +{ + KJS::Object returnObject = root; + QStringList objects = QStringList::split(".", objectString); + for( uint idx = 0; idx < objects.count(); ++idx) + { + KJS::Identifier id = KJS::Identifier( KJS::UString( objects[idx] )); + KJS::Value newObject = returnObject.get(exec, id ); + if( newObject.isValid() ) + returnObject = newObject.toObject(exec); + } + return returnObject; +} + +KJS::Value KJSEmbedPart::callMethod( const QString & methodName, const KJS::List & args ) const +{ + KJS::ExecState *exec = js->globalExec(); + KJS::Identifier id = KJS::Identifier( KJS::UString(methodName.latin1() )); + KJS::Object obj = js->globalObject(); + KJS::Object fun = obj.get(exec, id ).toObject( exec ); + KJS::Value retValue; + if ( !fun.implementsCall() ) + { + // We need to create an exception here... + } + else + retValue = fun.call(exec, obj, args); + kdDebug( 80001 ) << "Returned type is: " << retValue.type() << endl; + if( exec->hadException() ) + { + kdWarning( 80001 ) << "Got error: " << exec->exception().toString(exec).qstring() << endl; + return exec->exception(); + } + else + { + if( retValue.type() == 1 && retValue.type() == 0) + { + kdDebug( 80001 ) << "Got void return type. " << endl; + return KJS::Null(); + } + } + return retValue; +} + +KJS::Value KJSEmbedPart::getValue( const QString & valueName ) const +{ + KJS::ExecState *exec = js->globalExec(); + KJS::Identifier id = KJS::Identifier( KJS::UString(valueName.latin1() )); + KJS::Object obj = js->globalObject(); + return obj.get(exec, id ); +} + +void KJSEmbedPart::putValue( const QString & valueName, const KJS::Value & value ) +{ + KJS::ExecState *exec = js->globalExec(); + KJS::Identifier id = KJS::Identifier( KJS::UString(valueName.latin1() )); + KJS::Object obj = js->globalObject(); + obj.put(exec, id, value); +} + +void KJSEmbedPart::putVariant( const QString & valueName, const QVariant & value ) +{ + KJS::Value val = convertToValue( js->globalExec(), value); + putValue( valueName, val ); +} + +QVariant KJSEmbedPart::getVariant( const QString & valueName ) const +{ + return convertToVariant( js->globalExec(), getValue( valueName ) ); +} + +bool KJSEmbedPart::hasMethod( const QString & methodName ) +{ + KJS::ExecState *exec = js->globalExec(); + KJS::Identifier id = KJS::Identifier( KJS::UString(methodName.latin1() )); + KJS::Object obj = js->globalObject(); + KJS::Object fun = obj.get(exec, id ).toObject( exec ); + return fun.implementsCall(); +} + +}// namespace KJSEmbed + +// Local Variables: +// c-basic-offset: 4 +// End: diff --git a/kjsembed/kjsembedpart.h b/kjsembed/kjsembedpart.h new file mode 100644 index 00000000..4645cf60 --- /dev/null +++ b/kjsembed/kjsembedpart.h @@ -0,0 +1,328 @@ +// -*- c++ -*- + +/* + * Copyright (C) 2001-2003, Richard J. Moore <rich@kde.org> + * + * This 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. + * + * This 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 this library; see the file COPYING.LIB. If not, write to + * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, + * Boston, MA 02110-1301, USA. + */ + +#ifndef KJSEMBEDJSCONSOLEPART_H +#define KJSEMBEDJSCONSOLEPART_H +#include "global.h" +#include <qstringlist.h> + +#ifndef QT_ONLY +#include <kparts/part.h> +#endif + +#include <kjs/interpreter.h> +#include <kjs/object.h> +#include <kjs/value.h> + +#include <kjsembed/jsbinding.h> + +#ifndef QT_ONLY +#include <kjsembed/xmlactionclient.h> +#else +#include <kjsembed/qtstubs.h> +#endif + +class QWidget; + +#define KJSEMBED_VERSION_STRING "0.3" +#define KJSEMBED_VERSION_MAJOR 0 +#define KJSEMBED_VERSION_MINOR 3 + +/** + * Namespace containing the KJSEmbed library. + */ +namespace KJSEmbed { + +class JSObjectProxy; +class JSConsoleWidget; +class JSFactory; +class JSBuiltIn; + +/** + * A KPart for embedding KJS in an application. + * + * @version $Id$ + * @author Richard Moore, rich@kde.org + * This is the easiest class for interacting and embedding the interpreter. To use KJSEmbed in yours + * application you can simply create a new KJSEmbedPart. Once you have this object you can expose your + * QObect based classes with a few simple methods. The interface also allows for the manipulation of QVariant data + * structures between Javascript and C++. Complex Javascript arrays are transparently converted to QMaps and QValueLists + * depending on the type of the Array. KJSEmbed also provides transparent access to most QVariant datatypes between + * C++ and Javascript. The easiest way to integrate KJSEmbed into your application is to create a QObject based class + * that will be your interface between C++ and Javascript. This object than can expose C++ methods via Qt slots, and + * QVariant datatypes via Qt properties. This class will also have an interface where C++ objects can call Javascript + * methods. + */ +class KJSEMBED_EXPORT KJSEmbedPart : public KParts::ReadOnlyPart +{ + Q_OBJECT + Q_PROPERTY( QStringList constructorNames READ constructorNames ) + Q_PROPERTY( QCString versionString READ versionString ) + Q_PROPERTY( int versionMajor READ versionMajor ) + Q_PROPERTY( int versionMinor READ versionMinor ) + +public: + /** Create a KJSEmbedPart. */ + KJSEmbedPart( QObject *parent=0, const char *name=0 ); + + /** + * Creates a KJSEmbedPart for which the parents of the view and part are different. + * + * Caution! you cannot use parent = [KQ]Application and wparent = 0L. + * This will cause a crash on exit since the widget will not be destroyed + * but the part will get destroyed at the end of the QApplication + * constructor. This results in the widget trying to do GUI related things + * after the QPaint stuff is destroyed. + */ + KJSEmbedPart( QWidget *wparent, const char *wname=0, QObject *parent=0, const char *name=0 ); + + /** + * Create a KJSEmbedPart with the specified interpreter. + * + * See warning above. + */ + KJSEmbedPart( KJS::Interpreter *js, QWidget *wparent, const char *wname=0, + QObject *parent=0, const char *name=0 ); + + /** Cleans up. */ + virtual ~KJSEmbedPart(); + + // + // Version information + // + + /** Returns the version of KJSEmbed. */ + QCString versionString() const; + + /** Returns the minor version number of KJSEmbed. */ + int versionMajor() const; + + /** Returns the major version number of KJSEmbed. */ + int versionMinor() const; + + // + // Script environment. + // + + /** Checks to see if a desired method is available in Javascript. + * @code + * if ( js->hasMethod( "javascriptFunction" ) ) + * ... // do something with that function. + * else + * ... // function not present. + */ + bool hasMethod( const QString &methodName ); + + /** Calls a method from Javascript starting from the global context. + * @code + * KJS::List args; + * args.append(KJS::String("String Arg") ); + * args.append(KJS::Number(10) ); + * args.append(KJSEmbed::convertToValue(js->globalExec(), QColor("blue" ) ) ); + * KJS::Value val = js->callMethod("javascriptFunction", args ); + * QString myString = val.toString().qstring(); + * @endcode + */ + + KJS::Value callMethod(const QString &methodName, const KJS::List &args) const; + /** Gets a value from Javascript starting from the global context. + * @code + * KJS::Value val = js->getValue("someValue"); + * QString myString = val.toString().qstring(); + * @endcode + */ + KJS::Value getValue( const QString &valueName ) const; + + /** Sets a value in a Javascript starting from the global context. + * Note if this value is not present in the javascript context it will + * become defined once this method is called. + * @code + * KJS::Value val = KJSEmbed::convertToValue(js->globalExec(), QColor("blue")); + * js->putValue("myVar", val); + * @endcode + */ + void putValue( const QString &valueName, const KJS::Value &value); + + /** Convinence method that wraps around @ref putValue that only handles values + * that are supported by QVariant. + * @code + * js->putVariant( "myVar", QColor("blue") ); + * @endcode + */ + void putVariant( const QString &valueName, const QVariant &value); + + /** Convinence method that wraps around @ref getValue that only handles values + * that are supported by QVariant. + * @code + * QColor value = js->getVariant( "myVar").toColor(); + * @endcode + */ + QVariant getVariant( const QString &valueName ) const; + + /** Returns the global object of the interpreter. */ + KJS::Object globalObject() const { return js->globalObject(); } + + /** Returns the completion object for the last script executed. */ + KJS::Completion completion() const { return res; } + + /** Returns the JS object of the part. */ + KJS::Object partObject() const { return partobj; } + + /** + * Publishes 'obj' as property 'name' of the global object. If 'name' is + * not specified then the name property of 'obj' is used instead. + * @code + * // In C++ + * QObject *myClass = new QObjectBasedClass(this, "jsObject"); + * js->addObject( myClass ); + * // In Javascript + * jsObject.someProperty = "Test Property"; + * // In C++ again + * kdDebug() << "New Value: " << myClass->someProperty() << endl; // displays "Test Property" + * @endcode + */ + KJS::Object addObject( QObject *obj, const char *name=0 ); + + /** + * Publishes 'obj' as property 'name' of object 'parent'. The binding is defined + * using @ref JSObjectProxy, and is subject to the current default SecurityPolicy. + */ + KJS::Object addObject( QObject *obj, KJS::Object &parent, const char *name=0 ); + + /** Returns a JS::Object that provides a binding to the specified QObject. */ + KJS::Object bind( QObject *obj ); + + // + // Query the supported types + // + + /** Returns a list of the names of the constructors of this interpreter. */ + QStringList constructorNames() const; + + /** Returns a JS Array of the constructors of this interpreter. */ + KJS::Value constructors() const; + + /** Returns a list of the constructors of this interpreter. */ + KJS::List constructorList() const; + +public slots: + // + // Reimplement the KPart API. + // + + /** Returns the view widget, creating one if required.*/ + virtual KJSEmbed::JSConsoleWidget *view(); + + /** Opens a URL. If the URL has the protocol 'javascript' then it is executed. */ + virtual bool openURL( const KURL &url ); + + // + // XML Action Handling + // + + /** Returns the current XMLActionClient. */ + KJSEmbed::XMLActionClient *actionClient() const { return xmlclient; } + + /** Loads the XML actions defined in the specified file to the default XMLActionClient. */ + bool loadActionSet( const QString &file ); + + // + // Script environemnt + // + + /** Returns the current interpreter. */ + KJS::Interpreter *interpreter() const { return js; } + + /** Returns the execution context of the interpreter. */ + KJS::ExecState *globalExec() const { return js->globalExec(); } + + /** Returns the current factory object. */ + JSFactory *factory() const { return jsfactory; } + + /** Evaluates the specified string, with the specified value as 'this'. */ + virtual KJS::Value evaluate( const QString &script, const KJS::Value &self=KJS::Null() ); + + /** Executes the specified string, with the specified value as 'this'. */ + bool execute( const QString &script, const KJS::Value &self=KJS::Null() ); + + /** + * Executes the specified string, with the specified value as 'this' and sets + * result to the completion object returned by the interpreter. + */ + virtual bool execute( KJS::Completion &result, const QString &script, const KJS::Value &self ); + + /** Loads and runs the specified file. */ + virtual bool runFile( const QString &filename, const KJS::Value &self=KJS::Null() ); + + /** + * Loads but does not execute the specified script file. If the + * first line of the file starts with the string '#!' then that + * line will be omitted from the returned string. + */ + QString loadFile( const QString &file ); + +protected: + /** Creates the interpreter. */ + void createInterpreter(); + + /** + * Creates the built-in objects and methods in the specified parent object + * normally the global object of the interpreter. This method is called + * automatically unless you create the part with a custom interpreter, if + * you do then you have to call this method yourself if you want the + * built-ins to be available. + */ + void createBuiltIn( KJS::ExecState *exec, KJS::Object &parent ); + + /** Sets up the XMLActionClient. */ + void createActionClient(); + + /** Reimplemented to disable file support. */ + virtual bool openFile() { return false; } + + /** @internal Hook for virtual that cannot break compatibility. */ + virtual void virtual_hook( int id, void *data ); + +private: + XMLActionClient *xmlclient; + JSConsoleWidget *jsConsole; + JSFactory *jsfactory; + JSBuiltIn *builtins; + QWidget *widgetparent; + QCString widgetname; + + KJS::Object partobj; + KJS::Completion res; + KJS::Interpreter *js; + bool deletejs; + + class KJSEmbedPartPrivate *d; +}; + + +} // namespace KJSEmbed + +#endif // KJSEMBEDJSCONSOLEPART_H + +// Local Variables: +// c-basic-offset: 4 +// End: + diff --git a/kjsembed/kjsembedpart_imp.cpp b/kjsembed/kjsembedpart_imp.cpp new file mode 100644 index 00000000..98c74859 --- /dev/null +++ b/kjsembed/kjsembedpart_imp.cpp @@ -0,0 +1,60 @@ +/* + * Copyright (C) 2001-2003, Richard J. Moore <rich@kde.org> + * + * This 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. + * + * This 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 this library; see the file COPYING.LIB. If not, write to + * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, + * Boston, MA 02110-1301, USA. + */ + +#include "global.h" +#include "jsfactory.h" +#include "kjsembedpart.h" + +#include "kjsembedpart_imp.h" + +// +// KJSEmbedPart Bindings +// +namespace KJSEmbed { +namespace Bindings { + +KJSEmbedPartImp::KJSEmbedPartImp( KJS::ExecState *exec, KJSEmbedPart *jsp, int mid, const QString &p ) + : JSProxyImp(exec), part(jsp), id(mid), param(p) +{ +} + +KJSEmbedPartImp::~KJSEmbedPartImp() {} + +KJS::Value KJSEmbedPartImp::call( KJS::ExecState *exec, KJS::Object &/*self*/, const KJS::List &args ) +{ + QString arg0 = (args.size() > 0) ? args[0].toString(exec).qstring() : QString::null; +// QString arg1 = (args.size() > 1) ? args[1].toString(exec).qstring() : QString::null; + + if ( id == MethodCreate ) { + return part->factory()->create( exec, arg0.latin1(), args.copyTail() ); + } + else { + kdWarning() << "KJSEmbedPartImp has no method " << id << endl; + } + + QString msg = i18n( "KJSEmbedPartImp has no method with id '%1'." ).arg( id ); + return throwError(exec, msg,KJS::ReferenceError); +} + +} // namespace KJSEmbed::Bindings +} // namespace KJSEmbed + +// Local Variables: +// c-basic-offset: 4 +// End: diff --git a/kjsembed/kjsembedpart_imp.h b/kjsembed/kjsembedpart_imp.h new file mode 100644 index 00000000..a7ca1f83 --- /dev/null +++ b/kjsembed/kjsembedpart_imp.h @@ -0,0 +1,75 @@ +// -*- c++ -*- + +/* + * Copyright (C) 2001-2003, Richard J. Moore <rich@kde.org> + * + * This 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. + * + * This 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 this library; see the file COPYING.LIB. If not, write to + * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, + * Boston, MA 02110-1301, USA. + */ + +#ifndef KJSEMBEDPARTIMP_H +#define KJSEMBEDPARTIMP_H + +#include <kjs/object.h> +#include <kjsembed/jsobjectproxy_imp.h> + +namespace KJSEmbed { class KJSEmbedPart; } + +/** + * Namespace containing the KJSEmbed library. + */ +namespace KJSEmbed { +namespace Bindings { + +/** + * Implements KJS bindings for KJSEmbedPart. + * + * @author Richard Moore, rich@kde.org + */ +class KJSEmbedPartImp : public JSProxyImp +{ +public: + /** Identifiers for the various methods. */ + enum MethodId { + MethodCreate, + CustomMethod=0x1000 + }; + + KJSEmbedPartImp( KJS::ExecState *exec, KJSEmbedPart *part, int id, const QString ¶m=QString::null ); + ~KJSEmbedPartImp(); + + QString parameter() const { return param; } + + /** Returns true iff this object implements the call function. */ + virtual bool implementsCall() const { return true; } + + /** Invokes the call function. */ + virtual KJS::Value call( KJS::ExecState *exec, KJS::Object &self, const KJS::List &args ); + +private: + KJSEmbedPart *part; + uint id; + QString param; + class KJSEmbedPartImpPrivate *d; +}; + +} // namespace KJSEmbed::Bindings +} // namespace KJSEmbed + +#endif // KJSEMBEDPARTIMP_H + +// Local Variables: +// c-basic-offset: 4 +// End: diff --git a/kjsembed/kscript/Makefile.am b/kjsembed/kscript/Makefile.am new file mode 100644 index 00000000..2e3a6915 --- /dev/null +++ b/kjsembed/kscript/Makefile.am @@ -0,0 +1,17 @@ +INCLUDES = -I$(srcdir) -I$(top_srcdir) $(all_includes) + +kde_module_LTLIBRARIES = libjavascript.la + +libjavascript_la_SOURCES = javascript.cpp +libjavascript_la_LDFLAGS = $(all_libraries) -module $(KDE_PLUGIN) -no-undefined -avoid-version +libjavascript_la_LIBADD = -lkscript ../libkjsembed.la + + +METASOURCES = AUTO + +servicetypedir = $(kde_servicesdir) +servicetype_DATA = javascript.desktop + +katescriptsdir = $(kde_datadir)/kate/scripts +katescripts_DATA = swaptabs.desktop swaptabs.ui +katescripts_SCRIPTS = swaptabs.js diff --git a/kjsembed/kscript/javascript.cpp b/kjsembed/kscript/javascript.cpp new file mode 100644 index 00000000..31976981 --- /dev/null +++ b/kjsembed/kscript/javascript.cpp @@ -0,0 +1,111 @@ +/* This file is part of the KDE project + Copyright (C) 2003 Ian Reinhart Geiser (geiseri@kde.org) + + This 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. + + This 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 this library; see the file COPYING.LIB. If not, write to + the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, + Boston, MA 02110-1301, USA. +*/ + +#include "javascript.h" +#include <kapplication.h> +#include <dcopclient.h> +#include <kdebug.h> +#include <kjsembed/kjsembedpart.h> +#include <kjsembed/jsconsolewidget.h> +#include <kjsembed/jsbinding.h> + +#include <kgenericfactory.h> +#include <scriptclientinterface.h> +//using namespace KScriptInterface; +typedef KGenericFactory<JavaScript, KScriptClientInterface> JavaScriptFactory; +K_EXPORT_COMPONENT_FACTORY( libjavascript, JavaScriptFactory( "JavaScript" ) ) + +JavaScript::JavaScript(KScriptClientInterface *parent, const char *name, const QStringList &args ) +{ + ScriptClientInterface = parent; + m_jsembed = new KJSEmbed::KJSEmbedPart(this, "kjsembed_part"); + m_scriptLoc = ""; // arg1? + m_method = ""; // arg2? + m_jsembed->addObject( this, "KScriptInterface"); + m_jsembed->addObject( m_jsembed->view(), "console" ); +} + +JavaScript::~JavaScript() +{ +} + +QString JavaScript::script() const +{ + return m_scriptLoc; +} + +void JavaScript::setScript( const QString &scriptFile ) +{ + m_scriptLoc = scriptFile; +} + +void JavaScript::setScript( const QString &scriptFile, const QString &method ) +{ + m_scriptLoc = scriptFile; + m_method = method; +} + +void JavaScript::run(QObject *context, const QVariant &arg) +{ + QVariant retVal; + if( context ) m_jsembed->addObject(context); + + m_jsembed->runFile(m_scriptLoc, m_jsembed->globalObject() ); + + if( !m_method.isEmpty() ) + { + KJS::List args; + args.append( KJSEmbed::convertToValue(m_jsembed->globalExec(), arg) ); + KJS::Value val = m_jsembed->callMethod(m_method, args); + retVal = KJSEmbed::convertToVariant(m_jsembed->globalExec(),val); + } + ScriptClientInterface->done(KScriptClientInterface::ResultSuccess, retVal); +} + +void JavaScript::writeLine( const QString &msg ) +{ + ScriptClientInterface->output(msg); +} + +void JavaScript::writeWarning( const QString &msg ) +{ + ScriptClientInterface->warning(msg); +} + +void JavaScript::writeError( const QString &msg ) +{ + ScriptClientInterface->error(msg); +} + +void JavaScript::setProgress( int percent ) +{ + ScriptClientInterface->progress(percent); +} + +QString JavaScript::appID() const +{ + return kapp->dcopClient()->appId(); +} + +void JavaScript::kill() +{ + // not sure what to do here.... +} + +#include "javascript.moc" diff --git a/kjsembed/kscript/javascript.desktop b/kjsembed/kscript/javascript.desktop new file mode 100644 index 00000000..0055e68a --- /dev/null +++ b/kjsembed/kscript/javascript.desktop @@ -0,0 +1,7 @@ +[Desktop Entry] +Name=KJSEmbed Script Runner +Type=Service +X-KDE-Library=libjavascript +X-KDE-Script-Runner=JavaScript/kjs +ServiceTypes=KScriptRunner/KScriptRunner +Comment=Javascript scripts from inside the application. diff --git a/kjsembed/kscript/javascript.h b/kjsembed/kscript/javascript.h new file mode 100644 index 00000000..7b5143a7 --- /dev/null +++ b/kjsembed/kscript/javascript.h @@ -0,0 +1,60 @@ +/* This file is part of the KDE project + Copyright (C) 2003 Ian Reinhart Geiser (geiseri@kde.org) + + This 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. + + This 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 this library; see the file COPYING.LIB. If not, write to + the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, + Boston, MA 02110-1301, USA. +*/ +#ifndef __javascript_h__ +#define __javascript_h__ + +#include <scriptinterface.h> +#include <qvariant.h> +#include <qobject.h> + +namespace KJSEmbed { + class KJSEmbedPart; +} + +//using namespace KScriptInterface; +class JavaScript : public KScriptInterface +{ + Q_OBJECT + Q_PROPERTY( QString appID READ appID ) + +public: + JavaScript(KScriptClientInterface *parent, const char *name, const QStringList &args); + virtual ~JavaScript(); + QString script() const; + void setScript( const QString &scriptFile ); + void setScript( const QString &scriptLibFile, const QString &method ); + void run(QObject *context = 0, const QVariant &arg = 0); + void kill(); + + QString appID() const; + +public slots: + void writeLine( const QString &msg ); + void writeWarning( const QString &msg ); + void writeError( const QString &msg ); + void setProgress( int percent ); + +private: + KScriptClientInterface *ScriptClientInterface; + KJSEmbed::KJSEmbedPart *m_jsembed; + QString m_method; + QString m_scriptLoc; +}; + +#endif diff --git a/kjsembed/kscript/swaptabs.desktop b/kjsembed/kscript/swaptabs.desktop new file mode 100644 index 00000000..7de4dcfa --- /dev/null +++ b/kjsembed/kscript/swaptabs.desktop @@ -0,0 +1,5 @@ +[Desktop Entry] +Name=Swap tabs and spaces. +Comment=Swap tabs and space indentation in text. +Type=JavaScript/kjs +X-KDE-ScriptName=swaptabs.js diff --git a/kjsembed/kscript/swaptabs.js b/kjsembed/kscript/swaptabs.js new file mode 100644 index 00000000..6adbc2c3 --- /dev/null +++ b/kjsembed/kscript/swaptabs.js @@ -0,0 +1,75 @@ +#!/usr/bin/env kjscmd +var appID = "kate"; +StdDirs.addResourceType("swaptabs", StdDirs.kde_default("data") + "/kate/scripts"); + +var client = new DCOPClient(); +var config = new Config( this, "swaptabsrc" ); +var documentIndex = client.call(appID, "KateDocumentManager", "activeDocumentNumber()"); +var ui = StdDirs.findResource("swaptabs","swaptabs.ui"); +var dlg = Factory.loadui(ui); + +// Load prefs +dlg.count.value = config.readNumEntry("Spaces", 8 ); +dlg.swap.selectedId = config.readNumEntry("Mode", 0 ); + +if( dlg.exec() == 1 ) +{ + var spaces = dlg.count.value; + + var sourceText; + var destText; + if( dlg.selection.checked ) + sourceText = client.call(appID, "SelectionInterface#" + documentIndex, "selection()"); + else + sourceText = client.call(appID, "EditInterface#" + documentIndex, "text()"); + + if( dlg.swap.selectedId == 0 ) + destText = replaceSpaces( spaces, sourceText ); + else + destText = replaceTabs( spaces, sourceText ); + + if( dlg.selection.checked ) + { + if( client.call(appID, "SelectionInterface#" + documentIndex, "hasSelection()") ) + { + var startLine = client.call(appID, "SelectionInterfaceExt#" + documentIndex, "selStartLine()"); + var startCol = client.call(appID, "SelectionInterfaceExt#" + documentIndex, "selStartCol()"); + client.call(appID, "SelectionInterface#" + documentIndex, "removeSelectedText()"); + client.call(appID, "SelectionInterface#" + documentIndex, "clearSelection()"); + client.call(appID, "EditInterface#" + documentIndex, "insertText(uint,uint,QString)", startLine, startCol, destText); + } + else + { + alert("You must first select text."); + return false; + } + } + else + client.call(appID, "EditInterface#" + documentIndex, "setText(QString)", destText ); + + // save prefs + config.writeNumEntry("Spaces", dlg.count.value ); + config.writeNumEntry("Mode", dlg.swap.selectedId ); +} + +function replaceSpaces( count, text ) +{ + var regExp = new RegExp("[ ]{"+count+","+count+"}", "g"); + regExp.mulitline = true; + + returnText = text.replace( regExp, "\t"); + return returnText; +} + +function replaceTabs( count, text ) +{ + + var regExp = new RegExp("[\t]","g"); + regExp.mulitline = true; + + var spaces = ""; + for( var idx = 0; idx < count; ++idx) + spaces += " "; + returnText = text.replace( regExp, spaces); + return returnText; +} diff --git a/kjsembed/kscript/swaptabs.ui b/kjsembed/kscript/swaptabs.ui new file mode 100644 index 00000000..8cb243f8 --- /dev/null +++ b/kjsembed/kscript/swaptabs.ui @@ -0,0 +1,172 @@ +<!DOCTYPE UI><UI version="3.3" stdsetdef="1"> +<class>MyDialog</class> +<widget class="QDialog"> + <property name="name"> + <cstring>MyDialog</cstring> + </property> + <property name="geometry"> + <rect> + <x>0</x> + <y>0</y> + <width>219</width> + <height>176</height> + </rect> + </property> + <property name="caption"> + <string>Swap Tabs & Spaces</string> + </property> + <property name="sizeGripEnabled"> + <bool>true</bool> + </property> + <vbox> + <property name="name"> + <cstring>unnamed</cstring> + </property> + <widget class="QLayoutWidget"> + <property name="name"> + <cstring>layout2</cstring> + </property> + <hbox> + <property name="name"> + <cstring>unnamed</cstring> + </property> + <widget class="QLabel"> + <property name="name"> + <cstring>textLabel1</cstring> + </property> + <property name="text"> + <string>Number of spaces for a tab:</string> + </property> + </widget> + <widget class="QSpinBox"> + <property name="name"> + <cstring>count</cstring> + </property> + <property name="value"> + <number>4</number> + </property> + </widget> + </hbox> + </widget> + <widget class="QButtonGroup"> + <property name="name"> + <cstring>swap</cstring> + </property> + <property name="title"> + <string>Swap</string> + </property> + <property name="selectedId" stdset="0"> + <number>0</number> + </property> + <vbox> + <property name="name"> + <cstring>unnamed</cstring> + </property> + <widget class="QRadioButton"> + <property name="name"> + <cstring>radioButton1</cstring> + </property> + <property name="text"> + <string>Tabs for spaces</string> + </property> + </widget> + <widget class="QRadioButton"> + <property name="name"> + <cstring>radioButton2</cstring> + </property> + <property name="text"> + <string>Spaces for tabs</string> + </property> + </widget> + </vbox> + </widget> + <widget class="QCheckBox"> + <property name="name"> + <cstring>selection</cstring> + </property> + <property name="text"> + <string>Substitute only in current selection</string> + </property> + </widget> + <widget class="QLayoutWidget"> + <property name="name"> + <cstring>Layout1</cstring> + </property> + <hbox> + <property name="name"> + <cstring>unnamed</cstring> + </property> + <property name="margin"> + <number>0</number> + </property> + <property name="spacing"> + <number>6</number> + </property> + <spacer> + <property name="name"> + <cstring>Horizontal Spacing2</cstring> + </property> + <property name="orientation"> + <enum>Horizontal</enum> + </property> + <property name="sizeType"> + <enum>Expanding</enum> + </property> + <property name="sizeHint"> + <size> + <width>20</width> + <height>20</height> + </size> + </property> + </spacer> + <widget class="QPushButton"> + <property name="name"> + <cstring>buttonOk</cstring> + </property> + <property name="text"> + <string>&OK</string> + </property> + <property name="accel"> + <string></string> + </property> + <property name="autoDefault"> + <bool>true</bool> + </property> + <property name="default"> + <bool>true</bool> + </property> + </widget> + <widget class="QPushButton"> + <property name="name"> + <cstring>buttonCancel</cstring> + </property> + <property name="text"> + <string>&Cancel</string> + </property> + <property name="accel"> + <string></string> + </property> + <property name="autoDefault"> + <bool>true</bool> + </property> + </widget> + </hbox> + </widget> + </vbox> +</widget> +<connections> + <connection> + <sender>buttonOk</sender> + <signal>clicked()</signal> + <receiver>MyDialog</receiver> + <slot>accept()</slot> + </connection> + <connection> + <sender>buttonCancel</sender> + <signal>clicked()</signal> + <receiver>MyDialog</receiver> + <slot>reject()</slot> + </connection> +</connections> +<layoutdefaults spacing="6" margin="11"/> +</UI> diff --git a/kjsembed/ksimpleprocess.cpp b/kjsembed/ksimpleprocess.cpp new file mode 100644 index 00000000..ace19fcc --- /dev/null +++ b/kjsembed/ksimpleprocess.cpp @@ -0,0 +1,93 @@ +// -*- c++ -*- + +/* + * Copyright (C) 2004, Ian Reinhart Geiser <geiseri@kde.org> + * + * This 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. + * + * This 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 this library; see the file COPYING.LIB. If not, write to + * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, + * Boston, MA 02110-1301, USA. + */ +#include "ksimpleprocess.h" +#include <qapplication.h> +#include <klocale.h> +static QStringList splitArgList( const QString &args) +{ + QStringList returnArgs = QStringList::split( ' ', args); + return returnArgs; +} + +QString KSimpleProcess::exec( const QString &args, bool addStdErr ) +{ + KSimpleProcess proc; + return proc.execInternal( args, addStdErr); +} + +QString KSimpleProcess::execInternal( const QString &args, bool addStdError) +{ + m_proc->setArguments( splitArgList( args )); + connect(m_proc, SIGNAL(processExited()), this, SLOT(slotProcessExited())); + connect(m_proc, SIGNAL(readyReadStdout()), this, SLOT(slotReceivedStdout())); + if( addStdError ) + connect(m_proc, SIGNAL(readyReadStderr()), this, SLOT(slotReceivedStderr())); + + if ( !m_proc->start() ) + return i18n("Could not run command '%1'.").arg( args.latin1() ); + enter_loop(); + return m_currBuffer; +} + +KSimpleProcess::KSimpleProcess() : QObject(0,0) +{ + m_currBuffer = ""; + m_stdErrOn = false; + m_proc = new QProcess(this); +} + +KSimpleProcess::~KSimpleProcess() +{ + delete m_proc; +} + + +// If a troll sees this, he kills david not me +void qt_enter_modal( QWidget *widget ); +void qt_leave_modal( QWidget *widget ); + +void KSimpleProcess::enter_loop() +{ + QWidget dummy(0,0,WType_Dialog | WShowModal); + dummy.setFocusPolicy( QWidget::NoFocus ); + qt_enter_modal(&dummy); + qApp->enter_loop(); + qt_leave_modal(&dummy); +} + +void KSimpleProcess::slotProcessExited() +{ + while( m_proc->canReadLineStdout() ) + m_currBuffer += m_proc->readLineStdout() + '\n'; + qApp->exit_loop(); +} + +void KSimpleProcess::slotReceivedStdout() +{ + m_currBuffer += m_proc->readLineStdout() + '\n'; +} + +void KSimpleProcess::slotReceivedStderr() +{ + m_currBuffer += m_proc->readLineStderr() + '\n'; +} + +#include "ksimpleprocess.moc" diff --git a/kjsembed/ksimpleprocess.h b/kjsembed/ksimpleprocess.h new file mode 100644 index 00000000..12b20805 --- /dev/null +++ b/kjsembed/ksimpleprocess.h @@ -0,0 +1,70 @@ +// -*- c++ -*- + +/* + * Copyright (C) 2004, Ian Reinhart Geiser <geiseri@kde.org> + * + * This 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. + * + * This 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 this library; see the file COPYING.LIB. If not, write to + * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, + * Boston, MA 02110-1301, USA. + */ + +#ifndef KSIMPLE_PROCESS_H +#define KSIMPLE_PROCESS_H + +#include <qobject.h> +#include <qprocess.h> + +/** + * Very simple class that allows one to run a command and get the + * standard output back as a string value. + * + * @author Ian Reinhart Geiser, geiseri@kde.org + */ +class KSimpleProcess : public QObject +{ + Q_OBJECT + +public: + /** + * Executes a string as if it where at the current shell. This will block until + * execution is finished. Once its finished the standard output will be returned. + * if the addStdErr is true, the standard error will be combined with the standard + * in value. + * Example: + *\code + * QString myProc = KSimpleProcess::exec( "ps -uh" ); + * kdDebug() << "Running Processes\n" << myProc << endl; + *\endcode + */ + static QString exec( const QString &args, bool addStdErr = false ); + +private: + KSimpleProcess(); + ~KSimpleProcess(); + void enter_loop(); + QString execInternal( const QString &args, bool addStdError); + + QString m_currBuffer; + bool m_stdErrOn; + QProcess *m_proc; + +public slots: + void slotProcessExited(); + void slotReceivedStdout(); + void slotReceivedStderr(); + + friend class Im_lonely; // yet another reason why c++ is braindead... +}; + +#endif // KSIMPLE_PROCESS_H diff --git a/kjsembed/lgpl.txt b/kjsembed/lgpl.txt new file mode 100644 index 00000000..ec47efc0 --- /dev/null +++ b/kjsembed/lgpl.txt @@ -0,0 +1,504 @@ + GNU LESSER GENERAL PUBLIC LICENSE + Version 2.1, February 1999 + + Copyright (C) 1991, 1999 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. + +[This is the first released version of the Lesser GPL. It also counts + as the successor of the GNU Library Public License, version 2, hence + the version number 2.1.] + + Preamble + + The licenses for most software are designed to take away your +freedom to share and change it. By contrast, the GNU General Public +Licenses are intended to guarantee your freedom to share and change +free software--to make sure the software is free for all its users. + + This license, the Lesser General Public License, applies to some +specially designated software packages--typically libraries--of the +Free Software Foundation and other authors who decide to use it. You +can use it too, but we suggest you first think carefully about whether +this license or the ordinary General Public License is the better +strategy to use in any particular case, based on the explanations below. + + When we speak of free software, we are referring to freedom of use, +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 and use pieces of +it in new free programs; and that you are informed that you can do +these things. + + To protect your rights, we need to make restrictions that forbid +distributors to deny you these rights or to ask you to surrender these +rights. These restrictions translate to certain responsibilities for +you if you distribute copies of the library or if you modify it. + + For example, if you distribute copies of the library, whether gratis +or for a fee, you must give the recipients all the rights that we gave +you. You must make sure that they, too, receive or can get the source +code. If you link other code with the library, you must provide +complete object files to the recipients, so that they can relink them +with the library after making changes to the library and recompiling +it. And you must show them these terms so they know their rights. + + We protect your rights with a two-step method: (1) we copyright the +library, and (2) we offer you this license, which gives you legal +permission to copy, distribute and/or modify the library. + + To protect each distributor, we want to make it very clear that +there is no warranty for the free library. Also, if the library is +modified by someone else and passed on, the recipients should know +that what they have is not the original version, so that the original +author's reputation will not be affected by problems that might be +introduced by others. + + Finally, software patents pose a constant threat to the existence of +any free program. We wish to make sure that a company cannot +effectively restrict the users of a free program by obtaining a +restrictive license from a patent holder. Therefore, we insist that +any patent license obtained for a version of the library must be +consistent with the full freedom of use specified in this license. + + Most GNU software, including some libraries, is covered by the +ordinary GNU General Public License. This license, the GNU Lesser +General Public License, applies to certain designated libraries, and +is quite different from the ordinary General Public License. We use +this license for certain libraries in order to permit linking those +libraries into non-free programs. + + When a program is linked with a library, whether statically or using +a shared library, the combination of the two is legally speaking a +combined work, a derivative of the original library. The ordinary +General Public License therefore permits such linking only if the +entire combination fits its criteria of freedom. The Lesser General +Public License permits more lax criteria for linking other code with +the library. + + We call this license the "Lesser" General Public License because it +does Less to protect the user's freedom than the ordinary General +Public License. It also provides other free software developers Less +of an advantage over competing non-free programs. These disadvantages +are the reason we use the ordinary General Public License for many +libraries. However, the Lesser license provides advantages in certain +special circumstances. + + For example, on rare occasions, there may be a special need to +encourage the widest possible use of a certain library, so that it becomes +a de-facto standard. To achieve this, non-free programs must be +allowed to use the library. A more frequent case is that a free +library does the same job as widely used non-free libraries. In this +case, there is little to gain by limiting the free library to free +software only, so we use the Lesser General Public License. + + In other cases, permission to use a particular library in non-free +programs enables a greater number of people to use a large body of +free software. For example, permission to use the GNU C Library in +non-free programs enables many more people to use the whole GNU +operating system, as well as its variant, the GNU/Linux operating +system. + + Although the Lesser General Public License is Less protective of the +users' freedom, it does ensure that the user of a program that is +linked with the Library has the freedom and the wherewithal to run +that program using a modified version of the Library. + + The precise terms and conditions for copying, distribution and +modification follow. Pay close attention to the difference between a +"work based on the library" and a "work that uses the library". The +former contains code derived from the library, whereas the latter must +be combined with the library in order to run. + + GNU LESSER GENERAL PUBLIC LICENSE + TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION + + 0. This License Agreement applies to any software library or other +program which contains a notice placed by the copyright holder or +other authorized party saying it may be distributed under the terms of +this Lesser General Public License (also called "this License"). +Each licensee is addressed as "you". + + A "library" means a collection of software functions and/or data +prepared so as to be conveniently linked with application programs +(which use some of those functions and data) to form executables. + + The "Library", below, refers to any such software library or work +which has been distributed under these terms. A "work based on the +Library" means either the Library or any derivative work under +copyright law: that is to say, a work containing the Library or a +portion of it, either verbatim or with modifications and/or translated +straightforwardly into another language. (Hereinafter, translation is +included without limitation in the term "modification".) + + "Source code" for a work means the preferred form of the work for +making modifications to it. For a library, 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 library. + + Activities other than copying, distribution and modification are not +covered by this License; they are outside its scope. The act of +running a program using the Library is not restricted, and output from +such a program is covered only if its contents constitute a work based +on the Library (independent of the use of the Library in a tool for +writing it). Whether that is true depends on what the Library does +and what the program that uses the Library does. + + 1. You may copy and distribute verbatim copies of the Library's +complete 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 distribute a copy of this License along with the +Library. + + 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 Library or any portion +of it, thus forming a work based on the Library, 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) The modified work must itself be a software library. + + b) You must cause the files modified to carry prominent notices + stating that you changed the files and the date of any change. + + c) You must cause the whole of the work to be licensed at no + charge to all third parties under the terms of this License. + + d) If a facility in the modified Library refers to a function or a + table of data to be supplied by an application program that uses + the facility, other than as an argument passed when the facility + is invoked, then you must make a good faith effort to ensure that, + in the event an application does not supply such function or + table, the facility still operates, and performs whatever part of + its purpose remains meaningful. + + (For example, a function in a library to compute square roots has + a purpose that is entirely well-defined independent of the + application. Therefore, Subsection 2d requires that any + application-supplied function or table used by this function must + be optional: if the application does not supply it, the square + root function must still compute square roots.) + +These requirements apply to the modified work as a whole. If +identifiable sections of that work are not derived from the Library, +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 Library, 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 Library. + +In addition, mere aggregation of another work not based on the Library +with the Library (or with a work based on the Library) on a volume of +a storage or distribution medium does not bring the other work under +the scope of this License. + + 3. You may opt to apply the terms of the ordinary GNU General Public +License instead of this License to a given copy of the Library. To do +this, you must alter all the notices that refer to this License, so +that they refer to the ordinary GNU General Public License, version 2, +instead of to this License. (If a newer version than version 2 of the +ordinary GNU General Public License has appeared, then you can specify +that version instead if you wish.) Do not make any other change in +these notices. + + Once this change is made in a given copy, it is irreversible for +that copy, so the ordinary GNU General Public License applies to all +subsequent copies and derivative works made from that copy. + + This option is useful when you wish to copy part of the code of +the Library into a program that is not a library. + + 4. You may copy and distribute the Library (or a portion or +derivative of it, under Section 2) in object code or executable form +under the terms of Sections 1 and 2 above provided that you 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. + + If distribution of 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 satisfies the requirement to +distribute the source code, even though third parties are not +compelled to copy the source along with the object code. + + 5. A program that contains no derivative of any portion of the +Library, but is designed to work with the Library by being compiled or +linked with it, is called a "work that uses the Library". Such a +work, in isolation, is not a derivative work of the Library, and +therefore falls outside the scope of this License. + + However, linking a "work that uses the Library" with the Library +creates an executable that is a derivative of the Library (because it +contains portions of the Library), rather than a "work that uses the +library". The executable is therefore covered by this License. +Section 6 states terms for distribution of such executables. + + When a "work that uses the Library" uses material from a header file +that is part of the Library, the object code for the work may be a +derivative work of the Library even though the source code is not. +Whether this is true is especially significant if the work can be +linked without the Library, or if the work is itself a library. The +threshold for this to be true is not precisely defined by law. + + If such an object file uses only numerical parameters, data +structure layouts and accessors, and small macros and small inline +functions (ten lines or less in length), then the use of the object +file is unrestricted, regardless of whether it is legally a derivative +work. (Executables containing this object code plus portions of the +Library will still fall under Section 6.) + + Otherwise, if the work is a derivative of the Library, you may +distribute the object code for the work under the terms of Section 6. +Any executables containing that work also fall under Section 6, +whether or not they are linked directly with the Library itself. + + 6. As an exception to the Sections above, you may also combine or +link a "work that uses the Library" with the Library to produce a +work containing portions of the Library, and distribute that work +under terms of your choice, provided that the terms permit +modification of the work for the customer's own use and reverse +engineering for debugging such modifications. + + You must give prominent notice with each copy of the work that the +Library is used in it and that the Library and its use are covered by +this License. You must supply a copy of this License. If the work +during execution displays copyright notices, you must include the +copyright notice for the Library among them, as well as a reference +directing the user to the copy of this License. Also, you must do one +of these things: + + a) Accompany the work with the complete corresponding + machine-readable source code for the Library including whatever + changes were used in the work (which must be distributed under + Sections 1 and 2 above); and, if the work is an executable linked + with the Library, with the complete machine-readable "work that + uses the Library", as object code and/or source code, so that the + user can modify the Library and then relink to produce a modified + executable containing the modified Library. (It is understood + that the user who changes the contents of definitions files in the + Library will not necessarily be able to recompile the application + to use the modified definitions.) + + b) Use a suitable shared library mechanism for linking with the + Library. A suitable mechanism is one that (1) uses at run time a + copy of the library already present on the user's computer system, + rather than copying library functions into the executable, and (2) + will operate properly with a modified version of the library, if + the user installs one, as long as the modified version is + interface-compatible with the version that the work was made with. + + c) Accompany the work with a written offer, valid for at + least three years, to give the same user the materials + specified in Subsection 6a, above, for a charge no more + than the cost of performing this distribution. + + d) If distribution of the work is made by offering access to copy + from a designated place, offer equivalent access to copy the above + specified materials from the same place. + + e) Verify that the user has already received a copy of these + materials or that you have already sent this user a copy. + + For an executable, the required form of the "work that uses the +Library" must include any data and utility programs needed for +reproducing the executable from it. However, as a special exception, +the materials to be 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. + + It may happen that this requirement contradicts the license +restrictions of other proprietary libraries that do not normally +accompany the operating system. Such a contradiction means you cannot +use both them and the Library together in an executable that you +distribute. + + 7. You may place library facilities that are a work based on the +Library side-by-side in a single library together with other library +facilities not covered by this License, and distribute such a combined +library, provided that the separate distribution of the work based on +the Library and of the other library facilities is otherwise +permitted, and provided that you do these two things: + + a) Accompany the combined library with a copy of the same work + based on the Library, uncombined with any other library + facilities. This must be distributed under the terms of the + Sections above. + + b) Give prominent notice with the combined library of the fact + that part of it is a work based on the Library, and explaining + where to find the accompanying uncombined form of the same work. + + 8. You may not copy, modify, sublicense, link with, or distribute +the Library except as expressly provided under this License. Any +attempt otherwise to copy, modify, sublicense, link with, or +distribute the Library 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. + + 9. 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 Library or its derivative works. These actions are +prohibited by law if you do not accept this License. Therefore, by +modifying or distributing the Library (or any work based on the +Library), you indicate your acceptance of this License to do so, and +all its terms and conditions for copying, distributing or modifying +the Library or works based on it. + + 10. Each time you redistribute the Library (or any work based on the +Library), the recipient automatically receives a license from the +original licensor to copy, distribute, link with or modify the Library +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 with +this License. + + 11. 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 Library at all. For example, if a patent +license would not permit royalty-free redistribution of the Library 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 Library. + +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. + + 12. If the distribution and/or use of the Library is restricted in +certain countries either by patents or by copyrighted interfaces, the +original copyright holder who places the Library 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. + + 13. The Free Software Foundation may publish revised and/or new +versions of the Lesser 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 Library +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 Library does not specify a +license version number, you may choose any version ever published by +the Free Software Foundation. + + 14. If you wish to incorporate parts of the Library into other free +programs whose distribution conditions are incompatible with these, +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 + + 15. BECAUSE THE LIBRARY IS LICENSED FREE OF CHARGE, THERE IS NO +WARRANTY FOR THE LIBRARY, TO THE EXTENT PERMITTED BY APPLICABLE LAW. +EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT HOLDERS AND/OR +OTHER PARTIES PROVIDE THE LIBRARY "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 +LIBRARY IS WITH YOU. SHOULD THE LIBRARY PROVE DEFECTIVE, YOU ASSUME +THE COST OF ALL NECESSARY SERVICING, REPAIR OR CORRECTION. + + 16. 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 LIBRARY 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 +LIBRARY (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 LIBRARY TO OPERATE WITH ANY OTHER SOFTWARE), 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 Libraries + + If you develop a new library, and you want it to be of the greatest +possible use to the public, we recommend making it free software that +everyone can redistribute and change. You can do so by permitting +redistribution under these terms (or, alternatively, under the terms of the +ordinary General Public License). + + To apply these terms, attach the following notices to the library. 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 library's name and a brief idea of what it does.> + Copyright (C) <year> <name of author> + + This library is free software; you can redistribute it and/or + modify it under the terms of the GNU Lesser General Public + License as published by the Free Software Foundation; either + version 2 of the License, or (at your option) any later version. + + This 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 + Lesser General Public License for more details. + + You should have received a copy of the GNU Lesser General Public + License along with this library; 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. + +You should also get your employer (if you work as a programmer) or your +school, if any, to sign a "copyright disclaimer" for the library, if +necessary. Here is a sample; alter the names: + + Yoyodyne, Inc., hereby disclaims all copyright interest in the + library `Frob' (a library for tweaking knobs) written by James Random Hacker. + + <signature of Ty Coon>, 1 April 1990 + Ty Coon, President of Vice + +That's all there is to it! + + diff --git a/kjsembed/plugin/Makefile.am b/kjsembed/plugin/Makefile.am new file mode 100644 index 00000000..9ec99770 --- /dev/null +++ b/kjsembed/plugin/Makefile.am @@ -0,0 +1,20 @@ +# -*- makefile -*- + +# Make sure the include path includes Qt's uilib +INCLUDES= -I$(QTDIR)/tools/designer/uilib -I$(srcdir)/.. -I.. -I$(top_srcdir) $(all_includes) + +INCLUDES += -DQT_CLEAN_NAMESPACE -DQT_NO_ASCII_CAST + +kde_module_LTLIBRARIES = libjsconsoleplugin.la + +METASOURCES = AUTO + +libjsconsoleplugin_la_SOURCES = jsconsoleplugin.cpp +libjsconsoleplugin_la_LIBADD = $(LIB_KPARTS) ../libkjsembed.la +libjsconsoleplugin_la_LDFLAGS = -module $(KDE_PLUGIN) $(all_libraries) $(KDE_RPATH) + +#pluginsdir = $(kde_datadir)/konqueror/kpartplugins +#plugins_DATA = plugin_jsconsole.rc + + + diff --git a/kjsembed/plugin/jsconsoleplugin.cpp b/kjsembed/plugin/jsconsoleplugin.cpp new file mode 100644 index 00000000..132eead5 --- /dev/null +++ b/kjsembed/plugin/jsconsoleplugin.cpp @@ -0,0 +1,99 @@ +/* + * Copyright (C) 2001-2003, Richard J. Moore <rich@kde.org> + * + * This 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. + * + * This 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 this library; see the file COPYING.LIB. If not, write to + * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, + * Boston, MA 02110-1301, USA. + */ + +#include <kaction.h> +#include <kapplication.h> +#include <kdebug.h> +#include <kgenericfactory.h> +#include <kinstance.h> +#include <klocale.h> +#include <kparts/part.h> + +#include <jsfactory.h> +#include <jsconsolewidget.h> +#include <kjsembedpart.h> + +#include "jsconsoleplugin.h" +#include "jsconsoleplugin.moc" + +typedef KGenericFactory<KJSEmbed::JSConsolePlugin> JSConsolePluginFactory; +K_EXPORT_COMPONENT_FACTORY( libjsconsoleplugin, JSConsolePluginFactory( "jsconsoleplugin" ) ) + +// +// KParts::Plugin Implementation +// +namespace KJSEmbed { + +JSConsolePlugin::JSConsolePlugin( QObject *parent, const char *name, const QStringList & ) + : KParts::Plugin( parent, name ) +{ + js = 0; + + KActionMenu *menu; + menu = new KActionMenu( i18n("&JavaScript"), "jsconsole", + actionCollection(), "jsconsole" ); + menu->setDelayed( false ); + + menu->insert( new KAction( i18n("&Console"), 0, + this, SLOT( showConsole() ), + actionCollection(), "jsconsole_show") ); +} + +void JSConsolePlugin::init() +{ + Q_ASSERT( js == 0 ); + js = new KJSEmbedPart( 0, 0, name(), 0, name() ); // shouldn't "this" be the parent? + + KJS::Interpreter *interp = js->interpreter(); + KJS::Object global( interp->globalObject() ); + js->addObject( js->view(), global, "console" ); + js->addObject( parent(), global, "plugin_parent" ); + js->addObject( KApplication::kApplication(), global, "application" ); + + if ( parent()->inherits("KParts::Part") ) { + KParts::Part *part = static_cast<KParts::Part *>( parent() ); + js->addObject( part, "kpart" ); + if ( part->widget() ) { + js->addObject( part->widget(), "widget" ); + js->addObject( part->widget()->topLevelWidget(), "window" ); + } + } +} + +JSConsolePlugin::~JSConsolePlugin() +{ + delete js; +} + +void JSConsolePlugin::showConsole() +{ + if ( !js ) + init(); + js->widget()->show(); +} + +} // namespace KJSEmbed + +// Local Variables: +// c-basic-offset: 4 +// End: + + + + diff --git a/kjsembed/plugin/jsconsoleplugin.h b/kjsembed/plugin/jsconsoleplugin.h new file mode 100644 index 00000000..6f4bc54b --- /dev/null +++ b/kjsembed/plugin/jsconsoleplugin.h @@ -0,0 +1,61 @@ +// -*- c++ -*- + +/* + * Copyright (C) 2001-2003, Richard J. Moore <rich@kde.org> + * + * This 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. + * + * This 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 this library; see the file COPYING.LIB. If not, write to + * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, + * Boston, MA 02110-1301, USA. + */ + +#ifndef KJSEMBEDJSCONSOLEPLUGIN_H +#define KJSEMBEDJSCONSOLEPLUGIN_H + +#include <kparts/plugin.h> + +class KJSEmbedPart; + +namespace KJSEmbed { + +/** + * A KParts::Plugin that provides a console for executing Javascript commands. + * + * @version $Id$ + * @author Richard Moore, rich@kde.org + */ +class JSConsolePlugin : public KParts::Plugin +{ + Q_OBJECT + +public: + JSConsolePlugin( QObject *parent, const char *name, const QStringList & ); + ~JSConsolePlugin(); + +private slots: + void showConsole(); + +private: + void init(); + + KJSEmbedPart *js; + class Private *d; +}; + +} // namespace KJSEmbed + +#endif // KJSEMBEDJSCONSOLEPLUGIN_H + +// Local Variables: +// c-basic-offset: 4 +// End: diff --git a/kjsembed/plugin/plugin_jsconsole.rc b/kjsembed/plugin/plugin_jsconsole.rc new file mode 100644 index 00000000..b1adf821 --- /dev/null +++ b/kjsembed/plugin/plugin_jsconsole.rc @@ -0,0 +1,11 @@ +<!DOCTYPE kpartgui> +<kpartplugin name="jsconsole" library="libjsconsoleplugin"> +<MenuBar> + <Menu name="tools"><Text>&Tools</Text> + <Action name="jsconsole"/> + </Menu> +</MenuBar> +<ToolBar name="extraToolBar"> + <Action name="jsconsole"/> +</ToolBar> +</kpartplugin> diff --git a/kjsembed/plugins/Makefile.am b/kjsembed/plugins/Makefile.am new file mode 100644 index 00000000..f3071bb2 --- /dev/null +++ b/kjsembed/plugins/Makefile.am @@ -0,0 +1,38 @@ +INCLUDES= -I$(srcdir)/.. -I$(srcdir)/../.. $(all_includes) +KDE_CXXFLAGS = -DQT_NO_ASCII_CAST -DQT_CLEAN_NAMESPACE + +kde_module_LTLIBRARIES = libcustomobjectplugin.la libcustomqobjectplugin.la \ + libimagefxplugin.la libqprocessplugin.la libfileitemplugin.la +METASOURCES = AUTO + +# the Plugin's source, library search path, and link libraries +libcustomobjectplugin_la_SOURCES = customobject_plugin.cpp +libcustomobjectplugin_la_LDFLAGS = -module $(KDE_PLUGIN) $(KDE_RPATH) $(all_libraries) +libcustomobjectplugin_la_LIBADD = $(LIB_QT) $(LIB_KPARTS) $(LIB_KDECORE) $(LIB_KFILE) ../libkjsembed.la + +# the Plugin's source, library search path, and link libraries +libcustomqobjectplugin_la_SOURCES = customqobject_plugin.cpp +libcustomqobjectplugin_la_LDFLAGS = -module $(KDE_PLUGIN) $(KDE_RPATH) $(all_libraries) +libcustomqobjectplugin_la_LIBADD = $(LIB_QT) $(LIB_KPARTS) $(LIB_KDECORE) $(LIB_KFILE) ../libkjsembed.la + +# the Plugin's source, library search path, and link libraries +libimagefxplugin_la_SOURCES = imagefx_plugin.cpp +libimagefxplugin_la_LDFLAGS = -module $(KDE_PLUGIN) $(KDE_RPATH) $(all_libraries) +libimagefxplugin_la_LIBADD = $(LIB_QT) $(LIB_KPARTS) $(LIB_KDECORE) $(LIB_KFILE) ../libkjsembed.la + +# the Plugin's source, library search path, and link libraries +libqprocessplugin_la_SOURCES = qprocess_plugin.cpp +libqprocessplugin_la_LDFLAGS = -module $(KDE_PLUGIN) $(KDE_RPATH) $(all_libraries) +libqprocessplugin_la_LIBADD = $(LIB_QT) $(LIB_KPARTS) $(LIB_KDECORE) $(LIB_KFILE) ../libkjsembed.la + +# the Plugin's source, library search path, and link libraries +libfileitemplugin_la_SOURCES = kfileitemloader.cpp +libfileitemplugin_la_LDFLAGS = -module $(KDE_PLUGIN) $(all_libraries) +libfileitemplugin_la_LIBADD = $(LIB_KPARTS) $(LIB_KFILE) ../libkjsembed.la + + +# this is where the desktop file will go +plugindesktopdir = $(kde_servicesdir) +plugindesktop_DATA = customobject_plugin.desktop customqobject_plugin.desktop imagefx_plugin.desktop\ + qprocess_plugin.desktop kfileitem_plugin.desktop + diff --git a/kjsembed/plugins/customobject_plugin.cpp b/kjsembed/plugins/customobject_plugin.cpp new file mode 100644 index 00000000..7c188cba --- /dev/null +++ b/kjsembed/plugins/customobject_plugin.cpp @@ -0,0 +1,183 @@ +// -*- c++ -*- + +/* + * Copyright (C) 2003, Ian Reinhart Geiser <geiseri@kde.org> + * + * This 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. + * + * This 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 this library; see the file COPYING.LIB. If not, write to + * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, + * Boston, MA 02110-1301, USA. + */ + +#include <kdebug.h> +#include <kjsembed/jsopaqueproxy.h> +#include <kjsembed/jsbinding.h> +#include <kjsembed/jsfactory.h> +#include <kjsembed/jsfactory_imp.h> +#include <kjsembed/kjsembedpart.h> +#include <kjsembed/customobject_imp.h> +#include <qvariant.h> +#include <qbrush.h> + +#include "customobject_plugin.h" + +namespace KJSEmbed { +namespace Bindings { + +class MyCustomObject +{ + public: + enum Mode { On, Off }; + Mode mode; + QString thing; +}; + +MyCustomObjectLoader::MyCustomObjectLoader( QObject *parent, const char *name, const QStringList &args ) : + JSBindingPlugin(parent, name, args) +{ +} + +KJS::Object MyCustomObjectLoader::createBinding(KJSEmbedPart */*jspart*/, KJS::ExecState *exec, const KJS::List &/*args*/) const +{ + kdDebug() << "Loading a custom object" << endl; + MyCustomObject *obj = new MyCustomObject(); + JSOpaqueProxy *prx = new JSOpaqueProxy( (void *) obj, "MyCustomObject" ); + + KJS::Object proxyObj(prx); + MyCustomObjectImp::addBindings( exec, proxyObj ); + return proxyObj; +} + +MyCustomObjectImp::MyCustomObjectImp( KJS::ExecState *exec, int id ) + : JSProxyImp(exec), mid(id) +{ +} + +MyCustomObjectImp::~MyCustomObjectImp() +{ +} + +void MyCustomObjectImp::addBindings( KJS::ExecState *exec, KJS::Object &object ) { + + kdDebug() << "MyCustomObjectImp::addBindings()" << endl; + JSOpaqueProxy *op = JSProxy::toOpaqueProxy( object.imp() ); + if ( !op ) { + kdWarning() << "MyCustomObjectImp::addBindings() failed, not a JSOpaqueProxy" << endl; + return; + } + + if ( op->typeName() != "MyCustomObject" ) { + kdWarning() << "MyCustomObjectImp::addBindings() failed, type is " << op->typeName() << endl; + return; + } + + JSProxy::MethodTable methods[] = { + { Methodmode, "mode"}, + { MethodsetMode, "setMode"}, + { Methodthing, "thing"}, + { MethodsetThing, "setThing"}, + { 0, 0 } + }; + + int idx = 0; + do { + MyCustomObjectImp *meth = new MyCustomObjectImp( exec, methods[idx].id ); + object.put( exec , methods[idx].name, KJS::Object(meth) ); + ++idx; + } while( methods[idx].id ); + + // + // Define the enum constants + // + struct EnumValue { + const char *id; + int val; + }; + + EnumValue enums[] = { + // MyCustomObject::mode + { "On", 0 }, + { "Off", 1 }, + { 0, 0 } + }; + + int enumidx = 0; + do { + object.put( exec, enums[enumidx].id, KJS::Number(enums[enumidx].val), KJS::ReadOnly ); + ++enumidx; + } while( enums[enumidx].id ); +} + +KJS::Value MyCustomObjectImp::call( KJS::ExecState *exec, KJS::Object &self, const KJS::List &args ) { + + kdDebug() << "MyCustomObjectImp::call() " << mid << endl; + JSOpaqueProxy *op = JSProxy::toOpaqueProxy( self.imp() ); + if ( !op ) { + kdWarning() << "MyCustomObjectImp::call() failed, not a JSOpaqueProxy" << endl; + return KJS::Value(); + } + + if ( op->typeName() != "MyCustomObject" ) { + kdWarning() << "MyCustomObjectImp::call() failed, type is " << op->typeName() << endl; + return KJS::Value(); + } + + MyCustomObject *obj = op->toNative<MyCustomObject>(); + + KJS::Value retValue = KJS::Value(); + switch ( mid ) { + case Methodthing: + { + retValue = KJS::String(obj->thing); + break; + } + case MethodsetThing: + { + obj->thing = extractString(exec, args, 0); + break; + } + case Methodmode: + { + retValue = KJS::Number( (int)obj->mode ); + break; + } + case MethodsetMode: + { + obj->mode = (MyCustomObject::Mode) extractInt(exec, args, 0); + break; + } + default: + kdWarning() << "MyCustomObject has no method " << mid << endl; + break; + } + + op->setValue((void*) obj, "MyCustomObject"); + return retValue; +} + + +int MyCustomObjectImp::extractInt( KJS::ExecState *exec, const KJS::List &args, int idx) +{ + return (args.size() > idx) ? args[idx].toInteger(exec) : 0; +} +QString MyCustomObjectImp::extractString(KJS::ExecState *exec, const KJS::List &args, int idx) +{ + return (args.size() > idx) ? args[idx].toString(exec).qstring() : QString::null; +} + +} // namespace KJSEmbed::Bindings +} // namespace KJSEmbed + +#include <kgenericfactory.h> +typedef KGenericFactory<KJSEmbed::Bindings::MyCustomObjectLoader> MyCustomObjectLoaderFactory; +K_EXPORT_COMPONENT_FACTORY( libcustomobjectplugin, MyCustomObjectLoaderFactory( "MyCustomObjectLoader" ) ) diff --git a/kjsembed/plugins/customobject_plugin.desktop b/kjsembed/plugins/customobject_plugin.desktop new file mode 100644 index 00000000..129e8639 --- /dev/null +++ b/kjsembed/plugins/customobject_plugin.desktop @@ -0,0 +1,5 @@ +[Desktop Entry] +Name=MyCustomObject +ServiceTypes=JSBindingPlugin/Binding +Type=Service +X-KDE-Library=libcustomobjectplugin diff --git a/kjsembed/plugins/customobject_plugin.h b/kjsembed/plugins/customobject_plugin.h new file mode 100644 index 00000000..2cea3415 --- /dev/null +++ b/kjsembed/plugins/customobject_plugin.h @@ -0,0 +1,68 @@ +// -*- c++ -*- + +/* + * Copyright (C) 2003, Richard J. Moore <rich@kde.org> + * + * This 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. + * + * This 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 this library; see the file COPYING.LIB. If not, write to + * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, + * Boston, MA 02110-1301, USA. + */ + +#ifndef KJSEMBED_CUSTOMOBJECT_PLUGIN_H +#define KJSEMBED_CUSTOMOBJECT_PLUGIN_H + +#include <kjsembed/jsbindingplugin.h> +#include <kjsembed/jsproxy_imp.h> + +namespace KJSEmbed { +namespace Bindings { + +class KJSEMBED_EXPORT MyCustomObjectLoader : public JSBindingPlugin +{ +public: + MyCustomObjectLoader( QObject *parent, const char *name, const QStringList &args ); + KJS::Object createBinding(KJSEmbedPart *jspart, KJS::ExecState *exec, const KJS::List &args) const; +}; + + +class MyCustomObjectImp : public JSProxyImp { + + /** Identifiers for the methods provided by this class. */ + enum MethodId { Methodmode, MethodsetMode, Methodthing, MethodsetThing }; + +public: + MyCustomObjectImp( KJS::ExecState *exec, int id ); + virtual ~MyCustomObjectImp(); + + static void addBindings( KJS::ExecState *exec, KJS::Object &object ); + + /** Returns true iff this object implements the call function. */ + virtual bool implementsCall() const { + return true; + } + + /** Invokes the call function. */ + virtual KJS::Value call( KJS::ExecState *exec, KJS::Object &self, const KJS::List &args ); + + +private: + int extractInt( KJS::ExecState *exec, const KJS::List &args, int idx); + QString extractString(KJS::ExecState *exec, const KJS::List &args, int idx); + int mid; +}; + +} // namespace +} // namespace + +#endif // KJSEMBED_IMAGE_IMP_H diff --git a/kjsembed/plugins/customqobject_plugin.cpp b/kjsembed/plugins/customqobject_plugin.cpp new file mode 100644 index 00000000..f8c45a60 --- /dev/null +++ b/kjsembed/plugins/customqobject_plugin.cpp @@ -0,0 +1,96 @@ +// -*- c++ -*- + +/* + * Copyright (C) 2003, Ian Reinhart Geiser <geiseri@kde.org> + * + * This 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. + * + * This 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 this library; see the file COPYING.LIB. If not, write to + * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, + * Boston, MA 02110-1301, USA. + */ + +#include <kdebug.h> +#include <kjsembed/jsobjectproxy.h> +#include <kjsembed/jsbinding.h> +#include <kjsembed/kjsembedpart.h> +#include <kjsembed/customobject_imp.h> +#include <qvariant.h> + + +#include "customqobject_plugin.h" + +namespace KJSEmbed { +namespace Bindings { + +MyCustomQObjectLoader::MyCustomQObjectLoader( QObject *parent, const char *name, const QStringList &args ) : + JSBindingPlugin(parent, name, args) +{ +} + +KJS::Object MyCustomQObjectLoader::createBinding(KJSEmbedPart *jspart, KJS::ExecState *exec, const KJS::List &args) const +{ + kdDebug() << "Loading a custom object" << endl; + + QObject *parent = 0L; + JSObjectProxy *proxy = JSProxy::toObjectProxy( args[0].imp() ); + if ( proxy ) + parent = proxy->object(); + MyCustomQObjectImp *imp = new MyCustomQObjectImp(parent, "MyCustomQObject" ); + JSObjectProxy *prx = new JSObjectProxy( jspart, imp ); + + KJS::Object proxyObj( prx ); + prx->addBindings( exec, proxyObj ); + CustomObjectImp::addBindings( exec, proxyObj ); + return proxyObj; +} + +MyCustomQObjectImp::MyCustomQObjectImp(QObject *parent, const char *name ) + : QObject(parent, name) +{ + kdDebug() << "New MyCustomQObjectImp " << endl; +} + +MyCustomQObjectImp::~MyCustomQObjectImp() +{ +} + +MyCustomQObjectImp::Mode MyCustomQObjectImp::mode() const +{ + kdDebug() << "mode() " << endl; + return m_mode; +} +void MyCustomQObjectImp::setMode( Mode md) +{ + kdDebug() << "setMode() " << endl; + m_mode = md; +} +QString MyCustomQObjectImp::thing() const +{ + kdDebug() << "thing()" << endl; + return m_thing; +} +void MyCustomQObjectImp::setThing( const QString &t) +{ + kdDebug() << "setThing() " << t << endl; + m_thing = t; +} +} // namespace KJSEmbed::Bindings +} // namespace KJSEmbed + + +#include <kgenericfactory.h> +typedef KGenericFactory<KJSEmbed::Bindings::MyCustomQObjectLoader> MyCustomQObjectLoaderFactory; +K_EXPORT_COMPONENT_FACTORY( libcustomqobjectplugin, MyCustomQObjectLoaderFactory( "MyCustomQObjectLoader" ) ) + + +#include "customqobject_plugin.moc" diff --git a/kjsembed/plugins/customqobject_plugin.desktop b/kjsembed/plugins/customqobject_plugin.desktop new file mode 100644 index 00000000..6be09b1b --- /dev/null +++ b/kjsembed/plugins/customqobject_plugin.desktop @@ -0,0 +1,5 @@ +[Desktop Entry] +Name=MyCustomQObject +ServiceTypes=JSBindingPlugin/Binding +Type=Service +X-KDE-Library=libcustomqobjectplugin diff --git a/kjsembed/plugins/customqobject_plugin.h b/kjsembed/plugins/customqobject_plugin.h new file mode 100644 index 00000000..bd419b59 --- /dev/null +++ b/kjsembed/plugins/customqobject_plugin.h @@ -0,0 +1,68 @@ +// -*- c++ -*- + +/* + * Copyright (C) 2003, Richard J. Moore <rich@kde.org> + * + * This 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. + * + * This 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 this library; see the file COPYING.LIB. If not, write to + * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, + * Boston, MA 02110-1301, USA. + */ + +#ifndef KJSEMBED_CUSTOMQOBJECT_PLUGIN_H +#define KJSEMBED_CUSTOMQOBJECT_PLUGIN_H + +#include <kjsembed/jsbindingplugin.h> +#include <kjsembed/jsproxy_imp.h> +#include <qobject.h> + +namespace KJSEmbed { +namespace Bindings { + +class MyCustomQObjectLoader : public JSBindingPlugin +{ +public: + MyCustomQObjectLoader( QObject *parent, const char *name, const QStringList &args ); + virtual ~MyCustomQObjectLoader(){;} + KJS::Object createBinding(KJSEmbedPart *jspart, KJS::ExecState *exec, const KJS::List &args) const; +}; + + +class MyCustomQObjectImp : public QObject { + +Q_OBJECT + + /** Identifiers for the methods provided by this class. */ + enum Mode { On, Off }; + Q_PROPERTY(Mode mode READ mode WRITE setMode) + Q_PROPERTY(QString thing READ thing WRITE setThing) + Q_ENUMS(Mode) +public: + MyCustomQObjectImp( QObject *parent, const char *name); + virtual ~MyCustomQObjectImp(); + +public slots: + Mode mode() const; + void setMode( Mode md); + QString thing() const; + void setThing( const QString &t); +private: + Mode m_mode; + QString m_thing; + +}; + +} // namespace +} // namespace + +#endif // KJSEMBED_IMAGE_IMP_H diff --git a/kjsembed/plugins/imagefx_plugin.cpp b/kjsembed/plugins/imagefx_plugin.cpp new file mode 100644 index 00000000..903c7655 --- /dev/null +++ b/kjsembed/plugins/imagefx_plugin.cpp @@ -0,0 +1,858 @@ +// -*- c++ -*- + +/* + * Copyright (C) 2003, Ian Reinhart Geiser <geiseri@kde.org> + * + * This 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. + * + * This 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 this library; see the file COPYING.LIB. If not, write to + * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, + * Boston, MA 02110-1301, USA. + */ + +#include <kdebug.h> +#include <kglobal.h> +#include <kjsembed/jsopaqueproxy.h> +#include <kjsembed/jsbinding.h> +#include <kjsembed/jsfactory.h> +#include <kjsembed/jsfactory_imp.h> +#include <kjsembed/kjsembedpart.h> +#include <kjsembed/customobject_imp.h> +#include <qvariant.h> +#include <qbrush.h> + +#include "imagefx_plugin.h" + +namespace KJSEmbed { +namespace Bindings { + + +ImageFXLoader::ImageFXLoader( QObject *parent, const char *name, const QStringList &args ) : + JSBindingPlugin(parent, name, args) +{ +} + +KJS::Object ImageFXLoader::createBinding(KJSEmbedPart */*jspart*/, KJS::ExecState *exec, const KJS::List &/*args*/) const +{ + kdDebug() << "Loading a ImageFX object" << endl; + JSOpaqueProxy *prx = new JSOpaqueProxy( (int*)0, "ImageFX" ); + + KJS::Object proxyObj(prx); + ImageFX::addBindings( exec, proxyObj ); + return proxyObj; +} + +ImageFX::ImageFX( KJS::ExecState *exec, int id ) + : JSProxyImp(exec), mid(id) +{ +} + +ImageFX::~ImageFX() +{ +} + +void ImageFX::addBindings( KJS::ExecState *exec, KJS::Object &object ) { + + kdDebug() << "ImageFX::addBindings()" << endl; + JSOpaqueProxy *op = JSProxy::toOpaqueProxy( object.imp() ); + if ( !op ) { + kdWarning() << "ImageFX::addBindings() failed, not a JSOpaqueProxy" << endl; + return; + } + + if ( op->typeName() != "ImageFX" ) { + kdWarning() << "ImageFX::addBindings() failed, type is " << op->typeName() << endl; + return; + } + + JSProxy::MethodTable methods[] = { + { Methodgradient, "gradient" }, + { MethodunbalancedGradient, "unbalancedGradient" }, + { MethodblendColor, "blendColor" }, + { MethodblendImage, "blendImage" }, + { MethodcomputeDestinationRect, "computeDestinationRect" }, + { MethodchannelIntensity, "channelIntensity" }, + { Methodfade, "fade" }, + { Methodflatten, "flatten" }, + { Methodhash, "hash" }, + { Methodintensity, "intensity" }, + { Methodmodulate, "modulate" }, + { MethodtoGray, "toGray" }, + { Methoddesaturate, "desaturate" }, + { Methoddither, "dither" }, + { MethodselectedImage, "selectedImage" }, + { MethodcontrastHSV, "contrastHSV" }, + { Methodnormalize, "normalize" }, + { Methodequalize, "equalize" }, + { Methodthreshold, "threshold" }, + { Methodsolarize, "solarize" }, + { Methodemboss, "emboss" }, + { Methoddespeckle, "despeckle" }, + { Methodcharcoal, "charcoal" }, + { Methodcharcoal2, "charcoal2" }, + { Methodrotate, "rotate" }, + { Methodsample, "sample" }, + { MethodaddNoise, "addNoise" }, + { Methodblur, "blur" }, + { Methodedge, "edge" }, + { Methodimplode, "implode" }, + { MethodoilPaintConvolve, "oilPaintConvolve" }, + { MethodoilPaint, "MethodoilPaint" }, + { Methodsharpen, "sharpen" }, + { Methodsharpen2, "sharpen2" }, + { Methodspread, "spread" }, + { Methodshade, "shade" }, + { Methodswirl, "swirl" }, + { Methodwave, "wave" }, + { Methodcontrast, "contrast" }, + { MethodbumpMap, "bumpmap" }, + { 0, 0 } + }; + + int idx = 0; + do { + ImageFX *meth = new ImageFX( exec, methods[idx].id ); + object.put( exec , methods[idx].name, KJS::Object(meth) ); + ++idx; + } while( methods[idx].id ); + + // + // Define the enum constants + // + struct EnumValue { + const char *id; + int val; + }; + + EnumValue enums[] = { + // GradiantType + { "VerticalGradient", 0 }, + { "HorizontalGradient", 1 }, + { "DiagonalGradient", 2 }, + { "CrossDiagonalGradient", 3 }, + { "PyramidGradient", 4 }, + { "RectangleGradient", 5 }, + { "PipeCrossGradient", 6 }, + { "EllipticGradient", 7 }, + // RGBComponent + { "Red", 0 }, + { "Green", 1 }, + { "Blue", 2 }, + { "Gray", 3 }, + { "All", 4 }, + // Lighting + { "NorthLite", 0 }, + { "NWLite", 1 }, + { "WestLite", 2 }, + { "SWLite", 3 }, + { "SouthLite", 4 }, + { "SELite", 5 }, + { "EastLite", 6 }, + { "NELite", 7 }, + // ModulationType + { "Intensity", 0 }, + { "Saturation", 1 }, + { "HueShift", 2 }, + { "Contrast", 3 }, + // NoiseType + { "UniformNoise", 0 }, + { "GaussianNoise", 1 }, + { "MultiplicativeGaussianNoise", 2 }, + { "ImpulseNoise", 3 }, + { "LaplacianNoise", 4 }, + { "PoissonNoise", 5 }, + // RotateDirection + { "Rotate90", 0 }, + { "Rotate180", 1 }, + { "Rotate270", 2 }, + // BumpmapType + { "Linear", 0}, + { "Spherical", 1}, + { "Sinuosidal", 2}, + { 0, 0 } + }; + + int enumidx = 0; + do { + object.put( exec, enums[enumidx].id, KJS::Number(enums[enumidx].val), KJS::ReadOnly ); + ++enumidx; + } while( enums[enumidx].id ); +} + +KJS::Value ImageFX::call( KJS::ExecState *exec, KJS::Object &self, const KJS::List &args ) { + + kdDebug() << "ImageFX::call() " << mid << endl; + JSOpaqueProxy *op = JSProxy::toOpaqueProxy( self.imp() ); + if ( !op ) { + kdWarning() << "ImageFX::call() failed, not a JSOpaqueProxy" << endl; + return KJS::Value(); + } + + if ( op->typeName() != "ImageFX" ) { + kdWarning() << "ImageFX::call() failed, type is " << op->typeName() << endl; + return KJS::Value(); + } + + + KJS::Value retValue = KJS::Value(); + switch ( mid ) { + case Methodgradient: { + QSize size = extractQSize(exec, args, 0); + QColor ca = extractQColor(exec, args, 1); + QColor cb = extractQColor(exec, args, 2); + int type = extractInt( exec, args, 3); + int ncols = extractInt( exec, args, 4); + QImage img = KImageEffect::gradient(size, ca, cb, (KImageEffect::GradientType)type, ncols); + retValue = convertToValue(exec, img); + break; + } + case MethodunbalancedGradient: { + QSize size = extractQSize(exec, args, 0); + QColor ca = extractQColor(exec, args, 1); + QColor cb = extractQColor(exec, args, 2); + int type = extractInt( exec, args, 3); + int xfactor = extractInt( exec, args, 4); + int yfactor = extractInt( exec, args, 5); + int ncols = extractInt( exec, args, 6); + QImage img = KImageEffect::unbalancedGradient(size, ca, cb, (KImageEffect::GradientType)type, xfactor, yfactor, ncols); + retValue = convertToValue(exec, img); + break; + } + case MethodblendColor: { + QColor clr = extractQColor(exec, args, 0); + QImage dst = extractQImage(exec, args, 1); + float opacity = (float)extractDouble(exec, args, 2); + QImage img = KImageEffect::blend(clr, dst, opacity); + retValue = convertToValue(exec, img); + break; + } + case MethodblendImage: { + QImage src = extractQImage(exec, args, 0); + QImage dst = extractQImage(exec, args, 1); + float opacity = (float)extractDouble(exec, args, 2); + QImage img = KImageEffect::blend(src, dst, opacity); + retValue = convertToValue(exec, img); + break; + } + case MethodcomputeDestinationRect: { + QSize lowerSize = extractQSize(exec, args, 0); + int disposition = extractInt(exec, args, 1); + QImage upper = extractQImage(exec, args, 2); + QRect rect = KImageEffect::computeDestinationRect(lowerSize, (KImageEffect::Disposition) disposition, upper); + retValue = convertToValue(exec, rect); + break; + } + case MethodchannelIntensity: { + QImage image = extractQImage(exec, args, 0); + float percent = (float)extractDouble(exec, args, 1); + int channel = extractInt(exec, args, 2); + QImage img = KImageEffect::channelIntensity(image, percent, (KImageEffect::RGBComponent)channel); + retValue = convertToValue(exec, img); + break; + } + case Methodfade: { + QImage image = extractQImage(exec, args, 0); + float val = (float)extractDouble(exec, args, 1); + QColor color = extractQColor(exec, args, 2); + QImage img = KImageEffect::fade(image, val, color); + retValue = convertToValue(exec, img); + break; + } + case Methodflatten: { + QImage image = extractQImage(exec, args, 0); + QColor ca = extractQColor(exec, args, 1); + QColor cb = extractQColor(exec, args, 2); + int ncols = extractInt(exec, args, 3); + QImage img = KImageEffect::flatten(image, ca, cb, ncols); + retValue = convertToValue(exec, img); + break; + } + case Methodhash: { + + QImage image = extractQImage(exec, args, 0); + int lite = extractInt(exec, args, 1); + int spacing = extractInt(exec, args, 2); + QImage img = KImageEffect::hash(image, (KImageEffect::Lighting)lite, spacing); + retValue = convertToValue(exec, img); + break; + } + case Methodintensity: { + + QImage image = extractQImage(exec, args, 0); + float percent = (float)extractDouble(exec, args, 1); + QImage img = KImageEffect::intensity(image, percent); + retValue = convertToValue(exec, img); + break; + } + case Methodmodulate: { + QImage image = extractQImage(exec, args, 0); + QImage modImage = extractQImage(exec, args, 0); + bool reverse = extractBool(exec, args, 1); + int type = extractInt(exec, args, 2); + int factor = extractInt(exec, args, 3); + int channel = extractInt(exec, args, 4); + QImage img = KImageEffect::modulate(image, modImage, reverse, (KImageEffect::ModulationType)type, factor, (KImageEffect::RGBComponent)channel); + retValue = convertToValue(exec, img); + break; + } + + case MethodtoGray: { + QImage image = extractQImage(exec, args, 0); + bool fast = extractBool(exec, args, 1); + QImage img = KImageEffect::toGray(image, fast); + retValue = convertToValue(exec, img); + break; + } + case Methoddesaturate: { + QImage image = extractQImage(exec, args, 0); + float desat = (float)extractDouble(exec, args, 1); + QImage img = KImageEffect::desaturate(image, desat); + retValue = convertToValue(exec, img); + break; + } + case Methoddither: { + + //dither( palette, size) + break; + } + case MethodselectedImage: { + + QImage image = extractQImage(exec, args, 0); + QColor col = extractQColor(exec, args, 1); + QImage img = KImageEffect::selectedImage(image, col); + retValue = convertToValue(exec, img); + break; + } + case MethodcontrastHSV: { + QImage image = extractQImage(exec, args, 0); + bool sharpen = extractBool(exec, args, 1); + KImageEffect::contrastHSV(image, sharpen); + retValue = convertToValue(exec, image); + break; + } + case Methodnormalize: { + QImage image = extractQImage(exec, args, 0); + KImageEffect::normalize(image); + retValue = convertToValue(exec, image); + break; + } + case Methodequalize: { + QImage image = extractQImage(exec, args, 0); + KImageEffect::equalize(image); + retValue = convertToValue(exec, image); + break; + } + case Methodthreshold: { + QImage image = extractQImage(exec, args, 0); + uint value = extractUInt(exec, args, 1); + KImageEffect::threshold(image, value); + retValue = convertToValue(exec, image); + break; + } + case Methodsolarize: { + QImage image = extractQImage(exec, args, 0); + double factor = extractDouble(exec, args, 1); + KImageEffect::solarize(image, factor); + retValue = convertToValue(exec, image); + break; + } + case Methodemboss: { + QImage image = extractQImage(exec, args, 0); + double radius = extractDouble(exec, args, 1); + double sigma = extractDouble(exec, args, 2); + QImage img = KImageEffect::emboss(image, radius, sigma); + retValue = convertToValue(exec, img); + break; + } + case Methoddespeckle: { + QImage image = extractQImage(exec, args, 0); + QImage img = KImageEffect::despeckle(image); + retValue = convertToValue(exec, img); + break; + } + case Methodcharcoal: { + QImage image = extractQImage(exec, args, 0); + double factor = extractDouble(exec, args, 1); + QImage img = KImageEffect::charcoal( image, factor); + retValue = convertToValue(exec, img); + break; + } + case Methodcharcoal2: { + QImage image = extractQImage(exec, args, 0); + double radius = extractDouble(exec, args, 1); + double sigma = extractDouble(exec, args, 2); + QImage img = KImageEffect::charcoal(image, radius, sigma); + retValue = convertToValue(exec, img); + break; + } + case Methodrotate: { + QImage image = extractQImage(exec, args, 0); + int r = extractInt(exec, args, 1); + QImage img = KImageEffect::rotate(image, (KImageEffect::RotateDirection) r); + retValue = convertToValue(exec, img); + break; + } + case Methodsample: { + QImage image = extractQImage(exec, args, 0); + int width = extractInt(exec, args, 1); + int height = extractInt(exec, args, 2); + QImage img = KImageEffect::sample(image, width, height); + retValue = convertToValue(exec, img); + break; + } + case MethodaddNoise: { + QImage image = extractQImage(exec, args, 0); + int type = extractInt(exec, args, 1); + QImage img = KImageEffect::addNoise(image, (KImageEffect::NoiseType) type); + retValue = convertToValue(exec, img); + break; + } + case Methodblur: { + QImage image = extractQImage(exec, args, 0); + double radius = extractDouble(exec, args, 1); + double sigma = extractDouble(exec, args, 2); + QImage img = KImageEffect::blur(image, radius, sigma); + retValue = convertToValue(exec, img); + break; + } + case Methodedge: { + QImage image = extractQImage(exec, args, 0); + double radius = extractDouble(exec, args, 1); + QImage img = KImageEffect::edge(image, radius); + retValue = convertToValue(exec, img); + break; + } + case Methodimplode: { + QImage image = extractQImage(exec, args, 0); + double factor = extractDouble(exec, args, 1); + uint background = extractUInt(exec, args, 2); + QImage img = KImageEffect::implode(image, factor, background); + retValue = convertToValue(exec, img); + break; + } + case MethodoilPaintConvolve: { + QImage image = extractQImage(exec, args, 0); + double radius = extractDouble(exec, args, 1); + QImage img = KImageEffect::oilPaintConvolve(image, radius); + retValue = convertToValue(exec, img); + break; + } + case MethodoilPaint: { + QImage image = extractQImage(exec, args, 0); + int radius = extractInt(exec, args, 1); + QImage img = KImageEffect::oilPaint(image, radius); + retValue = convertToValue(exec, img); + break; + } + + + case Methodsharpen: { + QImage image = extractQImage(exec, args, 0); + double factor = extractDouble(exec, args, 1); + QImage img = KImageEffect::sharpen(image, factor); + retValue = convertToValue(exec, img); + break; + } + case Methodsharpen2: { + QImage image = extractQImage(exec, args, 0); + double radius = extractDouble(exec, args, 1); + double sigma = extractDouble(exec, args, 2); + QImage img = KImageEffect::sharpen(image, radius, sigma); + retValue = convertToValue(exec, img); + break; + } + case Methodspread: { + QImage image = extractQImage(exec, args, 0); + uint amount = extractUInt(exec, args, 1); + QImage img = KImageEffect::spread(image, amount); + retValue = convertToValue(exec, img); + break; + } + case Methodshade: { + QImage image = extractQImage(exec, args, 0); + bool color_shading = extractBool(exec, args, 1); + double azimuth = extractDouble(exec, args, 2); + double elevation = extractDouble(exec, args, 3); + QImage img = KImageEffect::shade(image, color_shading, azimuth, elevation); + retValue = convertToValue(exec, img); + break; + } + case Methodswirl: { + QImage image = extractQImage(exec, args, 0); + double degrees = extractDouble(exec, args, 1); + uint background = extractUInt(exec, args, 2); + QImage img = KImageEffect::swirl(image, degrees, background); + retValue = convertToValue(exec, img); + break; + } + case Methodwave: { + QImage image = extractQImage(exec, args, 0); + double amplitude = extractDouble(exec, args, 1); + double frequency = extractDouble(exec, args, 2); + uint background = extractUInt(exec, args, 3); + QImage img = KImageEffect::wave(image, amplitude, frequency, background); + retValue = convertToValue(exec, img); + break; + } + case Methodcontrast: { + QImage image = extractQImage(exec, args, 0); + int c = extractInt(exec, args, 1); + QImage img = KImageEffect::contrast(image, c); + retValue = convertToValue(exec, img); + break; + } + case MethodbumpMap: { + QImage mask = extractQImage(exec, args, 0); + QImage img = bumpmap(img, + mask, + extractDouble(exec, args, 1), + extractDouble(exec, args, 2), + extractInt(exec, args, 3), + extractInt(exec, args, 4), + extractInt(exec, args, 5), + extractInt(exec, args, 6), + extractInt(exec, args, 7), + extractBool(exec, args, 8), + extractBool(exec, args, 9), + (BumpmapType) extractInt(exec, args, 10), + extractBool(exec, args, 11)); + + retValue = convertToValue(exec, img); + break; + } + default: + kdWarning() << "ImageFX has no method " << mid << endl; + break; + } + + return retValue; +} + +/*********************************************************************** + * Here's a pretty fast bumpmap implementation. + * NOTE: remind me to move it to KImageEffects after 3.2. + */ +#define DegreesToRadians(x) ((x)*M_PI/180.0) +#define MOD(x, y) ((x) < 0 ? ((y) - 1 - ((y) - 1 - (x)) % (y)) : (x) % (y)) + +/** + * NOTE: kclamp needs to be moved to kglobals.h along kmin and kmax + */ +#define KCLAMP(x,low,high) kClamp(x,low,high) +template<class T> +inline const T& kClamp( const T& x, const T& low, const T& high ) +{ + if ( x < low ) + return low; + else if ( x > high ) + return high; + else + return x; +} + +static inline unsigned int intensityValue( unsigned int color ) { + return (unsigned int)( (0.299*qRed( color ) + + 0.587*qGreen( color ) + + 0.1140000000000001*qBlue( color ) ) ); +} + +struct BumpmapParams { + BumpmapParams( double bm_azimuth, double bm_elevation, + int bm_depth, BumpmapType bm_type, + bool invert ) { + /* Convert to radians */ + double azimuth = DegreesToRadians( bm_azimuth ); + double elevation = DegreesToRadians( bm_elevation ); + + /* Calculate the light vector */ + lx = (int)( cos(azimuth) * cos(elevation) * 255.0 ); + ly = (int)( sin(azimuth) * cos(elevation) * 255.0 ); + int lz = (int)( sin(elevation) * 255.0 ); + + /* Calculate constant Z component of surface normal */ + int nz = (6 * 255) / bm_depth; + nz2 = nz * nz; + nzlz = nz * lz; + + /* Optimize for vertical normals */ + background = lz; + + /* Calculate darkness compensation factor */ + compensation = sin(elevation); + + /* Create look-up table for map type */ + for (int i = 0; i < 256; i++) + { + double n = 0; + switch (bm_type) + { + case Spherical: + n = i / 255.0 - 1.0; + lut[i] = (int) (255.0 * sqrt(1.0 - n * n) + 0.5); + break; + + case Sinuosidal: + n = i / 255.0; + lut[i] = (int) (255.0 * (sin((-M_PI / 2.0) + M_PI * n) + 1.0) / + 2.0 + 0.5); + break; + + case Linear: + default: + lut[i] = i; + } + + if (invert) + lut[i] = 255 - lut[i]; + } + } + int lx, ly; + int nz2, nzlz; + int background; + double compensation; + uchar lut[256]; +}; + + +static void bumpmap_convert_row( uint *row, + int width, + int bpp, + int has_alpha, + uchar *lut, + int waterlevel ) +{ + uint *p; + + p = row; + + has_alpha = has_alpha ? 1 : 0; + + if (bpp >= 3) + for (; width; width--) + { + if (has_alpha) { + unsigned int idx = (unsigned int)(intensityValue( *row ) + 0.5); + *p++ = lut[(unsigned int) ( waterlevel + + ( ( idx - + waterlevel) * qBlue( *row )) / 255.0 )]; + } else { + unsigned int idx = (unsigned int)(intensityValue( *row ) + 0.5); + *p++ = lut[idx]; + } + + ++row; + } +} + +static void bumpmap_row( uint *src, + uint *dest, + int width, + int bpp, + int has_alpha, + uint *bm_row1, + uint *bm_row2, + uint *bm_row3, + int bm_width, + int bm_xofs, + bool tiled, + bool row_in_bumpmap, + int ambient, + bool compensate, + BumpmapParams *params ) +{ + int xofs1, xofs2, xofs3; + int shade; + int ndotl; + int nx, ny; + int x; + int pbpp; + int tmp; + + if (has_alpha) + pbpp = bpp - 1; + else + pbpp = bpp; + + tmp = bm_xofs; + xofs2 = MOD(tmp, bm_width); + + for (x = 0; x < width; x++) + { + /* Calculate surface normal from bump map */ + + if (tiled || (row_in_bumpmap && + x >= - tmp && x < - tmp + bm_width)) { + if (tiled) { + xofs1 = MOD(xofs2 - 1, bm_width); + xofs3 = MOD(xofs2 + 1, bm_width); + } else { + xofs1 = KCLAMP(xofs2 - 1, 0, bm_width - 1); + xofs3 = KCLAMP(xofs2 + 1, 0, bm_width - 1); + } + nx = (bm_row1[xofs1] + bm_row2[xofs1] + bm_row3[xofs1] - + bm_row1[xofs3] - bm_row2[xofs3] - bm_row3[xofs3]); + ny = (bm_row3[xofs1] + bm_row3[xofs2] + bm_row3[xofs3] - + bm_row1[xofs1] - bm_row1[xofs2] - bm_row1[xofs3]); + } else { + nx = ny = 0; + } + + /* Shade */ + + if ((nx == 0) && (ny == 0)) + shade = params->background; + else { + ndotl = nx * params->lx + ny * params->ly + params->nzlz; + + if (ndotl < 0) + shade = (int)( params->compensation * ambient ); + else { + shade = (int)( ndotl / sqrt(nx * nx + ny * ny + params->nz2) ); + + shade = (int)( shade + KMAX(0.0, (255 * params->compensation - shade)) * + ambient / 255 ); + } + } + + /* Paint */ + + /** + * NOTE: if we want to work with non-32bit images the alpha handling would + * also change + */ + if (compensate) { + int red = (int)((qRed( *src ) * shade) / (params->compensation * 255)); + int green = (int)((qGreen( *src ) * shade) / (params->compensation * 255)); + int blue = (int)((qBlue( *src ) * shade) / (params->compensation * 255)); + int alpha = (int)((qAlpha( *src ) * shade) / (params->compensation * 255)); + ++src; + *dest++ = qRgba( red, green, blue, alpha ); + } else { + int red = qRed( *src ) * shade / 255; + int green = qGreen( *src ) * shade / 255; + int blue = qBlue( *src ) * shade / 255; + int alpha = qAlpha( *src ) * shade / 255; + ++src; + *dest++ = qRgba( red, green, blue, alpha ); + } + + /* Next pixel */ + + if (++xofs2 == bm_width) + xofs2 = 0; + } +} + +/** + * A bumpmapping algorithm. + * + * @param img the image you want bumpmap + * @param map the map used + * @param azimuth azimuth + * @param elevation elevation + * @param depth depth (not the depth of the image, but of the map) + * @param xofs X offset + * @param yofs Y offset + * @param waterlevel level that full transparency should represent + * @param ambient ambient lighting factor + * @param compensate compensate for darkening + * @param invert invert bumpmap + * @param type type of the bumpmap + * + * @return The destination image (dst) containing the result. + * @author Zack Rusin <zack@kde.org> + */ +QImage ImageFX::bumpmap(QImage &img, QImage &map, double azimuth, double elevation, + int depth, int xofs, int yofs, int waterlevel, + int ambient, bool compensate, bool invert, + BumpmapType type, bool tiled) +{ + QImage dst; + + if ( img.depth() != 32 || img.depth() != 32 ) { + qWarning( "Bump-mapping effect works only with 32 bit images"); + return dst; + } + + dst.create( img.width(), img.height(), img.depth() ); + int bm_width = map.width(); + int bm_height = map.height(); + int bm_bpp = map.depth(); + int bm_has_alpha = map.hasAlphaBuffer(); + + int yofs1, yofs2, yofs3; + + if ( tiled ) { + yofs2 = MOD( yofs, bm_height ); + yofs1 = MOD( yofs2 - 1, bm_height); + yofs3 = MOD( yofs2 + 1, bm_height); + } else { + yofs1 = 0; + yofs2 = 0; + yofs3 = KCLAMP( yofs2+1, 0, bm_height - 1 ); + } + + BumpmapParams params( azimuth, elevation, depth, type, invert ); + + uint* bm_row1 = (unsigned int*)map.scanLine( yofs1 ); + uint* bm_row2 = (unsigned int*)map.scanLine( yofs2 ); + uint* bm_row3 = (unsigned int*)map.scanLine( yofs3 ); + + bumpmap_convert_row( bm_row1, bm_width, bm_bpp, bm_has_alpha, params.lut, waterlevel ); + bumpmap_convert_row( bm_row2, bm_width, bm_bpp, bm_has_alpha, params.lut, waterlevel ); + bumpmap_convert_row( bm_row3, bm_width, bm_bpp, bm_has_alpha, params.lut, waterlevel ); + + for (int y = 0; y < img.height(); ++y) + { + int row_in_bumpmap = (y >= - yofs && y < - yofs + bm_height); + + uint* src_row = (unsigned int*)img.scanLine( y ); + uint* dest_row = (unsigned int*)dst.scanLine( y ); + + bumpmap_row( src_row, dest_row, img.width(), img.depth(), img.hasAlphaBuffer(), + bm_row1, bm_row2, bm_row3, bm_width, xofs, + tiled, + row_in_bumpmap, ambient, compensate, + ¶ms ); + + /* Next line */ + + if (tiled || row_in_bumpmap) + { + uint* bm_tmprow = bm_row1; + bm_row1 = bm_row2; + bm_row2 = bm_row3; + bm_row3 = bm_tmprow; + + if (++yofs2 == bm_height) + yofs2 = 0; + + if (tiled) + yofs3 = MOD(yofs2 + 1, bm_height); + else + yofs3 = KCLAMP(yofs2 + 1, 0, bm_height - 1); + + bm_row3 = (unsigned int*)map.scanLine( yofs3 ); + bumpmap_convert_row( bm_row3, bm_width, bm_bpp, bm_has_alpha, + params.lut, waterlevel ); + } + } + return dst; +} + + +} // namespace KJSEmbed::Bindings +} // namespace KJSEmbed + +#include <kgenericfactory.h> +typedef KGenericFactory<KJSEmbed::Bindings::ImageFXLoader> ImageFXLoaderFactory; +K_EXPORT_COMPONENT_FACTORY( libimagefxplugin, ImageFXLoaderFactory( "ImageFXLoader" ) ) diff --git a/kjsembed/plugins/imagefx_plugin.desktop b/kjsembed/plugins/imagefx_plugin.desktop new file mode 100644 index 00000000..36921e3b --- /dev/null +++ b/kjsembed/plugins/imagefx_plugin.desktop @@ -0,0 +1,5 @@ +[Desktop Entry] +Name=ImageFX +ServiceTypes=JSBindingPlugin/Binding +Type=Service +X-KDE-Library=libimagefxplugin diff --git a/kjsembed/plugins/imagefx_plugin.h b/kjsembed/plugins/imagefx_plugin.h new file mode 100644 index 00000000..7acfed44 --- /dev/null +++ b/kjsembed/plugins/imagefx_plugin.h @@ -0,0 +1,130 @@ +// -*- c++ -*- + +/* + * Copyright (C) 2003, Ian Reinhart Geiser <geiseri@kde.org> + * + * This 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. + * + * This 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 this library; see the file COPYING.LIB. If not, write to + * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, + * Boston, MA 02110-1301, USA. + */ + +#ifndef KJSEMBED_IMAGEFX_PLUGIN_H +#define KJSEMBED_IMAGEFX_PLUGIN_H + +#include <kjsembed/jsbindingplugin.h> +#include <kjsembed/jsproxy_imp.h> +#include <kimageeffect.h> + +#include <qimage.h> + +namespace KJSEmbed { +namespace Bindings { + +class ImageFXLoader : public JSBindingPlugin +{ +public: + ImageFXLoader( QObject *parent, const char *name, const QStringList &args ); + KJS::Object createBinding(KJSEmbedPart *jspart, KJS::ExecState *exec, const KJS::List &args) const; +}; +enum BumpmapType { +Linear, +Spherical, +Sinuosidal +}; + +class ImageFX : JSProxyImp +{ + + /** Identifiers for the methods provided by this class. */ + enum MethodId { + // Image effects + Methodgradient, + MethodunbalancedGradient, MethodblendColor,MethodblendImage, + MethodcomputeDestinationRect, MethodchannelIntensity, Methodfade, + Methodflatten, Methodhash, Methodintensity, Methodmodulate, MethodtoGray, + Methoddesaturate, Methoddither, MethodselectedImage, MethodcontrastHSV, + Methodnormalize, Methodequalize, Methodthreshold, Methodsolarize, + Methodemboss, Methoddespeckle, Methodcharcoal, Methodcharcoal2, + Methodrotate, Methodsample, MethodaddNoise, Methodblur, Methodedge, + Methodimplode, MethodoilPaintConvolve, MethodoilPaint, Methodsharpen, + Methodsharpen2, Methodspread, Methodshade, Methodswirl, Methodwave, + Methodcontrast, MethodbumpMap + }; + + public: + ImageFX( KJS::ExecState *exec, int id ); + virtual ~ImageFX(); + + static void addBindings( KJS::ExecState *exec, KJS::Object &object ); + + /** Returns true iff this object implements the call function. */ + virtual bool implementsCall() const { return true; } + + /** Invokes the call function. */ + virtual KJS::Value call( KJS::ExecState *exec, KJS::Object &self, const KJS::List &args ); + + private: + // Image effects + void gradient(const QSize &size, const QColor &ca, const QColor &cb, KImageEffect::GradientType type, int ncols); + void unbalancedGradient(const QSize &size, const QColor &ca,const QColor &cb, KImageEffect::GradientType type, int xfactor,int yfactor, int ncols); + void blendColor(const QColor& clr, float opacity); + void blendImage(QImage& blendImage, float opacity); + QRect computeDestinationRect(const QSize &lowerSize,KImageEffect::Disposition disposition); + + void channelIntensity(float percent,KImageEffect::RGBComponent channel); + void fade(float val, const QColor &color); + void flatten(const QColor &ca,const QColor &cb, int ncols); + void hash(KImageEffect::Lighting lite,uint spacing); + void intensity(float percent); + void modulate(QImage &modImage, bool reverse,KImageEffect::ModulationType type, int factor, KImageEffect::RGBComponent channel); + void toGray(bool fast); + void desaturate(float desat); + void contrast(int c); + void dither(const QColor *palette, int size); + void selectedImage( const QColor &col ); + void contrastHSV( bool sharpen); + void normalize(); + void equalize(); + void threshold( uint value); + void solarize( double factor); + void emboss(double radius, double sigma); + //void emboss(); + void despeckle(); + void charcoal(double radius, double sigma); + void charcoal(double factor); + void rotate(KImageEffect::RotateDirection r); + void sample(int w, int h); + void addNoise(KImageEffect::NoiseType type); + void blur(double radius, double sigma); + void edge(double radius); + void implode(double factor, uint background ); + void oilPaintConvolve(double radius); + void oilPaint(int radius); + void sharpen(double radius, double sigma); + void sharpen(double factor); + void spread(uint amount); + void shade(bool color_shading, double azimuth,double elevation); + void swirl(double degrees, uint background); + void wave(double amplitude, double frequency,uint background); + + QImage bumpmap(QImage &img, QImage &map, double azimuth=135.0, double elevation=45.0, int depth=3, int xofs=0, int yofs=0, int waterlevel=0, int ambient=0, bool compensate=false, bool invert=false, BumpmapType type=Linear, bool tiled=false); + + int mid; +}; + + +} // namespace +} // namespace + +#endif // KJSEMBED_IMAGEFX_PLUGIN_H diff --git a/kjsembed/plugins/kfileitem_plugin.desktop b/kjsembed/plugins/kfileitem_plugin.desktop new file mode 100644 index 00000000..2cdab9aa --- /dev/null +++ b/kjsembed/plugins/kfileitem_plugin.desktop @@ -0,0 +1,5 @@ +[Desktop Entry] +Name=KFileItem +ServiceTypes=JSBindingPlugin/Binding +Type=Service +X-KDE-Library=libfileitemplugin diff --git a/kjsembed/plugins/kfileitemloader.cpp b/kjsembed/plugins/kfileitemloader.cpp new file mode 100644 index 00000000..0972e20a --- /dev/null +++ b/kjsembed/plugins/kfileitemloader.cpp @@ -0,0 +1,223 @@ +/*************************************************************************** + * Copyright (C) 2004 by ian reinhart geiser * + * geiseri@kde.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 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. * + ***************************************************************************/ +#include "kfileitemloader.h" + +#include <kjsembed/jsopaqueproxy.h> +#include <kjsembed/jsbinding.h> +#include <kjsembed/jsfactory.h> +#include <kjsembed/jsfactory_imp.h> +#include <kjsembed/kjsembedpart.h> + +#include <kfileitem.h> +#include <kdebug.h> + +namespace KJSEmbed { +namespace Bindings { + +KFileItemLoader::KFileItemLoader(QObject *parent, const char *name, const QStringList &args) + : JSBindingPlugin(parent, name, args) +{ +} + + +KFileItemLoader::~KFileItemLoader() +{ +} + +KJS::Object KFileItemLoader::createBinding(KJSEmbedPart *jspart, KJS::ExecState *exec, const KJS::List &args) const +{ + kdDebug() << "Loading a KFileItem object" << endl; + JSOpaqueProxy *prx = new JSOpaqueProxy( (void *) 0, "KFileItem" ); + + KJS::Object proxyObj(prx); + KFileItemImp::addBindings( exec, proxyObj ); + return proxyObj; +} + +} // Bindings +} // KJSEmbed + +KJSEmbed::Bindings::KFileItemImp::KFileItemImp( KJS::ExecState * exec, int id ) +: JSProxyImp(exec), mid(id) +{ + +} + +KJSEmbed::Bindings::KFileItemImp::~ KFileItemImp( ) +{ + +} + +void KJSEmbed::Bindings::KFileItemImp::addBindings( KJS::ExecState * exec, KJS::Object & object ) +{ + + JSOpaqueProxy *op = JSProxy::toOpaqueProxy( object.imp() ); + if ( !op ) + { + kdWarning() << "KFileItemImp::addBindings() failed, not a JSOpaqueProxy" << endl; + return; + } + + if ( op->typeName() != "KFileItem" ) + { + kdWarning() << "KFileItemImp::addBindings() failed, type is " << op->typeName() << + endl; + return; + } + + JSProxy::MethodTable methods[] = { + { Methodrefresh, "refresh"}, + { MethodrefreshMimeType, "refreshMimeType"}, + { Methodurl, "url"}, + { MethodsetUrl, "setUrl"}, + { MethodsetName, "setName"}, + { MethodpermissionsString, "permissionsString"}, + { Methoduser, "user"}, + { Methodgroup, "group"}, + { MethodisLink, "isLink"}, + { MethodisDir, "isDir"}, + { MethodisFile, "isFile"}, + { MethodisReadable, "isReadable"}, + { MethodlinkDest, "linkDest"}, + { MethodtimeString, "timeString"}, + { MethodisLocalFile, "isLocalFile"}, + { Methodtext, "text"}, + { Methodname, "name"}, + { MethodmimeType, "mimeType"}, + { MethodisMimeTypeKnown, "isMimeTypeKnown"}, + { MethodmimeComment, "mimeComment"}, + { MethodiconName, "iconName"}, + { Methodpixmap, "pixmap"}, + { Methodoverlays, "overlays"}, + { MethodgetStatusBarInfo, "getStatusBarInfo"}, + { MethodgetToolTipText, "getToolTipText"}, + { Methodrun, "run"}, + { 0, 0 } + }; + + int idx = 0; + do { + KFileItemImp *meth = new KFileItemImp( exec, methods[idx].id ); + object.put( exec , methods[idx].name, KJS::Object(meth) ); + ++idx; + } while( methods[idx].id ); + +} + +KJS::Value KJSEmbed::Bindings::KFileItemImp::call( KJS::ExecState * exec, KJS::Object & self, const KJS::List & args ) +{ + kdDebug() << "KFileItemImp::call() " << mid << endl; + JSOpaqueProxy *op = JSProxy::toOpaqueProxy( self.imp() ); + if ( !op ) { + kdWarning() << "KFileItemImp::call() failed, not a JSOpaqueProxy" << endl; + return KJS::Value(); + } + + if ( op->typeName() != "KFileItem" ) { + kdWarning() << "KFileItemImp::call() failed, type is " << op->typeName() << endl; + return KJS::Value(); + } + + KFileItem *obj = op->toNative<KFileItem >(); + + KJS::Value retValue = KJS::Value(); + switch ( mid ) { + case Methodrefresh: + obj->refresh(); + break; + case MethodrefreshMimeType: + obj->refreshMimeType(); + break; + case Methodurl: + { + QString url = obj->url().url(); + retValue = KJS::String(url); + break; + } + case MethodsetUrl: + { + QString url = extractQString(exec, args, 0); + obj->setURL(url); + break; + } + case MethodsetName: + case MethodpermissionsString: + case Methoduser: + case Methodgroup: + case MethodisLink: + case MethodisDir: + case MethodisFile: + case MethodisReadable: + case MethodlinkDest: + case MethodtimeString: + case MethodisLocalFile: + case Methodtext: + { + retValue = convertToValue(exec, obj->text() ); + break; + } + case Methodname: + case MethodmimeType: + case MethodisMimeTypeKnown: + case MethodmimeComment: + case MethodiconName: + { + retValue = convertToValue( exec, obj->iconName() ); + break; + } + case Methodpixmap: + { + int size = extractInt(exec, args, 0); + int state = extractInt(exec, args, 1); + retValue = convertToValue(exec, obj->pixmap(size, state)); + break; + } + case Methodoverlays: + { + retValue = convertToValue(exec, obj->overlays()); + break; + } + case MethodgetStatusBarInfo: + { + retValue = KJS::String( obj->getStatusBarInfo() ); + break; + } + case MethodgetToolTipText: + { + int maxcount = extractInt(exec, args, 0); + retValue = KJS::String(obj->getToolTipText(maxcount)); + break; + } + case Methodrun: + obj->run(); + break; + default: + kdWarning() << "KFileItemImp has no method " << mid << endl; + break; + } + + op->setValue((void*) obj, "KFileItem"); + return retValue; + +} + +#include <kgenericfactory.h> +typedef KGenericFactory<KJSEmbed::Bindings::KFileItemLoader> KFileItemLoaderFactory; +K_EXPORT_COMPONENT_FACTORY( libfileitemplugin, KFileItemLoaderFactory( "KFileItemLoader" ) ) diff --git a/kjsembed/plugins/kfileitemloader.h b/kjsembed/plugins/kfileitemloader.h new file mode 100644 index 00000000..bca77dc5 --- /dev/null +++ b/kjsembed/plugins/kfileitemloader.h @@ -0,0 +1,69 @@ +/*************************************************************************** + * Copyright (C) 2004 by ian reinhart geiser * + * geiseri@kde.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 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. * + ***************************************************************************/ +#ifndef KFILEITEMLOADER_H +#define KFILEITEMLOADER_H + +#include <kjsembed/jsbindingplugin.h> +#include <kjsembed/jsproxy_imp.h> + +/** +Loader for the KFileItem wrapper. This is automaticly invoked from the jsfactory. + +@author ian reinhart geiser +*/ +namespace KJSEmbed { +namespace Bindings { + +class KFileItemLoader : public JSBindingPlugin +{ +public: + KFileItemLoader(QObject *parent, const char *name, const QStringList &args); + + ~KFileItemLoader(); + + KJS::Object createBinding(KJSEmbedPart *jspart, KJS::ExecState *exec, const KJS::List &args) const; +}; + +class KFileItemImp : public JSProxyImp +{ + /** Identifiers for the methods provided by this class. */ + enum MethodId { Methodrefresh, MethodrefreshMimeType, Methodurl, MethodsetUrl, MethodsetName, MethodpermissionsString, Methoduser, Methodgroup, MethodisLink, MethodisDir, MethodisFile, MethodisReadable, MethodlinkDest, MethodtimeString, MethodisLocalFile, Methodtext, Methodname, MethodmimeType, MethodisMimeTypeKnown, MethodmimeComment, MethodiconName, Methodpixmap, Methodoverlays, MethodgetStatusBarInfo, MethodgetToolTipText, Methodrun}; +public: + KFileItemImp( KJS::ExecState *exec, int id ); + virtual ~KFileItemImp(); + + static void addBindings( KJS::ExecState *exec, KJS::Object &object ); + + /** Returns true iff this object implements the call function. */ + virtual bool implementsCall() const + { + return true; + } + + /** Invokes the call function. */ + virtual KJS::Value call( KJS::ExecState *exec, KJS::Object &self, const KJS::List &args ); +private: + int mid; +}; + +} // Bindings +} // KJSEmbed + +#endif diff --git a/kjsembed/plugins/qprocess_plugin.cpp b/kjsembed/plugins/qprocess_plugin.cpp new file mode 100644 index 00000000..497022e1 --- /dev/null +++ b/kjsembed/plugins/qprocess_plugin.cpp @@ -0,0 +1,144 @@ +// -*- c++ -*- + +/* + * Copyright (C) 2003, Ian Reinhart Geiser <geiseri@kde.org> + * + * This 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. + * + * This 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 this library; see the file COPYING.LIB. If not, write to + * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, + * Boston, MA 02110-1301, USA. + */ + +#include <kdebug.h> +#include <kjsembed/jsobjectproxy.h> +#include <kjsembed/jsbinding.h> +#include <kjsembed/kjsembedpart.h> +#include <kjsembed/customobject_imp.h> +#include <qvariant.h> + + +#include "qprocess_plugin.h" + +namespace KJSEmbed { +namespace Bindings { + +ProcessLoader::ProcessLoader( QObject *parent, const char *name, const QStringList &args ) : + JSBindingPlugin(parent, name, args) +{ +} + +KJS::Object ProcessLoader::createBinding(KJSEmbedPart *jspart, KJS::ExecState *exec, const KJS::List &args) const +{ + kdDebug() << "Loading a process object" << endl; + + QObject *parent = 0L; + JSObjectProxy *proxy = JSProxy::toObjectProxy( args[0].imp() ); + if ( proxy ) + parent = proxy->object(); + ProcessImp *imp = new ProcessImp(parent, "Process" ); + JSObjectProxy *prx = new JSObjectProxy( jspart, imp ); + + KJS::Object proxyObj( prx ); + prx->addBindings( exec, proxyObj ); + CustomObjectImp::addBindings( exec, proxyObj ); + return proxyObj; +} + +ProcessImp::ProcessImp(QObject *parent, const char *name ) + : QProcess(parent, name) +{ + kdDebug() << "New ProcessImp " << endl; +} + +ProcessImp::~ProcessImp() +{ +} + +QStringList ProcessImp::arguments() const +{ + return QProcess::arguments(); +} +void ProcessImp::setArguments( const QStringList args) +{ + QProcess::setArguments( args ); +} + +ProcessImp::Communication ProcessImp::communication() const +{ + return (ProcessImp::Communication)QProcess::communication(); +} +void ProcessImp::setCommunication( Communication comm) +{ + QProcess::setCommunication( comm ); +} + +bool ProcessImp::canReadLineStdout() const +{ + return QProcess::canReadLineStdout(); +} +bool ProcessImp::canReadLineStderr() const +{ + return QProcess::canReadLineStderr(); +} +bool ProcessImp::isRunning() const +{ + return QProcess::isRunning(); +} +bool ProcessImp::normalExit() const +{ + return QProcess::normalExit(); +} +int ProcessImp::exitStatus() const +{ + return QProcess::exitStatus(); +} + +bool ProcessImp::start() +{ + return QProcess::start( ); +} + +QString ProcessImp::readLineStdout () +{ + return QProcess::readLineStdout(); +} + +QString ProcessImp::readLineStderr () +{ + return QProcess::readLineStderr(); +} + +QDir ProcessImp::workingDirectory () const +{ + return QProcess::workingDirectory(); +} + +void ProcessImp::setWorkingDirectory ( const QDir & dir ) +{ + QProcess::setWorkingDirectory( dir ); +} + +void ProcessImp::addArgument ( const QString & arg ) +{ + QProcess::addArgument( arg ); +} + +} // namespace KJSEmbed::Bindings +} // namespace KJSEmbed + + +#include <kgenericfactory.h> +typedef KGenericFactory<KJSEmbed::Bindings::ProcessLoader> ProcessLoaderFactory; +K_EXPORT_COMPONENT_FACTORY( libqprocessplugin, ProcessLoaderFactory( "ProcessLoader" ) ) + +#include "qprocess_plugin.moc" diff --git a/kjsembed/plugins/qprocess_plugin.desktop b/kjsembed/plugins/qprocess_plugin.desktop new file mode 100644 index 00000000..91d18c99 --- /dev/null +++ b/kjsembed/plugins/qprocess_plugin.desktop @@ -0,0 +1,5 @@ +[Desktop Entry] +Name=Process +ServiceTypes=JSBindingPlugin/Binding +Type=Service +X-KDE-Library=libqprocessplugin diff --git a/kjsembed/plugins/qprocess_plugin.h b/kjsembed/plugins/qprocess_plugin.h new file mode 100644 index 00000000..8b0608a5 --- /dev/null +++ b/kjsembed/plugins/qprocess_plugin.h @@ -0,0 +1,86 @@ +// -*- c++ -*- + +/* + * Copyright (C) 2003, Ian Reinhart Geiser <geiseri@kde.org> + * + * This 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. + * + * This 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 this library; see the file COPYING.LIB. If not, write to + * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, + * Boston, MA 02110-1301, USA. + */ + +#ifndef KJSEMBED_QPROCESS_PLUGIN_H +#define KJSEMBED_QPROCESS_PLUGIN_H + +#include <kjsembed/jsbindingplugin.h> +#include <kjsembed/jsproxy_imp.h> +#include <qprocess.h> +#include <qdir.h> + +namespace KJSEmbed { +namespace Bindings { + +class ProcessLoader : public JSBindingPlugin +{ +public: + ProcessLoader( QObject *parent, const char *name, const QStringList &args ); + virtual ~ProcessLoader(){;} + KJS::Object createBinding(KJSEmbedPart *jspart, KJS::ExecState *exec, const KJS::List &args) const; +}; + + +class ProcessImp : public QProcess { + +Q_OBJECT + + /** Identifiers for the methods provided by this class. */ + enum Communication { Stdin = 0x01, Stdout = 0x02, Stderr = 0x04, DupStderr = 0x08 }; + + Q_PROPERTY(QStringList arguments READ arguments WRITE setArguments ) + Q_PROPERTY(Communication communication READ communication WRITE setCommunication) + Q_PROPERTY(bool canReadLineStdout READ canReadLineStdout ) + Q_PROPERTY(bool canReadLineStderr READ canReadLineStderr ) + Q_PROPERTY(bool isRunning READ isRunning ) + Q_PROPERTY(bool normalExit READ normalExit ) + Q_PROPERTY(int exitStatus READ exitStatus ) + Q_ENUMS(Communication) + +public: + ProcessImp( QObject *parent = 0, const char *name = 0); + virtual ~ProcessImp(); + + QStringList arguments() const; + void setArguments( const QStringList args); + + Communication communication() const; + void setCommunication( Communication comm); + + bool canReadLineStdout() const; + bool canReadLineStderr() const; + bool isRunning() const; + bool normalExit() const; + int exitStatus() const; + +public slots: + bool start(); + virtual QString readLineStdout (); + virtual QString readLineStderr (); + QDir workingDirectory () const; + void setWorkingDirectory ( const QDir & dir ); + void addArgument ( const QString & arg ); +}; + +} // namespace +} // namespace + +#endif // KJSEMBED_QPROCESS_PLUGIN_H diff --git a/kjsembed/qjscmd.cpp b/kjsembed/qjscmd.cpp new file mode 100644 index 00000000..f8a95ce6 --- /dev/null +++ b/kjsembed/qjscmd.cpp @@ -0,0 +1,83 @@ +/* + * Copyright (C) 2004, Richard J. Moore <rich@kde.org> + * + * This 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. + * + * This 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 this library; see the file COPYING.LIB. If not, write to + * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, + * Boston, MA 02110-1301, USA. + */ + +#include <stdio.h> +#include <errno.h> + +#include <qstring.h> +#include <qregexp.h> +#include <qapplication.h> +#include <qmainwindow.h> + +#include <kjs/interpreter.h> +#include <kjs/ustring.h> + +#include "kjsembedpart.h" +#include "jsconsolewidget.h" +#include "jssecuritypolicy.h" +#include "kjsembed/global.h" + +int main( int argc, char **argv ) +{ +#ifdef _WIN32 +# ifdef CONSOLEIO + RedirectIOToConsole(); +# endif +#endif + // Setup QApplication + QApplication *app; + app = new QApplication( argc, argv ); + app->connect( app, SIGNAL( lastWindowClosed() ), SLOT(quit()) ); + + // Setup Interpreter + KJSEmbed::JSSecurityPolicy::setDefaultPolicy( KJSEmbed::JSSecurityPolicy::CapabilityAll ); + KJSEmbed::KJSEmbedPart *part = new KJSEmbed::KJSEmbedPart; + KJS::Interpreter *js = part->interpreter(); + KJS::ExecState *exec = js->globalExec(); + + // Publish bindings + KJS::Object appobj = part->addObject( app, "application" ); + + // Build args array + KJS::List l; + for ( int i = 1 ; i < argc ; i++ ) + l.append( KJS::String( argv[i] ) ); + + KJS::Object argobj( js->builtinArray().construct( exec, l ) ); + appobj.put( exec, "args", argobj ); + + if ( argc > 1 ) { + // Run script + bool ok = part->runFile( argv[1] ); + if ( !ok ) { + KJS::Completion jsres = part->completion(); + (*KJSEmbed::conerr()) << jsres.value().toString(exec).qstring() << endl; + return 1; + } + } + + int result = 0; + part->execute( QString("include('cmdline.js');") ); + + return result; +} + +// Local Variables: +// c-basic-offset: 4 +// End: diff --git a/kjsembed/qjscmd/qjscmd.pro b/kjsembed/qjscmd/qjscmd.pro new file mode 100755 index 00000000..a1c27cf7 --- /dev/null +++ b/kjsembed/qjscmd/qjscmd.pro @@ -0,0 +1,14 @@ +include(../qjsembed.pri ) +INCLUDEPATH += ../.. .. ../kjsembed +SOURCES += qjscmd.cpp +LIBS += -L../bin -lqjsembed \ + -lqui + + +DEFINES += QT_ONLY +win32:DEFINES += KJSEMBED_DLL +CONFIG += qt + +TEMPLATE = app +DESTDIR = ../bin + diff --git a/kjsembed/qjscmdw/qjscmdw.pro b/kjsembed/qjscmdw/qjscmdw.pro new file mode 100755 index 00000000..f5913b1e --- /dev/null +++ b/kjsembed/qjscmdw/qjscmdw.pro @@ -0,0 +1,15 @@ +include(../qjsembed.pri) + +INCLUDEPATH += ../.. .. ../kjsembed +SOURCES += ../qjscmd/qjscmd.cpp +LIBS += -L../bin -lqjsembed -lqui + + +DEFINES += QT_ONLY +win32:DEFINES += KJSEMBED_DLL +CONFIG += qt console + +TEMPLATE = app +TARGET = qjscmdw +DESTDIR = ../bin + diff --git a/kjsembed/qjsembed.nsi b/kjsembed/qjsembed.nsi new file mode 100755 index 00000000..2e61ab5a --- /dev/null +++ b/kjsembed/qjsembed.nsi @@ -0,0 +1,226 @@ +!define VER_MAJOR 1
+!define VER_MINOR 0
+!define VER_FILE 10
+!define VER_DISPLAY "1.0 ${__TIMESTAMP__}"
+!define APP_NAME QJSEmbed
+!define APP_NAME_LC qjsembed
+
+
+Outfile ${APP_NAME}-${VER_FILE}.exe
+SetCompressor lzma
+
+InstallDir $PROGRAMFILES\${APP_NAME}
+InstallDirRegKey HKLM Software\SourceXtreme\${APP_NAME} ""
+
+!include "Sections.nsh"
+!include "MUI.nsh"
+
+Name "${APP_NAME}"
+Caption "${APP_NAME} ${VER_DISPLAY} Setup"
+XPStyle on
+
+!define MUI_ABORTWARNING
+!define MUI_HEADERIMAGE
+
+!insertmacro MUI_PAGE_WELCOME
+!insertmacro MUI_PAGE_LICENSE "lgpl.txt"
+!insertmacro MUI_PAGE_COMPONENTS
+!insertmacro MUI_PAGE_DIRECTORY
+!insertmacro MUI_PAGE_INSTFILES
+
+!insertmacro MUI_UNPAGE_CONFIRM
+!insertmacro MUI_UNPAGE_INSTFILES
+!insertmacro MUI_LANGUAGE "English"
+
+
+
+Section "${APP_NAME} SDK (Required)" secSDK
+ SectionIn RO
+ SetDetailsPrint textonly
+ DetailPrint "${APP_NAME} static library for embedding into Qt applications."
+ SetDetailsPrint listonly
+
+ SetOutPath "$WINDIR"
+
+
+ SetOutPath "$INSTDIR"
+ File lgpl.txt
+ File ReadMe.txt
+ SetOutPath "$INSTDIR"
+ File kjsembed\qjsembed.dll
+ SetOutPath "$INSTDIR\lib"
+ File kjsembed\qjsembed.lib
+ SetOutPath "$INSTDIR\include"
+ File kjs\completion.h
+ File kjs\list.h
+ File kjs\reference.h
+ File kjs\ustring.h
+ File kjs\function.h
+ File kjs\lookup.h
+ File kjs\reference_list.h
+ File kjs\value.h
+ File kjs\global.h
+ File kjs\object.h
+ File kjs\scope_chain.h
+ File kjs\identifier.h
+ File kjs\operations.h
+ File kjs\simple_number.h
+ File kjs\interpreter.h
+ File kjs\property_map.h
+ File kjs\types.h
+
+ File kjsembed\kjsembedpart.h
+ File kjsembed\jsconsolewidget.h
+ File kjsembed\jssecuritypolicy.h
+
+
+ ; Write the installation path into the registry
+ WriteRegStr HKLM Software\SourceXtreme\${APP_NAME} "Install_Dir" "$INSTDIR"
+
+ ; Write the uninstall keys for Windows
+ WriteRegStr HKLM "Software\Microsoft\Windows\CurrentVersion\Uninstall\${APP_NAME}" "DisplayName" "${APP_NAME} ${VER_DISPLAY}"
+ WriteRegStr HKLM "Software\Microsoft\Windows\CurrentVersion\Uninstall\${APP_NAME}" "DisplayVersion" "${VER_DISPLAY}"
+
+ WriteRegStr HKLM "Software\Microsoft\Windows\CurrentVersion\Uninstall\${APP_NAME}" "UninstallString" '"$INSTDIR\uninstall.exe"'
+ WriteRegDWORD HKLM "Software\Microsoft\Windows\CurrentVersion\Uninstall\${APP_NAME}" "NoModify" 1
+ WriteRegDWORD HKLM "Software\Microsoft\Windows\CurrentVersion\Uninstall\${APP_NAME}" "NoRepair" 1
+ WriteRegDWORD HKLM "Software\Microsoft\Windows\CurrentVersion\Uninstall\${APP_NAME}" "VersionMajor" "${VER_MAJOR}"
+ WriteRegDWORD HKLM "Software\Microsoft\Windows\CurrentVersion\Uninstall\${APP_NAME}" "VersionMinor" "${VER_MINOR}"
+ WriteRegStr HKLM "Software\Microsoft\Windows\CurrentVersion\Uninstall\${APP_NAME}" "URLInfoAbout" "http://www.sourcextreme.com/projects/${APP_NAME_LC}"
+ WriteRegStr HKLM "Software\Microsoft\Windows\CurrentVersion\Uninstall\${APP_NAME}" "Publisher" "SourceXtreme, Inc"
+ WriteRegStr HKLM "Software\Microsoft\Windows\CurrentVersion\Uninstall\${APP_NAME}" "HelpLink" "oss@sourcextreme.com"
+
+ WriteUninstaller "uninstall.exe"
+
+SectionEnd
+
+Section "${APP_NAME} Runtime" secRuntime
+ SetOutPath "$INSTDIR"
+ File qjscmd\qjscmd.exe
+ File qjscmdw\qjscmdw.exe
+ File stdlib\cmdline.js
+ File "$%QTDIR%\bin\qt-mt*.dll"
+SectionEnd
+
+Section "${APP_NAME} Source" secSrc
+ SetOutPath "$INSTDIR\source"
+ File *.pro
+ File *.pri
+ File lgpl.txt
+ File readme.txt
+ File todo.txt
+
+
+ SetOutPath "$INSTDIR\source\pcre"
+ File pcre\*.pro
+ File pcre\*.c
+ File pcre\*.h
+
+ SetOutPath "$INSTDIR\source\kjs"
+ File kjs\*.pro
+ File kjs\*.cpp
+ File kjs\*.h
+
+ SetOutPath "$INSTDIR\source\builtins"
+ File builtins\*.pro
+ File builtins\*.cpp
+ File builtins\*.h
+
+ SetOutPath "$INSTDIR\source\qtbindings"
+ File qtbindings\*.pro
+ File qtbindings\*.cpp
+ File qtbindings\*.h
+
+ SetOutPath "$INSTDIR\source\kjsembed"
+ File kjsembed\*.pro
+ File kjsembed\*.cpp
+ File kjsembed\*.h
+
+ SetOutPath "$INSTDIR\source\qjscmd"
+ File qjscmd\*.pro
+ File qjscmd\*.cpp
+
+
+ SetOutPath "$INSTDIR\source\stdlib"
+ File stdlib\*.js
+
+ SetOutPath "$INSTDIR\source\tests"
+ File tests\*.js
+ File tests\*.ui
+
+SectionEnd
+
+; Optional section (can be disabled by the user)
+Section "Start Menu Shortcuts" secMenu
+
+ SetOutPath "$INSTDIR"
+ CreateDirectory "$SMPROGRAMS\${APP_NAME}"
+ CreateShortCut "$SMPROGRAMS\${APP_NAME}\Uninstall.lnk" "$INSTDIR\uninstall.exe" "" "$INSTDIR\uninstall.exe" 0
+ CreateShortCut "$SMPROGRAMS\${APP_NAME}\ReadMe.lnk" "$INSTDIR\ReadMe.txt" "" "$INSTDIR\ReadMe.txt" 0
+ CreateShortCut "$SMPROGRAMS\${APP_NAME}\JSConsole.lnk" "$INSTDIR\qjscmdw.exe" "cmdline.js"
+
+
+; Create internet links
+ WriteINIStr "$SMPROGRAMS\${APP_NAME}\${APP_NAME} Webpage.url" "InternetShortcut" "URL" "http://www.sourcextreme.com/projects/${APP_NAME_LC}/"
+
+SectionEnd
+
+;Descriptions
+
+LangString DESC_secSDK ${LANG_ENGLISH} "${APP_NAME} static library for embedding into Qt applications."
+LangString DESC_secRuntime ${LANG_ENGLISH} "${APP_NAME} runtime for running scripts standalone."
+LangString DESC_secMenu ${LANG_ENGLISH} "Start menu shortcuts."
+LangString DESC_secSrc ${LANG_ENGLISH} "Source for building ${APP_NAME}."
+
+!insertmacro MUI_FUNCTION_DESCRIPTION_BEGIN
+!insertmacro MUI_DESCRIPTION_TEXT ${secSDK} $(DESC_secSDK)
+!insertmacro MUI_DESCRIPTION_TEXT ${secRuntime} $(DESC_secRuntime)
+!insertmacro MUI_DESCRIPTION_TEXT ${secMenu} $(DESC_secMenu)
+!insertmacro MUI_DESCRIPTION_TEXT ${secSrc} $(DESC_secSrc)
+!insertmacro MUI_FUNCTION_DESCRIPTION_END
+
+; Uninstaller
+
+Section "Uninstall"
+
+ ; Remove registry keys
+ DeleteRegKey HKLM "Software\Microsoft\Windows\CurrentVersion\Uninstall\${APP_NAME}"
+ DeleteRegKey HKLM SOFTWARE\SourceXtreme\${APP_NAME}
+
+ ; Remove files and uninstaller
+ Delete "$INSTDIR\*.*"
+
+ ; Remove source
+ Delete "$INSTDIR\include\*.*"
+ Delete "$INSTDIR\lib\*.*"
+ Delete "$INSTDIR\source\pcre\*.*"
+ Delete "$INSTDIR\source\kjsembed\*.*"
+ Delete "$INSTDIR\source\kjs\*.*"
+ Delete "$INSTDIR\source\qtbindings\*.*"
+ Delete "$INSTDIR\source\builtins\*.*"
+ Delete "$INSTDIR\source\qjscmd\*.*"
+ Delete "$INSTDIR\source\tests\*.*"
+ Delete "$INSTDIR\source\stdlib\*.*"
+ Delete "$INSTDIR\source\*.*"
+
+ Delete "$INSTDIR\src\*.*"
+ ; Remove shortcuts, if any
+ Delete "$SMPROGRAMS\${APP_NAME}\*.*"
+
+ ; Remove directories used
+ RMDir "$SMPROGRAMS\${APP_NAME}"
+ RMDir "$INSTDIR\lib"
+ RMDir "$INSTDIR\include"
+ RMDir "$INSTDIR\source\pcre"
+ RMDir "$INSTDIR\source\kjsembed"
+ RMDir "$INSTDIR\source\kjs"
+ RMDir "$INSTDIR\source\qtbindings"
+ RMDir "$INSTDIR\source\builtins"
+ RMDir "$INSTDIR\source\qjscmd"
+ RMDir "$INSTDIR\source\tests"
+ RMDir "$INSTDIR\source\stdlib"
+ RMDir "$INSTDIR\source"
+
+ RMDir "$INSTDIR"
+
+SectionEnd
diff --git a/kjsembed/qjsembed.pri b/kjsembed/qjsembed.pri new file mode 100755 index 00000000..ad1c5cb9 --- /dev/null +++ b/kjsembed/qjsembed.pri @@ -0,0 +1,18 @@ +unix:OBJECTS_DIR = unix_obj +unix:MOC_DIR = unix_moc + +win32:OBJECTS_DIR = win_obj +win32:MOC_DIR = win_moc + +DEFINES += QT_ONLY +win32:DEFINES += WIN32 _WIN32 KJSEMBED_DLL + +#DEBUG { +#CONFIG += debug warn_on +#} + +#RELEASE { +CONFIG += release warn_off +#} + +CONFIG += thread rtti diff --git a/kjsembed/qjsembed.pro b/kjsembed/qjsembed.pro new file mode 100755 index 00000000..4ef01284 --- /dev/null +++ b/kjsembed/qjsembed.pro @@ -0,0 +1,5 @@ +win32:SUBDIRS = pcre +SUBDIRS += kjs builtins qtbindings bindings kjsembed qjscmd qjscmdw + +TEMPLATE = subdirs +TARGETDEPS = pcre diff --git a/kjsembed/qtbindings/Makefile.am b/kjsembed/qtbindings/Makefile.am new file mode 100644 index 00000000..7fde7610 --- /dev/null +++ b/kjsembed/qtbindings/Makefile.am @@ -0,0 +1,35 @@ + +INCLUDES= -I$(srcdir)/.. -I$(srcdir)/../.. $(all_includes) +KDE_CXXFLAGS = -DQT_NO_ASCII_CAST -DQT_CLEAN_NAMESPACE -Wno-unused + +noinst_LTLIBRARIES = libkjsembedqtbindings.la + +libkjsembedqtbindings_la_SOURCES = qlistviewitem_imp.cpp \ + qcombobox_imp.cpp \ + qframe_imp.cpp \ + qt_imp.cpp \ + qchecklistitem_imp.cpp \ + qcanvasellipse_imp.cpp \ + qcanvas_imp.cpp \ + qcanvasitem_imp.cpp \ + qcanvasitemlist_imp.cpp \ + qcanvasline_imp.cpp \ + qcanvaspixmaparray_imp.cpp \ + qcanvaspixmap_imp.cpp \ + qcanvaspolygonalitem_imp.cpp \ + qcanvaspolygon_imp.cpp \ + qcanvasrectangle_imp.cpp \ + qcanvasspline_imp.cpp \ + qcanvassprite_imp.cpp \ + qcanvastext_imp.cpp \ + qcanvasview_imp.cpp \ + qpopupmenu_imp.cpp \ + qmenudata_imp.cpp \ + qmenuitem_imp.cpp + +libkjsembedqtbindings_la_LDFLAGS = $(all_libraries) $(KDE_RPATH) +libkjsembedqtbindings_la_LIBADD = $(LIB_QT) $(LIB_KDECORE) $(LIB_KDEUI) + +libkjsembedqtbindings_la_METASOURCES = AUTO + + diff --git a/kjsembed/qtbindings/qcanvas_imp.cpp b/kjsembed/qtbindings/qcanvas_imp.cpp new file mode 100644 index 00000000..65192798 --- /dev/null +++ b/kjsembed/qtbindings/qcanvas_imp.cpp @@ -0,0 +1,1117 @@ + + + +#include <qcstring.h> +#include <qimage.h> +#include <qpainter.h> +#include <qpalette.h> +#include <qpixmap.h> +#include <qfont.h> + +#include <kjs/object.h> + +#include <kjsembed/global.h> +#include <kjsembed/jsobjectproxy.h> +#include <kjsembed/jsopaqueproxy.h> +#include <kjsembed/jsbinding.h> + +#include <qcanvas.h> +#include "qcanvas_imp.h" + +/** + * Namespace containing the KJSEmbed library. + */ +namespace KJSEmbed { + +QCanvasImp::QCanvasImp( KJS::ExecState *exec, int mid, bool constructor ) + : JSProxyImp(exec), id(mid), cons(constructor) +{ +} + +QCanvasImp::~QCanvasImp() +{ +} + +/** + * Adds bindings for static methods and enum constants to the specified Object. + */ +void QCanvasImp::addStaticBindings( KJS::ExecState *exec, KJS::Object &object ) +{ + JSProxy::MethodTable methods[] = { + + { 0, 0 } + }; + + int idx = 0; + QCString lastName; + + while( methods[idx].name ) { + if ( lastName != methods[idx].name ) { + QCanvasImp *meth = new QCanvasImp( exec, methods[idx].id ); + object.put( exec , methods[idx].name, KJS::Object(meth) ); + lastName = methods[idx].name; + } + ++idx; + } + + +} + +/** + * Adds bindings for instance methods to the specified Object. + */ +void QCanvasImp::addBindings( KJS::ExecState *exec, KJS::Object &object ) +{ + JSProxy::MethodTable methods[] = { + + { Method_setTiles_5, "setTiles" }, + { Method_setBackgroundPixmap_6, "setBackgroundPixmap" }, + { Method_backgroundPixmap_7, "backgroundPixmap" }, + { Method_setBackgroundColor_8, "setBackgroundColor" }, + { Method_backgroundColor_9, "backgroundColor" }, + { Method_setTile_10, "setTile" }, + { Method_tile_11, "tile" }, + { Method_tilesHorizontally_12, "tilesHorizontally" }, + { Method_tilesVertically_13, "tilesVertically" }, + { Method_tileWidth_14, "tileWidth" }, + { Method_tileHeight_15, "tileHeight" }, + { Method_resize_16, "resize" }, + { Method_width_17, "width" }, + { Method_height_18, "height" }, + { Method_size_19, "size" }, + { Method_rect_20, "rect" }, + { Method_onCanvas_21, "onCanvas" }, + { Method_onCanvas_22, "onCanvas" }, + { Method_validChunk_23, "validChunk" }, + { Method_validChunk_24, "validChunk" }, + { Method_chunkSize_25, "chunkSize" }, + { Method_retune_26, "retune" }, + { Method_sameChunk_27, "sameChunk" }, + { Method_setChangedChunk_28, "setChangedChunk" }, + { Method_setChangedChunkContaining_29, "setChangedChunkContaining" }, + { Method_setAllChanged_30, "setAllChanged" }, + { Method_setChanged_31, "setChanged" }, + { Method_setUnchanged_32, "setUnchanged" }, + { Method_addItemToChunk_33, "addItemToChunk" }, + { Method_removeItemFromChunk_34, "removeItemFromChunk" }, + { Method_addItemToChunkContaining_35, "addItemToChunkContaining" }, + { Method_removeItemFromChunkContaining_36, "removeItemFromChunkContaining" }, + { Method_allItems_37, "allItems" }, + { Method_collisions_38, "collisions" }, + { Method_collisions_39, "collisions" }, + { Method_collisions_40, "collisions" }, + { Method_drawArea_41, "drawArea" }, + { Method_addView_42, "addView" }, + { Method_removeView_43, "removeView" }, + { Method_drawCanvasArea_44, "drawCanvasArea" }, + { Method_drawViewArea_45, "drawViewArea" }, + { Method_addItem_46, "addItem" }, + { Method_addAnimation_47, "addAnimation" }, + { Method_removeItem_48, "removeItem" }, + { Method_removeAnimation_49, "removeAnimation" }, + { Method_setAdvancePeriod_50, "setAdvancePeriod" }, + { Method_setUpdatePeriod_51, "setUpdatePeriod" }, + { Method_setDoubleBuffering_52, "setDoubleBuffering" }, + { 0, 0 } + }; + + int idx = 0; + QCString lastName; + + while( methods[idx].name ) { + if ( lastName != methods[idx].name ) { + QCanvasImp *meth = new QCanvasImp( exec, methods[idx].id ); + object.put( exec , methods[idx].name, KJS::Object(meth) ); + lastName = methods[idx].name; + } + ++idx; + } +} + +/** + * Extract a QCanvas pointer from an Object. + */ +QCanvas *QCanvasImp::toQCanvas( KJS::Object &self ) +{ + JSObjectProxy *ob = JSProxy::toObjectProxy( self.imp() ); + if ( ob ) { + QObject *obj = ob->object(); + if ( obj ) + return dynamic_cast<QCanvas *>( obj ); + } + + JSOpaqueProxy *op = JSProxy::toOpaqueProxy( self.imp() ); + if ( !op ) + return 0; + + if ( op->typeName() != "QCanvas" ) + return 0; + + return op->toNative<QCanvas>(); +} + +/** + * Select and invoke the correct constructor. + */ +KJS::Object QCanvasImp::construct( KJS::ExecState *exec, const KJS::List &args ) +{ + switch( id ) { + + case Constructor_QCanvas_1: + return QCanvas_1( exec, args ); + break; + + case Constructor_QCanvas_2: + return QCanvas_2( exec, args ); + break; + + case Constructor_QCanvas_3: + return QCanvas_3( exec, args ); + break; + + default: + break; + } + + QString msg = i18n("QCanvasCons has no constructor with id '%1'.").arg(id); + return throwError(exec, msg,KJS::ReferenceError); +} + + +KJS::Object QCanvasImp::QCanvas_1( KJS::ExecState *exec, const KJS::List &args ) +{ + + // Unsupported parameter QObject * + + QObject * arg0 = extractQObject(exec,args,0); + + const char *arg1 = (args.size() >= 2) ? args[1].toString(exec).ascii() : 0; + + + // We should now create an instance of the QCanvas object + + QCanvas *ret = new QCanvas( + + arg0, + arg1 ); + + JSOpaqueProxy *prx = new JSOpaqueProxy( ret, "QCanvas"); + return KJS::Object( prx ); +} + +KJS::Object QCanvasImp::QCanvas_2( KJS::ExecState *exec, const KJS::List &args ) +{ + + int arg0 = extractInt(exec, args, 0); + + int arg1 = extractInt(exec, args, 1); + + + // We should now create an instance of the QCanvas object + + QCanvas *ret = new QCanvas( + + arg0, + arg1 ); + JSOpaqueProxy *prx = new JSOpaqueProxy( ret, "QCanvas"); + return KJS::Object( prx ); + +} + +KJS::Object QCanvasImp::QCanvas_3( KJS::ExecState *exec, const KJS::List &args ) +{ + + // Unsupported parameter QPixmap + + QPixmap arg0 = extractQPixmap(exec, args, 0); + + int arg1 = extractInt(exec, args, 1); + + int arg2 = extractInt(exec, args, 2); + + int arg3 = extractInt(exec, args, 3); + + int arg4 = extractInt(exec, args, 4); + + + // We should now create an instance of the QCanvas object + + QCanvas *ret = new QCanvas( + + arg0, + arg1, + arg2, + arg3, + arg4 ); + + JSOpaqueProxy *prx = new JSOpaqueProxy( ret, "QCanvas"); + return KJS::Object( prx ); +} + +KJS::Value QCanvasImp::call( KJS::ExecState *exec, KJS::Object &self, const KJS::List &args ) +{ + instance = QCanvasImp::toQCanvas( self ); + + switch( id ) { + + case Method_setTiles_5: + return setTiles_5( exec, self, args ); + break; + + case Method_setBackgroundPixmap_6: + return setBackgroundPixmap_6( exec, self, args ); + break; + + case Method_backgroundPixmap_7: + return backgroundPixmap_7( exec, self, args ); + break; + + case Method_setBackgroundColor_8: + return setBackgroundColor_8( exec, self, args ); + break; + + case Method_backgroundColor_9: + return backgroundColor_9( exec, self, args ); + break; + + case Method_setTile_10: + return setTile_10( exec, self, args ); + break; + + case Method_tile_11: + return tile_11( exec, self, args ); + break; + + case Method_tilesHorizontally_12: + return tilesHorizontally_12( exec, self, args ); + break; + + case Method_tilesVertically_13: + return tilesVertically_13( exec, self, args ); + break; + + case Method_tileWidth_14: + return tileWidth_14( exec, self, args ); + break; + + case Method_tileHeight_15: + return tileHeight_15( exec, self, args ); + break; + + case Method_resize_16: + return resize_16( exec, self, args ); + break; + + case Method_width_17: + return width_17( exec, self, args ); + break; + + case Method_height_18: + return height_18( exec, self, args ); + break; + + case Method_size_19: + return size_19( exec, self, args ); + break; + + case Method_rect_20: + return rect_20( exec, self, args ); + break; + + case Method_onCanvas_21: + return onCanvas_21( exec, self, args ); + break; + + case Method_onCanvas_22: + return onCanvas_22( exec, self, args ); + break; + + case Method_validChunk_23: + return validChunk_23( exec, self, args ); + break; + + case Method_validChunk_24: + return validChunk_24( exec, self, args ); + break; + + case Method_chunkSize_25: + return chunkSize_25( exec, self, args ); + break; + + case Method_retune_26: + return retune_26( exec, self, args ); + break; + + case Method_sameChunk_27: + return sameChunk_27( exec, self, args ); + break; + + case Method_setChangedChunk_28: + return setChangedChunk_28( exec, self, args ); + break; + + case Method_setChangedChunkContaining_29: + return setChangedChunkContaining_29( exec, self, args ); + break; + + case Method_setAllChanged_30: + return setAllChanged_30( exec, self, args ); + break; + + case Method_setChanged_31: + return setChanged_31( exec, self, args ); + break; + + case Method_setUnchanged_32: + return setUnchanged_32( exec, self, args ); + break; + + case Method_addItemToChunk_33: + return addItemToChunk_33( exec, self, args ); + break; + + case Method_removeItemFromChunk_34: + return removeItemFromChunk_34( exec, self, args ); + break; + + case Method_addItemToChunkContaining_35: + return addItemToChunkContaining_35( exec, self, args ); + break; + + case Method_removeItemFromChunkContaining_36: + return removeItemFromChunkContaining_36( exec, self, args ); + break; + + case Method_allItems_37: + return allItems_37( exec, self, args ); + break; + + case Method_collisions_38: + return collisions_38( exec, self, args ); + break; + + case Method_collisions_39: + return collisions_39( exec, self, args ); + break; + + case Method_collisions_40: + return collisions_40( exec, self, args ); + break; + + case Method_drawArea_41: + return drawArea_41( exec, self, args ); + break; + + case Method_addView_42: + return addView_42( exec, self, args ); + break; + + case Method_removeView_43: + return removeView_43( exec, self, args ); + break; + + case Method_drawCanvasArea_44: + return drawCanvasArea_44( exec, self, args ); + break; + + case Method_drawViewArea_45: + return drawViewArea_45( exec, self, args ); + break; + + case Method_addItem_46: + return addItem_46( exec, self, args ); + break; + + case Method_addAnimation_47: + return addAnimation_47( exec, self, args ); + break; + + case Method_removeItem_48: + return removeItem_48( exec, self, args ); + break; + + case Method_removeAnimation_49: + return removeAnimation_49( exec, self, args ); + break; + + case Method_setAdvancePeriod_50: + return setAdvancePeriod_50( exec, self, args ); + break; + + case Method_setUpdatePeriod_51: + return setUpdatePeriod_51( exec, self, args ); + break; + + case Method_setDoubleBuffering_52: + return setDoubleBuffering_52( exec, self, args ); + break; + + default: + break; + } + + QString msg = i18n( "QCanvasImp has no method with id '%1'." ).arg( id ); + return throwError(exec, msg,KJS::ReferenceError); +} + + +KJS::Value QCanvasImp::setTiles_5( KJS::ExecState *exec, KJS::Object &obj, const KJS::List &args ) +{ + + // Unsupported parameter QPixmap + return KJS::Value(); + + QPixmap arg0; // Dummy + + int arg1 = extractInt(exec, args, 1); + + int arg2 = extractInt(exec, args, 2); + + int arg3 = extractInt(exec, args, 3); + + int arg4 = extractInt(exec, args, 4); + + instance->setTiles( + arg0, + arg1, + arg2, + arg3, + arg4 ); + return KJS::Value(); // Returns void + +} + +KJS::Value QCanvasImp::setBackgroundPixmap_6( KJS::ExecState *exec, KJS::Object &obj, const KJS::List &args ) +{ + + QPixmap arg0 = extractQPixmap(exec, args, 0); + + instance->setBackgroundPixmap( + arg0 ); + return KJS::Value(); // Returns void + +} + +KJS::Value QCanvasImp::backgroundPixmap_7( KJS::ExecState *exec, KJS::Object &obj, const KJS::List &args ) +{ + QPixmap ret; + ret = instance->backgroundPixmap( ); + + return convertToValue( exec, ret ); + +} + +KJS::Value QCanvasImp::setBackgroundColor_8( KJS::ExecState *exec, KJS::Object &obj, const KJS::List &args ) +{ + + QColor arg0 = extractQColor(exec, args, 0); + + instance->setBackgroundColor( + arg0 ); + return KJS::Value(); // Returns void + +} + +KJS::Value QCanvasImp::backgroundColor_9( KJS::ExecState *exec, KJS::Object &obj, const KJS::List &args ) +{ + + instance->backgroundColor( ); + return KJS::Value(); // Returns 'QColor' + +} + +KJS::Value QCanvasImp::setTile_10( KJS::ExecState *exec, KJS::Object &obj, const KJS::List &args ) +{ + + int arg0 = extractInt(exec, args, 0); + + int arg1 = extractInt(exec, args, 1); + + int arg2 = extractInt(exec, args, 2); + + instance->setTile( + arg0, + arg1, + arg2 ); + return KJS::Value(); // Returns void + +} + +KJS::Value QCanvasImp::tile_11( KJS::ExecState *exec, KJS::Object &obj, const KJS::List &args ) +{ + + int arg0 = extractInt(exec, args, 0); + + int arg1 = extractInt(exec, args, 1); + + int ret; + ret = instance->tile( + arg0, + arg1 ); + return KJS::Number( ret ); + +} + +KJS::Value QCanvasImp::tilesHorizontally_12( KJS::ExecState *exec, KJS::Object &obj, const KJS::List &args ) +{ + + int ret; + ret = instance->tilesHorizontally( ); + return KJS::Number( ret ); + +} + +KJS::Value QCanvasImp::tilesVertically_13( KJS::ExecState *exec, KJS::Object &obj, const KJS::List &args ) +{ + + int ret; + ret = instance->tilesVertically( ); + return KJS::Number( ret ); + +} + +KJS::Value QCanvasImp::tileWidth_14( KJS::ExecState *exec, KJS::Object &obj, const KJS::List &args ) +{ + + int ret; + ret = instance->tileWidth( ); + return KJS::Number( ret ); + +} + +KJS::Value QCanvasImp::tileHeight_15( KJS::ExecState *exec, KJS::Object &obj, const KJS::List &args ) +{ + + int ret; + ret = instance->tileHeight( ); + return KJS::Number( ret ); + +} + +KJS::Value QCanvasImp::resize_16( KJS::ExecState *exec, KJS::Object &obj, const KJS::List &args ) +{ + + int arg0 = extractInt(exec, args, 0); + + int arg1 = extractInt(exec, args, 1); + + instance->resize( + arg0, + arg1 ); + return KJS::Value(); // Returns void + +} + +KJS::Value QCanvasImp::width_17( KJS::ExecState *exec, KJS::Object &obj, const KJS::List &args ) +{ + + int ret; + ret = instance->width( ); + return KJS::Number( ret ); + +} + +KJS::Value QCanvasImp::height_18( KJS::ExecState *exec, KJS::Object &obj, const KJS::List &args ) +{ + + int ret; + ret = instance->height( ); + return KJS::Number( ret ); + +} + +KJS::Value QCanvasImp::size_19( KJS::ExecState *exec, KJS::Object &obj, const KJS::List &args ) +{ + QSize ret; + ret = instance->size( ); + + return convertToValue( exec, ret ); + +} + +KJS::Value QCanvasImp::rect_20( KJS::ExecState *exec, KJS::Object &obj, const KJS::List &args ) +{ + QRect ret; + ret = instance->rect( ); + + return convertToValue( exec, ret ); + +} + +KJS::Value QCanvasImp::onCanvas_21( KJS::ExecState *exec, KJS::Object &obj, const KJS::List &args ) +{ + + int arg0 = extractInt(exec, args, 0); + + int arg1 = extractInt(exec, args, 1); + + bool ret; + ret = instance->onCanvas( + arg0, + arg1 ); + return KJS::Boolean( ret ); + +} + +KJS::Value QCanvasImp::onCanvas_22( KJS::ExecState *exec, KJS::Object &obj, const KJS::List &args ) +{ + + QPoint arg0 = extractQPoint(exec, args, 0); + + bool ret; + ret = instance->onCanvas( + arg0 ); + return KJS::Boolean( ret ); + +} + +KJS::Value QCanvasImp::validChunk_23( KJS::ExecState *exec, KJS::Object &obj, const KJS::List &args ) +{ + + int arg0 = extractInt(exec, args, 0); + + int arg1 = extractInt(exec, args, 1); + + bool ret; + ret = instance->validChunk( + arg0, + arg1 ); + return KJS::Boolean( ret ); + +} + +KJS::Value QCanvasImp::validChunk_24( KJS::ExecState *exec, KJS::Object &obj, const KJS::List &args ) +{ + + QPoint arg0 = extractQPoint(exec, args, 0); + + bool ret; + ret = instance->validChunk( + arg0 ); + return KJS::Boolean( ret ); + +} + +KJS::Value QCanvasImp::chunkSize_25( KJS::ExecState *exec, KJS::Object &obj, const KJS::List &args ) +{ + + int ret; + ret = instance->chunkSize( ); + return KJS::Number( ret ); + +} + +KJS::Value QCanvasImp::retune_26( KJS::ExecState *exec, KJS::Object &obj, const KJS::List &args ) +{ + + int arg0 = extractInt(exec, args, 0); + + int arg1 = extractInt(exec, args, 1); + + instance->retune( + arg0, + arg1 ); + return KJS::Value(); // Returns void + +} + +KJS::Value QCanvasImp::sameChunk_27( KJS::ExecState *exec, KJS::Object &obj, const KJS::List &args ) +{ + + int arg0 = extractInt(exec, args, 0); + + int arg1 = extractInt(exec, args, 1); + + int arg2 = extractInt(exec, args, 2); + + int arg3 = extractInt(exec, args, 3); + + bool ret; + ret = instance->sameChunk( + arg0, + arg1, + arg2, + arg3 ); + return KJS::Boolean( ret ); + +} + +KJS::Value QCanvasImp::setChangedChunk_28( KJS::ExecState *exec, KJS::Object &obj, const KJS::List &args ) +{ + + int arg0 = extractInt(exec, args, 0); + + int arg1 = extractInt(exec, args, 1); + + instance->setChangedChunk( + arg0, + arg1 ); + return KJS::Value(); // Returns void + +} + +KJS::Value QCanvasImp::setChangedChunkContaining_29( KJS::ExecState *exec, KJS::Object &obj, const KJS::List &args ) +{ + + int arg0 = extractInt(exec, args, 0); + + int arg1 = extractInt(exec, args, 1); + + instance->setChangedChunkContaining( + arg0, + arg1 ); + return KJS::Value(); // Returns void + +} + +KJS::Value QCanvasImp::setAllChanged_30( KJS::ExecState *exec, KJS::Object &obj, const KJS::List &args ) +{ + + instance->setAllChanged( ); + return KJS::Value(); // Returns void + +} + +KJS::Value QCanvasImp::setChanged_31( KJS::ExecState *exec, KJS::Object &obj, const KJS::List &args ) +{ + + QRect arg0 = extractQRect(exec, args, 0); + + instance->setChanged( + arg0 ); + return KJS::Value(); // Returns void + +} + +KJS::Value QCanvasImp::setUnchanged_32( KJS::ExecState *exec, KJS::Object &obj, const KJS::List &args ) +{ + + QRect arg0 = extractQRect(exec, args, 0); + + instance->setUnchanged( + arg0 ); + return KJS::Value(); // Returns void + +} + +KJS::Value QCanvasImp::addItemToChunk_33( KJS::ExecState *exec, KJS::Object &obj, const KJS::List &args ) +{ + + // Unsupported parameter QCanvasItem * + return KJS::Value(); + + QCanvasItem * arg0; // Dummy + + int arg1 = extractInt(exec, args, 1); + + int arg2 = extractInt(exec, args, 2); + + instance->addItemToChunk( + arg0, + arg1, + arg2 ); + return KJS::Value(); // Returns void + +} + +KJS::Value QCanvasImp::removeItemFromChunk_34( KJS::ExecState *exec, KJS::Object &obj, const KJS::List &args ) +{ + + // Unsupported parameter QCanvasItem * + return KJS::Value(); + + QCanvasItem * arg0; // Dummy + + int arg1 = extractInt(exec, args, 1); + + int arg2 = extractInt(exec, args, 2); + + instance->removeItemFromChunk( + arg0, + arg1, + arg2 ); + return KJS::Value(); // Returns void + +} + +KJS::Value QCanvasImp::addItemToChunkContaining_35( KJS::ExecState *exec, KJS::Object &obj, const KJS::List &args ) +{ + + // Unsupported parameter QCanvasItem * + return KJS::Value(); + + QCanvasItem * arg0; // Dummy + + int arg1 = extractInt(exec, args, 1); + + int arg2 = extractInt(exec, args, 2); + + instance->addItemToChunkContaining( + arg0, + arg1, + arg2 ); + return KJS::Value(); // Returns void + +} + +KJS::Value QCanvasImp::removeItemFromChunkContaining_36( KJS::ExecState *exec, KJS::Object &obj, const KJS::List &args ) +{ + + // Unsupported parameter QCanvasItem * + return KJS::Value(); + + QCanvasItem * arg0; // Dummy + + int arg1 = extractInt(exec, args, 1); + + int arg2 = extractInt(exec, args, 2); + + instance->removeItemFromChunkContaining( + arg0, + arg1, + arg2 ); + return KJS::Value(); // Returns void + +} + +KJS::Value QCanvasImp::allItems_37( KJS::ExecState *exec, KJS::Object &obj, const KJS::List &args ) +{ + + instance->allItems( ); + return KJS::Value(); // Returns 'QCanvasItemList' + +} + +KJS::Value QCanvasImp::collisions_38( KJS::ExecState *exec, KJS::Object &obj, const KJS::List &args ) +{ + + QPoint arg0 = extractQPoint(exec, args, 0); + + instance->collisions( + arg0 ); + return KJS::Value(); // Returns 'QCanvasItemList' + +} + +KJS::Value QCanvasImp::collisions_39( KJS::ExecState *exec, KJS::Object &obj, const KJS::List &args ) +{ + + QRect arg0 = extractQRect(exec, args, 0); + + instance->collisions( + arg0 ); + return KJS::Value(); // Returns 'QCanvasItemList' + +} + +KJS::Value QCanvasImp::collisions_40( KJS::ExecState *exec, KJS::Object &obj, const KJS::List &args ) +{ + + QPointArray arg0; // TODO (hack for qcanvas) + + // Unsupported parameter const QCanvasItem * + return KJS::Value(); + + const QCanvasItem * arg1; // Dummy + + bool arg2 = extractBool(exec, args, 2); + + instance->collisions( + arg0, + arg1, + arg2 ); + return KJS::Value(); // Returns 'QCanvasItemList' + +} + +KJS::Value QCanvasImp::drawArea_41( KJS::ExecState *exec, KJS::Object &obj, const KJS::List &args ) +{ + + QRect arg0 = extractQRect(exec, args, 0); + + // Unsupported parameter QPainter * + return KJS::Value(); + + QPainter * arg1; // Dummy + + bool arg2 = extractBool(exec, args, 2); + + instance->drawArea( + arg0, + arg1, + arg2 ); + return KJS::Value(); // Returns void + +} + +KJS::Value QCanvasImp::addView_42( KJS::ExecState *exec, KJS::Object &obj, const KJS::List &args ) +{ + + // Unsupported parameter QCanvasView * + return KJS::Value(); + + QCanvasView * arg0; // Dummy + + instance->addView( + arg0 ); + return KJS::Value(); // Returns void + +} + +KJS::Value QCanvasImp::removeView_43( KJS::ExecState *exec, KJS::Object &obj, const KJS::List &args ) +{ + + // Unsupported parameter QCanvasView * + return KJS::Value(); + + QCanvasView * arg0; // Dummy + + instance->removeView( + arg0 ); + return KJS::Value(); // Returns void + +} + +KJS::Value QCanvasImp::drawCanvasArea_44( KJS::ExecState *exec, KJS::Object &obj, const KJS::List &args ) +{ + + QRect arg0 = extractQRect(exec, args, 0); + + // Unsupported parameter QPainter * + return KJS::Value(); + + QPainter * arg1; // Dummy + + bool arg2 = extractBool(exec, args, 2); + + instance->drawCanvasArea( + arg0, + arg1, + arg2 ); + return KJS::Value(); // Returns void + +} + +KJS::Value QCanvasImp::drawViewArea_45( KJS::ExecState *exec, KJS::Object &obj, const KJS::List &args ) +{ + + // Unsupported parameter QCanvasView * + return KJS::Value(); + + QCanvasView * arg0; // Dummy + + // Unsupported parameter QPainter * + return KJS::Value(); + + QPainter * arg1; // Dummy + + QRect arg2 = extractQRect(exec, args, 2); + + bool arg3 = extractBool(exec, args, 3); + + instance->drawViewArea( + arg0, + arg1, + arg2, + arg3 ); + return KJS::Value(); // Returns void + +} + +KJS::Value QCanvasImp::addItem_46( KJS::ExecState *exec, KJS::Object &obj, const KJS::List &args ) +{ + + // Unsupported parameter QCanvasItem * + return KJS::Value(); + + QCanvasItem * arg0; // Dummy + + instance->addItem( + arg0 ); + return KJS::Value(); // Returns void + +} + +KJS::Value QCanvasImp::addAnimation_47( KJS::ExecState *exec, KJS::Object &obj, const KJS::List &args ) +{ + + // Unsupported parameter QCanvasItem * + return KJS::Value(); + + QCanvasItem * arg0; // Dummy + + instance->addAnimation( + arg0 ); + return KJS::Value(); // Returns void + +} + +KJS::Value QCanvasImp::removeItem_48( KJS::ExecState *exec, KJS::Object &obj, const KJS::List &args ) +{ + + // Unsupported parameter QCanvasItem * + return KJS::Value(); + + QCanvasItem * arg0; // Dummy + + instance->removeItem( + arg0 ); + return KJS::Value(); // Returns void + +} + +KJS::Value QCanvasImp::removeAnimation_49( KJS::ExecState *exec, KJS::Object &obj, const KJS::List &args ) +{ + + // Unsupported parameter QCanvasItem * + return KJS::Value(); + + QCanvasItem * arg0; // Dummy + + instance->removeAnimation( + arg0 ); + return KJS::Value(); // Returns void + +} + +KJS::Value QCanvasImp::setAdvancePeriod_50( KJS::ExecState *exec, KJS::Object &obj, const KJS::List &args ) +{ + + int arg0 = extractInt(exec, args, 0); + + instance->setAdvancePeriod( + arg0 ); + return KJS::Value(); // Returns void + +} + +KJS::Value QCanvasImp::setUpdatePeriod_51( KJS::ExecState *exec, KJS::Object &obj, const KJS::List &args ) +{ + + int arg0 = extractInt(exec, args, 0); + + instance->setUpdatePeriod( + arg0 ); + return KJS::Value(); // Returns void + +} + +KJS::Value QCanvasImp::setDoubleBuffering_52( KJS::ExecState *exec, KJS::Object &obj, const KJS::List &args ) +{ + + bool arg0 = extractBool(exec, args, 0); + + instance->setDoubleBuffering( + arg0 ); + return KJS::Value(); // Returns void + +} + + +} // namespace KJSEmbed + +// Local Variables: +// c-basic-offset: 4 +// End: + + diff --git a/kjsembed/qtbindings/qcanvas_imp.h b/kjsembed/qtbindings/qcanvas_imp.h new file mode 100644 index 00000000..9bd167bb --- /dev/null +++ b/kjsembed/qtbindings/qcanvas_imp.h @@ -0,0 +1,198 @@ + + + +#ifndef KJSEMBED_QCanvas_H +#define KJSEMBED_QCanvas_H + +#include <kjs/interpreter.h> +#include <kjs/object.h> + +#include <kjsembed/jsobjectproxy_imp.h> + +class QCanvas; + +/** + * Namespace containing the KJSEmbed library. + */ +namespace KJSEmbed { + +/** + * Wrapper class for QCanvas methods. + * + * @author Richard Moore, rich@kde.org + */ +class QCanvasImp : public JSProxyImp +{ +public: + /** Enumerates the constructors supported by this class. */ + enum Constructors { + Constructor_QCanvas_1, + Constructor_QCanvas_2, + Constructor_QCanvas_3, + + LastConstuctor = -1 + }; + + /** Enumerates the methods supported by this class. */ + enum Methods { + + Method_setTiles_5, + Method_setBackgroundPixmap_6, + Method_backgroundPixmap_7, + Method_setBackgroundColor_8, + Method_backgroundColor_9, + Method_setTile_10, + Method_tile_11, + Method_tilesHorizontally_12, + Method_tilesVertically_13, + Method_tileWidth_14, + Method_tileHeight_15, + Method_resize_16, + Method_width_17, + Method_height_18, + Method_size_19, + Method_rect_20, + Method_onCanvas_21, + Method_onCanvas_22, + Method_validChunk_23, + Method_validChunk_24, + Method_chunkSize_25, + Method_retune_26, + Method_sameChunk_27, + Method_setChangedChunk_28, + Method_setChangedChunkContaining_29, + Method_setAllChanged_30, + Method_setChanged_31, + Method_setUnchanged_32, + Method_addItemToChunk_33, + Method_removeItemFromChunk_34, + Method_addItemToChunkContaining_35, + Method_removeItemFromChunkContaining_36, + Method_allItems_37, + Method_collisions_38, + Method_collisions_39, + Method_collisions_40, + Method_drawArea_41, + Method_addView_42, + Method_removeView_43, + Method_drawCanvasArea_44, + Method_drawViewArea_45, + Method_addItem_46, + Method_addAnimation_47, + Method_removeItem_48, + Method_removeAnimation_49, + Method_setAdvancePeriod_50, + Method_setUpdatePeriod_51, + Method_setDoubleBuffering_52, + Method_Last = -1 + }; + + QCanvasImp( KJS::ExecState *exec, int id, bool constructor=false ); + ~QCanvasImp(); + + /** + * Adds the static bindings for this class to the specified Object. The + * static bindings are the static methods and the enums of this class. + */ + static void addStaticBindings( KJS::ExecState *exec, KJS::Object &object ); + + /** + * Adds the bindings for this class to the specified Object. The bindings + * added are the instance methods of this class. + */ + static void addBindings( KJS::ExecState *exec, KJS::Object &object ); + + static QCanvas *toQCanvas( KJS::Object &object ); + + // + // Constructors implemented by this class. + // + + KJS::Object QCanvas_1( KJS::ExecState *exec, const KJS::List &args ); + KJS::Object QCanvas_2( KJS::ExecState *exec, const KJS::List &args ); + KJS::Object QCanvas_3( KJS::ExecState *exec, const KJS::List &args ); + + // + // Methods implemented by this class. + // + + KJS::Value setTiles_5( KJS::ExecState *exec, KJS::Object &obj, const KJS::List &args ); + KJS::Value setBackgroundPixmap_6( KJS::ExecState *exec, KJS::Object &obj, const KJS::List &args ); + KJS::Value backgroundPixmap_7( KJS::ExecState *exec, KJS::Object &obj, const KJS::List &args ); + KJS::Value setBackgroundColor_8( KJS::ExecState *exec, KJS::Object &obj, const KJS::List &args ); + KJS::Value backgroundColor_9( KJS::ExecState *exec, KJS::Object &obj, const KJS::List &args ); + KJS::Value setTile_10( KJS::ExecState *exec, KJS::Object &obj, const KJS::List &args ); + KJS::Value tile_11( KJS::ExecState *exec, KJS::Object &obj, const KJS::List &args ); + KJS::Value tilesHorizontally_12( KJS::ExecState *exec, KJS::Object &obj, const KJS::List &args ); + KJS::Value tilesVertically_13( KJS::ExecState *exec, KJS::Object &obj, const KJS::List &args ); + KJS::Value tileWidth_14( KJS::ExecState *exec, KJS::Object &obj, const KJS::List &args ); + KJS::Value tileHeight_15( KJS::ExecState *exec, KJS::Object &obj, const KJS::List &args ); + KJS::Value resize_16( KJS::ExecState *exec, KJS::Object &obj, const KJS::List &args ); + KJS::Value width_17( KJS::ExecState *exec, KJS::Object &obj, const KJS::List &args ); + KJS::Value height_18( KJS::ExecState *exec, KJS::Object &obj, const KJS::List &args ); + KJS::Value size_19( KJS::ExecState *exec, KJS::Object &obj, const KJS::List &args ); + KJS::Value rect_20( KJS::ExecState *exec, KJS::Object &obj, const KJS::List &args ); + KJS::Value onCanvas_21( KJS::ExecState *exec, KJS::Object &obj, const KJS::List &args ); + KJS::Value onCanvas_22( KJS::ExecState *exec, KJS::Object &obj, const KJS::List &args ); + KJS::Value validChunk_23( KJS::ExecState *exec, KJS::Object &obj, const KJS::List &args ); + KJS::Value validChunk_24( KJS::ExecState *exec, KJS::Object &obj, const KJS::List &args ); + KJS::Value chunkSize_25( KJS::ExecState *exec, KJS::Object &obj, const KJS::List &args ); + KJS::Value retune_26( KJS::ExecState *exec, KJS::Object &obj, const KJS::List &args ); + KJS::Value sameChunk_27( KJS::ExecState *exec, KJS::Object &obj, const KJS::List &args ); + KJS::Value setChangedChunk_28( KJS::ExecState *exec, KJS::Object &obj, const KJS::List &args ); + KJS::Value setChangedChunkContaining_29( KJS::ExecState *exec, KJS::Object &obj, const KJS::List &args ); + KJS::Value setAllChanged_30( KJS::ExecState *exec, KJS::Object &obj, const KJS::List &args ); + KJS::Value setChanged_31( KJS::ExecState *exec, KJS::Object &obj, const KJS::List &args ); + KJS::Value setUnchanged_32( KJS::ExecState *exec, KJS::Object &obj, const KJS::List &args ); + KJS::Value addItemToChunk_33( KJS::ExecState *exec, KJS::Object &obj, const KJS::List &args ); + KJS::Value removeItemFromChunk_34( KJS::ExecState *exec, KJS::Object &obj, const KJS::List &args ); + KJS::Value addItemToChunkContaining_35( KJS::ExecState *exec, KJS::Object &obj, const KJS::List &args ); + KJS::Value removeItemFromChunkContaining_36( KJS::ExecState *exec, KJS::Object &obj, const KJS::List &args ); + KJS::Value allItems_37( KJS::ExecState *exec, KJS::Object &obj, const KJS::List &args ); + KJS::Value collisions_38( KJS::ExecState *exec, KJS::Object &obj, const KJS::List &args ); + KJS::Value collisions_39( KJS::ExecState *exec, KJS::Object &obj, const KJS::List &args ); + KJS::Value collisions_40( KJS::ExecState *exec, KJS::Object &obj, const KJS::List &args ); + KJS::Value drawArea_41( KJS::ExecState *exec, KJS::Object &obj, const KJS::List &args ); + KJS::Value addView_42( KJS::ExecState *exec, KJS::Object &obj, const KJS::List &args ); + KJS::Value removeView_43( KJS::ExecState *exec, KJS::Object &obj, const KJS::List &args ); + KJS::Value drawCanvasArea_44( KJS::ExecState *exec, KJS::Object &obj, const KJS::List &args ); + KJS::Value drawViewArea_45( KJS::ExecState *exec, KJS::Object &obj, const KJS::List &args ); + KJS::Value addItem_46( KJS::ExecState *exec, KJS::Object &obj, const KJS::List &args ); + KJS::Value addAnimation_47( KJS::ExecState *exec, KJS::Object &obj, const KJS::List &args ); + KJS::Value removeItem_48( KJS::ExecState *exec, KJS::Object &obj, const KJS::List &args ); + KJS::Value removeAnimation_49( KJS::ExecState *exec, KJS::Object &obj, const KJS::List &args ); + KJS::Value setAdvancePeriod_50( KJS::ExecState *exec, KJS::Object &obj, const KJS::List &args ); + KJS::Value setUpdatePeriod_51( KJS::ExecState *exec, KJS::Object &obj, const KJS::List &args ); + KJS::Value setDoubleBuffering_52( KJS::ExecState *exec, KJS::Object &obj, const KJS::List &args ); + + // + // JS binding code. + // + + /** Returns true iff this object implements the construct function. */ + virtual bool implementsConstruct() const { return cons; } + + /** Invokes the construct function. */ + virtual KJS::Object construct( KJS::ExecState *exec, const KJS::List &args ); + + /** Returns true iff this object implements the call function. */ + virtual bool implementsCall() const { return !cons; } + + /** Invokes the call function. */ + virtual KJS::Value call( KJS::ExecState *exec, KJS::Object &self, const KJS::List &args ); + +private: + QCanvas *instance; // Temp + int id; + bool cons; +}; + +} // namespace KJSEmbed + +#endif // KJSEMBED_QCanvas_H + +// Local Variables: +// c-basic-offset: 4 +// End: + + diff --git a/kjsembed/qtbindings/qcanvasellipse_imp.cpp b/kjsembed/qtbindings/qcanvasellipse_imp.cpp new file mode 100644 index 00000000..6c4fbff3 --- /dev/null +++ b/kjsembed/qtbindings/qcanvasellipse_imp.cpp @@ -0,0 +1,368 @@ + + + +#include <qcstring.h> +#include <qimage.h> +#include <qpainter.h> +#include <qpalette.h> +#include <qpixmap.h> +#include <qfont.h> + +#include <kjs/object.h> + +#include <kjsembed/global.h> +#include <kjsembed/jsobjectproxy.h> +#include <kjsembed/jsopaqueproxy.h> +#include <kjsembed/jsbinding.h> + +#include <qcanvas.h> +#include "qcanvasellipse_imp.h" + +/** + * Namespace containing the KJSEmbed library. + */ +namespace KJSEmbed { + +QCanvasEllipseImp::QCanvasEllipseImp( KJS::ExecState *exec, int mid, bool constructor ) + : JSProxyImp(exec), id(mid), cons(constructor) +{ +} + +QCanvasEllipseImp::~QCanvasEllipseImp() +{ +} + +/** + * Adds bindings for static methods and enum constants to the specified Object. + */ +void QCanvasEllipseImp::addStaticBindings( KJS::ExecState *exec, KJS::Object &object ) +{ + JSProxy::MethodTable methods[] = { + + { 0, 0 } + }; + + int idx = 0; + QCString lastName; + + while( methods[idx].name ) { + if ( lastName != methods[idx].name ) { + QCanvasEllipseImp *meth = new QCanvasEllipseImp( exec, methods[idx].id ); + object.put( exec , methods[idx].name, KJS::Object(meth) ); + lastName = methods[idx].name; + } + ++idx; + } + + +} + +/** + * Adds bindings for instance methods to the specified Object. + */ +void QCanvasEllipseImp::addBindings( KJS::ExecState *exec, KJS::Object &object ) +{ + JSProxy::MethodTable methods[] = { + + { Method_width_5, "width" }, + { Method_height_6, "height" }, + { Method_setSize_7, "setSize" }, + { Method_setAngles_8, "setAngles" }, + { Method_angleStart_9, "angleStart" }, + { Method_angleLength_10, "angleLength" }, + { Method_areaPoints_11, "areaPoints" }, + { Method_collidesWith_12, "collidesWith" }, + { Method_rtti_13, "rtti" }, + { 0, 0 } + }; + + int idx = 0; + QCString lastName; + + while( methods[idx].name ) { + if ( lastName != methods[idx].name ) { + QCanvasEllipseImp *meth = new QCanvasEllipseImp( exec, methods[idx].id ); + object.put( exec , methods[idx].name, KJS::Object(meth) ); + lastName = methods[idx].name; + } + ++idx; + } +} + +/** + * Extract a QCanvasEllipse pointer from an Object. + */ +QCanvasEllipse *QCanvasEllipseImp::toQCanvasEllipse( KJS::Object &self ) +{ + JSObjectProxy *ob = JSProxy::toObjectProxy( self.imp() ); + if ( ob ) { + QObject *obj = ob->object(); + if ( obj ) + return dynamic_cast<QCanvasEllipse *>( obj ); + } + + JSOpaqueProxy *op = JSProxy::toOpaqueProxy( self.imp() ); + if ( !op ) + return 0; + + if ( op->typeName() != "QCanvasEllipse" ) + return 0; + + return op->toNative<QCanvasEllipse>(); +} + +/** + * Select and invoke the correct constructor. + */ +KJS::Object QCanvasEllipseImp::construct( KJS::ExecState *exec, const KJS::List &args ) +{ + switch( id ) { + + case Constructor_QCanvasEllipse_1: + return QCanvasEllipse_1( exec, args ); + break; + + case Constructor_QCanvasEllipse_2: + return QCanvasEllipse_2( exec, args ); + break; + + case Constructor_QCanvasEllipse_3: + return QCanvasEllipse_3( exec, args ); + break; + + default: + break; + } + + QString msg = i18n("QCanvasEllipseCons has no constructor with id '%1'.").arg(id); + return throwError(exec, msg,KJS::ReferenceError); +} + + +KJS::Object QCanvasEllipseImp::QCanvasEllipse_1( KJS::ExecState *exec, const KJS::List &args ) +{ + + // Unsupported parameter QCanvas * + return KJS::Object(); + + QCanvas * arg0; // Dummy + + + // We should now create an instance of the QCanvasEllipse object + + QCanvasEllipse *ret = new QCanvasEllipse( + + arg0 ); + + +} + +KJS::Object QCanvasEllipseImp::QCanvasEllipse_2( KJS::ExecState *exec, const KJS::List &args ) +{ + + int arg0 = extractInt(exec, args, 0); + + int arg1 = extractInt(exec, args, 1); + + // Unsupported parameter QCanvas * + return KJS::Object(); + + QCanvas * arg2; // Dummy + + + // We should now create an instance of the QCanvasEllipse object + + QCanvasEllipse *ret = new QCanvasEllipse( + + arg0, + arg1, + arg2 ); + + +} + +KJS::Object QCanvasEllipseImp::QCanvasEllipse_3( KJS::ExecState *exec, const KJS::List &args ) +{ + + int arg0 = extractInt(exec, args, 0); + + int arg1 = extractInt(exec, args, 1); + + int arg2 = extractInt(exec, args, 2); + + int arg3 = extractInt(exec, args, 3); + + // Unsupported parameter QCanvas * + return KJS::Object(); + + QCanvas * arg4; // Dummy + + + // We should now create an instance of the QCanvasEllipse object + + QCanvasEllipse *ret = new QCanvasEllipse( + + arg0, + arg1, + arg2, + arg3, + arg4 ); + + +} + +KJS::Value QCanvasEllipseImp::call( KJS::ExecState *exec, KJS::Object &self, const KJS::List &args ) +{ + instance = QCanvasEllipseImp::toQCanvasEllipse( self ); + + switch( id ) { + + case Method_width_5: + return width_5( exec, self, args ); + break; + + case Method_height_6: + return height_6( exec, self, args ); + break; + + case Method_setSize_7: + return setSize_7( exec, self, args ); + break; + + case Method_setAngles_8: + return setAngles_8( exec, self, args ); + break; + + case Method_angleStart_9: + return angleStart_9( exec, self, args ); + break; + + case Method_angleLength_10: + return angleLength_10( exec, self, args ); + break; + + case Method_areaPoints_11: + return areaPoints_11( exec, self, args ); + break; + + case Method_collidesWith_12: + return collidesWith_12( exec, self, args ); + break; + + case Method_rtti_13: + return rtti_13( exec, self, args ); + break; + + default: + break; + } + + QString msg = i18n( "QCanvasEllipseImp has no method with id '%1'." ).arg( id ); + return throwError(exec, msg,KJS::ReferenceError); +} + + +KJS::Value QCanvasEllipseImp::width_5( KJS::ExecState *exec, KJS::Object &obj, const KJS::List &args ) +{ + + int ret; + ret = instance->width( ); + return KJS::Number( ret ); + +} + +KJS::Value QCanvasEllipseImp::height_6( KJS::ExecState *exec, KJS::Object &obj, const KJS::List &args ) +{ + + int ret; + ret = instance->height( ); + return KJS::Number( ret ); + +} + +KJS::Value QCanvasEllipseImp::setSize_7( KJS::ExecState *exec, KJS::Object &obj, const KJS::List &args ) +{ + + int arg0 = extractInt(exec, args, 0); + + int arg1 = extractInt(exec, args, 1); + + instance->setSize( + arg0, + arg1 ); + return KJS::Value(); // Returns void + +} + +KJS::Value QCanvasEllipseImp::setAngles_8( KJS::ExecState *exec, KJS::Object &obj, const KJS::List &args ) +{ + + int arg0 = extractInt(exec, args, 0); + + int arg1 = extractInt(exec, args, 1); + + instance->setAngles( + arg0, + arg1 ); + return KJS::Value(); // Returns void + +} + +KJS::Value QCanvasEllipseImp::angleStart_9( KJS::ExecState *exec, KJS::Object &obj, const KJS::List &args ) +{ + + int ret; + ret = instance->angleStart( ); + return KJS::Number( ret ); + +} + +KJS::Value QCanvasEllipseImp::angleLength_10( KJS::ExecState *exec, KJS::Object &obj, const KJS::List &args ) +{ + + int ret; + ret = instance->angleLength( ); + return KJS::Number( ret ); + +} + +KJS::Value QCanvasEllipseImp::areaPoints_11( KJS::ExecState *exec, KJS::Object &obj, const KJS::List &args ) +{ + + instance->areaPoints( ); + return KJS::Value(); // Returns 'QPointArray' + +} + +KJS::Value QCanvasEllipseImp::collidesWith_12( KJS::ExecState *exec, KJS::Object &obj, const KJS::List &args ) +{ + + // Unsupported parameter const QCanvasItem * + return KJS::Value(); + + const QCanvasItem * arg0; // Dummy + + bool ret; + ret = instance->collidesWith( + arg0 ); + return KJS::Boolean( ret ); + +} + +KJS::Value QCanvasEllipseImp::rtti_13( KJS::ExecState *exec, KJS::Object &obj, const KJS::List &args ) +{ + + int ret; + ret = instance->rtti( ); + return KJS::Number( ret ); + +} + + +} // namespace KJSEmbed + +// Local Variables: +// c-basic-offset: 4 +// End: + + diff --git a/kjsembed/qtbindings/qcanvasellipse_imp.h b/kjsembed/qtbindings/qcanvasellipse_imp.h new file mode 100644 index 00000000..052f41cf --- /dev/null +++ b/kjsembed/qtbindings/qcanvasellipse_imp.h @@ -0,0 +1,120 @@ + + + +#ifndef KJSEMBED_QCanvasEllipse_H +#define KJSEMBED_QCanvasEllipse_H + +#include <kjs/interpreter.h> +#include <kjs/object.h> + +#include <kjsembed/jsobjectproxy_imp.h> + +class QCanvasEllipse; + +/** + * Namespace containing the KJSEmbed library. + */ +namespace KJSEmbed { + +/** + * Wrapper class for QCanvasEllipse methods. + * + * @author Richard Moore, rich@kde.org + */ +class QCanvasEllipseImp : public JSProxyImp +{ +public: + /** Enumerates the constructors supported by this class. */ + enum Constructors { + Constructor_QCanvasEllipse_1, + Constructor_QCanvasEllipse_2, + Constructor_QCanvasEllipse_3, + + LastConstuctor = -1 + }; + + /** Enumerates the methods supported by this class. */ + enum Methods { + + Method_width_5, + Method_height_6, + Method_setSize_7, + Method_setAngles_8, + Method_angleStart_9, + Method_angleLength_10, + Method_areaPoints_11, + Method_collidesWith_12, + Method_rtti_13, + Method_Last = -1 + }; + + QCanvasEllipseImp( KJS::ExecState *exec, int id, bool constructor=false ); + ~QCanvasEllipseImp(); + + /** + * Adds the static bindings for this class to the specified Object. The + * static bindings are the static methods and the enums of this class. + */ + static void addStaticBindings( KJS::ExecState *exec, KJS::Object &object ); + + /** + * Adds the bindings for this class to the specified Object. The bindings + * added are the instance methods of this class. + */ + static void addBindings( KJS::ExecState *exec, KJS::Object &object ); + + static QCanvasEllipse *toQCanvasEllipse( KJS::Object &object ); + + // + // Constructors implemented by this class. + // + + KJS::Object QCanvasEllipse_1( KJS::ExecState *exec, const KJS::List &args ); + KJS::Object QCanvasEllipse_2( KJS::ExecState *exec, const KJS::List &args ); + KJS::Object QCanvasEllipse_3( KJS::ExecState *exec, const KJS::List &args ); + + // + // Methods implemented by this class. + // + + KJS::Value width_5( KJS::ExecState *exec, KJS::Object &obj, const KJS::List &args ); + KJS::Value height_6( KJS::ExecState *exec, KJS::Object &obj, const KJS::List &args ); + KJS::Value setSize_7( KJS::ExecState *exec, KJS::Object &obj, const KJS::List &args ); + KJS::Value setAngles_8( KJS::ExecState *exec, KJS::Object &obj, const KJS::List &args ); + KJS::Value angleStart_9( KJS::ExecState *exec, KJS::Object &obj, const KJS::List &args ); + KJS::Value angleLength_10( KJS::ExecState *exec, KJS::Object &obj, const KJS::List &args ); + KJS::Value areaPoints_11( KJS::ExecState *exec, KJS::Object &obj, const KJS::List &args ); + KJS::Value collidesWith_12( KJS::ExecState *exec, KJS::Object &obj, const KJS::List &args ); + KJS::Value rtti_13( KJS::ExecState *exec, KJS::Object &obj, const KJS::List &args ); + + // + // JS binding code. + // + + /** Returns true iff this object implements the construct function. */ + virtual bool implementsConstruct() const { return cons; } + + /** Invokes the construct function. */ + virtual KJS::Object construct( KJS::ExecState *exec, const KJS::List &args ); + + /** Returns true iff this object implements the call function. */ + virtual bool implementsCall() const { return !cons; } + + /** Invokes the call function. */ + virtual KJS::Value call( KJS::ExecState *exec, KJS::Object &self, const KJS::List &args ); + +private: + QCanvasEllipse *instance; // Temp + int id; + bool cons; +}; + +} // namespace KJSEmbed + +#endif // KJSEMBED_QCanvasEllipse_H + +// Local Variables: +// c-basic-offset: 4 +// End: + + diff --git a/kjsembed/qtbindings/qcanvasitem_imp.cpp b/kjsembed/qtbindings/qcanvasitem_imp.cpp new file mode 100644 index 00000000..f2e1c0e0 --- /dev/null +++ b/kjsembed/qtbindings/qcanvasitem_imp.cpp @@ -0,0 +1,790 @@ + + + +#include <qcstring.h> +#include <qimage.h> +#include <qpainter.h> +#include <qpalette.h> +#include <qpixmap.h> +#include <qfont.h> + +#include <kjs/object.h> + +#include <kjsembed/global.h> +#include <kjsembed/jsobjectproxy.h> +#include <kjsembed/jsopaqueproxy.h> +#include <kjsembed/jsbinding.h> + +#include <qcanvas.h> +#include "qcanvasitem_imp.h" + +/** + * Namespace containing the KJSEmbed library. + */ +namespace KJSEmbed { + +QCanvasItemImp::QCanvasItemImp( KJS::ExecState *exec, int mid, bool constructor ) + : JSProxyImp(exec), id(mid), cons(constructor) +{ +} + +QCanvasItemImp::~QCanvasItemImp() +{ +} + +/** + * Adds bindings for static methods and enum constants to the specified Object. + */ +void QCanvasItemImp::addStaticBindings( KJS::ExecState *exec, KJS::Object &object ) +{ + JSProxy::MethodTable methods[] = { + + { 0, 0 } + }; + + int idx = 0; + QCString lastName; + + while( methods[idx].name ) { + if ( lastName != methods[idx].name ) { + QCanvasItemImp *meth = new QCanvasItemImp( exec, methods[idx].id ); + object.put( exec , methods[idx].name, KJS::Object(meth) ); + lastName = methods[idx].name; + } + ++idx; + } + + + // + // Define the enum constants + // + struct EnumValue { + const char *id; + int val; + }; + + EnumValue enums[] = { + + // enum RttiValues + { "Rtti_Item", QCanvasItem::Rtti_Item }, + { "Rtti_Sprite", QCanvasItem::Rtti_Sprite }, + { "Rtti_PolygonalItem", QCanvasItem::Rtti_PolygonalItem }, + { "Rtti_Text", QCanvasItem::Rtti_Text }, + { "Rtti_Polygon", QCanvasItem::Rtti_Polygon }, + { "Rtti_Rectangle", QCanvasItem::Rtti_Rectangle }, + { "Rtti_Ellipse", QCanvasItem::Rtti_Ellipse }, + { "Rtti_Line", QCanvasItem::Rtti_Line }, + { "Rtti_Spline", QCanvasItem::Rtti_Spline }, + { 0, 0 } + }; + + int enumidx = 0; + while( enums[enumidx].id ) { + object.put( exec, enums[enumidx].id, KJS::Number(enums[enumidx].val), KJS::ReadOnly ); + ++enumidx; + } + +} + +/** + * Adds bindings for instance methods to the specified Object. + */ +void QCanvasItemImp::addBindings( KJS::ExecState *exec, KJS::Object &object ) +{ + JSProxy::MethodTable methods[] = { + + { Method_x_3, "x" }, + { Method_y_4, "y" }, + { Method_z_5, "z" }, + { Method_moveBy_6, "moveBy" }, + { Method_move_7, "move" }, + { Method_setX_8, "setX" }, + { Method_setY_9, "setY" }, + { Method_setZ_10, "setZ" }, + { Method_animated_11, "animated" }, + { Method_setAnimated_12, "setAnimated" }, + { Method_setVelocity_13, "setVelocity" }, + { Method_setXVelocity_14, "setXVelocity" }, + { Method_setYVelocity_15, "setYVelocity" }, + { Method_xVelocity_16, "xVelocity" }, + { Method_yVelocity_17, "yVelocity" }, + { Method_advance_18, "advance" }, + { Method_collidesWith_19, "collidesWith" }, + { Method_collisions_20, "collisions" }, + { Method_setCanvas_21, "setCanvas" }, + { Method_draw_22, "draw" }, + { Method_show_23, "show" }, + { Method_hide_24, "hide" }, + { Method_setVisible_25, "setVisible" }, + { Method_isVisible_26, "isVisible" }, + { Method_setSelected_27, "setSelected" }, + { Method_isSelected_28, "isSelected" }, + { Method_setEnabled_29, "setEnabled" }, + { Method_isEnabled_30, "isEnabled" }, + { Method_setActive_31, "setActive" }, + { Method_isActive_32, "isActive" }, + { Method_visible_33, "visible" }, + { Method_selected_34, "selected" }, + { Method_enabled_35, "enabled" }, + { Method_active_36, "active" }, + { Method_rtti_37, "rtti" }, + { Method_boundingRect_38, "boundingRect" }, + { Method_boundingRectAdvanced_39, "boundingRectAdvanced" }, + { Method_canvas_40, "canvas" }, + { 0, 0 } + }; + + int idx = 0; + QCString lastName; + + while( methods[idx].name ) { + if ( lastName != methods[idx].name ) { + QCanvasItemImp *meth = new QCanvasItemImp( exec, methods[idx].id ); + object.put( exec , methods[idx].name, KJS::Object(meth) ); + lastName = methods[idx].name; + } + ++idx; + } +} + +/** + * Extract a QCanvasItem pointer from an Object. + */ +QCanvasItem *QCanvasItemImp::toQCanvasItem( KJS::Object &self ) +{ + JSObjectProxy *ob = JSProxy::toObjectProxy( self.imp() ); + if ( ob ) { + QObject *obj = ob->object(); + if ( obj ) + return dynamic_cast<QCanvasItem *>( obj ); + } + + JSOpaqueProxy *op = JSProxy::toOpaqueProxy( self.imp() ); + if ( !op ) + return 0; +/* + if ( !op->inherits("QCanvasItem") ) { + kdDebug() << "Typename of opaque canvas item is " << op->typeName() << endl; + // Check superclasses + return 0; + } +*/ + return op->toNative<QCanvasItem>(); +} + +/** + * Select and invoke the correct constructor. + */ +KJS::Object QCanvasItemImp::construct( KJS::ExecState *exec, const KJS::List &args ) +{ + switch( id ) { + + case Constructor_QCanvasItem_1: + return QCanvasItem_1( exec, args ); + break; + + default: + break; + } + + QString msg = i18n("QCanvasItemCons has no constructor with id '%1'.").arg(id); + return throwError(exec, msg,KJS::ReferenceError); +} + + +KJS::Object QCanvasItemImp::QCanvasItem_1( KJS::ExecState *exec, const KJS::List &args ) +{ + +#if 0 // This constructor has been disabled by the XSL template + + // Unsupported parameter QCanvas * + return KJS::Object(); + + QCanvas * arg0; // Dummy + + + // We should now create an instance of the QCanvasItem object + + QCanvasItem *ret = new QCanvasItem( + + arg0 ); + + +#endif // This constructor has been disabled by the XSL template + return KJS::Object(); + +} + +KJS::Value QCanvasItemImp::call( KJS::ExecState *exec, KJS::Object &self, const KJS::List &args ) +{ + instance = QCanvasItemImp::toQCanvasItem( self ); + /* + if ( !instance ) + { + QString msg = i18n( "QCanvasItemImp was not valid" ); + return throwError(exec, msg,KJS::ReferenceError); + } + */ + + switch( id ) { + + case Method_x_3: + return x_3( exec, self, args ); + break; + + case Method_y_4: + return y_4( exec, self, args ); + break; + + case Method_z_5: + return z_5( exec, self, args ); + break; + + case Method_moveBy_6: + return moveBy_6( exec, self, args ); + break; + + case Method_move_7: + return move_7( exec, self, args ); + break; + + case Method_setX_8: + return setX_8( exec, self, args ); + break; + + case Method_setY_9: + return setY_9( exec, self, args ); + break; + + case Method_setZ_10: + return setZ_10( exec, self, args ); + break; + + case Method_animated_11: + return animated_11( exec, self, args ); + break; + + case Method_setAnimated_12: + return setAnimated_12( exec, self, args ); + break; + + case Method_setVelocity_13: + return setVelocity_13( exec, self, args ); + break; + + case Method_setXVelocity_14: + return setXVelocity_14( exec, self, args ); + break; + + case Method_setYVelocity_15: + return setYVelocity_15( exec, self, args ); + break; + + case Method_xVelocity_16: + return xVelocity_16( exec, self, args ); + break; + + case Method_yVelocity_17: + return yVelocity_17( exec, self, args ); + break; + + case Method_advance_18: + return advance_18( exec, self, args ); + break; + + case Method_collidesWith_19: + return collidesWith_19( exec, self, args ); + break; + + case Method_collisions_20: + return collisions_20( exec, self, args ); + break; + + case Method_setCanvas_21: + return setCanvas_21( exec, self, args ); + break; + + case Method_draw_22: + return draw_22( exec, self, args ); + break; + + case Method_show_23: + return show_23( exec, self, args ); + break; + + case Method_hide_24: + return hide_24( exec, self, args ); + break; + + case Method_setVisible_25: + return setVisible_25( exec, self, args ); + break; + + case Method_isVisible_26: + return isVisible_26( exec, self, args ); + break; + + case Method_setSelected_27: + return setSelected_27( exec, self, args ); + break; + + case Method_isSelected_28: + return isSelected_28( exec, self, args ); + break; + + case Method_setEnabled_29: + return setEnabled_29( exec, self, args ); + break; + + case Method_isEnabled_30: + return isEnabled_30( exec, self, args ); + break; + + case Method_setActive_31: + return setActive_31( exec, self, args ); + break; + + case Method_isActive_32: + return isActive_32( exec, self, args ); + break; + + case Method_visible_33: + return visible_33( exec, self, args ); + break; + + case Method_selected_34: + return selected_34( exec, self, args ); + break; + + case Method_enabled_35: + return enabled_35( exec, self, args ); + break; + + case Method_active_36: + return active_36( exec, self, args ); + break; + + case Method_rtti_37: + return rtti_37( exec, self, args ); + break; + + case Method_boundingRect_38: + return boundingRect_38( exec, self, args ); + break; + + case Method_boundingRectAdvanced_39: + return boundingRectAdvanced_39( exec, self, args ); + break; + + case Method_canvas_40: + return canvas_40( exec, self, args ); + break; + + default: + break; + } + + QString msg = i18n( "QCanvasItemImp has no method with id '%1'." ).arg( id ); + return throwError(exec, msg,KJS::ReferenceError); +} + + +KJS::Value QCanvasItemImp::x_3( KJS::ExecState *exec, KJS::Object &obj, const KJS::List &args ) +{ + + double ret; + ret = instance->x( ); + return KJS::Number( ret ); + +} + +KJS::Value QCanvasItemImp::y_4( KJS::ExecState *exec, KJS::Object &obj, const KJS::List &args ) +{ + + double ret; + ret = instance->y( ); + return KJS::Number( ret ); + +} + +KJS::Value QCanvasItemImp::z_5( KJS::ExecState *exec, KJS::Object &obj, const KJS::List &args ) +{ + + double ret; + ret = instance->z( ); + return KJS::Number( ret ); + +} + +KJS::Value QCanvasItemImp::moveBy_6( KJS::ExecState *exec, KJS::Object &obj, const KJS::List &args ) +{ + + double arg0 = extractDouble(exec, args, 0); + + double arg1 = extractDouble(exec, args, 1); + + instance->moveBy( + arg0, + arg1 ); + return KJS::Value(); // Returns void + +} + +KJS::Value QCanvasItemImp::move_7( KJS::ExecState *exec, KJS::Object &obj, const KJS::List &args ) +{ + + double arg0 = extractDouble(exec, args, 0); + + double arg1 = extractDouble(exec, args, 1); + + instance->move( + arg0, + arg1 ); + return KJS::Value(); // Returns void + +} + +KJS::Value QCanvasItemImp::setX_8( KJS::ExecState *exec, KJS::Object &obj, const KJS::List &args ) +{ + + double arg0 = extractDouble(exec, args, 0); + + instance->setX( + arg0 ); + return KJS::Value(); // Returns void + +} + +KJS::Value QCanvasItemImp::setY_9( KJS::ExecState *exec, KJS::Object &obj, const KJS::List &args ) +{ + + double arg0 = extractDouble(exec, args, 0); + + instance->setY( + arg0 ); + return KJS::Value(); // Returns void + +} + +KJS::Value QCanvasItemImp::setZ_10( KJS::ExecState *exec, KJS::Object &obj, const KJS::List &args ) +{ + + double arg0 = extractDouble(exec, args, 0); + + instance->setZ( + arg0 ); + return KJS::Value(); // Returns void + +} + +KJS::Value QCanvasItemImp::animated_11( KJS::ExecState *exec, KJS::Object &obj, const KJS::List &args ) +{ + + bool ret; + ret = instance->animated( ); + return KJS::Boolean( ret ); + +} + +KJS::Value QCanvasItemImp::setAnimated_12( KJS::ExecState *exec, KJS::Object &obj, const KJS::List &args ) +{ + + bool arg0 = extractBool(exec, args, 0); + + instance->setAnimated( + arg0 ); + return KJS::Value(); // Returns void + +} + +KJS::Value QCanvasItemImp::setVelocity_13( KJS::ExecState *exec, KJS::Object &obj, const KJS::List &args ) +{ + + double arg0 = extractDouble(exec, args, 0); + + double arg1 = extractDouble(exec, args, 1); + + instance->setVelocity( + arg0, + arg1 ); + return KJS::Value(); // Returns void + +} + +KJS::Value QCanvasItemImp::setXVelocity_14( KJS::ExecState *exec, KJS::Object &obj, const KJS::List &args ) +{ + + double arg0 = extractDouble(exec, args, 0); + + instance->setXVelocity( + arg0 ); + return KJS::Value(); // Returns void + +} + +KJS::Value QCanvasItemImp::setYVelocity_15( KJS::ExecState *exec, KJS::Object &obj, const KJS::List &args ) +{ + + double arg0 = extractDouble(exec, args, 0); + + instance->setYVelocity( + arg0 ); + return KJS::Value(); // Returns void + +} + +KJS::Value QCanvasItemImp::xVelocity_16( KJS::ExecState *exec, KJS::Object &obj, const KJS::List &args ) +{ + + double ret; + ret = instance->xVelocity( ); + return KJS::Number( ret ); + +} + +KJS::Value QCanvasItemImp::yVelocity_17( KJS::ExecState *exec, KJS::Object &obj, const KJS::List &args ) +{ + + double ret; + ret = instance->yVelocity( ); + return KJS::Number( ret ); + +} + +KJS::Value QCanvasItemImp::advance_18( KJS::ExecState *exec, KJS::Object &obj, const KJS::List &args ) +{ + + int arg0 = extractInt(exec, args, 0); + + instance->advance( + arg0 ); + return KJS::Value(); // Returns void + +} + +KJS::Value QCanvasItemImp::collidesWith_19( KJS::ExecState *exec, KJS::Object &obj, const KJS::List &args ) +{ + + // Unsupported parameter const QCanvasItem * + return KJS::Value(); + + const QCanvasItem * arg0; // Dummy + + bool ret; + ret = instance->collidesWith( + arg0 ); + return KJS::Boolean( ret ); + +} + +KJS::Value QCanvasItemImp::collisions_20( KJS::ExecState *exec, KJS::Object &obj, const KJS::List &args ) +{ + + bool arg0 = extractBool(exec, args, 0); + + instance->collisions( + arg0 ); + return KJS::Value(); // Returns 'QCanvasItemList' + +} + +KJS::Value QCanvasItemImp::setCanvas_21( KJS::ExecState *exec, KJS::Object &obj, const KJS::List &args ) +{ + + // Unsupported parameter QCanvas * + return KJS::Value(); + + QCanvas * arg0; // Dummy + + instance->setCanvas( + arg0 ); + return KJS::Value(); // Returns void + +} + +KJS::Value QCanvasItemImp::draw_22( KJS::ExecState *exec, KJS::Object &obj, const KJS::List &args ) +{ + + QPainter arg0; // TODO (hack for qcanvas) + + instance->draw( + arg0 ); + return KJS::Value(); // Returns void + +} + +KJS::Value QCanvasItemImp::show_23( KJS::ExecState *exec, KJS::Object &obj, const KJS::List &args ) +{ + + instance->show( ); + return KJS::Value(); // Returns void + +} + +KJS::Value QCanvasItemImp::hide_24( KJS::ExecState *exec, KJS::Object &obj, const KJS::List &args ) +{ + + instance->hide( ); + return KJS::Value(); // Returns void + +} + +KJS::Value QCanvasItemImp::setVisible_25( KJS::ExecState *exec, KJS::Object &obj, const KJS::List &args ) +{ + + bool arg0 = extractBool(exec, args, 0); + + instance->setVisible( + arg0 ); + return KJS::Value(); // Returns void + +} + +KJS::Value QCanvasItemImp::isVisible_26( KJS::ExecState *exec, KJS::Object &obj, const KJS::List &args ) +{ + + bool ret; + ret = instance->isVisible( ); + return KJS::Boolean( ret ); + +} + +KJS::Value QCanvasItemImp::setSelected_27( KJS::ExecState *exec, KJS::Object &obj, const KJS::List &args ) +{ + + bool arg0 = extractBool(exec, args, 0); + + instance->setSelected( + arg0 ); + return KJS::Value(); // Returns void + +} + +KJS::Value QCanvasItemImp::isSelected_28( KJS::ExecState *exec, KJS::Object &obj, const KJS::List &args ) +{ + + bool ret; + ret = instance->isSelected( ); + return KJS::Boolean( ret ); + +} + +KJS::Value QCanvasItemImp::setEnabled_29( KJS::ExecState *exec, KJS::Object &obj, const KJS::List &args ) +{ + + bool arg0 = extractBool(exec, args, 0); + + instance->setEnabled( + arg0 ); + return KJS::Value(); // Returns void + +} + +KJS::Value QCanvasItemImp::isEnabled_30( KJS::ExecState *exec, KJS::Object &obj, const KJS::List &args ) +{ + + bool ret; + ret = instance->isEnabled( ); + return KJS::Boolean( ret ); + +} + +KJS::Value QCanvasItemImp::setActive_31( KJS::ExecState *exec, KJS::Object &obj, const KJS::List &args ) +{ + + bool arg0 = extractBool(exec, args, 0); + + instance->setActive( + arg0 ); + return KJS::Value(); // Returns void + +} + +KJS::Value QCanvasItemImp::isActive_32( KJS::ExecState *exec, KJS::Object &obj, const KJS::List &args ) +{ + + bool ret; + ret = instance->isActive( ); + return KJS::Boolean( ret ); + +} + +KJS::Value QCanvasItemImp::visible_33( KJS::ExecState *exec, KJS::Object &obj, const KJS::List &args ) +{ + + bool ret; + ret = instance->visible( ); + return KJS::Boolean( ret ); + +} + +KJS::Value QCanvasItemImp::selected_34( KJS::ExecState *exec, KJS::Object &obj, const KJS::List &args ) +{ + + bool ret; + ret = instance->selected( ); + return KJS::Boolean( ret ); + +} + +KJS::Value QCanvasItemImp::enabled_35( KJS::ExecState *exec, KJS::Object &obj, const KJS::List &args ) +{ + + bool ret; + ret = instance->enabled( ); + return KJS::Boolean( ret ); + +} + +KJS::Value QCanvasItemImp::active_36( KJS::ExecState *exec, KJS::Object &obj, const KJS::List &args ) +{ + + bool ret; + ret = instance->active( ); + return KJS::Boolean( ret ); + +} + +KJS::Value QCanvasItemImp::rtti_37( KJS::ExecState *exec, KJS::Object &obj, const KJS::List &args ) +{ + + int ret; + ret = instance->rtti( ); + return KJS::Number( ret ); + +} + +KJS::Value QCanvasItemImp::boundingRect_38( KJS::ExecState *exec, KJS::Object &obj, const KJS::List &args ) +{ + QRect ret; + ret = instance->boundingRect( ); + + return convertToValue( exec, ret ); + +} + +KJS::Value QCanvasItemImp::boundingRectAdvanced_39( KJS::ExecState *exec, KJS::Object &obj, const KJS::List &args ) +{ + QRect ret; + ret = instance->boundingRectAdvanced( ); + + return convertToValue( exec, ret ); + +} + +KJS::Value QCanvasItemImp::canvas_40( KJS::ExecState *exec, KJS::Object &obj, const KJS::List &args ) +{ + + instance->canvas( ); + return KJS::Value(); // Returns 'QCanvas *' + +} + + +} // namespace KJSEmbed + +// Local Variables: +// c-basic-offset: 4 +// End: + + diff --git a/kjsembed/qtbindings/qcanvasitem_imp.h b/kjsembed/qtbindings/qcanvasitem_imp.h new file mode 100644 index 00000000..5af88785 --- /dev/null +++ b/kjsembed/qtbindings/qcanvasitem_imp.h @@ -0,0 +1,174 @@ + + + +#ifndef KJSEMBED_QCanvasItem_H +#define KJSEMBED_QCanvasItem_H + +#include <kjs/interpreter.h> +#include <kjs/object.h> + +#include <kjsembed/jsobjectproxy_imp.h> + +class QCanvasItem; + +/** + * Namespace containing the KJSEmbed library. + */ +namespace KJSEmbed { + +/** + * Wrapper class for QCanvasItem methods. + * + * @author Richard Moore, rich@kde.org + */ +class QCanvasItemImp : public JSProxyImp +{ +public: + /** Enumerates the constructors supported by this class. */ + enum Constructors { + Constructor_QCanvasItem_1, + + LastConstuctor = -1 + }; + + /** Enumerates the methods supported by this class. */ + enum Methods { + + Method_x_3, + Method_y_4, + Method_z_5, + Method_moveBy_6, + Method_move_7, + Method_setX_8, + Method_setY_9, + Method_setZ_10, + Method_animated_11, + Method_setAnimated_12, + Method_setVelocity_13, + Method_setXVelocity_14, + Method_setYVelocity_15, + Method_xVelocity_16, + Method_yVelocity_17, + Method_advance_18, + Method_collidesWith_19, + Method_collisions_20, + Method_setCanvas_21, + Method_draw_22, + Method_show_23, + Method_hide_24, + Method_setVisible_25, + Method_isVisible_26, + Method_setSelected_27, + Method_isSelected_28, + Method_setEnabled_29, + Method_isEnabled_30, + Method_setActive_31, + Method_isActive_32, + Method_visible_33, + Method_selected_34, + Method_enabled_35, + Method_active_36, + Method_rtti_37, + Method_boundingRect_38, + Method_boundingRectAdvanced_39, + Method_canvas_40, + Method_Last = -1 + }; + + QCanvasItemImp( KJS::ExecState *exec, int id, bool constructor=false ); + ~QCanvasItemImp(); + + /** + * Adds the static bindings for this class to the specified Object. The + * static bindings are the static methods and the enums of this class. + */ + static void addStaticBindings( KJS::ExecState *exec, KJS::Object &object ); + + /** + * Adds the bindings for this class to the specified Object. The bindings + * added are the instance methods of this class. + */ + static void addBindings( KJS::ExecState *exec, KJS::Object &object ); + + static QCanvasItem *toQCanvasItem( KJS::Object &object ); + + // + // Constructors implemented by this class. + // + + KJS::Object QCanvasItem_1( KJS::ExecState *exec, const KJS::List &args ); + + // + // Methods implemented by this class. + // + + KJS::Value x_3( KJS::ExecState *exec, KJS::Object &obj, const KJS::List &args ); + KJS::Value y_4( KJS::ExecState *exec, KJS::Object &obj, const KJS::List &args ); + KJS::Value z_5( KJS::ExecState *exec, KJS::Object &obj, const KJS::List &args ); + KJS::Value moveBy_6( KJS::ExecState *exec, KJS::Object &obj, const KJS::List &args ); + KJS::Value move_7( KJS::ExecState *exec, KJS::Object &obj, const KJS::List &args ); + KJS::Value setX_8( KJS::ExecState *exec, KJS::Object &obj, const KJS::List &args ); + KJS::Value setY_9( KJS::ExecState *exec, KJS::Object &obj, const KJS::List &args ); + KJS::Value setZ_10( KJS::ExecState *exec, KJS::Object &obj, const KJS::List &args ); + KJS::Value animated_11( KJS::ExecState *exec, KJS::Object &obj, const KJS::List &args ); + KJS::Value setAnimated_12( KJS::ExecState *exec, KJS::Object &obj, const KJS::List &args ); + KJS::Value setVelocity_13( KJS::ExecState *exec, KJS::Object &obj, const KJS::List &args ); + KJS::Value setXVelocity_14( KJS::ExecState *exec, KJS::Object &obj, const KJS::List &args ); + KJS::Value setYVelocity_15( KJS::ExecState *exec, KJS::Object &obj, const KJS::List &args ); + KJS::Value xVelocity_16( KJS::ExecState *exec, KJS::Object &obj, const KJS::List &args ); + KJS::Value yVelocity_17( KJS::ExecState *exec, KJS::Object &obj, const KJS::List &args ); + KJS::Value advance_18( KJS::ExecState *exec, KJS::Object &obj, const KJS::List &args ); + KJS::Value collidesWith_19( KJS::ExecState *exec, KJS::Object &obj, const KJS::List &args ); + KJS::Value collisions_20( KJS::ExecState *exec, KJS::Object &obj, const KJS::List &args ); + KJS::Value setCanvas_21( KJS::ExecState *exec, KJS::Object &obj, const KJS::List &args ); + KJS::Value draw_22( KJS::ExecState *exec, KJS::Object &obj, const KJS::List &args ); + KJS::Value show_23( KJS::ExecState *exec, KJS::Object &obj, const KJS::List &args ); + KJS::Value hide_24( KJS::ExecState *exec, KJS::Object &obj, const KJS::List &args ); + KJS::Value setVisible_25( KJS::ExecState *exec, KJS::Object &obj, const KJS::List &args ); + KJS::Value isVisible_26( KJS::ExecState *exec, KJS::Object &obj, const KJS::List &args ); + KJS::Value setSelected_27( KJS::ExecState *exec, KJS::Object &obj, const KJS::List &args ); + KJS::Value isSelected_28( KJS::ExecState *exec, KJS::Object &obj, const KJS::List &args ); + KJS::Value setEnabled_29( KJS::ExecState *exec, KJS::Object &obj, const KJS::List &args ); + KJS::Value isEnabled_30( KJS::ExecState *exec, KJS::Object &obj, const KJS::List &args ); + KJS::Value setActive_31( KJS::ExecState *exec, KJS::Object &obj, const KJS::List &args ); + KJS::Value isActive_32( KJS::ExecState *exec, KJS::Object &obj, const KJS::List &args ); + KJS::Value visible_33( KJS::ExecState *exec, KJS::Object &obj, const KJS::List &args ); + KJS::Value selected_34( KJS::ExecState *exec, KJS::Object &obj, const KJS::List &args ); + KJS::Value enabled_35( KJS::ExecState *exec, KJS::Object &obj, const KJS::List &args ); + KJS::Value active_36( KJS::ExecState *exec, KJS::Object &obj, const KJS::List &args ); + KJS::Value rtti_37( KJS::ExecState *exec, KJS::Object &obj, const KJS::List &args ); + KJS::Value boundingRect_38( KJS::ExecState *exec, KJS::Object &obj, const KJS::List &args ); + KJS::Value boundingRectAdvanced_39( KJS::ExecState *exec, KJS::Object &obj, const KJS::List &args ); + KJS::Value canvas_40( KJS::ExecState *exec, KJS::Object &obj, const KJS::List &args ); + + // + // JS binding code. + // + + /** Returns true iff this object implements the construct function. */ + virtual bool implementsConstruct() const { return cons; } + + /** Invokes the construct function. */ + virtual KJS::Object construct( KJS::ExecState *exec, const KJS::List &args ); + + /** Returns true iff this object implements the call function. */ + virtual bool implementsCall() const { return !cons; } + + /** Invokes the call function. */ + virtual KJS::Value call( KJS::ExecState *exec, KJS::Object &self, const KJS::List &args ); + +private: + QCanvasItem *instance; // Temp + int id; + bool cons; +}; + +} // namespace KJSEmbed + +#endif // KJSEMBED_QCanvasItem_H + +// Local Variables: +// c-basic-offset: 4 +// End: + + diff --git a/kjsembed/qtbindings/qcanvasitemlist_imp.cpp b/kjsembed/qtbindings/qcanvasitemlist_imp.cpp new file mode 100644 index 00000000..293aa5f3 --- /dev/null +++ b/kjsembed/qtbindings/qcanvasitemlist_imp.cpp @@ -0,0 +1,172 @@ + + + +#include <qcstring.h> +#include <qimage.h> +#include <qpainter.h> +#include <qpalette.h> +#include <qpixmap.h> +#include <qfont.h> + +#include <kjs/object.h> + +#include <kjsembed/global.h> +#include <kjsembed/jsobjectproxy.h> +#include <kjsembed/jsopaqueproxy.h> +#include <kjsembed/jsbinding.h> + +#include <qcanvas.h> +#include "qcanvasitemlist_imp.h" + +/** + * Namespace containing the KJSEmbed library. + */ +namespace KJSEmbed { + +QCanvasItemListImp::QCanvasItemListImp( KJS::ExecState *exec, int mid, bool constructor ) + : JSProxyImp(exec), id(mid), cons(constructor) +{ +} + +QCanvasItemListImp::~QCanvasItemListImp() +{ +} + +/** + * Adds bindings for static methods and enum constants to the specified Object. + */ +void QCanvasItemListImp::addStaticBindings( KJS::ExecState *exec, KJS::Object &object ) +{ + JSProxy::MethodTable methods[] = { + + { 0, 0 } + }; + + int idx = 0; + QCString lastName; + + while( methods[idx].name ) { + if ( lastName != methods[idx].name ) { + QCanvasItemListImp *meth = new QCanvasItemListImp( exec, methods[idx].id ); + object.put( exec , methods[idx].name, KJS::Object(meth) ); + lastName = methods[idx].name; + } + ++idx; + } + + +} + +/** + * Adds bindings for instance methods to the specified Object. + */ +void QCanvasItemListImp::addBindings( KJS::ExecState *exec, KJS::Object &object ) +{ + JSProxy::MethodTable methods[] = { + + { Method_sort_1, "sort" }, + { Method_drawUnique_2, "drawUnique" }, + { 0, 0 } + }; + + int idx = 0; + QCString lastName; + + while( methods[idx].name ) { + if ( lastName != methods[idx].name ) { + QCanvasItemListImp *meth = new QCanvasItemListImp( exec, methods[idx].id ); + object.put( exec , methods[idx].name, KJS::Object(meth) ); + lastName = methods[idx].name; + } + ++idx; + } +} + +/** + * Extract a QCanvasItemList pointer from an Object. + */ +QCanvasItemList *QCanvasItemListImp::toQCanvasItemList( KJS::Object &self ) +{ + JSObjectProxy *ob = JSProxy::toObjectProxy( self.imp() ); + if ( ob ) { + QObject *obj = ob->object(); + if ( obj ) + return dynamic_cast<QCanvasItemList *>( obj ); + } + + JSOpaqueProxy *op = JSProxy::toOpaqueProxy( self.imp() ); + if ( !op ) + return 0; + + if ( op->typeName() != "QCanvasItemList" ) + return 0; + + return op->toNative<QCanvasItemList>(); +} + +/** + * Select and invoke the correct constructor. + */ +KJS::Object QCanvasItemListImp::construct( KJS::ExecState *exec, const KJS::List &args ) +{ + switch( id ) { + + default: + break; + } + + QString msg = i18n("QCanvasItemListCons has no constructor with id '%1'.").arg(id); + return throwError(exec, msg,KJS::ReferenceError); +} + + +KJS::Value QCanvasItemListImp::call( KJS::ExecState *exec, KJS::Object &self, const KJS::List &args ) +{ + instance = QCanvasItemListImp::toQCanvasItemList( self ); + + switch( id ) { + + case Method_sort_1: + return sort_1( exec, self, args ); + break; + + case Method_drawUnique_2: + return drawUnique_2( exec, self, args ); + break; + + default: + break; + } + + QString msg = i18n( "QCanvasItemListImp has no method with id '%1'." ).arg( id ); + return throwError(exec, msg,KJS::ReferenceError); +} + + +KJS::Value QCanvasItemListImp::sort_1( KJS::ExecState *exec, KJS::Object &obj, const KJS::List &args ) +{ + + instance->sort( ); + return KJS::Value(); // Returns void + +} + +KJS::Value QCanvasItemListImp::drawUnique_2( KJS::ExecState *exec, KJS::Object &obj, const KJS::List &args ) +{ + + QPainter arg0; // TODO (hack for qcanvas) + + instance->drawUnique( + arg0 ); + return KJS::Value(); // Returns void + +} + + +} // namespace KJSEmbed + +// Local Variables: +// c-basic-offset: 4 +// End: + + diff --git a/kjsembed/qtbindings/qcanvasitemlist_imp.h b/kjsembed/qtbindings/qcanvasitemlist_imp.h new file mode 100644 index 00000000..dad12e1a --- /dev/null +++ b/kjsembed/qtbindings/qcanvasitemlist_imp.h @@ -0,0 +1,100 @@ + + + +#ifndef KJSEMBED_QCanvasItemList_H +#define KJSEMBED_QCanvasItemList_H + +#include <kjs/interpreter.h> +#include <kjs/object.h> + +#include <kjsembed/jsobjectproxy_imp.h> + +class QCanvasItemList; + +/** + * Namespace containing the KJSEmbed library. + */ +namespace KJSEmbed { + +/** + * Wrapper class for QCanvasItemList methods. + * + * @author Richard Moore, rich@kde.org + */ +class QCanvasItemListImp : public JSProxyImp +{ +public: + /** Enumerates the constructors supported by this class. */ + enum Constructors { + + LastConstuctor = -1 + }; + + /** Enumerates the methods supported by this class. */ + enum Methods { + + Method_sort_1, + Method_drawUnique_2, + Method_Last = -1 + }; + + QCanvasItemListImp( KJS::ExecState *exec, int id, bool constructor=false ); + ~QCanvasItemListImp(); + + /** + * Adds the static bindings for this class to the specified Object. The + * static bindings are the static methods and the enums of this class. + */ + static void addStaticBindings( KJS::ExecState *exec, KJS::Object &object ); + + /** + * Adds the bindings for this class to the specified Object. The bindings + * added are the instance methods of this class. + */ + static void addBindings( KJS::ExecState *exec, KJS::Object &object ); + + static QCanvasItemList *toQCanvasItemList( KJS::Object &object ); + + // + // Constructors implemented by this class. + // + + + // + // Methods implemented by this class. + // + + KJS::Value sort_1( KJS::ExecState *exec, KJS::Object &obj, const KJS::List &args ); + KJS::Value drawUnique_2( KJS::ExecState *exec, KJS::Object &obj, const KJS::List &args ); + + // + // JS binding code. + // + + /** Returns true iff this object implements the construct function. */ + virtual bool implementsConstruct() const { return cons; } + + /** Invokes the construct function. */ + virtual KJS::Object construct( KJS::ExecState *exec, const KJS::List &args ); + + /** Returns true iff this object implements the call function. */ + virtual bool implementsCall() const { return !cons; } + + /** Invokes the call function. */ + virtual KJS::Value call( KJS::ExecState *exec, KJS::Object &self, const KJS::List &args ); + +private: + QCanvasItemList *instance; // Temp + int id; + bool cons; +}; + +} // namespace KJSEmbed + +#endif // KJSEMBED_QCanvasItemList_H + +// Local Variables: +// c-basic-offset: 4 +// End: + + diff --git a/kjsembed/qtbindings/qcanvasline_imp.cpp b/kjsembed/qtbindings/qcanvasline_imp.cpp new file mode 100644 index 00000000..6ddf7c5d --- /dev/null +++ b/kjsembed/qtbindings/qcanvasline_imp.cpp @@ -0,0 +1,270 @@ + + + +#include <qcstring.h> +#include <qimage.h> +#include <qpainter.h> +#include <qpalette.h> +#include <qpixmap.h> +#include <qfont.h> + +#include <kjs/object.h> + +#include <kjsembed/global.h> +#include <kjsembed/jsobjectproxy.h> +#include <kjsembed/jsopaqueproxy.h> +#include <kjsembed/jsbinding.h> + +#include <qcanvas.h> +#include "qcanvasline_imp.h" + +/** + * Namespace containing the KJSEmbed library. + */ +namespace KJSEmbed { + +QCanvasLineImp::QCanvasLineImp( KJS::ExecState *exec, int mid, bool constructor ) + : JSProxyImp(exec), id(mid), cons(constructor) +{ +} + +QCanvasLineImp::~QCanvasLineImp() +{ +} + +/** + * Adds bindings for static methods and enum constants to the specified Object. + */ +void QCanvasLineImp::addStaticBindings( KJS::ExecState *exec, KJS::Object &object ) +{ + JSProxy::MethodTable methods[] = { + + { 0, 0 } + }; + + int idx = 0; + QCString lastName; + + while( methods[idx].name ) { + if ( lastName != methods[idx].name ) { + QCanvasLineImp *meth = new QCanvasLineImp( exec, methods[idx].id ); + object.put( exec , methods[idx].name, KJS::Object(meth) ); + lastName = methods[idx].name; + } + ++idx; + } + + +} + +/** + * Adds bindings for instance methods to the specified Object. + */ +void QCanvasLineImp::addBindings( KJS::ExecState *exec, KJS::Object &object ) +{ + JSProxy::MethodTable methods[] = { + + { Method_setPoints_3, "setPoints" }, + { Method_startPoint_4, "startPoint" }, + { Method_endPoint_5, "endPoint" }, + { Method_rtti_6, "rtti" }, + { Method_setPen_7, "setPen" }, + { Method_moveBy_8, "moveBy" }, + { 0, 0 } + }; + + int idx = 0; + QCString lastName; + + while( methods[idx].name ) { + if ( lastName != methods[idx].name ) { + QCanvasLineImp *meth = new QCanvasLineImp( exec, methods[idx].id ); + object.put( exec , methods[idx].name, KJS::Object(meth) ); + lastName = methods[idx].name; + } + ++idx; + } +} + +/** + * Extract a QCanvasLine pointer from an Object. + */ +QCanvasLine *QCanvasLineImp::toQCanvasLine( KJS::Object &self ) +{ + JSObjectProxy *ob = JSProxy::toObjectProxy( self.imp() ); + if ( ob ) { + QObject *obj = ob->object(); + if ( obj ) + return dynamic_cast<QCanvasLine *>( obj ); + } + + JSOpaqueProxy *op = JSProxy::toOpaqueProxy( self.imp() ); + if ( !op ) + return 0; + + if ( op->typeName() != "QCanvasLine" ) + return 0; + + return op->toNative<QCanvasLine>(); +} + +/** + * Select and invoke the correct constructor. + */ +KJS::Object QCanvasLineImp::construct( KJS::ExecState *exec, const KJS::List &args ) +{ + switch( id ) { + + case Constructor_QCanvasLine_1: + return QCanvasLine_1( exec, args ); + break; + + default: + break; + } + + QString msg = i18n("QCanvasLineCons has no constructor with id '%1'.").arg(id); + return throwError(exec, msg,KJS::ReferenceError); +} + + +KJS::Object QCanvasLineImp::QCanvasLine_1( KJS::ExecState *exec, const KJS::List &args ) +{ + + // Unsupported parameter QCanvas * + return KJS::Object(); + + QCanvas * arg0; // Dummy + + + // We should now create an instance of the QCanvasLine object + + QCanvasLine *ret = new QCanvasLine( + + arg0 ); + + +} + +KJS::Value QCanvasLineImp::call( KJS::ExecState *exec, KJS::Object &self, const KJS::List &args ) +{ + instance = QCanvasLineImp::toQCanvasLine( self ); + + switch( id ) { + + case Method_setPoints_3: + return setPoints_3( exec, self, args ); + break; + + case Method_startPoint_4: + return startPoint_4( exec, self, args ); + break; + + case Method_endPoint_5: + return endPoint_5( exec, self, args ); + break; + + case Method_rtti_6: + return rtti_6( exec, self, args ); + break; + + case Method_setPen_7: + return setPen_7( exec, self, args ); + break; + + case Method_moveBy_8: + return moveBy_8( exec, self, args ); + break; + + default: + break; + } + + QString msg = i18n( "QCanvasLineImp has no method with id '%1'." ).arg( id ); + return throwError(exec, msg,KJS::ReferenceError); +} + + +KJS::Value QCanvasLineImp::setPoints_3( KJS::ExecState *exec, KJS::Object &obj, const KJS::List &args ) +{ + + int arg0 = extractInt(exec, args, 0); + + int arg1 = extractInt(exec, args, 1); + + int arg2 = extractInt(exec, args, 2); + + int arg3 = extractInt(exec, args, 3); + + instance->setPoints( + arg0, + arg1, + arg2, + arg3 ); + return KJS::Value(); // Returns void + +} + +KJS::Value QCanvasLineImp::startPoint_4( KJS::ExecState *exec, KJS::Object &obj, const KJS::List &args ) +{ + QPoint ret; + ret = instance->startPoint( ); + + return convertToValue( exec, ret ); + +} + +KJS::Value QCanvasLineImp::endPoint_5( KJS::ExecState *exec, KJS::Object &obj, const KJS::List &args ) +{ + QPoint ret; + ret = instance->endPoint( ); + + return convertToValue( exec, ret ); + +} + +KJS::Value QCanvasLineImp::rtti_6( KJS::ExecState *exec, KJS::Object &obj, const KJS::List &args ) +{ + + int ret; + ret = instance->rtti( ); + return KJS::Number( ret ); + +} + +KJS::Value QCanvasLineImp::setPen_7( KJS::ExecState *exec, KJS::Object &obj, const KJS::List &args ) +{ + + // Unsupported parameter QPen + return KJS::Value(); + + QPen arg0; // Dummy + + instance->setPen( + arg0 ); + return KJS::Value(); // Returns void + +} + +KJS::Value QCanvasLineImp::moveBy_8( KJS::ExecState *exec, KJS::Object &obj, const KJS::List &args ) +{ + + double arg0 = extractDouble(exec, args, 0); + + double arg1 = extractDouble(exec, args, 1); + + instance->moveBy( + arg0, + arg1 ); + return KJS::Value(); // Returns void + +} + + +} // namespace KJSEmbed + +// Local Variables: +// c-basic-offset: 4 +// End: + + diff --git a/kjsembed/qtbindings/qcanvasline_imp.h b/kjsembed/qtbindings/qcanvasline_imp.h new file mode 100644 index 00000000..5ce51a7e --- /dev/null +++ b/kjsembed/qtbindings/qcanvasline_imp.h @@ -0,0 +1,110 @@ + + + +#ifndef KJSEMBED_QCanvasLine_H +#define KJSEMBED_QCanvasLine_H + +#include <kjs/interpreter.h> +#include <kjs/object.h> + +#include <kjsembed/jsobjectproxy_imp.h> + +class QCanvasLine; + +/** + * Namespace containing the KJSEmbed library. + */ +namespace KJSEmbed { + +/** + * Wrapper class for QCanvasLine methods. + * + * @author Richard Moore, rich@kde.org + */ +class QCanvasLineImp : public JSProxyImp +{ +public: + /** Enumerates the constructors supported by this class. */ + enum Constructors { + Constructor_QCanvasLine_1, + + LastConstuctor = -1 + }; + + /** Enumerates the methods supported by this class. */ + enum Methods { + + Method_setPoints_3, + Method_startPoint_4, + Method_endPoint_5, + Method_rtti_6, + Method_setPen_7, + Method_moveBy_8, + Method_Last = -1 + }; + + QCanvasLineImp( KJS::ExecState *exec, int id, bool constructor=false ); + ~QCanvasLineImp(); + + /** + * Adds the static bindings for this class to the specified Object. The + * static bindings are the static methods and the enums of this class. + */ + static void addStaticBindings( KJS::ExecState *exec, KJS::Object &object ); + + /** + * Adds the bindings for this class to the specified Object. The bindings + * added are the instance methods of this class. + */ + static void addBindings( KJS::ExecState *exec, KJS::Object &object ); + + static QCanvasLine *toQCanvasLine( KJS::Object &object ); + + // + // Constructors implemented by this class. + // + + KJS::Object QCanvasLine_1( KJS::ExecState *exec, const KJS::List &args ); + + // + // Methods implemented by this class. + // + + KJS::Value setPoints_3( KJS::ExecState *exec, KJS::Object &obj, const KJS::List &args ); + KJS::Value startPoint_4( KJS::ExecState *exec, KJS::Object &obj, const KJS::List &args ); + KJS::Value endPoint_5( KJS::ExecState *exec, KJS::Object &obj, const KJS::List &args ); + KJS::Value rtti_6( KJS::ExecState *exec, KJS::Object &obj, const KJS::List &args ); + KJS::Value setPen_7( KJS::ExecState *exec, KJS::Object &obj, const KJS::List &args ); + KJS::Value moveBy_8( KJS::ExecState *exec, KJS::Object &obj, const KJS::List &args ); + + // + // JS binding code. + // + + /** Returns true iff this object implements the construct function. */ + virtual bool implementsConstruct() const { return cons; } + + /** Invokes the construct function. */ + virtual KJS::Object construct( KJS::ExecState *exec, const KJS::List &args ); + + /** Returns true iff this object implements the call function. */ + virtual bool implementsCall() const { return !cons; } + + /** Invokes the call function. */ + virtual KJS::Value call( KJS::ExecState *exec, KJS::Object &self, const KJS::List &args ); + +private: + QCanvasLine *instance; // Temp + int id; + bool cons; +}; + +} // namespace KJSEmbed + +#endif // KJSEMBED_QCanvasLine_H + +// Local Variables: +// c-basic-offset: 4 +// End: + + diff --git a/kjsembed/qtbindings/qcanvaspixmap_imp.cpp b/kjsembed/qtbindings/qcanvaspixmap_imp.cpp new file mode 100644 index 00000000..846f90fc --- /dev/null +++ b/kjsembed/qtbindings/qcanvaspixmap_imp.cpp @@ -0,0 +1,252 @@ + + + +#include <qcstring.h> +#include <qimage.h> +#include <qpainter.h> +#include <qpalette.h> +#include <qpixmap.h> +#include <qfont.h> + +#include <kjs/object.h> + +#include <kjsembed/global.h> +#include <kjsembed/jsobjectproxy.h> +#include <kjsembed/jsopaqueproxy.h> +#include <kjsembed/jsbinding.h> + +#include <qcanvas.h> +#include "qcanvaspixmap_imp.h" + +/** + * Namespace containing the KJSEmbed library. + */ +namespace KJSEmbed { + +QCanvasPixmapImp::QCanvasPixmapImp( KJS::ExecState *exec, int mid, bool constructor ) + : JSProxyImp(exec), id(mid), cons(constructor) +{ +} + +QCanvasPixmapImp::~QCanvasPixmapImp() +{ +} + +/** + * Adds bindings for static methods and enum constants to the specified Object. + */ +void QCanvasPixmapImp::addStaticBindings( KJS::ExecState *exec, KJS::Object &object ) +{ + JSProxy::MethodTable methods[] = { + + { 0, 0 } + }; + + int idx = 0; + QCString lastName; + + while( methods[idx].name ) { + if ( lastName != methods[idx].name ) { + QCanvasPixmapImp *meth = new QCanvasPixmapImp( exec, methods[idx].id ); + object.put( exec , methods[idx].name, KJS::Object(meth) ); + lastName = methods[idx].name; + } + ++idx; + } + + +} + +/** + * Adds bindings for instance methods to the specified Object. + */ +void QCanvasPixmapImp::addBindings( KJS::ExecState *exec, KJS::Object &object ) +{ + JSProxy::MethodTable methods[] = { + + { Method_offsetX_5, "offsetX" }, + { Method_offsetY_6, "offsetY" }, + { Method_setOffset_7, "setOffset" }, + { 0, 0 } + }; + + int idx = 0; + QCString lastName; + + while( methods[idx].name ) { + if ( lastName != methods[idx].name ) { + QCanvasPixmapImp *meth = new QCanvasPixmapImp( exec, methods[idx].id ); + object.put( exec , methods[idx].name, KJS::Object(meth) ); + lastName = methods[idx].name; + } + ++idx; + } +} + +/** + * Extract a QCanvasPixmap pointer from an Object. + */ +QCanvasPixmap *QCanvasPixmapImp::toQCanvasPixmap( KJS::Object &self ) +{ + JSObjectProxy *ob = JSProxy::toObjectProxy( self.imp() ); + if ( ob ) { + QObject *obj = ob->object(); + if ( obj ) + return dynamic_cast<QCanvasPixmap *>( obj ); + } + + JSOpaqueProxy *op = JSProxy::toOpaqueProxy( self.imp() ); + if ( !op ) + return 0; + + if ( op->typeName() != "QCanvasPixmap" ) + return 0; + + return op->toNative<QCanvasPixmap>(); +} + +/** + * Select and invoke the correct constructor. + */ +KJS::Object QCanvasPixmapImp::construct( KJS::ExecState *exec, const KJS::List &args ) +{ + switch( id ) { + + case Constructor_QCanvasPixmap_1: + return QCanvasPixmap_1( exec, args ); + break; + + case Constructor_QCanvasPixmap_2: + return QCanvasPixmap_2( exec, args ); + break; + + case Constructor_QCanvasPixmap_3: + return QCanvasPixmap_3( exec, args ); + break; + + default: + break; + } + + QString msg = i18n("QCanvasPixmapCons has no constructor with id '%1'.").arg(id); + return throwError(exec, msg,KJS::ReferenceError); +} + + +KJS::Object QCanvasPixmapImp::QCanvasPixmap_1( KJS::ExecState *exec, const KJS::List &args ) +{ + + QString arg0 = extractQString(exec, args, 0); + + + // We should now create an instance of the QCanvasPixmap object + + QCanvasPixmap *ret = new QCanvasPixmap( + + arg0 ); + + return KJS::Object(); +} + +KJS::Object QCanvasPixmapImp::QCanvasPixmap_2( KJS::ExecState *exec, const KJS::List &args ) +{ + + QImage arg0 = extractQImage(exec, args, 0); + + + // We should now create an instance of the QCanvasPixmap object + + QCanvasPixmap *ret = new QCanvasPixmap( + + arg0 ); + + return KJS::Object(); + +} + +KJS::Object QCanvasPixmapImp::QCanvasPixmap_3( KJS::ExecState *exec, const KJS::List &args ) +{ + + QPixmap arg0 = extractQPixmap(exec, args, 0); + + QPoint arg1 = extractQPoint(exec, args, 1); + + + // We should now create an instance of the QCanvasPixmap object + + QCanvasPixmap *ret = new QCanvasPixmap( + + arg0, + arg1 ); + + return KJS::Object(); + +} + +KJS::Value QCanvasPixmapImp::call( KJS::ExecState *exec, KJS::Object &self, const KJS::List &args ) +{ + instance = QCanvasPixmapImp::toQCanvasPixmap( self ); + + switch( id ) { + + case Method_offsetX_5: + return offsetX_5( exec, self, args ); + break; + + case Method_offsetY_6: + return offsetY_6( exec, self, args ); + break; + + case Method_setOffset_7: + return setOffset_7( exec, self, args ); + break; + + default: + break; + } + + QString msg = i18n( "QCanvasPixmapImp has no method with id '%1'." ).arg( id ); + return throwError(exec, msg,KJS::ReferenceError); +} + + +KJS::Value QCanvasPixmapImp::offsetX_5( KJS::ExecState *exec, KJS::Object &obj, const KJS::List &args ) +{ + + int ret; + ret = instance->offsetX( ); + return KJS::Number( ret ); + +} + +KJS::Value QCanvasPixmapImp::offsetY_6( KJS::ExecState *exec, KJS::Object &obj, const KJS::List &args ) +{ + + int ret; + ret = instance->offsetY( ); + return KJS::Number( ret ); + +} + +KJS::Value QCanvasPixmapImp::setOffset_7( KJS::ExecState *exec, KJS::Object &obj, const KJS::List &args ) +{ + + int arg0 = extractInt(exec, args, 0); + + int arg1 = extractInt(exec, args, 1); + + instance->setOffset( + arg0, + arg1 ); + return KJS::Value(); // Returns void + +} + + +} // namespace KJSEmbed + +// Local Variables: +// c-basic-offset: 4 +// End: + + diff --git a/kjsembed/qtbindings/qcanvaspixmap_imp.h b/kjsembed/qtbindings/qcanvaspixmap_imp.h new file mode 100644 index 00000000..38f8be81 --- /dev/null +++ b/kjsembed/qtbindings/qcanvaspixmap_imp.h @@ -0,0 +1,108 @@ + + + +#ifndef KJSEMBED_QCanvasPixmap_H +#define KJSEMBED_QCanvasPixmap_H + +#include <kjs/interpreter.h> +#include <kjs/object.h> + +#include <kjsembed/jsobjectproxy_imp.h> + +class QCanvasPixmap; + +/** + * Namespace containing the KJSEmbed library. + */ +namespace KJSEmbed { + +/** + * Wrapper class for QCanvasPixmap methods. + * + * @author Richard Moore, rich@kde.org + */ +class QCanvasPixmapImp : public JSProxyImp +{ +public: + /** Enumerates the constructors supported by this class. */ + enum Constructors { + Constructor_QCanvasPixmap_1, + Constructor_QCanvasPixmap_2, + Constructor_QCanvasPixmap_3, + + LastConstuctor = -1 + }; + + /** Enumerates the methods supported by this class. */ + enum Methods { + + Method_offsetX_5, + Method_offsetY_6, + Method_setOffset_7, + Method_Last = -1 + }; + + QCanvasPixmapImp( KJS::ExecState *exec, int id, bool constructor=false ); + ~QCanvasPixmapImp(); + + /** + * Adds the static bindings for this class to the specified Object. The + * static bindings are the static methods and the enums of this class. + */ + static void addStaticBindings( KJS::ExecState *exec, KJS::Object &object ); + + /** + * Adds the bindings for this class to the specified Object. The bindings + * added are the instance methods of this class. + */ + static void addBindings( KJS::ExecState *exec, KJS::Object &object ); + + static QCanvasPixmap *toQCanvasPixmap( KJS::Object &object ); + + // + // Constructors implemented by this class. + // + + KJS::Object QCanvasPixmap_1( KJS::ExecState *exec, const KJS::List &args ); + KJS::Object QCanvasPixmap_2( KJS::ExecState *exec, const KJS::List &args ); + KJS::Object QCanvasPixmap_3( KJS::ExecState *exec, const KJS::List &args ); + + // + // Methods implemented by this class. + // + + KJS::Value offsetX_5( KJS::ExecState *exec, KJS::Object &obj, const KJS::List &args ); + KJS::Value offsetY_6( KJS::ExecState *exec, KJS::Object &obj, const KJS::List &args ); + KJS::Value setOffset_7( KJS::ExecState *exec, KJS::Object &obj, const KJS::List &args ); + + // + // JS binding code. + // + + /** Returns true iff this object implements the construct function. */ + virtual bool implementsConstruct() const { return cons; } + + /** Invokes the construct function. */ + virtual KJS::Object construct( KJS::ExecState *exec, const KJS::List &args ); + + /** Returns true iff this object implements the call function. */ + virtual bool implementsCall() const { return !cons; } + + /** Invokes the call function. */ + virtual KJS::Value call( KJS::ExecState *exec, KJS::Object &self, const KJS::List &args ); + +private: + QCanvasPixmap *instance; // Temp + int id; + bool cons; +}; + +} // namespace KJSEmbed + +#endif // KJSEMBED_QCanvasPixmap_H + +// Local Variables: +// c-basic-offset: 4 +// End: + + diff --git a/kjsembed/qtbindings/qcanvaspixmaparray_imp.cpp b/kjsembed/qtbindings/qcanvaspixmaparray_imp.cpp new file mode 100644 index 00000000..dbb41a18 --- /dev/null +++ b/kjsembed/qtbindings/qcanvaspixmaparray_imp.cpp @@ -0,0 +1,340 @@ + + + +#include <qcstring.h> +#include <qimage.h> +#include <qpainter.h> +#include <qpalette.h> +#include <qpixmap.h> +#include <qfont.h> + +#include <kjs/object.h> + +#include <kjsembed/global.h> +#include <kjsembed/jsobjectproxy.h> +#include <kjsembed/jsopaqueproxy.h> +#include <kjsembed/jsbinding.h> + +#include <qcanvas.h> +#include "qcanvaspixmaparray_imp.h" + +/** + * Namespace containing the KJSEmbed library. + */ +namespace KJSEmbed { + +QCanvasPixmapArrayImp::QCanvasPixmapArrayImp( KJS::ExecState *exec, int mid, bool constructor ) + : JSProxyImp(exec), id(mid), cons(constructor) +{ +} + +QCanvasPixmapArrayImp::~QCanvasPixmapArrayImp() +{ +} + +/** + * Adds bindings for static methods and enum constants to the specified Object. + */ +void QCanvasPixmapArrayImp::addStaticBindings( KJS::ExecState *exec, KJS::Object &object ) +{ + JSProxy::MethodTable methods[] = { + + { 0, 0 } + }; + + int idx = 0; + QCString lastName; + + while( methods[idx].name ) { + if ( lastName != methods[idx].name ) { + QCanvasPixmapArrayImp *meth = new QCanvasPixmapArrayImp( exec, methods[idx].id ); + object.put( exec , methods[idx].name, KJS::Object(meth) ); + lastName = methods[idx].name; + } + ++idx; + } + + +} + +/** + * Adds bindings for instance methods to the specified Object. + */ +void QCanvasPixmapArrayImp::addBindings( KJS::ExecState *exec, KJS::Object &object ) +{ + JSProxy::MethodTable methods[] = { + + { Method_readPixmaps_6, "readPixmaps" }, + { Method_readCollisionMasks_7, "readCollisionMasks" }, + { Method_isValid_9, "isValid" }, + { Method_image_10, "image" }, + { Method_setImage_11, "setImage" }, + { Method_count_12, "count" }, + { 0, 0 } + }; + + int idx = 0; + QCString lastName; + + while( methods[idx].name ) { + if ( lastName != methods[idx].name ) { + QCanvasPixmapArrayImp *meth = new QCanvasPixmapArrayImp( exec, methods[idx].id ); + object.put( exec , methods[idx].name, KJS::Object(meth) ); + lastName = methods[idx].name; + } + ++idx; + } +} + +/** + * Extract a QCanvasPixmapArray pointer from an Object. + */ +QCanvasPixmapArray *QCanvasPixmapArrayImp::toQCanvasPixmapArray( KJS::Object &self ) +{ + JSObjectProxy *ob = JSProxy::toObjectProxy( self.imp() ); + if ( ob ) { + QObject *obj = ob->object(); + if ( obj ) + return dynamic_cast<QCanvasPixmapArray *>( obj ); + } + + JSOpaqueProxy *op = JSProxy::toOpaqueProxy( self.imp() ); + if ( !op ) + return 0; + + if ( op->typeName() != "QCanvasPixmapArray" ) + return 0; + + return op->toNative<QCanvasPixmapArray>(); +} + +/** + * Select and invoke the correct constructor. + */ +KJS::Object QCanvasPixmapArrayImp::construct( KJS::ExecState *exec, const KJS::List &args ) +{ + switch( id ) { + + case Constructor_QCanvasPixmapArray_1: + return QCanvasPixmapArray_1( exec, args ); + break; + + case Constructor_QCanvasPixmapArray_2: + return QCanvasPixmapArray_2( exec, args ); + break; + + case Constructor_QCanvasPixmapArray_3: + return QCanvasPixmapArray_3( exec, args ); + break; + + case Constructor_QCanvasPixmapArray_4: + return QCanvasPixmapArray_4( exec, args ); + break; + + default: + break; + } + + QString msg = i18n("QCanvasPixmapArrayCons has no constructor with id '%1'.").arg(id); + return throwError(exec, msg,KJS::ReferenceError); +} + + +KJS::Object QCanvasPixmapArrayImp::QCanvasPixmapArray_1( KJS::ExecState *exec, const KJS::List &args ) +{ + + + // We should now create an instance of the QCanvasPixmapArray object + + QCanvasPixmapArray *ret = new QCanvasPixmapArray( + ); + + return KJS::Object(); +} + +KJS::Object QCanvasPixmapArrayImp::QCanvasPixmapArray_2( KJS::ExecState *exec, const KJS::List &args ) +{ + + QString arg0 = extractQString(exec, args, 0); + + int arg1 = extractInt(exec, args, 1); + + + // We should now create an instance of the QCanvasPixmapArray object + + QCanvasPixmapArray *ret = new QCanvasPixmapArray( + + arg0, + arg1 ); + return KJS::Object(); + +} + +KJS::Object QCanvasPixmapArrayImp::QCanvasPixmapArray_3( KJS::ExecState *exec, const KJS::List &args ) +{ + + // Unsupported parameter QPtrList< QPixmap > + return KJS::Object(); + + QPtrList< QPixmap > arg0; // Dummy + + // Unsupported parameter QPtrList< QPoint > + return KJS::Object(); + + QPtrList< QPoint > arg1; // Dummy + + + // We should now create an instance of the QCanvasPixmapArray object + + QCanvasPixmapArray *ret = new QCanvasPixmapArray( + + arg0, + arg1 ); + + +} + +KJS::Object QCanvasPixmapArrayImp::QCanvasPixmapArray_4( KJS::ExecState *exec, const KJS::List &args ) +{ + + // Unsupported parameter QValueList< QPixmap > + return KJS::Object(); + + QValueList< QPixmap > arg0; // Dummy + + // Unsupported parameter QPointArray + return KJS::Object(); + + QPointArray arg1; // Dummy + + + // We should now create an instance of the QCanvasPixmapArray object + + QCanvasPixmapArray *ret = new QCanvasPixmapArray( + + arg0, + arg1 ); + + +} + +KJS::Value QCanvasPixmapArrayImp::call( KJS::ExecState *exec, KJS::Object &self, const KJS::List &args ) +{ + instance = QCanvasPixmapArrayImp::toQCanvasPixmapArray( self ); + + switch( id ) { + + case Method_readPixmaps_6: + return readPixmaps_6( exec, self, args ); + break; + + case Method_readCollisionMasks_7: + return readCollisionMasks_7( exec, self, args ); + break; + + case Method_isValid_9: + return isValid_9( exec, self, args ); + break; + + case Method_image_10: + return image_10( exec, self, args ); + break; + + case Method_setImage_11: + return setImage_11( exec, self, args ); + break; + + case Method_count_12: + return count_12( exec, self, args ); + break; + + default: + break; + } + + QString msg = i18n( "QCanvasPixmapArrayImp has no method with id '%1'." ).arg( id ); + return throwError(exec, msg,KJS::ReferenceError); +} + + +KJS::Value QCanvasPixmapArrayImp::readPixmaps_6( KJS::ExecState *exec, KJS::Object &obj, const KJS::List &args ) +{ + + QString arg0 = extractQString(exec, args, 0); + + int arg1 = extractInt(exec, args, 1); + + bool ret; + ret = instance->readPixmaps( + arg0, + arg1 ); + return KJS::Boolean( ret ); + +} + +KJS::Value QCanvasPixmapArrayImp::readCollisionMasks_7( KJS::ExecState *exec, KJS::Object &obj, const KJS::List &args ) +{ + + QString arg0 = extractQString(exec, args, 0); + + bool ret; + ret = instance->readCollisionMasks( + arg0 ); + return KJS::Boolean( ret ); + +} + +KJS::Value QCanvasPixmapArrayImp::isValid_9( KJS::ExecState *exec, KJS::Object &obj, const KJS::List &args ) +{ + + bool ret; + ret = instance->isValid( ); + return KJS::Boolean( ret ); + +} + +KJS::Value QCanvasPixmapArrayImp::image_10( KJS::ExecState *exec, KJS::Object &obj, const KJS::List &args ) +{ + + int arg0 = extractInt(exec, args, 0); + + instance->image( + arg0 ); + return KJS::Value(); // Returns 'QCanvasPixmap *' + +} + +KJS::Value QCanvasPixmapArrayImp::setImage_11( KJS::ExecState *exec, KJS::Object &obj, const KJS::List &args ) +{ + + int arg0 = extractInt(exec, args, 0); + + // Unsupported parameter QCanvasPixmap * + return KJS::Value(); + + QCanvasPixmap * arg1; // Dummy + + instance->setImage( + arg0, + arg1 ); + return KJS::Value(); // Returns void + +} + +KJS::Value QCanvasPixmapArrayImp::count_12( KJS::ExecState *exec, KJS::Object &obj, const KJS::List &args ) +{ + + uint ret; + ret = instance->count( ); + return KJS::Number( ret ); + +} + + +} // namespace KJSEmbed + +// Local Variables: +// c-basic-offset: 4 +// End: + + diff --git a/kjsembed/qtbindings/qcanvaspixmaparray_imp.h b/kjsembed/qtbindings/qcanvaspixmaparray_imp.h new file mode 100644 index 00000000..2b37d93a --- /dev/null +++ b/kjsembed/qtbindings/qcanvaspixmaparray_imp.h @@ -0,0 +1,116 @@ + + + +#ifndef KJSEMBED_QCanvasPixmapArray_H +#define KJSEMBED_QCanvasPixmapArray_H + +#include <kjs/interpreter.h> +#include <kjs/object.h> + +#include <kjsembed/jsobjectproxy_imp.h> + +class QCanvasPixmapArray; + +/** + * Namespace containing the KJSEmbed library. + */ +namespace KJSEmbed { + +/** + * Wrapper class for QCanvasPixmapArray methods. + * + * @author Richard Moore, rich@kde.org + */ +class QCanvasPixmapArrayImp : public JSProxyImp +{ +public: + /** Enumerates the constructors supported by this class. */ + enum Constructors { + Constructor_QCanvasPixmapArray_1, + Constructor_QCanvasPixmapArray_2, + Constructor_QCanvasPixmapArray_3, + Constructor_QCanvasPixmapArray_4, + + LastConstuctor = -1 + }; + + /** Enumerates the methods supported by this class. */ + enum Methods { + + Method_readPixmaps_6, + Method_readCollisionMasks_7, + Method_isValid_9, + Method_image_10, + Method_setImage_11, + Method_count_12, + Method_Last = -1 + }; + + QCanvasPixmapArrayImp( KJS::ExecState *exec, int id, bool constructor=false ); + ~QCanvasPixmapArrayImp(); + + /** + * Adds the static bindings for this class to the specified Object. The + * static bindings are the static methods and the enums of this class. + */ + static void addStaticBindings( KJS::ExecState *exec, KJS::Object &object ); + + /** + * Adds the bindings for this class to the specified Object. The bindings + * added are the instance methods of this class. + */ + static void addBindings( KJS::ExecState *exec, KJS::Object &object ); + + static QCanvasPixmapArray *toQCanvasPixmapArray( KJS::Object &object ); + + // + // Constructors implemented by this class. + // + + KJS::Object QCanvasPixmapArray_1( KJS::ExecState *exec, const KJS::List &args ); + KJS::Object QCanvasPixmapArray_2( KJS::ExecState *exec, const KJS::List &args ); + KJS::Object QCanvasPixmapArray_3( KJS::ExecState *exec, const KJS::List &args ); + KJS::Object QCanvasPixmapArray_4( KJS::ExecState *exec, const KJS::List &args ); + + // + // Methods implemented by this class. + // + + KJS::Value readPixmaps_6( KJS::ExecState *exec, KJS::Object &obj, const KJS::List &args ); + KJS::Value readCollisionMasks_7( KJS::ExecState *exec, KJS::Object &obj, const KJS::List &args ); + KJS::Value isValid_9( KJS::ExecState *exec, KJS::Object &obj, const KJS::List &args ); + KJS::Value image_10( KJS::ExecState *exec, KJS::Object &obj, const KJS::List &args ); + KJS::Value setImage_11( KJS::ExecState *exec, KJS::Object &obj, const KJS::List &args ); + KJS::Value count_12( KJS::ExecState *exec, KJS::Object &obj, const KJS::List &args ); + + // + // JS binding code. + // + + /** Returns true iff this object implements the construct function. */ + virtual bool implementsConstruct() const { return cons; } + + /** Invokes the construct function. */ + virtual KJS::Object construct( KJS::ExecState *exec, const KJS::List &args ); + + /** Returns true iff this object implements the call function. */ + virtual bool implementsCall() const { return !cons; } + + /** Invokes the call function. */ + virtual KJS::Value call( KJS::ExecState *exec, KJS::Object &self, const KJS::List &args ); + +private: + QCanvasPixmapArray *instance; // Temp + int id; + bool cons; +}; + +} // namespace KJSEmbed + +#endif // KJSEMBED_QCanvasPixmapArray_H + +// Local Variables: +// c-basic-offset: 4 +// End: + + diff --git a/kjsembed/qtbindings/qcanvaspolygon_imp.cpp b/kjsembed/qtbindings/qcanvaspolygon_imp.cpp new file mode 100644 index 00000000..d735fd7a --- /dev/null +++ b/kjsembed/qtbindings/qcanvaspolygon_imp.cpp @@ -0,0 +1,243 @@ + + + +#include <qcstring.h> +#include <qimage.h> +#include <qpainter.h> +#include <qpalette.h> +#include <qpixmap.h> +#include <qfont.h> + +#include <kjs/object.h> + +#include <kjsembed/global.h> +#include <kjsembed/jsobjectproxy.h> +#include <kjsembed/jsopaqueproxy.h> +#include <kjsembed/jsbinding.h> + +#include <qcanvas.h> +#include "qcanvaspolygon_imp.h" + +/** + * Namespace containing the KJSEmbed library. + */ +namespace KJSEmbed { + +QCanvasPolygonImp::QCanvasPolygonImp( KJS::ExecState *exec, int mid, bool constructor ) + : JSProxyImp(exec), id(mid), cons(constructor) +{ +} + +QCanvasPolygonImp::~QCanvasPolygonImp() +{ +} + +/** + * Adds bindings for static methods and enum constants to the specified Object. + */ +void QCanvasPolygonImp::addStaticBindings( KJS::ExecState *exec, KJS::Object &object ) +{ + JSProxy::MethodTable methods[] = { + + { 0, 0 } + }; + + int idx = 0; + QCString lastName; + + while( methods[idx].name ) { + if ( lastName != methods[idx].name ) { + QCanvasPolygonImp *meth = new QCanvasPolygonImp( exec, methods[idx].id ); + object.put( exec , methods[idx].name, KJS::Object(meth) ); + lastName = methods[idx].name; + } + ++idx; + } + + +} + +/** + * Adds bindings for instance methods to the specified Object. + */ +void QCanvasPolygonImp::addBindings( KJS::ExecState *exec, KJS::Object &object ) +{ + JSProxy::MethodTable methods[] = { + + { Method_setPoints_3, "setPoints" }, + { Method_points_4, "points" }, + { Method_moveBy_5, "moveBy" }, + { Method_areaPoints_6, "areaPoints" }, + { Method_rtti_7, "rtti" }, + { 0, 0 } + }; + + int idx = 0; + QCString lastName; + + while( methods[idx].name ) { + if ( lastName != methods[idx].name ) { + QCanvasPolygonImp *meth = new QCanvasPolygonImp( exec, methods[idx].id ); + object.put( exec , methods[idx].name, KJS::Object(meth) ); + lastName = methods[idx].name; + } + ++idx; + } +} + +/** + * Extract a QCanvasPolygon pointer from an Object. + */ +QCanvasPolygon *QCanvasPolygonImp::toQCanvasPolygon( KJS::Object &self ) +{ + JSObjectProxy *ob = JSProxy::toObjectProxy( self.imp() ); + if ( ob ) { + QObject *obj = ob->object(); + if ( obj ) + return dynamic_cast<QCanvasPolygon *>( obj ); + } + + JSOpaqueProxy *op = JSProxy::toOpaqueProxy( self.imp() ); + if ( !op ) + return 0; + + if ( op->typeName() != "QCanvasPolygon" ) + return 0; + + return op->toNative<QCanvasPolygon>(); +} + +/** + * Select and invoke the correct constructor. + */ +KJS::Object QCanvasPolygonImp::construct( KJS::ExecState *exec, const KJS::List &args ) +{ + switch( id ) { + + case Constructor_QCanvasPolygon_1: + return QCanvasPolygon_1( exec, args ); + break; + + default: + break; + } + + QString msg = i18n("QCanvasPolygonCons has no constructor with id '%1',").arg(id); + return throwError(exec, msg,KJS::ReferenceError); +} + + +KJS::Object QCanvasPolygonImp::QCanvasPolygon_1( KJS::ExecState *exec, const KJS::List &args ) +{ + + // Unsupported parameter QCanvas * + return KJS::Object(); + + QCanvas * arg0; // Dummy + + + // We should now create an instance of the QCanvasPolygon object + + QCanvasPolygon *ret = new QCanvasPolygon( + + arg0 ); + + +} + +KJS::Value QCanvasPolygonImp::call( KJS::ExecState *exec, KJS::Object &self, const KJS::List &args ) +{ + instance = QCanvasPolygonImp::toQCanvasPolygon( self ); + + switch( id ) { + + case Method_setPoints_3: + return setPoints_3( exec, self, args ); + break; + + case Method_points_4: + return points_4( exec, self, args ); + break; + + case Method_moveBy_5: + return moveBy_5( exec, self, args ); + break; + + case Method_areaPoints_6: + return areaPoints_6( exec, self, args ); + break; + + case Method_rtti_7: + return rtti_7( exec, self, args ); + break; + + default: + break; + } + + QString msg = i18n( "QCanvasPolygonImp has no method with id '%1'." ).arg( id ); + return throwError(exec, msg,KJS::ReferenceError); +} + + +KJS::Value QCanvasPolygonImp::setPoints_3( KJS::ExecState *exec, KJS::Object &obj, const KJS::List &args ) +{ + + // Unsupported parameter QPointArray + return KJS::Value(); + + QPointArray arg0; // Dummy + + instance->setPoints( + arg0 ); + return KJS::Value(); // Returns void + +} + +KJS::Value QCanvasPolygonImp::points_4( KJS::ExecState *exec, KJS::Object &obj, const KJS::List &args ) +{ + + instance->points( ); + return KJS::Value(); // Returns 'QPointArray' + +} + +KJS::Value QCanvasPolygonImp::moveBy_5( KJS::ExecState *exec, KJS::Object &obj, const KJS::List &args ) +{ + + double arg0 = extractDouble(exec, args, 0); + + double arg1 = extractDouble(exec, args, 1); + + instance->moveBy( + arg0, + arg1 ); + return KJS::Value(); // Returns void + +} + +KJS::Value QCanvasPolygonImp::areaPoints_6( KJS::ExecState *exec, KJS::Object &obj, const KJS::List &args ) +{ + + instance->areaPoints( ); + return KJS::Value(); // Returns 'QPointArray' + +} + +KJS::Value QCanvasPolygonImp::rtti_7( KJS::ExecState *exec, KJS::Object &obj, const KJS::List &args ) +{ + + int ret; + ret = instance->rtti( ); + return KJS::Number( ret ); + +} + + +} // namespace KJSEmbed + +// Local Variables: +// c-basic-offset: 4 +// End: + + diff --git a/kjsembed/qtbindings/qcanvaspolygon_imp.h b/kjsembed/qtbindings/qcanvaspolygon_imp.h new file mode 100644 index 00000000..0e1e3255 --- /dev/null +++ b/kjsembed/qtbindings/qcanvaspolygon_imp.h @@ -0,0 +1,108 @@ + + + +#ifndef KJSEMBED_QCanvasPolygon_H +#define KJSEMBED_QCanvasPolygon_H + +#include <kjs/interpreter.h> +#include <kjs/object.h> + +#include <kjsembed/jsobjectproxy_imp.h> + +class QCanvasPolygon; + +/** + * Namespace containing the KJSEmbed library. + */ +namespace KJSEmbed { + +/** + * Wrapper class for QCanvasPolygon methods. + * + * @author Richard Moore, rich@kde.org + */ +class QCanvasPolygonImp : public JSProxyImp +{ +public: + /** Enumerates the constructors supported by this class. */ + enum Constructors { + Constructor_QCanvasPolygon_1, + + LastConstuctor = -1 + }; + + /** Enumerates the methods supported by this class. */ + enum Methods { + + Method_setPoints_3, + Method_points_4, + Method_moveBy_5, + Method_areaPoints_6, + Method_rtti_7, + Method_Last = -1 + }; + + QCanvasPolygonImp( KJS::ExecState *exec, int id, bool constructor=false ); + ~QCanvasPolygonImp(); + + /** + * Adds the static bindings for this class to the specified Object. The + * static bindings are the static methods and the enums of this class. + */ + static void addStaticBindings( KJS::ExecState *exec, KJS::Object &object ); + + /** + * Adds the bindings for this class to the specified Object. The bindings + * added are the instance methods of this class. + */ + static void addBindings( KJS::ExecState *exec, KJS::Object &object ); + + static QCanvasPolygon *toQCanvasPolygon( KJS::Object &object ); + + // + // Constructors implemented by this class. + // + + KJS::Object QCanvasPolygon_1( KJS::ExecState *exec, const KJS::List &args ); + + // + // Methods implemented by this class. + // + + KJS::Value setPoints_3( KJS::ExecState *exec, KJS::Object &obj, const KJS::List &args ); + KJS::Value points_4( KJS::ExecState *exec, KJS::Object &obj, const KJS::List &args ); + KJS::Value moveBy_5( KJS::ExecState *exec, KJS::Object &obj, const KJS::List &args ); + KJS::Value areaPoints_6( KJS::ExecState *exec, KJS::Object &obj, const KJS::List &args ); + KJS::Value rtti_7( KJS::ExecState *exec, KJS::Object &obj, const KJS::List &args ); + + // + // JS binding code. + // + + /** Returns true iff this object implements the construct function. */ + virtual bool implementsConstruct() const { return cons; } + + /** Invokes the construct function. */ + virtual KJS::Object construct( KJS::ExecState *exec, const KJS::List &args ); + + /** Returns true iff this object implements the call function. */ + virtual bool implementsCall() const { return !cons; } + + /** Invokes the call function. */ + virtual KJS::Value call( KJS::ExecState *exec, KJS::Object &self, const KJS::List &args ); + +private: + QCanvasPolygon *instance; // Temp + int id; + bool cons; +}; + +} // namespace KJSEmbed + +#endif // KJSEMBED_QCanvasPolygon_H + +// Local Variables: +// c-basic-offset: 4 +// End: + + diff --git a/kjsembed/qtbindings/qcanvaspolygonalitem_imp.cpp b/kjsembed/qtbindings/qcanvaspolygonalitem_imp.cpp new file mode 100644 index 00000000..325260ba --- /dev/null +++ b/kjsembed/qtbindings/qcanvaspolygonalitem_imp.cpp @@ -0,0 +1,309 @@ + + + +#include <qcstring.h> +#include <qimage.h> +#include <qpainter.h> +#include <qpalette.h> +#include <qpixmap.h> +#include <qfont.h> + +#include <kjs/object.h> + +#include <kjsembed/global.h> +#include <kjsembed/jsobjectproxy.h> +#include <kjsembed/jsopaqueproxy.h> +#include <kjsembed/jsbinding.h> + +#include <qcanvas.h> +#include "qcanvaspolygonalitem_imp.h" + +/** + * Namespace containing the KJSEmbed library. + */ +namespace KJSEmbed { + +QCanvasPolygonalItemImp::QCanvasPolygonalItemImp( KJS::ExecState *exec, int mid, bool constructor ) + : JSProxyImp(exec), id(mid), cons(constructor) +{ +} + +QCanvasPolygonalItemImp::~QCanvasPolygonalItemImp() +{ +} + +/** + * Adds bindings for static methods and enum constants to the specified Object. + */ +void QCanvasPolygonalItemImp::addStaticBindings( KJS::ExecState *exec, KJS::Object &object ) +{ + JSProxy::MethodTable methods[] = { + + { 0, 0 } + }; + + int idx = 0; + QCString lastName; + + while( methods[idx].name ) { + if ( lastName != methods[idx].name ) { + QCanvasPolygonalItemImp *meth = new QCanvasPolygonalItemImp( exec, methods[idx].id ); + object.put( exec , methods[idx].name, KJS::Object(meth) ); + lastName = methods[idx].name; + } + ++idx; + } + + +} + +/** + * Adds bindings for instance methods to the specified Object. + */ +void QCanvasPolygonalItemImp::addBindings( KJS::ExecState *exec, KJS::Object &object ) +{ + JSProxy::MethodTable methods[] = { + + { Method_collidesWith_3, "collidesWith" }, + { Method_setPen_4, "setPen" }, + { Method_setBrush_5, "setBrush" }, + { Method_pen_6, "pen" }, + { Method_brush_7, "brush" }, + { Method_areaPoints_8, "areaPoints" }, + { Method_areaPointsAdvanced_9, "areaPointsAdvanced" }, + { Method_boundingRect_10, "boundingRect" }, + { Method_rtti_11, "rtti" }, + { 0, 0 } + }; + + int idx = 0; + QCString lastName; + + while( methods[idx].name ) { + if ( lastName != methods[idx].name ) { + QCanvasPolygonalItemImp *meth = new QCanvasPolygonalItemImp( exec, methods[idx].id ); + object.put( exec , methods[idx].name, KJS::Object(meth) ); + lastName = methods[idx].name; + } + ++idx; + } +} + +/** + * Extract a QCanvasPolygonalItem pointer from an Object. + */ +QCanvasPolygonalItem *QCanvasPolygonalItemImp::toQCanvasPolygonalItem( KJS::Object &self ) +{ + JSObjectProxy *ob = JSProxy::toObjectProxy( self.imp() ); + if ( ob ) { + QObject *obj = ob->object(); + if ( obj ) + return dynamic_cast<QCanvasPolygonalItem *>( obj ); + } + + JSOpaqueProxy *op = JSProxy::toOpaqueProxy( self.imp() ); + if ( !op ) + return 0; + + if ( op->typeName() != "QCanvasPolygonalItem" ) + return 0; + + return op->toNative<QCanvasPolygonalItem>(); +} + +/** + * Select and invoke the correct constructor. + */ +KJS::Object QCanvasPolygonalItemImp::construct( KJS::ExecState *exec, const KJS::List &args ) +{ + switch( id ) { + + case Constructor_QCanvasPolygonalItem_1: + return QCanvasPolygonalItem_1( exec, args ); + break; + + default: + break; + } + + QString msg = i18n("QCanvasPolygonalItemCons has no constructor with id '%1'.").arg(id); + return throwError(exec, msg,KJS::ReferenceError); +} + + +KJS::Object QCanvasPolygonalItemImp::QCanvasPolygonalItem_1( KJS::ExecState *exec, const KJS::List &args ) +{ + +#if 0 // This constructor has been disabled by the XSL template + + // Unsupported parameter QCanvas * + return KJS::Object(); + + QCanvas * arg0; // Dummy + + + // We should now create an instance of the QCanvasPolygonalItem object + + QCanvasPolygonalItem *ret = new QCanvasPolygonalItem( + + arg0 ); + + +#endif // This constructor has been disabled by the XSL template + return KJS::Object(); +} + +KJS::Value QCanvasPolygonalItemImp::call( KJS::ExecState *exec, KJS::Object &self, const KJS::List &args ) +{ + instance = QCanvasPolygonalItemImp::toQCanvasPolygonalItem( self ); + + switch( id ) { + + case Method_collidesWith_3: + return collidesWith_3( exec, self, args ); + break; + + case Method_setPen_4: + return setPen_4( exec, self, args ); + break; + + case Method_setBrush_5: + return setBrush_5( exec, self, args ); + break; + + case Method_pen_6: + return pen_6( exec, self, args ); + break; + + case Method_brush_7: + return brush_7( exec, self, args ); + break; + + case Method_areaPoints_8: + return areaPoints_8( exec, self, args ); + break; + + case Method_areaPointsAdvanced_9: + return areaPointsAdvanced_9( exec, self, args ); + break; + + case Method_boundingRect_10: + return boundingRect_10( exec, self, args ); + break; + + case Method_rtti_11: + return rtti_11( exec, self, args ); + break; + + default: + break; + } + + QString msg = i18n( "QCanvasPolygonalItemImp has no method with id '%1'." ).arg( id ); + return throwError(exec, msg,KJS::ReferenceError); +} + + +KJS::Value QCanvasPolygonalItemImp::collidesWith_3( KJS::ExecState *exec, KJS::Object &obj, const KJS::List &args ) +{ + + // Unsupported parameter const QCanvasItem * + return KJS::Value(); + + const QCanvasItem * arg0; // Dummy + + bool ret; + ret = instance->collidesWith( + arg0 ); + return KJS::Boolean( ret ); + +} + +KJS::Value QCanvasPolygonalItemImp::setPen_4( KJS::ExecState *exec, KJS::Object &obj, const KJS::List &args ) +{ + + // Unsupported parameter QPen + return KJS::Value(); + + QPen arg0; // Dummy + + instance->setPen( + arg0 ); + return KJS::Value(); // Returns void + +} + +KJS::Value QCanvasPolygonalItemImp::setBrush_5( KJS::ExecState *exec, KJS::Object &obj, const KJS::List &args ) +{ + + // Unsupported parameter QBrush + return KJS::Value(); + + QBrush arg0; // Dummy + + instance->setBrush( + arg0 ); + return KJS::Value(); // Returns void + +} + +KJS::Value QCanvasPolygonalItemImp::pen_6( KJS::ExecState *exec, KJS::Object &obj, const KJS::List &args ) +{ + QPen ret; + ret = instance->pen( ); + + return convertToValue( exec, ret ); + +} + +KJS::Value QCanvasPolygonalItemImp::brush_7( KJS::ExecState *exec, KJS::Object &obj, const KJS::List &args ) +{ + QBrush ret; + ret = instance->brush( ); + + return convertToValue( exec, ret ); + +} + +KJS::Value QCanvasPolygonalItemImp::areaPoints_8( KJS::ExecState *exec, KJS::Object &obj, const KJS::List &args ) +{ + + instance->areaPoints( ); + return KJS::Value(); // Returns 'QPointArray' + +} + +KJS::Value QCanvasPolygonalItemImp::areaPointsAdvanced_9( KJS::ExecState *exec, KJS::Object &obj, const KJS::List &args ) +{ + + instance->areaPointsAdvanced( ); + return KJS::Value(); // Returns 'QPointArray' + +} + +KJS::Value QCanvasPolygonalItemImp::boundingRect_10( KJS::ExecState *exec, KJS::Object &obj, const KJS::List &args ) +{ + QRect ret; + ret = instance->boundingRect( ); + + return convertToValue( exec, ret ); + +} + +KJS::Value QCanvasPolygonalItemImp::rtti_11( KJS::ExecState *exec, KJS::Object &obj, const KJS::List &args ) +{ + + int ret; + ret = instance->rtti( ); + return KJS::Number( ret ); + +} + + +} // namespace KJSEmbed + +// Local Variables: +// c-basic-offset: 4 +// End: + + diff --git a/kjsembed/qtbindings/qcanvaspolygonalitem_imp.h b/kjsembed/qtbindings/qcanvaspolygonalitem_imp.h new file mode 100644 index 00000000..fabda144 --- /dev/null +++ b/kjsembed/qtbindings/qcanvaspolygonalitem_imp.h @@ -0,0 +1,116 @@ + + + +#ifndef KJSEMBED_QCanvasPolygonalItem_H +#define KJSEMBED_QCanvasPolygonalItem_H + +#include <kjs/interpreter.h> +#include <kjs/object.h> + +#include <kjsembed/jsobjectproxy_imp.h> + +class QCanvasPolygonalItem; + +/** + * Namespace containing the KJSEmbed library. + */ +namespace KJSEmbed { + +/** + * Wrapper class for QCanvasPolygonalItem methods. + * + * @author Richard Moore, rich@kde.org + */ +class QCanvasPolygonalItemImp : public JSProxyImp +{ +public: + /** Enumerates the constructors supported by this class. */ + enum Constructors { + Constructor_QCanvasPolygonalItem_1, + + LastConstuctor = -1 + }; + + /** Enumerates the methods supported by this class. */ + enum Methods { + + Method_collidesWith_3, + Method_setPen_4, + Method_setBrush_5, + Method_pen_6, + Method_brush_7, + Method_areaPoints_8, + Method_areaPointsAdvanced_9, + Method_boundingRect_10, + Method_rtti_11, + Method_Last = -1 + }; + + QCanvasPolygonalItemImp( KJS::ExecState *exec, int id, bool constructor=false ); + ~QCanvasPolygonalItemImp(); + + /** + * Adds the static bindings for this class to the specified Object. The + * static bindings are the static methods and the enums of this class. + */ + static void addStaticBindings( KJS::ExecState *exec, KJS::Object &object ); + + /** + * Adds the bindings for this class to the specified Object. The bindings + * added are the instance methods of this class. + */ + static void addBindings( KJS::ExecState *exec, KJS::Object &object ); + + static QCanvasPolygonalItem *toQCanvasPolygonalItem( KJS::Object &object ); + + // + // Constructors implemented by this class. + // + + KJS::Object QCanvasPolygonalItem_1( KJS::ExecState *exec, const KJS::List &args ); + + // + // Methods implemented by this class. + // + + KJS::Value collidesWith_3( KJS::ExecState *exec, KJS::Object &obj, const KJS::List &args ); + KJS::Value setPen_4( KJS::ExecState *exec, KJS::Object &obj, const KJS::List &args ); + KJS::Value setBrush_5( KJS::ExecState *exec, KJS::Object &obj, const KJS::List &args ); + KJS::Value pen_6( KJS::ExecState *exec, KJS::Object &obj, const KJS::List &args ); + KJS::Value brush_7( KJS::ExecState *exec, KJS::Object &obj, const KJS::List &args ); + KJS::Value areaPoints_8( KJS::ExecState *exec, KJS::Object &obj, const KJS::List &args ); + KJS::Value areaPointsAdvanced_9( KJS::ExecState *exec, KJS::Object &obj, const KJS::List &args ); + KJS::Value boundingRect_10( KJS::ExecState *exec, KJS::Object &obj, const KJS::List &args ); + KJS::Value rtti_11( KJS::ExecState *exec, KJS::Object &obj, const KJS::List &args ); + + // + // JS binding code. + // + + /** Returns true iff this object implements the construct function. */ + virtual bool implementsConstruct() const { return cons; } + + /** Invokes the construct function. */ + virtual KJS::Object construct( KJS::ExecState *exec, const KJS::List &args ); + + /** Returns true iff this object implements the call function. */ + virtual bool implementsCall() const { return !cons; } + + /** Invokes the call function. */ + virtual KJS::Value call( KJS::ExecState *exec, KJS::Object &self, const KJS::List &args ); + +private: + QCanvasPolygonalItem *instance; // Temp + int id; + bool cons; +}; + +} // namespace KJSEmbed + +#endif // KJSEMBED_QCanvasPolygonalItem_H + +// Local Variables: +// c-basic-offset: 4 +// End: + + diff --git a/kjsembed/qtbindings/qcanvasrectangle_imp.cpp b/kjsembed/qtbindings/qcanvasrectangle_imp.cpp new file mode 100644 index 00000000..809d571b --- /dev/null +++ b/kjsembed/qtbindings/qcanvasrectangle_imp.cpp @@ -0,0 +1,346 @@ + + + +#include <qcstring.h> +#include <qimage.h> +#include <qpainter.h> +#include <qpalette.h> +#include <qpixmap.h> +#include <qfont.h> + +#include <kjs/object.h> + +#include <kjsembed/global.h> +#include <kjsembed/jsobjectproxy.h> +#include <kjsembed/jsopaqueproxy.h> +#include <kjsembed/jsbinding.h> + +#include <qcanvas.h> +#include "qcanvasrectangle_imp.h" + +/** + * Namespace containing the KJSEmbed library. + */ +namespace KJSEmbed { + +QCanvasRectangleImp::QCanvasRectangleImp( KJS::ExecState *exec, int mid, bool constructor ) + : JSProxyImp(exec), id(mid), cons(constructor) +{ +} + +QCanvasRectangleImp::~QCanvasRectangleImp() +{ +} + +/** + * Adds bindings for static methods and enum constants to the specified Object. + */ +void QCanvasRectangleImp::addStaticBindings( KJS::ExecState *exec, KJS::Object &object ) +{ + JSProxy::MethodTable methods[] = { + + { 0, 0 } + }; + + int idx = 0; + QCString lastName; + + while( methods[idx].name ) { + if ( lastName != methods[idx].name ) { + QCanvasRectangleImp *meth = new QCanvasRectangleImp( exec, methods[idx].id ); + object.put( exec , methods[idx].name, KJS::Object(meth) ); + lastName = methods[idx].name; + } + ++idx; + } + + +} + +/** + * Adds bindings for instance methods to the specified Object. + */ +void QCanvasRectangleImp::addBindings( KJS::ExecState *exec, KJS::Object &object ) +{ + JSProxy::MethodTable methods[] = { + + { Method_width_5, "width" }, + { Method_height_6, "height" }, + { Method_setSize_7, "setSize" }, + { Method_size_8, "size" }, + { Method_areaPoints_9, "areaPoints" }, + { Method_rect_10, "rect" }, + { Method_collidesWith_11, "collidesWith" }, + { Method_rtti_12, "rtti" }, + { 0, 0 } + }; + + int idx = 0; + QCString lastName; + + while( methods[idx].name ) { + if ( lastName != methods[idx].name ) { + QCanvasRectangleImp *meth = new QCanvasRectangleImp( exec, methods[idx].id ); + object.put( exec , methods[idx].name, KJS::Object(meth) ); + lastName = methods[idx].name; + } + ++idx; + } +} + +/** + * Extract a QCanvasRectangle pointer from an Object. + */ +QCanvasRectangle *QCanvasRectangleImp::toQCanvasRectangle( KJS::Object &self ) +{ + JSObjectProxy *ob = JSProxy::toObjectProxy( self.imp() ); + if ( ob ) { + QObject *obj = ob->object(); + if ( obj ) + return dynamic_cast<QCanvasRectangle *>( obj ); + } + + JSOpaqueProxy *op = JSProxy::toOpaqueProxy( self.imp() ); + if ( !op ) + return 0; + + if ( op->typeName() != "QCanvasRectangle" ) + return 0; + + return op->toNative<QCanvasRectangle>(); +} + +/** + * Select and invoke the correct constructor. + */ +KJS::Object QCanvasRectangleImp::construct( KJS::ExecState *exec, const KJS::List &args ) +{ + switch( id ) { + + case Constructor_QCanvasRectangle_1: + return QCanvasRectangle_1( exec, args ); + break; + + case Constructor_QCanvasRectangle_2: + return QCanvasRectangle_2( exec, args ); + break; + + case Constructor_QCanvasRectangle_3: + return QCanvasRectangle_3( exec, args ); + break; + + default: + break; + } + + QString msg = i18n("QCanvasRectangleCons has no constructor with id '%1'.").arg(id); + return throwError(exec, msg,KJS::ReferenceError); +} + + +KJS::Object QCanvasRectangleImp::QCanvasRectangle_1( KJS::ExecState *exec, const KJS::List &args ) +{ + + // Unsupported parameter QCanvas * + return KJS::Object(); + + QCanvas * arg0; // Dummy + + + // We should now create an instance of the QCanvasRectangle object + + QCanvasRectangle *ret = new QCanvasRectangle( + + arg0 ); + + +} + +KJS::Object QCanvasRectangleImp::QCanvasRectangle_2( KJS::ExecState *exec, const KJS::List &args ) +{ + + QRect arg0 = extractQRect(exec, args, 0); + + // Unsupported parameter QCanvas * + return KJS::Object(); + + QCanvas * arg1; // Dummy + + + // We should now create an instance of the QCanvasRectangle object + + QCanvasRectangle *ret = new QCanvasRectangle( + + arg0, + arg1 ); + + +} + +KJS::Object QCanvasRectangleImp::QCanvasRectangle_3( KJS::ExecState *exec, const KJS::List &args ) +{ + + int arg0 = extractInt(exec, args, 0); + + int arg1 = extractInt(exec, args, 1); + + int arg2 = extractInt(exec, args, 2); + + int arg3 = extractInt(exec, args, 3); + + // Unsupported parameter QCanvas * + return KJS::Object(); + + QCanvas * arg4; // Dummy + + + // We should now create an instance of the QCanvasRectangle object + + QCanvasRectangle *ret = new QCanvasRectangle( + + arg0, + arg1, + arg2, + arg3, + arg4 ); + + +} + +KJS::Value QCanvasRectangleImp::call( KJS::ExecState *exec, KJS::Object &self, const KJS::List &args ) +{ + instance = QCanvasRectangleImp::toQCanvasRectangle( self ); + + switch( id ) { + + case Method_width_5: + return width_5( exec, self, args ); + break; + + case Method_height_6: + return height_6( exec, self, args ); + break; + + case Method_setSize_7: + return setSize_7( exec, self, args ); + break; + + case Method_size_8: + return size_8( exec, self, args ); + break; + + case Method_areaPoints_9: + return areaPoints_9( exec, self, args ); + break; + + case Method_rect_10: + return rect_10( exec, self, args ); + break; + + case Method_collidesWith_11: + return collidesWith_11( exec, self, args ); + break; + + case Method_rtti_12: + return rtti_12( exec, self, args ); + break; + + default: + break; + } + + QString msg = i18n( "QCanvasRectangleImp has no method with id '%1'." ).arg( id ); + return throwError(exec, msg,KJS::ReferenceError); +} + + +KJS::Value QCanvasRectangleImp::width_5( KJS::ExecState *exec, KJS::Object &obj, const KJS::List &args ) +{ + + int ret; + ret = instance->width( ); + return KJS::Number( ret ); + +} + +KJS::Value QCanvasRectangleImp::height_6( KJS::ExecState *exec, KJS::Object &obj, const KJS::List &args ) +{ + + int ret; + ret = instance->height( ); + return KJS::Number( ret ); + +} + +KJS::Value QCanvasRectangleImp::setSize_7( KJS::ExecState *exec, KJS::Object &obj, const KJS::List &args ) +{ + + int arg0 = extractInt(exec, args, 0); + + int arg1 = extractInt(exec, args, 1); + + instance->setSize( + arg0, + arg1 ); + return KJS::Value(); // Returns void + +} + +KJS::Value QCanvasRectangleImp::size_8( KJS::ExecState *exec, KJS::Object &obj, const KJS::List &args ) +{ + QSize ret; + ret = instance->size( ); + + return convertToValue( exec, ret ); + +} + +KJS::Value QCanvasRectangleImp::areaPoints_9( KJS::ExecState *exec, KJS::Object &obj, const KJS::List &args ) +{ + + instance->areaPoints( ); + return KJS::Value(); // Returns 'QPointArray' + +} + +KJS::Value QCanvasRectangleImp::rect_10( KJS::ExecState *exec, KJS::Object &obj, const KJS::List &args ) +{ + QRect ret; + ret = instance->rect( ); + + return convertToValue( exec, ret ); + +} + +KJS::Value QCanvasRectangleImp::collidesWith_11( KJS::ExecState *exec, KJS::Object &obj, const KJS::List &args ) +{ + + // Unsupported parameter const QCanvasItem * + return KJS::Value(); + + const QCanvasItem * arg0; // Dummy + + bool ret; + ret = instance->collidesWith( + arg0 ); + return KJS::Boolean( ret ); + +} + +KJS::Value QCanvasRectangleImp::rtti_12( KJS::ExecState *exec, KJS::Object &obj, const KJS::List &args ) +{ + + int ret; + ret = instance->rtti( ); + return KJS::Number( ret ); + +} + + +} // namespace KJSEmbed + +// Local Variables: +// c-basic-offset: 4 +// End: + + diff --git a/kjsembed/qtbindings/qcanvasrectangle_imp.h b/kjsembed/qtbindings/qcanvasrectangle_imp.h new file mode 100644 index 00000000..0ba72f37 --- /dev/null +++ b/kjsembed/qtbindings/qcanvasrectangle_imp.h @@ -0,0 +1,118 @@ + + + +#ifndef KJSEMBED_QCanvasRectangle_H +#define KJSEMBED_QCanvasRectangle_H + +#include <kjs/interpreter.h> +#include <kjs/object.h> + +#include <kjsembed/jsobjectproxy_imp.h> + +class QCanvasRectangle; + +/** + * Namespace containing the KJSEmbed library. + */ +namespace KJSEmbed { + +/** + * Wrapper class for QCanvasRectangle methods. + * + * @author Richard Moore, rich@kde.org + */ +class QCanvasRectangleImp : public JSProxyImp +{ +public: + /** Enumerates the constructors supported by this class. */ + enum Constructors { + Constructor_QCanvasRectangle_1, + Constructor_QCanvasRectangle_2, + Constructor_QCanvasRectangle_3, + + LastConstuctor = -1 + }; + + /** Enumerates the methods supported by this class. */ + enum Methods { + + Method_width_5, + Method_height_6, + Method_setSize_7, + Method_size_8, + Method_areaPoints_9, + Method_rect_10, + Method_collidesWith_11, + Method_rtti_12, + Method_Last = -1 + }; + + QCanvasRectangleImp( KJS::ExecState *exec, int id, bool constructor=false ); + ~QCanvasRectangleImp(); + + /** + * Adds the static bindings for this class to the specified Object. The + * static bindings are the static methods and the enums of this class. + */ + static void addStaticBindings( KJS::ExecState *exec, KJS::Object &object ); + + /** + * Adds the bindings for this class to the specified Object. The bindings + * added are the instance methods of this class. + */ + static void addBindings( KJS::ExecState *exec, KJS::Object &object ); + + static QCanvasRectangle *toQCanvasRectangle( KJS::Object &object ); + + // + // Constructors implemented by this class. + // + + KJS::Object QCanvasRectangle_1( KJS::ExecState *exec, const KJS::List &args ); + KJS::Object QCanvasRectangle_2( KJS::ExecState *exec, const KJS::List &args ); + KJS::Object QCanvasRectangle_3( KJS::ExecState *exec, const KJS::List &args ); + + // + // Methods implemented by this class. + // + + KJS::Value width_5( KJS::ExecState *exec, KJS::Object &obj, const KJS::List &args ); + KJS::Value height_6( KJS::ExecState *exec, KJS::Object &obj, const KJS::List &args ); + KJS::Value setSize_7( KJS::ExecState *exec, KJS::Object &obj, const KJS::List &args ); + KJS::Value size_8( KJS::ExecState *exec, KJS::Object &obj, const KJS::List &args ); + KJS::Value areaPoints_9( KJS::ExecState *exec, KJS::Object &obj, const KJS::List &args ); + KJS::Value rect_10( KJS::ExecState *exec, KJS::Object &obj, const KJS::List &args ); + KJS::Value collidesWith_11( KJS::ExecState *exec, KJS::Object &obj, const KJS::List &args ); + KJS::Value rtti_12( KJS::ExecState *exec, KJS::Object &obj, const KJS::List &args ); + + // + // JS binding code. + // + + /** Returns true iff this object implements the construct function. */ + virtual bool implementsConstruct() const { return cons; } + + /** Invokes the construct function. */ + virtual KJS::Object construct( KJS::ExecState *exec, const KJS::List &args ); + + /** Returns true iff this object implements the call function. */ + virtual bool implementsCall() const { return !cons; } + + /** Invokes the call function. */ + virtual KJS::Value call( KJS::ExecState *exec, KJS::Object &self, const KJS::List &args ); + +private: + QCanvasRectangle *instance; // Temp + int id; + bool cons; +}; + +} // namespace KJSEmbed + +#endif // KJSEMBED_QCanvasRectangle_H + +// Local Variables: +// c-basic-offset: 4 +// End: + + diff --git a/kjsembed/qtbindings/qcanvasspline_imp.cpp b/kjsembed/qtbindings/qcanvasspline_imp.cpp new file mode 100644 index 00000000..57ea74b1 --- /dev/null +++ b/kjsembed/qtbindings/qcanvasspline_imp.cpp @@ -0,0 +1,228 @@ + + + +#include <qcstring.h> +#include <qimage.h> +#include <qpainter.h> +#include <qpalette.h> +#include <qpixmap.h> +#include <qfont.h> + +#include <kjs/object.h> + +#include <kjsembed/global.h> +#include <kjsembed/jsobjectproxy.h> +#include <kjsembed/jsopaqueproxy.h> +#include <kjsembed/jsbinding.h> + +#include <qcanvas.h> +#include "qcanvasspline_imp.h" + +/** + * Namespace containing the KJSEmbed library. + */ +namespace KJSEmbed { + +QCanvasSplineImp::QCanvasSplineImp( KJS::ExecState *exec, int mid, bool constructor ) + : JSProxyImp(exec), id(mid), cons(constructor) +{ +} + +QCanvasSplineImp::~QCanvasSplineImp() +{ +} + +/** + * Adds bindings for static methods and enum constants to the specified Object. + */ +void QCanvasSplineImp::addStaticBindings( KJS::ExecState *exec, KJS::Object &object ) +{ + JSProxy::MethodTable methods[] = { + + { 0, 0 } + }; + + int idx = 0; + QCString lastName; + + while( methods[idx].name ) { + if ( lastName != methods[idx].name ) { + QCanvasSplineImp *meth = new QCanvasSplineImp( exec, methods[idx].id ); + object.put( exec , methods[idx].name, KJS::Object(meth) ); + lastName = methods[idx].name; + } + ++idx; + } + + +} + +/** + * Adds bindings for instance methods to the specified Object. + */ +void QCanvasSplineImp::addBindings( KJS::ExecState *exec, KJS::Object &object ) +{ + JSProxy::MethodTable methods[] = { + + { Method_setControlPoints_3, "setControlPoints" }, + { Method_controlPoints_4, "controlPoints" }, + { Method_closed_5, "closed" }, + { Method_rtti_6, "rtti" }, + { 0, 0 } + }; + + int idx = 0; + QCString lastName; + + while( methods[idx].name ) { + if ( lastName != methods[idx].name ) { + QCanvasSplineImp *meth = new QCanvasSplineImp( exec, methods[idx].id ); + object.put( exec , methods[idx].name, KJS::Object(meth) ); + lastName = methods[idx].name; + } + ++idx; + } +} + +/** + * Extract a QCanvasSpline pointer from an Object. + */ +QCanvasSpline *QCanvasSplineImp::toQCanvasSpline( KJS::Object &self ) +{ + JSObjectProxy *ob = JSProxy::toObjectProxy( self.imp() ); + if ( ob ) { + QObject *obj = ob->object(); + if ( obj ) + return dynamic_cast<QCanvasSpline *>( obj ); + } + + JSOpaqueProxy *op = JSProxy::toOpaqueProxy( self.imp() ); + if ( !op ) + return 0; + + if ( op->typeName() != "QCanvasSpline" ) + return 0; + + return op->toNative<QCanvasSpline>(); +} + +/** + * Select and invoke the correct constructor. + */ +KJS::Object QCanvasSplineImp::construct( KJS::ExecState *exec, const KJS::List &args ) +{ + switch( id ) { + + case Constructor_QCanvasSpline_1: + return QCanvasSpline_1( exec, args ); + break; + + default: + break; + } + + QString msg = i18n("QCanvasSplineCons has no constructor with id '%1'.").arg(id); + return throwError(exec, msg,KJS::ReferenceError); +} + + +KJS::Object QCanvasSplineImp::QCanvasSpline_1( KJS::ExecState *exec, const KJS::List &args ) +{ + + // Unsupported parameter QCanvas * + return KJS::Object(); + + QCanvas * arg0; // Dummy + + + // We should now create an instance of the QCanvasSpline object + + QCanvasSpline *ret = new QCanvasSpline( + + arg0 ); + + +} + +KJS::Value QCanvasSplineImp::call( KJS::ExecState *exec, KJS::Object &self, const KJS::List &args ) +{ + instance = QCanvasSplineImp::toQCanvasSpline( self ); + + switch( id ) { + + case Method_setControlPoints_3: + return setControlPoints_3( exec, self, args ); + break; + + case Method_controlPoints_4: + return controlPoints_4( exec, self, args ); + break; + + case Method_closed_5: + return closed_5( exec, self, args ); + break; + + case Method_rtti_6: + return rtti_6( exec, self, args ); + break; + + default: + break; + } + + QString msg = i18n( "QCanvasSplineImp has no method with id '%1'." ).arg( id ); + return throwError(exec, msg,KJS::ReferenceError); +} + + +KJS::Value QCanvasSplineImp::setControlPoints_3( KJS::ExecState *exec, KJS::Object &obj, const KJS::List &args ) +{ + + // Unsupported parameter QPointArray + return KJS::Value(); + + QPointArray arg0; // Dummy + + bool arg1 = extractBool(exec, args, 1); + + instance->setControlPoints( + arg0, + arg1 ); + return KJS::Value(); // Returns void + +} + +KJS::Value QCanvasSplineImp::controlPoints_4( KJS::ExecState *exec, KJS::Object &obj, const KJS::List &args ) +{ + + instance->controlPoints( ); + return KJS::Value(); // Returns 'QPointArray' + +} + +KJS::Value QCanvasSplineImp::closed_5( KJS::ExecState *exec, KJS::Object &obj, const KJS::List &args ) +{ + + bool ret; + ret = instance->closed( ); + return KJS::Boolean( ret ); + +} + +KJS::Value QCanvasSplineImp::rtti_6( KJS::ExecState *exec, KJS::Object &obj, const KJS::List &args ) +{ + + int ret; + ret = instance->rtti( ); + return KJS::Number( ret ); + +} + + +} // namespace KJSEmbed + +// Local Variables: +// c-basic-offset: 4 +// End: + + diff --git a/kjsembed/qtbindings/qcanvasspline_imp.h b/kjsembed/qtbindings/qcanvasspline_imp.h new file mode 100644 index 00000000..dc4d4ed8 --- /dev/null +++ b/kjsembed/qtbindings/qcanvasspline_imp.h @@ -0,0 +1,106 @@ + + + +#ifndef KJSEMBED_QCanvasSpline_H +#define KJSEMBED_QCanvasSpline_H + +#include <kjs/interpreter.h> +#include <kjs/object.h> + +#include <kjsembed/jsobjectproxy_imp.h> + +class QCanvasSpline; + +/** + * Namespace containing the KJSEmbed library. + */ +namespace KJSEmbed { + +/** + * Wrapper class for QCanvasSpline methods. + * + * @author Richard Moore, rich@kde.org + */ +class QCanvasSplineImp : public JSProxyImp +{ +public: + /** Enumerates the constructors supported by this class. */ + enum Constructors { + Constructor_QCanvasSpline_1, + + LastConstuctor = -1 + }; + + /** Enumerates the methods supported by this class. */ + enum Methods { + + Method_setControlPoints_3, + Method_controlPoints_4, + Method_closed_5, + Method_rtti_6, + Method_Last = -1 + }; + + QCanvasSplineImp( KJS::ExecState *exec, int id, bool constructor=false ); + ~QCanvasSplineImp(); + + /** + * Adds the static bindings for this class to the specified Object. The + * static bindings are the static methods and the enums of this class. + */ + static void addStaticBindings( KJS::ExecState *exec, KJS::Object &object ); + + /** + * Adds the bindings for this class to the specified Object. The bindings + * added are the instance methods of this class. + */ + static void addBindings( KJS::ExecState *exec, KJS::Object &object ); + + static QCanvasSpline *toQCanvasSpline( KJS::Object &object ); + + // + // Constructors implemented by this class. + // + + KJS::Object QCanvasSpline_1( KJS::ExecState *exec, const KJS::List &args ); + + // + // Methods implemented by this class. + // + + KJS::Value setControlPoints_3( KJS::ExecState *exec, KJS::Object &obj, const KJS::List &args ); + KJS::Value controlPoints_4( KJS::ExecState *exec, KJS::Object &obj, const KJS::List &args ); + KJS::Value closed_5( KJS::ExecState *exec, KJS::Object &obj, const KJS::List &args ); + KJS::Value rtti_6( KJS::ExecState *exec, KJS::Object &obj, const KJS::List &args ); + + // + // JS binding code. + // + + /** Returns true iff this object implements the construct function. */ + virtual bool implementsConstruct() const { return cons; } + + /** Invokes the construct function. */ + virtual KJS::Object construct( KJS::ExecState *exec, const KJS::List &args ); + + /** Returns true iff this object implements the call function. */ + virtual bool implementsCall() const { return !cons; } + + /** Invokes the call function. */ + virtual KJS::Value call( KJS::ExecState *exec, KJS::Object &self, const KJS::List &args ); + +private: + QCanvasSpline *instance; // Temp + int id; + bool cons; +}; + +} // namespace KJSEmbed + +#endif // KJSEMBED_QCanvasSpline_H + +// Local Variables: +// c-basic-offset: 4 +// End: + + diff --git a/kjsembed/qtbindings/qcanvassprite_imp.cpp b/kjsembed/qtbindings/qcanvassprite_imp.cpp new file mode 100644 index 00000000..6268e75c --- /dev/null +++ b/kjsembed/qtbindings/qcanvassprite_imp.cpp @@ -0,0 +1,593 @@ + + + +#include <qcstring.h> +#include <qimage.h> +#include <qpainter.h> +#include <qpalette.h> +#include <qpixmap.h> +#include <qfont.h> + +#include <kjs/object.h> + +#include <kjsembed/global.h> +#include <kjsembed/jsobjectproxy.h> +#include <kjsembed/jsopaqueproxy.h> +#include <kjsembed/jsbinding.h> + +#include <qcanvas.h> +#include "qcanvassprite_imp.h" + +/** + * Namespace containing the KJSEmbed library. + */ +namespace KJSEmbed { + +QCanvasSpriteImp::QCanvasSpriteImp( KJS::ExecState *exec, int mid, bool constructor ) + : JSProxyImp(exec), id(mid), cons(constructor) +{ +} + +QCanvasSpriteImp::~QCanvasSpriteImp() +{ +} + +/** + * Adds bindings for static methods and enum constants to the specified Object. + */ +void QCanvasSpriteImp::addStaticBindings( KJS::ExecState *exec, KJS::Object &object ) +{ + JSProxy::MethodTable methods[] = { + + { 0, 0 } + }; + + int idx = 0; + QCString lastName; + + while( methods[idx].name ) { + if ( lastName != methods[idx].name ) { + QCanvasSpriteImp *meth = new QCanvasSpriteImp( exec, methods[idx].id ); + object.put( exec , methods[idx].name, KJS::Object(meth) ); + lastName = methods[idx].name; + } + ++idx; + } + + + // + // Define the enum constants + // + struct EnumValue { + const char *id; + int val; + }; + + EnumValue enums[] = { + + // enum FrameAnimationType + { "Cycle", QCanvasSprite::Cycle }, + { "Oscillate", QCanvasSprite::Oscillate }, + { 0, 0 } + }; + + int enumidx = 0; + while( enums[enumidx].id ) { + object.put( exec, enums[enumidx].id, KJS::Number(enums[enumidx].val), KJS::ReadOnly ); + ++enumidx; + } + +} + +/** + * Adds bindings for instance methods to the specified Object. + */ +void QCanvasSpriteImp::addBindings( KJS::ExecState *exec, KJS::Object &object ) +{ + JSProxy::MethodTable methods[] = { + + { Method_setSequence_2, "setSequence" }, + { Method_move_4, "move" }, + { Method_move_5, "move" }, + { Method_setFrame_6, "setFrame" }, + { Method_setFrameAnimation_7, "setFrameAnimation" }, + { Method_frame_8, "frame" }, + { Method_frameCount_9, "frameCount" }, + { Method_rtti_10, "rtti" }, + { Method_collidesWith_11, "collidesWith" }, + { Method_boundingRect_12, "boundingRect" }, + { Method_width_13, "width" }, + { Method_height_14, "height" }, + { Method_leftEdge_15, "leftEdge" }, + { Method_topEdge_16, "topEdge" }, + { Method_rightEdge_17, "rightEdge" }, + { Method_bottomEdge_18, "bottomEdge" }, + { Method_leftEdge_19, "leftEdge" }, + { Method_topEdge_20, "topEdge" }, + { Method_rightEdge_21, "rightEdge" }, + { Method_bottomEdge_22, "bottomEdge" }, + { Method_image_23, "image" }, + { Method_imageAdvanced_24, "imageAdvanced" }, + { Method_image_25, "image" }, + { Method_advance_26, "advance" }, + { Method_draw_27, "draw" }, + { 0, 0 } + }; + + int idx = 0; + QCString lastName; + + while( methods[idx].name ) { + if ( lastName != methods[idx].name ) { + QCanvasSpriteImp *meth = new QCanvasSpriteImp( exec, methods[idx].id ); + object.put( exec , methods[idx].name, KJS::Object(meth) ); + lastName = methods[idx].name; + } + ++idx; + } +} + +/** + * Extract a QCanvasSprite pointer from an Object. + */ +QCanvasSprite *QCanvasSpriteImp::toQCanvasSprite( KJS::Object &self ) +{ + JSObjectProxy *ob = JSProxy::toObjectProxy( self.imp() ); + if ( ob ) { + QObject *obj = ob->object(); + if ( obj ) + return dynamic_cast<QCanvasSprite *>( obj ); + } + + JSOpaqueProxy *op = JSProxy::toOpaqueProxy( self.imp() ); + if ( !op ) + return 0; + + if ( op->typeName() != "QCanvasSprite" ) + return 0; + + return op->toNative<QCanvasSprite>(); +} + +/** + * Select and invoke the correct constructor. + */ +KJS::Object QCanvasSpriteImp::construct( KJS::ExecState *exec, const KJS::List &args ) +{ + switch( id ) { + + case Constructor_QCanvasSprite_1: + return QCanvasSprite_1( exec, args ); + break; + + default: + break; + } + + QString msg = i18n("QCanvasSpriteCons has no constructor with id '%1'.").arg(id); + return throwError(exec, msg,KJS::ReferenceError); +} + + +KJS::Object QCanvasSpriteImp::QCanvasSprite_1( KJS::ExecState *exec, const KJS::List &args ) +{ + + // Unsupported parameter QCanvasPixmapArray * + return KJS::Object(); + + QCanvasPixmapArray * arg0; // Dummy + + // Unsupported parameter QCanvas * + return KJS::Object(); + + QCanvas * arg1; // Dummy + + + // We should now create an instance of the QCanvasSprite object + + QCanvasSprite *ret = new QCanvasSprite( + + arg0, + arg1 ); + + +} + +KJS::Value QCanvasSpriteImp::call( KJS::ExecState *exec, KJS::Object &self, const KJS::List &args ) +{ + instance = QCanvasSpriteImp::toQCanvasSprite( self ); + + switch( id ) { + + case Method_setSequence_2: + return setSequence_2( exec, self, args ); + break; + + case Method_move_4: + return move_4( exec, self, args ); + break; + + case Method_move_5: + return move_5( exec, self, args ); + break; + + case Method_setFrame_6: + return setFrame_6( exec, self, args ); + break; + + case Method_setFrameAnimation_7: + return setFrameAnimation_7( exec, self, args ); + break; + + case Method_frame_8: + return frame_8( exec, self, args ); + break; + + case Method_frameCount_9: + return frameCount_9( exec, self, args ); + break; + + case Method_rtti_10: + return rtti_10( exec, self, args ); + break; + + case Method_collidesWith_11: + return collidesWith_11( exec, self, args ); + break; + + case Method_boundingRect_12: + return boundingRect_12( exec, self, args ); + break; + + case Method_width_13: + return width_13( exec, self, args ); + break; + + case Method_height_14: + return height_14( exec, self, args ); + break; + + case Method_leftEdge_15: + return leftEdge_15( exec, self, args ); + break; + + case Method_topEdge_16: + return topEdge_16( exec, self, args ); + break; + + case Method_rightEdge_17: + return rightEdge_17( exec, self, args ); + break; + + case Method_bottomEdge_18: + return bottomEdge_18( exec, self, args ); + break; + + case Method_leftEdge_19: + return leftEdge_19( exec, self, args ); + break; + + case Method_topEdge_20: + return topEdge_20( exec, self, args ); + break; + + case Method_rightEdge_21: + return rightEdge_21( exec, self, args ); + break; + + case Method_bottomEdge_22: + return bottomEdge_22( exec, self, args ); + break; + + case Method_image_23: + return image_23( exec, self, args ); + break; + + case Method_imageAdvanced_24: + return imageAdvanced_24( exec, self, args ); + break; + + case Method_image_25: + return image_25( exec, self, args ); + break; + + case Method_advance_26: + return advance_26( exec, self, args ); + break; + + case Method_draw_27: + return draw_27( exec, self, args ); + break; + + default: + break; + } + + QString msg = i18n( "QCanvasSpriteImp has no method with id '%1'." ).arg( id ); + return throwError(exec, msg,KJS::ReferenceError); +} + + +KJS::Value QCanvasSpriteImp::setSequence_2( KJS::ExecState *exec, KJS::Object &obj, const KJS::List &args ) +{ + + // Unsupported parameter QCanvasPixmapArray * + return KJS::Value(); + + QCanvasPixmapArray * arg0; // Dummy + + instance->setSequence( + arg0 ); + return KJS::Value(); // Returns void + +} + +KJS::Value QCanvasSpriteImp::move_4( KJS::ExecState *exec, KJS::Object &obj, const KJS::List &args ) +{ + + double arg0 = extractDouble(exec, args, 0); + + double arg1 = extractDouble(exec, args, 1); + + instance->move( + arg0, + arg1 ); + return KJS::Value(); // Returns void + +} + +KJS::Value QCanvasSpriteImp::move_5( KJS::ExecState *exec, KJS::Object &obj, const KJS::List &args ) +{ + + double arg0 = extractDouble(exec, args, 0); + + double arg1 = extractDouble(exec, args, 1); + + int arg2 = extractInt(exec, args, 2); + + instance->move( + arg0, + arg1, + arg2 ); + return KJS::Value(); // Returns void + +} + +KJS::Value QCanvasSpriteImp::setFrame_6( KJS::ExecState *exec, KJS::Object &obj, const KJS::List &args ) +{ + + int arg0 = extractInt(exec, args, 0); + + instance->setFrame( + arg0 ); + return KJS::Value(); // Returns void + +} + +KJS::Value QCanvasSpriteImp::setFrameAnimation_7( KJS::ExecState *exec, KJS::Object &obj, const KJS::List &args ) +{ + + QCanvasSprite::FrameAnimationType arg0 = QCanvasSprite::Cycle; // TODO (hack for QCanvasSprite) + + int arg1 = extractInt(exec, args, 1); + + int arg2 = extractInt(exec, args, 2); + + instance->setFrameAnimation( + arg0, + arg1, + arg2 ); + return KJS::Value(); // Returns void + +} + +KJS::Value QCanvasSpriteImp::frame_8( KJS::ExecState *exec, KJS::Object &obj, const KJS::List &args ) +{ + + int ret; + ret = instance->frame( ); + return KJS::Number( ret ); + +} + +KJS::Value QCanvasSpriteImp::frameCount_9( KJS::ExecState *exec, KJS::Object &obj, const KJS::List &args ) +{ + + int ret; + ret = instance->frameCount( ); + return KJS::Number( ret ); + +} + +KJS::Value QCanvasSpriteImp::rtti_10( KJS::ExecState *exec, KJS::Object &obj, const KJS::List &args ) +{ + + int ret; + ret = instance->rtti( ); + return KJS::Number( ret ); + +} + +KJS::Value QCanvasSpriteImp::collidesWith_11( KJS::ExecState *exec, KJS::Object &obj, const KJS::List &args ) +{ + + // Unsupported parameter const QCanvasItem * + return KJS::Value(); + + const QCanvasItem * arg0; // Dummy + + bool ret; + ret = instance->collidesWith( + arg0 ); + return KJS::Boolean( ret ); + +} + +KJS::Value QCanvasSpriteImp::boundingRect_12( KJS::ExecState *exec, KJS::Object &obj, const KJS::List &args ) +{ + QRect ret; + ret = instance->boundingRect( ); + + return convertToValue( exec, ret ); + +} + +KJS::Value QCanvasSpriteImp::width_13( KJS::ExecState *exec, KJS::Object &obj, const KJS::List &args ) +{ + + int ret; + ret = instance->width( ); + return KJS::Number( ret ); + +} + +KJS::Value QCanvasSpriteImp::height_14( KJS::ExecState *exec, KJS::Object &obj, const KJS::List &args ) +{ + + int ret; + ret = instance->height( ); + return KJS::Number( ret ); + +} + +KJS::Value QCanvasSpriteImp::leftEdge_15( KJS::ExecState *exec, KJS::Object &obj, const KJS::List &args ) +{ + + int ret; + ret = instance->leftEdge( ); + return KJS::Number( ret ); + +} + +KJS::Value QCanvasSpriteImp::topEdge_16( KJS::ExecState *exec, KJS::Object &obj, const KJS::List &args ) +{ + + int ret; + ret = instance->topEdge( ); + return KJS::Number( ret ); + +} + +KJS::Value QCanvasSpriteImp::rightEdge_17( KJS::ExecState *exec, KJS::Object &obj, const KJS::List &args ) +{ + + int ret; + ret = instance->rightEdge( ); + return KJS::Number( ret ); + +} + +KJS::Value QCanvasSpriteImp::bottomEdge_18( KJS::ExecState *exec, KJS::Object &obj, const KJS::List &args ) +{ + + int ret; + ret = instance->bottomEdge( ); + return KJS::Number( ret ); + +} + +KJS::Value QCanvasSpriteImp::leftEdge_19( KJS::ExecState *exec, KJS::Object &obj, const KJS::List &args ) +{ + + int arg0 = extractInt(exec, args, 0); + + int ret; + ret = instance->leftEdge( + arg0 ); + return KJS::Number( ret ); + +} + +KJS::Value QCanvasSpriteImp::topEdge_20( KJS::ExecState *exec, KJS::Object &obj, const KJS::List &args ) +{ + + int arg0 = extractInt(exec, args, 0); + + int ret; + ret = instance->topEdge( + arg0 ); + return KJS::Number( ret ); + +} + +KJS::Value QCanvasSpriteImp::rightEdge_21( KJS::ExecState *exec, KJS::Object &obj, const KJS::List &args ) +{ + + int arg0 = extractInt(exec, args, 0); + + int ret; + ret = instance->rightEdge( + arg0 ); + return KJS::Number( ret ); + +} + +KJS::Value QCanvasSpriteImp::bottomEdge_22( KJS::ExecState *exec, KJS::Object &obj, const KJS::List &args ) +{ + + int arg0 = extractInt(exec, args, 0); + + int ret; + ret = instance->bottomEdge( + arg0 ); + return KJS::Number( ret ); + +} + +KJS::Value QCanvasSpriteImp::image_23( KJS::ExecState *exec, KJS::Object &obj, const KJS::List &args ) +{ + + instance->image( ); + return KJS::Value(); // Returns 'QCanvasPixmap *' + +} + +KJS::Value QCanvasSpriteImp::imageAdvanced_24( KJS::ExecState *exec, KJS::Object &obj, const KJS::List &args ) +{ + + instance->imageAdvanced( ); + return KJS::Value(); // Returns 'QCanvasPixmap *' + +} + +KJS::Value QCanvasSpriteImp::image_25( KJS::ExecState *exec, KJS::Object &obj, const KJS::List &args ) +{ + + int arg0 = extractInt(exec, args, 0); + + instance->image( + arg0 ); + return KJS::Value(); // Returns 'QCanvasPixmap *' + +} + +KJS::Value QCanvasSpriteImp::advance_26( KJS::ExecState *exec, KJS::Object &obj, const KJS::List &args ) +{ + + int arg0 = extractInt(exec, args, 0); + + instance->advance( + arg0 ); + return KJS::Value(); // Returns void + +} + +KJS::Value QCanvasSpriteImp::draw_27( KJS::ExecState *exec, KJS::Object &obj, const KJS::List &args ) +{ + + QPainter arg0; // TODO (hack for qcanvas) + + instance->draw( + arg0 ); + return KJS::Value(); // Returns void + +} + + +} // namespace KJSEmbed + +// Local Variables: +// c-basic-offset: 4 +// End: + + diff --git a/kjsembed/qtbindings/qcanvassprite_imp.h b/kjsembed/qtbindings/qcanvassprite_imp.h new file mode 100644 index 00000000..5f597077 --- /dev/null +++ b/kjsembed/qtbindings/qcanvassprite_imp.h @@ -0,0 +1,148 @@ + + + +#ifndef KJSEMBED_QCanvasSprite_H +#define KJSEMBED_QCanvasSprite_H + +#include <kjs/interpreter.h> +#include <kjs/object.h> + +#include <kjsembed/jsobjectproxy_imp.h> + +class QCanvasSprite; + +/** + * Namespace containing the KJSEmbed library. + */ +namespace KJSEmbed { + +/** + * Wrapper class for QCanvasSprite methods. + * + * @author Richard Moore, rich@kde.org + */ +class QCanvasSpriteImp : public JSProxyImp +{ +public: + /** Enumerates the constructors supported by this class. */ + enum Constructors { + Constructor_QCanvasSprite_1, + + LastConstuctor = -1 + }; + + /** Enumerates the methods supported by this class. */ + enum Methods { + + Method_setSequence_2, + Method_move_4, + Method_move_5, + Method_setFrame_6, + Method_setFrameAnimation_7, + Method_frame_8, + Method_frameCount_9, + Method_rtti_10, + Method_collidesWith_11, + Method_boundingRect_12, + Method_width_13, + Method_height_14, + Method_leftEdge_15, + Method_topEdge_16, + Method_rightEdge_17, + Method_bottomEdge_18, + Method_leftEdge_19, + Method_topEdge_20, + Method_rightEdge_21, + Method_bottomEdge_22, + Method_image_23, + Method_imageAdvanced_24, + Method_image_25, + Method_advance_26, + Method_draw_27, + Method_Last = -1 + }; + + QCanvasSpriteImp( KJS::ExecState *exec, int id, bool constructor=false ); + ~QCanvasSpriteImp(); + + /** + * Adds the static bindings for this class to the specified Object. The + * static bindings are the static methods and the enums of this class. + */ + static void addStaticBindings( KJS::ExecState *exec, KJS::Object &object ); + + /** + * Adds the bindings for this class to the specified Object. The bindings + * added are the instance methods of this class. + */ + static void addBindings( KJS::ExecState *exec, KJS::Object &object ); + + static QCanvasSprite *toQCanvasSprite( KJS::Object &object ); + + // + // Constructors implemented by this class. + // + + KJS::Object QCanvasSprite_1( KJS::ExecState *exec, const KJS::List &args ); + + // + // Methods implemented by this class. + // + + KJS::Value setSequence_2( KJS::ExecState *exec, KJS::Object &obj, const KJS::List &args ); + KJS::Value move_4( KJS::ExecState *exec, KJS::Object &obj, const KJS::List &args ); + KJS::Value move_5( KJS::ExecState *exec, KJS::Object &obj, const KJS::List &args ); + KJS::Value setFrame_6( KJS::ExecState *exec, KJS::Object &obj, const KJS::List &args ); + KJS::Value setFrameAnimation_7( KJS::ExecState *exec, KJS::Object &obj, const KJS::List &args ); + KJS::Value frame_8( KJS::ExecState *exec, KJS::Object &obj, const KJS::List &args ); + KJS::Value frameCount_9( KJS::ExecState *exec, KJS::Object &obj, const KJS::List &args ); + KJS::Value rtti_10( KJS::ExecState *exec, KJS::Object &obj, const KJS::List &args ); + KJS::Value collidesWith_11( KJS::ExecState *exec, KJS::Object &obj, const KJS::List &args ); + KJS::Value boundingRect_12( KJS::ExecState *exec, KJS::Object &obj, const KJS::List &args ); + KJS::Value width_13( KJS::ExecState *exec, KJS::Object &obj, const KJS::List &args ); + KJS::Value height_14( KJS::ExecState *exec, KJS::Object &obj, const KJS::List &args ); + KJS::Value leftEdge_15( KJS::ExecState *exec, KJS::Object &obj, const KJS::List &args ); + KJS::Value topEdge_16( KJS::ExecState *exec, KJS::Object &obj, const KJS::List &args ); + KJS::Value rightEdge_17( KJS::ExecState *exec, KJS::Object &obj, const KJS::List &args ); + KJS::Value bottomEdge_18( KJS::ExecState *exec, KJS::Object &obj, const KJS::List &args ); + KJS::Value leftEdge_19( KJS::ExecState *exec, KJS::Object &obj, const KJS::List &args ); + KJS::Value topEdge_20( KJS::ExecState *exec, KJS::Object &obj, const KJS::List &args ); + KJS::Value rightEdge_21( KJS::ExecState *exec, KJS::Object &obj, const KJS::List &args ); + KJS::Value bottomEdge_22( KJS::ExecState *exec, KJS::Object &obj, const KJS::List &args ); + KJS::Value image_23( KJS::ExecState *exec, KJS::Object &obj, const KJS::List &args ); + KJS::Value imageAdvanced_24( KJS::ExecState *exec, KJS::Object &obj, const KJS::List &args ); + KJS::Value image_25( KJS::ExecState *exec, KJS::Object &obj, const KJS::List &args ); + KJS::Value advance_26( KJS::ExecState *exec, KJS::Object &obj, const KJS::List &args ); + KJS::Value draw_27( KJS::ExecState *exec, KJS::Object &obj, const KJS::List &args ); + + // + // JS binding code. + // + + /** Returns true iff this object implements the construct function. */ + virtual bool implementsConstruct() const { return cons; } + + /** Invokes the construct function. */ + virtual KJS::Object construct( KJS::ExecState *exec, const KJS::List &args ); + + /** Returns true iff this object implements the call function. */ + virtual bool implementsCall() const { return !cons; } + + /** Invokes the call function. */ + virtual KJS::Value call( KJS::ExecState *exec, KJS::Object &self, const KJS::List &args ); + +private: + QCanvasSprite *instance; // Temp + int id; + bool cons; +}; + +} // namespace KJSEmbed + +#endif // KJSEMBED_QCanvasSprite_H + +// Local Variables: +// c-basic-offset: 4 +// End: + + diff --git a/kjsembed/qtbindings/qcanvastext_imp.cpp b/kjsembed/qtbindings/qcanvastext_imp.cpp new file mode 100644 index 00000000..84548eea --- /dev/null +++ b/kjsembed/qtbindings/qcanvastext_imp.cpp @@ -0,0 +1,406 @@ + + + +#include <qcstring.h> +#include <qimage.h> +#include <qpainter.h> +#include <qpalette.h> +#include <qpixmap.h> +#include <qfont.h> + +#include <kjs/object.h> + +#include <kjsembed/global.h> +#include <kjsembed/jsobjectproxy.h> +#include <kjsembed/jsopaqueproxy.h> +#include <kjsembed/jsbinding.h> + +#include <qcanvas.h> +#include "qcanvastext_imp.h" + +/** + * Namespace containing the KJSEmbed library. + */ +namespace KJSEmbed { + +QCanvasTextImp::QCanvasTextImp( KJS::ExecState *exec, int mid, bool constructor ) + : JSProxyImp(exec), id(mid), cons(constructor) +{ +} + +QCanvasTextImp::~QCanvasTextImp() +{ +} + +/** + * Adds bindings for static methods and enum constants to the specified Object. + */ +void QCanvasTextImp::addStaticBindings( KJS::ExecState *exec, KJS::Object &object ) +{ + JSProxy::MethodTable methods[] = { + + { 0, 0 } + }; + + int idx = 0; + QCString lastName; + + while( methods[idx].name ) { + if ( lastName != methods[idx].name ) { + QCanvasTextImp *meth = new QCanvasTextImp( exec, methods[idx].id ); + object.put( exec , methods[idx].name, KJS::Object(meth) ); + lastName = methods[idx].name; + } + ++idx; + } + + +} + +/** + * Adds bindings for instance methods to the specified Object. + */ +void QCanvasTextImp::addBindings( KJS::ExecState *exec, KJS::Object &object ) +{ + JSProxy::MethodTable methods[] = { + + { Method_setText_5, "setText" }, + { Method_setFont_6, "setFont" }, + { Method_setColor_7, "setColor" }, + { Method_text_8, "text" }, + { Method_font_9, "font" }, + { Method_color_10, "color" }, + { Method_moveBy_11, "moveBy" }, + { Method_textFlags_12, "textFlags" }, + { Method_setTextFlags_13, "setTextFlags" }, + { Method_boundingRect_14, "boundingRect" }, + { Method_collidesWith_15, "collidesWith" }, + { Method_rtti_16, "rtti" }, + { 0, 0 } + }; + + int idx = 0; + QCString lastName; + + while( methods[idx].name ) { + if ( lastName != methods[idx].name ) { + QCanvasTextImp *meth = new QCanvasTextImp( exec, methods[idx].id ); + object.put( exec , methods[idx].name, KJS::Object(meth) ); + lastName = methods[idx].name; + } + ++idx; + } +} + +/** + * Extract a QCanvasText pointer from an Object. + */ +QCanvasText *QCanvasTextImp::toQCanvasText( KJS::Object &self ) +{ + JSObjectProxy *ob = JSProxy::toObjectProxy( self.imp() ); + if ( ob ) { + QObject *obj = ob->object(); + if ( obj ) + return dynamic_cast<QCanvasText *>( obj ); + } + + JSOpaqueProxy *op = JSProxy::toOpaqueProxy( self.imp() ); + if ( !op ) + return 0; + + if ( op->typeName() != "QCanvasText" ) + return 0; + + return op->toNative<QCanvasText>(); +} + +/** + * Select and invoke the correct constructor. + */ +KJS::Object QCanvasTextImp::construct( KJS::ExecState *exec, const KJS::List &args ) +{ + switch( id ) { + + case Constructor_QCanvasText_1: + return QCanvasText_1( exec, args ); + break; + + case Constructor_QCanvasText_2: + return QCanvasText_2( exec, args ); + break; + + case Constructor_QCanvasText_3: + return QCanvasText_3( exec, args ); + break; + + default: + break; + } + + QString msg = i18n("QCanvasTextCons has no constructor with id '%1'.").arg(id); + return throwError(exec, msg,KJS::ReferenceError); +} + + +KJS::Object QCanvasTextImp::QCanvasText_1( KJS::ExecState *exec, const KJS::List &args ) +{ + + // Unsupported parameter QCanvas * + return KJS::Object(); + + QCanvas * arg0; // Dummy + + + // We should now create an instance of the QCanvasText object + + QCanvasText *ret = new QCanvasText( + + arg0 ); + + +} + +KJS::Object QCanvasTextImp::QCanvasText_2( KJS::ExecState *exec, const KJS::List &args ) +{ + + QString arg0 = extractQString(exec, args, 0); + + // Unsupported parameter QCanvas * + return KJS::Object(); + + QCanvas * arg1; // Dummy + + + // We should now create an instance of the QCanvasText object + + QCanvasText *ret = new QCanvasText( + + arg0, + arg1 ); + + +} + +KJS::Object QCanvasTextImp::QCanvasText_3( KJS::ExecState *exec, const KJS::List &args ) +{ + + QString arg0 = extractQString(exec, args, 0); + + // Unsupported parameter QFont + return KJS::Object(); + + QFont arg1; // Dummy + + // Unsupported parameter QCanvas * + return KJS::Object(); + + QCanvas * arg2; // Dummy + + + // We should now create an instance of the QCanvasText object + + QCanvasText *ret = new QCanvasText( + + arg0, + arg1, + arg2 ); + + +} + +KJS::Value QCanvasTextImp::call( KJS::ExecState *exec, KJS::Object &self, const KJS::List &args ) +{ + instance = QCanvasTextImp::toQCanvasText( self ); + + switch( id ) { + + case Method_setText_5: + return setText_5( exec, self, args ); + break; + + case Method_setFont_6: + return setFont_6( exec, self, args ); + break; + + case Method_setColor_7: + return setColor_7( exec, self, args ); + break; + + case Method_text_8: + return text_8( exec, self, args ); + break; + + case Method_font_9: + return font_9( exec, self, args ); + break; + + case Method_color_10: + return color_10( exec, self, args ); + break; + + case Method_moveBy_11: + return moveBy_11( exec, self, args ); + break; + + case Method_textFlags_12: + return textFlags_12( exec, self, args ); + break; + + case Method_setTextFlags_13: + return setTextFlags_13( exec, self, args ); + break; + + case Method_boundingRect_14: + return boundingRect_14( exec, self, args ); + break; + + case Method_collidesWith_15: + return collidesWith_15( exec, self, args ); + break; + + case Method_rtti_16: + return rtti_16( exec, self, args ); + break; + + default: + break; + } + + QString msg = i18n( "QCanvasTextImp has no method with id '%1'." ).arg( id ); + return throwError(exec, msg,KJS::ReferenceError); +} + + +KJS::Value QCanvasTextImp::setText_5( KJS::ExecState *exec, KJS::Object &obj, const KJS::List &args ) +{ + + QString arg0 = extractQString(exec, args, 0); + + instance->setText( + arg0 ); + return KJS::Value(); // Returns void + +} + +KJS::Value QCanvasTextImp::setFont_6( KJS::ExecState *exec, KJS::Object &obj, const KJS::List &args ) +{ + + QFont arg0 = extractQFont(exec, args, 0); + + instance->setFont( + arg0 ); + return KJS::Value(); // Returns void + +} + +KJS::Value QCanvasTextImp::setColor_7( KJS::ExecState *exec, KJS::Object &obj, const KJS::List &args ) +{ + + QColor arg0 = extractQColor(exec, args, 0); + + instance->setColor( + arg0 ); + return KJS::Value(); // Returns void + +} + +KJS::Value QCanvasTextImp::text_8( KJS::ExecState *exec, KJS::Object &obj, const KJS::List &args ) +{ + + QString ret; + ret = instance->text( ); + return KJS::String( ret ); + +} + +KJS::Value QCanvasTextImp::font_9( KJS::ExecState *exec, KJS::Object &obj, const KJS::List &args ) +{ + + instance->font( ); + return KJS::Value(); // Returns 'QFont' + +} + +KJS::Value QCanvasTextImp::color_10( KJS::ExecState *exec, KJS::Object &obj, const KJS::List &args ) +{ + + instance->color( ); + return KJS::Value(); // Returns 'QColor' + +} + +KJS::Value QCanvasTextImp::moveBy_11( KJS::ExecState *exec, KJS::Object &obj, const KJS::List &args ) +{ + + double arg0 = extractDouble(exec, args, 0); + + double arg1 = extractDouble(exec, args, 1); + + instance->moveBy( + arg0, + arg1 ); + return KJS::Value(); // Returns void + +} + +KJS::Value QCanvasTextImp::textFlags_12( KJS::ExecState *exec, KJS::Object &obj, const KJS::List &args ) +{ + + int ret; + ret = instance->textFlags( ); + return KJS::Number( ret ); + +} + +KJS::Value QCanvasTextImp::setTextFlags_13( KJS::ExecState *exec, KJS::Object &obj, const KJS::List &args ) +{ + + int arg0 = extractInt(exec, args, 0); + + instance->setTextFlags( + arg0 ); + return KJS::Value(); // Returns void + +} + +KJS::Value QCanvasTextImp::boundingRect_14( KJS::ExecState *exec, KJS::Object &obj, const KJS::List &args ) +{ + QRect ret; + ret = instance->boundingRect( ); + + return convertToValue( exec, ret ); + +} + +KJS::Value QCanvasTextImp::collidesWith_15( KJS::ExecState *exec, KJS::Object &obj, const KJS::List &args ) +{ + + // Unsupported parameter const QCanvasItem * + return KJS::Value(); + + const QCanvasItem * arg0; // Dummy + + bool ret; + ret = instance->collidesWith( + arg0 ); + return KJS::Boolean( ret ); + +} + +KJS::Value QCanvasTextImp::rtti_16( KJS::ExecState *exec, KJS::Object &obj, const KJS::List &args ) +{ + + int ret; + ret = instance->rtti( ); + return KJS::Number( ret ); + +} + + +} // namespace KJSEmbed + +// Local Variables: +// c-basic-offset: 4 +// End: + + diff --git a/kjsembed/qtbindings/qcanvastext_imp.h b/kjsembed/qtbindings/qcanvastext_imp.h new file mode 100644 index 00000000..56fa2b6a --- /dev/null +++ b/kjsembed/qtbindings/qcanvastext_imp.h @@ -0,0 +1,126 @@ + + + +#ifndef KJSEMBED_QCanvasText_H +#define KJSEMBED_QCanvasText_H + +#include <kjs/interpreter.h> +#include <kjs/object.h> + +#include <kjsembed/jsobjectproxy_imp.h> + +class QCanvasText; + +/** + * Namespace containing the KJSEmbed library. + */ +namespace KJSEmbed { + +/** + * Wrapper class for QCanvasText methods. + * + * @author Richard Moore, rich@kde.org + */ +class QCanvasTextImp : public JSProxyImp +{ +public: + /** Enumerates the constructors supported by this class. */ + enum Constructors { + Constructor_QCanvasText_1, + Constructor_QCanvasText_2, + Constructor_QCanvasText_3, + + LastConstuctor = -1 + }; + + /** Enumerates the methods supported by this class. */ + enum Methods { + + Method_setText_5, + Method_setFont_6, + Method_setColor_7, + Method_text_8, + Method_font_9, + Method_color_10, + Method_moveBy_11, + Method_textFlags_12, + Method_setTextFlags_13, + Method_boundingRect_14, + Method_collidesWith_15, + Method_rtti_16, + Method_Last = -1 + }; + + QCanvasTextImp( KJS::ExecState *exec, int id, bool constructor=false ); + ~QCanvasTextImp(); + + /** + * Adds the static bindings for this class to the specified Object. The + * static bindings are the static methods and the enums of this class. + */ + static void addStaticBindings( KJS::ExecState *exec, KJS::Object &object ); + + /** + * Adds the bindings for this class to the specified Object. The bindings + * added are the instance methods of this class. + */ + static void addBindings( KJS::ExecState *exec, KJS::Object &object ); + + static QCanvasText *toQCanvasText( KJS::Object &object ); + + // + // Constructors implemented by this class. + // + + KJS::Object QCanvasText_1( KJS::ExecState *exec, const KJS::List &args ); + KJS::Object QCanvasText_2( KJS::ExecState *exec, const KJS::List &args ); + KJS::Object QCanvasText_3( KJS::ExecState *exec, const KJS::List &args ); + + // + // Methods implemented by this class. + // + + KJS::Value setText_5( KJS::ExecState *exec, KJS::Object &obj, const KJS::List &args ); + KJS::Value setFont_6( KJS::ExecState *exec, KJS::Object &obj, const KJS::List &args ); + KJS::Value setColor_7( KJS::ExecState *exec, KJS::Object &obj, const KJS::List &args ); + KJS::Value text_8( KJS::ExecState *exec, KJS::Object &obj, const KJS::List &args ); + KJS::Value font_9( KJS::ExecState *exec, KJS::Object &obj, const KJS::List &args ); + KJS::Value color_10( KJS::ExecState *exec, KJS::Object &obj, const KJS::List &args ); + KJS::Value moveBy_11( KJS::ExecState *exec, KJS::Object &obj, const KJS::List &args ); + KJS::Value textFlags_12( KJS::ExecState *exec, KJS::Object &obj, const KJS::List &args ); + KJS::Value setTextFlags_13( KJS::ExecState *exec, KJS::Object &obj, const KJS::List &args ); + KJS::Value boundingRect_14( KJS::ExecState *exec, KJS::Object &obj, const KJS::List &args ); + KJS::Value collidesWith_15( KJS::ExecState *exec, KJS::Object &obj, const KJS::List &args ); + KJS::Value rtti_16( KJS::ExecState *exec, KJS::Object &obj, const KJS::List &args ); + + // + // JS binding code. + // + + /** Returns true iff this object implements the construct function. */ + virtual bool implementsConstruct() const { return cons; } + + /** Invokes the construct function. */ + virtual KJS::Object construct( KJS::ExecState *exec, const KJS::List &args ); + + /** Returns true iff this object implements the call function. */ + virtual bool implementsCall() const { return !cons; } + + /** Invokes the call function. */ + virtual KJS::Value call( KJS::ExecState *exec, KJS::Object &self, const KJS::List &args ); + +private: + QCanvasText *instance; // Temp + int id; + bool cons; +}; + +} // namespace KJSEmbed + +#endif // KJSEMBED_QCanvasText_H + +// Local Variables: +// c-basic-offset: 4 +// End: + + diff --git a/kjsembed/qtbindings/qcanvasview_imp.cpp b/kjsembed/qtbindings/qcanvasview_imp.cpp new file mode 100644 index 00000000..f51e7f0c --- /dev/null +++ b/kjsembed/qtbindings/qcanvasview_imp.cpp @@ -0,0 +1,276 @@ + + + +#include <qcstring.h> +#include <qimage.h> +#include <qpainter.h> +#include <qpalette.h> +#include <qpixmap.h> +#include <qfont.h> + +#include <kjs/object.h> + +#include <kjsembed/global.h> +#include <kjsembed/jsobjectproxy.h> +#include <kjsembed/jsopaqueproxy.h> +#include <kjsembed/jsbinding.h> + +#include <qcanvas.h> +#include "qcanvasview_imp.h" + +/** + * Namespace containing the KJSEmbed library. + */ +namespace KJSEmbed { + +QCanvasViewImp::QCanvasViewImp( KJS::ExecState *exec, int mid, bool constructor ) + : JSProxyImp(exec), id(mid), cons(constructor) +{ +} + +QCanvasViewImp::~QCanvasViewImp() +{ +} + +/** + * Adds bindings for static methods and enum constants to the specified Object. + */ +void QCanvasViewImp::addStaticBindings( KJS::ExecState *exec, KJS::Object &object ) +{ + JSProxy::MethodTable methods[] = { + + { 0, 0 } + }; + + int idx = 0; + QCString lastName; + + while( methods[idx].name ) { + if ( lastName != methods[idx].name ) { + QCanvasViewImp *meth = new QCanvasViewImp( exec, methods[idx].id ); + object.put( exec , methods[idx].name, KJS::Object(meth) ); + lastName = methods[idx].name; + } + ++idx; + } + + +} + +/** + * Adds bindings for instance methods to the specified Object. + */ +void QCanvasViewImp::addBindings( KJS::ExecState *exec, KJS::Object &object ) +{ + JSProxy::MethodTable methods[] = { + + { Method_canvas_4, "canvas" }, + { Method_setCanvas_5, "setCanvas" }, + { Method_worldMatrix_6, "worldMatrix" }, + { Method_inverseWorldMatrix_7, "inverseWorldMatrix" }, + { Method_setWorldMatrix_8, "setWorldMatrix" }, + { 0, 0 } + }; + + int idx = 0; + QCString lastName; + + while( methods[idx].name ) { + if ( lastName != methods[idx].name ) { + QCanvasViewImp *meth = new QCanvasViewImp( exec, methods[idx].id ); + object.put( exec , methods[idx].name, KJS::Object(meth) ); + lastName = methods[idx].name; + } + ++idx; + } +} + +/** + * Extract a QCanvasView pointer from an Object. + */ +QCanvasView *QCanvasViewImp::toQCanvasView( KJS::Object &self ) +{ + JSObjectProxy *ob = JSProxy::toObjectProxy( self.imp() ); + if ( ob ) { + QObject *obj = ob->object(); + if ( obj ) + return dynamic_cast<QCanvasView *>( obj ); + } + + JSOpaqueProxy *op = JSProxy::toOpaqueProxy( self.imp() ); + if ( !op ) + return 0; + + if ( op->typeName() != "QCanvasView" ) + return 0; + + return op->toNative<QCanvasView>(); +} + +/** + * Select and invoke the correct constructor. + */ +KJS::Object QCanvasViewImp::construct( KJS::ExecState *exec, const KJS::List &args ) +{ + switch( id ) { + + case Constructor_QCanvasView_1: + return QCanvasView_1( exec, args ); + break; + + case Constructor_QCanvasView_2: + return QCanvasView_2( exec, args ); + break; + + default: + break; + } + + QString msg = i18n("QCanvasViewCons has no constructor with id '%1'.").arg(id); + return throwError(exec, msg,KJS::ReferenceError); +} + + +KJS::Object QCanvasViewImp::QCanvasView_1( KJS::ExecState *exec, const KJS::List &args ) +{ + + QWidget *arg0 = extractQWidget(exec, args, 0); + + + const char *arg1 = (args.size() >= 2) ? args[1].toString(exec).ascii() : 0; + + Qt::WFlags arg2 = 0; // TODO (hack for QCanvasView) + + + // We should now create an instance of the QCanvasView object + + QCanvasView *ret = new QCanvasView( + + arg0, + arg1, + arg2 ); + + JSOpaqueProxy *prx = new JSOpaqueProxy( ret, "QCanvasView"); + return KJS::Object( prx ); +} + +KJS::Object QCanvasViewImp::QCanvasView_2( KJS::ExecState *exec, const KJS::List &args ) +{ + QCanvas * arg0 = 0L;; + + KJS::Object obj = args[0].toObject(exec); + JSObjectProxy *proxy = JSProxy::toObjectProxy( obj.imp() ); + if ( proxy ) arg0 = dynamic_cast<QCanvas *>( proxy->widget() ); + + QWidget * arg1 = extractQWidget(exec, args, 1); + + const char *arg2 = (args.size() >= 3) ? args[2].toString(exec).ascii() : 0; + + Qt::WFlags arg3 = 0; // TODO (hack for QCanvasView) + + + // We should now create an instance of the QCanvasView object + + QCanvasView *ret = new QCanvasView( + arg0, + arg1, + arg2, + arg3 ); + + JSOpaqueProxy *prx = new JSOpaqueProxy( ret, "QCanvasView"); + return KJS::Object( prx ); +} + +KJS::Value QCanvasViewImp::call( KJS::ExecState *exec, KJS::Object &self, const KJS::List &args ) +{ + instance = QCanvasViewImp::toQCanvasView( self ); + + switch( id ) { + + case Method_canvas_4: + return canvas_4( exec, self, args ); + break; + + case Method_setCanvas_5: + return setCanvas_5( exec, self, args ); + break; + + case Method_worldMatrix_6: + return worldMatrix_6( exec, self, args ); + break; + + case Method_inverseWorldMatrix_7: + return inverseWorldMatrix_7( exec, self, args ); + break; + + case Method_setWorldMatrix_8: + return setWorldMatrix_8( exec, self, args ); + break; + + default: + break; + } + + QString msg = i18n( "QCanvasViewImp has no method with id '%1'." ).arg( id ); + return throwError(exec, msg,KJS::ReferenceError); +} + + +KJS::Value QCanvasViewImp::canvas_4( KJS::ExecState *exec, KJS::Object &obj, const KJS::List &args ) +{ + + instance->canvas( ); + return KJS::Value(); // Returns 'QCanvas *' + +} + +KJS::Value QCanvasViewImp::setCanvas_5( KJS::ExecState *exec, KJS::Object &obj, const KJS::List &args ) +{ + + // Unsupported parameter QCanvas * + return KJS::Value(); + + QCanvas * arg0; // Dummy + + instance->setCanvas( + arg0 ); + return KJS::Value(); // Returns void + +} + +KJS::Value QCanvasViewImp::worldMatrix_6( KJS::ExecState *exec, KJS::Object &obj, const KJS::List &args ) +{ + + instance->worldMatrix( ); + return KJS::Value(); // Returns 'const QWMatrix &' + +} + +KJS::Value QCanvasViewImp::inverseWorldMatrix_7( KJS::ExecState *exec, KJS::Object &obj, const KJS::List &args ) +{ + + instance->inverseWorldMatrix( ); + return KJS::Value(); // Returns 'const QWMatrix &' + +} + +KJS::Value QCanvasViewImp::setWorldMatrix_8( KJS::ExecState *exec, KJS::Object &obj, const KJS::List &args ) +{ + + QWMatrix arg0; // TODO (hack for qcanvasview) + + bool ret; + ret = instance->setWorldMatrix( + arg0 ); + return KJS::Boolean( ret ); + +} + + +} // namespace KJSEmbed + +// Local Variables: +// c-basic-offset: 4 +// End: + + diff --git a/kjsembed/qtbindings/qcanvasview_imp.h b/kjsembed/qtbindings/qcanvasview_imp.h new file mode 100644 index 00000000..59024535 --- /dev/null +++ b/kjsembed/qtbindings/qcanvasview_imp.h @@ -0,0 +1,110 @@ + + + +#ifndef KJSEMBED_QCanvasView_H +#define KJSEMBED_QCanvasView_H + +#include <kjs/interpreter.h> +#include <kjs/object.h> + +#include <kjsembed/jsobjectproxy_imp.h> + +class QCanvasView; + +/** + * Namespace containing the KJSEmbed library. + */ +namespace KJSEmbed { + +/** + * Wrapper class for QCanvasView methods. + * + * @author Richard Moore, rich@kde.org + */ +class QCanvasViewImp : public JSProxyImp +{ +public: + /** Enumerates the constructors supported by this class. */ + enum Constructors { + Constructor_QCanvasView_1, + Constructor_QCanvasView_2, + + LastConstuctor = -1 + }; + + /** Enumerates the methods supported by this class. */ + enum Methods { + + Method_canvas_4, + Method_setCanvas_5, + Method_worldMatrix_6, + Method_inverseWorldMatrix_7, + Method_setWorldMatrix_8, + Method_Last = -1 + }; + + QCanvasViewImp( KJS::ExecState *exec, int id, bool constructor=false ); + ~QCanvasViewImp(); + + /** + * Adds the static bindings for this class to the specified Object. The + * static bindings are the static methods and the enums of this class. + */ + static void addStaticBindings( KJS::ExecState *exec, KJS::Object &object ); + + /** + * Adds the bindings for this class to the specified Object. The bindings + * added are the instance methods of this class. + */ + static void addBindings( KJS::ExecState *exec, KJS::Object &object ); + + static QCanvasView *toQCanvasView( KJS::Object &object ); + + // + // Constructors implemented by this class. + // + + KJS::Object QCanvasView_1( KJS::ExecState *exec, const KJS::List &args ); + KJS::Object QCanvasView_2( KJS::ExecState *exec, const KJS::List &args ); + + // + // Methods implemented by this class. + // + + KJS::Value canvas_4( KJS::ExecState *exec, KJS::Object &obj, const KJS::List &args ); + KJS::Value setCanvas_5( KJS::ExecState *exec, KJS::Object &obj, const KJS::List &args ); + KJS::Value worldMatrix_6( KJS::ExecState *exec, KJS::Object &obj, const KJS::List &args ); + KJS::Value inverseWorldMatrix_7( KJS::ExecState *exec, KJS::Object &obj, const KJS::List &args ); + KJS::Value setWorldMatrix_8( KJS::ExecState *exec, KJS::Object &obj, const KJS::List &args ); + + // + // JS binding code. + // + + /** Returns true iff this object implements the construct function. */ + virtual bool implementsConstruct() const { return cons; } + + /** Invokes the construct function. */ + virtual KJS::Object construct( KJS::ExecState *exec, const KJS::List &args ); + + /** Returns true iff this object implements the call function. */ + virtual bool implementsCall() const { return !cons; } + + /** Invokes the call function. */ + virtual KJS::Value call( KJS::ExecState *exec, KJS::Object &self, const KJS::List &args ); + +private: + QCanvasView *instance; // Temp + int id; + bool cons; +}; + +} // namespace KJSEmbed + +#endif // KJSEMBED_QCanvasView_H + +// Local Variables: +// c-basic-offset: 4 +// End: + + diff --git a/kjsembed/qtbindings/qchecklistitem_imp.cpp b/kjsembed/qtbindings/qchecklistitem_imp.cpp new file mode 100644 index 00000000..afa32dab --- /dev/null +++ b/kjsembed/qtbindings/qchecklistitem_imp.cpp @@ -0,0 +1,587 @@ + + + +#include <qcstring.h> +#include <qpalette.h> +#include <qpixmap.h> +#include <qfont.h> + +#include <kjs/object.h> + +#include <kjsembed/global.h> +#include <kjsembed/jsobjectproxy.h> +#include <kjsembed/jsopaqueproxy.h> +#include <kjsembed/jsbinding.h> + +#include <qlistview.h> +#include "qchecklistitem_imp.h" +#include "qlistviewitem_imp.h" +/** + * Namespace containing the KJSEmbed library. + */ +namespace KJSEmbed { +namespace Bindings { + + KJS::Object QCheckListItemLoader::createBinding(KJSEmbedPart *jspart, KJS::ExecState *exec, const KJS::List &args) const + { + if ( args.size() == 0 ) { + // FALL THRU + } else { + JSOpaqueProxy * arg0 = JSProxy::toOpaqueProxy( args[ 0 ].imp() ); + QString arg1 = ( args.size() >= 2 ) ? args[ 1 ].toString( exec ).qstring() : QString::null; + JSOpaqueProxy *prx = 0; + + if ( arg0 ) { + if ( arg0->typeName() == "QListViewItem" ) { + QListViewItem * parent = arg0->toNative<QListViewItem>(); + prx = new JSOpaqueProxy( new QCheckListItem( parent, arg1 ), "QCheckListItem" ); + } else { + return KJS::Object(); + } + } else { + JSObjectProxy *arg0 = JSProxy::toObjectProxy( args[ 0 ].imp() ); + if ( arg0 ) { + QListView * parent = ( QListView * ) ( arg0->widget() ); + prx = new JSOpaqueProxy( new QCheckListItem( parent, arg1 ), "QCheckListItem" ); + } else { + return KJS::Object(); + } + } + prx->setOwner( JSProxy::Native ); + KJS::Object proxyObj( prx ); + addBindings(jspart, exec, proxyObj ); + return proxyObj; + } + return KJS::Object(); + } + void QCheckListItemLoader::addBindings( KJSEmbedPart *jspart, KJS::ExecState *exec, KJS::Object &proxy ) const + { + QListViewItemImp::addBindings( exec, proxy ); + QCheckListItemImp::addBindings( exec, proxy ); + } + +} +QCheckListItemImp::QCheckListItemImp( KJS::ExecState *exec, int mid, bool constructor ) + : JSProxyImp(exec), id(mid), cons(constructor) +{ +} + +QCheckListItemImp::~QCheckListItemImp() +{ +} + +void QCheckListItemImp::addBindings( KJS::ExecState *exec, KJS::Object &object ) +{ + JSProxy::MethodTable methods[] = { + + { Method_paintCell_10, "paintCell" }, + { Method_paintFocus_11, "paintFocus" }, + { Method_width_12, "width" }, + { Method_setup_13, "setup" }, + { Method_setOn_14, "setOn" }, + { Method_isOn_15, "isOn" }, + { Method_type_16, "type" }, + { Method_text_17, "text" }, + { Method_text_18, "text" }, + { Method_setTristate_19, "setTristate" }, + { Method_isTristate_20, "isTristate" }, + { Method_state_21, "state" }, + { Method_setState_22, "setState" }, + { Method_rtti_23, "rtti" }, + { 0, 0 } + }; + + int idx = 0; + QCString lastName; + + while( methods[idx].id ) { + if ( lastName != methods[idx].name ) { + QCheckListItemImp *meth = new QCheckListItemImp( exec, methods[idx].id ); + object.put( exec , methods[idx].name, KJS::Object(meth) ); + lastName = methods[idx].name; + } + ++idx; + } + + + // + // Define the enum constants + // + struct EnumValue { + const char *id; + int val; + }; + + EnumValue enums[] = { + + // enum Type + { "RadioButton", QCheckListItem::RadioButton }, + { "CheckBox", QCheckListItem::CheckBox }, + { "Controller", QCheckListItem::Controller }, + { "RadioButtonController", QCheckListItem::RadioButtonController }, + { "CheckBoxController", QCheckListItem::CheckBoxController }, + // enum ToggleState + { "Off", QCheckListItem::Off }, + { "NoChange", QCheckListItem::NoChange }, + { "On", QCheckListItem::On }, + { 0, 0 } + }; + + int enumidx = 0; + do { + object.put( exec, enums[enumidx].id, KJS::Number(enums[enumidx].val), KJS::ReadOnly ); + ++enumidx; + } while( enums[enumidx].id ); + +} + +QCheckListItem *QCheckListItemImp::toQCheckListItem( KJS::Object &self ) +{ + JSObjectProxy *ob = JSProxy::toObjectProxy( self.imp() ); + if ( ob ) { + QObject *obj = ob->object(); + if ( obj ) + return dynamic_cast<QCheckListItem *>( obj ); + } + + JSOpaqueProxy *op = JSProxy::toOpaqueProxy( self.imp() ); + if ( !op ) + return 0; + return op->toNative<QCheckListItem>(); +} + + +KJS::Object QCheckListItemImp::construct( KJS::ExecState *exec, const KJS::List &args ) +{ + switch( id ) { + + case Constructor_QCheckListItem_1: + return QCheckListItem_1( exec, args ); + break; + + case Constructor_QCheckListItem_2: + return QCheckListItem_2( exec, args ); + break; + + case Constructor_QCheckListItem_3: + return QCheckListItem_3( exec, args ); + break; + + case Constructor_QCheckListItem_4: + return QCheckListItem_4( exec, args ); + break; + + case Constructor_QCheckListItem_5: + return QCheckListItem_5( exec, args ); + break; + + case Constructor_QCheckListItem_6: + return QCheckListItem_6( exec, args ); + break; + + case Constructor_QCheckListItem_7: + return QCheckListItem_7( exec, args ); + break; + + case Constructor_QCheckListItem_8: + return QCheckListItem_8( exec, args ); + break; + + default: + break; + } + + QString msg = i18n("QCheckListItemCons has no constructor with id '%1'.").arg(id); + return throwError(exec, msg,KJS::ReferenceError); +} + + +KJS::Object QCheckListItemImp::QCheckListItem_1( KJS::ExecState *exec, const KJS::List &args ) +{ + + QWidget *arg0 = extractQWidget(exec,args,0); + + QWidget *arg1 = extractQWidget(exec,args,1); + + QWidget *arg2 = extractQWidget(exec,args,2); + + return KJS::Object( ); +} + +KJS::Object QCheckListItemImp::QCheckListItem_2( KJS::ExecState *exec, const KJS::List &args ) +{ + + // TODO + QWidget *arg0 = extractQWidget(exec,args,0); + + // TODO + QWidget *arg1 = extractQWidget(exec,args,0); + + // TODO + QWidget *arg2 = extractQWidget(exec,args,0); + + // TODO + QWidget *arg3 = extractQWidget(exec,args,0); + return KJS::Object(); + +} + +KJS::Object QCheckListItemImp::QCheckListItem_3( KJS::ExecState *exec, const KJS::List &args ) +{ + + // TODO + QWidget *arg0 = extractQWidget(exec,args,0); + + // TODO + QWidget *arg1 = extractQWidget(exec,args,0); + + // TODO + QWidget *arg2 = extractQWidget(exec,args,0); + return KJS::Object(); + +} + +KJS::Object QCheckListItemImp::QCheckListItem_4( KJS::ExecState *exec, const KJS::List &args ) +{ + + // TODO + QWidget *arg0 = extractQWidget(exec,args,0); + + // TODO + QWidget *arg1 = extractQWidget(exec,args,0); + + // TODO + QWidget *arg2 = extractQWidget(exec,args,0); + + // TODO + QWidget *arg3 = extractQWidget(exec,args,0); + return KJS::Object(); + +} + +KJS::Object QCheckListItemImp::QCheckListItem_5( KJS::ExecState *exec, const KJS::List &args ) +{ + + // TODO + QWidget *arg0 = extractQWidget(exec,args,0); + + // TODO + QWidget *arg1 = extractQWidget(exec,args,0); + + // TODO + QWidget *arg2 = extractQWidget(exec,args,0); + return KJS::Object(); + +} + +KJS::Object QCheckListItemImp::QCheckListItem_6( KJS::ExecState *exec, const KJS::List &args ) +{ + + // TODO + QWidget *arg0 = extractQWidget(exec,args,0); + + // TODO + QWidget *arg1 = extractQWidget(exec,args,0); + + // TODO + QWidget *arg2 = extractQWidget(exec,args,0); + + // TODO + QWidget *arg3 = extractQWidget(exec,args,0); + return KJS::Object(); + +} + +KJS::Object QCheckListItemImp::QCheckListItem_7( KJS::ExecState *exec, const KJS::List &args ) +{ + + // TODO + QWidget *arg0 = extractQWidget(exec,args,0); + + // TODO + QWidget *arg1 = extractQWidget(exec,args,0); + + // TODO + QWidget *arg2 = extractQWidget(exec,args,0); + return KJS::Object(); + +} + +KJS::Object QCheckListItemImp::QCheckListItem_8( KJS::ExecState *exec, const KJS::List &args ) +{ + + // TODO + QWidget *arg0 = extractQWidget(exec,args,0); + + // TODO + QWidget *arg1 = extractQWidget(exec,args,0); + + // TODO + QWidget *arg2 = extractQWidget(exec,args,0); + return KJS::Object(); + +} + +KJS::Value QCheckListItemImp::call( KJS::ExecState *exec, KJS::Object &self, const KJS::List &args ) +{ + instance = QCheckListItemImp::toQCheckListItem( self ); + + switch( id ) { + + case Method_paintCell_10: + return paintCell_10( exec, self, args ); + break; + + case Method_paintFocus_11: + return paintFocus_11( exec, self, args ); + break; + + case Method_width_12: + return width_12( exec, self, args ); + break; + + case Method_setup_13: + return setup_13( exec, self, args ); + break; + + case Method_setOn_14: + return setOn_14( exec, self, args ); + break; + + case Method_isOn_15: + return isOn_15( exec, self, args ); + break; + + case Method_type_16: + return type_16( exec, self, args ); + break; + + case Method_text_17: + return text_17( exec, self, args ); + break; + + case Method_text_18: + return text_18( exec, self, args ); + break; + + case Method_setTristate_19: + return setTristate_19( exec, self, args ); + break; + + case Method_isTristate_20: + return isTristate_20( exec, self, args ); + break; + + case Method_state_21: + return state_21( exec, self, args ); + break; + + case Method_setState_22: + return setState_22( exec, self, args ); + break; + + case Method_rtti_23: + return rtti_23( exec, self, args ); + break; + + default: + break; + } + + QString msg = i18n( "QCheckListItemImp has no method with id '%1'." ).arg( id ); + return throwError(exec, msg,KJS::ReferenceError); +} + + +KJS::Value QCheckListItemImp::paintCell_10( KJS::ExecState *exec, KJS::Object &obj, const KJS::List &args ) +{ + + // Unsupported parameter QPainter * + return KJS::Value(); + + QPainter * arg0; // Dummy + + // Unsupported parameter const QColorGroup & + return KJS::Value(); +#if 0 + const QColorGroup & arg1; // Dummy + + int arg2 = (args.size() >= 3) ? args[2].toInteger(exec) : -1; + + int arg3 = (args.size() >= 4) ? args[3].toInteger(exec) : -1; + + int arg4 = (args.size() >= 5) ? args[4].toInteger(exec) : -1; + + instance->paintCell( + arg0, + arg1, + arg2, + arg3, + arg4 ); + return KJS::Value(); // Returns void +#endif +} + +KJS::Value QCheckListItemImp::paintFocus_11( KJS::ExecState *exec, KJS::Object &obj, const KJS::List &args ) +{ + + // Unsupported parameter QPainter * + return KJS::Value(); +#if 0 + QPainter * arg0; // Dummy + + // Unsupported parameter const QColorGroup & + return KJS::Value(); + + const QColorGroup & arg1; // Dummy + + QRect arg2 = extractQRect(exec, args, 2); + + instance->paintFocus( + arg0, + arg1, + arg2 ); + return KJS::Value(); // Returns void +#endif +} + +KJS::Value QCheckListItemImp::width_12( KJS::ExecState *exec, KJS::Object &obj, const KJS::List &args ) +{ + + // Unsupported parameter const QFontMetrics & + return KJS::Value(); +#if 0 + const QFontMetrics & arg0; // Dummy + + // Unsupported parameter const QListView * + return KJS::Value(); + + const QListView * arg1; // Dummy + + int arg2 = (args.size() >= 3) ? args[2].toInteger(exec) : -1; + + int ret; + ret = instance->width( + arg0, + arg1, + arg2 ); + return KJS::Number( ret ); +#endif +} + +KJS::Value QCheckListItemImp::setup_13( KJS::ExecState *exec, KJS::Object &obj, const KJS::List &args ) +{ + + instance->setup( ); + return KJS::Value(); // Returns void + +} + +KJS::Value QCheckListItemImp::setOn_14( KJS::ExecState *exec, KJS::Object &obj, const KJS::List &args ) +{ + + bool arg0 = (args.size() >= 1) ? args[0].toBoolean(exec) : false; + + instance->setOn( + arg0 ); + return KJS::Value(); // Returns void + +} + +KJS::Value QCheckListItemImp::isOn_15( KJS::ExecState *exec, KJS::Object &obj, const KJS::List &args ) +{ + + bool ret; + ret = instance->isOn( ); + return KJS::Boolean( ret ); + +} + +KJS::Value QCheckListItemImp::type_16( KJS::ExecState *exec, KJS::Object &obj, const KJS::List &args ) +{ + + instance->type( ); + return KJS::Value(); // Returns 'Type' + +} + +KJS::Value QCheckListItemImp::text_17( KJS::ExecState *exec, KJS::Object &obj, const KJS::List &args ) +{ + + QString ret; + ret = instance->text( ); + return KJS::String( ret ); + +} + +KJS::Value QCheckListItemImp::text_18( KJS::ExecState *exec, KJS::Object &obj, const KJS::List &args ) +{ + + int arg0 = (args.size() >= 1) ? args[0].toInteger(exec) : -1; + + QString ret; + ret = instance->text( + arg0 ); + return KJS::String( ret ); + +} + +KJS::Value QCheckListItemImp::setTristate_19( KJS::ExecState *exec, KJS::Object &obj, const KJS::List &args ) +{ + + bool arg0 = (args.size() >= 1) ? args[0].toBoolean(exec) : false; + + instance->setTristate( + arg0 ); + return KJS::Value(); // Returns void + +} + +KJS::Value QCheckListItemImp::isTristate_20( KJS::ExecState *exec, KJS::Object &obj, const KJS::List &args ) +{ + + bool ret; + ret = instance->isTristate( ); + return KJS::Boolean( ret ); + +} + +KJS::Value QCheckListItemImp::state_21( KJS::ExecState *exec, KJS::Object &obj, const KJS::List &args ) +{ + + instance->state( ); + return KJS::Value(); // Returns 'ToggleState' + +} + +KJS::Value QCheckListItemImp::setState_22( KJS::ExecState *exec, KJS::Object &obj, const KJS::List &args ) +{ + + // Unsupported parameter ToggleState + return KJS::Value(); +#if 0 + ToggleState arg0; // Dummy + + instance->setState( + arg0 ); + return KJS::Value(); // Returns void +#endif +} + +KJS::Value QCheckListItemImp::rtti_23( KJS::ExecState *exec, KJS::Object &obj, const KJS::List &args ) +{ + + int ret; + ret = instance->rtti( ); + return KJS::Number( ret ); + +} + + +} // namespace KJSEmbed + +// Local Variables: +// c-basic-offset: 4 +// End: + + diff --git a/kjsembed/qtbindings/qchecklistitem_imp.h b/kjsembed/qtbindings/qchecklistitem_imp.h new file mode 100644 index 00000000..a1030d2a --- /dev/null +++ b/kjsembed/qtbindings/qchecklistitem_imp.h @@ -0,0 +1,139 @@ + + + +#ifndef KJSEMBED_QCheckListItem_H +#define KJSEMBED_QCheckListItem_H + +#include <kjs/interpreter.h> +#include <kjs/object.h> + +#include <kjsembed/jsobjectproxy_imp.h> +#include <kjsembed/jsbindingbase.h> + +class QCheckListItem; + +/** + * Namespace containing the KJSEmbed library. + */ +namespace KJSEmbed { +namespace Bindings { + + class QCheckListItemLoader : public JSBindingBase + { + public: + KJS::Object createBinding(KJSEmbedPart *jspart, KJS::ExecState *exec, const KJS::List &args) const; + void addBindings( KJSEmbedPart *jspart, KJS::ExecState *exec, KJS::Object &proxy) const; + }; +} +/** + * Wrapper class for QCheckListItem methods. + * + * @author Richard Moore, rich@kde.org + */ +class QCheckListItemImp : public JSProxyImp +{ +public: + /** Enumerates the constructors supported by this class. */ + enum Constructors { + Constructor_QCheckListItem_1, + Constructor_QCheckListItem_2, + Constructor_QCheckListItem_3, + Constructor_QCheckListItem_4, + Constructor_QCheckListItem_5, + Constructor_QCheckListItem_6, + Constructor_QCheckListItem_7, + Constructor_QCheckListItem_8, + + LastConstuctor = -1 + }; + + /** Enumerates the methods supported by this class. */ + enum Methods { + + Method_paintCell_10, + Method_paintFocus_11, + Method_width_12, + Method_setup_13, + Method_setOn_14, + Method_isOn_15, + Method_type_16, + Method_text_17, + Method_text_18, + Method_setTristate_19, + Method_isTristate_20, + Method_state_21, + Method_setState_22, + Method_rtti_23, + Method_Last = -1 + }; + + QCheckListItemImp( KJS::ExecState *exec, int id, bool constructor=false ); + ~QCheckListItemImp(); + + static void addBindings( KJS::ExecState *exec, KJS::Object &object ); + + static QCheckListItem *toQCheckListItem( KJS::Object &object ); + + // + // Constructors implemented by this class. + // + + KJS::Object QCheckListItem_1( KJS::ExecState *exec, const KJS::List &args ); + KJS::Object QCheckListItem_2( KJS::ExecState *exec, const KJS::List &args ); + KJS::Object QCheckListItem_3( KJS::ExecState *exec, const KJS::List &args ); + KJS::Object QCheckListItem_4( KJS::ExecState *exec, const KJS::List &args ); + KJS::Object QCheckListItem_5( KJS::ExecState *exec, const KJS::List &args ); + KJS::Object QCheckListItem_6( KJS::ExecState *exec, const KJS::List &args ); + KJS::Object QCheckListItem_7( KJS::ExecState *exec, const KJS::List &args ); + KJS::Object QCheckListItem_8( KJS::ExecState *exec, const KJS::List &args ); + + // + // Methods implemented by this class. + // + + KJS::Value paintCell_10( KJS::ExecState *exec, KJS::Object &obj, const KJS::List &args ); + KJS::Value paintFocus_11( KJS::ExecState *exec, KJS::Object &obj, const KJS::List &args ); + KJS::Value width_12( KJS::ExecState *exec, KJS::Object &obj, const KJS::List &args ); + KJS::Value setup_13( KJS::ExecState *exec, KJS::Object &obj, const KJS::List &args ); + KJS::Value setOn_14( KJS::ExecState *exec, KJS::Object &obj, const KJS::List &args ); + KJS::Value isOn_15( KJS::ExecState *exec, KJS::Object &obj, const KJS::List &args ); + KJS::Value type_16( KJS::ExecState *exec, KJS::Object &obj, const KJS::List &args ); + KJS::Value text_17( KJS::ExecState *exec, KJS::Object &obj, const KJS::List &args ); + KJS::Value text_18( KJS::ExecState *exec, KJS::Object &obj, const KJS::List &args ); + KJS::Value setTristate_19( KJS::ExecState *exec, KJS::Object &obj, const KJS::List &args ); + KJS::Value isTristate_20( KJS::ExecState *exec, KJS::Object &obj, const KJS::List &args ); + KJS::Value state_21( KJS::ExecState *exec, KJS::Object &obj, const KJS::List &args ); + KJS::Value setState_22( KJS::ExecState *exec, KJS::Object &obj, const KJS::List &args ); + KJS::Value rtti_23( KJS::ExecState *exec, KJS::Object &obj, const KJS::List &args ); + + // + // JS binding code. + // + + /** Returns true iff this object implements the construct function. */ + virtual bool implementsConstruct() const { return cons; } + + /** Invokes the construct function. */ + virtual KJS::Object construct( KJS::ExecState *exec, const KJS::List &args ); + + /** Returns true iff this object implements the call function. */ + virtual bool implementsCall() const { return !cons; } + + /** Invokes the call function. */ + virtual KJS::Value call( KJS::ExecState *exec, KJS::Object &self, const KJS::List &args ); + +private: + QCheckListItem *instance; // Temp + int id; + bool cons; +}; + +} // namespace KJSEmbed + +#endif // KJSEMBED_QCheckListItem_H + +// Local Variables: +// c-basic-offset: 4 +// End: + + diff --git a/kjsembed/qtbindings/qcombobox_imp.cpp b/kjsembed/qtbindings/qcombobox_imp.cpp new file mode 100644 index 00000000..56407cb7 --- /dev/null +++ b/kjsembed/qtbindings/qcombobox_imp.cpp @@ -0,0 +1,964 @@ + + + +#include <qcstring.h> +#include <qpalette.h> +#include <qpixmap.h> +#include <qfont.h> + +#include <kjs/object.h> + +#include <kjsembed/global.h> +#include <kjsembed/jsobjectproxy.h> +#include <kjsembed/jsopaqueproxy.h> +#include <kjsembed/jsbinding.h> + +#include <qcombobox.h> +#include "qcombobox_imp.h" + +/** + * Namespace containing the KJSEmbed library. + */ +namespace KJSEmbed { + +QComboBoxImp::QComboBoxImp( KJS::ExecState *exec, int mid, bool constructor ) + : JSProxyImp(exec), id(mid), cons(constructor) +{ +} + +QComboBoxImp::~QComboBoxImp() +{ +} + +/** + * Adds bindings for static methods and enum constants to the specified Object. + */ +void QComboBoxImp::addStaticBindings( KJS::ExecState *exec, KJS::Object &object ) +{ + JSProxy::MethodTable methods[] = { + + { 0, 0 } + }; + + int idx = 0; + QCString lastName; + + while( methods[idx].name ) { + if ( lastName != methods[idx].name ) { + QComboBoxImp *meth = new QComboBoxImp( exec, methods[idx].id ); + object.put( exec , methods[idx].name, KJS::Object(meth) ); + lastName = methods[idx].name; + } + ++idx; + } + + + // + // Define the enum constants + // + struct EnumValue { + const char *id; + int val; + }; + + EnumValue enums[] = { + + // enum Policy + { "NoInsertion", QComboBox::NoInsertion }, + { "AtTop", QComboBox::AtTop }, + { "AtCurrent", QComboBox::AtCurrent }, + { "AtBottom", QComboBox::AtBottom }, + { "AfterCurrent", QComboBox::AfterCurrent }, + { "BeforeCurrent", QComboBox::BeforeCurrent }, + { 0, 0 } + }; + + int enumidx = 0; + while( enums[enumidx].id ) { + object.put( exec, enums[enumidx].id, KJS::Number(enums[enumidx].val), KJS::ReadOnly ); + ++enumidx; + } + +} + +/** + * Adds bindings for instance methods to the specified Object. + */ +void QComboBoxImp::addBindings( KJS::ExecState *exec, KJS::Object &object ) +{ + JSProxy::MethodTable methods[] = { + + { Method_count_4, "count" }, + { Method_insertStringList_5, "insertStringList" }, + { Method_insertStrList_6, "insertStrList" }, + { Method_insertStrList_7, "insertStrList" }, + { Method_insertStrList_8, "insertStrList" }, + { Method_insertItem_9, "insertItem" }, + { Method_insertItem_10, "insertItem" }, + { Method_insertItem_11, "insertItem" }, + { Method_removeItem_12, "removeItem" }, + { Method_currentItem_13, "currentItem" }, + { Method_setCurrentItem_14, "setCurrentItem" }, + { Method_currentText_15, "currentText" }, + { Method_setCurrentText_16, "setCurrentText" }, + { Method_text_17, "text" }, + { Method_pixmap_18, "pixmap" }, + { Method_changeItem_19, "changeItem" }, + { Method_changeItem_20, "changeItem" }, + { Method_changeItem_21, "changeItem" }, + { Method_autoResize_22, "autoResize" }, + { Method_setAutoResize_23, "setAutoResize" }, + { Method_sizeHint_24, "sizeHint" }, + { Method_setPalette_25, "setPalette" }, + { Method_setFont_26, "setFont" }, + { Method_setEnabled_27, "setEnabled" }, + { Method_setSizeLimit_28, "setSizeLimit" }, + { Method_sizeLimit_29, "sizeLimit" }, + { Method_setMaxCount_30, "setMaxCount" }, + { Method_maxCount_31, "maxCount" }, + { Method_setInsertionPolicy_32, "setInsertionPolicy" }, + { Method_insertionPolicy_33, "insertionPolicy" }, + { Method_setValidator_34, "setValidator" }, + { Method_validator_35, "validator" }, + { Method_setListBox_36, "setListBox" }, + { Method_listBox_37, "listBox" }, + { Method_setLineEdit_38, "setLineEdit" }, + { Method_lineEdit_39, "lineEdit" }, + { Method_setAutoCompletion_40, "setAutoCompletion" }, + { Method_autoCompletion_41, "autoCompletion" }, + { Method_eventFilter_42, "eventFilter" }, + { Method_setDuplicatesEnabled_43, "setDuplicatesEnabled" }, + { Method_duplicatesEnabled_44, "duplicatesEnabled" }, + { Method_editable_45, "editable" }, + { Method_setEditable_46, "setEditable" }, + { Method_popup_47, "popup" }, + { Method_hide_48, "hide" }, + { 0, 0 } + }; + + int idx = 0; + QCString lastName; + + while( methods[idx].name ) { + if ( lastName != methods[idx].name ) { + QComboBoxImp *meth = new QComboBoxImp( exec, methods[idx].id ); + object.put( exec , methods[idx].name, KJS::Object(meth) ); + lastName = methods[idx].name; + } + ++idx; + } +} + +/** + * Extract a QComboBox pointer from an Object. + */ +QComboBox *QComboBoxImp::toQComboBox( KJS::Object &self ) +{ + JSObjectProxy *ob = JSProxy::toObjectProxy( self.imp() ); + if ( ob ) { + QObject *obj = ob->object(); + if ( obj ) + return dynamic_cast<QComboBox *>( obj ); + } + + JSOpaqueProxy *op = JSProxy::toOpaqueProxy( self.imp() ); + if ( !op ) + return 0; + + if ( op->typeName() != "QComboBox" ) + return 0; + + return op->toNative<QComboBox>(); +} + +/** + * Select and invoke the correct constructor. + */ +KJS::Object QComboBoxImp::construct( KJS::ExecState *exec, const KJS::List &args ) +{ + switch( id ) { + + case Constructor_QComboBox_1: + return QComboBox_1( exec, args ); + break; + + case Constructor_QComboBox_2: + return QComboBox_2( exec, args ); + break; + + default: + break; + } + + QString msg = i18n("QComboBoxCons has no constructor with id '%1'.").arg(id); + return throwError(exec, msg,KJS::ReferenceError); +} + + +KJS::Object QComboBoxImp::QComboBox_1( KJS::ExecState *exec, const KJS::List &args ) +{ +#if 0 + // Unsupported parameter QWidget * + return KJS::Value(); + + QWidget * arg0; // Dummy + + const char *arg1 = (args.size() >= 2) ? args[1].toString(exec).ascii() : 0; + + + // We should now create an object of type QComboBoxQComboBox *ret = new QComboBox( + + arg0, + arg1 ); +#endif +return KJS::Object(); +} + +KJS::Object QComboBoxImp::QComboBox_2( KJS::ExecState *exec, const KJS::List &args ) +{ +#if 0 + bool arg0 = extractBool(exec, args, 0); + + // Unsupported parameter QWidget * + return KJS::Value(); + + QWidget * arg1; // Dummy + + const char *arg2 = (args.size() >= 3) ? args[2].toString(exec).ascii() : 0; + + + // We should now create an object of type QComboBoxQComboBox *ret = new QComboBox( + + arg0, + arg1, + arg2 ); +#endif +return KJS::Object(); + +} + +KJS::Value QComboBoxImp::call( KJS::ExecState *exec, KJS::Object &self, const KJS::List &args ) +{ + instance = QComboBoxImp::toQComboBox( self ); + + switch( id ) { + + case Method_count_4: + return count_4( exec, self, args ); + break; + + case Method_insertStringList_5: + return insertStringList_5( exec, self, args ); + break; + + case Method_insertStrList_6: + return insertStrList_6( exec, self, args ); + break; + + case Method_insertStrList_7: + return insertStrList_7( exec, self, args ); + break; + + case Method_insertStrList_8: + return insertStrList_8( exec, self, args ); + break; + + case Method_insertItem_9: + return insertItem_9( exec, self, args ); + break; + + case Method_insertItem_10: + return insertItem_10( exec, self, args ); + break; + + case Method_insertItem_11: + return insertItem_11( exec, self, args ); + break; + + case Method_removeItem_12: + return removeItem_12( exec, self, args ); + break; + + case Method_currentItem_13: + return currentItem_13( exec, self, args ); + break; + + case Method_setCurrentItem_14: + return setCurrentItem_14( exec, self, args ); + break; + + case Method_currentText_15: + return currentText_15( exec, self, args ); + break; + + case Method_setCurrentText_16: + return setCurrentText_16( exec, self, args ); + break; + + case Method_text_17: + return text_17( exec, self, args ); + break; + + case Method_pixmap_18: + return pixmap_18( exec, self, args ); + break; + + case Method_changeItem_19: + return changeItem_19( exec, self, args ); + break; + + case Method_changeItem_20: + return changeItem_20( exec, self, args ); + break; + + case Method_changeItem_21: + return changeItem_21( exec, self, args ); + break; + + case Method_autoResize_22: + return autoResize_22( exec, self, args ); + break; + + case Method_setAutoResize_23: + return setAutoResize_23( exec, self, args ); + break; + + case Method_sizeHint_24: + return sizeHint_24( exec, self, args ); + break; + + case Method_setPalette_25: + return setPalette_25( exec, self, args ); + break; + + case Method_setFont_26: + return setFont_26( exec, self, args ); + break; + + case Method_setEnabled_27: + return setEnabled_27( exec, self, args ); + break; + + case Method_setSizeLimit_28: + return setSizeLimit_28( exec, self, args ); + break; + + case Method_sizeLimit_29: + return sizeLimit_29( exec, self, args ); + break; + + case Method_setMaxCount_30: + return setMaxCount_30( exec, self, args ); + break; + + case Method_maxCount_31: + return maxCount_31( exec, self, args ); + break; + + case Method_setInsertionPolicy_32: + return setInsertionPolicy_32( exec, self, args ); + break; + + case Method_insertionPolicy_33: + return insertionPolicy_33( exec, self, args ); + break; + + case Method_setValidator_34: + return setValidator_34( exec, self, args ); + break; + + case Method_validator_35: + return validator_35( exec, self, args ); + break; + + case Method_setListBox_36: + return setListBox_36( exec, self, args ); + break; + + case Method_listBox_37: + return listBox_37( exec, self, args ); + break; + + case Method_setLineEdit_38: + return setLineEdit_38( exec, self, args ); + break; + + case Method_lineEdit_39: + return lineEdit_39( exec, self, args ); + break; + + case Method_setAutoCompletion_40: + return setAutoCompletion_40( exec, self, args ); + break; + + case Method_autoCompletion_41: + return autoCompletion_41( exec, self, args ); + break; + + case Method_eventFilter_42: + return eventFilter_42( exec, self, args ); + break; + + case Method_setDuplicatesEnabled_43: + return setDuplicatesEnabled_43( exec, self, args ); + break; + + case Method_duplicatesEnabled_44: + return duplicatesEnabled_44( exec, self, args ); + break; + + case Method_editable_45: + return editable_45( exec, self, args ); + break; + + case Method_setEditable_46: + return setEditable_46( exec, self, args ); + break; + + case Method_popup_47: + return popup_47( exec, self, args ); + break; + + case Method_hide_48: + return hide_48( exec, self, args ); + break; + + default: + break; + } + + QString msg = i18n( "QComboBoxImp has no method with id '%1'." ).arg( id ); + return throwError(exec, msg,KJS::ReferenceError); +} + + +KJS::Value QComboBoxImp::count_4( KJS::ExecState *exec, KJS::Object &obj, const KJS::List &args ) +{ + + int ret; + ret = instance->count( ); + return KJS::Number( ret ); + +} + +KJS::Value QComboBoxImp::insertStringList_5( KJS::ExecState *exec, KJS::Object &obj, const KJS::List &args ) +{ + + QStringList arg0 = extractQStringList(exec, args, 0); + + int arg1 = extractInt(exec, args, 1); + + instance->insertStringList( + arg0, + arg1 ); + return KJS::Value(); // Returns void + +} + +KJS::Value QComboBoxImp::insertStrList_6( KJS::ExecState *exec, KJS::Object &obj, const KJS::List &args ) +{ + + QStrList arg0 = extractQStrList(exec, args, 0); + + int arg1 = extractInt(exec, args, 1); + + instance->insertStrList( + arg0, + arg1 ); + return KJS::Value(); // Returns void + +} + +KJS::Value QComboBoxImp::insertStrList_7( KJS::ExecState *exec, KJS::Object &obj, const KJS::List &args ) +{ + + // Unsupported parameter const QStrList * + return KJS::Value(); + + const QStrList * arg0; // Dummy + + int arg1 = extractInt(exec, args, 1); + + instance->insertStrList( + arg0, + arg1 ); + return KJS::Value(); // Returns void + +} + +KJS::Value QComboBoxImp::insertStrList_8( KJS::ExecState *exec, KJS::Object &obj, const KJS::List &args ) +{ + + // Unsupported parameter const char ** + return KJS::Value(); + + const char ** arg0; // Dummy + + int arg1 = extractInt(exec, args, 1); + + int arg2 = extractInt(exec, args, 2); + + instance->insertStrList( + arg0, + arg1, + arg2 ); + return KJS::Value(); // Returns void + +} + +KJS::Value QComboBoxImp::insertItem_9( KJS::ExecState *exec, KJS::Object &obj, const KJS::List &args ) +{ + + QString arg0 = extractQString(exec, args, 0); + + int arg1 = extractInt(exec, args, 1); + + instance->insertItem( + arg0, + arg1 ); + return KJS::Value(); // Returns void + +} + +KJS::Value QComboBoxImp::insertItem_10( KJS::ExecState *exec, KJS::Object &obj, const KJS::List &args ) +{ + + QPixmap arg0 = extractQPixmap(exec, args, 0); + + int arg1 = extractInt(exec, args, 1); + + instance->insertItem( + arg0, + arg1 ); + return KJS::Value(); // Returns void + +} + +KJS::Value QComboBoxImp::insertItem_11( KJS::ExecState *exec, KJS::Object &obj, const KJS::List &args ) +{ + + QPixmap arg0 = extractQPixmap(exec, args, 0); + + QString arg1 = extractQString(exec, args, 1); + + int arg2 = extractInt(exec, args, 2); + + instance->insertItem( + arg0, + arg1, + arg2 ); + return KJS::Value(); // Returns void + +} + +KJS::Value QComboBoxImp::removeItem_12( KJS::ExecState *exec, KJS::Object &obj, const KJS::List &args ) +{ + + int arg0 = extractInt(exec, args, 0); + + instance->removeItem( + arg0 ); + return KJS::Value(); // Returns void + +} + +KJS::Value QComboBoxImp::currentItem_13( KJS::ExecState *exec, KJS::Object &obj, const KJS::List &args ) +{ + + int ret; + ret = instance->currentItem( ); + return KJS::Number( ret ); + +} + +KJS::Value QComboBoxImp::setCurrentItem_14( KJS::ExecState *exec, KJS::Object &obj, const KJS::List &args ) +{ + + int arg0 = extractInt(exec, args, 0); + + instance->setCurrentItem( + arg0 ); + return KJS::Value(); // Returns void + +} + +KJS::Value QComboBoxImp::currentText_15( KJS::ExecState *exec, KJS::Object &obj, const KJS::List &args ) +{ + + QString ret; + ret = instance->currentText( ); + return KJS::String( ret ); + +} + +KJS::Value QComboBoxImp::setCurrentText_16( KJS::ExecState *exec, KJS::Object &obj, const KJS::List &args ) +{ + + QString arg0 = extractQString(exec, args, 0); + + instance->setCurrentText( + arg0 ); + return KJS::Value(); // Returns void + +} + +KJS::Value QComboBoxImp::text_17( KJS::ExecState *exec, KJS::Object &obj, const KJS::List &args ) +{ + + int arg0 = extractInt(exec, args, 0); + + QString ret; + ret = instance->text( + arg0 ); + return KJS::String( ret ); + +} + +KJS::Value QComboBoxImp::pixmap_18( KJS::ExecState *exec, KJS::Object &obj, const KJS::List &args ) +{ + + int arg0 = extractInt(exec, args, 0); + + instance->pixmap( + arg0 ); + return KJS::Value(); // Returns 'const QPixmap *' + +} + +KJS::Value QComboBoxImp::changeItem_19( KJS::ExecState *exec, KJS::Object &obj, const KJS::List &args ) +{ + + QString arg0 = extractQString(exec, args, 0); + + int arg1 = extractInt(exec, args, 1); + + instance->changeItem( + arg0, + arg1 ); + return KJS::Value(); // Returns void + +} + +KJS::Value QComboBoxImp::changeItem_20( KJS::ExecState *exec, KJS::Object &obj, const KJS::List &args ) +{ + + QPixmap arg0 = extractQPixmap(exec, args, 0); + + int arg1 = extractInt(exec, args, 1); + + instance->changeItem( + arg0, + arg1 ); + return KJS::Value(); // Returns void + +} + +KJS::Value QComboBoxImp::changeItem_21( KJS::ExecState *exec, KJS::Object &obj, const KJS::List &args ) +{ + + QPixmap arg0 = extractQPixmap(exec, args, 0); + + QString arg1 = extractQString(exec, args, 1); + + int arg2 = extractInt(exec, args, 2); + + instance->changeItem( + arg0, + arg1, + arg2 ); + return KJS::Value(); // Returns void + +} + +KJS::Value QComboBoxImp::autoResize_22( KJS::ExecState *exec, KJS::Object &obj, const KJS::List &args ) +{ + + bool ret; + ret = instance->autoResize( ); + return KJS::Boolean( ret ); + +} + +KJS::Value QComboBoxImp::setAutoResize_23( KJS::ExecState *exec, KJS::Object &obj, const KJS::List &args ) +{ + + bool arg0 = extractBool(exec, args, 0); + + instance->setAutoResize( + arg0 ); + return KJS::Value(); // Returns void + +} + +KJS::Value QComboBoxImp::sizeHint_24( KJS::ExecState *exec, KJS::Object &obj, const KJS::List &args ) +{ + QSize ret; + ret = instance->sizeHint( ); + + return convertToValue( exec, ret ); + +} + +KJS::Value QComboBoxImp::setPalette_25( KJS::ExecState *exec, KJS::Object &obj, const KJS::List &args ) +{ + + QPalette arg0 = extractQPalette(exec, args, 0); + + instance->setPalette( + arg0 ); + return KJS::Value(); // Returns void + +} + +KJS::Value QComboBoxImp::setFont_26( KJS::ExecState *exec, KJS::Object &obj, const KJS::List &args ) +{ + + QFont arg0 = extractQFont(exec, args, 0); + + instance->setFont( + arg0 ); + return KJS::Value(); // Returns void + +} + +KJS::Value QComboBoxImp::setEnabled_27( KJS::ExecState *exec, KJS::Object &obj, const KJS::List &args ) +{ + + bool arg0 = extractBool(exec, args, 0); + + instance->setEnabled( + arg0 ); + return KJS::Value(); // Returns void + +} + +KJS::Value QComboBoxImp::setSizeLimit_28( KJS::ExecState *exec, KJS::Object &obj, const KJS::List &args ) +{ + + int arg0 = extractInt(exec, args, 0); + + instance->setSizeLimit( + arg0 ); + return KJS::Value(); // Returns void + +} + +KJS::Value QComboBoxImp::sizeLimit_29( KJS::ExecState *exec, KJS::Object &obj, const KJS::List &args ) +{ + + int ret; + ret = instance->sizeLimit( ); + return KJS::Number( ret ); + +} + +KJS::Value QComboBoxImp::setMaxCount_30( KJS::ExecState *exec, KJS::Object &obj, const KJS::List &args ) +{ + + int arg0 = extractInt(exec, args, 0); + + instance->setMaxCount( + arg0 ); + return KJS::Value(); // Returns void + +} + +KJS::Value QComboBoxImp::maxCount_31( KJS::ExecState *exec, KJS::Object &obj, const KJS::List &args ) +{ + + int ret; + ret = instance->maxCount( ); + return KJS::Number( ret ); + +} + +KJS::Value QComboBoxImp::setInsertionPolicy_32( KJS::ExecState *exec, KJS::Object &obj, const KJS::List &args ) +{ + + QComboBox::Policy arg0 = QComboBox::AtBottom; // TODO (hack for combo box) + + instance->setInsertionPolicy( + arg0 ); + return KJS::Value(); // Returns void + +} + +KJS::Value QComboBoxImp::insertionPolicy_33( KJS::ExecState *exec, KJS::Object &obj, const KJS::List &args ) +{ + + instance->insertionPolicy( ); + return KJS::Value(); // Returns 'Policy' + +} + +KJS::Value QComboBoxImp::setValidator_34( KJS::ExecState *exec, KJS::Object &obj, const KJS::List &args ) +{ + + // Unsupported parameter const QValidator * + return KJS::Value(); + + const QValidator * arg0; // Dummy + + instance->setValidator( + arg0 ); + return KJS::Value(); // Returns void + +} + +KJS::Value QComboBoxImp::validator_35( KJS::ExecState *exec, KJS::Object &obj, const KJS::List &args ) +{ + + instance->validator( ); + return KJS::Value(); // Returns 'const QValidator *' + +} + +KJS::Value QComboBoxImp::setListBox_36( KJS::ExecState *exec, KJS::Object &obj, const KJS::List &args ) +{ + + // Unsupported parameter QListBox * + return KJS::Value(); + + QListBox * arg0; // Dummy + + instance->setListBox( + arg0 ); + return KJS::Value(); // Returns void + +} + +KJS::Value QComboBoxImp::listBox_37( KJS::ExecState *exec, KJS::Object &obj, const KJS::List &args ) +{ + + instance->listBox( ); + return KJS::Value(); // Returns 'QListBox *' + +} + +KJS::Value QComboBoxImp::setLineEdit_38( KJS::ExecState *exec, KJS::Object &obj, const KJS::List &args ) +{ + + // Unsupported parameter QLineEdit * + return KJS::Value(); + + QLineEdit * arg0; // Dummy + + instance->setLineEdit( + arg0 ); + return KJS::Value(); // Returns void + +} + +KJS::Value QComboBoxImp::lineEdit_39( KJS::ExecState *exec, KJS::Object &obj, const KJS::List &args ) +{ + + instance->lineEdit( ); + return KJS::Value(); // Returns 'QLineEdit *' + +} + +KJS::Value QComboBoxImp::setAutoCompletion_40( KJS::ExecState *exec, KJS::Object &obj, const KJS::List &args ) +{ + + bool arg0 = extractBool(exec, args, 0); + + instance->setAutoCompletion( + arg0 ); + return KJS::Value(); // Returns void + +} + +KJS::Value QComboBoxImp::autoCompletion_41( KJS::ExecState *exec, KJS::Object &obj, const KJS::List &args ) +{ + + bool ret; + ret = instance->autoCompletion( ); + return KJS::Boolean( ret ); + +} + +KJS::Value QComboBoxImp::eventFilter_42( KJS::ExecState *exec, KJS::Object &obj, const KJS::List &args ) +{ + + // Unsupported parameter QObject * + return KJS::Value(); + + QObject * arg0; // Dummy + + // Unsupported parameter QEvent * + return KJS::Value(); + + QEvent * arg1; // Dummy + + bool ret; + ret = instance->eventFilter( + arg0, + arg1 ); + return KJS::Boolean( ret ); + +} + +KJS::Value QComboBoxImp::setDuplicatesEnabled_43( KJS::ExecState *exec, KJS::Object &obj, const KJS::List &args ) +{ + + bool arg0 = extractBool(exec, args, 0); + + instance->setDuplicatesEnabled( + arg0 ); + return KJS::Value(); // Returns void + +} + +KJS::Value QComboBoxImp::duplicatesEnabled_44( KJS::ExecState *exec, KJS::Object &obj, const KJS::List &args ) +{ + + bool ret; + ret = instance->duplicatesEnabled( ); + return KJS::Boolean( ret ); + +} + +KJS::Value QComboBoxImp::editable_45( KJS::ExecState *exec, KJS::Object &obj, const KJS::List &args ) +{ + + bool ret; + ret = instance->editable( ); + return KJS::Boolean( ret ); + +} + +KJS::Value QComboBoxImp::setEditable_46( KJS::ExecState *exec, KJS::Object &obj, const KJS::List &args ) +{ + + bool arg0 = extractBool(exec, args, 0); + + instance->setEditable( + arg0 ); + return KJS::Value(); // Returns void + +} + +KJS::Value QComboBoxImp::popup_47( KJS::ExecState *exec, KJS::Object &obj, const KJS::List &args ) +{ + + instance->popup( ); + return KJS::Value(); // Returns void + +} + +KJS::Value QComboBoxImp::hide_48( KJS::ExecState *exec, KJS::Object &obj, const KJS::List &args ) +{ + + instance->hide( ); + return KJS::Value(); // Returns void + +} + + +} // namespace KJSEmbed + +// Local Variables: +// c-basic-offset: 4 +// End: + + diff --git a/kjsembed/qtbindings/qcombobox_imp.h b/kjsembed/qtbindings/qcombobox_imp.h new file mode 100644 index 00000000..56653345 --- /dev/null +++ b/kjsembed/qtbindings/qcombobox_imp.h @@ -0,0 +1,190 @@ + + + +#ifndef KJSEMBED_QComboBox_H +#define KJSEMBED_QComboBox_H + +#include <kjs/interpreter.h> +#include <kjs/object.h> + +#include <kjsembed/jsobjectproxy_imp.h> + +class QComboBox; + +/** + * Namespace containing the KJSEmbed library. + */ +namespace KJSEmbed { + +/** + * Wrapper class for QComboBox methods. + * + * @author Richard Moore, rich@kde.org + */ +class QComboBoxImp : public JSProxyImp +{ +public: + /** Enumerates the constructors supported by this class. */ + enum Constructors { + Constructor_QComboBox_1, + Constructor_QComboBox_2, + + LastConstuctor = -1 + }; + + /** Enumerates the methods supported by this class. */ + enum Methods { + + Method_count_4, + Method_insertStringList_5, + Method_insertStrList_6, + Method_insertStrList_7, + Method_insertStrList_8, + Method_insertItem_9, + Method_insertItem_10, + Method_insertItem_11, + Method_removeItem_12, + Method_currentItem_13, + Method_setCurrentItem_14, + Method_currentText_15, + Method_setCurrentText_16, + Method_text_17, + Method_pixmap_18, + Method_changeItem_19, + Method_changeItem_20, + Method_changeItem_21, + Method_autoResize_22, + Method_setAutoResize_23, + Method_sizeHint_24, + Method_setPalette_25, + Method_setFont_26, + Method_setEnabled_27, + Method_setSizeLimit_28, + Method_sizeLimit_29, + Method_setMaxCount_30, + Method_maxCount_31, + Method_setInsertionPolicy_32, + Method_insertionPolicy_33, + Method_setValidator_34, + Method_validator_35, + Method_setListBox_36, + Method_listBox_37, + Method_setLineEdit_38, + Method_lineEdit_39, + Method_setAutoCompletion_40, + Method_autoCompletion_41, + Method_eventFilter_42, + Method_setDuplicatesEnabled_43, + Method_duplicatesEnabled_44, + Method_editable_45, + Method_setEditable_46, + Method_popup_47, + Method_hide_48, + Method_Last = -1 + }; + + QComboBoxImp( KJS::ExecState *exec, int id, bool constructor=false ); + ~QComboBoxImp(); + + /** + * Adds the static bindings for this class to the specified Object. The + * static bindings are the static methods and the enums of this class. + */ + static void addStaticBindings( KJS::ExecState *exec, KJS::Object &object ); + + /** + * Adds the bindings for this class to the specified Object. The bindings + * added are the instance methods of this class. + */ + static void addBindings( KJS::ExecState *exec, KJS::Object &object ); + + static QComboBox *toQComboBox( KJS::Object &object ); + + // + // Constructors implemented by this class. + // + + KJS::Object QComboBox_1( KJS::ExecState *exec, const KJS::List &args ); + KJS::Object QComboBox_2( KJS::ExecState *exec, const KJS::List &args ); + + // + // Methods implemented by this class. + // + + KJS::Value count_4( KJS::ExecState *exec, KJS::Object &obj, const KJS::List &args ); + KJS::Value insertStringList_5( KJS::ExecState *exec, KJS::Object &obj, const KJS::List &args ); + KJS::Value insertStrList_6( KJS::ExecState *exec, KJS::Object &obj, const KJS::List &args ); + KJS::Value insertStrList_7( KJS::ExecState *exec, KJS::Object &obj, const KJS::List &args ); + KJS::Value insertStrList_8( KJS::ExecState *exec, KJS::Object &obj, const KJS::List &args ); + KJS::Value insertItem_9( KJS::ExecState *exec, KJS::Object &obj, const KJS::List &args ); + KJS::Value insertItem_10( KJS::ExecState *exec, KJS::Object &obj, const KJS::List &args ); + KJS::Value insertItem_11( KJS::ExecState *exec, KJS::Object &obj, const KJS::List &args ); + KJS::Value removeItem_12( KJS::ExecState *exec, KJS::Object &obj, const KJS::List &args ); + KJS::Value currentItem_13( KJS::ExecState *exec, KJS::Object &obj, const KJS::List &args ); + KJS::Value setCurrentItem_14( KJS::ExecState *exec, KJS::Object &obj, const KJS::List &args ); + KJS::Value currentText_15( KJS::ExecState *exec, KJS::Object &obj, const KJS::List &args ); + KJS::Value setCurrentText_16( KJS::ExecState *exec, KJS::Object &obj, const KJS::List &args ); + KJS::Value text_17( KJS::ExecState *exec, KJS::Object &obj, const KJS::List &args ); + KJS::Value pixmap_18( KJS::ExecState *exec, KJS::Object &obj, const KJS::List &args ); + KJS::Value changeItem_19( KJS::ExecState *exec, KJS::Object &obj, const KJS::List &args ); + KJS::Value changeItem_20( KJS::ExecState *exec, KJS::Object &obj, const KJS::List &args ); + KJS::Value changeItem_21( KJS::ExecState *exec, KJS::Object &obj, const KJS::List &args ); + KJS::Value autoResize_22( KJS::ExecState *exec, KJS::Object &obj, const KJS::List &args ); + KJS::Value setAutoResize_23( KJS::ExecState *exec, KJS::Object &obj, const KJS::List &args ); + KJS::Value sizeHint_24( KJS::ExecState *exec, KJS::Object &obj, const KJS::List &args ); + KJS::Value setPalette_25( KJS::ExecState *exec, KJS::Object &obj, const KJS::List &args ); + KJS::Value setFont_26( KJS::ExecState *exec, KJS::Object &obj, const KJS::List &args ); + KJS::Value setEnabled_27( KJS::ExecState *exec, KJS::Object &obj, const KJS::List &args ); + KJS::Value setSizeLimit_28( KJS::ExecState *exec, KJS::Object &obj, const KJS::List &args ); + KJS::Value sizeLimit_29( KJS::ExecState *exec, KJS::Object &obj, const KJS::List &args ); + KJS::Value setMaxCount_30( KJS::ExecState *exec, KJS::Object &obj, const KJS::List &args ); + KJS::Value maxCount_31( KJS::ExecState *exec, KJS::Object &obj, const KJS::List &args ); + KJS::Value setInsertionPolicy_32( KJS::ExecState *exec, KJS::Object &obj, const KJS::List &args ); + KJS::Value insertionPolicy_33( KJS::ExecState *exec, KJS::Object &obj, const KJS::List &args ); + KJS::Value setValidator_34( KJS::ExecState *exec, KJS::Object &obj, const KJS::List &args ); + KJS::Value validator_35( KJS::ExecState *exec, KJS::Object &obj, const KJS::List &args ); + KJS::Value setListBox_36( KJS::ExecState *exec, KJS::Object &obj, const KJS::List &args ); + KJS::Value listBox_37( KJS::ExecState *exec, KJS::Object &obj, const KJS::List &args ); + KJS::Value setLineEdit_38( KJS::ExecState *exec, KJS::Object &obj, const KJS::List &args ); + KJS::Value lineEdit_39( KJS::ExecState *exec, KJS::Object &obj, const KJS::List &args ); + KJS::Value setAutoCompletion_40( KJS::ExecState *exec, KJS::Object &obj, const KJS::List &args ); + KJS::Value autoCompletion_41( KJS::ExecState *exec, KJS::Object &obj, const KJS::List &args ); + KJS::Value eventFilter_42( KJS::ExecState *exec, KJS::Object &obj, const KJS::List &args ); + KJS::Value setDuplicatesEnabled_43( KJS::ExecState *exec, KJS::Object &obj, const KJS::List &args ); + KJS::Value duplicatesEnabled_44( KJS::ExecState *exec, KJS::Object &obj, const KJS::List &args ); + KJS::Value editable_45( KJS::ExecState *exec, KJS::Object &obj, const KJS::List &args ); + KJS::Value setEditable_46( KJS::ExecState *exec, KJS::Object &obj, const KJS::List &args ); + KJS::Value popup_47( KJS::ExecState *exec, KJS::Object &obj, const KJS::List &args ); + KJS::Value hide_48( KJS::ExecState *exec, KJS::Object &obj, const KJS::List &args ); + + // + // JS binding code. + // + + /** Returns true iff this object implements the construct function. */ + virtual bool implementsConstruct() const { return cons; } + + /** Invokes the construct function. */ + virtual KJS::Object construct( KJS::ExecState *exec, const KJS::List &args ); + + /** Returns true iff this object implements the call function. */ + virtual bool implementsCall() const { return !cons; } + + /** Invokes the call function. */ + virtual KJS::Value call( KJS::ExecState *exec, KJS::Object &self, const KJS::List &args ); + +private: + QComboBox *instance; // Temp + int id; + bool cons; +}; + +} // namespace KJSEmbed + +#endif // KJSEMBED_QComboBox_H + +// Local Variables: +// c-basic-offset: 4 +// End: + + diff --git a/kjsembed/qtbindings/qframe_imp.cpp b/kjsembed/qtbindings/qframe_imp.cpp new file mode 100644 index 00000000..92254a8b --- /dev/null +++ b/kjsembed/qtbindings/qframe_imp.cpp @@ -0,0 +1,64 @@ + +#include <kjs/object.h> + +#include <kjsembed/global.h> +#include <kjsembed/jsobjectproxy.h> +#include <kjsembed/jsbinding.h> + +#include <qframe.h> +#include "qframe_imp.h" + +/** + * Namespace containing the KJSEmbed library. + */ +namespace KJSEmbed { +void QFrameImp::addBindings( KJS::ExecState *exec, KJS::Object &object ) +{ + // + // Define the enum constants + // + struct EnumValue { + const char *id; + int val; + }; + + EnumValue enums[] = { + + // enum Shape + { "NoFrame", QFrame::NoFrame }, + { "Box", QFrame::Box }, + { "Panel", QFrame::Panel }, + { "WinPanel", QFrame::WinPanel }, + { "HLine", QFrame::HLine }, + { "VLine", QFrame::VLine }, + { "StyledPanel", QFrame::StyledPanel }, + { "PopupPanel", QFrame::PopupPanel }, + { "MenuBarPanel", QFrame::MenuBarPanel }, + { "ToolBarPanel", QFrame::ToolBarPanel }, + { "LineEditPanel", QFrame::LineEditPanel }, + { "TabWidgetPanel", QFrame::TabWidgetPanel }, + { "GroupBoxPanel", QFrame::GroupBoxPanel }, + { "MShape", QFrame::MShape }, + // enum Shadow + { "Plain", QFrame::Plain }, + { "Raised", QFrame::Raised }, + { "Sunken", QFrame::Sunken }, + { "MShadow", QFrame::MShadow }, + { 0, 0 } + }; + + int enumidx = 0; + do { + object.put( exec, enums[enumidx].id, KJS::Number(enums[enumidx].val), KJS::ReadOnly ); + ++enumidx; + } while( enums[enumidx].id ); + +} + +} // namespace KJSEmbed + +// Local Variables: +// c-basic-offset: 4 +// End: + + diff --git a/kjsembed/qtbindings/qframe_imp.h b/kjsembed/qtbindings/qframe_imp.h new file mode 100644 index 00000000..0f227605 --- /dev/null +++ b/kjsembed/qtbindings/qframe_imp.h @@ -0,0 +1,35 @@ + + + +#ifndef KJSEMBED_QFrame_H +#define KJSEMBED_QFrame_H + +#include <kjs/interpreter.h> +#include <kjs/object.h> + + +/** + * Namespace containing the KJSEmbed library. + */ +namespace KJSEmbed { + +/** + * Wrapper class for QFrame enums. + * + * @author Ian Reinhart Geiser, geiseri@kde.org + */ +class QFrameImp +{ +public: + static void addBindings( KJS::ExecState *exec, KJS::Object &object ); +}; + +} // namespace KJSEmbed + +#endif // KJSEMBED_QFrame_H + +// Local Variables: +// c-basic-offset: 4 +// End: + + diff --git a/kjsembed/qtbindings/qlistview_imp.cpp b/kjsembed/qtbindings/qlistview_imp.cpp new file mode 100644 index 00000000..a5f4c022 --- /dev/null +++ b/kjsembed/qtbindings/qlistview_imp.cpp @@ -0,0 +1,1329 @@ + + + +#include <qcstring.h> +#include <qpalette.h> +#include <qpixmap.h> +#include <qfont.h> +#include <qiconset.h> + +#include <kjs/object.h> + +#include <kjsembed/global.h> +#include <kjsembed/jsobjectproxy.h> +#include <kjsembed/jsopaqueproxy.h> +#include <kjsembed/jsbinding.h> + +#include <qlistview.h> +#include "qlistview_imp.h" + +/** + * Namespace containing the KJSEmbed library. + */ +namespace KJSEmbed { + +QListViewImp::QListViewImp( KJS::ExecState *exec, int mid, bool constructor ) + : JSProxyImp(exec), id(mid), cons(constructor) +{ +} + +QListViewImp::~QListViewImp() +{ +} + +void QListViewImp::addBindings( KJS::ExecState *exec, KJS::Object &object ) +{ + JSProxy::MethodTable methods[] = { + + { Method_treeStepSize_3, "treeStepSize" }, + { Method_setTreeStepSize_4, "setTreeStepSize" }, + { Method_insertItem_5, "insertItem" }, + { Method_takeItem_6, "takeItem" }, + { Method_removeItem_7, "removeItem" }, + { Method_header_8, "header" }, + { Method_addColumn_9, "addColumn" }, + { Method_addColumn_10, "addColumn" }, + { Method_removeColumn_11, "removeColumn" }, + { Method_setColumnText_12, "setColumnText" }, + { Method_setColumnText_13, "setColumnText" }, + { Method_columnText_14, "columnText" }, + { Method_setColumnWidth_15, "setColumnWidth" }, + { Method_columnWidth_16, "columnWidth" }, + { Method_setColumnWidthMode_17, "setColumnWidthMode" }, + { Method_columnWidthMode_18, "columnWidthMode" }, + { Method_columns_19, "columns" }, + { Method_setColumnAlignment_20, "setColumnAlignment" }, + { Method_columnAlignment_21, "columnAlignment" }, + { Method_show_22, "show" }, + { Method_itemAt_23, "itemAt" }, + { Method_itemRect_24, "itemRect" }, + { Method_itemPos_25, "itemPos" }, + { Method_ensureItemVisible_26, "ensureItemVisible" }, + { Method_repaintItem_27, "repaintItem" }, + { Method_setMultiSelection_28, "setMultiSelection" }, + { Method_isMultiSelection_29, "isMultiSelection" }, + { Method_setSelectionMode_30, "setSelectionMode" }, + { Method_selectionMode_31, "selectionMode" }, + { Method_clearSelection_32, "clearSelection" }, + { Method_setSelected_33, "setSelected" }, + { Method_setSelectionAnchor_34, "setSelectionAnchor" }, + { Method_isSelected_35, "isSelected" }, + { Method_selectedItem_36, "selectedItem" }, + { Method_setOpen_37, "setOpen" }, + { Method_isOpen_38, "isOpen" }, + { Method_setCurrentItem_39, "setCurrentItem" }, + { Method_currentItem_40, "currentItem" }, + { Method_firstChild_41, "firstChild" }, + { Method_lastItem_42, "lastItem" }, + { Method_childCount_43, "childCount" }, + { Method_setAllColumnsShowFocus_44, "setAllColumnsShowFocus" }, + { Method_allColumnsShowFocus_45, "allColumnsShowFocus" }, + { Method_setItemMargin_46, "setItemMargin" }, + { Method_itemMargin_47, "itemMargin" }, + { Method_setRootIsDecorated_48, "setRootIsDecorated" }, + { Method_rootIsDecorated_49, "rootIsDecorated" }, + { Method_setSorting_50, "setSorting" }, + { Method_sortColumn_51, "sortColumn" }, + { Method_setSortColumn_52, "setSortColumn" }, + { Method_sortOrder_53, "sortOrder" }, + { Method_setSortOrder_54, "setSortOrder" }, + { Method_sort_55, "sort" }, + { Method_setFont_56, "setFont" }, + { Method_setPalette_57, "setPalette" }, + { Method_eventFilter_58, "eventFilter" }, + { Method_sizeHint_59, "sizeHint" }, + { Method_minimumSizeHint_60, "minimumSizeHint" }, + { Method_setShowSortIndicator_61, "setShowSortIndicator" }, + { Method_showSortIndicator_62, "showSortIndicator" }, + { Method_setShowToolTips_63, "setShowToolTips" }, + { Method_showToolTips_64, "showToolTips" }, + { Method_setResizeMode_65, "setResizeMode" }, + { Method_resizeMode_66, "resizeMode" }, + { Method_findItem_67, "findItem" }, + { Method_setDefaultRenameAction_68, "setDefaultRenameAction" }, + { Method_defaultRenameAction_69, "defaultRenameAction" }, + { Method_isRenaming_70, "isRenaming" }, + { Method_hideColumn_71, "hideColumn" }, + { 0, 0 } + }; + + int idx = 0; + QCString lastName; + + while( methods[idx].id ) { + if ( lastName != methods[idx].name ) { + QListViewImp *meth = new QListViewImp( exec, methods[idx].id ); + object.put( exec , methods[idx].name, KJS::Object(meth) ); + lastName = methods[idx].name; + } + ++idx; + } + + + // + // Define the enum constants + // + struct EnumValue { + const char *id; + int val; + }; + + EnumValue enums[] = { + + // enum WidthMode + { "Manual", QListView::Manual }, + { "Maximum", QListView::Maximum }, + // enum SelectionMode + { "Single", QListView::Single }, + { "Multi", QListView::Multi }, + { "Extended", QListView::Extended }, + { "NoSelection", QListView::NoSelection }, + // enum ResizeMode + { "NoColumn", QListView::NoColumn }, + { "AllColumns", QListView::AllColumns }, + { "LastColumn", QListView::LastColumn }, + // enum RenameAction + { "Accept", QListView::Accept }, + { "Reject", QListView::Reject }, + { 0, 0 } + }; + + int enumidx = 0; + do { + object.put( exec, enums[enumidx].id, KJS::Number(enums[enumidx].val), KJS::ReadOnly ); + ++enumidx; + } while( enums[enumidx].id ); + +} + +QListView *QListViewImp::toQListView( KJS::Object &self ) +{ + JSObjectProxy *ob = JSProxy::toObjectProxy( self.imp() ); + if ( ob ) { + QObject *obj = ob->object(); + if ( obj ) + return dynamic_cast<QListView *>( obj ); + } + + JSOpaqueProxy *op = JSProxy::toOpaqueProxy( self.imp() ); + if ( !op ) + return 0; + + if ( op->typeName() != "QListView" ) + return 0; + + return op->toNative<QListView>(); +} + + +KJS::Object QListViewImp::construct( KJS::ExecState *exec, const KJS::List &args ) +{ + switch( id ) { + + case Constructor_QListView_1: + return QListView_1( exec, args ); + break; + + default: + break; + } + + QString msg = i18n("QListViewCons has no constructor with id '%1'.").arg(id); + return throwError(exec, msg,KJS::ReferenceError); +} + + +KJS::Object QListViewImp::QListView_1( KJS::ExecState *exec, const KJS::List &args ) +{ + + // TODO + QWidget *arg0 = 0L; + + // TODO + QWidget *arg1 = 0L; + + // TODO + QWidget *arg2 = 0L; + +} + +KJS::Value QListViewImp::call( KJS::ExecState *exec, KJS::Object &self, const KJS::List &args ) +{ + instance = QListViewImp::toQListView( self ); + + switch( id ) { + + case Method_treeStepSize_3: + return treeStepSize_3( exec, self, args ); + break; + + case Method_setTreeStepSize_4: + return setTreeStepSize_4( exec, self, args ); + break; + + case Method_insertItem_5: + return insertItem_5( exec, self, args ); + break; + + case Method_takeItem_6: + return takeItem_6( exec, self, args ); + break; + + case Method_removeItem_7: + return removeItem_7( exec, self, args ); + break; + + case Method_header_8: + return header_8( exec, self, args ); + break; + + case Method_addColumn_9: + return addColumn_9( exec, self, args ); + break; + + case Method_addColumn_10: + return addColumn_10( exec, self, args ); + break; + + case Method_removeColumn_11: + return removeColumn_11( exec, self, args ); + break; + + case Method_setColumnText_12: + return setColumnText_12( exec, self, args ); + break; + + case Method_setColumnText_13: + return setColumnText_13( exec, self, args ); + break; + + case Method_columnText_14: + return columnText_14( exec, self, args ); + break; + + case Method_setColumnWidth_15: + return setColumnWidth_15( exec, self, args ); + break; + + case Method_columnWidth_16: + return columnWidth_16( exec, self, args ); + break; + + case Method_setColumnWidthMode_17: + return setColumnWidthMode_17( exec, self, args ); + break; + + case Method_columnWidthMode_18: + return columnWidthMode_18( exec, self, args ); + break; + + case Method_columns_19: + return columns_19( exec, self, args ); + break; + + case Method_setColumnAlignment_20: + return setColumnAlignment_20( exec, self, args ); + break; + + case Method_columnAlignment_21: + return columnAlignment_21( exec, self, args ); + break; + + case Method_show_22: + return show_22( exec, self, args ); + break; + + case Method_itemAt_23: + return itemAt_23( exec, self, args ); + break; + + case Method_itemRect_24: + return itemRect_24( exec, self, args ); + break; + + case Method_itemPos_25: + return itemPos_25( exec, self, args ); + break; + + case Method_ensureItemVisible_26: + return ensureItemVisible_26( exec, self, args ); + break; + + case Method_repaintItem_27: + return repaintItem_27( exec, self, args ); + break; + + case Method_setMultiSelection_28: + return setMultiSelection_28( exec, self, args ); + break; + + case Method_isMultiSelection_29: + return isMultiSelection_29( exec, self, args ); + break; + + case Method_setSelectionMode_30: + return setSelectionMode_30( exec, self, args ); + break; + + case Method_selectionMode_31: + return selectionMode_31( exec, self, args ); + break; + + case Method_clearSelection_32: + return clearSelection_32( exec, self, args ); + break; + + case Method_setSelected_33: + return setSelected_33( exec, self, args ); + break; + + case Method_setSelectionAnchor_34: + return setSelectionAnchor_34( exec, self, args ); + break; + + case Method_isSelected_35: + return isSelected_35( exec, self, args ); + break; + + case Method_selectedItem_36: + return selectedItem_36( exec, self, args ); + break; + + case Method_setOpen_37: + return setOpen_37( exec, self, args ); + break; + + case Method_isOpen_38: + return isOpen_38( exec, self, args ); + break; + + case Method_setCurrentItem_39: + return setCurrentItem_39( exec, self, args ); + break; + + case Method_currentItem_40: + return currentItem_40( exec, self, args ); + break; + + case Method_firstChild_41: + return firstChild_41( exec, self, args ); + break; + + case Method_lastItem_42: + return lastItem_42( exec, self, args ); + break; + + case Method_childCount_43: + return childCount_43( exec, self, args ); + break; + + case Method_setAllColumnsShowFocus_44: + return setAllColumnsShowFocus_44( exec, self, args ); + break; + + case Method_allColumnsShowFocus_45: + return allColumnsShowFocus_45( exec, self, args ); + break; + + case Method_setItemMargin_46: + return setItemMargin_46( exec, self, args ); + break; + + case Method_itemMargin_47: + return itemMargin_47( exec, self, args ); + break; + + case Method_setRootIsDecorated_48: + return setRootIsDecorated_48( exec, self, args ); + break; + + case Method_rootIsDecorated_49: + return rootIsDecorated_49( exec, self, args ); + break; + + case Method_setSorting_50: + return setSorting_50( exec, self, args ); + break; + + case Method_sortColumn_51: + return sortColumn_51( exec, self, args ); + break; + + case Method_setSortColumn_52: + return setSortColumn_52( exec, self, args ); + break; + + case Method_sortOrder_53: + return sortOrder_53( exec, self, args ); + break; + + case Method_setSortOrder_54: + return setSortOrder_54( exec, self, args ); + break; + + case Method_sort_55: + return sort_55( exec, self, args ); + break; + + case Method_setFont_56: + return setFont_56( exec, self, args ); + break; + + case Method_setPalette_57: + return setPalette_57( exec, self, args ); + break; + + case Method_eventFilter_58: + return eventFilter_58( exec, self, args ); + break; + + case Method_sizeHint_59: + return sizeHint_59( exec, self, args ); + break; + + case Method_minimumSizeHint_60: + return minimumSizeHint_60( exec, self, args ); + break; + + case Method_setShowSortIndicator_61: + return setShowSortIndicator_61( exec, self, args ); + break; + + case Method_showSortIndicator_62: + return showSortIndicator_62( exec, self, args ); + break; + + case Method_setShowToolTips_63: + return setShowToolTips_63( exec, self, args ); + break; + + case Method_showToolTips_64: + return showToolTips_64( exec, self, args ); + break; + + case Method_setResizeMode_65: + return setResizeMode_65( exec, self, args ); + break; + + case Method_resizeMode_66: + return resizeMode_66( exec, self, args ); + break; + + case Method_findItem_67: + return findItem_67( exec, self, args ); + break; + + case Method_setDefaultRenameAction_68: + return setDefaultRenameAction_68( exec, self, args ); + break; + + case Method_defaultRenameAction_69: + return defaultRenameAction_69( exec, self, args ); + break; + + case Method_isRenaming_70: + return isRenaming_70( exec, self, args ); + break; + + case Method_hideColumn_71: + return hideColumn_71( exec, self, args ); + break; + + default: + break; + } + + QString msg = i18n( "QListViewImp has no method with id '%1'." ).arg( id ); + return throwError(exec, msg,KJS::ReferenceError); +} + + +KJS::Value QListViewImp::treeStepSize_3( KJS::ExecState *exec, KJS::Object &obj, const KJS::List &args ) +{ + + int ret; + ret = instance->treeStepSize( ); + return KJS::Number( ret ); + +} + +KJS::Value QListViewImp::setTreeStepSize_4( KJS::ExecState *exec, KJS::Object &obj, const KJS::List &args ) +{ + + int arg0 = (args.size() >= 1) ? args[0].toInteger(exec) : -1; + + instance->setTreeStepSize( + arg0 ); + return KJS::Value(); // Returns void + +} + +KJS::Value QListViewImp::insertItem_5( KJS::ExecState *exec, KJS::Object &obj, const KJS::List &args ) +{ + + // Unsupported parameter QListViewItem * + return KJS::Value(); + + QListViewItem * arg0; // Dummy + + instance->insertItem( + arg0 ); + return KJS::Value(); // Returns void + +} + +KJS::Value QListViewImp::takeItem_6( KJS::ExecState *exec, KJS::Object &obj, const KJS::List &args ) +{ + + // Unsupported parameter QListViewItem * + return KJS::Value(); + + QListViewItem * arg0; // Dummy + + instance->takeItem( + arg0 ); + return KJS::Value(); // Returns void + +} + +KJS::Value QListViewImp::removeItem_7( KJS::ExecState *exec, KJS::Object &obj, const KJS::List &args ) +{ + + // Unsupported parameter QListViewItem * + return KJS::Value(); + + QListViewItem * arg0; // Dummy + + instance->removeItem( + arg0 ); + return KJS::Value(); // Returns void + +} + +KJS::Value QListViewImp::header_8( KJS::ExecState *exec, KJS::Object &obj, const KJS::List &args ) +{ + + instance->header( ); + return KJS::Value(); // Returns 'QHeader *' + +} + +KJS::Value QListViewImp::addColumn_9( KJS::ExecState *exec, KJS::Object &obj, const KJS::List &args ) +{ + + QString arg0 = (args.size() >= 1) ? args[0].toString(exec).qstring() : QString::null; + + int arg1 = (args.size() >= 2) ? args[1].toInteger(exec) : -1; + + int ret; + ret = instance->addColumn( + arg0, + arg1 ); + return KJS::Number( ret ); + +} + +KJS::Value QListViewImp::addColumn_10( KJS::ExecState *exec, KJS::Object &obj, const KJS::List &args ) +{ + + // Unsupported parameter const QIconSet + return KJS::Value(); + + const QIconSet arg0; // Dummy + + QString arg1 = (args.size() >= 2) ? args[1].toString(exec).qstring() : QString::null; + + int arg2 = (args.size() >= 3) ? args[2].toInteger(exec) : -1; + + int ret; + ret = instance->addColumn( + arg0, + arg1, + arg2 ); + return KJS::Number( ret ); + +} + +KJS::Value QListViewImp::removeColumn_11( KJS::ExecState *exec, KJS::Object &obj, const KJS::List &args ) +{ + + int arg0 = (args.size() >= 1) ? args[0].toInteger(exec) : -1; + + instance->removeColumn( + arg0 ); + return KJS::Value(); // Returns void + +} + +KJS::Value QListViewImp::setColumnText_12( KJS::ExecState *exec, KJS::Object &obj, const KJS::List &args ) +{ + + int arg0 = (args.size() >= 1) ? args[0].toInteger(exec) : -1; + + QString arg1 = (args.size() >= 2) ? args[1].toString(exec).qstring() : QString::null; + + instance->setColumnText( + arg0, + arg1 ); + return KJS::Value(); // Returns void + +} + +KJS::Value QListViewImp::setColumnText_13( KJS::ExecState *exec, KJS::Object &obj, const KJS::List &args ) +{ + + int arg0 = (args.size() >= 1) ? args[0].toInteger(exec) : -1; + + // Unsupported parameter const QIconSet + return KJS::Value(); + + const QIconSet arg1; // Dummy + + QString arg2 = (args.size() >= 3) ? args[2].toString(exec).qstring() : QString::null; + + instance->setColumnText( + arg0, + arg1, + arg2 ); + return KJS::Value(); // Returns void + +} + +KJS::Value QListViewImp::columnText_14( KJS::ExecState *exec, KJS::Object &obj, const KJS::List &args ) +{ + + int arg0 = (args.size() >= 1) ? args[0].toInteger(exec) : -1; + + QString ret; + ret = instance->columnText( + arg0 ); + return KJS::String( ret ); + +} + +KJS::Value QListViewImp::setColumnWidth_15( KJS::ExecState *exec, KJS::Object &obj, const KJS::List &args ) +{ + + int arg0 = (args.size() >= 1) ? args[0].toInteger(exec) : -1; + + int arg1 = (args.size() >= 2) ? args[1].toInteger(exec) : -1; + + instance->setColumnWidth( + arg0, + arg1 ); + return KJS::Value(); // Returns void + +} + +KJS::Value QListViewImp::columnWidth_16( KJS::ExecState *exec, KJS::Object &obj, const KJS::List &args ) +{ + + int arg0 = (args.size() >= 1) ? args[0].toInteger(exec) : -1; + + int ret; + ret = instance->columnWidth( + arg0 ); + return KJS::Number( ret ); + +} + +KJS::Value QListViewImp::setColumnWidthMode_17( KJS::ExecState *exec, KJS::Object &obj, const KJS::List &args ) +{ + + int arg0 = (args.size() >= 1) ? args[0].toInteger(exec) : -1; + + // Unsupported parameter WidthMode + return KJS::Value(); + + WidthMode arg1; // Dummy + + instance->setColumnWidthMode( + arg0, + arg1 ); + return KJS::Value(); // Returns void + +} + +KJS::Value QListViewImp::columnWidthMode_18( KJS::ExecState *exec, KJS::Object &obj, const KJS::List &args ) +{ + + int arg0 = (args.size() >= 1) ? args[0].toInteger(exec) : -1; + + instance->columnWidthMode( + arg0 ); + return KJS::Value(); // Returns 'WidthMode' + +} + +KJS::Value QListViewImp::columns_19( KJS::ExecState *exec, KJS::Object &obj, const KJS::List &args ) +{ + + int ret; + ret = instance->columns( ); + return KJS::Number( ret ); + +} + +KJS::Value QListViewImp::setColumnAlignment_20( KJS::ExecState *exec, KJS::Object &obj, const KJS::List &args ) +{ + + int arg0 = (args.size() >= 1) ? args[0].toInteger(exec) : -1; + + int arg1 = (args.size() >= 2) ? args[1].toInteger(exec) : -1; + + instance->setColumnAlignment( + arg0, + arg1 ); + return KJS::Value(); // Returns void + +} + +KJS::Value QListViewImp::columnAlignment_21( KJS::ExecState *exec, KJS::Object &obj, const KJS::List &args ) +{ + + int arg0 = (args.size() >= 1) ? args[0].toInteger(exec) : -1; + + int ret; + ret = instance->columnAlignment( + arg0 ); + return KJS::Number( ret ); + +} + +KJS::Value QListViewImp::show_22( KJS::ExecState *exec, KJS::Object &obj, const KJS::List &args ) +{ + + instance->show( ); + return KJS::Value(); // Returns void + +} + +KJS::Value QListViewImp::itemAt_23( KJS::ExecState *exec, KJS::Object &obj, const KJS::List &args ) +{ + + // Unsupported parameter const QPoint & + return KJS::Value(); + + const QPoint & arg0; // Dummy + + instance->itemAt( + arg0 ); + return KJS::Value(); // Returns 'QListViewItem *' + +} + +KJS::Value QListViewImp::itemRect_24( KJS::ExecState *exec, KJS::Object &obj, const KJS::List &args ) +{ + + // Unsupported parameter const QListViewItem * + return KJS::Value(); + + const QListViewItem * arg0; // Dummy + + instance->itemRect( + arg0 ); + return KJS::Value(); // Returns 'QRect' + +} + +KJS::Value QListViewImp::itemPos_25( KJS::ExecState *exec, KJS::Object &obj, const KJS::List &args ) +{ + + // Unsupported parameter const QListViewItem * + return KJS::Value(); + + const QListViewItem * arg0; // Dummy + + int ret; + ret = instance->itemPos( + arg0 ); + return KJS::Number( ret ); + +} + +KJS::Value QListViewImp::ensureItemVisible_26( KJS::ExecState *exec, KJS::Object &obj, const KJS::List &args ) +{ + + // Unsupported parameter const QListViewItem * + return KJS::Value(); + + const QListViewItem * arg0; // Dummy + + instance->ensureItemVisible( + arg0 ); + return KJS::Value(); // Returns void + +} + +KJS::Value QListViewImp::repaintItem_27( KJS::ExecState *exec, KJS::Object &obj, const KJS::List &args ) +{ + + // Unsupported parameter const QListViewItem * + return KJS::Value(); + + const QListViewItem * arg0; // Dummy + + instance->repaintItem( + arg0 ); + return KJS::Value(); // Returns void + +} + +KJS::Value QListViewImp::setMultiSelection_28( KJS::ExecState *exec, KJS::Object &obj, const KJS::List &args ) +{ + + bool arg0 = (args.size() >= 1) ? args[0].toBoolean(exec) : false; + + instance->setMultiSelection( + arg0 ); + return KJS::Value(); // Returns void + +} + +KJS::Value QListViewImp::isMultiSelection_29( KJS::ExecState *exec, KJS::Object &obj, const KJS::List &args ) +{ + + bool ret; + ret = instance->isMultiSelection( ); + return KJS::Boolean( ret ); + +} + +KJS::Value QListViewImp::setSelectionMode_30( KJS::ExecState *exec, KJS::Object &obj, const KJS::List &args ) +{ + + // Unsupported parameter SelectionMode + return KJS::Value(); + + SelectionMode arg0; // Dummy + + instance->setSelectionMode( + arg0 ); + return KJS::Value(); // Returns void + +} + +KJS::Value QListViewImp::selectionMode_31( KJS::ExecState *exec, KJS::Object &obj, const KJS::List &args ) +{ + + instance->selectionMode( ); + return KJS::Value(); // Returns 'SelectionMode' + +} + +KJS::Value QListViewImp::clearSelection_32( KJS::ExecState *exec, KJS::Object &obj, const KJS::List &args ) +{ + + instance->clearSelection( ); + return KJS::Value(); // Returns void + +} + +KJS::Value QListViewImp::setSelected_33( KJS::ExecState *exec, KJS::Object &obj, const KJS::List &args ) +{ + + // Unsupported parameter QListViewItem * + return KJS::Value(); + + QListViewItem * arg0; // Dummy + + bool arg1 = (args.size() >= 2) ? args[1].toBoolean(exec) : false; + + instance->setSelected( + arg0, + arg1 ); + return KJS::Value(); // Returns void + +} + +KJS::Value QListViewImp::setSelectionAnchor_34( KJS::ExecState *exec, KJS::Object &obj, const KJS::List &args ) +{ + + // Unsupported parameter QListViewItem * + return KJS::Value(); + + QListViewItem * arg0; // Dummy + + instance->setSelectionAnchor( + arg0 ); + return KJS::Value(); // Returns void + +} + +KJS::Value QListViewImp::isSelected_35( KJS::ExecState *exec, KJS::Object &obj, const KJS::List &args ) +{ + + // Unsupported parameter const QListViewItem * + return KJS::Value(); + + const QListViewItem * arg0; // Dummy + + bool ret; + ret = instance->isSelected( + arg0 ); + return KJS::Boolean( ret ); + +} + +KJS::Value QListViewImp::selectedItem_36( KJS::ExecState *exec, KJS::Object &obj, const KJS::List &args ) +{ + + instance->selectedItem( ); + return KJS::Value(); // Returns 'QListViewItem *' + +} + +KJS::Value QListViewImp::setOpen_37( KJS::ExecState *exec, KJS::Object &obj, const KJS::List &args ) +{ + + // Unsupported parameter QListViewItem * + return KJS::Value(); + + QListViewItem * arg0; // Dummy + + bool arg1 = (args.size() >= 2) ? args[1].toBoolean(exec) : false; + + instance->setOpen( + arg0, + arg1 ); + return KJS::Value(); // Returns void + +} + +KJS::Value QListViewImp::isOpen_38( KJS::ExecState *exec, KJS::Object &obj, const KJS::List &args ) +{ + + // Unsupported parameter const QListViewItem * + return KJS::Value(); + + const QListViewItem * arg0; // Dummy + + bool ret; + ret = instance->isOpen( + arg0 ); + return KJS::Boolean( ret ); + +} + +KJS::Value QListViewImp::setCurrentItem_39( KJS::ExecState *exec, KJS::Object &obj, const KJS::List &args ) +{ + + // Unsupported parameter QListViewItem * + return KJS::Value(); + + QListViewItem * arg0; // Dummy + + instance->setCurrentItem( + arg0 ); + return KJS::Value(); // Returns void + +} + +KJS::Value QListViewImp::currentItem_40( KJS::ExecState *exec, KJS::Object &obj, const KJS::List &args ) +{ + + instance->currentItem( ); + return KJS::Value(); // Returns 'QListViewItem *' + +} + +KJS::Value QListViewImp::firstChild_41( KJS::ExecState *exec, KJS::Object &obj, const KJS::List &args ) +{ + + instance->firstChild( ); + return KJS::Value(); // Returns 'QListViewItem *' + +} + +KJS::Value QListViewImp::lastItem_42( KJS::ExecState *exec, KJS::Object &obj, const KJS::List &args ) +{ + + instance->lastItem( ); + return KJS::Value(); // Returns 'QListViewItem *' + +} + +KJS::Value QListViewImp::childCount_43( KJS::ExecState *exec, KJS::Object &obj, const KJS::List &args ) +{ + + int ret; + ret = instance->childCount( ); + return KJS::Number( ret ); + +} + +KJS::Value QListViewImp::setAllColumnsShowFocus_44( KJS::ExecState *exec, KJS::Object &obj, const KJS::List &args ) +{ + + bool arg0 = (args.size() >= 1) ? args[0].toBoolean(exec) : false; + + instance->setAllColumnsShowFocus( + arg0 ); + return KJS::Value(); // Returns void + +} + +KJS::Value QListViewImp::allColumnsShowFocus_45( KJS::ExecState *exec, KJS::Object &obj, const KJS::List &args ) +{ + + bool ret; + ret = instance->allColumnsShowFocus( ); + return KJS::Boolean( ret ); + +} + +KJS::Value QListViewImp::setItemMargin_46( KJS::ExecState *exec, KJS::Object &obj, const KJS::List &args ) +{ + + int arg0 = (args.size() >= 1) ? args[0].toInteger(exec) : -1; + + instance->setItemMargin( + arg0 ); + return KJS::Value(); // Returns void + +} + +KJS::Value QListViewImp::itemMargin_47( KJS::ExecState *exec, KJS::Object &obj, const KJS::List &args ) +{ + + int ret; + ret = instance->itemMargin( ); + return KJS::Number( ret ); + +} + +KJS::Value QListViewImp::setRootIsDecorated_48( KJS::ExecState *exec, KJS::Object &obj, const KJS::List &args ) +{ + + bool arg0 = (args.size() >= 1) ? args[0].toBoolean(exec) : false; + + instance->setRootIsDecorated( + arg0 ); + return KJS::Value(); // Returns void + +} + +KJS::Value QListViewImp::rootIsDecorated_49( KJS::ExecState *exec, KJS::Object &obj, const KJS::List &args ) +{ + + bool ret; + ret = instance->rootIsDecorated( ); + return KJS::Boolean( ret ); + +} + +KJS::Value QListViewImp::setSorting_50( KJS::ExecState *exec, KJS::Object &obj, const KJS::List &args ) +{ + + int arg0 = (args.size() >= 1) ? args[0].toInteger(exec) : -1; + + bool arg1 = (args.size() >= 2) ? args[1].toBoolean(exec) : false; + + instance->setSorting( + arg0, + arg1 ); + return KJS::Value(); // Returns void + +} + +KJS::Value QListViewImp::sortColumn_51( KJS::ExecState *exec, KJS::Object &obj, const KJS::List &args ) +{ + + int ret; + ret = instance->sortColumn( ); + return KJS::Number( ret ); + +} + +KJS::Value QListViewImp::setSortColumn_52( KJS::ExecState *exec, KJS::Object &obj, const KJS::List &args ) +{ + + int arg0 = (args.size() >= 1) ? args[0].toInteger(exec) : -1; + + instance->setSortColumn( + arg0 ); + return KJS::Value(); // Returns void + +} + +KJS::Value QListViewImp::sortOrder_53( KJS::ExecState *exec, KJS::Object &obj, const KJS::List &args ) +{ + + instance->sortOrder( ); + return KJS::Value(); // Returns 'SortOrder' + +} + +KJS::Value QListViewImp::setSortOrder_54( KJS::ExecState *exec, KJS::Object &obj, const KJS::List &args ) +{ + + // Unsupported parameter SortOrder + return KJS::Value(); + + SortOrder arg0; // Dummy + + instance->setSortOrder( + arg0 ); + return KJS::Value(); // Returns void + +} + +KJS::Value QListViewImp::sort_55( KJS::ExecState *exec, KJS::Object &obj, const KJS::List &args ) +{ + + instance->sort( ); + return KJS::Value(); // Returns void + +} + +KJS::Value QListViewImp::setFont_56( KJS::ExecState *exec, KJS::Object &obj, const KJS::List &args ) +{ + + QFont arg0; // TODO + + instance->setFont( + arg0 ); + return KJS::Value(); // Returns void + +} + +KJS::Value QListViewImp::setPalette_57( KJS::ExecState *exec, KJS::Object &obj, const KJS::List &args ) +{ + + QPalette arg0; // TODO + + instance->setPalette( + arg0 ); + return KJS::Value(); // Returns void + +} + +KJS::Value QListViewImp::eventFilter_58( KJS::ExecState *exec, KJS::Object &obj, const KJS::List &args ) +{ + + // Unsupported parameter QObject * + return KJS::Value(); + + QObject * arg0; // Dummy + + // Unsupported parameter QEvent * + return KJS::Value(); + + QEvent * arg1; // Dummy + + bool ret; + ret = instance->eventFilter( + arg0, + arg1 ); + return KJS::Boolean( ret ); + +} + +KJS::Value QListViewImp::sizeHint_59( KJS::ExecState *exec, KJS::Object &obj, const KJS::List &args ) +{ + + instance->sizeHint( ); + return KJS::Value(); // Returns 'QSize' + +} + +KJS::Value QListViewImp::minimumSizeHint_60( KJS::ExecState *exec, KJS::Object &obj, const KJS::List &args ) +{ + + instance->minimumSizeHint( ); + return KJS::Value(); // Returns 'QSize' + +} + +KJS::Value QListViewImp::setShowSortIndicator_61( KJS::ExecState *exec, KJS::Object &obj, const KJS::List &args ) +{ + + bool arg0 = (args.size() >= 1) ? args[0].toBoolean(exec) : false; + + instance->setShowSortIndicator( + arg0 ); + return KJS::Value(); // Returns void + +} + +KJS::Value QListViewImp::showSortIndicator_62( KJS::ExecState *exec, KJS::Object &obj, const KJS::List &args ) +{ + + bool ret; + ret = instance->showSortIndicator( ); + return KJS::Boolean( ret ); + +} + +KJS::Value QListViewImp::setShowToolTips_63( KJS::ExecState *exec, KJS::Object &obj, const KJS::List &args ) +{ + + bool arg0 = (args.size() >= 1) ? args[0].toBoolean(exec) : false; + + instance->setShowToolTips( + arg0 ); + return KJS::Value(); // Returns void + +} + +KJS::Value QListViewImp::showToolTips_64( KJS::ExecState *exec, KJS::Object &obj, const KJS::List &args ) +{ + + bool ret; + ret = instance->showToolTips( ); + return KJS::Boolean( ret ); + +} + +KJS::Value QListViewImp::setResizeMode_65( KJS::ExecState *exec, KJS::Object &obj, const KJS::List &args ) +{ + + // Unsupported parameter ResizeMode + return KJS::Value(); + + ResizeMode arg0; // Dummy + + instance->setResizeMode( + arg0 ); + return KJS::Value(); // Returns void + +} + +KJS::Value QListViewImp::resizeMode_66( KJS::ExecState *exec, KJS::Object &obj, const KJS::List &args ) +{ + + instance->resizeMode( ); + return KJS::Value(); // Returns 'ResizeMode' + +} + +KJS::Value QListViewImp::findItem_67( KJS::ExecState *exec, KJS::Object &obj, const KJS::List &args ) +{ + + QString arg0 = (args.size() >= 1) ? args[0].toString(exec).qstring() : QString::null; + + int arg1 = (args.size() >= 2) ? args[1].toInteger(exec) : -1; + + // Unsupported parameter ComparisonFlags + return KJS::Value(); + + ComparisonFlags arg2; // Dummy + + instance->findItem( + arg0, + arg1, + arg2 ); + return KJS::Value(); // Returns 'QListViewItem *' + +} + +KJS::Value QListViewImp::setDefaultRenameAction_68( KJS::ExecState *exec, KJS::Object &obj, const KJS::List &args ) +{ + + // Unsupported parameter RenameAction + return KJS::Value(); + + RenameAction arg0; // Dummy + + instance->setDefaultRenameAction( + arg0 ); + return KJS::Value(); // Returns void + +} + +KJS::Value QListViewImp::defaultRenameAction_69( KJS::ExecState *exec, KJS::Object &obj, const KJS::List &args ) +{ + + instance->defaultRenameAction( ); + return KJS::Value(); // Returns 'RenameAction' + +} + +KJS::Value QListViewImp::isRenaming_70( KJS::ExecState *exec, KJS::Object &obj, const KJS::List &args ) +{ + + bool ret; + ret = instance->isRenaming( ); + return KJS::Boolean( ret ); + +} + +KJS::Value QListViewImp::hideColumn_71( KJS::ExecState *exec, KJS::Object &obj, const KJS::List &args ) +{ + + int arg0 = (args.size() >= 1) ? args[0].toInteger(exec) : -1; + + instance->hideColumn( + arg0 ); + return KJS::Value(); // Returns void + +} + + +} // namespace KJSEmbed + +// Local Variables: +// c-basic-offset: 4 +// End: + + diff --git a/kjsembed/qtbindings/qlistview_imp.h b/kjsembed/qtbindings/qlistview_imp.h new file mode 100644 index 00000000..0c1edf2d --- /dev/null +++ b/kjsembed/qtbindings/qlistview_imp.h @@ -0,0 +1,226 @@ + + + +#ifndef KJSEMBED_QListView_H +#define KJSEMBED_QListView_H + +#include <kjs/interpreter.h> +#include <kjs/object.h> + +#include <kjsembed/jsobjectproxy_imp.h> + +class QListView; + +/** + * Namespace containing the KJSEmbed library. + */ +namespace KJSEmbed { + +/** + * Wrapper class for QListView methods. + * + * @author Richard Moore, rich@kde.org + */ +class QListViewImp : public JSProxyImp +{ +public: + /** Enumerates the constructors supported by this class. */ + enum Constructors { + Constructor_QListView_1, + + LastConstuctor = -1 + }; + + /** Enumerates the methods supported by this class. */ + enum Methods { + + Method_treeStepSize_3, + Method_setTreeStepSize_4, + Method_insertItem_5, + Method_takeItem_6, + Method_removeItem_7, + Method_header_8, + Method_addColumn_9, + Method_addColumn_10, + Method_removeColumn_11, + Method_setColumnText_12, + Method_setColumnText_13, + Method_columnText_14, + Method_setColumnWidth_15, + Method_columnWidth_16, + Method_setColumnWidthMode_17, + Method_columnWidthMode_18, + Method_columns_19, + Method_setColumnAlignment_20, + Method_columnAlignment_21, + Method_show_22, + Method_itemAt_23, + Method_itemRect_24, + Method_itemPos_25, + Method_ensureItemVisible_26, + Method_repaintItem_27, + Method_setMultiSelection_28, + Method_isMultiSelection_29, + Method_setSelectionMode_30, + Method_selectionMode_31, + Method_clearSelection_32, + Method_setSelected_33, + Method_setSelectionAnchor_34, + Method_isSelected_35, + Method_selectedItem_36, + Method_setOpen_37, + Method_isOpen_38, + Method_setCurrentItem_39, + Method_currentItem_40, + Method_firstChild_41, + Method_lastItem_42, + Method_childCount_43, + Method_setAllColumnsShowFocus_44, + Method_allColumnsShowFocus_45, + Method_setItemMargin_46, + Method_itemMargin_47, + Method_setRootIsDecorated_48, + Method_rootIsDecorated_49, + Method_setSorting_50, + Method_sortColumn_51, + Method_setSortColumn_52, + Method_sortOrder_53, + Method_setSortOrder_54, + Method_sort_55, + Method_setFont_56, + Method_setPalette_57, + Method_eventFilter_58, + Method_sizeHint_59, + Method_minimumSizeHint_60, + Method_setShowSortIndicator_61, + Method_showSortIndicator_62, + Method_setShowToolTips_63, + Method_showToolTips_64, + Method_setResizeMode_65, + Method_resizeMode_66, + Method_findItem_67, + Method_setDefaultRenameAction_68, + Method_defaultRenameAction_69, + Method_isRenaming_70, + Method_hideColumn_71, + Method_Last = -1 + }; + + QListViewImp( KJS::ExecState *exec, int id, bool constructor=false ); + ~QListViewImp(); + + static void addBindings( KJS::ExecState *exec, KJS::Object &object ); + + static QListView *toQListView( KJS::Object &object ); + + // + // Constructors implemented by this class. + // + + KJS::Object QListView_1( KJS::ExecState *exec, const KJS::List &args ); + + // + // Methods implemented by this class. + // + + KJS::Value treeStepSize_3( KJS::ExecState *exec, KJS::Object &obj, const KJS::List &args ); + KJS::Value setTreeStepSize_4( KJS::ExecState *exec, KJS::Object &obj, const KJS::List &args ); + KJS::Value insertItem_5( KJS::ExecState *exec, KJS::Object &obj, const KJS::List &args ); + KJS::Value takeItem_6( KJS::ExecState *exec, KJS::Object &obj, const KJS::List &args ); + KJS::Value removeItem_7( KJS::ExecState *exec, KJS::Object &obj, const KJS::List &args ); + KJS::Value header_8( KJS::ExecState *exec, KJS::Object &obj, const KJS::List &args ); + KJS::Value addColumn_9( KJS::ExecState *exec, KJS::Object &obj, const KJS::List &args ); + KJS::Value addColumn_10( KJS::ExecState *exec, KJS::Object &obj, const KJS::List &args ); + KJS::Value removeColumn_11( KJS::ExecState *exec, KJS::Object &obj, const KJS::List &args ); + KJS::Value setColumnText_12( KJS::ExecState *exec, KJS::Object &obj, const KJS::List &args ); + KJS::Value setColumnText_13( KJS::ExecState *exec, KJS::Object &obj, const KJS::List &args ); + KJS::Value columnText_14( KJS::ExecState *exec, KJS::Object &obj, const KJS::List &args ); + KJS::Value setColumnWidth_15( KJS::ExecState *exec, KJS::Object &obj, const KJS::List &args ); + KJS::Value columnWidth_16( KJS::ExecState *exec, KJS::Object &obj, const KJS::List &args ); + KJS::Value setColumnWidthMode_17( KJS::ExecState *exec, KJS::Object &obj, const KJS::List &args ); + KJS::Value columnWidthMode_18( KJS::ExecState *exec, KJS::Object &obj, const KJS::List &args ); + KJS::Value columns_19( KJS::ExecState *exec, KJS::Object &obj, const KJS::List &args ); + KJS::Value setColumnAlignment_20( KJS::ExecState *exec, KJS::Object &obj, const KJS::List &args ); + KJS::Value columnAlignment_21( KJS::ExecState *exec, KJS::Object &obj, const KJS::List &args ); + KJS::Value show_22( KJS::ExecState *exec, KJS::Object &obj, const KJS::List &args ); + KJS::Value itemAt_23( KJS::ExecState *exec, KJS::Object &obj, const KJS::List &args ); + KJS::Value itemRect_24( KJS::ExecState *exec, KJS::Object &obj, const KJS::List &args ); + KJS::Value itemPos_25( KJS::ExecState *exec, KJS::Object &obj, const KJS::List &args ); + KJS::Value ensureItemVisible_26( KJS::ExecState *exec, KJS::Object &obj, const KJS::List &args ); + KJS::Value repaintItem_27( KJS::ExecState *exec, KJS::Object &obj, const KJS::List &args ); + KJS::Value setMultiSelection_28( KJS::ExecState *exec, KJS::Object &obj, const KJS::List &args ); + KJS::Value isMultiSelection_29( KJS::ExecState *exec, KJS::Object &obj, const KJS::List &args ); + KJS::Value setSelectionMode_30( KJS::ExecState *exec, KJS::Object &obj, const KJS::List &args ); + KJS::Value selectionMode_31( KJS::ExecState *exec, KJS::Object &obj, const KJS::List &args ); + KJS::Value clearSelection_32( KJS::ExecState *exec, KJS::Object &obj, const KJS::List &args ); + KJS::Value setSelected_33( KJS::ExecState *exec, KJS::Object &obj, const KJS::List &args ); + KJS::Value setSelectionAnchor_34( KJS::ExecState *exec, KJS::Object &obj, const KJS::List &args ); + KJS::Value isSelected_35( KJS::ExecState *exec, KJS::Object &obj, const KJS::List &args ); + KJS::Value selectedItem_36( KJS::ExecState *exec, KJS::Object &obj, const KJS::List &args ); + KJS::Value setOpen_37( KJS::ExecState *exec, KJS::Object &obj, const KJS::List &args ); + KJS::Value isOpen_38( KJS::ExecState *exec, KJS::Object &obj, const KJS::List &args ); + KJS::Value setCurrentItem_39( KJS::ExecState *exec, KJS::Object &obj, const KJS::List &args ); + KJS::Value currentItem_40( KJS::ExecState *exec, KJS::Object &obj, const KJS::List &args ); + KJS::Value firstChild_41( KJS::ExecState *exec, KJS::Object &obj, const KJS::List &args ); + KJS::Value lastItem_42( KJS::ExecState *exec, KJS::Object &obj, const KJS::List &args ); + KJS::Value childCount_43( KJS::ExecState *exec, KJS::Object &obj, const KJS::List &args ); + KJS::Value setAllColumnsShowFocus_44( KJS::ExecState *exec, KJS::Object &obj, const KJS::List &args ); + KJS::Value allColumnsShowFocus_45( KJS::ExecState *exec, KJS::Object &obj, const KJS::List &args ); + KJS::Value setItemMargin_46( KJS::ExecState *exec, KJS::Object &obj, const KJS::List &args ); + KJS::Value itemMargin_47( KJS::ExecState *exec, KJS::Object &obj, const KJS::List &args ); + KJS::Value setRootIsDecorated_48( KJS::ExecState *exec, KJS::Object &obj, const KJS::List &args ); + KJS::Value rootIsDecorated_49( KJS::ExecState *exec, KJS::Object &obj, const KJS::List &args ); + KJS::Value setSorting_50( KJS::ExecState *exec, KJS::Object &obj, const KJS::List &args ); + KJS::Value sortColumn_51( KJS::ExecState *exec, KJS::Object &obj, const KJS::List &args ); + KJS::Value setSortColumn_52( KJS::ExecState *exec, KJS::Object &obj, const KJS::List &args ); + KJS::Value sortOrder_53( KJS::ExecState *exec, KJS::Object &obj, const KJS::List &args ); + KJS::Value setSortOrder_54( KJS::ExecState *exec, KJS::Object &obj, const KJS::List &args ); + KJS::Value sort_55( KJS::ExecState *exec, KJS::Object &obj, const KJS::List &args ); + KJS::Value setFont_56( KJS::ExecState *exec, KJS::Object &obj, const KJS::List &args ); + KJS::Value setPalette_57( KJS::ExecState *exec, KJS::Object &obj, const KJS::List &args ); + KJS::Value eventFilter_58( KJS::ExecState *exec, KJS::Object &obj, const KJS::List &args ); + KJS::Value sizeHint_59( KJS::ExecState *exec, KJS::Object &obj, const KJS::List &args ); + KJS::Value minimumSizeHint_60( KJS::ExecState *exec, KJS::Object &obj, const KJS::List &args ); + KJS::Value setShowSortIndicator_61( KJS::ExecState *exec, KJS::Object &obj, const KJS::List &args ); + KJS::Value showSortIndicator_62( KJS::ExecState *exec, KJS::Object &obj, const KJS::List &args ); + KJS::Value setShowToolTips_63( KJS::ExecState *exec, KJS::Object &obj, const KJS::List &args ); + KJS::Value showToolTips_64( KJS::ExecState *exec, KJS::Object &obj, const KJS::List &args ); + KJS::Value setResizeMode_65( KJS::ExecState *exec, KJS::Object &obj, const KJS::List &args ); + KJS::Value resizeMode_66( KJS::ExecState *exec, KJS::Object &obj, const KJS::List &args ); + KJS::Value findItem_67( KJS::ExecState *exec, KJS::Object &obj, const KJS::List &args ); + KJS::Value setDefaultRenameAction_68( KJS::ExecState *exec, KJS::Object &obj, const KJS::List &args ); + KJS::Value defaultRenameAction_69( KJS::ExecState *exec, KJS::Object &obj, const KJS::List &args ); + KJS::Value isRenaming_70( KJS::ExecState *exec, KJS::Object &obj, const KJS::List &args ); + KJS::Value hideColumn_71( KJS::ExecState *exec, KJS::Object &obj, const KJS::List &args ); + + // + // JS binding code. + // + + /** Returns true iff this object implements the construct function. */ + virtual bool implementsConstruct() const { return cons; } + + /** Invokes the construct function. */ + virtual KJS::Object construct( KJS::ExecState *exec, const KJS::List &args ); + + /** Returns true iff this object implements the call function. */ + virtual bool implementsCall() const { return !cons; } + + /** Invokes the call function. */ + virtual KJS::Value call( KJS::ExecState *exec, KJS::Object &self, const KJS::List &args ); + +private: + QListView *instance; // Temp + int id; + bool cons; +}; + +} // namespace KJSEmbed + +#endif // KJSEMBED_QListView_H + +// Local Variables: +// c-basic-offset: 4 +// End: + + diff --git a/kjsembed/qtbindings/qlistviewitem_imp.cpp b/kjsembed/qtbindings/qlistviewitem_imp.cpp new file mode 100644 index 00000000..b7e18820 --- /dev/null +++ b/kjsembed/qtbindings/qlistviewitem_imp.cpp @@ -0,0 +1,1429 @@ + + + +#include <qcstring.h> +#include <qpalette.h> +#include <qpixmap.h> +#include <qfont.h> + +#include <kjs/object.h> + +#include <kjsembed/global.h> +#include <kjsembed/jsobjectproxy.h> +#include <kjsembed/jsopaqueproxy.h> +#include <kjsembed/jsbinding.h> + +#include <qlistview.h> +#include "qlistviewitem_imp.h" + +/** + * Namespace containing the KJSEmbed library. + */ +namespace KJSEmbed { +namespace Bindings { + + KJS::Object QListViewItemLoader::createBinding(KJSEmbedPart *jspart, KJS::ExecState *exec, const KJS::List &args) const + { + if ( args.size() == 0 ) { + // FALL THRU + } else { + JSOpaqueProxy * arg0 = JSProxy::toOpaqueProxy( args[ 0 ].imp() ); + JSOpaqueProxy *prx = 0; + + if ( arg0 ) { + if ( arg0->typeName() == "QListViewItem" ) { + QListViewItem * parent = arg0->toNative<QListViewItem>(); + prx = new JSOpaqueProxy( new QListViewItem( parent ), "QListViewItem" ); + } else { + return KJS::Object(); + } + } else { + JSObjectProxy *arg0 = JSProxy::toObjectProxy( args[ 0 ].imp() ); + if ( arg0 ) { + QListView * parent = ( QListView * ) ( arg0->widget() ); + prx = new JSOpaqueProxy( new QListViewItem( parent ), "QListViewItem" ); + } else { + return KJS::Object(); + } + } + prx->setOwner( JSProxy::Native ); + KJS::Object proxyObj( prx ); + addBindings(jspart,exec,proxyObj); + return proxyObj; + } + return KJS::Object(); + } + + void QListViewItemLoader::addBindings( KJSEmbedPart *jspart, KJS::ExecState *exec, KJS::Object &proxy ) const + { + QListViewItemImp::addBindings( exec, proxy ); + } +} + +QListViewItemImp::QListViewItemImp( KJS::ExecState *exec, int mid, bool constructor ) + : JSProxyImp(exec), id(mid), cons(constructor) +{ +} + +QListViewItemImp::~QListViewItemImp() +{ +} + +/** + * Adds bindings for static methods and enum constants to the specified Object. + */ +void QListViewItemImp::addStaticBindings( KJS::ExecState *exec, KJS::Object &object ) +{ + JSProxy::MethodTable methods[] = { + + { 0, 0 } + }; + + int idx = 0; + QCString lastName; + + while( methods[idx].name ) { + if ( lastName != methods[idx].name ) { + QListViewItemImp *meth = new QListViewItemImp( exec, methods[idx].id ); + object.put( exec , methods[idx].name, KJS::Object(meth) ); + lastName = methods[idx].name; + } + ++idx; + } + + +} + +/** + * Adds bindings for instance methods to the specified Object. + */ +void QListViewItemImp::addBindings( KJS::ExecState *exec, KJS::Object &object ) +{ + JSProxy::MethodTable methods[] = { + + { Method_insertItem_10, "insertItem" }, + { Method_takeItem_11, "takeItem" }, + { Method_removeItem_12, "removeItem" }, + { Method_height_13, "height" }, + { Method_invalidateHeight_14, "invalidateHeight" }, + { Method_totalHeight_15, "totalHeight" }, + { Method_width_16, "width" }, + { Method_widthChanged_17, "widthChanged" }, + { Method_depth_18, "depth" }, + { Method_setText_19, "setText" }, + { Method_text_20, "text" }, + { Method_setPixmap_21, "setPixmap" }, + { Method_pixmap_22, "pixmap" }, + { Method_key_23, "key" }, + { Method_compare_24, "compare" }, + { Method_sortChildItems_25, "sortChildItems" }, + { Method_childCount_26, "childCount" }, + { Method_isOpen_27, "isOpen" }, + { Method_setOpen_28, "setOpen" }, + { Method_setup_29, "setup" }, + { Method_setSelected_30, "setSelected" }, + { Method_isSelected_31, "isSelected" }, + { Method_paintCell_32, "paintCell" }, + { Method_paintBranches_33, "paintBranches" }, + { Method_paintFocus_34, "paintFocus" }, + { Method_firstChild_35, "firstChild" }, + { Method_nextSibling_36, "nextSibling" }, + { Method_parent_37, "parent" }, + { Method_itemAbove_38, "itemAbove" }, + { Method_itemBelow_39, "itemBelow" }, + { Method_itemPos_40, "itemPos" }, + { Method_listView_41, "listView" }, + { Method_setSelectable_42, "setSelectable" }, + { Method_isSelectable_43, "isSelectable" }, + { Method_setExpandable_44, "setExpandable" }, + { Method_isExpandable_45, "isExpandable" }, + { Method_repaint_46, "repaint" }, + { Method_sort_47, "sort" }, + { Method_moveItem_48, "moveItem" }, + { Method_setDragEnabled_49, "setDragEnabled" }, + { Method_setDropEnabled_50, "setDropEnabled" }, + { Method_dragEnabled_51, "dragEnabled" }, + { Method_dropEnabled_52, "dropEnabled" }, + { Method_acceptDrop_53, "acceptDrop" }, + { Method_setVisible_54, "setVisible" }, + { Method_isVisible_55, "isVisible" }, + { Method_setRenameEnabled_56, "setRenameEnabled" }, + { Method_renameEnabled_57, "renameEnabled" }, + { Method_startRename_58, "startRename" }, + { Method_setEnabled_59, "setEnabled" }, + { Method_isEnabled_60, "isEnabled" }, + { Method_rtti_61, "rtti" }, + { Method_setMultiLinesEnabled_62, "setMultiLinesEnabled" }, + { Method_multiLinesEnabled_63, "multiLinesEnabled" }, + { 0, 0 } + }; + + int idx = 0; + QCString lastName; + + while( methods[idx].name ) { + if ( lastName != methods[idx].name ) { + QListViewItemImp *meth = new QListViewItemImp( exec, methods[idx].id ); + object.put( exec , methods[idx].name, KJS::Object(meth) ); + lastName = methods[idx].name; + } + ++idx; + } +} + +/** + * Extract a QListViewItem pointer from an Object. + */ +QListViewItem *QListViewItemImp::toQListViewItem( KJS::Object &self ) +{ + JSObjectProxy *ob = JSProxy::toObjectProxy( self.imp() ); + if ( ob ) { + QObject *obj = ob->object(); + if ( obj ) + return dynamic_cast<QListViewItem *>( obj ); + } + + JSOpaqueProxy *op = JSProxy::toOpaqueProxy( self.imp() ); + if ( !op ) + return 0; + return op->toNative<QListViewItem>(); +} + +/** + * Select and invoke the correct constructor. + */ +KJS::Object QListViewItemImp::construct( KJS::ExecState *exec, const KJS::List &args ) +{ + switch( id ) { + + case Constructor_QListViewItem_1: + return QListViewItem_1( exec, args ); + break; + + case Constructor_QListViewItem_2: + return QListViewItem_2( exec, args ); + break; + + case Constructor_QListViewItem_3: + return QListViewItem_3( exec, args ); + break; + + case Constructor_QListViewItem_4: + return QListViewItem_4( exec, args ); + break; + + case Constructor_QListViewItem_5: + return QListViewItem_5( exec, args ); + break; + + case Constructor_QListViewItem_6: + return QListViewItem_6( exec, args ); + break; + + case Constructor_QListViewItem_7: + return QListViewItem_7( exec, args ); + break; + + case Constructor_QListViewItem_8: + return QListViewItem_8( exec, args ); + break; + + default: + break; + } + + QString msg = i18n("QListViewItemCons has no constructor with id '%1'.").arg(id); + return throwError(exec, msg,KJS::ReferenceError); +} + + +KJS::Object QListViewItemImp::QListViewItem_1( KJS::ExecState *exec, const KJS::List &args ) +{ +#if 0 + // Unsupported parameter QListView * + return KJS::Value(); + + QListView * arg0; // Dummy + + + // We should now create an object of type QListViewItemQListViewItem *ret = new QListViewItem( + + arg0 ); +#endif +return KJS::Object(); + +} + +KJS::Object QListViewItemImp::QListViewItem_2( KJS::ExecState *exec, const KJS::List &args ) +{ +#if 0 + // Unsupported parameter QListViewItem * + return KJS::Value(); + + QListViewItem * arg0; // Dummy + + + // We should now create an object of type QListViewItemQListViewItem *ret = new QListViewItem( + + arg0 ); +#endif +return KJS::Object(); +} + +KJS::Object QListViewItemImp::QListViewItem_3( KJS::ExecState *exec, const KJS::List &args ) +{ +#if 0 + + // Unsupported parameter QListView * + return KJS::Value(); + + QListView * arg0; // Dummy + + // Unsupported parameter QListViewItem * + return KJS::Value(); + + QListViewItem * arg1; // Dummy + + + // We should now create an object of type QListViewItemQListViewItem *ret = new QListViewItem( + + arg0, + arg1 ); +#endif +return KJS::Object(); +} + +KJS::Object QListViewItemImp::QListViewItem_4( KJS::ExecState *exec, const KJS::List &args ) +{ +#if 0 + + // Unsupported parameter QListViewItem * + return KJS::Value(); + + QListViewItem * arg0; // Dummy + + // Unsupported parameter QListViewItem * + return KJS::Value(); + + QListViewItem * arg1; // Dummy + + + // We should now create an object of type QListViewItemQListViewItem *ret = new QListViewItem( + + arg0, + arg1 ); +#endif +return KJS::Object(); + +} + +KJS::Object QListViewItemImp::QListViewItem_5( KJS::ExecState *exec, const KJS::List &args ) +{ +#if 0 + + // Unsupported parameter QListView * + return KJS::Value(); + + QListView * arg0; // Dummy + + QString arg1 = extractQString(exec, args, 1); + + QString arg2 = extractQString(exec, args, 2); + + QString arg3 = extractQString(exec, args, 3); + + QString arg4 = extractQString(exec, args, 4); + + QString arg5 = extractQString(exec, args, 5); + + QString arg6 = extractQString(exec, args, 6); + + QString arg7 = extractQString(exec, args, 7); + + QString arg8 = extractQString(exec, args, 8); + + + // We should now create an object of type QListViewItemQListViewItem *ret = new QListViewItem( + + arg0, + arg1, + arg2, + arg3, + arg4, + arg5, + arg6, + arg7, + arg8 ); +#endif +return KJS::Object(); + +} + +KJS::Object QListViewItemImp::QListViewItem_6( KJS::ExecState *exec, const KJS::List &args ) +{ +#if 0 + + // Unsupported parameter QListViewItem * + return KJS::Value(); + + QListViewItem * arg0; // Dummy + + QString arg1 = extractQString(exec, args, 1); + + QString arg2 = extractQString(exec, args, 2); + + QString arg3 = extractQString(exec, args, 3); + + QString arg4 = extractQString(exec, args, 4); + + QString arg5 = extractQString(exec, args, 5); + + QString arg6 = extractQString(exec, args, 6); + + QString arg7 = extractQString(exec, args, 7); + + QString arg8 = extractQString(exec, args, 8); + + + // We should now create an object of type QListViewItemQListViewItem *ret = new QListViewItem( + + arg0, + arg1, + arg2, + arg3, + arg4, + arg5, + arg6, + arg7, + arg8 ); + +#endif +return KJS::Object(); + +} + +KJS::Object QListViewItemImp::QListViewItem_7( KJS::ExecState *exec, const KJS::List &args ) +{ +#if 0 + // Unsupported parameter QListView * + return KJS::Value(); + + QListView * arg0; // Dummy + + // Unsupported parameter QListViewItem * + return KJS::Value(); + + QListViewItem * arg1; // Dummy + + QString arg2 = extractQString(exec, args, 2); + + QString arg3 = extractQString(exec, args, 3); + + QString arg4 = extractQString(exec, args, 4); + + QString arg5 = extractQString(exec, args, 5); + + QString arg6 = extractQString(exec, args, 6); + + QString arg7 = extractQString(exec, args, 7); + + QString arg8 = extractQString(exec, args, 8); + + QString arg9 = extractQString(exec, args, 9); + + + // We should now create an object of type QListViewItemQListViewItem *ret = new QListViewItem( + + arg0, + arg1, + arg2, + arg3, + arg4, + arg5, + arg6, + arg7, + arg8, + arg9 ); +#endif +return KJS::Object(); + +} + +KJS::Object QListViewItemImp::QListViewItem_8( KJS::ExecState *exec, const KJS::List &args ) +{ +#if 0 + // Unsupported parameter QListViewItem * + return KJS::Value(); + + QListViewItem * arg0; // Dummy + + // Unsupported parameter QListViewItem * + return KJS::Value(); + + QListViewItem * arg1; // Dummy + + QString arg2 = extractQString(exec, args, 2); + + QString arg3 = extractQString(exec, args, 3); + + QString arg4 = extractQString(exec, args, 4); + + QString arg5 = extractQString(exec, args, 5); + + QString arg6 = extractQString(exec, args, 6); + + QString arg7 = extractQString(exec, args, 7); + + QString arg8 = extractQString(exec, args, 8); + + QString arg9 = extractQString(exec, args, 9); + + + // We should now create an object of type QListViewItemQListViewItem *ret = new QListViewItem( + + arg0, + arg1, + arg2, + arg3, + arg4, + arg5, + arg6, + arg7, + arg8, + arg9 ); +#endif +return KJS::Object(); + +} + +KJS::Value QListViewItemImp::call( KJS::ExecState *exec, KJS::Object &self, const KJS::List &args ) +{ + instance = QListViewItemImp::toQListViewItem( self ); + + switch( id ) { + + case Method_insertItem_10: + return insertItem_10( exec, self, args ); + break; + + case Method_takeItem_11: + return takeItem_11( exec, self, args ); + break; + + case Method_removeItem_12: + return removeItem_12( exec, self, args ); + break; + + case Method_height_13: + return height_13( exec, self, args ); + break; + + case Method_invalidateHeight_14: + return invalidateHeight_14( exec, self, args ); + break; + + case Method_totalHeight_15: + return totalHeight_15( exec, self, args ); + break; + + case Method_width_16: + return width_16( exec, self, args ); + break; + + case Method_widthChanged_17: + return widthChanged_17( exec, self, args ); + break; + + case Method_depth_18: + return depth_18( exec, self, args ); + break; + + case Method_setText_19: + return setText_19( exec, self, args ); + break; + + case Method_text_20: + return text_20( exec, self, args ); + break; + + case Method_setPixmap_21: + return setPixmap_21( exec, self, args ); + break; + + case Method_pixmap_22: + return pixmap_22( exec, self, args ); + break; + + case Method_key_23: + return key_23( exec, self, args ); + break; + + case Method_compare_24: + return compare_24( exec, self, args ); + break; + + case Method_sortChildItems_25: + return sortChildItems_25( exec, self, args ); + break; + + case Method_childCount_26: + return childCount_26( exec, self, args ); + break; + + case Method_isOpen_27: + return isOpen_27( exec, self, args ); + break; + + case Method_setOpen_28: + return setOpen_28( exec, self, args ); + break; + + case Method_setup_29: + return setup_29( exec, self, args ); + break; + + case Method_setSelected_30: + return setSelected_30( exec, self, args ); + break; + + case Method_isSelected_31: + return isSelected_31( exec, self, args ); + break; + + case Method_paintCell_32: + return paintCell_32( exec, self, args ); + break; + + case Method_paintBranches_33: + return paintBranches_33( exec, self, args ); + break; + + case Method_paintFocus_34: + return paintFocus_34( exec, self, args ); + break; + + case Method_firstChild_35: + return firstChild_35( exec, self, args ); + break; + + case Method_nextSibling_36: + return nextSibling_36( exec, self, args ); + break; + + case Method_parent_37: + return parent_37( exec, self, args ); + break; + + case Method_itemAbove_38: + return itemAbove_38( exec, self, args ); + break; + + case Method_itemBelow_39: + return itemBelow_39( exec, self, args ); + break; + + case Method_itemPos_40: + return itemPos_40( exec, self, args ); + break; + + case Method_listView_41: + return listView_41( exec, self, args ); + break; + + case Method_setSelectable_42: + return setSelectable_42( exec, self, args ); + break; + + case Method_isSelectable_43: + return isSelectable_43( exec, self, args ); + break; + + case Method_setExpandable_44: + return setExpandable_44( exec, self, args ); + break; + + case Method_isExpandable_45: + return isExpandable_45( exec, self, args ); + break; + + case Method_repaint_46: + return repaint_46( exec, self, args ); + break; + + case Method_sort_47: + return sort_47( exec, self, args ); + break; + + case Method_moveItem_48: + return moveItem_48( exec, self, args ); + break; + + case Method_setDragEnabled_49: + return setDragEnabled_49( exec, self, args ); + break; + + case Method_setDropEnabled_50: + return setDropEnabled_50( exec, self, args ); + break; + + case Method_dragEnabled_51: + return dragEnabled_51( exec, self, args ); + break; + + case Method_dropEnabled_52: + return dropEnabled_52( exec, self, args ); + break; + + case Method_acceptDrop_53: + return acceptDrop_53( exec, self, args ); + break; + + case Method_setVisible_54: + return setVisible_54( exec, self, args ); + break; + + case Method_isVisible_55: + return isVisible_55( exec, self, args ); + break; + + case Method_setRenameEnabled_56: + return setRenameEnabled_56( exec, self, args ); + break; + + case Method_renameEnabled_57: + return renameEnabled_57( exec, self, args ); + break; + + case Method_startRename_58: + return startRename_58( exec, self, args ); + break; + + case Method_setEnabled_59: + return setEnabled_59( exec, self, args ); + break; + + case Method_isEnabled_60: + return isEnabled_60( exec, self, args ); + break; + + case Method_rtti_61: + return rtti_61( exec, self, args ); + break; + + case Method_setMultiLinesEnabled_62: + return setMultiLinesEnabled_62( exec, self, args ); + break; + + case Method_multiLinesEnabled_63: + return multiLinesEnabled_63( exec, self, args ); + break; + + default: + break; + } + + QString msg = i18n( "QListViewItemImp has no method with id '%1'." ).arg( id ); + return throwError(exec, msg,KJS::ReferenceError); +} + + +KJS::Value QListViewItemImp::insertItem_10( KJS::ExecState *exec, KJS::Object &obj, const KJS::List &args ) +{ + + // Unsupported parameter QListViewItem * + return KJS::Value(); + + QListViewItem * arg0; // Dummy + + instance->insertItem( + arg0 ); + return KJS::Value(); // Returns void + +} + +KJS::Value QListViewItemImp::takeItem_11( KJS::ExecState *exec, KJS::Object &obj, const KJS::List &args ) +{ + + // Unsupported parameter QListViewItem * + return KJS::Value(); + + QListViewItem * arg0; // Dummy + + instance->takeItem( + arg0 ); + return KJS::Value(); // Returns void + +} + +KJS::Value QListViewItemImp::removeItem_12( KJS::ExecState *exec, KJS::Object &obj, const KJS::List &args ) +{ + + // Unsupported parameter QListViewItem * + return KJS::Value(); + + QListViewItem * arg0; // Dummy + + instance->removeItem( + arg0 ); + return KJS::Value(); // Returns void + +} + +KJS::Value QListViewItemImp::height_13( KJS::ExecState *exec, KJS::Object &obj, const KJS::List &args ) +{ + + int ret; + ret = instance->height( ); + return KJS::Number( ret ); + +} + +KJS::Value QListViewItemImp::invalidateHeight_14( KJS::ExecState *exec, KJS::Object &obj, const KJS::List &args ) +{ + + instance->invalidateHeight( ); + return KJS::Value(); // Returns void + +} + +KJS::Value QListViewItemImp::totalHeight_15( KJS::ExecState *exec, KJS::Object &obj, const KJS::List &args ) +{ + + int ret; + ret = instance->totalHeight( ); + return KJS::Number( ret ); + +} + +KJS::Value QListViewItemImp::width_16( KJS::ExecState *exec, KJS::Object &obj, const KJS::List &args ) +{ +#if 0 + // Unsupported parameter const QFontMetrics & + return KJS::Value(); + + const QFontMetrics & arg0; // Dummy + + // Unsupported parameter const QListView * + return KJS::Value(); + + const QListView * arg1; // Dummy + + int arg2 = extractInt(exec, args, 2); + + int ret; + ret = instance->width( + arg0, + arg1, + arg2 ); + return KJS::Number( ret ); +#endif +return KJS::Object(); + +} + +KJS::Value QListViewItemImp::widthChanged_17( KJS::ExecState *exec, KJS::Object &obj, const KJS::List &args ) +{ + + int arg0 = extractInt(exec, args, 0); + + instance->widthChanged( + arg0 ); + return KJS::Value(); // Returns void + +} + +KJS::Value QListViewItemImp::depth_18( KJS::ExecState *exec, KJS::Object &obj, const KJS::List &args ) +{ + + int ret; + ret = instance->depth( ); + return KJS::Number( ret ); + +} + +KJS::Value QListViewItemImp::setText_19( KJS::ExecState *exec, KJS::Object &obj, const KJS::List &args ) +{ + + int arg0 = extractInt(exec, args, 0); + + QString arg1 = extractQString(exec, args, 1); + + instance->setText( + arg0, + arg1 ); + return KJS::Value(); // Returns void + +} + +KJS::Value QListViewItemImp::text_20( KJS::ExecState *exec, KJS::Object &obj, const KJS::List &args ) +{ + + int arg0 = extractInt(exec, args, 0); + + QString ret; + ret = instance->text( + arg0 ); + return KJS::String( ret ); + +} + +KJS::Value QListViewItemImp::setPixmap_21( KJS::ExecState *exec, KJS::Object &obj, const KJS::List &args ) +{ + + int arg0 = extractInt(exec, args, 0); + + QPixmap arg1 = extractQPixmap(exec, args, 1); + + instance->setPixmap( + arg0, + arg1 ); + return KJS::Value(); // Returns void + +} + +KJS::Value QListViewItemImp::pixmap_22( KJS::ExecState *exec, KJS::Object &obj, const KJS::List &args ) +{ + + int arg0 = extractInt(exec, args, 0); + + instance->pixmap( + arg0 ); + return KJS::Value(); // Returns 'const QPixmap *' + +} + +KJS::Value QListViewItemImp::key_23( KJS::ExecState *exec, KJS::Object &obj, const KJS::List &args ) +{ + + int arg0 = extractInt(exec, args, 0); + + bool arg1 = extractBool(exec, args, 1); + + QString ret; + ret = instance->key( + arg0, + arg1 ); + return KJS::String( ret ); + +} + +KJS::Value QListViewItemImp::compare_24( KJS::ExecState *exec, KJS::Object &obj, const KJS::List &args ) +{ + + // Unsupported parameter QListViewItem * + return KJS::Value(); + + QListViewItem * arg0; // Dummy + + int arg1 = extractInt(exec, args, 1); + + bool arg2 = extractBool(exec, args, 2); + + int ret; + ret = instance->compare( + arg0, + arg1, + arg2 ); + return KJS::Number( ret ); + +} + +KJS::Value QListViewItemImp::sortChildItems_25( KJS::ExecState *exec, KJS::Object &obj, const KJS::List &args ) +{ + + int arg0 = extractInt(exec, args, 0); + + bool arg1 = extractBool(exec, args, 1); + + instance->sortChildItems( + arg0, + arg1 ); + return KJS::Value(); // Returns void + +} + +KJS::Value QListViewItemImp::childCount_26( KJS::ExecState *exec, KJS::Object &obj, const KJS::List &args ) +{ + + int ret; + ret = instance->childCount( ); + return KJS::Number( ret ); + +} + +KJS::Value QListViewItemImp::isOpen_27( KJS::ExecState *exec, KJS::Object &obj, const KJS::List &args ) +{ + + bool ret; + ret = instance->isOpen( ); + return KJS::Boolean( ret ); + +} + +KJS::Value QListViewItemImp::setOpen_28( KJS::ExecState *exec, KJS::Object &obj, const KJS::List &args ) +{ + + bool arg0 = extractBool(exec, args, 0); + + instance->setOpen( + arg0 ); + return KJS::Value(); // Returns void + +} + +KJS::Value QListViewItemImp::setup_29( KJS::ExecState *exec, KJS::Object &obj, const KJS::List &args ) +{ + + instance->setup( ); + return KJS::Value(); // Returns void + +} + +KJS::Value QListViewItemImp::setSelected_30( KJS::ExecState *exec, KJS::Object &obj, const KJS::List &args ) +{ + + bool arg0 = extractBool(exec, args, 0); + + instance->setSelected( + arg0 ); + return KJS::Value(); // Returns void + +} + +KJS::Value QListViewItemImp::isSelected_31( KJS::ExecState *exec, KJS::Object &obj, const KJS::List &args ) +{ + + bool ret; + ret = instance->isSelected( ); + return KJS::Boolean( ret ); + +} + +KJS::Value QListViewItemImp::paintCell_32( KJS::ExecState *exec, KJS::Object &obj, const KJS::List &args ) +{ +#if 0 + // Unsupported parameter QPainter * + return KJS::Value(); + + QPainter * arg0; // Dummy + + // Unsupported parameter const QColorGroup & + return KJS::Value(); + + const QColorGroup & arg1; // Dummy + + int arg2 = extractInt(exec, args, 2); + + int arg3 = extractInt(exec, args, 3); + + int arg4 = extractInt(exec, args, 4); + + instance->paintCell( + arg0, + arg1, + arg2, + arg3, + arg4 ); + return KJS::Value(); // Returns void +#endif + +return KJS::Object(); +} + +KJS::Value QListViewItemImp::paintBranches_33( KJS::ExecState *exec, KJS::Object &obj, const KJS::List &args ) +{ +#if 0 + // Unsupported parameter QPainter * + return KJS::Value(); + + QPainter * arg0; // Dummy + + // Unsupported parameter const QColorGroup & + return KJS::Value(); + + const QColorGroup & arg1; // Dummy + + int arg2 = extractInt(exec, args, 2); + + int arg3 = extractInt(exec, args, 3); + + int arg4 = extractInt(exec, args, 4); + + instance->paintBranches( + arg0, + arg1, + arg2, + arg3, + arg4 ); + return KJS::Value(); // Returns void +#endif +return KJS::Object(); + +} + +KJS::Value QListViewItemImp::paintFocus_34( KJS::ExecState *exec, KJS::Object &obj, const KJS::List &args ) +{ +#if 0 + // Unsupported parameter QPainter * + return KJS::Value(); + + QPainter * arg0; // Dummy + + // Unsupported parameter const QColorGroup & + return KJS::Value(); + + const QColorGroup & arg1; // Dummy + + QRect arg2 = extractQRect(exec, args, 2); + + instance->paintFocus( + arg0, + arg1, + arg2 ); + return KJS::Value(); // Returns void +#endif +return KJS::Object(); + +} + +KJS::Value QListViewItemImp::firstChild_35( KJS::ExecState *exec, KJS::Object &obj, const KJS::List &args ) +{ + + QListViewItem *item = instance->firstChild( ); + if( item ) + { + JSOpaqueProxy *prx = new JSOpaqueProxy( item, "QListViewItem" ); + prx->setOwner( JSProxy::Native ); + KJS::Object proxyObj( prx ); + addBindings(exec,proxyObj); + return proxyObj; + } + else + return KJS::Null(); + +} + +KJS::Value QListViewItemImp::nextSibling_36( KJS::ExecState *exec, KJS::Object &obj, const KJS::List &args ) +{ + + QListViewItem *item = instance->nextSibling( ); + if( item ) + { + JSOpaqueProxy *prx = new JSOpaqueProxy( item, "QListViewItem" ); + prx->setOwner( JSProxy::Native ); + KJS::Object proxyObj( prx ); + addBindings(exec,proxyObj); + return proxyObj; + } + else + return KJS::Null(); + +} + +KJS::Value QListViewItemImp::parent_37( KJS::ExecState *exec, KJS::Object &obj, const KJS::List &args ) +{ + + QListViewItem *item = instance->parent( ); + if( item ) + { + JSOpaqueProxy *prx = new JSOpaqueProxy( item, "QListViewItem" ); + prx->setOwner( JSProxy::Native ); + KJS::Object proxyObj( prx ); + addBindings(exec,proxyObj); + return proxyObj; + } + else + return KJS::Null(); + +} + +KJS::Value QListViewItemImp::itemAbove_38( KJS::ExecState *exec, KJS::Object &obj, const KJS::List &args ) +{ + + QListViewItem *item = instance->itemAbove( ); + if( item ) + { + JSOpaqueProxy *prx = new JSOpaqueProxy( item, "QListViewItem" ); + prx->setOwner( JSProxy::Native ); + KJS::Object proxyObj( prx ); + addBindings(exec,proxyObj); + return proxyObj; + } + else + return KJS::Null(); + +} + +KJS::Value QListViewItemImp::itemBelow_39( KJS::ExecState *exec, KJS::Object &obj, const KJS::List &args ) +{ + + QListViewItem *item = instance->itemBelow( ); + if( item ) + { + JSOpaqueProxy *prx = new JSOpaqueProxy( item, "QListViewItem" ); + prx->setOwner( JSProxy::Native ); + KJS::Object proxyObj( prx ); + addBindings(exec,proxyObj); + return proxyObj; + } + else + return KJS::Null(); + +} + +KJS::Value QListViewItemImp::itemPos_40( KJS::ExecState *exec, KJS::Object &obj, const KJS::List &args ) +{ + + int ret; + ret = instance->itemPos( ); + return KJS::Number( ret ); + +} + +KJS::Value QListViewItemImp::listView_41( KJS::ExecState *exec, KJS::Object &obj, const KJS::List &args ) +{ + + instance->listView( ); + return KJS::Value(); // Returns 'QListView *' + +} + +KJS::Value QListViewItemImp::setSelectable_42( KJS::ExecState *exec, KJS::Object &obj, const KJS::List &args ) +{ + + bool arg0 = extractBool(exec, args, 0); + + instance->setSelectable( + arg0 ); + return KJS::Value(); // Returns void + +} + +KJS::Value QListViewItemImp::isSelectable_43( KJS::ExecState *exec, KJS::Object &obj, const KJS::List &args ) +{ + + bool ret; + ret = instance->isSelectable( ); + return KJS::Boolean( ret ); + +} + +KJS::Value QListViewItemImp::setExpandable_44( KJS::ExecState *exec, KJS::Object &obj, const KJS::List &args ) +{ + + bool arg0 = extractBool(exec, args, 0); + + instance->setExpandable( + arg0 ); + return KJS::Value(); // Returns void + +} + +KJS::Value QListViewItemImp::isExpandable_45( KJS::ExecState *exec, KJS::Object &obj, const KJS::List &args ) +{ + + bool ret; + ret = instance->isExpandable( ); + return KJS::Boolean( ret ); + +} + +KJS::Value QListViewItemImp::repaint_46( KJS::ExecState *exec, KJS::Object &obj, const KJS::List &args ) +{ + + instance->repaint( ); + return KJS::Value(); // Returns void + +} + +KJS::Value QListViewItemImp::sort_47( KJS::ExecState *exec, KJS::Object &obj, const KJS::List &args ) +{ + + instance->sort( ); + return KJS::Value(); // Returns void + +} + +KJS::Value QListViewItemImp::moveItem_48( KJS::ExecState *exec, KJS::Object &obj, const KJS::List &args ) +{ + + // Unsupported parameter QListViewItem * + return KJS::Value(); + + QListViewItem * arg0; // Dummy + + instance->moveItem( + arg0 ); + return KJS::Value(); // Returns void + +} + +KJS::Value QListViewItemImp::setDragEnabled_49( KJS::ExecState *exec, KJS::Object &obj, const KJS::List &args ) +{ + + bool arg0 = extractBool(exec, args, 0); + + instance->setDragEnabled( + arg0 ); + return KJS::Value(); // Returns void + +} + +KJS::Value QListViewItemImp::setDropEnabled_50( KJS::ExecState *exec, KJS::Object &obj, const KJS::List &args ) +{ + + bool arg0 = extractBool(exec, args, 0); + + instance->setDropEnabled( + arg0 ); + return KJS::Value(); // Returns void + +} + +KJS::Value QListViewItemImp::dragEnabled_51( KJS::ExecState *exec, KJS::Object &obj, const KJS::List &args ) +{ + + bool ret; + ret = instance->dragEnabled( ); + return KJS::Boolean( ret ); + +} + +KJS::Value QListViewItemImp::dropEnabled_52( KJS::ExecState *exec, KJS::Object &obj, const KJS::List &args ) +{ + + bool ret; + ret = instance->dropEnabled( ); + return KJS::Boolean( ret ); + +} + +KJS::Value QListViewItemImp::acceptDrop_53( KJS::ExecState *exec, KJS::Object &obj, const KJS::List &args ) +{ + + // Unsupported parameter const QMimeSource * + return KJS::Value(); + + const QMimeSource * arg0; // Dummy + + bool ret; + ret = instance->acceptDrop( + arg0 ); + return KJS::Boolean( ret ); + +} + +KJS::Value QListViewItemImp::setVisible_54( KJS::ExecState *exec, KJS::Object &obj, const KJS::List &args ) +{ + + bool arg0 = extractBool(exec, args, 0); + + instance->setVisible( + arg0 ); + return KJS::Value(); // Returns void + +} + +KJS::Value QListViewItemImp::isVisible_55( KJS::ExecState *exec, KJS::Object &obj, const KJS::List &args ) +{ + + bool ret; + ret = instance->isVisible( ); + return KJS::Boolean( ret ); + +} + +KJS::Value QListViewItemImp::setRenameEnabled_56( KJS::ExecState *exec, KJS::Object &obj, const KJS::List &args ) +{ + + int arg0 = extractInt(exec, args, 0); + + bool arg1 = extractBool(exec, args, 1); + + instance->setRenameEnabled( + arg0, + arg1 ); + return KJS::Value(); // Returns void + +} + +KJS::Value QListViewItemImp::renameEnabled_57( KJS::ExecState *exec, KJS::Object &obj, const KJS::List &args ) +{ + + int arg0 = extractInt(exec, args, 0); + + bool ret; + ret = instance->renameEnabled( + arg0 ); + return KJS::Boolean( ret ); + +} + +KJS::Value QListViewItemImp::startRename_58( KJS::ExecState *exec, KJS::Object &obj, const KJS::List &args ) +{ + + int arg0 = extractInt(exec, args, 0); + + instance->startRename( + arg0 ); + return KJS::Value(); // Returns void + +} + +KJS::Value QListViewItemImp::setEnabled_59( KJS::ExecState *exec, KJS::Object &obj, const KJS::List &args ) +{ + + bool arg0 = extractBool(exec, args, 0); + + instance->setEnabled( + arg0 ); + return KJS::Value(); // Returns void + +} + +KJS::Value QListViewItemImp::isEnabled_60( KJS::ExecState *exec, KJS::Object &obj, const KJS::List &args ) +{ + + bool ret; + ret = instance->isEnabled( ); + return KJS::Boolean( ret ); + +} + +KJS::Value QListViewItemImp::rtti_61( KJS::ExecState *exec, KJS::Object &obj, const KJS::List &args ) +{ + + int ret; + ret = instance->rtti( ); + return KJS::Number( ret ); + +} + +KJS::Value QListViewItemImp::setMultiLinesEnabled_62( KJS::ExecState *exec, KJS::Object &obj, const KJS::List &args ) +{ + + bool arg0 = extractBool(exec, args, 0); + + instance->setMultiLinesEnabled( + arg0 ); + return KJS::Value(); // Returns void + +} + +KJS::Value QListViewItemImp::multiLinesEnabled_63( KJS::ExecState *exec, KJS::Object &obj, const KJS::List &args ) +{ + + bool ret; + ret = instance->multiLinesEnabled( ); + return KJS::Boolean( ret ); + +} + + +} // namespace KJSEmbed + +// Local Variables: +// c-basic-offset: 4 +// End: + + diff --git a/kjsembed/qtbindings/qlistviewitem_imp.h b/kjsembed/qtbindings/qlistviewitem_imp.h new file mode 100644 index 00000000..590cde36 --- /dev/null +++ b/kjsembed/qtbindings/qlistviewitem_imp.h @@ -0,0 +1,229 @@ + + + +#ifndef KJSEMBED_QListViewItem_H +#define KJSEMBED_QListViewItem_H + +#include <kjs/interpreter.h> +#include <kjs/object.h> + +#include <kjsembed/jsobjectproxy_imp.h> +#include <kjsembed/jsbindingbase.h> + +class QListViewItem; + +/** + * Namespace containing the KJSEmbed library. + */ +namespace KJSEmbed { +namespace Bindings { + + class QListViewItemLoader : public JSBindingBase + { + public: + KJS::Object createBinding(KJSEmbedPart *jspart, KJS::ExecState *exec, const KJS::List &args) const; + void addBindings( KJSEmbedPart *jspart, KJS::ExecState *exec, KJS::Object &proxy) const; + }; +} +/** + * Wrapper class for QListViewItem methods. + * + * @author Richard Moore, rich@kde.org + */ +class QListViewItemImp : public JSProxyImp +{ +public: + /** Enumerates the constructors supported by this class. */ + enum Constructors { + Constructor_QListViewItem_1, + Constructor_QListViewItem_2, + Constructor_QListViewItem_3, + Constructor_QListViewItem_4, + Constructor_QListViewItem_5, + Constructor_QListViewItem_6, + Constructor_QListViewItem_7, + Constructor_QListViewItem_8, + + LastConstuctor = -1 + }; + + /** Enumerates the methods supported by this class. */ + enum Methods { + + Method_insertItem_10, + Method_takeItem_11, + Method_removeItem_12, + Method_height_13, + Method_invalidateHeight_14, + Method_totalHeight_15, + Method_width_16, + Method_widthChanged_17, + Method_depth_18, + Method_setText_19, + Method_text_20, + Method_setPixmap_21, + Method_pixmap_22, + Method_key_23, + Method_compare_24, + Method_sortChildItems_25, + Method_childCount_26, + Method_isOpen_27, + Method_setOpen_28, + Method_setup_29, + Method_setSelected_30, + Method_isSelected_31, + Method_paintCell_32, + Method_paintBranches_33, + Method_paintFocus_34, + Method_firstChild_35, + Method_nextSibling_36, + Method_parent_37, + Method_itemAbove_38, + Method_itemBelow_39, + Method_itemPos_40, + Method_listView_41, + Method_setSelectable_42, + Method_isSelectable_43, + Method_setExpandable_44, + Method_isExpandable_45, + Method_repaint_46, + Method_sort_47, + Method_moveItem_48, + Method_setDragEnabled_49, + Method_setDropEnabled_50, + Method_dragEnabled_51, + Method_dropEnabled_52, + Method_acceptDrop_53, + Method_setVisible_54, + Method_isVisible_55, + Method_setRenameEnabled_56, + Method_renameEnabled_57, + Method_startRename_58, + Method_setEnabled_59, + Method_isEnabled_60, + Method_rtti_61, + Method_setMultiLinesEnabled_62, + Method_multiLinesEnabled_63, + Method_Last = -1 + }; + + QListViewItemImp( KJS::ExecState *exec, int id, bool constructor=false ); + ~QListViewItemImp(); + + /** + * Adds the static bindings for this class to the specified Object. The + * static bindings are the static methods and the enums of this class. + */ + static void addStaticBindings( KJS::ExecState *exec, KJS::Object &object ); + + /** + * Adds the bindings for this class to the specified Object. The bindings + * added are the instance methods of this class. + */ + static void addBindings( KJS::ExecState *exec, KJS::Object &object ); + + static QListViewItem *toQListViewItem( KJS::Object &object ); + + // + // Constructors implemented by this class. + // + + KJS::Object QListViewItem_1( KJS::ExecState *exec, const KJS::List &args ); + KJS::Object QListViewItem_2( KJS::ExecState *exec, const KJS::List &args ); + KJS::Object QListViewItem_3( KJS::ExecState *exec, const KJS::List &args ); + KJS::Object QListViewItem_4( KJS::ExecState *exec, const KJS::List &args ); + KJS::Object QListViewItem_5( KJS::ExecState *exec, const KJS::List &args ); + KJS::Object QListViewItem_6( KJS::ExecState *exec, const KJS::List &args ); + KJS::Object QListViewItem_7( KJS::ExecState *exec, const KJS::List &args ); + KJS::Object QListViewItem_8( KJS::ExecState *exec, const KJS::List &args ); + + // + // Methods implemented by this class. + // + + KJS::Value insertItem_10( KJS::ExecState *exec, KJS::Object &obj, const KJS::List &args ); + KJS::Value takeItem_11( KJS::ExecState *exec, KJS::Object &obj, const KJS::List &args ); + KJS::Value removeItem_12( KJS::ExecState *exec, KJS::Object &obj, const KJS::List &args ); + KJS::Value height_13( KJS::ExecState *exec, KJS::Object &obj, const KJS::List &args ); + KJS::Value invalidateHeight_14( KJS::ExecState *exec, KJS::Object &obj, const KJS::List &args ); + KJS::Value totalHeight_15( KJS::ExecState *exec, KJS::Object &obj, const KJS::List &args ); + KJS::Value width_16( KJS::ExecState *exec, KJS::Object &obj, const KJS::List &args ); + KJS::Value widthChanged_17( KJS::ExecState *exec, KJS::Object &obj, const KJS::List &args ); + KJS::Value depth_18( KJS::ExecState *exec, KJS::Object &obj, const KJS::List &args ); + KJS::Value setText_19( KJS::ExecState *exec, KJS::Object &obj, const KJS::List &args ); + KJS::Value text_20( KJS::ExecState *exec, KJS::Object &obj, const KJS::List &args ); + KJS::Value setPixmap_21( KJS::ExecState *exec, KJS::Object &obj, const KJS::List &args ); + KJS::Value pixmap_22( KJS::ExecState *exec, KJS::Object &obj, const KJS::List &args ); + KJS::Value key_23( KJS::ExecState *exec, KJS::Object &obj, const KJS::List &args ); + KJS::Value compare_24( KJS::ExecState *exec, KJS::Object &obj, const KJS::List &args ); + KJS::Value sortChildItems_25( KJS::ExecState *exec, KJS::Object &obj, const KJS::List &args ); + KJS::Value childCount_26( KJS::ExecState *exec, KJS::Object &obj, const KJS::List &args ); + KJS::Value isOpen_27( KJS::ExecState *exec, KJS::Object &obj, const KJS::List &args ); + KJS::Value setOpen_28( KJS::ExecState *exec, KJS::Object &obj, const KJS::List &args ); + KJS::Value setup_29( KJS::ExecState *exec, KJS::Object &obj, const KJS::List &args ); + KJS::Value setSelected_30( KJS::ExecState *exec, KJS::Object &obj, const KJS::List &args ); + KJS::Value isSelected_31( KJS::ExecState *exec, KJS::Object &obj, const KJS::List &args ); + KJS::Value paintCell_32( KJS::ExecState *exec, KJS::Object &obj, const KJS::List &args ); + KJS::Value paintBranches_33( KJS::ExecState *exec, KJS::Object &obj, const KJS::List &args ); + KJS::Value paintFocus_34( KJS::ExecState *exec, KJS::Object &obj, const KJS::List &args ); + KJS::Value firstChild_35( KJS::ExecState *exec, KJS::Object &obj, const KJS::List &args ); + KJS::Value nextSibling_36( KJS::ExecState *exec, KJS::Object &obj, const KJS::List &args ); + KJS::Value parent_37( KJS::ExecState *exec, KJS::Object &obj, const KJS::List &args ); + KJS::Value itemAbove_38( KJS::ExecState *exec, KJS::Object &obj, const KJS::List &args ); + KJS::Value itemBelow_39( KJS::ExecState *exec, KJS::Object &obj, const KJS::List &args ); + KJS::Value itemPos_40( KJS::ExecState *exec, KJS::Object &obj, const KJS::List &args ); + KJS::Value listView_41( KJS::ExecState *exec, KJS::Object &obj, const KJS::List &args ); + KJS::Value setSelectable_42( KJS::ExecState *exec, KJS::Object &obj, const KJS::List &args ); + KJS::Value isSelectable_43( KJS::ExecState *exec, KJS::Object &obj, const KJS::List &args ); + KJS::Value setExpandable_44( KJS::ExecState *exec, KJS::Object &obj, const KJS::List &args ); + KJS::Value isExpandable_45( KJS::ExecState *exec, KJS::Object &obj, const KJS::List &args ); + KJS::Value repaint_46( KJS::ExecState *exec, KJS::Object &obj, const KJS::List &args ); + KJS::Value sort_47( KJS::ExecState *exec, KJS::Object &obj, const KJS::List &args ); + KJS::Value moveItem_48( KJS::ExecState *exec, KJS::Object &obj, const KJS::List &args ); + KJS::Value setDragEnabled_49( KJS::ExecState *exec, KJS::Object &obj, const KJS::List &args ); + KJS::Value setDropEnabled_50( KJS::ExecState *exec, KJS::Object &obj, const KJS::List &args ); + KJS::Value dragEnabled_51( KJS::ExecState *exec, KJS::Object &obj, const KJS::List &args ); + KJS::Value dropEnabled_52( KJS::ExecState *exec, KJS::Object &obj, const KJS::List &args ); + KJS::Value acceptDrop_53( KJS::ExecState *exec, KJS::Object &obj, const KJS::List &args ); + KJS::Value setVisible_54( KJS::ExecState *exec, KJS::Object &obj, const KJS::List &args ); + KJS::Value isVisible_55( KJS::ExecState *exec, KJS::Object &obj, const KJS::List &args ); + KJS::Value setRenameEnabled_56( KJS::ExecState *exec, KJS::Object &obj, const KJS::List &args ); + KJS::Value renameEnabled_57( KJS::ExecState *exec, KJS::Object &obj, const KJS::List &args ); + KJS::Value startRename_58( KJS::ExecState *exec, KJS::Object &obj, const KJS::List &args ); + KJS::Value setEnabled_59( KJS::ExecState *exec, KJS::Object &obj, const KJS::List &args ); + KJS::Value isEnabled_60( KJS::ExecState *exec, KJS::Object &obj, const KJS::List &args ); + KJS::Value rtti_61( KJS::ExecState *exec, KJS::Object &obj, const KJS::List &args ); + KJS::Value setMultiLinesEnabled_62( KJS::ExecState *exec, KJS::Object &obj, const KJS::List &args ); + KJS::Value multiLinesEnabled_63( KJS::ExecState *exec, KJS::Object &obj, const KJS::List &args ); + + // + // JS binding code. + // + + /** Returns true iff this object implements the construct function. */ + virtual bool implementsConstruct() const { return cons; } + + /** Invokes the construct function. */ + virtual KJS::Object construct( KJS::ExecState *exec, const KJS::List &args ); + + /** Returns true iff this object implements the call function. */ + virtual bool implementsCall() const { return !cons; } + + /** Invokes the call function. */ + virtual KJS::Value call( KJS::ExecState *exec, KJS::Object &self, const KJS::List &args ); + +private: + QListViewItem *instance; // Temp + int id; + bool cons; +}; + +} // namespace KJSEmbed + +#endif // KJSEMBED_QListViewItem_H + +// Local Variables: +// c-basic-offset: 4 +// End: + + diff --git a/kjsembed/qtbindings/qmenudata_imp.cpp b/kjsembed/qtbindings/qmenudata_imp.cpp new file mode 100644 index 00000000..aecd1808 --- /dev/null +++ b/kjsembed/qtbindings/qmenudata_imp.cpp @@ -0,0 +1,1351 @@ + + + +#include <qcstring.h> +#include <qimage.h> +#include <qpainter.h> +#include <qpalette.h> +#include <qpixmap.h> +#include <qfont.h> +#include <qkeysequence.h> +#include <kjs/object.h> + +#include <kjsembed/global.h> +#include <kjsembed/jsobjectproxy.h> +#include <kjsembed/jsopaqueproxy.h> +#include <kjsembed/jsbinding.h> + +#include <qmenudata.h> +#include "qmenudata_imp.h" + +/** + * Namespace containing the KJSEmbed library. + */ +namespace KJSEmbed { + +QMenuDataImp::QMenuDataImp( KJS::ExecState *exec, int mid, bool constructor ) + : JSProxyImp(exec), id(mid), cons(constructor) +{ +} + +QMenuDataImp::~QMenuDataImp() +{ +} + +/** + * Adds bindings for static methods and enum constants to the specified Object. + */ +void QMenuDataImp::addStaticBindings( KJS::ExecState *exec, KJS::Object &object ) +{ + JSProxy::MethodTable methods[] = { + + { 0, 0 } + }; + + int idx = 0; + QCString lastName; + + while( methods[idx].name ) { + if ( lastName != methods[idx].name ) { + QMenuDataImp *meth = new QMenuDataImp( exec, methods[idx].id ); + object.put( exec , methods[idx].name, KJS::Object(meth) ); + lastName = methods[idx].name; + } + ++idx; + } + + +} + +/** + * Adds bindings for instance methods to the specified Object. + */ +void QMenuDataImp::addBindings( KJS::ExecState *exec, KJS::Object &object ) +{ + JSProxy::MethodTable methods[] = { + + { Method_count_3, "count" }, + { Method_insertItem_4, "insertItem" }, + { Method_insertItem_5, "insertItem" }, + { Method_insertItem_6, "insertItem" }, + { Method_insertItem_7, "insertItem" }, + { Method_insertItem_8, "insertItem" }, + { Method_insertItem_9, "insertItem" }, + { Method_insertItem_10, "insertItem" }, + { Method_insertItem_11, "insertItem" }, + { Method_insertItem_12, "insertItem" }, + { Method_insertItem_13, "insertItem" }, + { Method_insertItem_14, "insertItem" }, + { Method_insertItem_15, "insertItem" }, + { Method_insertItem_16, "insertItem" }, + { Method_insertItem_17, "insertItem" }, + { Method_insertItem_18, "insertItem" }, + { Method_insertSeparator_19, "insertSeparator" }, + { Method_removeItem_20, "removeItem" }, + { Method_removeItemAt_21, "removeItemAt" }, + { Method_clear_22, "clear" }, + { Method_accel_23, "accel" }, + { Method_setAccel_24, "setAccel" }, + { Method_iconSet_25, "iconSet" }, + { Method_text_26, "text" }, + { Method_pixmap_27, "pixmap" }, + { Method_setWhatsThis_28, "setWhatsThis" }, + { Method_whatsThis_29, "whatsThis" }, + { Method_changeItem_30, "changeItem" }, + { Method_changeItem_31, "changeItem" }, + { Method_changeItem_32, "changeItem" }, + { Method_changeItem_33, "changeItem" }, + { Method_changeItem_34, "changeItem" }, + { Method_changeItem_35, "changeItem" }, + { Method_changeItem_36, "changeItem" }, + { Method_isItemActive_37, "isItemActive" }, + { Method_isItemEnabled_38, "isItemEnabled" }, + { Method_setItemEnabled_39, "setItemEnabled" }, + { Method_isItemChecked_40, "isItemChecked" }, + { Method_setItemChecked_41, "setItemChecked" }, + { Method_isItemVisible_42, "isItemVisible" }, + { Method_setItemVisible_43, "setItemVisible" }, + { Method_updateItem_44, "updateItem" }, + { Method_indexOf_45, "indexOf" }, + { Method_idAt_46, "idAt" }, + { Method_setId_47, "setId" }, + { Method_connectItem_48, "connectItem" }, + { Method_disconnectItem_49, "disconnectItem" }, + { Method_setItemParameter_50, "setItemParameter" }, + { Method_itemParameter_51, "itemParameter" }, + { Method_findItem_52, "findItem" }, + { Method_findItem_53, "findItem" }, + { Method_findPopup_54, "findPopup" }, + { Method_activateItemAt_55, "activateItemAt" }, + { 0, 0 } + }; + + int idx = 0; + QCString lastName; + + while( methods[idx].name ) { + if ( lastName != methods[idx].name ) { + QMenuDataImp *meth = new QMenuDataImp( exec, methods[idx].id ); + object.put( exec , methods[idx].name, KJS::Object(meth) ); + lastName = methods[idx].name; + } + ++idx; + } +} + +/** + * Extract a QMenuData pointer from an Object. + */ +QMenuData *QMenuDataImp::toQMenuData( KJS::Object &self ) +{ + JSObjectProxy *ob = JSProxy::toObjectProxy( self.imp() ); + if ( ob ) { + QObject *obj = ob->object(); + if ( obj ) + return dynamic_cast<QMenuData *>( obj ); + } + + JSOpaqueProxy *op = JSProxy::toOpaqueProxy( self.imp() ); + if ( !op ) + return 0; + + if ( op->typeName() != "QMenuData" ) + return 0; + + return op->toNative<QMenuData>(); +} + +/** + * Select and invoke the correct constructor. + */ +KJS::Object QMenuDataImp::construct( KJS::ExecState *exec, const KJS::List &args ) +{ + switch( id ) { + + case Constructor_QMenuData_1: + return QMenuData_1( exec, args ); + break; + + default: + break; + } + + QString msg = i18n("QMenuDataCons has no constructor with id '%1'").arg(id); + return throwError(exec, msg,KJS::ReferenceError); +} + + +KJS::Object QMenuDataImp::QMenuData_1( KJS::ExecState *exec, const KJS::List &args ) +{ + + + // We should now create an instance of the QMenuData object + + QMenuData *ret = new QMenuData( + ); + + return KJS::Object(); +} + +KJS::Value QMenuDataImp::call( KJS::ExecState *exec, KJS::Object &self, const KJS::List &args ) +{ + instance = QMenuDataImp::toQMenuData( self ); + + switch( id ) { + + case Method_count_3: + return count_3( exec, self, args ); + break; + + case Method_insertItem_4: + return insertItem_4( exec, self, args ); + break; + + case Method_insertItem_5: + return insertItem_5( exec, self, args ); + break; + + case Method_insertItem_6: + return insertItem_6( exec, self, args ); + break; + + case Method_insertItem_7: + return insertItem_7( exec, self, args ); + break; + + case Method_insertItem_8: + return insertItem_8( exec, self, args ); + break; + + case Method_insertItem_9: + return insertItem_9( exec, self, args ); + break; + + case Method_insertItem_10: + return insertItem_10( exec, self, args ); + break; + + case Method_insertItem_11: + return insertItem_11( exec, self, args ); + break; + + case Method_insertItem_12: + return insertItem_12( exec, self, args ); + break; + + case Method_insertItem_13: + return insertItem_13( exec, self, args ); + break; + + case Method_insertItem_14: + return insertItem_14( exec, self, args ); + break; + + case Method_insertItem_15: + return insertItem_15( exec, self, args ); + break; + + case Method_insertItem_16: + return insertItem_16( exec, self, args ); + break; + + case Method_insertItem_17: + return insertItem_17( exec, self, args ); + break; + + case Method_insertItem_18: + return insertItem_18( exec, self, args ); + break; + + case Method_insertSeparator_19: + return insertSeparator_19( exec, self, args ); + break; + + case Method_removeItem_20: + return removeItem_20( exec, self, args ); + break; + + case Method_removeItemAt_21: + return removeItemAt_21( exec, self, args ); + break; + + case Method_clear_22: + return clear_22( exec, self, args ); + break; + + case Method_accel_23: + return accel_23( exec, self, args ); + break; + + case Method_setAccel_24: + return setAccel_24( exec, self, args ); + break; + + case Method_iconSet_25: + return iconSet_25( exec, self, args ); + break; + + case Method_text_26: + return text_26( exec, self, args ); + break; + + case Method_pixmap_27: + return pixmap_27( exec, self, args ); + break; + + case Method_setWhatsThis_28: + return setWhatsThis_28( exec, self, args ); + break; + + case Method_whatsThis_29: + return whatsThis_29( exec, self, args ); + break; + + case Method_changeItem_30: + return changeItem_30( exec, self, args ); + break; + + case Method_changeItem_31: + return changeItem_31( exec, self, args ); + break; + + case Method_changeItem_32: + return changeItem_32( exec, self, args ); + break; + + case Method_changeItem_33: + return changeItem_33( exec, self, args ); + break; + + case Method_changeItem_34: + return changeItem_34( exec, self, args ); + break; + + case Method_changeItem_35: + return changeItem_35( exec, self, args ); + break; + + case Method_changeItem_36: + return changeItem_36( exec, self, args ); + break; + + case Method_isItemActive_37: + return isItemActive_37( exec, self, args ); + break; + + case Method_isItemEnabled_38: + return isItemEnabled_38( exec, self, args ); + break; + + case Method_setItemEnabled_39: + return setItemEnabled_39( exec, self, args ); + break; + + case Method_isItemChecked_40: + return isItemChecked_40( exec, self, args ); + break; + + case Method_setItemChecked_41: + return setItemChecked_41( exec, self, args ); + break; + + case Method_isItemVisible_42: + return isItemVisible_42( exec, self, args ); + break; + + case Method_setItemVisible_43: + return setItemVisible_43( exec, self, args ); + break; + + case Method_updateItem_44: + return updateItem_44( exec, self, args ); + break; + + case Method_indexOf_45: + return indexOf_45( exec, self, args ); + break; + + case Method_idAt_46: + return idAt_46( exec, self, args ); + break; + + case Method_setId_47: + return setId_47( exec, self, args ); + break; + + case Method_connectItem_48: + return connectItem_48( exec, self, args ); + break; + + case Method_disconnectItem_49: + return disconnectItem_49( exec, self, args ); + break; + + case Method_setItemParameter_50: + return setItemParameter_50( exec, self, args ); + break; + + case Method_itemParameter_51: + return itemParameter_51( exec, self, args ); + break; + + case Method_findItem_52: + return findItem_52( exec, self, args ); + break; + + case Method_findItem_53: + return findItem_53( exec, self, args ); + break; + + case Method_findPopup_54: + return findPopup_54( exec, self, args ); + break; + + case Method_activateItemAt_55: + return activateItemAt_55( exec, self, args ); + break; + + default: + break; + } + + QString msg = i18n( "QMenuDataImp has no method with id '%1'" ).arg( id ); + return throwError(exec, msg,KJS::ReferenceError); +} + + +KJS::Value QMenuDataImp::count_3( KJS::ExecState *exec, KJS::Object &obj, const KJS::List &args ) +{ + + uint ret; + ret = instance->count( ); + return KJS::Number( ret ); + +} + +KJS::Value QMenuDataImp::insertItem_4( KJS::ExecState *exec, KJS::Object &obj, const KJS::List &args ) +{ + + QString arg0 = extractQString(exec, args, 0); + + // Unsupported parameter const QObject * + return KJS::Value(); + + const QObject * arg1; // Dummy + + const char *arg2 = (args.size() >= 3) ? args[2].toString(exec).ascii() : 0; + + // Unsupported parameter const QKeySequence + return KJS::Value(); + + const QKeySequence arg3; // Dummy + + int arg4 = extractInt(exec, args, 4); + + int arg5 = extractInt(exec, args, 5); + + int ret; + ret = instance->insertItem( + arg0, + arg1, + arg2, + arg3, + arg4, + arg5 ); + return KJS::Number( ret ); + +} + +KJS::Value QMenuDataImp::insertItem_5( KJS::ExecState *exec, KJS::Object &obj, const KJS::List &args ) +{ + + // Unsupported parameter const QIconSet + return KJS::Value(); + + const QIconSet arg0; // Dummy + + QString arg1 = extractQString(exec, args, 1); + + // Unsupported parameter const QObject * + return KJS::Value(); + + const QObject * arg2; // Dummy + + const char *arg3 = (args.size() >= 4) ? args[3].toString(exec).ascii() : 0; + + // Unsupported parameter const QKeySequence + return KJS::Value(); + + const QKeySequence arg4; // Dummy + + int arg5 = extractInt(exec, args, 5); + + int arg6 = extractInt(exec, args, 6); + + int ret; + ret = instance->insertItem( + arg0, + arg1, + arg2, + arg3, + arg4, + arg5, + arg6 ); + return KJS::Number( ret ); + +} + +KJS::Value QMenuDataImp::insertItem_6( KJS::ExecState *exec, KJS::Object &obj, const KJS::List &args ) +{ + + QPixmap arg0 = extractQPixmap(exec, args, 0); + + // Unsupported parameter const QObject * + return KJS::Value(); + + const QObject * arg1; // Dummy + + const char *arg2 = (args.size() >= 3) ? args[2].toString(exec).ascii() : 0; + + // Unsupported parameter const QKeySequence + return KJS::Value(); + + const QKeySequence arg3; // Dummy + + int arg4 = extractInt(exec, args, 4); + + int arg5 = extractInt(exec, args, 5); + + int ret; + ret = instance->insertItem( + arg0, + arg1, + arg2, + arg3, + arg4, + arg5 ); + return KJS::Number( ret ); + +} + +KJS::Value QMenuDataImp::insertItem_7( KJS::ExecState *exec, KJS::Object &obj, const KJS::List &args ) +{ + + // Unsupported parameter const QIconSet + return KJS::Value(); + + const QIconSet arg0; // Dummy + + QPixmap arg1 = extractQPixmap(exec, args, 1); + + // Unsupported parameter const QObject * + return KJS::Value(); + + const QObject * arg2; // Dummy + + const char *arg3 = (args.size() >= 4) ? args[3].toString(exec).ascii() : 0; + + // Unsupported parameter const QKeySequence + return KJS::Value(); + + const QKeySequence arg4; // Dummy + + int arg5 = extractInt(exec, args, 5); + + int arg6 = extractInt(exec, args, 6); + + int ret; + ret = instance->insertItem( + arg0, + arg1, + arg2, + arg3, + arg4, + arg5, + arg6 ); + return KJS::Number( ret ); + +} + +KJS::Value QMenuDataImp::insertItem_8( KJS::ExecState *exec, KJS::Object &obj, const KJS::List &args ) +{ + + QString arg0 = extractQString(exec, args, 0); + + int arg1 = extractInt(exec, args, 1); + + int arg2 = extractInt(exec, args, 2); + + int ret; + ret = instance->insertItem( + arg0, + arg1, + arg2 ); + return KJS::Number( ret ); + +} + +KJS::Value QMenuDataImp::insertItem_9( KJS::ExecState *exec, KJS::Object &obj, const KJS::List &args ) +{ + + // Unsupported parameter const QIconSet + return KJS::Value(); + + const QIconSet arg0; // Dummy + + QString arg1 = extractQString(exec, args, 1); + + int arg2 = extractInt(exec, args, 2); + + int arg3 = extractInt(exec, args, 3); + + int ret; + ret = instance->insertItem( + arg0, + arg1, + arg2, + arg3 ); + return KJS::Number( ret ); + +} + +KJS::Value QMenuDataImp::insertItem_10( KJS::ExecState *exec, KJS::Object &obj, const KJS::List &args ) +{ + + QString arg0 = extractQString(exec, args, 0); + + // Unsupported parameter QPopupMenu * + return KJS::Value(); + + QPopupMenu * arg1; // Dummy + + int arg2 = extractInt(exec, args, 2); + + int arg3 = extractInt(exec, args, 3); + + int ret; + ret = instance->insertItem( + arg0, + arg1, + arg2, + arg3 ); + return KJS::Number( ret ); + +} + +KJS::Value QMenuDataImp::insertItem_11( KJS::ExecState *exec, KJS::Object &obj, const KJS::List &args ) +{ + + // Unsupported parameter const QIconSet + return KJS::Value(); + + const QIconSet arg0; // Dummy + + QString arg1 = extractQString(exec, args, 1); + + // Unsupported parameter QPopupMenu * + return KJS::Value(); + + QPopupMenu * arg2; // Dummy + + int arg3 = extractInt(exec, args, 3); + + int arg4 = extractInt(exec, args, 4); + + int ret; + ret = instance->insertItem( + arg0, + arg1, + arg2, + arg3, + arg4 ); + return KJS::Number( ret ); + +} + +KJS::Value QMenuDataImp::insertItem_12( KJS::ExecState *exec, KJS::Object &obj, const KJS::List &args ) +{ + + QPixmap arg0 = extractQPixmap(exec, args, 0); + + int arg1 = extractInt(exec, args, 1); + + int arg2 = extractInt(exec, args, 2); + + int ret; + ret = instance->insertItem( + arg0, + arg1, + arg2 ); + return KJS::Number( ret ); + +} + +KJS::Value QMenuDataImp::insertItem_13( KJS::ExecState *exec, KJS::Object &obj, const KJS::List &args ) +{ + + // Unsupported parameter const QIconSet + return KJS::Value(); + + const QIconSet arg0; // Dummy + + QPixmap arg1 = extractQPixmap(exec, args, 1); + + int arg2 = extractInt(exec, args, 2); + + int arg3 = extractInt(exec, args, 3); + + int ret; + ret = instance->insertItem( + arg0, + arg1, + arg2, + arg3 ); + return KJS::Number( ret ); + +} + +KJS::Value QMenuDataImp::insertItem_14( KJS::ExecState *exec, KJS::Object &obj, const KJS::List &args ) +{ + + QPixmap arg0 = extractQPixmap(exec, args, 0); + + // Unsupported parameter QPopupMenu * + return KJS::Value(); + + QPopupMenu * arg1; // Dummy + + int arg2 = extractInt(exec, args, 2); + + int arg3 = extractInt(exec, args, 3); + + int ret; + ret = instance->insertItem( + arg0, + arg1, + arg2, + arg3 ); + return KJS::Number( ret ); + +} + +KJS::Value QMenuDataImp::insertItem_15( KJS::ExecState *exec, KJS::Object &obj, const KJS::List &args ) +{ + + // Unsupported parameter const QIconSet + return KJS::Value(); + + const QIconSet arg0; // Dummy + + QPixmap arg1 = extractQPixmap(exec, args, 1); + + // Unsupported parameter QPopupMenu * + return KJS::Value(); + + QPopupMenu * arg2; // Dummy + + int arg3 = extractInt(exec, args, 3); + + int arg4 = extractInt(exec, args, 4); + + int ret; + ret = instance->insertItem( + arg0, + arg1, + arg2, + arg3, + arg4 ); + return KJS::Number( ret ); + +} + +KJS::Value QMenuDataImp::insertItem_16( KJS::ExecState *exec, KJS::Object &obj, const KJS::List &args ) +{ + + // Unsupported parameter QWidget * + return KJS::Value(); + + QWidget * arg0; // Dummy + + int arg1 = extractInt(exec, args, 1); + + int arg2 = extractInt(exec, args, 2); + + int ret; + ret = instance->insertItem( + arg0, + arg1, + arg2 ); + return KJS::Number( ret ); + +} + +KJS::Value QMenuDataImp::insertItem_17( KJS::ExecState *exec, KJS::Object &obj, const KJS::List &args ) +{ + + // Unsupported parameter const QIconSet + return KJS::Value(); + + const QIconSet arg0; // Dummy + + // Unsupported parameter QCustomMenuItem * + return KJS::Value(); + + QCustomMenuItem * arg1; // Dummy + + int arg2 = extractInt(exec, args, 2); + + int arg3 = extractInt(exec, args, 3); + + int ret; + ret = instance->insertItem( + arg0, + arg1, + arg2, + arg3 ); + return KJS::Number( ret ); + +} + +KJS::Value QMenuDataImp::insertItem_18( KJS::ExecState *exec, KJS::Object &obj, const KJS::List &args ) +{ + + // Unsupported parameter QCustomMenuItem * + return KJS::Value(); + + QCustomMenuItem * arg0; // Dummy + + int arg1 = extractInt(exec, args, 1); + + int arg2 = extractInt(exec, args, 2); + + int ret; + ret = instance->insertItem( + arg0, + arg1, + arg2 ); + return KJS::Number( ret ); + +} + +KJS::Value QMenuDataImp::insertSeparator_19( KJS::ExecState *exec, KJS::Object &obj, const KJS::List &args ) +{ + + int arg0 = extractInt(exec, args, 0); + + int ret; + ret = instance->insertSeparator( + arg0 ); + return KJS::Number( ret ); + +} + +KJS::Value QMenuDataImp::removeItem_20( KJS::ExecState *exec, KJS::Object &obj, const KJS::List &args ) +{ + + int arg0 = extractInt(exec, args, 0); + + instance->removeItem( + arg0 ); + return KJS::Value(); // Returns void + +} + +KJS::Value QMenuDataImp::removeItemAt_21( KJS::ExecState *exec, KJS::Object &obj, const KJS::List &args ) +{ + + int arg0 = extractInt(exec, args, 0); + + instance->removeItemAt( + arg0 ); + return KJS::Value(); // Returns void + +} + +KJS::Value QMenuDataImp::clear_22( KJS::ExecState *exec, KJS::Object &obj, const KJS::List &args ) +{ + + instance->clear( ); + return KJS::Value(); // Returns void + +} + +KJS::Value QMenuDataImp::accel_23( KJS::ExecState *exec, KJS::Object &obj, const KJS::List &args ) +{ + + int arg0 = extractInt(exec, args, 0); + + instance->accel( + arg0 ); + return KJS::Value(); // Returns 'QKeySequence' + +} + +KJS::Value QMenuDataImp::setAccel_24( KJS::ExecState *exec, KJS::Object &obj, const KJS::List &args ) +{ + + // Unsupported parameter const QKeySequence + return KJS::Value(); + + const QKeySequence arg0; // Dummy + + int arg1 = extractInt(exec, args, 1); + + instance->setAccel( + arg0, + arg1 ); + return KJS::Value(); // Returns void + +} + +KJS::Value QMenuDataImp::iconSet_25( KJS::ExecState *exec, KJS::Object &obj, const KJS::List &args ) +{ + + int arg0 = extractInt(exec, args, 0); + + instance->iconSet( + arg0 ); + return KJS::Value(); // Returns 'QIconSet *' + +} + +KJS::Value QMenuDataImp::text_26( KJS::ExecState *exec, KJS::Object &obj, const KJS::List &args ) +{ + + int arg0 = extractInt(exec, args, 0); + + QString ret; + ret = instance->text( + arg0 ); + return KJS::String( ret ); + +} + +KJS::Value QMenuDataImp::pixmap_27( KJS::ExecState *exec, KJS::Object &obj, const KJS::List &args ) +{ + + int arg0 = extractInt(exec, args, 0); + + instance->pixmap( + arg0 ); + return KJS::Value(); // Returns 'QPixmap *' + +} + +KJS::Value QMenuDataImp::setWhatsThis_28( KJS::ExecState *exec, KJS::Object &obj, const KJS::List &args ) +{ + + int arg0 = extractInt(exec, args, 0); + + QString arg1 = extractQString(exec, args, 1); + + instance->setWhatsThis( + arg0, + arg1 ); + return KJS::Value(); // Returns void + +} + +KJS::Value QMenuDataImp::whatsThis_29( KJS::ExecState *exec, KJS::Object &obj, const KJS::List &args ) +{ + + int arg0 = extractInt(exec, args, 0); + + QString ret; + ret = instance->whatsThis( + arg0 ); + return KJS::String( ret ); + +} + +KJS::Value QMenuDataImp::changeItem_30( KJS::ExecState *exec, KJS::Object &obj, const KJS::List &args ) +{ + + int arg0 = extractInt(exec, args, 0); + + QString arg1 = extractQString(exec, args, 1); + + instance->changeItem( + arg0, + arg1 ); + return KJS::Value(); // Returns void + +} + +KJS::Value QMenuDataImp::changeItem_31( KJS::ExecState *exec, KJS::Object &obj, const KJS::List &args ) +{ + + int arg0 = extractInt(exec, args, 0); + + QPixmap arg1 = extractQPixmap(exec, args, 1); + + instance->changeItem( + arg0, + arg1 ); + return KJS::Value(); // Returns void + +} + +KJS::Value QMenuDataImp::changeItem_32( KJS::ExecState *exec, KJS::Object &obj, const KJS::List &args ) +{ + + int arg0 = extractInt(exec, args, 0); + + // Unsupported parameter const QIconSet + return KJS::Value(); + + const QIconSet arg1; // Dummy + + QString arg2 = extractQString(exec, args, 2); + + instance->changeItem( + arg0, + arg1, + arg2 ); + return KJS::Value(); // Returns void + +} + +KJS::Value QMenuDataImp::changeItem_33( KJS::ExecState *exec, KJS::Object &obj, const KJS::List &args ) +{ + + int arg0 = extractInt(exec, args, 0); + + // Unsupported parameter const QIconSet + return KJS::Value(); + + const QIconSet arg1; // Dummy + + QPixmap arg2 = extractQPixmap(exec, args, 2); + + instance->changeItem( + arg0, + arg1, + arg2 ); + return KJS::Value(); // Returns void + +} + +KJS::Value QMenuDataImp::changeItem_34( KJS::ExecState *exec, KJS::Object &obj, const KJS::List &args ) +{ + + QString arg0 = extractQString(exec, args, 0); + + int arg1 = extractInt(exec, args, 1); + + instance->changeItem( + arg0, + arg1 ); + return KJS::Value(); // Returns void + +} + +KJS::Value QMenuDataImp::changeItem_35( KJS::ExecState *exec, KJS::Object &obj, const KJS::List &args ) +{ + + QPixmap arg0 = extractQPixmap(exec, args, 0); + + int arg1 = extractInt(exec, args, 1); + + instance->changeItem( + arg0, + arg1 ); + return KJS::Value(); // Returns void + +} + +KJS::Value QMenuDataImp::changeItem_36( KJS::ExecState *exec, KJS::Object &obj, const KJS::List &args ) +{ + + // Unsupported parameter const QIconSet + return KJS::Value(); + + const QIconSet arg0; // Dummy + + QString arg1 = extractQString(exec, args, 1); + + int arg2 = extractInt(exec, args, 2); + + instance->changeItem( + arg0, + arg1, + arg2 ); + return KJS::Value(); // Returns void + +} + +KJS::Value QMenuDataImp::isItemActive_37( KJS::ExecState *exec, KJS::Object &obj, const KJS::List &args ) +{ + + int arg0 = extractInt(exec, args, 0); + + bool ret; + ret = instance->isItemActive( + arg0 ); + return KJS::Boolean( ret ); + +} + +KJS::Value QMenuDataImp::isItemEnabled_38( KJS::ExecState *exec, KJS::Object &obj, const KJS::List &args ) +{ + + int arg0 = extractInt(exec, args, 0); + + bool ret; + ret = instance->isItemEnabled( + arg0 ); + return KJS::Boolean( ret ); + +} + +KJS::Value QMenuDataImp::setItemEnabled_39( KJS::ExecState *exec, KJS::Object &obj, const KJS::List &args ) +{ + + int arg0 = extractInt(exec, args, 0); + + bool arg1 = extractBool(exec, args, 1); + + instance->setItemEnabled( + arg0, + arg1 ); + return KJS::Value(); // Returns void + +} + +KJS::Value QMenuDataImp::isItemChecked_40( KJS::ExecState *exec, KJS::Object &obj, const KJS::List &args ) +{ + + int arg0 = extractInt(exec, args, 0); + + bool ret; + ret = instance->isItemChecked( + arg0 ); + return KJS::Boolean( ret ); + +} + +KJS::Value QMenuDataImp::setItemChecked_41( KJS::ExecState *exec, KJS::Object &obj, const KJS::List &args ) +{ + + int arg0 = extractInt(exec, args, 0); + + bool arg1 = extractBool(exec, args, 1); + + instance->setItemChecked( + arg0, + arg1 ); + return KJS::Value(); // Returns void + +} + +KJS::Value QMenuDataImp::isItemVisible_42( KJS::ExecState *exec, KJS::Object &obj, const KJS::List &args ) +{ + + int arg0 = extractInt(exec, args, 0); + + bool ret; + ret = instance->isItemVisible( + arg0 ); + return KJS::Boolean( ret ); + +} + +KJS::Value QMenuDataImp::setItemVisible_43( KJS::ExecState *exec, KJS::Object &obj, const KJS::List &args ) +{ + + int arg0 = extractInt(exec, args, 0); + + bool arg1 = extractBool(exec, args, 1); + + instance->setItemVisible( + arg0, + arg1 ); + return KJS::Value(); // Returns void + +} + +KJS::Value QMenuDataImp::updateItem_44( KJS::ExecState *exec, KJS::Object &obj, const KJS::List &args ) +{ + + int arg0 = extractInt(exec, args, 0); + + instance->updateItem( + arg0 ); + return KJS::Value(); // Returns void + +} + +KJS::Value QMenuDataImp::indexOf_45( KJS::ExecState *exec, KJS::Object &obj, const KJS::List &args ) +{ + + int arg0 = extractInt(exec, args, 0); + + int ret; + ret = instance->indexOf( + arg0 ); + return KJS::Number( ret ); + +} + +KJS::Value QMenuDataImp::idAt_46( KJS::ExecState *exec, KJS::Object &obj, const KJS::List &args ) +{ + + int arg0 = extractInt(exec, args, 0); + + int ret; + ret = instance->idAt( + arg0 ); + return KJS::Number( ret ); + +} + +KJS::Value QMenuDataImp::setId_47( KJS::ExecState *exec, KJS::Object &obj, const KJS::List &args ) +{ + + int arg0 = extractInt(exec, args, 0); + + int arg1 = extractInt(exec, args, 1); + + instance->setId( + arg0, + arg1 ); + return KJS::Value(); // Returns void + +} + +KJS::Value QMenuDataImp::connectItem_48( KJS::ExecState *exec, KJS::Object &obj, const KJS::List &args ) +{ + + int arg0 = extractInt(exec, args, 0); + + // Unsupported parameter const QObject * + return KJS::Value(); + + const QObject * arg1; // Dummy + + const char *arg2 = (args.size() >= 3) ? args[2].toString(exec).ascii() : 0; + + bool ret; + ret = instance->connectItem( + arg0, + arg1, + arg2 ); + return KJS::Boolean( ret ); + +} + +KJS::Value QMenuDataImp::disconnectItem_49( KJS::ExecState *exec, KJS::Object &obj, const KJS::List &args ) +{ + + int arg0 = extractInt(exec, args, 0); + + // Unsupported parameter const QObject * + return KJS::Value(); + + const QObject * arg1; // Dummy + + const char *arg2 = (args.size() >= 3) ? args[2].toString(exec).ascii() : 0; + + bool ret; + ret = instance->disconnectItem( + arg0, + arg1, + arg2 ); + return KJS::Boolean( ret ); + +} + +KJS::Value QMenuDataImp::setItemParameter_50( KJS::ExecState *exec, KJS::Object &obj, const KJS::List &args ) +{ + + int arg0 = extractInt(exec, args, 0); + + int arg1 = extractInt(exec, args, 1); + + bool ret; + ret = instance->setItemParameter( + arg0, + arg1 ); + return KJS::Boolean( ret ); + +} + +KJS::Value QMenuDataImp::itemParameter_51( KJS::ExecState *exec, KJS::Object &obj, const KJS::List &args ) +{ + + int arg0 = extractInt(exec, args, 0); + + int ret; + ret = instance->itemParameter( + arg0 ); + return KJS::Number( ret ); + +} + +KJS::Value QMenuDataImp::findItem_52( KJS::ExecState *exec, KJS::Object &obj, const KJS::List &args ) +{ + + int arg0 = extractInt(exec, args, 0); + + instance->findItem( + arg0 ); + return KJS::Value(); // Returns 'QMenuItem *' + +} + +KJS::Value QMenuDataImp::findItem_53( KJS::ExecState *exec, KJS::Object &obj, const KJS::List &args ) +{ + + int arg0 = extractInt(exec, args, 0); + + // Unsupported parameter QMenuData ** + return KJS::Value(); + + QMenuData ** arg1; // Dummy + + instance->findItem( + arg0, + arg1 ); + return KJS::Value(); // Returns 'QMenuItem *' + +} + +KJS::Value QMenuDataImp::findPopup_54( KJS::ExecState *exec, KJS::Object &obj, const KJS::List &args ) +{ + + // Unsupported parameter QPopupMenu * + return KJS::Value(); + + QPopupMenu * arg0; // Dummy + + // Unsupported parameter int * + return KJS::Value(); + + int * arg1; // Dummy + + instance->findPopup( + arg0, + arg1 ); + return KJS::Value(); // Returns 'QMenuItem *' + +} + +KJS::Value QMenuDataImp::activateItemAt_55( KJS::ExecState *exec, KJS::Object &obj, const KJS::List &args ) +{ + + int arg0 = extractInt(exec, args, 0); + + instance->activateItemAt( + arg0 ); + return KJS::Value(); // Returns void + +} + + +} // namespace KJSEmbed + +// Local Variables: +// c-basic-offset: 4 +// End: + + diff --git a/kjsembed/qtbindings/qmenudata_imp.h b/kjsembed/qtbindings/qmenudata_imp.h new file mode 100644 index 00000000..f5ed75b4 --- /dev/null +++ b/kjsembed/qtbindings/qmenudata_imp.h @@ -0,0 +1,204 @@ + + + +#ifndef KJSEMBED_QMenuData_H +#define KJSEMBED_QMenuData_H + +#include <kjs/interpreter.h> +#include <kjs/object.h> + +#include <kjsembed/jsobjectproxy_imp.h> + +class QMenuData; + +/** + * Namespace containing the KJSEmbed library. + */ +namespace KJSEmbed { + +/** + * Wrapper class for QMenuData methods. + * + * @author Richard Moore, rich@kde.org + */ +class QMenuDataImp : public JSProxyImp +{ +public: + /** Enumerates the constructors supported by this class. */ + enum Constructors { + Constructor_QMenuData_1, + + LastConstuctor = -1 + }; + + /** Enumerates the methods supported by this class. */ + enum Methods { + + Method_count_3, + Method_insertItem_4, + Method_insertItem_5, + Method_insertItem_6, + Method_insertItem_7, + Method_insertItem_8, + Method_insertItem_9, + Method_insertItem_10, + Method_insertItem_11, + Method_insertItem_12, + Method_insertItem_13, + Method_insertItem_14, + Method_insertItem_15, + Method_insertItem_16, + Method_insertItem_17, + Method_insertItem_18, + Method_insertSeparator_19, + Method_removeItem_20, + Method_removeItemAt_21, + Method_clear_22, + Method_accel_23, + Method_setAccel_24, + Method_iconSet_25, + Method_text_26, + Method_pixmap_27, + Method_setWhatsThis_28, + Method_whatsThis_29, + Method_changeItem_30, + Method_changeItem_31, + Method_changeItem_32, + Method_changeItem_33, + Method_changeItem_34, + Method_changeItem_35, + Method_changeItem_36, + Method_isItemActive_37, + Method_isItemEnabled_38, + Method_setItemEnabled_39, + Method_isItemChecked_40, + Method_setItemChecked_41, + Method_isItemVisible_42, + Method_setItemVisible_43, + Method_updateItem_44, + Method_indexOf_45, + Method_idAt_46, + Method_setId_47, + Method_connectItem_48, + Method_disconnectItem_49, + Method_setItemParameter_50, + Method_itemParameter_51, + Method_findItem_52, + Method_findItem_53, + Method_findPopup_54, + Method_activateItemAt_55, + Method_Last = -1 + }; + + QMenuDataImp( KJS::ExecState *exec, int id, bool constructor=false ); + ~QMenuDataImp(); + + /** + * Adds the static bindings for this class to the specified Object. The + * static bindings are the static methods and the enums of this class. + */ + static void addStaticBindings( KJS::ExecState *exec, KJS::Object &object ); + + /** + * Adds the bindings for this class to the specified Object. The bindings + * added are the instance methods of this class. + */ + static void addBindings( KJS::ExecState *exec, KJS::Object &object ); + + static QMenuData *toQMenuData( KJS::Object &object ); + + // + // Constructors implemented by this class. + // + + KJS::Object QMenuData_1( KJS::ExecState *exec, const KJS::List &args ); + + // + // Methods implemented by this class. + // + + KJS::Value count_3( KJS::ExecState *exec, KJS::Object &obj, const KJS::List &args ); + KJS::Value insertItem_4( KJS::ExecState *exec, KJS::Object &obj, const KJS::List &args ); + KJS::Value insertItem_5( KJS::ExecState *exec, KJS::Object &obj, const KJS::List &args ); + KJS::Value insertItem_6( KJS::ExecState *exec, KJS::Object &obj, const KJS::List &args ); + KJS::Value insertItem_7( KJS::ExecState *exec, KJS::Object &obj, const KJS::List &args ); + KJS::Value insertItem_8( KJS::ExecState *exec, KJS::Object &obj, const KJS::List &args ); + KJS::Value insertItem_9( KJS::ExecState *exec, KJS::Object &obj, const KJS::List &args ); + KJS::Value insertItem_10( KJS::ExecState *exec, KJS::Object &obj, const KJS::List &args ); + KJS::Value insertItem_11( KJS::ExecState *exec, KJS::Object &obj, const KJS::List &args ); + KJS::Value insertItem_12( KJS::ExecState *exec, KJS::Object &obj, const KJS::List &args ); + KJS::Value insertItem_13( KJS::ExecState *exec, KJS::Object &obj, const KJS::List &args ); + KJS::Value insertItem_14( KJS::ExecState *exec, KJS::Object &obj, const KJS::List &args ); + KJS::Value insertItem_15( KJS::ExecState *exec, KJS::Object &obj, const KJS::List &args ); + KJS::Value insertItem_16( KJS::ExecState *exec, KJS::Object &obj, const KJS::List &args ); + KJS::Value insertItem_17( KJS::ExecState *exec, KJS::Object &obj, const KJS::List &args ); + KJS::Value insertItem_18( KJS::ExecState *exec, KJS::Object &obj, const KJS::List &args ); + KJS::Value insertSeparator_19( KJS::ExecState *exec, KJS::Object &obj, const KJS::List &args ); + KJS::Value removeItem_20( KJS::ExecState *exec, KJS::Object &obj, const KJS::List &args ); + KJS::Value removeItemAt_21( KJS::ExecState *exec, KJS::Object &obj, const KJS::List &args ); + KJS::Value clear_22( KJS::ExecState *exec, KJS::Object &obj, const KJS::List &args ); + KJS::Value accel_23( KJS::ExecState *exec, KJS::Object &obj, const KJS::List &args ); + KJS::Value setAccel_24( KJS::ExecState *exec, KJS::Object &obj, const KJS::List &args ); + KJS::Value iconSet_25( KJS::ExecState *exec, KJS::Object &obj, const KJS::List &args ); + KJS::Value text_26( KJS::ExecState *exec, KJS::Object &obj, const KJS::List &args ); + KJS::Value pixmap_27( KJS::ExecState *exec, KJS::Object &obj, const KJS::List &args ); + KJS::Value setWhatsThis_28( KJS::ExecState *exec, KJS::Object &obj, const KJS::List &args ); + KJS::Value whatsThis_29( KJS::ExecState *exec, KJS::Object &obj, const KJS::List &args ); + KJS::Value changeItem_30( KJS::ExecState *exec, KJS::Object &obj, const KJS::List &args ); + KJS::Value changeItem_31( KJS::ExecState *exec, KJS::Object &obj, const KJS::List &args ); + KJS::Value changeItem_32( KJS::ExecState *exec, KJS::Object &obj, const KJS::List &args ); + KJS::Value changeItem_33( KJS::ExecState *exec, KJS::Object &obj, const KJS::List &args ); + KJS::Value changeItem_34( KJS::ExecState *exec, KJS::Object &obj, const KJS::List &args ); + KJS::Value changeItem_35( KJS::ExecState *exec, KJS::Object &obj, const KJS::List &args ); + KJS::Value changeItem_36( KJS::ExecState *exec, KJS::Object &obj, const KJS::List &args ); + KJS::Value isItemActive_37( KJS::ExecState *exec, KJS::Object &obj, const KJS::List &args ); + KJS::Value isItemEnabled_38( KJS::ExecState *exec, KJS::Object &obj, const KJS::List &args ); + KJS::Value setItemEnabled_39( KJS::ExecState *exec, KJS::Object &obj, const KJS::List &args ); + KJS::Value isItemChecked_40( KJS::ExecState *exec, KJS::Object &obj, const KJS::List &args ); + KJS::Value setItemChecked_41( KJS::ExecState *exec, KJS::Object &obj, const KJS::List &args ); + KJS::Value isItemVisible_42( KJS::ExecState *exec, KJS::Object &obj, const KJS::List &args ); + KJS::Value setItemVisible_43( KJS::ExecState *exec, KJS::Object &obj, const KJS::List &args ); + KJS::Value updateItem_44( KJS::ExecState *exec, KJS::Object &obj, const KJS::List &args ); + KJS::Value indexOf_45( KJS::ExecState *exec, KJS::Object &obj, const KJS::List &args ); + KJS::Value idAt_46( KJS::ExecState *exec, KJS::Object &obj, const KJS::List &args ); + KJS::Value setId_47( KJS::ExecState *exec, KJS::Object &obj, const KJS::List &args ); + KJS::Value connectItem_48( KJS::ExecState *exec, KJS::Object &obj, const KJS::List &args ); + KJS::Value disconnectItem_49( KJS::ExecState *exec, KJS::Object &obj, const KJS::List &args ); + KJS::Value setItemParameter_50( KJS::ExecState *exec, KJS::Object &obj, const KJS::List &args ); + KJS::Value itemParameter_51( KJS::ExecState *exec, KJS::Object &obj, const KJS::List &args ); + KJS::Value findItem_52( KJS::ExecState *exec, KJS::Object &obj, const KJS::List &args ); + KJS::Value findItem_53( KJS::ExecState *exec, KJS::Object &obj, const KJS::List &args ); + KJS::Value findPopup_54( KJS::ExecState *exec, KJS::Object &obj, const KJS::List &args ); + KJS::Value activateItemAt_55( KJS::ExecState *exec, KJS::Object &obj, const KJS::List &args ); + + // + // JS binding code. + // + + /** Returns true iff this object implements the construct function. */ + virtual bool implementsConstruct() const { return cons; } + + /** Invokes the construct function. */ + virtual KJS::Object construct( KJS::ExecState *exec, const KJS::List &args ); + + /** Returns true iff this object implements the call function. */ + virtual bool implementsCall() const { return !cons; } + + /** Invokes the call function. */ + virtual KJS::Value call( KJS::ExecState *exec, KJS::Object &self, const KJS::List &args ); + +private: + QMenuData *instance; // Temp + int id; + bool cons; +}; + +} // namespace KJSEmbed + +#endif // KJSEMBED_QMenuData_H + +// Local Variables: +// c-basic-offset: 4 +// End: + + diff --git a/kjsembed/qtbindings/qmenuitem_imp.cpp b/kjsembed/qtbindings/qmenuitem_imp.cpp new file mode 100644 index 00000000..fa994b21 --- /dev/null +++ b/kjsembed/qtbindings/qmenuitem_imp.cpp @@ -0,0 +1,430 @@ + + + +#include <qcstring.h> +#include <qimage.h> +#include <qpainter.h> +#include <qpalette.h> +#include <qpixmap.h> +#include <qfont.h> + +#include <kjs/object.h> + +#include <kjsembed/global.h> +#include <kjsembed/jsobjectproxy.h> +#include <kjsembed/jsopaqueproxy.h> +#include <kjsembed/jsbinding.h> + +#include <qmenudata.h> +#include "qmenuitem_imp.h" + +/** + * Namespace containing the KJSEmbed library. + */ +namespace KJSEmbed { + +QMenuItemImp::QMenuItemImp( KJS::ExecState *exec, int mid, bool constructor ) + : JSProxyImp(exec), id(mid), cons(constructor) +{ +} + +QMenuItemImp::~QMenuItemImp() +{ +} + +/** + * Adds bindings for static methods and enum constants to the specified Object. + */ +void QMenuItemImp::addStaticBindings( KJS::ExecState *exec, KJS::Object &object ) +{ + JSProxy::MethodTable methods[] = { + + { 0, 0 } + }; + + int idx = 0; + QCString lastName; + + while( methods[idx].name ) { + if ( lastName != methods[idx].name ) { + QMenuItemImp *meth = new QMenuItemImp( exec, methods[idx].id ); + object.put( exec , methods[idx].name, KJS::Object(meth) ); + lastName = methods[idx].name; + } + ++idx; + } + + +} + +/** + * Adds bindings for instance methods to the specified Object. + */ +void QMenuItemImp::addBindings( KJS::ExecState *exec, KJS::Object &object ) +{ + JSProxy::MethodTable methods[] = { + { Method_id_3, "id" }, + { Method_iconSet_4, "iconSet" }, + { Method_text_5, "text" }, + { Method_whatsThis_6, "whatsThis" }, + { Method_pixmap_7, "pixmap" }, + { Method_popup_8, "popup" }, + { Method_widget_9, "widget" }, + { Method_custom_10, "custom" }, + { Method_key_11, "key" }, + { Method_signal_12, "signal" }, + { Method_isSeparator_13, "isSeparator" }, + { Method_isEnabled_14, "isEnabled" }, + { Method_isChecked_15, "isChecked" }, + { Method_isDirty_16, "isDirty" }, + { Method_isVisible_17, "isVisible" }, + { Method_isEnabledAndVisible_18, "isEnabledAndVisible" }, + { Method_setText_19, "setText" }, + { Method_setDirty_20, "setDirty" }, + { Method_setVisible_21, "setVisible" }, + { Method_setWhatsThis_22, "setWhatsThis" }, + { 0, 0 } + }; + + JSProxy::addMethods<QMenuItemImp>(exec, methods, object ); + +} + +/** + * Extract a QMenuItem pointer from an Object. + */ +QMenuItem *QMenuItemImp::toQMenuItem( KJS::Object &self ) +{ + JSObjectProxy *ob = JSProxy::toObjectProxy( self.imp() ); + if ( ob ) { + QObject *obj = ob->object(); + if ( obj ) + return dynamic_cast<QMenuItem *>( obj ); + } + + if( !JSProxy::checkType(self, JSProxy::ObjectProxy, "QMenuItem") ) { + QObject *obj = JSProxy::toObjectProxy( self.imp() )->object(); + return dynamic_cast<QMenuItem *>( obj ); + } + + if( !JSProxy::checkType(self, JSProxy::OpaqueProxy, "QMenuItem") ) { + return JSProxy::toOpaqueProxy( self.imp() )->toNative<QMenuItem>(); + } + return 0; + +} + +/** + * Select and invoke the correct constructor. + */ +KJS::Object QMenuItemImp::construct( KJS::ExecState *exec, const KJS::List &args ) +{ + switch( id ) { + + case Constructor_QMenuItem_1: + return QMenuItem_1( exec, args ); + break; + + default: + break; + } + + QString msg = i18n("QMenuItemCons has no constructor with id '%1'").arg(id); + return throwError(exec, msg,KJS::ReferenceError); +} + + +KJS::Object QMenuItemImp::QMenuItem_1( KJS::ExecState *exec, const KJS::List &args ) +{ + + + // We should now create an instance of the QMenuItem object + + QMenuItem *ret = new QMenuItem( + ); + + return KJS::Object(); +} + +KJS::Value QMenuItemImp::call( KJS::ExecState *exec, KJS::Object &self, const KJS::List &args ) +{ + instance = QMenuItemImp::toQMenuItem( self ); + + switch( id ) { + + case Method_id_3: + return id_3( exec, self, args ); + break; + + case Method_iconSet_4: + return iconSet_4( exec, self, args ); + break; + + case Method_text_5: + return text_5( exec, self, args ); + break; + + case Method_whatsThis_6: + return whatsThis_6( exec, self, args ); + break; + + case Method_pixmap_7: + return pixmap_7( exec, self, args ); + break; + + case Method_popup_8: + return popup_8( exec, self, args ); + break; + + case Method_widget_9: + return widget_9( exec, self, args ); + break; + + case Method_custom_10: + return custom_10( exec, self, args ); + break; + + case Method_key_11: + return key_11( exec, self, args ); + break; + + case Method_signal_12: + return signal_12( exec, self, args ); + break; + + case Method_isSeparator_13: + return isSeparator_13( exec, self, args ); + break; + + case Method_isEnabled_14: + return isEnabled_14( exec, self, args ); + break; + + case Method_isChecked_15: + return isChecked_15( exec, self, args ); + break; + + case Method_isDirty_16: + return isDirty_16( exec, self, args ); + break; + + case Method_isVisible_17: + return isVisible_17( exec, self, args ); + break; + + case Method_isEnabledAndVisible_18: + return isEnabledAndVisible_18( exec, self, args ); + break; + + case Method_setText_19: + return setText_19( exec, self, args ); + break; + + case Method_setDirty_20: + return setDirty_20( exec, self, args ); + break; + + case Method_setVisible_21: + return setVisible_21( exec, self, args ); + break; + + case Method_setWhatsThis_22: + return setWhatsThis_22( exec, self, args ); + break; + + default: + break; + } + + QString msg = i18n( "QMenuItemImp has no method with id '%1'" ).arg( id ); + return throwError(exec, msg,KJS::ReferenceError); +} + + +KJS::Value QMenuItemImp::id_3( KJS::ExecState *exec, KJS::Object &obj, const KJS::List &args ) +{ + + int ret; + ret = instance->id( ); + return KJS::Number( ret ); + +} + +KJS::Value QMenuItemImp::iconSet_4( KJS::ExecState *exec, KJS::Object &obj, const KJS::List &args ) +{ + + instance->iconSet( ); + return KJS::Value(); // Returns 'QIconSet *' + +} + +KJS::Value QMenuItemImp::text_5( KJS::ExecState *exec, KJS::Object &obj, const KJS::List &args ) +{ + + QString ret; + ret = instance->text( ); + return KJS::String( ret ); + +} + +KJS::Value QMenuItemImp::whatsThis_6( KJS::ExecState *exec, KJS::Object &obj, const KJS::List &args ) +{ + + QString ret; + ret = instance->whatsThis( ); + return KJS::String( ret ); + +} + +KJS::Value QMenuItemImp::pixmap_7( KJS::ExecState *exec, KJS::Object &obj, const KJS::List &args ) +{ + + return convertToValue(exec, *instance->pixmap( )); + +} + +KJS::Value QMenuItemImp::popup_8( KJS::ExecState *exec, KJS::Object &obj, const KJS::List &args ) +{ + + instance->popup( ); + return KJS::Value(); // Returns 'QPopupMenu *' + +} + +KJS::Value QMenuItemImp::widget_9( KJS::ExecState *exec, KJS::Object &obj, const KJS::List &args ) +{ + + instance->widget( ); + return KJS::Value(); // Returns 'QWidget *' + +} + +KJS::Value QMenuItemImp::custom_10( KJS::ExecState *exec, KJS::Object &obj, const KJS::List &args ) +{ + + instance->custom( ); + return KJS::Value(); // Returns 'QCustomMenuItem *' + +} + +KJS::Value QMenuItemImp::key_11( KJS::ExecState *exec, KJS::Object &obj, const KJS::List &args ) +{ + + return convertToValue( exec, instance->key( )); + +} + +KJS::Value QMenuItemImp::signal_12( KJS::ExecState *exec, KJS::Object &obj, const KJS::List &args ) +{ + + instance->signal( ); + return KJS::Value(); // Returns 'QSignal *' + +} + +KJS::Value QMenuItemImp::isSeparator_13( KJS::ExecState *exec, KJS::Object &obj, const KJS::List &args ) +{ + + bool ret; + ret = instance->isSeparator( ); + return KJS::Boolean( ret ); + +} + +KJS::Value QMenuItemImp::isEnabled_14( KJS::ExecState *exec, KJS::Object &obj, const KJS::List &args ) +{ + + bool ret; + ret = instance->isEnabled( ); + return KJS::Boolean( ret ); + +} + +KJS::Value QMenuItemImp::isChecked_15( KJS::ExecState *exec, KJS::Object &obj, const KJS::List &args ) +{ + + bool ret; + ret = instance->isChecked( ); + return KJS::Boolean( ret ); + +} + +KJS::Value QMenuItemImp::isDirty_16( KJS::ExecState *exec, KJS::Object &obj, const KJS::List &args ) +{ + + bool ret; + ret = instance->isDirty( ); + return KJS::Boolean( ret ); + +} + +KJS::Value QMenuItemImp::isVisible_17( KJS::ExecState *exec, KJS::Object &obj, const KJS::List &args ) +{ + + bool ret; + ret = instance->isVisible( ); + return KJS::Boolean( ret ); + +} + +KJS::Value QMenuItemImp::isEnabledAndVisible_18( KJS::ExecState *exec, KJS::Object &obj, const KJS::List &args ) +{ + + bool ret; + ret = instance->isEnabledAndVisible( ); + return KJS::Boolean( ret ); + +} + +KJS::Value QMenuItemImp::setText_19( KJS::ExecState *exec, KJS::Object &obj, const KJS::List &args ) +{ + + QString arg0 = extractQString(exec, args, 0); + + instance->setText( + arg0 ); + return KJS::Value(); // Returns void + +} + +KJS::Value QMenuItemImp::setDirty_20( KJS::ExecState *exec, KJS::Object &obj, const KJS::List &args ) +{ + + bool arg0 = extractBool(exec, args, 0); + + instance->setDirty( + arg0 ); + return KJS::Value(); // Returns void + +} + +KJS::Value QMenuItemImp::setVisible_21( KJS::ExecState *exec, KJS::Object &obj, const KJS::List &args ) +{ + + bool arg0 = extractBool(exec, args, 0); + + instance->setVisible( + arg0 ); + return KJS::Value(); // Returns void + +} + +KJS::Value QMenuItemImp::setWhatsThis_22( KJS::ExecState *exec, KJS::Object &obj, const KJS::List &args ) +{ + + QString arg0 = extractQString(exec, args, 0); + + instance->setWhatsThis( + arg0 ); + return KJS::Value(); // Returns void + +} + + +} // namespace KJSEmbed + +// Local Variables: +// c-basic-offset: 4 +// End: + + diff --git a/kjsembed/qtbindings/qmenuitem_imp.h b/kjsembed/qtbindings/qmenuitem_imp.h new file mode 100644 index 00000000..3b1935d2 --- /dev/null +++ b/kjsembed/qtbindings/qmenuitem_imp.h @@ -0,0 +1,138 @@ + + + +#ifndef KJSEMBED_QMenuItem_H +#define KJSEMBED_QMenuItem_H + +#include <kjs/interpreter.h> +#include <kjs/object.h> + +#include <kjsembed/jsobjectproxy_imp.h> + +class QMenuItem; + +/** + * Namespace containing the KJSEmbed library. + */ +namespace KJSEmbed { + +/** + * Wrapper class for QMenuItem methods. + * + * @author Richard Moore, rich@kde.org + */ +class QMenuItemImp : public JSProxyImp +{ +public: + /** Enumerates the constructors supported by this class. */ + enum Constructors { + Constructor_QMenuItem_1, + + LastConstuctor = -1 + }; + + /** Enumerates the methods supported by this class. */ + enum Methods { + + Method_id_3, + Method_iconSet_4, + Method_text_5, + Method_whatsThis_6, + Method_pixmap_7, + Method_popup_8, + Method_widget_9, + Method_custom_10, + Method_key_11, + Method_signal_12, + Method_isSeparator_13, + Method_isEnabled_14, + Method_isChecked_15, + Method_isDirty_16, + Method_isVisible_17, + Method_isEnabledAndVisible_18, + Method_setText_19, + Method_setDirty_20, + Method_setVisible_21, + Method_setWhatsThis_22, + Method_Last = -1 + }; + + QMenuItemImp( KJS::ExecState *exec, int id, bool constructor=false ); + ~QMenuItemImp(); + + /** + * Adds the static bindings for this class to the specified Object. The + * static bindings are the static methods and the enums of this class. + */ + static void addStaticBindings( KJS::ExecState *exec, KJS::Object &object ); + + /** + * Adds the bindings for this class to the specified Object. The bindings + * added are the instance methods of this class. + */ + static void addBindings( KJS::ExecState *exec, KJS::Object &object ); + + static QMenuItem *toQMenuItem( KJS::Object &object ); + + // + // Constructors implemented by this class. + // + + KJS::Object QMenuItem_1( KJS::ExecState *exec, const KJS::List &args ); + + // + // Methods implemented by this class. + // + + KJS::Value id_3( KJS::ExecState *exec, KJS::Object &obj, const KJS::List &args ); + KJS::Value iconSet_4( KJS::ExecState *exec, KJS::Object &obj, const KJS::List &args ); + KJS::Value text_5( KJS::ExecState *exec, KJS::Object &obj, const KJS::List &args ); + KJS::Value whatsThis_6( KJS::ExecState *exec, KJS::Object &obj, const KJS::List &args ); + KJS::Value pixmap_7( KJS::ExecState *exec, KJS::Object &obj, const KJS::List &args ); + KJS::Value popup_8( KJS::ExecState *exec, KJS::Object &obj, const KJS::List &args ); + KJS::Value widget_9( KJS::ExecState *exec, KJS::Object &obj, const KJS::List &args ); + KJS::Value custom_10( KJS::ExecState *exec, KJS::Object &obj, const KJS::List &args ); + KJS::Value key_11( KJS::ExecState *exec, KJS::Object &obj, const KJS::List &args ); + KJS::Value signal_12( KJS::ExecState *exec, KJS::Object &obj, const KJS::List &args ); + KJS::Value isSeparator_13( KJS::ExecState *exec, KJS::Object &obj, const KJS::List &args ); + KJS::Value isEnabled_14( KJS::ExecState *exec, KJS::Object &obj, const KJS::List &args ); + KJS::Value isChecked_15( KJS::ExecState *exec, KJS::Object &obj, const KJS::List &args ); + KJS::Value isDirty_16( KJS::ExecState *exec, KJS::Object &obj, const KJS::List &args ); + KJS::Value isVisible_17( KJS::ExecState *exec, KJS::Object &obj, const KJS::List &args ); + KJS::Value isEnabledAndVisible_18( KJS::ExecState *exec, KJS::Object &obj, const KJS::List &args ); + KJS::Value setText_19( KJS::ExecState *exec, KJS::Object &obj, const KJS::List &args ); + KJS::Value setDirty_20( KJS::ExecState *exec, KJS::Object &obj, const KJS::List &args ); + KJS::Value setVisible_21( KJS::ExecState *exec, KJS::Object &obj, const KJS::List &args ); + KJS::Value setWhatsThis_22( KJS::ExecState *exec, KJS::Object &obj, const KJS::List &args ); + + // + // JS binding code. + // + + /** Returns true iff this object implements the construct function. */ + virtual bool implementsConstruct() const { return cons; } + + /** Invokes the construct function. */ + virtual KJS::Object construct( KJS::ExecState *exec, const KJS::List &args ); + + /** Returns true iff this object implements the call function. */ + virtual bool implementsCall() const { return !cons; } + + /** Invokes the call function. */ + virtual KJS::Value call( KJS::ExecState *exec, KJS::Object &self, const KJS::List &args ); + +private: + QMenuItem *instance; // Temp + int id; + bool cons; +}; + +} // namespace KJSEmbed + +#endif // KJSEMBED_QMenuItem_H + +// Local Variables: +// c-basic-offset: 4 +// End: + + diff --git a/kjsembed/qtbindings/qpopupmenu_imp.cpp b/kjsembed/qtbindings/qpopupmenu_imp.cpp new file mode 100644 index 00000000..14430351 --- /dev/null +++ b/kjsembed/qtbindings/qpopupmenu_imp.cpp @@ -0,0 +1,440 @@ + + + +#include <qcstring.h> +#include <qimage.h> +#include <qpainter.h> +#include <qpalette.h> +#include <qpixmap.h> +#include <qfont.h> + +#include <kjs/object.h> + +#include <kjsembed/global.h> +#include <kjsembed/jsobjectproxy.h> +#include <kjsembed/jsopaqueproxy.h> +#include <kjsembed/jsbinding.h> + +#include <qpopupmenu.h> +#include "qpopupmenu_imp.h" + +/** + * Namespace containing the KJSEmbed library. + */ +namespace KJSEmbed { + +QPopupMenuImp::QPopupMenuImp( KJS::ExecState *exec, int mid, bool constructor ) + : JSProxyImp(exec), id(mid), cons(constructor) +{ +} + +QPopupMenuImp::~QPopupMenuImp() +{ +} + +/** + * Adds bindings for static methods and enum constants to the specified Object. + */ +void QPopupMenuImp::addStaticBindings( KJS::ExecState *exec, KJS::Object &object ) +{ + JSProxy::MethodTable methods[] = { + + { 0, 0 } + }; + + int idx = 0; + QCString lastName; + + while( methods[idx].name ) { + if ( lastName != methods[idx].name ) { + QPopupMenuImp *meth = new QPopupMenuImp( exec, methods[idx].id ); + object.put( exec , methods[idx].name, KJS::Object(meth) ); + lastName = methods[idx].name; + } + ++idx; + } + + +} + +/** + * Adds bindings for instance methods to the specified Object. + */ +void QPopupMenuImp::addBindings( KJS::ExecState *exec, KJS::Object &object ) +{ + JSProxy::MethodTable methods[] = { + + { Method_popup_3, "popup" }, + { Method_updateItem_4, "updateItem" }, + { Method_setCheckable_5, "setCheckable" }, + { Method_isCheckable_6, "isCheckable" }, + { Method_setFont_7, "setFont" }, + { Method_show_8, "show" }, + { Method_hide_9, "hide" }, + { Method_exec_10, "exec" }, + { Method_exec_11, "exec" }, + { Method_setActiveItem_12, "setActiveItem" }, + { Method_sizeHint_13, "sizeHint" }, + { Method_idAt_14, "idAt" }, + { Method_idAt_15, "idAt" }, + { Method_customWhatsThis_16, "customWhatsThis" }, + { Method_insertTearOffHandle_17, "insertTearOffHandle" }, + { Method_activateItemAt_18, "activateItemAt" }, + { Method_itemGeometry_19, "itemGeometry" }, + { 0, 0 } + }; + + int idx = 0; + QCString lastName; + + while( methods[idx].name ) { + if ( lastName != methods[idx].name ) { + QPopupMenuImp *meth = new QPopupMenuImp( exec, methods[idx].id ); + object.put( exec , methods[idx].name, KJS::Object(meth) ); + lastName = methods[idx].name; + } + ++idx; + } +} + +/** + * Extract a QPopupMenu pointer from an Object. + */ +QPopupMenu *QPopupMenuImp::toQPopupMenu( KJS::Object &self ) +{ + JSObjectProxy *ob = JSProxy::toObjectProxy( self.imp() ); + if ( ob ) { + QObject *obj = ob->object(); + if ( obj ) + return dynamic_cast<QPopupMenu *>( obj ); + } + + JSOpaqueProxy *op = JSProxy::toOpaqueProxy( self.imp() ); + if ( !op ) + return 0; + + if ( op->typeName() != "QPopupMenu" ) + return 0; + + return op->toNative<QPopupMenu>(); +} + +/** + * Select and invoke the correct constructor. + */ +KJS::Object QPopupMenuImp::construct( KJS::ExecState *exec, const KJS::List &args ) +{ + switch( id ) { + + case Constructor_QPopupMenu_1: + return QPopupMenu_1( exec, args ); + break; + + default: + break; + } + + QString msg = i18n("QPopupMenuCons has no constructor with id '%1'").arg(id); + return throwError(exec, msg,KJS::ReferenceError); +} + + +KJS::Object QPopupMenuImp::QPopupMenu_1( KJS::ExecState *exec, const KJS::List &args ) +{ + + // Unsupported parameter QWidget * + return KJS::Object(); + + QWidget * arg0; // Dummy + + const char *arg1 = (args.size() >= 2) ? args[1].toString(exec).ascii() : 0; + + + // We should now create an instance of the QPopupMenu object + + QPopupMenu *ret = new QPopupMenu( + + arg0, + arg1 ); + + +} + +KJS::Value QPopupMenuImp::call( KJS::ExecState *exec, KJS::Object &self, const KJS::List &args ) +{ + instance = QPopupMenuImp::toQPopupMenu( self ); + + switch( id ) { + + case Method_popup_3: + return popup_3( exec, self, args ); + break; + + case Method_updateItem_4: + return updateItem_4( exec, self, args ); + break; + + case Method_setCheckable_5: + return setCheckable_5( exec, self, args ); + break; + + case Method_isCheckable_6: + return isCheckable_6( exec, self, args ); + break; + + case Method_setFont_7: + return setFont_7( exec, self, args ); + break; + + case Method_show_8: + return show_8( exec, self, args ); + break; + + case Method_hide_9: + return hide_9( exec, self, args ); + break; + + case Method_exec_10: + return exec_10( exec, self, args ); + break; + + case Method_exec_11: + return exec_11( exec, self, args ); + break; + + case Method_setActiveItem_12: + return setActiveItem_12( exec, self, args ); + break; + + case Method_sizeHint_13: + return sizeHint_13( exec, self, args ); + break; + + case Method_idAt_14: + return idAt_14( exec, self, args ); + break; + + case Method_idAt_15: + return idAt_15( exec, self, args ); + break; + + case Method_customWhatsThis_16: + return customWhatsThis_16( exec, self, args ); + break; + + case Method_insertTearOffHandle_17: + return insertTearOffHandle_17( exec, self, args ); + break; + + case Method_activateItemAt_18: + return activateItemAt_18( exec, self, args ); + break; + + case Method_itemGeometry_19: + return itemGeometry_19( exec, self, args ); + break; + + default: + break; + } + + QString msg = i18n( "QPopupMenuImp has no method with id '%1'" ).arg( id ); + return throwError(exec, msg,KJS::ReferenceError); +} + + +KJS::Value QPopupMenuImp::popup_3( KJS::ExecState *exec, KJS::Object &obj, const KJS::List &args ) +{ + + QPoint arg0 = extractQPoint(exec, args, 0); + + int arg1 = extractInt(exec, args, 1); + + instance->popup( + arg0, + arg1 ); + return KJS::Value(); // Returns void + +} + +KJS::Value QPopupMenuImp::updateItem_4( KJS::ExecState *exec, KJS::Object &obj, const KJS::List &args ) +{ + + int arg0 = extractInt(exec, args, 0); + + instance->updateItem( + arg0 ); + return KJS::Value(); // Returns void + +} + +KJS::Value QPopupMenuImp::setCheckable_5( KJS::ExecState *exec, KJS::Object &obj, const KJS::List &args ) +{ + + bool arg0 = extractBool(exec, args, 0); + + instance->setCheckable( + arg0 ); + return KJS::Value(); // Returns void + +} + +KJS::Value QPopupMenuImp::isCheckable_6( KJS::ExecState *exec, KJS::Object &obj, const KJS::List &args ) +{ + + bool ret; + ret = instance->isCheckable( ); + return KJS::Boolean( ret ); + +} + +KJS::Value QPopupMenuImp::setFont_7( KJS::ExecState *exec, KJS::Object &obj, const KJS::List &args ) +{ + + QFont arg0 = extractQFont(exec, args, 0); + + instance->setFont( + arg0 ); + return KJS::Value(); // Returns void + +} + +KJS::Value QPopupMenuImp::show_8( KJS::ExecState *exec, KJS::Object &obj, const KJS::List &args ) +{ + + instance->show( ); + return KJS::Value(); // Returns void + +} + +KJS::Value QPopupMenuImp::hide_9( KJS::ExecState *exec, KJS::Object &obj, const KJS::List &args ) +{ + + instance->hide( ); + return KJS::Value(); // Returns void + +} + +KJS::Value QPopupMenuImp::exec_10( KJS::ExecState *exec, KJS::Object &obj, const KJS::List &args ) +{ + + int ret; + ret = instance->exec( ); + return KJS::Number( ret ); + +} + +KJS::Value QPopupMenuImp::exec_11( KJS::ExecState *exec, KJS::Object &obj, const KJS::List &args ) +{ + + QPoint arg0 = extractQPoint(exec, args, 0); + + int arg1 = extractInt(exec, args, 1); + + int ret; + ret = instance->exec( + arg0, + arg1 ); + return KJS::Number( ret ); + +} + +KJS::Value QPopupMenuImp::setActiveItem_12( KJS::ExecState *exec, KJS::Object &obj, const KJS::List &args ) +{ + + int arg0 = extractInt(exec, args, 0); + + instance->setActiveItem( + arg0 ); + return KJS::Value(); // Returns void + +} + +KJS::Value QPopupMenuImp::sizeHint_13( KJS::ExecState *exec, KJS::Object &obj, const KJS::List &args ) +{ + QSize ret; + ret = instance->sizeHint( ); + + return convertToValue( exec, ret ); + +} + +KJS::Value QPopupMenuImp::idAt_14( KJS::ExecState *exec, KJS::Object &obj, const KJS::List &args ) +{ + + int arg0 = extractInt(exec, args, 0); + + int ret; + ret = instance->idAt( + arg0 ); + return KJS::Number( ret ); + +} + +KJS::Value QPopupMenuImp::idAt_15( KJS::ExecState *exec, KJS::Object &obj, const KJS::List &args ) +{ + + QPoint arg0 = extractQPoint(exec, args, 0); + + int ret; + ret = instance->idAt( + arg0 ); + return KJS::Number( ret ); + +} + +KJS::Value QPopupMenuImp::customWhatsThis_16( KJS::ExecState *exec, KJS::Object &obj, const KJS::List &args ) +{ + + bool ret; + ret = instance->customWhatsThis( ); + return KJS::Boolean( ret ); + +} + +KJS::Value QPopupMenuImp::insertTearOffHandle_17( KJS::ExecState *exec, KJS::Object &obj, const KJS::List &args ) +{ + + int arg0 = extractInt(exec, args, 0); + + int arg1 = extractInt(exec, args, 1); + + int ret; + ret = instance->insertTearOffHandle( + arg0, + arg1 ); + return KJS::Number( ret ); + +} + +KJS::Value QPopupMenuImp::activateItemAt_18( KJS::ExecState *exec, KJS::Object &obj, const KJS::List &args ) +{ + + int arg0 = extractInt(exec, args, 0); + + instance->activateItemAt( + arg0 ); + return KJS::Value(); // Returns void + +} + +KJS::Value QPopupMenuImp::itemGeometry_19( KJS::ExecState *exec, KJS::Object &obj, const KJS::List &args ) +{ + + int arg0 = extractInt(exec, args, 0); + QRect ret; + ret = instance->itemGeometry( + arg0 ); + + return convertToValue( exec, ret ); + +} + + +} // namespace KJSEmbed + +// Local Variables: +// c-basic-offset: 4 +// End: + + diff --git a/kjsembed/qtbindings/qpopupmenu_imp.h b/kjsembed/qtbindings/qpopupmenu_imp.h new file mode 100644 index 00000000..6695f486 --- /dev/null +++ b/kjsembed/qtbindings/qpopupmenu_imp.h @@ -0,0 +1,132 @@ + + + +#ifndef KJSEMBED_QPopupMenu_H +#define KJSEMBED_QPopupMenu_H + +#include <kjs/interpreter.h> +#include <kjs/object.h> + +#include <kjsembed/jsobjectproxy_imp.h> + +class QPopupMenu; + +/** + * Namespace containing the KJSEmbed library. + */ +namespace KJSEmbed { + +/** + * Wrapper class for QPopupMenu methods. + * + * @author Richard Moore, rich@kde.org + */ +class QPopupMenuImp : public JSProxyImp +{ +public: + /** Enumerates the constructors supported by this class. */ + enum Constructors { + Constructor_QPopupMenu_1, + + LastConstuctor = -1 + }; + + /** Enumerates the methods supported by this class. */ + enum Methods { + + Method_popup_3, + Method_updateItem_4, + Method_setCheckable_5, + Method_isCheckable_6, + Method_setFont_7, + Method_show_8, + Method_hide_9, + Method_exec_10, + Method_exec_11, + Method_setActiveItem_12, + Method_sizeHint_13, + Method_idAt_14, + Method_idAt_15, + Method_customWhatsThis_16, + Method_insertTearOffHandle_17, + Method_activateItemAt_18, + Method_itemGeometry_19, + Method_Last = -1 + }; + + QPopupMenuImp( KJS::ExecState *exec, int id, bool constructor=false ); + ~QPopupMenuImp(); + + /** + * Adds the static bindings for this class to the specified Object. The + * static bindings are the static methods and the enums of this class. + */ + static void addStaticBindings( KJS::ExecState *exec, KJS::Object &object ); + + /** + * Adds the bindings for this class to the specified Object. The bindings + * added are the instance methods of this class. + */ + static void addBindings( KJS::ExecState *exec, KJS::Object &object ); + + static QPopupMenu *toQPopupMenu( KJS::Object &object ); + + // + // Constructors implemented by this class. + // + + KJS::Object QPopupMenu_1( KJS::ExecState *exec, const KJS::List &args ); + + // + // Methods implemented by this class. + // + + KJS::Value popup_3( KJS::ExecState *exec, KJS::Object &obj, const KJS::List &args ); + KJS::Value updateItem_4( KJS::ExecState *exec, KJS::Object &obj, const KJS::List &args ); + KJS::Value setCheckable_5( KJS::ExecState *exec, KJS::Object &obj, const KJS::List &args ); + KJS::Value isCheckable_6( KJS::ExecState *exec, KJS::Object &obj, const KJS::List &args ); + KJS::Value setFont_7( KJS::ExecState *exec, KJS::Object &obj, const KJS::List &args ); + KJS::Value show_8( KJS::ExecState *exec, KJS::Object &obj, const KJS::List &args ); + KJS::Value hide_9( KJS::ExecState *exec, KJS::Object &obj, const KJS::List &args ); + KJS::Value exec_10( KJS::ExecState *exec, KJS::Object &obj, const KJS::List &args ); + KJS::Value exec_11( KJS::ExecState *exec, KJS::Object &obj, const KJS::List &args ); + KJS::Value setActiveItem_12( KJS::ExecState *exec, KJS::Object &obj, const KJS::List &args ); + KJS::Value sizeHint_13( KJS::ExecState *exec, KJS::Object &obj, const KJS::List &args ); + KJS::Value idAt_14( KJS::ExecState *exec, KJS::Object &obj, const KJS::List &args ); + KJS::Value idAt_15( KJS::ExecState *exec, KJS::Object &obj, const KJS::List &args ); + KJS::Value customWhatsThis_16( KJS::ExecState *exec, KJS::Object &obj, const KJS::List &args ); + KJS::Value insertTearOffHandle_17( KJS::ExecState *exec, KJS::Object &obj, const KJS::List &args ); + KJS::Value activateItemAt_18( KJS::ExecState *exec, KJS::Object &obj, const KJS::List &args ); + KJS::Value itemGeometry_19( KJS::ExecState *exec, KJS::Object &obj, const KJS::List &args ); + + // + // JS binding code. + // + + /** Returns true iff this object implements the construct function. */ + virtual bool implementsConstruct() const { return cons; } + + /** Invokes the construct function. */ + virtual KJS::Object construct( KJS::ExecState *exec, const KJS::List &args ); + + /** Returns true iff this object implements the call function. */ + virtual bool implementsCall() const { return !cons; } + + /** Invokes the call function. */ + virtual KJS::Value call( KJS::ExecState *exec, KJS::Object &self, const KJS::List &args ); + +private: + QPopupMenu *instance; // Temp + int id; + bool cons; +}; + +} // namespace KJSEmbed + +#endif // KJSEMBED_QPopupMenu_H + +// Local Variables: +// c-basic-offset: 4 +// End: + + diff --git a/kjsembed/qtbindings/qt_imp.cpp b/kjsembed/qtbindings/qt_imp.cpp new file mode 100644 index 00000000..ba72c824 --- /dev/null +++ b/kjsembed/qtbindings/qt_imp.cpp @@ -0,0 +1,780 @@ + + + +#include <qcstring.h> +#include <qpalette.h> +#include <qpixmap.h> +#include <qfont.h> + +#include <kjs/object.h> + +#include <kjsembed/global.h> +#include <kjsembed/jsobjectproxy.h> +#include <kjsembed/jsopaqueproxy.h> +#include <kjsembed/jsbinding.h> + +#include <qnamespace.h> +#include "qt_imp.h" + +/** + * Namespace containing the KJSEmbed library. + */ +namespace KJSEmbed { + +QtImp::QtImp( KJS::ExecState *exec, int mid, bool constructor ) + : JSProxyImp(exec), id(mid), cons(constructor) +{ +} + +QtImp::~QtImp() +{ +} + +/** + * Adds bindings for static methods and enum constants to the specified Object. + */ +void QtImp::addStaticBindings( KJS::ExecState *exec, KJS::Object &object ) +{ + JSProxy::MethodTable methods[] = { + + { 0, 0 } + }; + + int idx = 0; + QCString lastName; + + while( methods[idx].name ) { + if ( lastName != methods[idx].name ) { + QtImp *meth = new QtImp( exec, methods[idx].id ); + object.put( exec , methods[idx].name, KJS::Object(meth) ); + lastName = methods[idx].name; + } + ++idx; + } + + + // + // Define the enum constants + // + struct EnumValue { + const char *id; + int val; + }; + + EnumValue enums[] = { + + // enum ButtonState + { "NoButton", Qt::NoButton }, + { "LeftButton", Qt::LeftButton }, + { "RightButton", Qt::RightButton }, + { "MidButton", Qt::MidButton }, + { "MouseButtonMask", Qt::MouseButtonMask }, + { "ShiftButton", Qt::ShiftButton }, + { "ControlButton", Qt::ControlButton }, + { "AltButton", Qt::AltButton }, + { "MetaButton", Qt::MetaButton }, + { "KeyButtonMask", Qt::KeyButtonMask }, + { "Keypad", Qt::Keypad }, + // enum Orientation + { "Horizontal", Qt::Horizontal }, + { "Vertical", Qt::Vertical }, + // enum SortOrder + { "Ascending", Qt::Ascending }, + { "Descending", Qt::Descending }, + // enum AlignmentFlags + { "AlignAuto", Qt::AlignAuto }, + { "AlignLeft", Qt::AlignLeft }, + { "AlignRight", Qt::AlignRight }, + { "AlignHCenter", Qt::AlignHCenter }, + { "AlignJustify", Qt::AlignJustify }, + { "AlignHorizontal_Mask", Qt::AlignHorizontal_Mask }, + { "AlignTop", Qt::AlignTop }, + { "AlignBottom", Qt::AlignBottom }, + { "AlignVCenter", Qt::AlignVCenter }, + { "AlignVertical_Mask", Qt::AlignVertical_Mask }, + { "AlignCenter", Qt::AlignCenter }, + // enum TextFlags + { "SingleLine", Qt::SingleLine }, + { "DontClip", Qt::DontClip }, + { "ExpandTabs", Qt::ExpandTabs }, + { "ShowPrefix", Qt::ShowPrefix }, + { "WordBreak", Qt::WordBreak }, + { "BreakAnywhere", Qt::BreakAnywhere }, + { "DontPrint", Qt::DontPrint }, + { "Underline", Qt::Underline }, + { "Overline", Qt::Overline }, + { "StrikeOut", Qt::StrikeOut }, + { "IncludeTrailingSpaces", Qt::IncludeTrailingSpaces }, + { "NoAccel", Qt::NoAccel }, + // enum WidgetState + { "WState_Created", Qt::WState_Created }, + { "WState_Disabled", Qt::WState_Disabled }, + { "WState_Visible", Qt::WState_Visible }, + { "WState_ForceHide", Qt::WState_ForceHide }, + { "WState_OwnCursor", Qt::WState_OwnCursor }, + { "WState_MouseTracking", Qt::WState_MouseTracking }, + { "WState_CompressKeys", Qt::WState_CompressKeys }, + { "WState_BlockUpdates", Qt::WState_BlockUpdates }, + { "WState_InPaintEvent", Qt::WState_InPaintEvent }, + { "WState_Reparented", Qt::WState_Reparented }, + { "WState_ConfigPending", Qt::WState_ConfigPending }, + { "WState_Resized", Qt::WState_Resized }, + { "WState_AutoMask", Qt::WState_AutoMask }, + { "WState_Polished", Qt::WState_Polished }, + { "WState_DND", Qt::WState_DND }, + { "WState_Reserved0", Qt::WState_Reserved0 }, + { "WState_FullScreen", Qt::WState_FullScreen }, + { "WState_OwnSizePolicy", Qt::WState_OwnSizePolicy }, + { "WState_CreatedHidden", Qt::WState_CreatedHidden }, + { "WState_Maximized", Qt::WState_Maximized }, + { "WState_Minimized", Qt::WState_Minimized }, + { "WState_ForceDisabled", Qt::WState_ForceDisabled }, + { "WState_Exposed", Qt::WState_Exposed }, + { "WState_HasMouse", Qt::WState_HasMouse }, + // enum WidgetFlags + { "WType_TopLevel", Qt::WType_TopLevel }, + { "WType_Dialog", Qt::WType_Dialog }, + { "WType_Popup", Qt::WType_Popup }, + { "WType_Desktop", Qt::WType_Desktop }, + { "WType_Mask", Qt::WType_Mask }, + { "WStyle_Customize", Qt::WStyle_Customize }, + { "WStyle_NormalBorder", Qt::WStyle_NormalBorder }, + { "WStyle_DialogBorder", Qt::WStyle_DialogBorder }, + { "WStyle_NoBorder", Qt::WStyle_NoBorder }, + { "WStyle_Title", Qt::WStyle_Title }, + { "WStyle_SysMenu", Qt::WStyle_SysMenu }, + { "WStyle_Minimize", Qt::WStyle_Minimize }, + { "WStyle_Maximize", Qt::WStyle_Maximize }, + { "WStyle_MinMax", Qt::WStyle_MinMax }, + { "WStyle_Tool", Qt::WStyle_Tool }, + { "WStyle_StaysOnTop", Qt::WStyle_StaysOnTop }, + { "WStyle_ContextHelp", Qt::WStyle_ContextHelp }, + { "WStyle_Reserved", Qt::WStyle_Reserved }, + { "WStyle_Mask", Qt::WStyle_Mask }, + { "WDestructiveClose", Qt::WDestructiveClose }, + { "WPaintDesktop", Qt::WPaintDesktop }, + { "WPaintUnclipped", Qt::WPaintUnclipped }, + { "WPaintClever", Qt::WPaintClever }, + { "WResizeNoErase", Qt::WResizeNoErase }, + { "WMouseNoMask", Qt::WMouseNoMask }, + { "WStaticContents", Qt::WStaticContents }, + { "WRepaintNoErase", Qt::WRepaintNoErase }, + { "WX11BypassWM", Qt::WX11BypassWM }, + { "WWinOwnDC", Qt::WWinOwnDC }, + { "WMacNoSheet", Qt::WMacNoSheet }, + { "WMacDrawer", Qt::WMacDrawer }, + { "WGroupLeader", Qt::WGroupLeader }, + { "WShowModal", Qt::WShowModal }, + { "WNoMousePropagation", Qt::WNoMousePropagation }, + { "WSubWindow", Qt::WSubWindow }, + { "WStyle_Splash", Qt::WStyle_Splash }, + { "WNoAutoErase", Qt::WNoAutoErase }, + { "WNorthWestGravity", Qt::WNorthWestGravity }, + { "WType_Modal", Qt::WType_Modal }, + { "WStyle_Dialog", Qt::WStyle_Dialog }, + { "WStyle_NoBorderEx", Qt::WStyle_NoBorderEx }, + // enum WindowState + { "WindowNoState", Qt::WindowNoState }, + { "WindowMinimized", Qt::WindowMinimized }, + { "WindowMaximized", Qt::WindowMaximized }, + { "WindowFullScreen", Qt::WindowFullScreen }, + { "WindowActive", Qt::WindowActive }, + // enum ImageConversionFlags + { "ColorMode_Mask", Qt::ColorMode_Mask }, + { "AutoColor", Qt::AutoColor }, + { "ColorOnly", Qt::ColorOnly }, + { "MonoOnly", Qt::MonoOnly }, + { "AlphaDither_Mask", Qt::AlphaDither_Mask }, + { "ThresholdAlphaDither", Qt::ThresholdAlphaDither }, + { "OrderedAlphaDither", Qt::OrderedAlphaDither }, + { "DiffuseAlphaDither", Qt::DiffuseAlphaDither }, + { "NoAlpha", Qt::NoAlpha }, + { "Dither_Mask", Qt::Dither_Mask }, + { "DiffuseDither", Qt::DiffuseDither }, + { "OrderedDither", Qt::OrderedDither }, + { "ThresholdDither", Qt::ThresholdDither }, + { "DitherMode_Mask", Qt::DitherMode_Mask }, + { "AutoDither", Qt::AutoDither }, + { "PreferDither", Qt::PreferDither }, + { "AvoidDither", Qt::AvoidDither }, + // enum BGMode + { "TransparentMode", Qt::TransparentMode }, + { "OpaqueMode", Qt::OpaqueMode }, + // enum PaintUnit + { "PixelUnit", Qt::PixelUnit }, + { "LoMetricUnit", Qt::LoMetricUnit }, + { "HiMetricUnit", Qt::HiMetricUnit }, + { "LoEnglishUnit", Qt::LoEnglishUnit }, + { "HiEnglishUnit", Qt::HiEnglishUnit }, + { "TwipsUnit", Qt::TwipsUnit }, + // enum GUIStyle + { "MacStyle", Qt::MacStyle }, + { "WindowsStyle", Qt::WindowsStyle }, + { "Win3Style", Qt::Win3Style }, + { "PMStyle", Qt::PMStyle }, + { "MotifStyle", Qt::MotifStyle }, + // enum SequenceMatch + { "NoMatch", Qt::NoMatch }, + { "PartialMatch", Qt::PartialMatch }, + { "Identical", Qt::Identical }, + // enum Modifier + { "META", Qt::META }, + { "SHIFT", Qt::SHIFT }, + { "CTRL", Qt::CTRL }, + { "ALT", Qt::ALT }, + { "MODIFIER_MASK", Qt::MODIFIER_MASK }, + { "UNICODE_ACCEL", Qt::UNICODE_ACCEL }, + { "ASCII_ACCEL", Qt::ASCII_ACCEL }, + // enum Key + { "Key_Escape", Qt::Key_Escape }, + { "Key_Tab", Qt::Key_Tab }, + { "Key_Backtab", Qt::Key_Backtab }, + { "Key_BackTab", Qt::Key_BackTab }, + { "Key_Backspace", Qt::Key_Backspace }, + { "Key_BackSpace", Qt::Key_BackSpace }, + { "Key_Return", Qt::Key_Return }, + { "Key_Enter", Qt::Key_Enter }, + { "Key_Insert", Qt::Key_Insert }, + { "Key_Delete", Qt::Key_Delete }, + { "Key_Pause", Qt::Key_Pause }, + { "Key_Print", Qt::Key_Print }, + { "Key_SysReq", Qt::Key_SysReq }, + { "Key_Clear", Qt::Key_Clear }, + { "Key_Home", Qt::Key_Home }, + { "Key_End", Qt::Key_End }, + { "Key_Left", Qt::Key_Left }, + { "Key_Up", Qt::Key_Up }, + { "Key_Right", Qt::Key_Right }, + { "Key_Down", Qt::Key_Down }, + { "Key_Prior", Qt::Key_Prior }, + { "Key_PageUp", Qt::Key_PageUp }, + { "Key_Next", Qt::Key_Next }, + { "Key_PageDown", Qt::Key_PageDown }, + { "Key_Shift", Qt::Key_Shift }, + { "Key_Control", Qt::Key_Control }, + { "Key_Meta", Qt::Key_Meta }, + { "Key_Alt", Qt::Key_Alt }, + { "Key_CapsLock", Qt::Key_CapsLock }, + { "Key_NumLock", Qt::Key_NumLock }, + { "Key_ScrollLock", Qt::Key_ScrollLock }, + { "Key_F1", Qt::Key_F1 }, + { "Key_F2", Qt::Key_F2 }, + { "Key_F3", Qt::Key_F3 }, + { "Key_F4", Qt::Key_F4 }, + { "Key_F5", Qt::Key_F5 }, + { "Key_F6", Qt::Key_F6 }, + { "Key_F7", Qt::Key_F7 }, + { "Key_F8", Qt::Key_F8 }, + { "Key_F9", Qt::Key_F9 }, + { "Key_F10", Qt::Key_F10 }, + { "Key_F11", Qt::Key_F11 }, + { "Key_F12", Qt::Key_F12 }, + { "Key_F13", Qt::Key_F13 }, + { "Key_F14", Qt::Key_F14 }, + { "Key_F15", Qt::Key_F15 }, + { "Key_F16", Qt::Key_F16 }, + { "Key_F17", Qt::Key_F17 }, + { "Key_F18", Qt::Key_F18 }, + { "Key_F19", Qt::Key_F19 }, + { "Key_F20", Qt::Key_F20 }, + { "Key_F21", Qt::Key_F21 }, + { "Key_F22", Qt::Key_F22 }, + { "Key_F23", Qt::Key_F23 }, + { "Key_F24", Qt::Key_F24 }, + { "Key_F25", Qt::Key_F25 }, + { "Key_F26", Qt::Key_F26 }, + { "Key_F27", Qt::Key_F27 }, + { "Key_F28", Qt::Key_F28 }, + { "Key_F29", Qt::Key_F29 }, + { "Key_F30", Qt::Key_F30 }, + { "Key_F31", Qt::Key_F31 }, + { "Key_F32", Qt::Key_F32 }, + { "Key_F33", Qt::Key_F33 }, + { "Key_F34", Qt::Key_F34 }, + { "Key_F35", Qt::Key_F35 }, + { "Key_Super_L", Qt::Key_Super_L }, + { "Key_Super_R", Qt::Key_Super_R }, + { "Key_Menu", Qt::Key_Menu }, + { "Key_Hyper_L", Qt::Key_Hyper_L }, + { "Key_Hyper_R", Qt::Key_Hyper_R }, + { "Key_Help", Qt::Key_Help }, + { "Key_Direction_L", Qt::Key_Direction_L }, + { "Key_Direction_R", Qt::Key_Direction_R }, + { "Key_Space", Qt::Key_Space }, + { "Key_Any", Qt::Key_Any }, + { "Key_Exclam", Qt::Key_Exclam }, + { "Key_QuoteDbl", Qt::Key_QuoteDbl }, + { "Key_NumberSign", Qt::Key_NumberSign }, + { "Key_Dollar", Qt::Key_Dollar }, + { "Key_Percent", Qt::Key_Percent }, + { "Key_Ampersand", Qt::Key_Ampersand }, + { "Key_Apostrophe", Qt::Key_Apostrophe }, + { "Key_ParenLeft", Qt::Key_ParenLeft }, + { "Key_ParenRight", Qt::Key_ParenRight }, + { "Key_Asterisk", Qt::Key_Asterisk }, + { "Key_Plus", Qt::Key_Plus }, + { "Key_Comma", Qt::Key_Comma }, + { "Key_Minus", Qt::Key_Minus }, + { "Key_Period", Qt::Key_Period }, + { "Key_Slash", Qt::Key_Slash }, + { "Key_0", Qt::Key_0 }, + { "Key_1", Qt::Key_1 }, + { "Key_2", Qt::Key_2 }, + { "Key_3", Qt::Key_3 }, + { "Key_4", Qt::Key_4 }, + { "Key_5", Qt::Key_5 }, + { "Key_6", Qt::Key_6 }, + { "Key_7", Qt::Key_7 }, + { "Key_8", Qt::Key_8 }, + { "Key_9", Qt::Key_9 }, + { "Key_Colon", Qt::Key_Colon }, + { "Key_Semicolon", Qt::Key_Semicolon }, + { "Key_Less", Qt::Key_Less }, + { "Key_Equal", Qt::Key_Equal }, + { "Key_Greater", Qt::Key_Greater }, + { "Key_Question", Qt::Key_Question }, + { "Key_At", Qt::Key_At }, + { "Key_A", Qt::Key_A }, + { "Key_B", Qt::Key_B }, + { "Key_C", Qt::Key_C }, + { "Key_D", Qt::Key_D }, + { "Key_E", Qt::Key_E }, + { "Key_F", Qt::Key_F }, + { "Key_G", Qt::Key_G }, + { "Key_H", Qt::Key_H }, + { "Key_I", Qt::Key_I }, + { "Key_J", Qt::Key_J }, + { "Key_K", Qt::Key_K }, + { "Key_L", Qt::Key_L }, + { "Key_M", Qt::Key_M }, + { "Key_N", Qt::Key_N }, + { "Key_O", Qt::Key_O }, + { "Key_P", Qt::Key_P }, + { "Key_Q", Qt::Key_Q }, + { "Key_R", Qt::Key_R }, + { "Key_S", Qt::Key_S }, + { "Key_T", Qt::Key_T }, + { "Key_U", Qt::Key_U }, + { "Key_V", Qt::Key_V }, + { "Key_W", Qt::Key_W }, + { "Key_X", Qt::Key_X }, + { "Key_Y", Qt::Key_Y }, + { "Key_Z", Qt::Key_Z }, + { "Key_BracketLeft", Qt::Key_BracketLeft }, + { "Key_Backslash", Qt::Key_Backslash }, + { "Key_BracketRight", Qt::Key_BracketRight }, + { "Key_AsciiCircum", Qt::Key_AsciiCircum }, + { "Key_Underscore", Qt::Key_Underscore }, + { "Key_QuoteLeft", Qt::Key_QuoteLeft }, + { "Key_BraceLeft", Qt::Key_BraceLeft }, + { "Key_Bar", Qt::Key_Bar }, + { "Key_BraceRight", Qt::Key_BraceRight }, + { "Key_AsciiTilde", Qt::Key_AsciiTilde }, + { "Key_nobreakspace", Qt::Key_nobreakspace }, + { "Key_exclamdown", Qt::Key_exclamdown }, + { "Key_cent", Qt::Key_cent }, + { "Key_sterling", Qt::Key_sterling }, + { "Key_currency", Qt::Key_currency }, + { "Key_yen", Qt::Key_yen }, + { "Key_brokenbar", Qt::Key_brokenbar }, + { "Key_section", Qt::Key_section }, + { "Key_diaeresis", Qt::Key_diaeresis }, + { "Key_copyright", Qt::Key_copyright }, + { "Key_ordfeminine", Qt::Key_ordfeminine }, + { "Key_guillemotleft", Qt::Key_guillemotleft }, + { "Key_notsign", Qt::Key_notsign }, + { "Key_hyphen", Qt::Key_hyphen }, + { "Key_registered", Qt::Key_registered }, + { "Key_macron", Qt::Key_macron }, + { "Key_degree", Qt::Key_degree }, + { "Key_plusminus", Qt::Key_plusminus }, + { "Key_twosuperior", Qt::Key_twosuperior }, + { "Key_threesuperior", Qt::Key_threesuperior }, + { "Key_acute", Qt::Key_acute }, + { "Key_mu", Qt::Key_mu }, + { "Key_paragraph", Qt::Key_paragraph }, + { "Key_periodcentered", Qt::Key_periodcentered }, + { "Key_cedilla", Qt::Key_cedilla }, + { "Key_onesuperior", Qt::Key_onesuperior }, + { "Key_masculine", Qt::Key_masculine }, + { "Key_guillemotright", Qt::Key_guillemotright }, + { "Key_onequarter", Qt::Key_onequarter }, + { "Key_onehalf", Qt::Key_onehalf }, + { "Key_threequarters", Qt::Key_threequarters }, + { "Key_questiondown", Qt::Key_questiondown }, + { "Key_Agrave", Qt::Key_Agrave }, + { "Key_Aacute", Qt::Key_Aacute }, + { "Key_Acircumflex", Qt::Key_Acircumflex }, + { "Key_Atilde", Qt::Key_Atilde }, + { "Key_Adiaeresis", Qt::Key_Adiaeresis }, + { "Key_Aring", Qt::Key_Aring }, + { "Key_AE", Qt::Key_AE }, + { "Key_Ccedilla", Qt::Key_Ccedilla }, + { "Key_Egrave", Qt::Key_Egrave }, + { "Key_Eacute", Qt::Key_Eacute }, + { "Key_Ecircumflex", Qt::Key_Ecircumflex }, + { "Key_Ediaeresis", Qt::Key_Ediaeresis }, + { "Key_Igrave", Qt::Key_Igrave }, + { "Key_Iacute", Qt::Key_Iacute }, + { "Key_Icircumflex", Qt::Key_Icircumflex }, + { "Key_Idiaeresis", Qt::Key_Idiaeresis }, + { "Key_ETH", Qt::Key_ETH }, + { "Key_Ntilde", Qt::Key_Ntilde }, + { "Key_Ograve", Qt::Key_Ograve }, + { "Key_Oacute", Qt::Key_Oacute }, + { "Key_Ocircumflex", Qt::Key_Ocircumflex }, + { "Key_Otilde", Qt::Key_Otilde }, + { "Key_Odiaeresis", Qt::Key_Odiaeresis }, + { "Key_multiply", Qt::Key_multiply }, + { "Key_Ooblique", Qt::Key_Ooblique }, + { "Key_Ugrave", Qt::Key_Ugrave }, + { "Key_Uacute", Qt::Key_Uacute }, + { "Key_Ucircumflex", Qt::Key_Ucircumflex }, + { "Key_Udiaeresis", Qt::Key_Udiaeresis }, + { "Key_Yacute", Qt::Key_Yacute }, + { "Key_THORN", Qt::Key_THORN }, + { "Key_ssharp", Qt::Key_ssharp }, + { "Key_agrave", Qt::Key_agrave }, + { "Key_aacute", Qt::Key_aacute }, + { "Key_acircumflex", Qt::Key_acircumflex }, + { "Key_atilde", Qt::Key_atilde }, + { "Key_adiaeresis", Qt::Key_adiaeresis }, + { "Key_aring", Qt::Key_aring }, + { "Key_ae", Qt::Key_ae }, + { "Key_ccedilla", Qt::Key_ccedilla }, + { "Key_egrave", Qt::Key_egrave }, + { "Key_eacute", Qt::Key_eacute }, + { "Key_ecircumflex", Qt::Key_ecircumflex }, + { "Key_ediaeresis", Qt::Key_ediaeresis }, + { "Key_igrave", Qt::Key_igrave }, + { "Key_iacute", Qt::Key_iacute }, + { "Key_icircumflex", Qt::Key_icircumflex }, + { "Key_idiaeresis", Qt::Key_idiaeresis }, + { "Key_eth", Qt::Key_eth }, + { "Key_ntilde", Qt::Key_ntilde }, + { "Key_ograve", Qt::Key_ograve }, + { "Key_oacute", Qt::Key_oacute }, + { "Key_ocircumflex", Qt::Key_ocircumflex }, + { "Key_otilde", Qt::Key_otilde }, + { "Key_odiaeresis", Qt::Key_odiaeresis }, + { "Key_division", Qt::Key_division }, + { "Key_oslash", Qt::Key_oslash }, + { "Key_ugrave", Qt::Key_ugrave }, + { "Key_uacute", Qt::Key_uacute }, + { "Key_ucircumflex", Qt::Key_ucircumflex }, + { "Key_udiaeresis", Qt::Key_udiaeresis }, + { "Key_yacute", Qt::Key_yacute }, + { "Key_thorn", Qt::Key_thorn }, + { "Key_ydiaeresis", Qt::Key_ydiaeresis }, + { "Key_Back", Qt::Key_Back }, + { "Key_Forward", Qt::Key_Forward }, + { "Key_Stop", Qt::Key_Stop }, + { "Key_Refresh", Qt::Key_Refresh }, + { "Key_VolumeDown", Qt::Key_VolumeDown }, + { "Key_VolumeMute", Qt::Key_VolumeMute }, + { "Key_VolumeUp", Qt::Key_VolumeUp }, + { "Key_BassBoost", Qt::Key_BassBoost }, + { "Key_BassUp", Qt::Key_BassUp }, + { "Key_BassDown", Qt::Key_BassDown }, + { "Key_TrebleUp", Qt::Key_TrebleUp }, + { "Key_TrebleDown", Qt::Key_TrebleDown }, + { "Key_MediaPlay", Qt::Key_MediaPlay }, + { "Key_MediaStop", Qt::Key_MediaStop }, + { "Key_MediaPrev", Qt::Key_MediaPrev }, + { "Key_MediaNext", Qt::Key_MediaNext }, + { "Key_MediaRecord", Qt::Key_MediaRecord }, + { "Key_HomePage", Qt::Key_HomePage }, + { "Key_Favorites", Qt::Key_Favorites }, + { "Key_Search", Qt::Key_Search }, + { "Key_Standby", Qt::Key_Standby }, + { "Key_OpenUrl", Qt::Key_OpenUrl }, + { "Key_LaunchMail", Qt::Key_LaunchMail }, + { "Key_LaunchMedia", Qt::Key_LaunchMedia }, + { "Key_Launch0", Qt::Key_Launch0 }, + { "Key_Launch1", Qt::Key_Launch1 }, + { "Key_Launch2", Qt::Key_Launch2 }, + { "Key_Launch3", Qt::Key_Launch3 }, + { "Key_Launch4", Qt::Key_Launch4 }, + { "Key_Launch5", Qt::Key_Launch5 }, + { "Key_Launch6", Qt::Key_Launch6 }, + { "Key_Launch7", Qt::Key_Launch7 }, + { "Key_Launch8", Qt::Key_Launch8 }, + { "Key_Launch9", Qt::Key_Launch9 }, + { "Key_LaunchA", Qt::Key_LaunchA }, + { "Key_LaunchB", Qt::Key_LaunchB }, + { "Key_LaunchC", Qt::Key_LaunchC }, + { "Key_LaunchD", Qt::Key_LaunchD }, + { "Key_LaunchE", Qt::Key_LaunchE }, + { "Key_LaunchF", Qt::Key_LaunchF }, + { "Key_MediaLast", Qt::Key_MediaLast }, + { "Key_unknown", Qt::Key_unknown }, + // enum ArrowType + { "UpArrow", Qt::UpArrow }, + { "DownArrow", Qt::DownArrow }, + { "LeftArrow", Qt::LeftArrow }, + { "RightArrow", Qt::RightArrow }, + // enum RasterOp + { "CopyROP", Qt::CopyROP }, + { "OrROP", Qt::OrROP }, + { "XorROP", Qt::XorROP }, + { "NotAndROP", Qt::NotAndROP }, + { "EraseROP", Qt::EraseROP }, + { "NotCopyROP", Qt::NotCopyROP }, + { "NotOrROP", Qt::NotOrROP }, + { "NotXorROP", Qt::NotXorROP }, + { "AndROP", Qt::AndROP }, + { "NotEraseROP", Qt::NotEraseROP }, + { "NotROP", Qt::NotROP }, + { "ClearROP", Qt::ClearROP }, + { "SetROP", Qt::SetROP }, + { "NopROP", Qt::NopROP }, + { "AndNotROP", Qt::AndNotROP }, + { "OrNotROP", Qt::OrNotROP }, + { "NandROP", Qt::NandROP }, + { "NorROP", Qt::NorROP }, + { "LastROP", Qt::LastROP }, + // enum PenStyle + { "NoPen", Qt::NoPen }, + { "SolidLine", Qt::SolidLine }, + { "DashLine", Qt::DashLine }, + { "DotLine", Qt::DotLine }, + { "DashDotLine", Qt::DashDotLine }, + { "DashDotDotLine", Qt::DashDotDotLine }, + { "MPenStyle", Qt::MPenStyle }, + // enum PenCapStyle + { "FlatCap", Qt::FlatCap }, + { "SquareCap", Qt::SquareCap }, + { "RoundCap", Qt::RoundCap }, + { "MPenCapStyle", Qt::MPenCapStyle }, + // enum PenJoinStyle + { "MiterJoin", Qt::MiterJoin }, + { "BevelJoin", Qt::BevelJoin }, + { "RoundJoin", Qt::RoundJoin }, + { "MPenJoinStyle", Qt::MPenJoinStyle }, + // enum BrushStyle + { "NoBrush", Qt::NoBrush }, + { "SolidPattern", Qt::SolidPattern }, + { "Dense1Pattern", Qt::Dense1Pattern }, + { "Dense2Pattern", Qt::Dense2Pattern }, + { "Dense3Pattern", Qt::Dense3Pattern }, + { "Dense4Pattern", Qt::Dense4Pattern }, + { "Dense5Pattern", Qt::Dense5Pattern }, + { "Dense6Pattern", Qt::Dense6Pattern }, + { "Dense7Pattern", Qt::Dense7Pattern }, + { "HorPattern", Qt::HorPattern }, + { "VerPattern", Qt::VerPattern }, + { "CrossPattern", Qt::CrossPattern }, + { "BDiagPattern", Qt::BDiagPattern }, + { "FDiagPattern", Qt::FDiagPattern }, + { "DiagCrossPattern", Qt::DiagCrossPattern }, + { "CustomPattern", Qt::CustomPattern }, + // enum MacintoshVersion + { "MV_Unknown", Qt::MV_Unknown }, + { "MV_9", Qt::MV_9 }, + { "MV_10_DOT_0", Qt::MV_10_DOT_0 }, + { "MV_10_DOT_1", Qt::MV_10_DOT_1 }, + { "MV_10_DOT_2", Qt::MV_10_DOT_2 }, + { "MV_10_DOT_3", Qt::MV_10_DOT_3 }, + { "MV_CHEETAH", Qt::MV_CHEETAH }, + { "MV_PUMA", Qt::MV_PUMA }, + { "MV_JAGUAR", Qt::MV_JAGUAR }, + { "MV_PANTHER", Qt::MV_PANTHER }, + // enum WindowsVersion + { "WV_32s", Qt::WV_32s }, + { "WV_95", Qt::WV_95 }, + { "WV_98", Qt::WV_98 }, + { "WV_Me", Qt::WV_Me }, + { "WV_DOS_based", Qt::WV_DOS_based }, + { "WV_NT", Qt::WV_NT }, + { "WV_2000", Qt::WV_2000 }, + { "WV_XP", Qt::WV_XP }, + { "WV_2003", Qt::WV_2003 }, + { "WV_NT_based", Qt::WV_NT_based }, + { "WV_CE", Qt::WV_CE }, + { "WV_CENET", Qt::WV_CENET }, + { "WV_CE_based", Qt::WV_CE_based }, + // enum UIEffect + { "UI_General", Qt::UI_General }, + { "UI_AnimateMenu", Qt::UI_AnimateMenu }, + { "UI_FadeMenu", Qt::UI_FadeMenu }, + { "UI_AnimateCombo", Qt::UI_AnimateCombo }, + { "UI_AnimateTooltip", Qt::UI_AnimateTooltip }, + { "UI_FadeTooltip", Qt::UI_FadeTooltip }, + { "UI_AnimateToolBox", Qt::UI_AnimateToolBox }, + // enum CursorShape + { "ArrowCursor", Qt::ArrowCursor }, + { "UpArrowCursor", Qt::UpArrowCursor }, + { "CrossCursor", Qt::CrossCursor }, + { "WaitCursor", Qt::WaitCursor }, + { "IbeamCursor", Qt::IbeamCursor }, + { "SizeVerCursor", Qt::SizeVerCursor }, + { "SizeHorCursor", Qt::SizeHorCursor }, + { "SizeBDiagCursor", Qt::SizeBDiagCursor }, + { "SizeFDiagCursor", Qt::SizeFDiagCursor }, + { "SizeAllCursor", Qt::SizeAllCursor }, + { "BlankCursor", Qt::BlankCursor }, + { "SplitVCursor", Qt::SplitVCursor }, + { "SplitHCursor", Qt::SplitHCursor }, + { "PointingHandCursor", Qt::PointingHandCursor }, + { "ForbiddenCursor", Qt::ForbiddenCursor }, + { "WhatsThisCursor", Qt::WhatsThisCursor }, + { "BusyCursor", Qt::BusyCursor }, + { "LastCursor", Qt::LastCursor }, + { "BitmapCursor", Qt::BitmapCursor }, + // enum TextFormat + { "PlainText", Qt::PlainText }, + { "RichText", Qt::RichText }, + { "AutoText", Qt::AutoText }, + { "LogText", Qt::LogText }, + // enum AnchorAttribute + { "AnchorName", Qt::AnchorName }, + { "AnchorHref", Qt::AnchorHref }, + // enum Dock + { "DockUnmanaged", Qt::DockUnmanaged }, + { "DockTornOff", Qt::DockTornOff }, + { "DockTop", Qt::DockTop }, + { "DockBottom", Qt::DockBottom }, + { "DockRight", Qt::DockRight }, + { "DockLeft", Qt::DockLeft }, + { "DockMinimized", Qt::DockMinimized }, + { "Unmanaged", Qt::Unmanaged }, + { "TornOff", Qt::TornOff }, + { "Top", Qt::Top }, + { "Bottom", Qt::Bottom }, + { "Right", Qt::Right }, + { "Left", Qt::Left }, + { "Minimized", Qt::Minimized }, + // enum DateFormat + { "TextDate", Qt::TextDate }, + { "ISODate", Qt::ISODate }, + { "LocalDate", Qt::LocalDate }, + // enum TimeSpec + { "LocalTime", Qt::LocalTime }, + { "UTC", Qt::UTC }, + // enum BackgroundMode + { "FixedColor", Qt::FixedColor }, + { "FixedPixmap", Qt::FixedPixmap }, + { "NoBackground", Qt::NoBackground }, + { "PaletteForeground", Qt::PaletteForeground }, + { "PaletteButton", Qt::PaletteButton }, + { "PaletteLight", Qt::PaletteLight }, + { "PaletteMidlight", Qt::PaletteMidlight }, + { "PaletteDark", Qt::PaletteDark }, + { "PaletteMid", Qt::PaletteMid }, + { "PaletteText", Qt::PaletteText }, + { "PaletteBrightText", Qt::PaletteBrightText }, + { "PaletteBase", Qt::PaletteBase }, + { "PaletteBackground", Qt::PaletteBackground }, + { "PaletteShadow", Qt::PaletteShadow }, + { "PaletteHighlight", Qt::PaletteHighlight }, + { "PaletteHighlightedText", Qt::PaletteHighlightedText }, + { "PaletteButtonText", Qt::PaletteButtonText }, + { "PaletteLink", Qt::PaletteLink }, + { "PaletteLinkVisited", Qt::PaletteLinkVisited }, + { "X11ParentRelative", Qt::X11ParentRelative }, + // enum StringComparisonMode + { "CaseSensitive", Qt::CaseSensitive }, + { "BeginsWith", Qt::BeginsWith }, + { "EndsWith", Qt::EndsWith }, + { "Contains", Qt::Contains }, + { "ExactMatch", Qt::ExactMatch }, + // enum Corner + { "TopLeft", Qt::TopLeft }, + { "TopRight", Qt::TopRight }, + { "BottomLeft", Qt::BottomLeft }, + { "BottomRight", Qt::BottomRight }, + { 0, 0 } + }; + + int enumidx = 0; + while( enums[enumidx].id ) { + object.put( exec, enums[enumidx].id, KJS::Number(enums[enumidx].val), KJS::ReadOnly ); + ++enumidx; + } + +} + +/** + * Adds bindings for instance methods to the specified Object. + */ +void QtImp::addBindings( KJS::ExecState *exec, KJS::Object &object ) +{ + JSProxy::MethodTable methods[] = { + + { 0, 0 } + }; + + int idx = 0; + QCString lastName; + + while( methods[idx].name ) { + if ( lastName != methods[idx].name ) { + QtImp *meth = new QtImp( exec, methods[idx].id ); + object.put( exec , methods[idx].name, KJS::Object(meth) ); + lastName = methods[idx].name; + } + ++idx; + } +} + +/** + * Extract a Qt pointer from an Object. + */ +Qt *QtImp::toQt( KJS::Object &self ) +{ + JSObjectProxy *ob = JSProxy::toObjectProxy( self.imp() ); + if ( ob ) { + QObject *obj = ob->object(); + if ( obj ) + return dynamic_cast<Qt *>( obj ); + } + + JSOpaqueProxy *op = JSProxy::toOpaqueProxy( self.imp() ); + if ( !op ) + return 0; + + if ( op->typeName() != "Qt" ) + return 0; + + return op->toNative<Qt>(); +} + +/** + * Select and invoke the correct constructor. + */ +KJS::Object QtImp::construct( KJS::ExecState *exec, const KJS::List &args ) +{ + switch( id ) { + + default: + break; + } + + QString msg = i18n("QtCons has no constructor with id '%1'.").arg(id); + return throwError(exec, msg,KJS::ReferenceError); +} + + +KJS::Value QtImp::call( KJS::ExecState *exec, KJS::Object &self, const KJS::List &args ) +{ + instance = QtImp::toQt( self ); + + switch( id ) { + + default: + break; + } + + QString msg = i18n( "QtImp has no method with id '%1'." ).arg( id ); + return throwError(exec, msg,KJS::ReferenceError); +} + + + +} // namespace KJSEmbed + +// Local Variables: +// c-basic-offset: 4 +// End: + + diff --git a/kjsembed/qtbindings/qt_imp.h b/kjsembed/qtbindings/qt_imp.h new file mode 100644 index 00000000..6bc3b489 --- /dev/null +++ b/kjsembed/qtbindings/qt_imp.h @@ -0,0 +1,96 @@ + + + +#ifndef KJSEMBED_Qt_H +#define KJSEMBED_Qt_H + +#include <kjs/interpreter.h> +#include <kjs/object.h> + +#include <kjsembed/jsobjectproxy_imp.h> + +class Qt; + +/** + * Namespace containing the KJSEmbed library. + */ +namespace KJSEmbed { + +/** + * Wrapper class for Qt methods. + * + * @author Richard Moore, rich@kde.org + */ +class QtImp : public JSProxyImp +{ +public: + /** Enumerates the constructors supported by this class. */ + enum Constructors { + + LastConstuctor = -1 + }; + + /** Enumerates the methods supported by this class. */ + enum Methods { + + Method_Last = -1 + }; + + QtImp( KJS::ExecState *exec, int id, bool constructor=false ); + ~QtImp(); + + /** + * Adds the static bindings for this class to the specified Object. The + * static bindings are the static methods and the enums of this class. + */ + static void addStaticBindings( KJS::ExecState *exec, KJS::Object &object ); + + /** + * Adds the bindings for this class to the specified Object. The bindings + * added are the instance methods of this class. + */ + static void addBindings( KJS::ExecState *exec, KJS::Object &object ); + + static Qt *toQt( KJS::Object &object ); + + // + // Constructors implemented by this class. + // + + + // + // Methods implemented by this class. + // + + + // + // JS binding code. + // + + /** Returns true iff this object implements the construct function. */ + virtual bool implementsConstruct() const { return cons; } + + /** Invokes the construct function. */ + virtual KJS::Object construct( KJS::ExecState *exec, const KJS::List &args ); + + /** Returns true iff this object implements the call function. */ + virtual bool implementsCall() const { return !cons; } + + /** Invokes the call function. */ + virtual KJS::Value call( KJS::ExecState *exec, KJS::Object &self, const KJS::List &args ); + +private: + Qt *instance; // Temp + int id; + bool cons; +}; + +} // namespace KJSEmbed + +#endif // KJSEMBED_Qt_H + +// Local Variables: +// c-basic-offset: 4 +// End: + + diff --git a/kjsembed/qtbindings/qtbindings.pro b/kjsembed/qtbindings/qtbindings.pro new file mode 100644 index 00000000..eaaa1b7a --- /dev/null +++ b/kjsembed/qtbindings/qtbindings.pro @@ -0,0 +1,32 @@ +include(../qjsembed.pri) + +HEADERS += qcombobox_imp.h \ + qframe_imp.h \ + qlistviewitem_imp.h \ + qt_imp.h \ + qchecklistitem_imp.h + +SOURCES += \ + qlistviewitem_imp.cpp \ + qcombobox_imp.cpp \ + qframe_imp.cpp \ + qt_imp.cpp \ + qchecklistitem_imp.cpp \ + qcanvasellipse_imp.cpp \ + qcanvas_imp.cpp \ + qcanvasitem_imp.cpp \ + qcanvasitemlist_imp.cpp \ + qcanvasline_imp.cpp \ + qcanvaspixmaparray_imp.cpp \ + qcanvaspixmap_imp.cpp \ + qcanvaspolygonalitem_imp.cpp \ + qcanvaspolygon_imp.cpp \ + qcanvasrectangle_imp.cpp \ + qcanvasspline_imp.cpp \ + qcanvassprite_imp.cpp \ + qcanvastext_imp.cpp \ + qcanvasview_imp.cpp + +INCLUDEPATH += .. . ../.. +CONFIG += staticlib +TEMPLATE = lib diff --git a/kjsembed/qtstubs.cpp b/kjsembed/qtstubs.cpp new file mode 100644 index 00000000..0e78237a --- /dev/null +++ b/kjsembed/qtstubs.cpp @@ -0,0 +1,51 @@ +/*************************************************************************** + * Copyright (C) 2004 by Richard Moore * + * rich@kde.org * + * * + * This program 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. * + * * + * 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 Library 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. * + ***************************************************************************/ + +#include "qtstubs.h" + +#ifndef QT_ONLY +#include "qtstubs.moc" +#endif // QT_ONLY + +#ifdef QT_ONLY + +namespace KParts { + +ReadOnlyPart::ReadOnlyPart( QObject *parent, const char *name ) + : QObject( parent, name ), m_widget(0) +{ +} + +ReadOnlyPart::~ReadOnlyPart() +{ +} + +ReadWritePart::ReadWritePart( QObject *parent, const char *name ) + : ReadOnlyPart( parent, name ) +{ +} + +ReadWritePart::~ReadWritePart() +{ +} + +} // namespace KParts + +#endif // QT_ONLY diff --git a/kjsembed/qtstubs.h b/kjsembed/qtstubs.h new file mode 100644 index 00000000..24ddd739 --- /dev/null +++ b/kjsembed/qtstubs.h @@ -0,0 +1,76 @@ +// -*- c++ -*- +/*************************************************************************** + * Copyright (C) 2004 by Richard Moore * + * rich@kde.org * + * * + * This program 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. * + * * + * 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 Library 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. * + ***************************************************************************/ + +#ifndef QTSTUBS_H +#define QTSTUBS_H +#include "global.h" +#ifdef QT_ONLY + +#include <qobject.h> +#include <qurl.h> + +class QWidget; + +typedef QUrl KURL; + +namespace KParts { + +class KJSEMBED_EXPORT ReadOnlyPart : public QObject +{ + Q_OBJECT + +public: + ReadOnlyPart( QObject *parent, const char *name=0 ); + virtual ~ReadOnlyPart(); + + void setWidget( QWidget *w ) { m_widget = w; } + +private: + QWidget *m_widget; +}; + +class KJSEMBED_EXPORT ReadWritePart : public ReadOnlyPart +{ + Q_OBJECT + +public: + ReadWritePart( QObject *parent, const char *name=0 ); + virtual ~ReadWritePart(); +}; + +} // namespace KParts + +namespace KJSEmbed { + +class KJSEMBED_EXPORT XMLActionClientStub +{ +public: + XMLActionClientStub() {} + ~XMLActionClientStub() {} +}; + +typedef XMLActionClientStub XMLActionClient; + +} // namespace KJSEmbed + +#endif // QT_ONLY + +#endif // QTSTUBS_H diff --git a/kjsembed/setup_qtonly b/kjsembed/setup_qtonly new file mode 100755 index 00000000..c0a790ca --- /dev/null +++ b/kjsembed/setup_qtonly @@ -0,0 +1,54 @@ +#!/bin/sh + +# +# Sets a clean checkout of kjsembed for qt-only builds. +# + +# If there is no kjs tree then fetch one +if test ! -d kjs ; then + echo 'Setting up kjs tree' + + cvs co -l kdelibs + cd kdelibs + cvs up -dP kjs + mv kjs .. + cd .. + rm -rf kdelibs + + cd kjs + ln -s ../kjs.pro . + echo > config.h + perl create_hash_table keywords.table -i > lexer.lut.h + perl create_hash_table array_object.cpp -i > array_object.lut.h + perl create_hash_table math_object.cpp -i > math_object.lut.h + perl create_hash_table date_object.cpp -i > date_object.lut.h + perl create_hash_table number_object.cpp -i > number_object.lut.h + perl create_hash_table string_object.cpp -i > string_object.lut.h + cd .. +fi + +echo 'Running qmake' +cd kjs +qmake kjs.pro +cd ../builtins +qmake builtins.pro +cd ../qtbindings +qmake qtbindings.pro +cd .. +qmake kjsembed.pro +qmake -o Makefile.qjscmd qjscmd.pro + +echo 'Building KJSEmbed/Qt' + +echo ' + kjs...' +( cd kjs ; make ) +echo ' + builtins...' +( cd builtins ; make ) +echo ' + qtbindings...' +( cd qtbindings ; make ) +echo ' + lib...' +make +echo ' + app...' +make -f Makefile.qjscmd + +echo 'Done' diff --git a/kjsembed/slotproxy.cpp b/kjsembed/slotproxy.cpp new file mode 100644 index 00000000..7a99f056 --- /dev/null +++ b/kjsembed/slotproxy.cpp @@ -0,0 +1,276 @@ +/* + * Copyright (C) 2003-2004, Richard J. Moore <rich@kde.org> + * + * This 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. + * + * This 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 this library; see the file COPYING.LIB. If not, write to + * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, + * Boston, MA 02110-1301, USA. + */ + +#include <kjs/interpreter.h> + +#ifndef QT_ONLY +#include <kurl.h> +#else +#include "qtstubs.h" +#endif // QT_ONLY + +#include "jsopaqueproxy.h" +#include "global.h" +#include "jsbinding.h" +#include "jsfactory.h" +#include "jsobjectproxy.h" +#include "slotproxy.h" + +#include "kjsembedpart.h" + +#ifndef QT_ONLY +#include "slotproxy.moc" +#endif // QT_ONLY + +namespace KJSEmbed { + +JSSlotProxy::JSSlotProxy( QObject *parent, const char *name ) + : QObject( parent, name ? name : "slot_proxy" ), + proxy(0), js(0) +{ +} + +JSSlotProxy::JSSlotProxy( QObject *parent, const char *name, JSObjectProxy *prx ) + : QObject( parent, name ? name : "slot_proxy" ), + proxy(prx), js( prx ? prx->interpreter() : 0 ) +{ +} + +JSSlotProxy::~JSSlotProxy() +{ +} + +void JSSlotProxy::slot_void() +{ + execute( KJS::List() ); +} + +void JSSlotProxy::slot_bool( bool b ) +{ + KJS::List args; + args.append( KJS::Boolean(b) ); + execute( args ); +} + +void JSSlotProxy::slot_string( const QString &s ) +{ + KJS::List args; + args.append( KJS::String(s) ); + execute( args ); +} + +void JSSlotProxy::slot_int( int i ) +{ + KJS::List args; + args.append( KJS::Number(i) ); + execute( args ); +} + +void JSSlotProxy::slot_uint( uint i ) +{ + KJS::List args; + args.append( KJS::Number(i) ); + execute( args ); +} + +void JSSlotProxy::slot_long( long i ) +{ + KJS::List args; + args.append( KJS::Number(i) ); + execute( args ); +} + +void JSSlotProxy::slot_ulong( ulong i ) +{ + KJS::List args; + args.append( KJS::Number(i) ); + execute( args ); +} + +void JSSlotProxy::slot_double( double d ) +{ + KJS::List args; + args.append( KJS::Number(d) ); + execute( args ); +} + +void JSSlotProxy::slot_color( const QColor &color ) +{ + KJS::List args; + args.append( convertToValue(js->globalExec(), color) ); + execute( args ); +} + +void JSSlotProxy::slot_font( const QFont &font ) +{ + KJS::List args; + args.append( convertToValue(js->globalExec(), font) ); + execute( args ); +} +}// namespace KJSEmbed + + +void KJSEmbed::JSSlotProxy::slot_point( const QPoint & point ) +{ + KJS::List args; + args.append( convertToValue(js->globalExec(), point) ); + execute( args ); +} + +void KJSEmbed::JSSlotProxy::slot_rect( const QRect & rec ) +{ + KJS::List args; + args.append( convertToValue(js->globalExec(), rec) ); + execute( args ); +} + +void KJSEmbed::JSSlotProxy::slot_size( const QSize & size ) +{ + KJS::List args; + args.append( convertToValue(js->globalExec(), size) ); + execute( args ); +} + +void KJSEmbed::JSSlotProxy::slot_pixmap( const QPixmap & pix ) +{ + KJS::List args; + args.append( convertToValue(js->globalExec(), QVariant( pix ) ) ); + execute( args ); +} + +void KJSEmbed::JSSlotProxy::slot_url( const KURL & url ) +{ + KJS::List args; +#ifndef QT_ONLY + args.append( convertToValue(js->globalExec(), url.prettyURL() )); +#else // QT_ONLY + args.append( convertToValue(js->globalExec(), url.toString() )); +#endif // QT_ONLY + execute( args ); +} + +void KJSEmbed::JSSlotProxy::slot_intint( int arg, int arg1) +{ + KJS::List args; + args.append( convertToValue(js->globalExec(), arg )); + args.append( convertToValue(js->globalExec(), arg1 )); + execute( args ); +} +void KJSEmbed::JSSlotProxy::slot_intbool( int arg, bool arg1) +{ + KJS::List args; + args.append( convertToValue(js->globalExec(), arg )); + args.append( convertToValue(js->globalExec(), arg1 )); + execute( args ); +} + +void KJSEmbed::JSSlotProxy::slot_intintint( int arg, int arg1, int arg2) +{ + KJS::List args; + args.append( convertToValue(js->globalExec(), arg )); + args.append( convertToValue(js->globalExec(), arg1 )); + args.append( convertToValue(js->globalExec(), arg2 )); + execute( args ); +} + +void KJSEmbed::JSSlotProxy::execute( const KJS::List &args ) +{ + KJS::ExecState *exec = js->globalExec(); + KJS::Value val = obj.get( exec, KJS::Identifier(KJS::UString(method)) ); + KJS::Object fun = val.toObject( exec ); + + if ( !fun.implementsCall() ) { + kdDebug(80001) << "Target does not support call, class " + << fun.toString(exec).qstring() << " method " << method << endl; + return; + } + + fun.call( exec, obj, args ); + + if ( exec->hadException() ) { + kdWarning( 80001 ) << "Exception in slot function '" << method << "', " + << exec->exception().toString(exec).qstring() << endl; + + exec->clearException(); + } +} + +void KJSEmbed::JSSlotProxy::slot_widget( QWidget * widget ) +{ + KJS::List args; + if ( widget ) + args.append( proxy->part()->factory()->createProxy( js->globalExec(), widget ) ); + else + args.append( KJS::Null() ); + + execute( args ); +} + +void KJSEmbed::JSSlotProxy::slot_datetime( const QDateTime & dateTime ) +{ + KJS::List args; + args.append( convertToValue(js->globalExec(), QVariant( dateTime ) )); + execute( args ); +} + +void KJSEmbed::JSSlotProxy::slot_datedate( const QDate & date1, const QDate & date2 ) +{ + KJS::List args; + args.append( convertToValue(js->globalExec(), QVariant( date1 ) )); + args.append( convertToValue(js->globalExec(), QVariant( date2 ) )); + execute( args ); +} + +void KJSEmbed::JSSlotProxy::slot_colorstring( const QColor & color, const QString & string ) +{ + KJS::List args; + args.append( convertToValue(js->globalExec(), color )); + args.append( convertToValue(js->globalExec(), string )); + execute( args ); +} + +void KJSEmbed::JSSlotProxy::slot_image( const QImage & image ) +{ + KJS::List args; + args.append( convertToValue(js->globalExec(), QVariant( image ) )); + execute( args ); +} + +void KJSEmbed::JSSlotProxy::slot_date( const QDate & date ) +{ + KJS::List args; + args.append( convertToValue(js->globalExec(), QVariant( date ) )); + execute( args ); +} + +void KJSEmbed::JSSlotProxy::slot_time( const QTime &time ) +{ + KJS::List args; + args.append( convertToValue(js->globalExec(), QVariant( time ) )); + execute( args ); +} + +void KJSEmbed::JSSlotProxy::slot_variant( const QVariant & variant ) +{ + KJS::List args; + args.append( convertToValue(js->globalExec(), variant ) ); + execute( args ); +} + + diff --git a/kjsembed/slotproxy.h b/kjsembed/slotproxy.h new file mode 100644 index 00000000..3df42215 --- /dev/null +++ b/kjsembed/slotproxy.h @@ -0,0 +1,110 @@ +// -*- c++ -*- + +/* + * Copyright (C) 2003-2004, Richard J. Moore <rich@kde.org> + * + * This 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. + * + * This 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 this library; see the file COPYING.LIB. If not, write to + * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, + * Boston, MA 02110-1301, USA. + */ + +#ifndef KJSEMBED_SLOTPROXY_H +#define KJSEMBED_SLOTPROXY_H +#include <kjsembed/global.h> + +#include <kjs/object.h> +#include <qobject.h> + +#ifndef QT_ONLY +#include <kurl.h> +#else +#include <kjsembed/qtstubs.h> +#endif // QT_ONLY + +class QDate; +class QTime; +class QDateTime; + +namespace KJS { +class Interpreter; +} + +namespace KJSEmbed { + +class JSObjectProxy; + +/** + * Allows slots to be connected to methods of a JS object. + * + * @author Richard Moore, rich@kde.org + */ +class KJSEMBED_EXPORT JSSlotProxy : public QObject +{ + Q_OBJECT + +public: + JSSlotProxy( QObject *parent, const char *name=0 ); + JSSlotProxy( QObject *parent, const char *name, JSObjectProxy *prx ); + + virtual ~JSSlotProxy(); + + void setInterpreter( KJS::Interpreter *js ) { this->js = js; } + void setProxy( JSObjectProxy *proxy ) { this->proxy = proxy; } + void setObject( const KJS::Object &obj ) { this->obj = obj; } + void setMethod( const QString &method ) { this->method = method; } + +public slots: + void slot_void(); + void slot_bool( bool b ); + void slot_string( const QString &s ); + void slot_int( int i ); + void slot_uint( uint i ); + void slot_long( long i ); + void slot_ulong( ulong i ); + void slot_double( double d ); + void slot_font( const QFont &font ); + void slot_color( const QColor &color ); + void slot_point( const QPoint &point ); + void slot_rect( const QRect &rec ); + void slot_size( const QSize &size ); + void slot_pixmap( const QPixmap &pix ); + void slot_url( const KURL &url ); + void slot_intint( int , int ); + void slot_intbool( int , bool ); + void slot_intintint( int , int , int ); + + void slot_date(const QDate& date); + void slot_time(const QTime& time); + void slot_datetime( const QDateTime &dateTime ); + void slot_datedate( const QDate &date1, const QDate &date2 ); + void slot_colorstring( const QColor &color, const QString &string); + void slot_image( const QImage &image ); + + void slot_variant( const QVariant &variant ); + + void slot_widget( QWidget *widget ); + +private: + void execute( const KJS::List &args ); + JSObjectProxy *proxy; + KJS::Interpreter *js; + KJS::Object obj; + QString method; + class SlotProxyPrivate *d; +}; + +} // namespace KJSEmbed + +#endif // KJSEMBED_SLOTPROXY_H + diff --git a/kjsembed/slotutils.cpp b/kjsembed/slotutils.cpp new file mode 100644 index 00000000..58670e21 --- /dev/null +++ b/kjsembed/slotutils.cpp @@ -0,0 +1,879 @@ +/* + * Copyright (C) 2001-2003, Richard J. Moore <rich@kde.org> + * + * This 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. + * + * This 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 this library; see the file COPYING.LIB. If not, write to + * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, + * Boston, MA 02110-1301, USA. + */ + +#include <qobject.h> +#include <qobjectlist.h> +#include <qdialog.h> +#include <qlistbox.h> +#include <qlistview.h> +#include <qmetaobject.h> +#include <qregexp.h> +#include <qsignal.h> +#include <qstrlist.h> +#include <qtimer.h> +#include <qvariant.h> +#include <qdatetime.h> +#include <qstringlist.h> + +#include <private/qucom_p.h> +#include <private/qucomextra_p.h> + +#ifndef QT_ONLY +#include <klistview.h> +#include <kurl.h> +#else // QT_ONLY +#include "qtstubs.h" +#endif // QT_ONLY + +#include <kjs/interpreter.h> +#include <kjs/types.h> +#include <kjs/ustring.h> + +#include "kjsembedpart.h" +#include "jssecuritypolicy.h" + +#include "global.h" +#include "jsfactory.h" +#include "slotproxy.h" +#include "jsvalueproxy.h" +#include "jsopaqueproxy.h" + +#include "jsobjectproxy_imp.h" + +#include "slotutils.h" + +namespace KJSEmbed { +namespace Bindings { + +JSSlotUtils::JSSlotUtils() +{ +} + +JSSlotUtils::~JSSlotUtils() +{ +} + +bool JSSlotUtils::connect( QObject *sender, const char *sig, QObject *recv, const char *dest ) +{ + if ( (!sender) || (!recv) ) + return false; + + // Source + QString si = QString("2%1").arg(sig); + const char *sigc = si.ascii(); + + // Connect to slot + if ( recv->metaObject()->findSlot(dest, true) >= 0 ) { + QString sl = QString("1%1").arg(dest); + const char *slotc = sl.ascii(); + + //kdDebug(80001) << "connect: "<<sender->name()<<" "<<sigc<<", slot "<<recv->name()<<" "<<slotc<< endl; + bool ok = QObject::connect( sender, sigc, recv, slotc ); + if (ok) + return true; + } + + // Connect to signal + if ( recv->metaObject()->findSignal(dest, true) >= 0 ) { + QString si2 = QString("2%1").arg(dest); + const char *sig2c = si2.ascii(); + + kdDebug(80001) << "connect: "<<sender->name()<<" "<<sigc<<", sig "<<recv->name()<<" "<<sig2c<< endl; + bool ok = QObject::connect( sender, sigc, recv, sig2c ); + if (ok) + return true; + } + + return false; +} + +KJS::Boolean JSSlotUtils::disconnect( KJS::ExecState */*exec*/, KJS::Object &/*self*/, + QObject *sender, const char *sig, + QObject *recv, const char *dest ) +{ + if ( (!sender) || (!recv) ) + return KJS::Boolean(false); + + bool ok; + + // Source + QString si = QString("2%1").arg(sig); + const char *sigc = si.ascii(); + + // Disconnect from slot + if ( recv->metaObject()->findSlot(dest, true) >= 0 ) { + QString sl = QString("1%1").arg(dest); + const char *slotc = sl.ascii(); + + //kdDebug(80001) << "disconnect: "<<sender->name()<<" "<<sigc<<", slot "<<recv->name()<<" "<<slotc<< endl; + ok = QObject::disconnect( sender, sigc, recv, slotc ); + if (ok) + return KJS::Boolean(ok); + } + + // Disonnect to signal + if ( recv->metaObject()->findSignal(dest, true) >= 0 ) { + QString si2("2"); + si2 = si2 + dest; + const char *sig2c = si2.ascii(); + + //kdDebug(80001)<< "disconnect: "<<sender->name()<<" "<<sigc<<", sig "<<recv->name()<<" "<<sig2c<< endl; + ok = QObject::disconnect( sender, sigc, recv, sig2c ); + if (ok) + return KJS::Boolean(ok); + } + + return KJS::Boolean(false); +} + +KJS::Value JSSlotUtils::extractValue( KJS::ExecState *exec, QUObject *uo, JSObjectProxy *parent ) +{ + QCString typenm( uo->type->desc() ); + kdDebug(80001) << "JSSlotUtils:extractValue() " << typenm << endl; + + if ( typenm == "null" ) + return KJS::Null(); + else if ( typenm == "bool" ) + return KJS::Boolean( static_QUType_bool.get(uo) ); + else if ( typenm == "int" ) + return KJS::Number( static_QUType_int.get(uo) ); + else if ( typenm == "double" ) + return KJS::Number( static_QUType_double.get(uo) ); + else if ( typenm == "charstar" ) + return KJS::String( static_QUType_charstar.get(uo) ); + else if ( typenm == "QString" ) + return KJS::String( static_QUType_QString.get(uo) ); + else if ( typenm == "QVariant" ) + return convertToValue( exec, static_QUType_QVariant.get(uo) ); + else if ( typenm == "ptr" ) { + void *ptr = static_QUType_ptr.get(uo); + + // If it's a QObject and we know the parent + if ( ptr && parent ) { + QObject *qobj = (QObject *)(ptr); // Crash in kst + return parent->part()->factory()->createProxy( exec, qobj, parent); + } + } + + kdWarning(80001) << "JSSlotUtils:extractValue() Failed (" << typenm << ")" << endl; + QString msg = i18n( "Value of type (%1) is not supported." ).arg( typenm ); + throwError(exec, msg,KJS::TypeError); + return KJS::Null(); +} + +// +// Add a value to a QUObject. +// + +void JSSlotUtils::implantInt( KJS::ExecState *exec, QUObject *uo, const KJS::Value &v ) +{ + static_QUType_int.set( uo, v.toInteger( exec ) ); +} + +void JSSlotUtils::implantCharStar( KJS::ExecState *exec, QUObject *uo, const KJS::Value &v ) +{ + static_QUType_charstar.set( uo, v.toString( exec ).ascii() ); +} + +void JSSlotUtils::implantBool( KJS::ExecState *exec, QUObject *uo, const KJS::Value &v ) +{ + static_QUType_bool.set( uo, v.toBoolean( exec ) ); +} + +void JSSlotUtils::implantDouble( KJS::ExecState *exec, QUObject *uo, const KJS::Value &v ) +{ + static_QUType_double.set( uo, v.toNumber( exec ) ); +} + +void JSSlotUtils::implantQString( KJS::ExecState *exec, QUObject *uo, const KJS::Value &v ) +{ + static_QUType_QString.set( uo, v.toString(exec).qstring() ); +} + +void JSSlotUtils::implantCString( KJS::ExecState *exec, QUObject *uo, const KJS::Value &v ) +{ + static_QUType_charstar.set( uo, v.toString(exec).ascii() ); +} + +void JSSlotUtils::implantURL( KJS::ExecState *exec, QUObject *uo, const KJS::Value &v,KURL *url ) +{ + *url = QString( v.toString(exec).qstring() ); + static_QUType_ptr.set( uo, url ); +} + +void JSSlotUtils::implantColor( KJS::ExecState *exec, QUObject *uo, const KJS::Value &v, QColor *color ) +{ + bool ok; + QString s( v.toString(exec).qstring() ); + + if ( s.startsWith("#") ) { + + QRegExp re("#([0-9a-f][0-9a-f]){3,4}"); + re.setCaseSensitive( false ); + + if ( re.search(s) != -1 ) { + uint r = re.cap(1).toUInt(&ok, 16); + uint g = re.cap(2).toUInt(&ok, 16); + uint b = re.cap(3).toUInt(&ok, 16); + + if ( re.numCaptures() == 3 ) + *color = QColor(r,g,b); + else if ( re.numCaptures() == 4 ) { + uint a = re.cap(4).toUInt(&ok, 16); + uint pix = r; + pix = pix << 8; + pix = pix | g; + pix = pix << 8; + pix = pix | b; + pix = pix << 8; + pix = pix | a; + + *color = QColor( qRgba(r,g,b,a), pix ); + } + } + + } + else { + // Try for a named color + *color = QColor( s ); + } + + static_QUType_ptr.set( uo, color ); +} + +void JSSlotUtils::implantPoint( KJS::ExecState *exec, QUObject *uo, const KJS::Value &v, QPoint *point ) +{ + KJS::Object o = v.toObject( exec ); + if ( !o.isValid() ) + return; + + int x, y; + KJS::Identifier zero("0"), one("1"), ex("x"), wi("y"); + + if ( o.hasProperty(exec, zero) && o.hasProperty(exec, one) ) { + x = o.get( exec, zero ).toInteger(exec); + y = o.get( exec, one ).toInteger(exec); + } + else if ( o.hasProperty(exec, ex) && o.hasProperty(exec, wi) ) { + x = o.get( exec, ex ).toInteger(exec); + y = o.get( exec, wi ).toInteger(exec); + } + else + return; + + *point = QPoint( x, y ); + static_QUType_ptr.set( uo, point ); +} + +void JSSlotUtils::implantSize( KJS::ExecState *exec, QUObject *uo, const KJS::Value &v, QSize *size ) +{ + KJS::Object o = v.toObject( exec ); + if ( !o.isValid() ) + return; + + int w, h; + KJS::Identifier zero("0"), one("1"), wid("width"), hih("height"); + + if ( o.hasProperty(exec, zero) && o.hasProperty(exec, one) ) { + w = o.get( exec, zero ).toInteger(exec); + h = o.get( exec, one ).toInteger(exec); + } + else if ( o.hasProperty(exec, wid) && o.hasProperty(exec, hih) ) { + w = o.get( exec, wid ).toInteger(exec); + h = o.get( exec, hih ).toInteger(exec); + } + else + return; + + *size = QSize( w, h ); + static_QUType_ptr.set( uo, size ); +} + +void JSSlotUtils::implantRect( KJS::ExecState *exec, QUObject *uo, const KJS::Value &v, QRect *rect ) +{ + KJS::Object o = v.toObject( exec ); + if ( !o.isValid() ) + return; + + int x, y, w, h; + KJS::Identifier zero("0"), one("1"), two("2"), three("3"); + KJS::Identifier ex("x"), wi("y"), wid("width"), hih("height"); + + if ( o.hasProperty(exec, zero) && o.hasProperty(exec, one) + && o.hasProperty(exec, two) && o.hasProperty(exec, three) ) { + x = o.get( exec, zero ).toInteger(exec); + y = o.get( exec, one ).toInteger(exec); + w = o.get( exec, two ).toInteger(exec); + h = o.get( exec, three ).toInteger(exec); + } + else if ( o.hasProperty(exec, ex) && o.hasProperty(exec, wi) + && o.hasProperty(exec, wid) && o.hasProperty(exec, hih) ) { + x = o.get( exec, ex ).toInteger(exec); + y = o.get( exec, wi ).toInteger(exec); + w = o.get( exec, wid ).toInteger(exec); + h = o.get( exec, hih ).toInteger(exec); + } + else + return; + + *rect = QRect( x, y, w, h ); + static_QUType_ptr.set( uo, rect ); +} + +void JSSlotUtils::implantDate( KJS::ExecState *exec, QUObject *uo, const KJS::Value &v, QDate *date ) +{ + QDateTime jsDate = convertDateToDateTime(exec, v); + date->setYMD( jsDate.date().year(), jsDate.date().month(), jsDate.date().day() ); + static_QUType_ptr.set( uo, date ); +} + +void JSSlotUtils::implantStringList(KJS::ExecState *exec, QUObject *uo, const KJS::Value &v, QStringList *lst ) +{ + *lst = convertArrayToStringList(exec,v); + static_QUType_ptr.set(uo,lst); +} + +void JSSlotUtils::implantTime( KJS::ExecState *exec, QUObject *uo, const KJS::Value &v, QTime *time ) +{ + QDateTime jsDate = convertDateToDateTime(exec, v); + time->setHMS( jsDate.time().hour(), jsDate.time().minute(), jsDate.time().second() ); + static_QUType_ptr.set( uo, time ); +} + +void JSSlotUtils::implantDateTime( KJS::ExecState *exec, QUObject *uo, const KJS::Value &v, QDateTime *datetime ) +{ + QDateTime jsDate = convertDateToDateTime(exec, v); + datetime->setDate( jsDate.date() ); + datetime->setTime( jsDate.time() ); + static_QUType_ptr.set( uo, datetime ); +} + +void JSSlotUtils::implantPixmap( KJS::ExecState *exec, QUObject *uo, const KJS::Value &v, QPixmap *pix ) +{ + *pix = convertToVariant(exec, v).toPixmap() ; + static_QUType_ptr.set( uo, pix ); +} + +bool JSSlotUtils::implantQVariant( KJS::ExecState *, QUObject *uo, const KJS::Value &v) +{ + JSValueProxy *prx = JSProxy::toValueProxy( v.imp() ); + if ( !prx ) + return false; + kdDebug(80001) << "We got a " << prx->typeName() << endl; + + static_QUType_QVariant.set( uo, prx->toVariant() ); + return true; +} + +bool JSSlotUtils::implantValueProxy( KJS::ExecState *, QUObject *uo, + const KJS::Value &val, const QString &clazz ) +{ + JSValueProxy *prx = JSProxy::toValueProxy( val.imp() ); + if ( !prx ) + return false; + if ( prx->typeName() != clazz ) + return false; + + kdDebug(80001) << "We got a " << prx->typeName() << " and is valid " << prx->toVariant().isValid() << endl; + QVariant var = prx->toVariant(); + kdDebug(80001) << "We got a " << var.typeName()<< " and is valid " << var.isValid() << endl; + static_QUType_QVariant.set( uo, var ); + return var.isValid(); +} + +bool JSSlotUtils::implantOpaqueProxy( KJS::ExecState *, QUObject *uo, + const KJS::Value &v, const QString &clazz ) +{ + JSOpaqueProxy *prx = JSProxy::toOpaqueProxy( v.imp() ); + if ( !prx ) + return false; + if ( prx->typeName() != clazz ) + return false; + + static_QUType_ptr.set( uo, prx->toNative<void>() ); + return true; +} + +bool JSSlotUtils::implantObjectProxy( KJS::ExecState *, QUObject *uo, + const KJS::Value &v, const QString &clazz ) +{ + JSObjectProxy *prx = JSProxy::toObjectProxy( v.imp() ); + if ( !prx ) + return false; + + if ( !prx->object()->inherits( clazz.latin1() ) ) + return false; + + static_QUType_ptr.set( uo, prx->toObjectProxy()->object() ); + return true; +} + +int JSSlotUtils::findSignature( const QString &sig ) +{ + // No args + if ( sig.contains("()") ) + return SignatureNone; + + // One arg + if ( sig.contains("(int)") ) + return SignatureInt; + else if ( sig.contains("(uint)") ) + return SignatureUInt; + else if ( sig.contains("(long)") ) + return SignatureLong; + else if ( sig.contains("(ulong)") ) + return SignatureULong; + else if ( sig.contains("(bool)") ) + return SignatureBool; + else if ( sig.contains("(double)") ) + return SignatureDouble; + + else if ( sig.contains("(const QString&)") ) + return SignatureString; + else if ( sig.contains("(const QCString&)") ) + return SignatureCString; + else if ( sig.contains("(const char*)") ) + return SignatureCString; + else if ( sig.contains("(const KURL&)") ) + return SignatureURL; + else if ( sig.contains("(const QColor&)") ) + return SignatureColor; + else if ( sig.contains("(const QPoint&)") ) + return SignaturePoint; + else if ( sig.contains("(const QRect&)") ) + return SignatureRect; + else if ( sig.contains("(const QSize&)") ) + return SignatureSize; + else if ( sig.contains("(const QPixmap&)") ) + return SignaturePixmap; + else if ( sig.contains("(const QFont&)") ) + return SignatureFont; + else if ( sig.contains("(const QDate&)") ) + return SignatureDate; + else if ( sig.contains("(const QTime&)") ) + return SignatureTime; + else if ( sig.contains("(const QDateTime&)") ) + return SignatureDateTime; + else if ( sig.contains("(const QImage&)") ) + return SignatureImage; + else if ( sig.contains("(QWidget*)") ) + return SignatureQWidget; + // Two args + else if ( sig.contains("(const QDate&, const QDate&)") ) + return SignatureDateDate; + else if ( sig.contains("(const QColor&, const QString&)") ) + return SignatureColorString; + + else if ( sig.contains("(const QString&,const QString&,const QString&)") ) + return SignatureStringStringString; + + else if ( sig.contains("(const QString&,const QString&)") ) + return SignatureStringString; + else if ( sig.contains("(int,int)") ) + return SignatureIntInt; + else if ( sig.contains("(int,int,int,int)") ) + return SignatureIntIntIntInt; + else if ( sig.contains("(int,int,int,int,int)") ) + return SignatureIntIntIntIntInt; + else if ( sig.contains("(int,int,int,int,bool)") ) + return SignatureIntIntIntIntBool; + + else if ( sig.contains("(const QString&,int)") ) + return SignatureStringInt; + else if ( sig.contains("(const QString&,uint)") ) + return SignatureStringInt; + + else if ( sig.contains("(const KURL&,const KURL&)") ) + return SignatureURLURL; + else if ( sig.contains("(const KURL&,const QString&)") ) + return SignatureURLString; + else if ( sig.contains("(const QString&,const KURL&)") ) + return SignatureStringURL; + else if ( sig.contains("(const QRect&,bool)") ) + return SignatureRectBool; + else if ( sig.contains("(const QString&,bool)") ) + return SignatureStringBool; + else if ( sig.contains("(int,bool)") ) + return SignatureIntBool; + else if ( sig.contains("(int,int,bool)") ) + return SignatureIntIntBool; + else if ( sig.contains("(int,int,const QString&)") ) + return SignatureIntIntString; + else if ( sig.contains("(const QString&,bool,int)") ) + return SignatureStringBoolInt; + else if ( sig.contains("(const QString&,bool,bool)") ) + return SignatureStringBoolBool; + else if ( sig.contains("(const QString&,int,int)") ) + return SignatureStringIntInt; + else if ( sig.contains("(int,const QColor&,bool)") ) + return SignatureIntColorBool; + else if ( sig.contains("(int,const QColor&)") ) + return SignatureIntColor; + + else if ( sig.contains("(int,int,float,float)") ) + return SignatureIntIntFloatFloat; + else if ( sig.contains("(const QString&,bool,bool,bool)") ) + return SignatureStringBoolBoolBool; + else if ( sig.contains("(int,int,int,int,int,int)") ) + return SignatureIntIntIntIntIntInt; + + // Handle anything that falls through + if ( sig.contains("QString") || sig.contains("QColor") || + sig.contains("int") || sig.contains("bool") || + sig.contains("float") || sig.contains("KURL") || + sig.contains("QVariant") || sig.contains("QSize") || + sig.contains("QRect") || sig.contains("QPixmap") || + sig.contains("QCString") || sig.contains("QPoint") || + sig.contains("double") || sig.contains("QFont") || + sig.contains("QDate") || sig.contains("QTime") || + sig.contains("QDateTime") || sig.contains("QStringList") || + sig.contains("QWidget") || sig.contains("QObject") || + sig.contains("QPen") || sig.contains("QImage") ) + return SignatureCustom; + + kdWarning(80001) << "findSignature: not supported type " << sig << endl; + return SignatureNotSupported; +} + +#define MAX_SUPPORTED_ARGS (12) + +KJS::Value JSSlotUtils::invokeSlot( KJS::ExecState *exec, KJS::Object &, const KJS::List &args, + JSObjectProxyImp *proxyimp ) +{ + QUObject uo[ MAX_SUPPORTED_ARGS ] = { QUObject(), QUObject(), QUObject(), + QUObject(), QUObject(), QUObject(), + QUObject(), QUObject(), QUObject(), + QUObject(), QUObject(), QUObject() }; + + KJS::Value retValue; + JSObjectProxy *proxy = proxyimp->objectProxy(); + QCString slotname( proxyimp->slotName() ); + int sigid = proxyimp->signature(); + QPtrList<uint> uintlist; + uintlist.setAutoDelete(true); + QObject *obj = proxy->object(); + int slotid = obj->metaObject()->findSlot( slotname, true ); + if ( slotid == -1 ) + { + QString msg = i18n( "Slot %1 was not found." ).arg( slotname ); + return throwError(exec, msg,KJS::ReferenceError); + } + + if ( args.size() > MAX_SUPPORTED_ARGS ) + { + QString msg = i18n( "Slots with more than %1 arguments are not supported." ).arg( MAX_SUPPORTED_ARGS ); + return throwError(exec, msg,KJS::ReferenceError); + } + // Keep args in scope for duration of the method. + KURL url[MAX_SUPPORTED_ARGS]; + QColor color[MAX_SUPPORTED_ARGS]; + QPoint point[MAX_SUPPORTED_ARGS]; + QSize size[MAX_SUPPORTED_ARGS]; + QRect rect[MAX_SUPPORTED_ARGS]; + QDate date[MAX_SUPPORTED_ARGS]; + QDateTime datetime[MAX_SUPPORTED_ARGS]; + QTime time[MAX_SUPPORTED_ARGS]; + QPixmap pix[MAX_SUPPORTED_ARGS]; + QStringList slst[MAX_SUPPORTED_ARGS]; + + bool notsupported = true; + + if ( args.size() == 1 ) { + //kdDebug( 80001 ) << "One Arg" << endl; + switch (sigid) { + case SignatureInt: + implantInt( exec, uo+1, args[0] ); + break; + case SignatureBool: + implantBool( exec, uo+1, args[0] ); + break; + case SignatureString: + implantQString( exec, uo+1, args[0] ); + break; + case SignatureCString: + implantCString( exec, uo+1, args[0] ); + break; + case SignatureDouble: + implantDouble( exec, uo+1, args[0] ); + break; + case SignatureURL: + implantURL( exec, uo+1, args[0], &url[0] ); + break; + case SignatureColor: + implantColor( exec, uo+1, args[0], &color[0] ); + break; + case SignaturePoint: + implantPoint( exec, uo+1, args[0], &point[0] ); + break; + case SignatureSize: + implantSize( exec, uo+1, args[0], &size[0] ); + break; + case SignatureRect: + implantRect( exec, uo+1, args[0], &rect[0] ); + break; + default: + notsupported = true; + break; + } + + } else if ( args.size() == 2 ) { + //kdDebug( 80001 ) << "Two Args" << endl; + switch (sigid) { + case SignatureIntInt: + implantInt( exec, uo+1, args[0] ); + implantInt( exec, uo+2, args[1] ); + break; + case SignatureStringInt: + implantQString( exec, uo+1, args[0] ); + implantInt( exec, uo+2, args[1] ); + break; + case SignatureRectBool: + implantRect( exec, uo+1, args[0], &rect[0] ); + implantBool( exec, uo+2, args[1] ); + break; + case SignatureStringString: + implantQString( exec, uo+1, args[0] ); + implantQString( exec, uo+2, args[1] ); + break; + case SignatureStringBool: + implantQString( exec, uo+1, args[0] ); + implantBool( exec, uo+2, args[1] ); + break; + case SignatureIntColor: + implantInt( exec, uo+1, args[0] ); + implantColor( exec, uo+2, args[1], &color[0] ); + break; + case SignatureURLURL: + implantURL( exec, uo+1, args[0], &url[0] ); + implantURL( exec, uo+2, args[1], &url[1] ); + break; + case SignatureURLString: + implantURL( exec, uo+1, args[0], &url[0] ); + implantQString( exec, uo+2, args[1] ); + break; + case SignatureStringURL: + implantQString( exec, uo+1, args[0] ); + implantURL( exec, uo+2, args[1], &url[0] ); + break; + + default: + notsupported = true; + break; + } + + } else { + //kdDebug( 80001 ) << args.size() << " Args" << endl; + notsupported = false; + switch (sigid) { + case SignatureNone: + break; + case SignatureStringStringString: + if ( args.size() != 3 ) + return KJS::Null(); + implantQString( exec, uo+1, args[0] ); + implantQString( exec, uo+2, args[1] ); + implantQString( exec, uo+3, args[2] ); + break; + case SignatureIntIntString: + if ( args.size() != 3 ) + return KJS::Null(); + implantInt( exec, uo+1, args[0] ); + implantInt( exec, uo+2, args[1] ); + implantQString( exec, uo+3, args[2] ); + break; + case SignatureIntIntIntInt: + if ( args.size() != 4 ) + return KJS::Null(); + implantInt( exec, uo+1, args[0] ); + implantInt( exec, uo+2, args[1] ); + implantInt( exec, uo+3, args[2] ); + implantInt( exec, uo+4, args[3] ); + break; + case SignatureIntIntIntIntBool: + if ( args.size() != 5 ) + return KJS::Null(); + implantInt( exec, uo+1, args[0] ); + implantInt( exec, uo+2, args[1] ); + implantInt( exec, uo+3, args[2] ); + implantInt( exec, uo+4, args[3] ); + implantBool( exec, uo+5, args[4] ); + break; + case SignatureIntIntIntIntIntInt: + if ( args.size() != 6 ) + return KJS::Null(); + implantInt( exec, uo+1, args[0] ); + implantInt( exec, uo+2, args[1] ); + implantInt( exec, uo+3, args[2] ); + implantInt( exec, uo+4, args[3] ); + implantInt( exec, uo+5, args[4] ); + implantInt( exec, uo+6, args[5] ); + break; + default: + notsupported = true; + } + } + + if ( notsupported ) { + //kdDebug( 80001 ) << "Trying method 2" << endl; + // Rip apart the call signature to get the args slow but effective. + notsupported = false; + int argsStart = slotname.find('('); + int argsEnd = slotname.find(')'); + QString fargs = slotname.mid( argsStart+1, argsEnd-argsStart-1 ); + + // Iterate over the parameters + QStringList argList = QStringList::split(',', fargs, true); + uint count = QMIN( argList.count(), MAX_SUPPORTED_ARGS ); + + kdDebug( 80001 ) << "======== arg count " << count << endl; + for( uint idx = 0; idx < count; idx++ ) { + kdDebug( 80001 ) << "======== Handling arg " << idx << endl; + + QString arg = argList[idx]; + arg = arg.replace("const", ""); + arg = arg.replace("&", ""); + arg = arg.simplifyWhiteSpace(); + kdDebug( 80001 ) << "Testing " << arg.latin1() << endl; + + if(arg.contains("uint") == 1) { + unsigned int *unsignedint=new uint; + *unsignedint=args[idx].toUInt32(exec); + uintlist.append(unsignedint); + static_QUType_ptr.set( uo+1+idx, unsignedint) ; + } + else if( arg.contains("int") == 1 ) + implantInt( exec, uo+1+idx, args[idx] ); + else if ( arg.contains("double") == 1 ) + implantDouble(exec, uo+1+idx, args[idx]); + else if ( arg.contains("QStringList") == 1 ) + implantStringList( exec, uo+1+idx, args[idx], &slst[idx] ); + else if ( arg.contains("QString") == 1 ) + implantQString(exec, uo+1+idx, args[idx] ); + else if ( arg.contains("QCString") == 1 ) + implantCString(exec, uo+1+idx, args[idx] ); + else if ( arg.contains("bool") == 1 ) + implantBool( exec, uo+1+idx, args[idx] ); + else if ( arg.contains("KURL") == 1 ) + implantURL( exec, uo+1+idx, args[idx], &url[idx] ); + else if ( arg.contains("QColor") == 1 ) + implantColor( exec, uo+1+idx, args[idx], &color[idx] ); + else if ( arg.contains("QPoint") == 1 ) + implantPoint( exec, uo+1+idx, args[idx], &point[idx] ); + else if ( arg.contains("QSize") == 1 ) + implantSize( exec, uo+1+idx, args[idx], &size[idx] ); + else if ( arg.contains("QRect") == 1 ) + implantRect( exec, uo+1+idx, args[idx], &rect[idx] ); + else if ( arg.contains("QDate") == 1 ) + implantDate( exec, uo+1+idx, args[idx], &date[idx] ); + else if ( arg.contains("QTime") == 1 ) + implantTime( exec, uo+1+idx, args[idx], &time[idx] ); + else if ( arg.contains("QDateTime") == 1 ) + implantDateTime( exec, uo+1+idx, args[idx], &datetime[idx] ); + else if ( arg.contains("QPixmap") == 1 ) + implantPixmap( exec, uo+1+idx, args[idx], &pix[idx] ); + else if ( arg.contains("char") == 1) + implantCharStar( exec, uo+1+idx, args[idx] ); + else if ( ( arg.contains("QObject") == 1 ) || ( arg.contains("QWidget") == 1 ) ) + { + kdDebug( 80001 ) << "Doing a QObject" << endl; + notsupported = !implantObjectProxy( exec, uo+1+idx, args[idx], "QObject" ); + } + else if ( QVariant::nameToType(arg.latin1()) != QVariant::Invalid ) { + bool ok = implantValueProxy( exec, uo+1+idx, args[idx], arg ); + if ( !ok ) { + notsupported = true; + break; + } + else + { + kdDebug( 80001 ) << "Implanted the variant " << static_QUType_QVariant.get(uo+1+idx).isValid() << endl; + } + } + /* else if ( ( arg.contains("QVariant") == 1 ) || + ( arg.contains("QPen") == 1 ) || (arg.contains("QFont") == 1 ) || + ( arg.contains("QBrush") == 1 )) + if(!implantQVariant(exec, uo+1+idx, args[idx] )){ + notsupported = true; + break; + } */ + else if ( arg.contains("*") == 1 ) { + QRegExp re("(\\w+)\\*"); + if ( re.search(arg) >= 0 ) { + bool ok = implantObjectProxy( exec, uo+1+idx, args[idx], re.cap(1) ); + if ( !ok ) { + ok = implantOpaqueProxy( exec, uo+1+idx, args[idx], re.cap(1) ); + if ( !ok ) { + notsupported = true; + break; + } + } + } + else { + notsupported = true; + break; + } + } else { + notsupported = true; + break; // Abort on the first unsupported parameter + } + } + } + + if ( notsupported ) { + kdWarning(80001) << "Signature " << slotname << " has not been implemented" << endl; + return KJS::Null(); + } else { + kdDebug(80001) << "Call Signature: " << slotname << endl; + + obj->qt_invoke( slotid, uo ); + } + // Handle return types + QCString ret( proxyimp->returnType() ); + if ( ret.isEmpty() ) { + // Basic type (void, int etc.) + return extractValue( exec, uo ); + } + + // Object type + kdDebug(80001) << "Handling a pointer return of type " << ret << endl; + + if ( proxy->part()->factory()->isQObject(ret) ) { + kdDebug(80001) << "Return type is QObject " << ret << endl; + return extractValue( exec, uo, proxy ); + } + + // Opaque type + kdDebug(80001) << "Return type is opaque " << ret << endl; + + JSOpaqueProxy *opaque = new JSOpaqueProxy(static_QUType_ptr.get(uo), ret.data()); + //opaque->setValue( ); + + KJS::Object opaqueObj( opaque ); + opaque->addBindings( exec, opaqueObj ); + + return opaqueObj; +} + +} // namespace KJSEmbed::Bindings +} // namespace KJSEmbed + +// Local Variables: +// c-basic-offset: 4 +// End: + diff --git a/kjsembed/slotutils.h b/kjsembed/slotutils.h new file mode 100644 index 00000000..ff43a95a --- /dev/null +++ b/kjsembed/slotutils.h @@ -0,0 +1,175 @@ +// -*- c++ -*- + +/* + * Copyright (C) 2001-2003, Richard J. Moore <rich@kde.org> + * + * This 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. + * + * This 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 this library; see the file COPYING.LIB. If not, write to + * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, + * Boston, MA 02110-1301, USA. + */ + +#ifndef KJSEMBEDSLOTUTILS_H +#define KJSEMBEDSLOTUTILS_H +#include "global.h" + +#include <kjs/object.h> +#include <kjsembed/jsbinding.h> + +class QObject; + +namespace KJS { class Interpreter; } + +namespace KJSEmbed { +namespace Bindings { + +class JSObjectProxyImp; + +/** + * Provides utility methods for slot invocation. + * + * @author Richard Moore, rich@kde.org + * @version $Id$ + */ +class KJSEMBED_EXPORT JSSlotUtils +{ +public: + /** + * Identifiers for fast slot signatures. + */ + enum SignatureId { + SignatureNotSupported = -1, + SignatureUnknown, + + SignatureNone, + + SignatureInt, SignatureUInt, SignatureLong, SignatureULong, + SignatureBool, SignatureDouble, SignatureDateTime, + SignatureString, SignatureCString, SignatureDate, SignatureTime, + + SignatureURL, SignatureColor, SignaturePoint, SignatureRect, + SignatureSize, SignaturePixmap, SignatureFont, SignatureImage, + + SignatureQWidget, + + SignatureIntInt, SignatureStringInt, SignatureRectBool, + SignatureStringString, SignatureDateDate, SignatureColorString, + SignatureStringBool, SignatureIntColor, SignatureIntBool, + SignatureURLURL, SignatureURLString, SignatureStringURL, + + SignatureStringStringString, SignatureStringBoolBool, SignatureStringIntInt, + SignatureIntColorBool, SignatureIntIntBool, SignatureIntIntString, + SignatureStringBoolInt, + + SignatureIntIntIntInt,SignatureIntIntFloatFloat, SignatureStringBoolBoolBool, + + SignatureIntIntIntIntBool, SignatureIntIntIntIntInt, SignatureIntIntIntIntIntInt, + SignatureCustom + + }; + + /** + * Returns the method id for the specified slot signature. If there is no match + * then -1 is returned. + */ + static int findSignature( const QString &sig ); + + /** Connects the specified signal to the specified slot. */ + static bool connect( QObject *sender, const char *sig, QObject *recv, const char *dest ); + + static KJS::Boolean disconnect( KJS::ExecState *exec, KJS::Object &self, + QObject *sender, const char *sig, QObject *recv, const char *dest ); + + static KJS::Value invokeSlot( KJS::ExecState *exec, KJS::Object &self, const KJS::List&args, + JSObjectProxyImp *proxyimp ); + + /** Returns the value of the QUObject or KJS::Null. */ + static KJS::Value extractValue( KJS::ExecState *exec, QUObject *uo, JSObjectProxy *parent=0 ); + + /** Implant an int into a QUObject. */ + static void implantInt( KJS::ExecState *exec, QUObject *uo, const KJS::Value &v ); + /** Implant a QString into a QUObject. */ + static void implantQString( KJS::ExecState *exec, QUObject *uo, const KJS::Value &v ); + /** Implant a bool into a QUObject. */ + static void implantBool( KJS::ExecState *exec, QUObject *uo, const KJS::Value &v ); + /** Implant a double into a QUObject. */ + static void implantDouble( KJS::ExecState *exec, QUObject *uo, const KJS::Value &v ); + /** Implant a C string into a QUObject. */ + static void implantCString( KJS::ExecState *exec, QUObject *uo, const KJS::Value &v ); + + /** Implant a KURL into a QUObject. */ + static void implantURL( KJS::ExecState *exec, QUObject *uo, const KJS::Value &v, KURL *url ); + /** Implant a QColor into a QUObject. */ + static void implantColor( KJS::ExecState *exec, QUObject *uo, const KJS::Value &v, QColor *color ); + /** Implant a QPoint into a QUObject. */ + static void implantPoint( KJS::ExecState *exec, QUObject *uo, const KJS::Value &v, QPoint *point ); + /** Implant a QRect into a QUObject. */ + static void implantRect( KJS::ExecState *exec, QUObject *uo, const KJS::Value &v, QRect *rect ); + /** Implant a QSize into a QUObject. */ + static void implantSize( KJS::ExecState *exec, QUObject *uo, const KJS::Value &v, QSize *size ); + + /** Implant a QDate into a QUObject. */ + static void implantDate( KJS::ExecState *exec, QUObject *uo, const KJS::Value &v, QDate *date ); + /** Implant a QTime into a QUObject. */ + static void implantTime( KJS::ExecState *exec, QUObject *uo, const KJS::Value &v, QTime *time ); + /** Implant a QDateTime into a QUObject. */ + static void implantDateTime( KJS::ExecState *exec, QUObject *uo, const KJS::Value &v, QDateTime *datetime ); + /** Implant a QPixmap into a QUObject. */ + static void implantPixmap( KJS::ExecState *exec, QUObject *uo, const KJS::Value &v, QPixmap *pix ); + + /** + * Implant a value proxy into a QUObject. The type specified in the clazz parameter + * must match the type of the proxy'd value for the method to succeed. + */ + static bool implantValueProxy( KJS::ExecState *exec, QUObject *uo, + const KJS::Value &v, const QString &clazz); + + /** Implant a QVariant into a QUObject. */ + static bool implantQVariant( KJS::ExecState *exec, QUObject *uo,const KJS::Value &v); + + /** + * Implant an opaque proxy into a QUObject. The type specified in the + * clazz parameter must match the type of the proxy'd value for the method + * to succeed. + */ + static bool implantOpaqueProxy( KJS::ExecState *, QUObject *uo, + const KJS::Value &v, const QString &clazz ); + + /** + * Implant an object proxy into a QUObject. The object proxy'd by the specified value + * must inherit the class specified for the converstion to succeed. + */ + static bool implantObjectProxy( KJS::ExecState *exec, QUObject *uo, + const KJS::Value &v, const QString &clazz ); + /** Implant a QString into a QUObject. */ + static void implantStringList(KJS::ExecState *exec, QUObject *uo, + const KJS::Value &v, QStringList *lst ); + + /** Implant a char* into a QUObject. */ + static void implantCharStar( KJS::ExecState *exec, QUObject *uo, const KJS::Value &v ); + +private: + JSSlotUtils(); + ~JSSlotUtils(); + + class JSSlotUtilsPrivate *d; +}; + +} // namespace KJSEmbed::Bindings +} // namespace KJSEmbed + +#endif // KJSEMBEDSLOTUTILS_H + +// Local Variables: +// c-basic-offset: 4 +// End: diff --git a/kjsembed/stdlib/Makefile.am b/kjsembed/stdlib/Makefile.am new file mode 100644 index 00000000..bd7e241a --- /dev/null +++ b/kjsembed/stdlib/Makefile.am @@ -0,0 +1,5 @@ +# -*- makefile -*- + +jslibdir = $(kde_datadir)/kjsembed +jslib_DATA = cmdline.js + diff --git a/kjsembed/stdlib/cmdline.js b/kjsembed/stdlib/cmdline.js new file mode 100755 index 00000000..9c96c6cb --- /dev/null +++ b/kjsembed/stdlib/cmdline.js @@ -0,0 +1,78 @@ +#!/usr/bin/env kjscmd + +function list(obj) +{ + println( obj ); + + for ( var i in obj ) { + try { + tp = typeof obj[i]; + + count = 20 - i.length; + spc = ''; + for ( var s=0; s < count; s++ ) + spc = spc + ' '; + + println( ' ' + i + spc + tp ); + } + catch(err) { + println( ' ' + i + spc + 'Error, ' + err ); + } + } +} + +function help() +{ + println(); + println( 'KJSCmd ' + part.versionString + ' Prompt' ); + println( '=======' + '===' + '=======' ); + println(); + println( "Type 'quit' to exit, and 'help' for this text. Anything else" ); + println( 'is evaluated by the KJSCmd engine and the result displayed.' ); + println(); +} + +function cmd_prompt() +{ + System.stdout.print( 'kjscmd> ' ); + return System.stdin.readLine(); +} + +// +// Main +// + +println( "KJSCmd " + part.versionString + " (type 'help' for more information)" ); +done = false; + +do { + + line = cmd_prompt(); + + if ( line == 'quit' ) { + done = true; + } + else if ( line == 'help' ) { + help(); + } + else if ( line == '' ) { + // DO NOTHING + } + else if ( line == null ) { + done = true; + } + else { + try { + output = eval( line ); + + if ( typeof(output) != 'undefined' ) + println( output ); + } + catch(err) { + println( 'Error: ' + err ); + } + } + +} while ( !done ); + +System.exit(0); diff --git a/kjsembed/testkjsembed.cpp b/kjsembed/testkjsembed.cpp new file mode 100644 index 00000000..228e1093 --- /dev/null +++ b/kjsembed/testkjsembed.cpp @@ -0,0 +1,61 @@ +/* + * Copyright (C) 2001-2003, Richard J. Moore <rich@kde.org> + * + * This 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. + * + * This 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 this library; see the file COPYING.LIB. If not, write to + * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, + * Boston, MA 02110-1301, USA. + */ + +#include <kaboutdata.h> +#include <kapplication.h> +#include <kcmdlineargs.h> +#include <klocale.h> +#include <kjs/interpreter.h> + +#include <jsconsolewidget.h> +#include <jsobjectproxy.h> +#include <jsfactory.h> +#include <jssecuritypolicy.h> + +int main( int argc, char **argv ) +{ + KAboutData about( "test-kjsembed", I18N_NOOP("KJS Embed Test"), "0.1", + I18N_NOOP("Test"), + KAboutData::License_LGPL, I18N_NOOP("(c) 2001-2003 Richard Moore") ); + KCmdLineArgs::init( argc, argv, &about ); + KApplication app; + + // Setup Interpreter + KJS::Interpreter *js = KJSEmbed::JSFactory::defaultJS(); + KJS::Object global = js->globalObject(); + + // Create Console + KJSEmbed::JSConsoleWidget *console = new KJSEmbed::JSConsoleWidget( js ); + + console->addBindings( global ); + JSFactory::publish( &app, js, global, "app" ); + JSFactory::publish( console, js, global, "console" ); + + // Setup Window + app.setMainWidget( console ); + app.connect( &app, SIGNAL( lastWindowClosed() ), SLOT(quit()) ); + console->resize( 600, 450 ); + console->show(); + + return app.exec(); +} + +// Local Variables: +// c-basic-offset: 4 +// End: diff --git a/kjsembed/tests/TestApplet.java b/kjsembed/tests/TestApplet.java new file mode 100644 index 00000000..7d4bbfda --- /dev/null +++ b/kjsembed/tests/TestApplet.java @@ -0,0 +1,17 @@ +import java.awt.*; + +public class TestApplet extends javax.swing.JApplet { + String parameter; + + public void init() { + parameter = getParameter( "TEXT" ); + if( parameter == null ) + parameter = "No value found"; + } + + public void paint( Graphics screen ) { + Graphics2D screen2D = (Graphics2D) screen; + screen2D.drawString( "I got value '" + parameter + "'.", 5, 50); + } + +} diff --git a/kjsembed/tests/dcop.js b/kjsembed/tests/dcop.js new file mode 100644 index 00000000..03e8ac87 --- /dev/null +++ b/kjsembed/tests/dcop.js @@ -0,0 +1,40 @@ +#!/usr/bin/env kjscmd + +println( "Hello World" ); + +var d = new DCOPClient(); + +if ( d.attach()) +{ + println("Attached..."); + if( d.isAttached() ) + { + println( "send test..." ) + if (d.send( "kded","kmilod", "displayText(QString)", "Test") ) + println("send worked..."); + else + println("send failed..."); + println( "call test..." ) + var dta = d.call( "kded","kmilod", "pollMilliSeconds()"); + println( dta ); + println( "call test with args" ) + var dta = d.call( "KWeatherService","WeatherService", "wind(QString)", "KMKE"); + println( dta ); + + + var ref = d.call("rssservice", "RSSService", "add(QString)", "http://www.freshmeat.net/rdf.xml"); + if( ref ) + { + println( "Got ref"); + var data = ref.call("maxAge()"); + println(data); + } + + } + else + println( "Error!" ) +} +else + println("Failed..."); + +println( "Done" ); diff --git a/kjsembed/tests/plugin.js b/kjsembed/tests/plugin.js new file mode 100644 index 00000000..04d91a4f --- /dev/null +++ b/kjsembed/tests/plugin.js @@ -0,0 +1,40 @@ + +var plugins = Factory.listBindingPlugins(); +println("Currently Usable Plugins:"); +for ( var idx = 0; idx < plugins.length; ++idx) + println(plugins[idx]); + +try { +var invalid1 = new NotReallyThere(this); +} +catch(ex) { +println('Exception: '+ex); +} + +var foo1 = new MyCustomObject(this); +var foo2 = new MyCustomObject(this); + +foo1.setThing("Test"); + +println( foo1.On ); +println( foo1.Off ); + +foo2.setMode(foo2.On); +foo2.setThing(foo2.thing()); + +if( foo2.mode() == foo1.On ) +{ + var foo3 = foo2; + println("Foo3 thing " + foo3.thing()); + +} + +var foo4 = new MyCustomQObject(this); + +foo4.mode = foo4.On; +foo4.thing = "Test"; + +if( foo4.mode ) +{ + println( foo4.thing ); +} diff --git a/kjsembed/tests/test.js b/kjsembed/tests/test.js new file mode 100644 index 00000000..1810c2b1 --- /dev/null +++ b/kjsembed/tests/test.js @@ -0,0 +1,11 @@ +print( "Hello World" ) +warn( "Beware World" ) + +dlg = Factory.loadui( "test.ui" ) +dlg.caption = "Testing KJSEmbed" + +dlg.exec() + +print( "line=" + dlg.child("KLineEdit1").text ) +print( "date=" + dlg.child("DateEdit1").date ) +print( "time=" + dlg.child("TimeEdit1").time ) diff --git a/kjsembed/tests/test.png b/kjsembed/tests/test.png Binary files differnew file mode 100644 index 00000000..257b90eb --- /dev/null +++ b/kjsembed/tests/test.png diff --git a/kjsembed/tests/test.ui b/kjsembed/tests/test.ui new file mode 100644 index 00000000..fb9cdc26 --- /dev/null +++ b/kjsembed/tests/test.ui @@ -0,0 +1,111 @@ +<!DOCTYPE UI><UI version="3.1" stdsetdef="1"> +<class>Form1</class> +<widget class="QDialog"> + <property name="name"> + <cstring>Form1</cstring> + </property> + <property name="geometry"> + <rect> + <x>0</x> + <y>0</y> + <width>403</width> + <height>297</height> + </rect> + </property> + <grid> + <property name="name"> + <cstring>unnamed</cstring> + </property> + <property name="margin"> + <number>11</number> + </property> + <property name="spacing"> + <number>6</number> + </property> + <widget class="QLabel" row="0" column="0" rowspan="1" colspan="3"> + <property name="name"> + <cstring>TextLabel1</cstring> + </property> + <property name="text"> + <string><h1>Test Dialog</h1></string> + </property> + </widget> + <widget class="QDateEdit" row="2" column="1" rowspan="1" colspan="2"> + <property name="name"> + <cstring>DateEdit1</cstring> + </property> + </widget> + <widget class="QLabel" row="1" column="0"> + <property name="name"> + <cstring>TextLabel2</cstring> + </property> + <property name="text"> + <string>Line edit:</string> + </property> + </widget> + <widget class="QTimeEdit" row="3" column="1" rowspan="1" colspan="2"> + <property name="name"> + <cstring>TimeEdit1</cstring> + </property> + </widget> + <widget class="KLineEdit" row="1" column="1" rowspan="1" colspan="2"> + <property name="name"> + <cstring>KLineEdit1</cstring> + </property> + </widget> + <widget class="QLabel" row="2" column="0"> + <property name="name"> + <cstring>TextLabel2_3</cstring> + </property> + <property name="text"> + <string>Date edit:</string> + </property> + </widget> + <widget class="QLabel" row="3" column="0"> + <property name="name"> + <cstring>TextLabel2_4</cstring> + </property> + <property name="text"> + <string>Time edit:</string> + </property> + </widget> + <spacer row="4" column="0" rowspan="1" colspan="2"> + <property name="name"> + <cstring>spacer1</cstring> + </property> + <property name="orientation"> + <enum>Horizontal</enum> + </property> + <property name="sizeType"> + <enum>Expanding</enum> + </property> + <property name="sizeHint"> + <size> + <width>161</width> + <height>20</height> + </size> + </property> + </spacer> + <widget class="QPushButton" row="4" column="2"> + <property name="name"> + <cstring>pushButton1</cstring> + </property> + <property name="text"> + <string>&Close</string> + </property> + </widget> + </grid> +</widget> +<connections> + <connection> + <sender>pushButton1</sender> + <signal>clicked()</signal> + <receiver>Form1</receiver> + <slot>accept()</slot> + </connection> +</connections> +<layoutdefaults spacing="6" margin="11"/> +<includehints> + <includehint>klineedit.h</includehint> +</includehints> +</UI> diff --git a/kjsembed/tests/test2.js b/kjsembed/tests/test2.js new file mode 100644 index 00000000..8e633efb --- /dev/null +++ b/kjsembed/tests/test2.js @@ -0,0 +1,4 @@ + +print( "line=" + dlg.child("KLineEdit1").text ) +print( "date=" + dlg.child("DateEdit1").date ) +print( "time=" + dlg.child("TimeEdit1").time ) diff --git a/kjsembed/tests/test_args.js b/kjsembed/tests/test_args.js new file mode 100755 index 00000000..5915cbf1 --- /dev/null +++ b/kjsembed/tests/test_args.js @@ -0,0 +1,9 @@ +#!/usr/local/kde/bin/kjscmd + + +for ( var i = 0 ; i < application.args.length ; i++ ) { + println( 'Arg' + i + ': ' + application.args[i] ); +} + +part.view().show(); +application.exec(); diff --git a/kjsembed/tests/test_arrays.js b/kjsembed/tests/test_arrays.js new file mode 100644 index 00000000..4f505d8a --- /dev/null +++ b/kjsembed/tests/test_arrays.js @@ -0,0 +1,49 @@ +#!/usr/bin/env kjscmd + +var empty = []; +var map1 = []; + +var array = ["Test A", "Test B", "Test C", "Test D"]; +var map2 = {"Test 1":"Test Map A", "Test 2":"Test Map B","Test 3":"Test Map C","Test 4":"Test Map D"}; + +map1["Test 1"] = "Test Map A"; +map1["Test 2"] = "Test Map B"; +map2.length = 1; +empty.length = 3; + +list = ["Test A"]; +list[3] = "Test B"; +list[5] = "Test C"; +list[7] = "Test D"; + +println( "Sparse value 2:" + list[2] ); +try { + println( "Array: " + array.length ); + println( "Array max value: " + array[array.length - 1] ); +} catch(x) { println( "Error: " + x); } + +try { + println( "Map1: " + map1.length ); + println( "Map1 max value: " + map1[map1.length - 1] ); +} catch(x) { println( "Error: " + x); } + +try { + println( "Map2: " + map2.length ); + println( "Map2 max value: " + map2[map2.length - 1] ); +} catch(x) { println( "Error: " + x); } + +try { + println( "List: " + list.length ); + println( "List max value: " + list[list.length - 1] ); +} catch(x) { println( "Error: " + x); } + +try { + println( "Empty: " + empty.length ); + println( "Empty max value: " + empty[empty.length - 1] ); +} catch(x) { println( "Error: " + x); } + +System.KJSConfig.writeListEntry("Test Array", array ); +System.KJSConfig.writeListEntry("Test Map1", map1 ); +System.KJSConfig.writeListEntry("Test Map2", map2 ); +System.KJSConfig.writeListEntry("Test List", list ); +System.KJSConfig.writeListEntry("Test Empty", empty );
\ No newline at end of file diff --git a/kjsembed/tests/test_childevent.js b/kjsembed/tests/test_childevent.js new file mode 100644 index 00000000..363f3492 --- /dev/null +++ b/kjsembed/tests/test_childevent.js @@ -0,0 +1,45 @@ +#!/usr/bin/env kjscmd + +/** + * Test of QChildEvent handling. This example will not work at the moment + * because support for these events is disabled. The problem occurs because we + * reenter the interpreter if the object was created by js. + */ + +var top = new QVBox(); +var hbox = new QHBox(top, 'button_hbox'); +var add = new QPushButton(hbox, 'add_button'); +var del = new QPushButton(hbox, 'del_button'); + +add.text = 'Add'; +del.text = 'Delete'; + +top.childInsertEvent = function(ev) +{ + println( 'Inserted!!!!!' ); +} + +top.childRemoveEvent = function(ev) +{ + println( 'Removed! ' + ev.className ); +} + +top.addSlot = function() +{ + l = new QLabel( this, 'demo_label' ); + l.text = 'Hello World'; + l.show(); +} + +top.delSlot = function() +{ + if ( top.childCount() > 2 ) { + top.child( top.childCount()-1 ).deleteLater(); + } +} + +top.connect( add, 'clicked()', top, 'addSlot' ); +top.connect( del, 'clicked()', top, 'delSlot' ); + +top.show(); +application.exec(); diff --git a/kjsembed/tests/test_connect.js b/kjsembed/tests/test_connect.js new file mode 100644 index 00000000..abeb14bb --- /dev/null +++ b/kjsembed/tests/test_connect.js @@ -0,0 +1,11 @@ +var box = new QHBox( 'tree_view' ); +box.margin = 6; + +var led = new KLed( box ); + +var btn = new QCheckBox(box); +btn.text = 'Light' + +btn.connect( 'toggled(bool)', led, 'toggle()' ); + +box.show(); diff --git a/kjsembed/tests/test_connectsignal.js b/kjsembed/tests/test_connectsignal.js new file mode 100644 index 00000000..e0392375 --- /dev/null +++ b/kjsembed/tests/test_connectsignal.js @@ -0,0 +1,14 @@ +var box = new QHBox( 'tree_view' ); +box.margin = 6; + +var led = new KLed( box ); +var check = new QCheckBox(box); +var check2 = new QCheckBox(box); + +check.text = 'Light'; +check2.text = 'Bounce'; + +check.connect( 'toggled(bool)', led, 'toggle()' ); +check2.connect( 'toggled(bool)', check, 'toggled(bool)' ); + +box.show(); diff --git a/kjsembed/tests/test_customslots.js b/kjsembed/tests/test_customslots.js new file mode 100644 index 00000000..0c1dd05c --- /dev/null +++ b/kjsembed/tests/test_customslots.js @@ -0,0 +1,17 @@ +#!/usr/bin/env kjscmd + +var dateTime = new QDateTimeEdit(this); +dateTime.connect( dateTime, 'valueChanged(const QDateTime&)', this, 'changed'); + +var jsDate = new Date(); +dateTime.setDateTime( jsDate ); + +dateTime.show(); +application.exec(); + +function changed( time ) +{ + println( time.toString() ); + println( jsDate.toString() ); +} + diff --git a/kjsembed/tests/test_datetime.js b/kjsembed/tests/test_datetime.js new file mode 100644 index 00000000..b35853ad --- /dev/null +++ b/kjsembed/tests/test_datetime.js @@ -0,0 +1,14 @@ +#!/usr/bin/env kjscmd + +var realDate = new Date(); +var dtEdit = new QDateTimeEdit(this); +dtEdit.dateTime = realDate; + +var dt = dtEdit.dateTime; +if( dt.toString() == realDate.toString() ) + println( "Times match" ); +else +{ + println( "Time got " + dt.toString() ); + println( "Time wanted " + realDate.toString() ); +} diff --git a/kjsembed/tests/test_dcop_interface.js b/kjsembed/tests/test_dcop_interface.js new file mode 100755 index 00000000..f0da8c27 --- /dev/null +++ b/kjsembed/tests/test_dcop_interface.js @@ -0,0 +1,45 @@ +#!/usr/bin/env kjscmd + +function exitJavascript(exitValue ) +{ + println("Exiting the javascript now with " + exitValue); + exit(exitValue); +} + +function doSomthing( message, maxTimes ) +{ + println( message + " " + maxTimes ); + for( var times = 0; times < maxTimes; times++) + println(message); + return "Javascript said '" + message + "' " + maxTimes + " times."; +} + +function test() +{ + println("this is a test"); + return 1; +} + +function pixmap(color) +{ + var pixmap = new Pixmap(); + pixmap.resize( 25,25 ); + pixmap.fill( color ); + return pixmap; +} + +function makeRef() +{ + var client = new DCOPClient(); + var ref = new DCOPRef(client.appId(), "someInterface"); + return ref; +} + +var dcop = new DCOPInterface(this, "someInterface"); // Create the DCOP object. +dcop.publish("void exitJavascript(int)"); // Publish a javascript function. +dcop.publish("QString doSomthing(QString,int)"); // Publish another javascript function. +dcop.publish("int test()"); +dcop.publish("QPixmap pixmap(QString)"); +dcop.publish("DCOPRef makeRef()"); + +application.exec(); // Start the event loop diff --git a/kjsembed/tests/test_dcop_isregistered.js b/kjsembed/tests/test_dcop_isregistered.js new file mode 100644 index 00000000..c9f813da --- /dev/null +++ b/kjsembed/tests/test_dcop_isregistered.js @@ -0,0 +1,19 @@ +#!/usr/bin/env kjscmd + +var d = new DCOPClient(); + +if ( d.attach()) +{ + println("Attached..."); + if (!d.isApplicationRegistered( "kate" ) ) + { + var appID = d.dcopStart("kate"); + println( appID + " started" ); + } + else + println( "its already registered" ); +} +else + println("Failed..."); + +println( "Done" ); diff --git a/kjsembed/tests/test_dcopref.js b/kjsembed/tests/test_dcopref.js new file mode 100644 index 00000000..3576a4aa --- /dev/null +++ b/kjsembed/tests/test_dcopref.js @@ -0,0 +1,27 @@ +#!/usr/bin/env kjscmd + +println( "Hello World" ); + +var d = new DCOPClient(); + +if ( d.attach()) +{ + println("Attached..."); + if( d.isAttached() ) + { + var ref = d.call("kdesktop", "KDesktopIface", "background()"); + if( ref ) + { + println( "Got ref"); + var data = ref.call("isCommon()"); + println("Returned a : " + data); + } + + } + else + println( "Error!" ) +} +else + println("Failed..."); + +println( "Done" ); diff --git a/kjsembed/tests/test_dcopref2.js b/kjsembed/tests/test_dcopref2.js new file mode 100644 index 00000000..02cd3df3 --- /dev/null +++ b/kjsembed/tests/test_dcopref2.js @@ -0,0 +1,23 @@ +#!/usr/bin/env kjscmd + +println( "Hello World" ); + +var d = new DCOPClient(); + +if ( d.attach()) +{ + println("Attached..."); + if( d.isAttached() ) + { + var ref = new DCOPRef(); + ref.setRef( "KWeatherService", "WeatherService" ); + println ( ref.call( "date(QString)", "KMKE") ); + + } + else + println( "Error!" ) +} +else + println("Failed..."); + +println( "Done" ); diff --git a/kjsembed/tests/test_dcopstart.js b/kjsembed/tests/test_dcopstart.js new file mode 100644 index 00000000..e2dee415 --- /dev/null +++ b/kjsembed/tests/test_dcopstart.js @@ -0,0 +1,27 @@ +#!/usr/bin/env kjscmd + +var d = new DCOPClient(); + +if ( d.attach()) +{ + println("Attached..."); + if( d.isAttached() ) + { + var app = d.dcopStart("kwrite"); + if( app != "" ) + { + println( "Got ref"); + var worked = d.send(app, "EditInterface#1","setText(QString)", "This is a test"); + println("Returned a : " + worked); + } + else + println( "Error: no appname returned." ); + + } + else + println( "Error!" ) +} +else + println("Failed..."); + +println( "Done" ); diff --git a/kjsembed/tests/test_dom.js b/kjsembed/tests/test_dom.js new file mode 100644 index 00000000..97188438 --- /dev/null +++ b/kjsembed/tests/test_dom.js @@ -0,0 +1,22 @@ +// +// Tests the DOM methods +// + +var box = console.getElementById('HBox'); +var btn = box.child('RunButton'); + +print('Button: '); +println(btn); + +println( 'Property: enabled' ); +print( 'hasAttribute: ' ); +println( btn.hasAttribute('enabled') ); +print( 'getAttribute: ' ); +println( btn.getAttribute('enabled') ); +print( 'setAttribute: ' ); +println( btn.setAttribute('enabled', false) ); +print( 'getAttribute: ' ); +println( btn.getAttribute('enabled') ); + +println(); +println( 'Now the console will be displayed with button disabled' ); diff --git a/kjsembed/tests/test_gc.js b/kjsembed/tests/test_gc.js new file mode 100755 index 00000000..aa1e11af --- /dev/null +++ b/kjsembed/tests/test_gc.js @@ -0,0 +1,21 @@ +print( "Hello World" ) +var arr = new Array(); + +for( var idx = 0; idx < 500; ++idx ) +{ + arr[idx] = new QLabel(this); + arr[idx].text = "foo " + idx; +} + +for( var idx = 0; idx < 500; ++idx ) +{ + println( arr[idx].text ); + arr[idx] = new QLabel(this); + arr[idx].text = "bar " + idx; +} + +for( var idx = 0; idx < 500; ++idx ) +{ + println( arr[idx].text ); +} + diff --git a/kjsembed/tests/test_image.js b/kjsembed/tests/test_image.js new file mode 100644 index 00000000..309ff18f --- /dev/null +++ b/kjsembed/tests/test_image.js @@ -0,0 +1,18 @@ + +var img = new Image(); +var imgfx = new ImageFX(); + +println( 'Trying to load an image...' ); +var result = img.load('test.png'); +println( 'Result: ' + result ); + +println(); +println( 'Width=' + img.width() + ", " + 'Height=' + img.height() ); + +println( 'Trying to charcoal the image...' ); +img = imgfx.charcoal(img, 2.0); +img = imgfx.rotate( img, img.Rotate180 ); + +println( 'Trying to save the image...' ); +var result2 = img.save('out.png'); +println( 'Result2: ' + result2 ); diff --git a/kjsembed/tests/test_kconfig.js b/kjsembed/tests/test_kconfig.js new file mode 100755 index 00000000..519f13fb --- /dev/null +++ b/kjsembed/tests/test_kconfig.js @@ -0,0 +1,40 @@ +#!/usr/bin/env kjscmd + +var confName = "jsconfigrc"; +var groupName = "Blah"; + +var conf = new Config(this, confName); + +var grp = conf.group(); + +println( "Group=" + grp ); + +conf.setGroup(groupName); +conf.writeColorEntry("Test Color", "blue"); +conf.writeListEntry("Test Array", ["A Value","B Value", "C Value"]); +conf.writeEntry("Test Text", "this is a test"); +conf.sync(); + +var newData = conf.readListEntry("Test Array"); +var newColor = conf.readColorEntry("Test Color"); +var newText = conf.readEntry("Test Text"); +println("Reread Active Config"); +println("Groups: " + conf.groupList()); +println(newData); +println(newColor); +println(newText); + + +var newConf = new Config(this, confName); +println("Reread Saved Config"); +println("Groups: " + newConf.groupList()); +newConf.setGroup(groupName); + +newData = newConf.readListEntry("Test Array"); +newColor = newConf.readColorEntry("Test Color", "red"); +newText = newConf.readEntry("Test Text", "Wrong Text"); + +println(newData); +println(newColor); +println(newText); + diff --git a/kjsembed/tests/test_kio.js b/kjsembed/tests/test_kio.js new file mode 100755 index 00000000..11bd6a1c --- /dev/null +++ b/kjsembed/tests/test_kio.js @@ -0,0 +1,26 @@ +#!/usr/bin/env kjscmd + +var net = new NetAccess( this, 'net' ); + +var loc = '/tmp/test.jpg'; + +var ret = net.download( 'http://www.kde.org/media/images/kde_logo.jpg', loc ); + +if ( ret ) { + var mime = net.mimetype( loc ); + print( "Mimetype = " + mime + '\n' ); + var img = new Image(); + img.load( loc ); + if ( !img.isOk() ) { + warn( 'Failed to load image '+loc); + return; + } else { + print( 'Image ' + loc + ' is OK \n' ); + } + var lbl = new QLabel(this); + lbl.pixmap = img.pixmap(); + lbl.show(); +} + +net.del( loc ); +application.exec(); diff --git a/kjsembed/tests/test_kparts_args.js b/kjsembed/tests/test_kparts_args.js new file mode 100644 index 00000000..aee1745e --- /dev/null +++ b/kjsembed/tests/test_kparts_args.js @@ -0,0 +1,16 @@ +#!/usr/bin/env kjscmd + +var mw = new KMainWindow(); +var box = new QVBox( mw ); +mw.setCentralWidget( box ); + +var args = [ "WIDTH=300", "HEIGHT=250", "CODE=TestApplet.class", "CLASSPATH=.", "TEXT=Foobar" ] +var part = Factory.createROPart( "application/x-java-applet", + "'KParts/ReadOnlyPart' in ServiceTypes", + box, "foobar", + args ); + +part.openURL( "./TestApplet.class" ); + +mw.show(); +application.exec(); diff --git a/kjsembed/tests/test_kropart.js b/kjsembed/tests/test_kropart.js new file mode 100644 index 00000000..1e2d4344 --- /dev/null +++ b/kjsembed/tests/test_kropart.js @@ -0,0 +1,5 @@ +var box = new QHBox( this ); +var view = Factory.createROPart( "cat", box, "view" ); + +box.show(); +application.exec(); diff --git a/kjsembed/tests/test_nogui.js b/kjsembed/tests/test_nogui.js new file mode 100755 index 00000000..e7002ec4 --- /dev/null +++ b/kjsembed/tests/test_nogui.js @@ -0,0 +1,3 @@ +#!/usr/bin/env kjscmd + +println( 'Script executed ok' ); diff --git a/kjsembed/tests/test_pixmap_slots.js b/kjsembed/tests/test_pixmap_slots.js new file mode 100644 index 00000000..f2ca40fa --- /dev/null +++ b/kjsembed/tests/test_pixmap_slots.js @@ -0,0 +1,11 @@ +#!/usr/bin/env kjscmd + +var img = new Image(); +img.load("test.png"); + +var pix = img.pixmap(); +var btn = new QToolButton(this); +btn.pixmap = pix; +btn.setIcon( pix ); +btn.show(); +application.exec(); diff --git a/kjsembed/tests/test_point.js b/kjsembed/tests/test_point.js new file mode 100644 index 00000000..6c4bae57 --- /dev/null +++ b/kjsembed/tests/test_point.js @@ -0,0 +1,22 @@ + +var x = 10; +var y = 10; + +var point = new Point(x,y); +var point2 = new Point(); +point2.setX(point.x()); +point2.setY(point.y()); + +if( point.x() != x ) +{ + println( "X not "+ x +" " + point.x()); + exit(1); +} + +if( point.y() != y ) +{ + println( "Y not "+ y +" " + point.y()); + exit(1); +} + +println( "All tests passed");
\ No newline at end of file diff --git a/kjsembed/tests/test_popupmenu.js b/kjsembed/tests/test_popupmenu.js new file mode 100644 index 00000000..6d60231c --- /dev/null +++ b/kjsembed/tests/test_popupmenu.js @@ -0,0 +1,15 @@ +#!/usr/bin/env kjscmd +var menu = new QPopupMenu(this); +var subMenu = new QPopupMenu(menu); +var pix = new Pixmap(); +pix.resize(12,12); +pix.fill("blue"); + +menu.insertItem("Test"); +menu.insertItem(pix, "Test pix"); + +subMenu.insertItem("Test Sub", menu); +subMenu.insertItem(pix, "Test sub pix", menu); + +menu.show(); +application.exec(); diff --git a/kjsembed/tests/test_qcanvas.js b/kjsembed/tests/test_qcanvas.js new file mode 100644 index 00000000..c5ffd7f9 --- /dev/null +++ b/kjsembed/tests/test_qcanvas.js @@ -0,0 +1,29 @@ +#!/usr/bin/env kjscmd + +c = new QCanvas(); + +item = new QCanvasText( '<font="blue">hi</font>', c ); +item.move( 50, 50 ); +item.show(); + +item = new QCanvasText( '<font="blue">hi</font>', c ); +item.move( 150, 50 ); +item.show(); + +item = new QCanvasText( '<font="blue">hixxx</font>', c ); +item.move( 50, 150 ); +item.show(); + +item = new QCanvasText( '<font="blue">hixxxxxxx</font>', c ); +item.move( 150, 150 ); +item.show(); + +view = new QCanvasView(); +view.setCanvas( c ); + +view.update(); +view.show(); + +//load( '../docs/examples/docviewer/docviewer.js' ); + +application.exec(); diff --git a/kjsembed/tests/test_qcombobox.js b/kjsembed/tests/test_qcombobox.js new file mode 100644 index 00000000..03111692 --- /dev/null +++ b/kjsembed/tests/test_qcombobox.js @@ -0,0 +1,8 @@ +var h=new QHBox(this); +var combo = new QComboBox(h, "combo"); +combo.insertItem("Item 1"); +combo.insertItem("Item 2"); +combo.insertItem("Item 3"); +combo.insertItem("Item 4"); +h.show(); +application.exec(); diff --git a/kjsembed/tests/test_qdir.js b/kjsembed/tests/test_qdir.js new file mode 100644 index 00000000..c51f15e0 --- /dev/null +++ b/kjsembed/tests/test_qdir.js @@ -0,0 +1,9 @@ +#!/usr/bin/env kjscmd + +var dir = new QDir(); // CWD +println( dir.path() ); + +var files = dir.entryList( '*.js' ); +for ( i in files ) { + println( files[i] ); +} diff --git a/kjsembed/tests/test_qframe.js b/kjsembed/tests/test_qframe.js new file mode 100644 index 00000000..218b2e7f --- /dev/null +++ b/kjsembed/tests/test_qframe.js @@ -0,0 +1,33 @@ +#!/usr/bin/env kjscmd +var mw = new KMainWindow(this); +var hbox = new QHBox( mw ); + +var f1 = new QLabel( hbox ); +f1.frameShape = QLabel.Box; +f1.frameShadow = QLabel.Raised; +f1.lineWidth = 4; +f1.margin = 4; +f1.midLineWidth = 1; +f1.paletteBackgroundColor = "red"; +f1.text = "Frame 1"; + +var f2 = new QLabel( hbox ); +f2.frameShape = QLabel.WinPanel; +f2.frameShadow = QLabel.Sunken; +f2.lineWidth = 4; +f2.margin = 4; +f2.midLineWidth = 1; +f2.paletteBackgroundColor = "white"; +f2.text = "Frame 2"; + +var f3 = new QLabel( hbox ); +f3.frameShape = QLabel.Box; +f3.lineWidth = 4; +f3.margin = 4; +f3.midLineWidth = 1; +f3.paletteBackgroundColor = "blue"; +f3.text = "Frame 3"; + +mw.setCentralWidget(hbox); +mw.show(); +application.exec(); diff --git a/kjsembed/tests/test_qlistview.js b/kjsembed/tests/test_qlistview.js new file mode 100644 index 00000000..2f8f37bf --- /dev/null +++ b/kjsembed/tests/test_qlistview.js @@ -0,0 +1,30 @@ +var lv = new QListView(); +lv.rootIsDecorated = true; +lv.addColumn('Name'); +lv.addColumn('Description'); + +var i = new QListViewItem( lv ); +i.setText( 0, 'One' ); +i.setText( 1, 'First item' ); + +var j = new QListViewItem( lv ); +j.setText( 0, 'Two' ); +j.setText( 1, 'Second item' ); + +var k = new QListViewItem( i ); +k.setText( 0, 'Three' ); +k.setText( 1, 'Third item' ); + +var l = new QCheckListItem( lv ); +l.setText(0, 'Four' ); + +lv.show(); + +var lvi = lv.firstChild(); +while( lvi ) +{ + println( lvi.text(0) ); + lvi = lvi.nextSibling(); +} + +application.exec(); diff --git a/kjsembed/tests/test_qtabctl.js b/kjsembed/tests/test_qtabctl.js new file mode 100755 index 00000000..60eebfdf --- /dev/null +++ b/kjsembed/tests/test_qtabctl.js @@ -0,0 +1,26 @@ +#!/usr/bin/env kjscmd + +var vbox = new QVBox(); +var tw = new QTabWidget(vbox); +var okButton = new QToolButton(vbox); + +okButton.text = "Ok"; + +var c1 = new QToolButton( tw ); +var c2 = new QToolButton( tw ); + +function tabchanged(q) { + alert( "Tab Changed, " + q.text ); +} + +c1.text = "Tab1's button"; +c2.text = "Tab2's button"; + +tw.addTab(c1, "1"); +tw.addTab(c2, "2"); + +vbox.connect(tw, "currentChanged(QWidget*)", this, "tabchanged"); +vbox.connect(okButton, "clicked()", this, "exit"); +vbox.show(); + +application.exec(); diff --git a/kjsembed/tests/test_qtimeedit.js b/kjsembed/tests/test_qtimeedit.js new file mode 100644 index 00000000..632c4929 --- /dev/null +++ b/kjsembed/tests/test_qtimeedit.js @@ -0,0 +1,8 @@ +var h = new QHBox(this); +var dt = new QTimeEdit(h, 'tc'); +var n = new Date(); // now + +dt.time = n; // set the control to now +var t = dt.time; // get the time out + +println( t.getHours().toString()+':'+t.getMinutes().toString()); // always puts out 23:59 diff --git a/kjsembed/tests/test_qtimeedit2.js b/kjsembed/tests/test_qtimeedit2.js new file mode 100644 index 00000000..825fa10f --- /dev/null +++ b/kjsembed/tests/test_qtimeedit2.js @@ -0,0 +1,13 @@ +var vbox=new QVBox(); +var te=new QTimeEdit(vbox); +var okButton=new QToolButton(vbox); +okButton.text="Ok"; + +function TimeChanged(q) { + alert("Time Changed: " +q); +} + +vbox.connect(te, "valueChanged(const QTime&)", this, "TimeChanged"); +vbox.connect(okButton, "clicked()", this, "exit"); +vbox.show(); +application.exec(); diff --git a/kjsembed/tests/test_qtoolbox.js b/kjsembed/tests/test_qtoolbox.js new file mode 100755 index 00000000..c56e1d4a --- /dev/null +++ b/kjsembed/tests/test_qtoolbox.js @@ -0,0 +1,22 @@ +#!/usr/bin/env kjscmd + +var vbox = new QVBox(this); +var tb = new QToolBox(vbox); + +var c1 = new QPushButton( tb ); +var c2 = new QPushButton( tb ); + +function itemchanged(idx) { + alert( "Tab Changed, " + tb.item(idx).text ); +} + +c1.text = "Tab1's button"; +c2.text = "Tab2's button"; + +tb.addItem(c1, "1"); +tb.addItem(c2, "2"); + +vbox.connect(tb, "currentChanged(int)", this, "itemchanged"); +vbox.show(); + +application.exec(); diff --git a/kjsembed/tests/test_rect.js b/kjsembed/tests/test_rect.js new file mode 100644 index 00000000..24f8cc69 --- /dev/null +++ b/kjsembed/tests/test_rect.js @@ -0,0 +1,38 @@ + +var x = 10; +var y = 10; +var w = 25; +var h = 25; + +var rect = new Rect(x,y,w,h); +var rect2 = new Rect(); +rect2.setX(rect.x()); +rect2.setY(rect.y()); +rect2.setHeight(rect.height()); +rect2.setWidth(rect.width()); + +if( rect.x() != x ) +{ + println( "X not "+ x +" " + rect.x()); + exit(1); +} + +if( rect.y() != y ) +{ + println( "Y not "+ y +" " + rect.y()); + exit(1); +} + +if( rect.width() != w ) +{ + println( "W not "+ w +" " + rect.width()); + exit(1); +} + +if( rect.height() != h ) +{ + println( "H not "+ h +" " + rect.height()); + exit(1); +} + +println( "All tests passed");
\ No newline at end of file diff --git a/kjsembed/tests/test_shellexec.js b/kjsembed/tests/test_shellexec.js new file mode 100644 index 00000000..51a2fbdd --- /dev/null +++ b/kjsembed/tests/test_shellexec.js @@ -0,0 +1,44 @@ +#!/usr/bin/env kjscmd + +println( "Hello World" ); +var proc = new Process(this); +proc.connect( proc, "readyReadStdout()", this, "stdOut" ); +proc.connect( proc, "readyReadStderr()", this, "stdError" ); +proc.connect( proc, "processExited()", this, "done" ); + +proc.addArgument("ps"); +proc.addArgument("-l"); + +if ( !proc.start() ) +{ + println( "Could not start process" ); +} + +println( "test single cmd" ); + +var output = shell("ps aux"); +println( "Shell responds: " + output ); + +application.exec(); + +function done() +{ + while ( proc.canReadLineStdout ) + stdOut(); + while ( proc.canReadLineStderr ) + stdError(); + println("Process done with " + proc.exitStatus ); + exit(0); +} + +function stdError( ) +{ + var errorMessage = proc.readLineStderr(); + println( "StdErr: " + errorMessage ); +} + +function stdOut( ) +{ + var message = proc.readLineStdout(); + println( "StdOut: " + message ); +}
\ No newline at end of file diff --git a/kjsembed/tests/test_size.js b/kjsembed/tests/test_size.js new file mode 100644 index 00000000..511b3530 --- /dev/null +++ b/kjsembed/tests/test_size.js @@ -0,0 +1,22 @@ + +var w = 25; +var h = 25; + +var size = new Size(w,h); +var size2 = new Size(); +size2.setHeight(size.height()); +size2.setWidth(size.width()); + +if( size.width() != w ) +{ + println( "W not "+ w +" " + size.width()); + exit(1); +} + +if( size.height() != h ) +{ + println( "H not "+ h +" " + size.height()); + exit(1); +} + +println( "All tests passed"); diff --git a/kjsembed/tests/test_splashscreen.js b/kjsembed/tests/test_splashscreen.js new file mode 100644 index 00000000..bb465df0 --- /dev/null +++ b/kjsembed/tests/test_splashscreen.js @@ -0,0 +1,16 @@ +var lab = new QLabel(this); +var splash = new QSplashScreen(this); +var pix = new Pixmap(); +pix.resize(128,128); +pix.fill("blue"); + +splash.setPixmap( pix ); +splash.show(); +for( var x = 0; x < 1000; ++x) +{ + splash.message("Count: " + x); + lab.text = "Count: " + x; +} +lab.show(); +splash.finish(lab); +application.exec(); diff --git a/kjsembed/tests/test_stdio.js b/kjsembed/tests/test_stdio.js new file mode 100644 index 00000000..932f7496 --- /dev/null +++ b/kjsembed/tests/test_stdio.js @@ -0,0 +1,29 @@ +#!/usr/bin/env kjscmd + +println( '==============================' ); + +println( 'Text with newline' ); +System.stdout.println( 'Text with newline' ); + +System.stdout.print( 'There should be an OK after the colon: ' ); +System.stdout.println( 'OK' ); + +System.stdout.println( 'stdin is readable: ' + System.stdin.isReadable() ); +System.stdout.println( 'stdin is writable: ' + System.stdin.isWritable() ); + +System.stdout.println( 'stdout is readable: ' + System.stdout.isReadable() ); +System.stdout.println( 'stdout is writable: ' + System.stdout.isWritable() ); + +System.stdout.println( 'stderr is readable: ' + System.stderr.isReadable() ); +System.stdout.println( 'stderr is writable: ' + System.stderr.isWritable() ); + +System.stdout.println( 'There should be an exception now: ' ); +System.stdin.println( 'INVALID' ); + +System.stdout.println( 'There should be another exception: ' ); +System.stdout.readLine( 'INVALID' ); + +println( '==============================' ); +System.stdout.println( dump(System.stdin) ); + +System.exit(0); diff --git a/kjsembed/tests/testkjsembed.cpp b/kjsembed/tests/testkjsembed.cpp new file mode 100644 index 00000000..8cb33adc --- /dev/null +++ b/kjsembed/tests/testkjsembed.cpp @@ -0,0 +1,64 @@ +/* + * Copyright (C) 2001-2002, Richard J. Moore <rich@kde.org> + * + * This 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. + * + * This 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 this library; see the file COPYING.LIB. If not, write to + * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, + * Boston, MA 02110-1301, USA. + */ + +#include <kaboutdata.h> +#include <kapplication.h> +#include <kcmdlineargs.h> +#include <klocale.h> +#include <kjs/interpreter.h> + +#include <kjsembed/jsconsolewidget.h> +#include <kjsembed/jsobjectproxy.h> +#include <kjsembed/dialogfactory.h> +#include <kjsembed/factory.h> +#include <kjsembed/securitypolicy.h> + +using namespace KJSEmbed; + +int main( int argc, char **argv ) +{ + KAboutData about( "test-kjsembed", I18N_NOOP("KJS Embed Test"), "0.1", + I18N_NOOP("Test"), + KAboutData::License_LGPL, I18N_NOOP("(c) 2001-2002 Richard Moore") ); + KCmdLineArgs::init( argc, argv, &about ); + KApplication app; + + // Setup Interpreter + KJS::Interpreter *js = Factory::defaultJS(); + KJS::Object global = js->globalObject(); + + // Create Console + JSConsoleWidget *console = new JSConsoleWidget( js ); + + console->addBindings( global ); + Factory::publish( &app, js, global, "app" ); + Factory::publish( console, js, global, "console" ); + + // Setup Window + app.setMainWidget( console ); + app.connect( &app, SIGNAL( lastWindowClosed() ), SLOT(quit()) ); + console->resize( 600, 450 ); + console->show(); + + return app.exec(); +} + +// Local Variables: +// c-basic-offset: 4 +// End: diff --git a/kjsembed/tests/thisfail.js b/kjsembed/tests/thisfail.js new file mode 100644 index 00000000..081d274e --- /dev/null +++ b/kjsembed/tests/thisfail.js @@ -0,0 +1,37 @@ + +var dcop = new Dcop(this); +dcop.attach(); + +println("this works"); +var foo = dcop.registeredApplications(); +println(foo); + +var s = this; +//var s = foo; +//var s = dcop; +//var s = Factory; + +println("1this works"); +try { +println(dump(s)); +} +catch(y) { +println('yyyyyy failed ' + y); +} + +println("22this works"+s); +try { +dump(s); +} +catch(x) { +println('xxxxxxxx failed ' + x); +} + +println("2this works"); +dumpCompletion(s); +println("/2this works"); + +println("3this fails"); +var bar = dumpCompletion(s); +println( typeof(bar) ); +println("done -------------"); diff --git a/kjsembed/tools/Doxyfile b/kjsembed/tools/Doxyfile new file mode 100644 index 00000000..e2686a09 --- /dev/null +++ b/kjsembed/tools/Doxyfile @@ -0,0 +1,824 @@ +# Doxyfile 1.2.9.1 + +# 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 (" ") + +#--------------------------------------------------------------------------- +# General configuration options +#--------------------------------------------------------------------------- + +# The PROJECT_NAME tag is a single word (or a sequence of words surrounded +# by quotes) that should identify the project. + +PROJECT_NAME = KJSEmbed + +# 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 = + +# 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 = + +# 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: +# Brazilian, Chinese, Croatian, Czech, Danish, Dutch, Finnish, French, +# German, Hungarian, Italian, Japanese, Korean, Norwegian, Polish, +# Portuguese, Romanian, Russian, Slovak, Slovene, Spanish and Swedish. + +OUTPUT_LANGUAGE = English + +# 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 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 = NO + +# 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 class will be included in the various +# overviews. This option has no effect if EXTRACT_ALL is enabled. + +HIDE_UNDOC_CLASSES = YES + +# 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 = NO + +# 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 + +# 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 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 = NO + +# 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. It is allowed to use relative paths in the argument list. + +STRIP_FROM_PATH = + +# 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 CLASS_DIAGRAMS tag is set to YES (the default) Doxygen will +# generate a class diagram (in Html and LaTeX) for classes with base or +# super classes. Setting the tag to NO turns the diagrams off. + +CLASS_DIAGRAMS = YES + +# 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. + +SOURCE_BROWSER = NO + +# 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 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 +# users are adviced to set this option to NO. + +CASE_SENSE_NAMES = YES + +# 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 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 = YES + +# 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 + +# If the SHOW_INCLUDE_FILES tag is set to YES (the default) then Doxygen +# will put list of the files that are included by a file in the documentation +# of that file. + +SHOW_INCLUDE_FILES = YES + +# 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 the Qt-style comments (thus requiring an +# explict @brief command for a brief description. + +JAVADOC_AUTOBRIEF = YES + +# If the INHERIT_DOCS tag is set to YES (the default) then an undocumented +# member inherits the documentation from any documented member that it +# reimplements. + +INHERIT_DOCS = YES + +# 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 = NO + +# 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 + +# 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 + +# The ENABLED_SECTIONS tag can be used to enable conditional +# documentation sections, marked by \if sectionname ... \endif. + +ENABLED_SECTIONS = + +# 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 + +# 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 = + +# The MAX_INITIALIZER_LINES tag determines the maximum number of lines +# the initial value of a variable or define consist 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 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 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 + +#--------------------------------------------------------------------------- +# 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 = YES + +# 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 = NO + +# 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. + +WARN_FORMAT = + +# 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 = headers + +# 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 all files are included. + +FILE_PATTERNS = *.h + +# 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 = NO + +# 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 = doxygen_fakes.h +#EXCLUDE = customobject_imp.h jsfactory_imp.h jsproxy_imp.h \ +# kjsembedpart_imp.h jsbuiltin_imp.h \ +# jsobjectproxy_imp.h jsvalueproxy_imp.h \ +# doxygen_fakes.h + +# 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. + +EXCLUDE_PATTERNS = *.moc.* + +# 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 = + +# 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. + +INPUT_FILTER = + +# 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. + +FILTER_SOURCE_FILES = 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 = KJSEmbed + +#--------------------------------------------------------------------------- +# 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 = NO + +# 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 = . + +# 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 + +HTML_STYLESHEET = + +# 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 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 compressed HTML help file (.chm) +# of the generated HTML documentation. + +GENERATE_HTMLHELP = NO + +# 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 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 + +# 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 + +# If the GENERATE_TREEVIEW tag 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 and frames is required (for instance Netscape 4.0+ +# or Internet explorer 4.0+). + +GENERATE_TREEVIEW = 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 + +#--------------------------------------------------------------------------- +# 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 = + +# 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 = NO + +# 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 = NO + +# 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 + +#--------------------------------------------------------------------------- +# 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 optimised 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 = + +# 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 assigments. 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 = + +# The MAN_EXTENSION tag determines the extension that is added to +# the generated man pages (default is the subroutine's section .3) + +MAN_EXTENSION = + +# 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. Note that this +# feature is still experimental and incomplete at the +# moment. + +GENERATE_XML = YES + +#--------------------------------------------------------------------------- +# 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 = YES + +# 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_PREDEFINED tags. + +EXPAND_ONLY_PREDEF = YES + +# 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. + +PREDEFINED = Q_PROPERTY()= + +# If the MACRO_EXPANSION and EXPAND_PREDEF_ONLY 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 = + +#--------------------------------------------------------------------------- +# Configuration::addtions related to external references +#--------------------------------------------------------------------------- + +# The TAGFILES tag can be used to specify one or more tagfiles. + +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 + +# The PERL_PATH should be the absolute path and name of the perl script +# interpreter (i.e. the result of `which perl'). + +PERL_PATH = + +#--------------------------------------------------------------------------- +# Configuration options related to the dot tool +#--------------------------------------------------------------------------- + +# 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 = NO + +# 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 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 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 + +# 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 on the path. + +DOT_PATH = + +# The MAX_DOT_GRAPH_WIDTH tag can be used to set the maximum allowed width +# (in pixels) of the graphs generated by dot. If a graph becomes larger than +# this value, doxygen will try to truncate the graph, so that it fits within +# the specified constraint. Beware that most browsers cannot cope with very +# large images. + +MAX_DOT_GRAPH_WIDTH = 1024 + +# The MAX_DOT_GRAPH_HEIGHT tag can be used to set the maximum allows height +# (in pixels) of the graphs generated by dot. If a graph becomes larger than +# this value, doxygen will try to truncate the graph, so that it fits within +# the specified constraint. Beware that most browsers cannot cope with very +# large images. + +MAX_DOT_GRAPH_HEIGHT = 1024 + +# 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 intermedate dot files that are used to generate +# the various graphs. + +DOT_CLEANUP = YES + +#--------------------------------------------------------------------------- +# Configuration::addtions related to the search engine +#--------------------------------------------------------------------------- + +# The SEARCHENGINE tag specifies whether or not a search engine should be +# used. If set to NO the values of all tags below this one will be ignored. + +SEARCHENGINE = NO + +# The CGI_NAME tag should be the name of the CGI script that +# starts the search engine (doxysearch) with the correct parameters. +# A script with this name will be generated by doxygen. + +CGI_NAME = + +# The CGI_URL tag should be the absolute URL to the directory where the +# cgi binaries are located. See the documentation of your http daemon for +# details. + +CGI_URL = + +# The DOC_URL tag should be the absolute URL to the directory where the +# documentation is located. If left blank the absolute path to the +# documentation, with file:// prepended to it, will be used. + +DOC_URL = + +# The DOC_ABSPATH tag should be the absolute path to the directory where the +# documentation is located. If left blank the directory on the local machine +# will be used. + +DOC_ABSPATH = + +# The BIN_ABSPATH tag must point to the directory where the doxysearch binary +# is installed. + +BIN_ABSPATH = + +# The EXT_DOC_PATHS tag can be used to specify one or more paths to +# documentation generated for other projects. This allows doxysearch to search +# the documentation for these projects as well. + +EXT_DOC_PATHS = diff --git a/kjsembed/tools/README b/kjsembed/tools/README new file mode 100644 index 00000000..6cb7547e --- /dev/null +++ b/kjsembed/tools/README @@ -0,0 +1,3 @@ +This directory contains work that will hopefully lead to automatic generation +of the bindings. + diff --git a/kjsembed/tools/coverage/README b/kjsembed/tools/coverage/README new file mode 100644 index 00000000..e6b57569 --- /dev/null +++ b/kjsembed/tools/coverage/README @@ -0,0 +1,2 @@ +A simplistic way to check which objects are supported by kjsembed and which +are missing. diff --git a/kjsembed/tools/coverage/allqobjects.txt b/kjsembed/tools/coverage/allqobjects.txt new file mode 100644 index 00000000..853e9e1d --- /dev/null +++ b/kjsembed/tools/coverage/allqobjects.txt @@ -0,0 +1,145 @@ +QAccel +QAccessibleObject +QAction +QActionGroup +QApplication +QAquaStyle +QAssistantClient +QAxObject +QAxWidget +QBoxLayout +QButton +QButtonGroup +QCDEStyle +QCanvas +QCanvasView +QCheckBox +QClipboard +QColorDialog +QColorDrag +QComboBox +QCommonStyle +QCopChannel +QDataBrowser +QDataPump +QDataTable +QDataView +QDateEdit +QDateTimeEdit +QDateTimeEditBase +QDesktopWidget +QDial +QDialog +QDns +QDockArea +QDockWindow +QDoubleValidator +QDragObject +QEditorFactory +QErrorMessage +QEventLoop +QFileDialog +QFileIconProvider +QFontDialog +QFrame +QFtp +QGLWidget +QGrid +QGridLayout +QGridView +QGroupBox +QHBox +QHBoxLayout +QHButtonGroup +QHGroupBox +QHeader +QHttp +QIconDrag +QIconView +QImageDrag +QInputDialog +QIntValidator +QLCDNumber +QLabel +QLayout +QLineEdit +QListBox +QListView +QLocalFs +QMacStyle +QMainWindow +QMenuBar +QMessageBox +QMotif +QMotifDialog +QMotifPlusStyle +QMotifStyle +QMotifWidget +QMultiLineEdit +QNPInstance +QNPWidget +QNetworkOperation +QNetworkProtocol +QObject +QObjectCleanupHandler +QPlatinumStyle +QPopupMenu +QProcess +QProgressBar +QProgressDialog +QPushButton +QRadioButton +QRegExpValidator +QSGIStyle +QScrollBar +QScrollView +QServerSocket +QSessionManager +QSignal +QSignalMapper +QSizeGrip +QSlider +QSocket +QSocketNotifier +QSound +QSpinBox +QSplashScreen +QSplitter +QSqlDatabase +QSqlDriver +QSqlEditorFactory +QSqlForm +QStatusBar +QStoredDrag +QStyle +QStyleSheet +QTabBar +QTabDialog +QTabWidget +QTable +QTextBrowser +QTextDrag +QTextEdit +QTextView +QTimeEdit +QTimer +QToolBar +QToolBox +QToolButton +QToolTipGroup +QTranslator +QUriDrag +QUrlOperator +QVBox +QVBoxLayout +QVButtonGroup +QVGroupBox +QValidator +QWSKeyboardHandler +QWidget +QWidgetStack +QWindowsStyle +QWindowsXPStyle +QWizard +QWorkspace +QXtWidget diff --git a/kjsembed/tools/coverage/classes.js b/kjsembed/tools/coverage/classes.js new file mode 100644 index 00000000..acd7206e --- /dev/null +++ b/kjsembed/tools/coverage/classes.js @@ -0,0 +1,5 @@ +var classes = Factory.constructors().sort(); + +// Print out the supported classes +for ( var i=0 ; i < classes.length ; i++ ) + print( classes[i]+'\n' ); diff --git a/kjsembed/tools/coverage/coverage.sh b/kjsembed/tools/coverage/coverage.sh new file mode 100644 index 00000000..3b181bb3 --- /dev/null +++ b/kjsembed/tools/coverage/coverage.sh @@ -0,0 +1,7 @@ +#!/bin/sh + +KJSCMD='../../kjscmd' + +$KJSCMD classes.js > supported.txt +$KJSCMD unsupported.js < allqobjects.txt > unsupported.txt + diff --git a/kjsembed/tools/coverage/supported.txt b/kjsembed/tools/coverage/supported.txt new file mode 100644 index 00000000..dbf96951 --- /dev/null +++ b/kjsembed/tools/coverage/supported.txt @@ -0,0 +1,71 @@ +Config +Dcop +EvalError +Image +Line +Movie +NetAccess +Painter +Pen +Pixmap +PixmapLabel +QBoxLayout +QButtonGroup +QCanvasView +QCheckBox +QComboBox +QDataBrowser +QDataTable +QDataView +QDateEdit +QDateTimeEdit +QDial +QDialog +QFrame +QGrid +QGroupBox +QHBox +QHBoxLayout +QIconView +QLCDNumber +QLabel +QLayout +QLayoutWidget +QLineEdit +QListBox +QListView +QMainWindow +QMultiLineEdit +QObject +QPopupMenu +QProgressBar +QPushButton +QRadioButton +QScrollBar +QScrollView +QSlider +QSpinBox +QSplitter +QTabWidget +QTable +QTextBrowser +QTextEdit +QTextView +QTimeEdit +QTimer +QToolBox +QToolButton +QVBox +QVBoxLayout +QWidget +QWidgetStack +QWizard +RangeError +ReferenceError +SqlDatabase +SqlQuery +SyntaxError +TextLabel +TextStream +TypeError +URIError diff --git a/kjsembed/tools/coverage/unsupported.js b/kjsembed/tools/coverage/unsupported.js new file mode 100644 index 00000000..331849e2 --- /dev/null +++ b/kjsembed/tools/coverage/unsupported.js @@ -0,0 +1,11 @@ + +var line = readLine(); +while ( line != null ) { + line = line.replace( /^ */g, '' ); + line = line.replace( / *$/g, '' ); + + if ( !Factory.isSupported( line ) ) + print( line + ' MISSING\n' ); + + line = readLine(); +} diff --git a/kjsembed/tools/coverage/unsupported.txt b/kjsembed/tools/coverage/unsupported.txt new file mode 100644 index 00000000..1ea2eb7b --- /dev/null +++ b/kjsembed/tools/coverage/unsupported.txt @@ -0,0 +1,95 @@ +QAccel MISSING +QAccessibleObject MISSING +QAction MISSING +QActionGroup MISSING +QApplication MISSING +QAquaStyle MISSING +QAssistantClient MISSING +QAxObject MISSING +QAxWidget MISSING +QButton MISSING +QCDEStyle MISSING +QCanvas MISSING +QClipboard MISSING +QColorDialog MISSING +QColorDrag MISSING +QCommonStyle MISSING +QCopChannel MISSING +QDataPump MISSING +QDateTimeEditBase MISSING +QDesktopWidget MISSING +QDns MISSING +QDockArea MISSING +QDockWindow MISSING +QDoubleValidator MISSING +QDragObject MISSING +QEditorFactory MISSING +QErrorMessage MISSING +QEventLoop MISSING +QFileDialog MISSING +QFileIconProvider MISSING +QFontDialog MISSING +QFtp MISSING +QGLWidget MISSING +QGridLayout MISSING +QGridView MISSING +QHButtonGroup MISSING +QHGroupBox MISSING +QHeader MISSING +QHttp MISSING +QIconDrag MISSING +QImageDrag MISSING +QInputDialog MISSING +QIntValidator MISSING +QLocalFs MISSING +QMacStyle MISSING +QMenuBar MISSING +QMessageBox MISSING +QMotif MISSING +QMotifDialog MISSING +QMotifPlusStyle MISSING +QMotifStyle MISSING +QMotifWidget MISSING +QNPInstance MISSING +QNPWidget MISSING +QNetworkOperation MISSING +QNetworkProtocol MISSING +QObjectCleanupHandler MISSING +QPlatinumStyle MISSING +QProcess MISSING +QProgressDialog MISSING +QRegExpValidator MISSING +QSGIStyle MISSING +QServerSocket MISSING +QSessionManager MISSING +QSignal MISSING +QSignalMapper MISSING +QSizeGrip MISSING +QSocket MISSING +QSocketNotifier MISSING +QSound MISSING +QSplashScreen MISSING +QSqlDatabase MISSING +QSqlDriver MISSING +QSqlEditorFactory MISSING +QSqlForm MISSING +QStatusBar MISSING +QStoredDrag MISSING +QStyle MISSING +QStyleSheet MISSING +QTabBar MISSING +QTabDialog MISSING +QTextDrag MISSING +QToolBar MISSING +QToolTipGroup MISSING +QTranslator MISSING +QUriDrag MISSING +QUrlOperator MISSING +QVButtonGroup MISSING +QVGroupBox MISSING +QValidator MISSING +QWSKeyboardHandler MISSING +QWindowsStyle MISSING +QWindowsXPStyle MISSING +QWorkspace MISSING +QXtWidget MISSING diff --git a/kjsembed/tools/create_bindings.sh b/kjsembed/tools/create_bindings.sh new file mode 100755 index 00000000..54c65965 --- /dev/null +++ b/kjsembed/tools/create_bindings.sh @@ -0,0 +1,23 @@ +#!/bin/sh + +function bind_class() +{ + xsltproc doxygen2imp_h.xsl "xml/class$1.xml" > "$2_imp.h" + xsltproc doxygen2imp_cpp.xsl "xml/class$1.xml" > "$2_imp.cpp" + xsltproc doxygen2cons_h.xsl "xml/class$1.xml" > "$2_cons.h" + xsltproc doxygen2cons_cpp.xsl "xml/class$1.xml" > "$2_cons.cpp" +} + +doxygen + +bind_class QComboBox qcombobox +bind_class Qt qnamespace +bind_class KPopupTitle kpopupmenu + +#bind_class QDir qdir +#bind_class QListViewItem qlistview + +#bind_class QTimer qtimer +#bind_class QBrush qbrush +#bind_class QPen qpen +#bind_class QPainter qpainter diff --git a/kjsembed/tools/doxygen2cons_cpp.xsl b/kjsembed/tools/doxygen2cons_cpp.xsl new file mode 100644 index 00000000..e352246f --- /dev/null +++ b/kjsembed/tools/doxygen2cons_cpp.xsl @@ -0,0 +1,99 @@ +<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform"> +<xsl:output method="text" /> + +<xsl:template match="/doxygen/compounddef"> +<xsl:variable name="clazz" select="compoundname" /> +<xsl:variable name="consmeth" select="sectiondef/memberdef[@kind='function' and @prot='public']" /> + +#include <klocale.h> +#include <kjs/object.h> + +#include <<xsl:value-of select="includes" />> +#include "<xsl:value-of select="substring-before(includes,'.h')"/>_imp.h" + +/** + * Namespace containing the KJSEmbed library. + */ +namespace KJSEmbed { + +<!-- Select and invoke the correct constructor. --> +KJS::Object <xsl:value-of select="$clazz" />Cons::construct( KJS::ExecState *exec, KJS::Object &obj, const KJS::List &args ) +{ + switch( id ) { +<xsl:for-each select="$consmeth"> + <xsl:choose> + <xsl:when test="name = $clazz"> + <xsl:variable name="cons_name"><xsl:value-of select="name" />_<xsl:value-of select="position()" /></xsl:variable> + <xsl:variable name="cons_id">Constructor_<xsl:value-of select="$cons_name" /></xsl:variable> + case <xsl:value-of select="$cons_id" />: + return <xsl:value-of select="$cons_name" />( exec, obj, args ); + break; + </xsl:when> + </xsl:choose> +</xsl:for-each> + default: + break; + } + + QString msg = i18n("<xsl:value-of select="$clazz" />Cons has no constructor with id '%1'").arg(id); + KJS::Object err = KJS::Error::create( exec, KJS::ReferenceError, msg.utf8() ); + exec->setException( err ); + return err; +} + +<!-- Implementations of the constructors. --> +<xsl:for-each select="$consmeth"> + <xsl:choose> + <xsl:when test="name = $clazz"> + <xsl:variable name="cons_name"><xsl:value-of select="name" />_<xsl:value-of select="position()" /></xsl:variable> + <xsl:variable name="cons_id">Constructor_<xsl:value-of select="$cons_name" /></xsl:variable> +KJS::Object <xsl:value-of select="$clazz" />Cons::<xsl:value-of select="$cons_name" />( KJS::ExecState *exec, KJS::Object &obj, const KJS::List &args ) +{ + <xsl:for-each select="param/type"> + <xsl:choose> + <xsl:when test=". = 'QString'"> + QString arg<xsl:value-of select="position()-1" /> = (args.size() >= <xsl:value-of select="position()" />) ? args[<xsl:value-of select="position()-1" />].toString(exec).qstring() : QString::null; + </xsl:when> + <xsl:when test=". = 'const QString &'"> + QString arg<xsl:value-of select="position()-1" /> = (args.size() >= <xsl:value-of select="position()" />) ? args[<xsl:value-of select="position()-1" />].toString(exec).qstring() : QString::null; + </xsl:when> + <xsl:when test=". = 'const char *'"> + const char *arg<xsl:value-of select="position()-1" /> = (args.size() >= <xsl:value-of select="position()" />) ? args[<xsl:value-of select="position()-1" />].toString(exec).ascii() : 0; + </xsl:when> + <xsl:when test=". = 'int'"> + int arg<xsl:value-of select="position()-1" /> = (args.size() >= <xsl:value-of select="position()" />) ? args[<xsl:value-of select="position()-1" />].toInteger(exec) : -1; + </xsl:when> + <xsl:when test=". = 'uint'"> + uint arg<xsl:value-of select="position()-1" /> = (args.size() >= <xsl:value-of select="position()" />) ? args[<xsl:value-of select="position()-1" />].toInteger(exec) : -1; + </xsl:when> + <xsl:when test=". = 'double'"> + double arg<xsl:value-of select="position()-1" /> = (args.size() >= <xsl:value-of select="position()" />) ? args[<xsl:value-of select="position()-1" />].toInteger(exec) : -1; + </xsl:when> + <xsl:when test=". = 'bool'"> + bool arg<xsl:value-of select="position()-1" /> = (args.size() >= <xsl:value-of select="position()" />) ? args[<xsl:value-of select="position()-1" />].toBoolean(exec) : false; + </xsl:when> + <xsl:when test=". = 'const QStringList &'"> + QStringList arg<xsl:value-of select="position()-1" />; + if ( args.size() >= <xsl:value-of select="position()" /> ) { + // TODO: populate the list + } + </xsl:when> + <xsl:otherwise> + // Unsupported parameter <xsl:value-of select="." /> + return KJS::Value(); + </xsl:otherwise> + </xsl:choose> + </xsl:for-each> +} + </xsl:when> + </xsl:choose> +</xsl:for-each> + +} // namespace KJSEmbed + +// Local Variables: +// c-basic-offset: 4 +// End: + +</xsl:template> +</xsl:stylesheet> diff --git a/kjsembed/tools/doxygen2cons_h.xsl b/kjsembed/tools/doxygen2cons_h.xsl new file mode 100644 index 00000000..8140d52e --- /dev/null +++ b/kjsembed/tools/doxygen2cons_h.xsl @@ -0,0 +1,79 @@ +<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform"> +<xsl:output method="text" /> + +<xsl:template match="/doxygen/compounddef"> + +<xsl:variable name="clazz" select="compoundname" /> +<xsl:variable name="consmeth" select="sectiondef/memberdef[@kind='function' and @prot='public']" /> + +#ifndef KJSEMBED_<xsl:value-of select="$clazz" />_H +#define KJSEMBED_<xsl:value-of select="$clazz" />_H + +#include <kjs/interpreter.h> +#include <kjs/object.h> + +#include <kjsembed/jsobjectproxy_imp.h> + +class <xsl:value-of select="$clazz" />; + +/** + * Namespace containing the KJSEmbed library. + */ +namespace KJSEmbed { + +/** + * Wrapper class for <xsl:value-of select="$clazz" /> constructors. + * + * @author Richard Moore, rich@kde.org + */ +class <xsl:value-of select="$clazz" />Cons : public JSProxyImp +{ +public: + /** Enumerates the constructors supported by this class. */ + enum Constructors { +<xsl:for-each select="$consmeth"> + <xsl:choose> + <xsl:when test="name = $clazz"> + <xsl:variable name="cons_name"><xsl:value-of select="name" />_<xsl:value-of select="position()" /></xsl:variable> + <xsl:variable name="cons_id">Constructor_<xsl:value-of select="$cons_name" /></xsl:variable> + <xsl:text> </xsl:text><xsl:value-of select="$cons_id" />, +</xsl:when> + </xsl:choose> +</xsl:for-each> + LastConstuctor = -1 + }; + + // + // Constructors implemented by this class. + // +<xsl:for-each select="$consmeth"> + <xsl:variable name="cons_name"><xsl:value-of select="name" />_<xsl:value-of select="position()" /></xsl:variable> + <xsl:choose> + <xsl:when test="name = $clazz"> + KJS::Object <xsl:value-of select="$cons_name" />( KJS::ExecState *exec, KJS::Object &obj, const KJS::List &args );</xsl:when> + </xsl:choose> +</xsl:for-each> + + // + // JS binding code. + // + + /** Returns true iff this object implements the construct function. */ + virtual bool implementsConstruct() const { return true; } + + /** Invokes the construct function. */ + virtual KJS::Value construct( KJS::ExecState *exec, KJS::Object &self, const KJS::List &args ); +private: + int id; +}; + +} // namespace KJSEmbed + +#endif // KJSEMBED_<xsl:value-of select="compoundname" />_H + +// Local Variables: +// c-basic-offset: 4 +// End: + +</xsl:template> +</xsl:stylesheet> diff --git a/kjsembed/tools/doxygen2imp_cpp.xsl b/kjsembed/tools/doxygen2imp_cpp.xsl new file mode 100644 index 00000000..4e8d73bf --- /dev/null +++ b/kjsembed/tools/doxygen2imp_cpp.xsl @@ -0,0 +1,299 @@ +<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform"> +<xsl:output method="text" /> + +<xsl:template match="/doxygen/compounddef"> + +<xsl:variable name="clazz" select="compoundname" /> +<xsl:variable name="consmeth" select="sectiondef/memberdef[@kind='function' and @prot='public']" /> +<xsl:variable name="enums" select="sectiondef/memberdef[@kind='enum' and @prot='public']" /> + +#include <qpalette.h> +#include <qpixmap.h> +#include <qfont.h> + +#include <klocale.h> +#include <kjs/object.h> +#include <kdebug.h> + +#include <kjsembed/jsobjectproxy.h> +#include <kjsembed/jsopaqueproxy.h> +#include <kjsembed/jsbinding.h> + +#include <<xsl:value-of select="includes" />> +#include "<xsl:value-of select="substring-before(includes,'.h')"/>_imp.h" + +/** + * Namespace containing the KJSEmbed library. + */ +namespace KJSEmbed { + +<xsl:value-of select="$clazz" />Imp::<xsl:value-of select="$clazz" />Imp( KJS::ExecState *exec, int id ) + : JSProxyImp(exec), mid(id) +{ +} + +<xsl:value-of select="$clazz" />Imp::~<xsl:value-of select="$clazz" />Imp() +{ +} + +void <xsl:value-of select="$clazz" />Imp::addBindings( KJS::ExecState *exec, KJS::Object &object ) +{ + JSProxy::MethodTable methods[] = { +<xsl:for-each select="$consmeth"> + <xsl:variable name="method_name"><xsl:value-of select="name" />_<xsl:value-of select="position()" /></xsl:variable> + <xsl:variable name="method_id">Method_<xsl:value-of select="$method_name" /></xsl:variable> + <xsl:choose> + <xsl:when test="not(starts-with( name, 'operator' ) or starts-with( name, '~' ) or starts-with( name, $clazz ))"> + { <xsl:value-of select="$method_id" />, "<xsl:value-of select="name" />" },</xsl:when></xsl:choose> +</xsl:for-each> + { 0, 0 } + }; + + int idx = 0; + do { + <xsl:value-of select="$clazz" />Imp *meth = new <xsl:value-of select="$clazz" />Imp( exec, methods[idx].id ); + object.put( exec , methods[idx].name, KJS::Object(meth) ); + ++idx; + } while( methods[idx].id ); + +<xsl:if test="count($enums) != 0"> + // + // Define the enum constants + // + struct EnumValue { + const char *id; + int val; + }; + + EnumValue enums[] = { +<xsl:for-each select="$enums"> + // enum <xsl:value-of select="./name" /> + <xsl:for-each select="./enumvalue"> + { "<xsl:value-of select="./name" />", <xsl:value-of select="$clazz" />::<xsl:value-of select="./name" /> },</xsl:for-each> +</xsl:for-each> + { 0, 0 } + }; + + int enumidx = 0; + do { + object.put( exec, enums[enumidx].id, KJS::Number(enums[enumidx].val), KJS::ReadOnly ); + ++enumidx; + } while( enums[enumidx].id ); +</xsl:if> +} + +<xsl:value-of select="$clazz" /> *<xsl:value-of select="$clazz" />Imp::to<xsl:value-of select="$clazz" />( KJS::Object &self ) +{ + JSObjectProxy *ob = JSProxy::toObjectProxy( self.imp() ); + if ( ob ) { + QObject *obj = ob->object(); + if ( obj ) + return dynamic_cast<QComboBox *>( obj ); + } + + JSOpaqueProxy *op = JSProxy::toOpaqueProxy( self.imp() ); + if ( !op ) + return 0; + + if ( op->typeName() != "<xsl:value-of select="$clazz" />" ) + return 0; + + return (<xsl:value-of select="$clazz" /> *)( op->toVoidStar() ); +} + +<!-- Select and invoke the correct method. --> +KJS::Value <xsl:value-of select="$clazz" />Imp::call( KJS::ExecState *exec, KJS::Object &self, const KJS::List &args ) +{ + instance = <xsl:value-of select="$clazz" />Imp::to<xsl:value-of select="$clazz" />( self ); + + switch( mid ) { +<xsl:for-each select="$consmeth"> + <xsl:variable name="method_name"><xsl:value-of select="name" />_<xsl:value-of select="position()" /></xsl:variable> + <xsl:variable name="method_id">Method_<xsl:value-of select="$method_name" /></xsl:variable> + <xsl:choose> + <xsl:when test="not(starts-with( name, 'operator' ) or starts-with( name, '~' ) or starts-with( name, $clazz ))"> + case <xsl:value-of select="$method_id" />: + return <xsl:value-of select="$method_name" />( exec, self, args ); + break; + </xsl:when> + </xsl:choose> +</xsl:for-each> + default: + break; + } + + QString msg = i18n( "<xsl:value-of select="$clazz" />Imp has no method with id '%1'" ).arg( mid ); + KJS::Object err = KJS::Error::create( exec, KJS::ReferenceError, msg.utf8() ); + exec->setException( err ); + return err; +} + +<!-- Create the implementation for each method. --> +<xsl:for-each select="$consmeth"> +<xsl:variable name="method"> +<xsl:value-of select="$clazz" />Imp::<xsl:value-of select="name" />_<xsl:value-of select="position()" /> +</xsl:variable> + + <xsl:choose> + <xsl:when test="(name != $clazz) and not(starts-with(name, 'operator') or starts-with(name, '~'))"> +<!-- Binding defined for a specific method. --> +KJS::Value <xsl:value-of select="$method" />( KJS::ExecState *exec, KJS::Object &obj, const KJS::List &args ) +{ + <xsl:for-each select="param/type"> + <xsl:choose> + <xsl:when test=". = 'QString'"> + QString arg<xsl:value-of select="position()-1" /> = (args.size() >= <xsl:value-of select="position()" />) ? args[<xsl:value-of select="position()-1" />].toString(exec).qstring() : QString::null; + </xsl:when> + <xsl:when test=". = 'const QString &'"> + QString arg<xsl:value-of select="position()-1" /> = (args.size() >= <xsl:value-of select="position()" />) ? args[<xsl:value-of select="position()-1" />].toString(exec).qstring() : QString::null; + </xsl:when> + <xsl:when test=". = 'const char *'"> + const char *arg<xsl:value-of select="position()-1" /> = (args.size() >= <xsl:value-of select="position()" />) ? args[<xsl:value-of select="position()-1" />].toString(exec).ascii() : 0; + </xsl:when> + <xsl:when test=". = 'int'"> + int arg<xsl:value-of select="position()-1" /> = (args.size() >= <xsl:value-of select="position()" />) ? args[<xsl:value-of select="position()-1" />].toInteger(exec) : -1; + </xsl:when> + <xsl:when test=". = 'uint'"> + uint arg<xsl:value-of select="position()-1" /> = (args.size() >= <xsl:value-of select="position()" />) ? args[<xsl:value-of select="position()-1" />].toInteger(exec) : -1; + </xsl:when> + <xsl:when test=". = 'double'"> + double arg<xsl:value-of select="position()-1" /> = (args.size() >= <xsl:value-of select="position()" />) ? args[<xsl:value-of select="position()-1" />].toInteger(exec) : -1; + </xsl:when> + <xsl:when test=". = 'bool'"> + bool arg<xsl:value-of select="position()-1" /> = (args.size() >= <xsl:value-of select="position()" />) ? args[<xsl:value-of select="position()-1" />].toBoolean(exec) : false; + </xsl:when> + <xsl:when test=". = 'const QFont &'"> + QFont arg<xsl:value-of select="position()-1" />; // TODO + </xsl:when> + <xsl:when test=". = 'const QPalette &'"> + QPalette arg<xsl:value-of select="position()-1" />; // TODO + </xsl:when> + <xsl:when test=". = 'const QStringList &'"> + QStringList arg<xsl:value-of select="position()-1" /> = extractQStringList(exec, args, <xsl:value-of select="position()-1" />); + </xsl:when> + <xsl:when test=". = 'const QStrList &'"> + QStrList arg<xsl:value-of select="position()-1" />; + if ( args.size() >= <xsl:value-of select="position()" /> ) { + // TODO: populate the list + } + </xsl:when> + <xsl:when test=". = 'const QRect &'"> + QRect arg<xsl:value-of select="position()-1" /> = extractQRect(exec, args, <xsl:value-of select="position()-1" />); + </xsl:when> + <xsl:when test=". = 'const QSize &'"> + QSize arg<xsl:value-of select="position()-1" /> = extractQSize(exec, args, <xsl:value-of select="position()-1" />); + </xsl:when> + <xsl:when test=". = 'const QPixmap &'"> + QPixmap arg<xsl:value-of select="position()-1" /> = extractQPixmap(exec, args, <xsl:value-of select="position()-1" />); + </xsl:when> + <xsl:when test=". = 'const QColor &'"> + QColor arg<xsl:value-of select="position()-1" /> = extractQColor(exec, args, <xsl:value-of select="position()-1" />); + </xsl:when> + <xsl:when test=". = 'const QDate &'"> + QDate arg<xsl:value-of select="position()-1" /> = extractQDate(exec, args, <xsl:value-of select="position()-1" />); + </xsl:when> + <xsl:when test=". = 'const QTime &'"> + QTime arg<xsl:value-of select="position()-1" /> = extractQTime(exec, args, <xsl:value-of select="position()-1" />); + </xsl:when> + <xsl:when test=". = 'const QDateTime &'"> + QDateTime arg<xsl:value-of select="position()-1" /> = extractQDateTime(exec, args, <xsl:value-of select="position()-1" />); + </xsl:when> + <xsl:when test=". = 'Policy'"> + QComboBox::Policy arg<xsl:value-of select="position()-1" />; // TODO (hack for combo box) + </xsl:when> + <xsl:otherwise> + // Unsupported parameter <xsl:value-of select="." /> + return KJS::Value(); + + <xsl:value-of select="." />arg<xsl:value-of select="position()-1" />; // Dummy + </xsl:otherwise> + </xsl:choose> + </xsl:for-each> + + <!-- Specifies the return type --> + <xsl:variable name="rettype"> + <xsl:choose> + <xsl:when test="starts-with(type,'virtual ')"> + <xsl:value-of select="substring-after(type,'virtual ')" /> + </xsl:when> + <xsl:otherwise><xsl:value-of select="type" /></xsl:otherwise> + </xsl:choose> + </xsl:variable> + + <xsl:choose> + + <xsl:when test="$rettype = 'bool'"> + bool ret; + ret = instance-><xsl:value-of select="name" />( <xsl:for-each select="param"> + arg<xsl:value-of select="position()-1" /><xsl:if test="position() != count(../param)">,</xsl:if></xsl:for-each> ); + return KJS::Boolean( ret ); + </xsl:when> + + <xsl:when test="$rettype = 'int'"> + int ret; + ret = instance-><xsl:value-of select="name" />( <xsl:for-each select="param"> + arg<xsl:value-of select="position()-1" /><xsl:if test="position() != count(../param)">,</xsl:if></xsl:for-each> ); + return KJS::Number( ret ); + </xsl:when> + + <xsl:when test="$rettype = 'uint'"> + uint ret; + ret = instance-><xsl:value-of select="name" />( <xsl:for-each select="param"> + arg<xsl:value-of select="position()-1" /><xsl:if test="position() != count(../param)">,</xsl:if></xsl:for-each> ); + return KJS::Number( ret ); + </xsl:when> + + <xsl:when test="$rettype = 'double'"> + double ret; + ret = instance-><xsl:value-of select="name" />( <xsl:for-each select="param"> + arg<xsl:value-of select="position()-1" /><xsl:if test="position() != count(../param)">,</xsl:if></xsl:for-each> ); + return KJS::Number( ret ); + </xsl:when> + + <xsl:when test="$rettype = 'QString'"> + QString ret; + ret = instance-><xsl:value-of select="name" />( <xsl:for-each select="param"> + arg<xsl:value-of select="position()-1" /><xsl:if test="position() != count(../param)">,</xsl:if></xsl:for-each> ); + return KJS::String( ret ); + </xsl:when> + + <xsl:when test="$rettype = 'const char *'"> + const char *ret; + ret = instance-><xsl:value-of select="name" />( <xsl:for-each select="param"> + arg<xsl:value-of select="position()-1" /><xsl:if test="position() != count(../param)">,</xsl:if></xsl:for-each> ); + return KJS::String( ret ); + </xsl:when> + + <xsl:when test="$rettype = 'QStringList'"> + QStringList ret; + ret = instance-><xsl:value-of select="name" />( <xsl:for-each select="param"> + arg<xsl:value-of select="position()-1" /><xsl:if test="position() != count(../param)">,</xsl:if></xsl:for-each> ); + + return convertToValue( exec, ret ); + </xsl:when> + + <xsl:when test="$rettype = 'void'"> + instance-><xsl:value-of select="name" />( <xsl:for-each select="param"> + arg<xsl:value-of select="position()-1" /><xsl:if test="position() != count(../param)">,</xsl:if></xsl:for-each> ); + return KJS::Value(); // Returns void + </xsl:when> + + <xsl:otherwise> + instance-><xsl:value-of select="name" />( <xsl:for-each select="param"> + arg<xsl:value-of select="position()-1" /><xsl:if test="position() != count(../param)">,</xsl:if></xsl:for-each> ); + return KJS::Value(); // Returns '<xsl:value-of select="$rettype" />' + </xsl:otherwise> + </xsl:choose> +} + </xsl:when> + </xsl:choose> +</xsl:for-each> + +} // namespace KJSEmbed + +// Local Variables: +// c-basic-offset: 4 +// End: + +</xsl:template> +</xsl:stylesheet> diff --git a/kjsembed/tools/doxygen2imp_h.xsl b/kjsembed/tools/doxygen2imp_h.xsl new file mode 100644 index 00000000..ce00e7a1 --- /dev/null +++ b/kjsembed/tools/doxygen2imp_h.xsl @@ -0,0 +1,86 @@ +<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform"> +<xsl:output method="text" /> + +<xsl:template match="/doxygen/compounddef"> + +<xsl:variable name="clazz" select="compoundname" /> +<xsl:variable name="consmeth" select="sectiondef/memberdef[@kind='function' and @prot='public']" /> + +#ifndef KJSEMBED_<xsl:value-of select="$clazz" />_H +#define KJSEMBED_<xsl:value-of select="$clazz" />_H + +#include <kjs/interpreter.h> +#include <kjs/object.h> + +#include <kjsembed/jsobjectproxy_imp.h> + +class <xsl:value-of select="$clazz" />; + +/** + * Namespace containing the KJSEmbed library. + */ +namespace KJSEmbed { + +/** + * Wrapper class for <xsl:value-of select="$clazz" /> methods. + * + * @author Richard Moore, rich@kde.org + */ +class <xsl:value-of select="$clazz" />Imp : public JSProxyImp +{ +public: + /** Enumerates the methods supported by this class. */ + enum Methods { +<xsl:for-each select="$consmeth"> + <xsl:variable name="method_name"><xsl:value-of select="name" />_<xsl:value-of select="position()" /></xsl:variable> + <xsl:choose> + <xsl:when test="not(starts-with( name, 'operator' ) or starts-with( name, '~' ) or starts-with( name, $clazz ))"> + Method_<xsl:value-of select="$method_name" />,</xsl:when> + </xsl:choose> +</xsl:for-each> + Method_Last = -1 + }; + + <xsl:value-of select="$clazz" />Imp( KJS::ExecState *exec, int id ); + ~<xsl:value-of select="$clazz" />Imp(); + + static void addBindings( KJS::ExecState *exec, KJS::Object &object ); + + static <xsl:value-of select="$clazz" /> *to<xsl:value-of select="$clazz" />( KJS::Object &object ); + + // + // Methods implemented by this class. + // +<xsl:for-each select="$consmeth"> + <xsl:variable name="method_name"><xsl:value-of select="name" />_<xsl:value-of select="position()" /></xsl:variable> + <xsl:choose> + <xsl:when test="not(starts-with( name, 'operator' ) or starts-with( name, '~' ) or starts-with( name, $clazz ))"> + KJS::Value <xsl:value-of select="$method_name" />( KJS::ExecState *exec, KJS::Object &obj, const KJS::List &args );</xsl:when> + </xsl:choose> +</xsl:for-each> + + // + // JS binding code. + // + + /** Returns true iff this object implements the call function. */ + virtual bool implementsCall() const { return true; } + + /** Invokes the call function. */ + virtual KJS::Value call( KJS::ExecState *exec, KJS::Object &self, const KJS::List &args ); + +private: + <xsl:value-of select="$clazz" /> *instance; // Temp + int mid; +}; + +} // namespace KJSEmbed + +#endif // KJSEMBED_<xsl:value-of select="compoundname" />_H + +// Local Variables: +// c-basic-offset: 4 +// End: + +</xsl:template> +</xsl:stylesheet> diff --git a/kjsembed/tools/headers/qbrush.h b/kjsembed/tools/headers/qbrush.h new file mode 100644 index 00000000..16e4f3db --- /dev/null +++ b/kjsembed/tools/headers/qbrush.h @@ -0,0 +1,91 @@ +/**************************************************************************** +** +** +** Definition of QBrush class +** +** Created : 940112 +** +** Copyright (C) 1992-2000 Trolltech AS. All rights reserved. +** +** This file is part of the kernel module of the Qt GUI Toolkit. +** +** This file may be distributed under the terms of the Q Public License +** as defined by Trolltech AS of Norway and appearing in the file +** LICENSE.QPL included in the packaging of this file. +** +** This file may be distributed and/or modified under the terms of the +** GNU General Public License version 2 as published by the Free Software +** Foundation and appearing in the file LICENSE.GPL included in the +** packaging of this file. +** +** Licensees holding valid Qt Enterprise Edition or Qt Professional Edition +** licenses may use this file in accordance with the Qt Commercial License +** Agreement provided with the Software. +** +** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE +** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. +** +** See http://www.trolltech.com/pricing.html or email sales@trolltech.com for +** information about Qt Commercial License Agreements. +** See http://www.trolltech.com/qpl/ for QPL licensing information. +** See http://www.trolltech.com/gpl/ for GPL licensing information. +** +** Contact info@trolltech.com if any conditions of this licensing are +** not clear to you. +** +**********************************************************************/ + +#ifndef QBRUSH_H +#define QBRUSH_H + +#ifndef QT_H +#include "qcolor.h" +#include "qshared.h" +#endif // QT_H + + +class Q_EXPORT QBrush: public Qt +{ +friend class QPainter; +public: + QBrush(); + QBrush( BrushStyle ); + QBrush( const QColor &, BrushStyle=SolidPattern ); + QBrush( const QColor &, const QPixmap & ); + QBrush( const QBrush & ); + ~QBrush(); + QBrush &operator=( const QBrush & ); + + BrushStyle style() const { return data->style; } + void setStyle( BrushStyle ); + const QColor &color()const { return data->color; } + void setColor( const QColor & ); + QPixmap *pixmap() const { return data->pixmap; } + void setPixmap( const QPixmap & ); + + bool operator==( const QBrush &p ) const; + bool operator!=( const QBrush &b ) const + { return !(operator==(b)); } + +private: + QBrush copy() const; + void detach(); + void init( const QColor &, BrushStyle ); + struct QBrushData : public QShared { // brush data + BrushStyle style; + QColor color; + QPixmap *pixmap; + } *data; +}; + + +/***************************************************************************** + QBrush stream functions + *****************************************************************************/ + +#ifndef QT_NO_DATASTREAM +Q_EXPORT QDataStream &operator<<( QDataStream &, const QBrush & ); +Q_EXPORT QDataStream &operator>>( QDataStream &, QBrush & ); +#endif + +#endif // QBRUSH_H diff --git a/kjsembed/tools/headers/qcanvas.h b/kjsembed/tools/headers/qcanvas.h new file mode 100644 index 00000000..62a33b65 --- /dev/null +++ b/kjsembed/tools/headers/qcanvas.h @@ -0,0 +1,806 @@ +/********************************************************************** +** +** +** Definition of QCanvas classes +** +** Created : 991211 +** +** Copyright (C) 1999-2002 Trolltech AS. All rights reserved. +** +** This file is part of the canvas module of the Qt GUI Toolkit. +** +** This file may be distributed under the terms of the Q Public License +** as defined by Trolltech AS of Norway and appearing in the file +** LICENSE.QPL included in the packaging of this file. +** +** This file may be distributed and/or modified under the terms of the +** GNU General Public License version 2 as published by the Free Software +** Foundation and appearing in the file LICENSE.GPL included in the +** packaging of this file. +** +** Licensees holding valid Qt Enterprise Edition licenses may use this +** file in accordance with the Qt Commercial License Agreement provided +** with the Software. +** +** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE +** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. +** +** See http://www.trolltech.com/pricing.html or email sales@trolltech.com for +** information about Qt Commercial License Agreements. +** See http://www.trolltech.com/qpl/ for QPL licensing information. +** See http://www.trolltech.com/gpl/ for GPL licensing information. +** +** Contact info@trolltech.com if any conditions of this licensing are +** not clear to you. +** +**********************************************************************/ + +#ifndef QCANVAS_H +#define QCANVAS_H + +#ifndef QT_H +#include "qscrollview.h" +#include "qpixmap.h" +#include "qptrlist.h" +#include "qbrush.h" +#include "qpen.h" +#include "qvaluelist.h" +#include "qpointarray.h" +#endif // QT_H + +#if !defined( QT_MODULE_CANVAS ) || defined( QT_LICENSE_PROFESSIONAL ) || defined( QT_INTERNAL_CANVAS ) +#define QM_EXPORT_CANVAS +#define QM_TEMPLATE_EXTERN_CANVAS +#else +#define QM_EXPORT_CANVAS Q_EXPORT +#define QM_TEMPLATE_EXTERN_CANVAS Q_TEMPLATE_EXTERN +#endif + +#ifndef QT_NO_CANVAS + + +class QCanvasSprite; +class QCanvasPolygonalItem; +class QCanvasRectangle; +class QCanvasPolygon; +class QCanvasEllipse; +class QCanvasText; +class QCanvasLine; +class QCanvasChunk; +class QCanvas; +class QCanvasItem; +class QCanvasView; +class QCanvasPixmap; + + +class QM_EXPORT_CANVAS QCanvasItemList : public QValueList<QCanvasItem*> { +public: + void sort(); + void drawUnique( QPainter& painter ); +}; + + +class QCanvasItemExtra; + +class QM_EXPORT_CANVAS QCanvasItem : public Qt +{ +public: + QCanvasItem(QCanvas* canvas); + virtual ~QCanvasItem(); + + double x() const + { return myx; } + double y() const + { return myy; } + double z() const + { return myz; } // (depth) + + virtual void moveBy(double dx, double dy); + void move(double x, double y); + void setX(double a) { move(a,y()); } + void setY(double a) { move(x(),a); } + void setZ(double a) { myz=a; changeChunks(); } + + bool animated() const; + virtual void setAnimated(bool y); + virtual void setVelocity( double vx, double vy); + void setXVelocity( double vx ) { setVelocity(vx,yVelocity()); } + void setYVelocity( double vy ) { setVelocity(xVelocity(),vy); } + double xVelocity() const; + double yVelocity() const; + virtual void advance(int stage); + + virtual bool collidesWith( const QCanvasItem* ) const=0; + + QCanvasItemList collisions(bool exact /* NO DEFAULT */ ) const; + + virtual void setCanvas(QCanvas*); + + virtual void draw(QPainter&)=0; + + void show(); + void hide(); + + virtual void setVisible(bool yes); + bool isVisible() const + { return (bool)vis; } + virtual void setSelected(bool yes); + bool isSelected() const + { return (bool)sel; } + virtual void setEnabled(bool yes); + bool isEnabled() const + { return (bool)ena; } + virtual void setActive(bool yes); + bool isActive() const + { return (bool)act; } +#ifndef QT_NO_COMPAT + bool visible() const + { return (bool)vis; } + bool selected() const + { return (bool)sel; } + bool enabled() const + { return (bool)ena; } + bool active() const + { return (bool)act; } +#endif + + enum RttiValues { + Rtti_Item = 0, + Rtti_Sprite = 1, + Rtti_PolygonalItem = 2, + Rtti_Text = 3, + Rtti_Polygon = 4, + Rtti_Rectangle = 5, + Rtti_Ellipse = 6, + Rtti_Line = 7, + Rtti_Spline = 8 + }; + + virtual int rtti() const; + static int RTTI; + + virtual QRect boundingRect() const=0; + virtual QRect boundingRectAdvanced() const; + + QCanvas* canvas() const + { return cnv; } + +protected: + void update() { changeChunks(); } + +private: + // For friendly subclasses... + + friend class QCanvasPolygonalItem; + friend class QCanvasSprite; + friend class QCanvasRectangle; + friend class QCanvasPolygon; + friend class QCanvasEllipse; + friend class QCanvasText; + friend class QCanvasLine; + + virtual QPointArray chunks() const; + virtual void addToChunks(); + virtual void removeFromChunks(); + virtual void changeChunks(); + virtual bool collidesWith( const QCanvasSprite*, + const QCanvasPolygonalItem*, + const QCanvasRectangle*, + const QCanvasEllipse*, + const QCanvasText* ) const = 0; + // End of friend stuff + + QCanvas* cnv; + static QCanvas* current_canvas; + double myx,myy,myz; + QCanvasItemExtra *ext; + QCanvasItemExtra& extra(); + uint ani:1; + uint vis:1; + uint val:1; + uint sel:1; + uint ena:1; + uint act:1; +}; + + +class QCanvasData; + +class QM_EXPORT_CANVAS QCanvas : public QObject +{ + Q_OBJECT +public: + QCanvas( QObject* parent = 0, const char* name = 0 ); + QCanvas(int w, int h); + QCanvas( QPixmap p, int h, int v, int tilewidth, int tileheight ); + + virtual ~QCanvas(); + + virtual void setTiles( QPixmap tiles, int h, int v, + int tilewidth, int tileheight ); + virtual void setBackgroundPixmap( const QPixmap& p ); + QPixmap backgroundPixmap() const; + + virtual void setBackgroundColor( const QColor& c ); + QColor backgroundColor() const; + + virtual void setTile( int x, int y, int tilenum ); + int tile( int x, int y ) const + { return grid[x+y*htiles]; } + + int tilesHorizontally() const + { return htiles; } + int tilesVertically() const + { return vtiles; } + + int tileWidth() const + { return tilew; } + int tileHeight() const + { return tileh; } + + virtual void resize(int width, int height); + int width() const + { return awidth; } + int height() const + { return aheight; } + QSize size() const + { return QSize(awidth,aheight); } + QRect rect() const + { return QRect( 0, 0, awidth, aheight ); } + bool onCanvas( int x, int y ) const + { return x>=0 && y>=0 && x<awidth && y<aheight; } + bool onCanvas( const QPoint& p ) const + { return onCanvas(p.x(),p.y()); } + bool validChunk( int x, int y ) const + { return x>=0 && y>=0 && x<chwidth && y<chheight; } + bool validChunk( const QPoint& p ) const + { return validChunk(p.x(),p.y()); } + + int chunkSize() const + { return chunksize; } + virtual void retune(int chunksize, int maxclusters=100); + + bool sameChunk(int x1, int y1, int x2, int y2) const + { return x1/chunksize==x2/chunksize && y1/chunksize==y2/chunksize; } + virtual void setChangedChunk(int i, int j); + virtual void setChangedChunkContaining(int x, int y); + virtual void setAllChanged(); + virtual void setChanged(const QRect& area); + virtual void setUnchanged(const QRect& area); + + // These call setChangedChunk. + void addItemToChunk(QCanvasItem*, int i, int j); + void removeItemFromChunk(QCanvasItem*, int i, int j); + void addItemToChunkContaining(QCanvasItem*, int x, int y); + void removeItemFromChunkContaining(QCanvasItem*, int x, int y); + + QCanvasItemList allItems(); + QCanvasItemList collisions( const QPoint&) const; + QCanvasItemList collisions( const QRect&) const; + QCanvasItemList collisions( const QPointArray& pa, const QCanvasItem* item, + bool exact) const; + + void drawArea(const QRect&, QPainter* p, bool double_buffer=FALSE); + + // These are for QCanvasView to call + virtual void addView(QCanvasView*); + virtual void removeView(QCanvasView*); + void drawCanvasArea(const QRect&, QPainter* p=0, bool double_buffer=TRUE); + void drawViewArea( QCanvasView* view, QPainter* p, const QRect& r, bool dbuf ); + + // These are for QCanvasItem to call + virtual void addItem(QCanvasItem*); + virtual void addAnimation(QCanvasItem*); + virtual void removeItem(QCanvasItem*); + virtual void removeAnimation(QCanvasItem*); + + virtual void setAdvancePeriod(int ms); + virtual void setUpdatePeriod(int ms); + + virtual void setDoubleBuffering(bool y); + +signals: + void resized(); + +public slots: + virtual void advance(); + virtual void update(); + +protected: + virtual void drawBackground(QPainter&, const QRect& area); + virtual void drawForeground(QPainter&, const QRect& area); + +private: + void init(int w, int h, int chunksze=16, int maxclust=100); + + QCanvasChunk& chunk(int i, int j) const; + QCanvasChunk& chunkContaining(int x, int y) const; + + QRect changeBounds(const QRect& inarea); + void drawChanges(const QRect& inarea); + + void ensureOffScrSize( int osw, int osh ); + QPixmap offscr; + int awidth,aheight; + int chunksize; + int maxclusters; + int chwidth,chheight; + QCanvasChunk* chunks; + + QCanvasData* d; + + void initTiles(QPixmap p, int h, int v, int tilewidth, int tileheight); + ushort *grid; + ushort htiles; + ushort vtiles; + ushort tilew; + ushort tileh; + bool oneone; + QPixmap pm; + QTimer* update_timer; + QColor bgcolor; + bool debug_redraw_areas; + bool dblbuf; + + friend void qt_unview(QCanvas* c); + +#if defined(Q_DISABLE_COPY) // Disabled copy constructor and operator= + QCanvas( const QCanvas & ); + QCanvas &operator=( const QCanvas & ); +#endif +}; + +class QCanvasViewData; + +class QM_EXPORT_CANVAS QCanvasView : public QScrollView +{ + Q_OBJECT +public: + + QCanvasView(QWidget* parent=0, const char* name=0, WFlags f=0); + QCanvasView(QCanvas* viewing, QWidget* parent=0, const char* name=0, WFlags f=0); + ~QCanvasView(); + + QCanvas* canvas() const + { return viewing; } + void setCanvas(QCanvas* v); + + const QWMatrix &worldMatrix() const; + const QWMatrix &inverseWorldMatrix() const; + bool setWorldMatrix( const QWMatrix & ); + +protected: + void drawContents( QPainter*, int cx, int cy, int cw, int ch ); + QSize sizeHint() const; + +private: + void drawContents( QPainter* ); + QCanvas* viewing; + QCanvasViewData* d; + friend void qt_unview(QCanvas* c); + +private slots: + void cMoving(int,int); + void updateContentsSize(); + +private: +#if defined(Q_DISABLE_COPY) // Disabled copy constructor and operator= + QCanvasView( const QCanvasView & ); + QCanvasView &operator=( const QCanvasView & ); +#endif +}; + + +class QM_EXPORT_CANVAS QCanvasPixmap : public QPixmap +{ +public: +#ifndef QT_NO_IMAGEIO + QCanvasPixmap(const QString& datafilename); +#endif + QCanvasPixmap(const QImage& image); + QCanvasPixmap(const QPixmap&, const QPoint& hotspot); + ~QCanvasPixmap(); + + int offsetX() const + { return hotx; } + int offsetY() const + { return hoty; } + void setOffset(int x, int y) { hotx = x; hoty = y; } + +private: +#if defined(Q_DISABLE_COPY) + QCanvasPixmap( const QCanvasPixmap & ); + QCanvasPixmap &operator=( const QCanvasPixmap & ); +#endif + void init(const QImage&); + void init(const QPixmap& pixmap, int hx, int hy); + + friend class QCanvasSprite; + friend class QCanvasPixmapArray; + friend bool qt_testCollision(const QCanvasSprite* s1, const QCanvasSprite* s2); + + int hotx,hoty; + + QImage* collision_mask; +}; + + +class QM_EXPORT_CANVAS QCanvasPixmapArray +{ +public: + QCanvasPixmapArray(); +#ifndef QT_NO_IMAGEIO + QCanvasPixmapArray(const QString& datafilenamepattern, int framecount=0); +#endif + // this form is deprecated + QCanvasPixmapArray(QPtrList<QPixmap>, QPtrList<QPoint> hotspots); + + QCanvasPixmapArray(QValueList<QPixmap>, QPointArray hotspots = QPointArray() ); + ~QCanvasPixmapArray(); + +#ifndef QT_NO_IMAGEIO + bool readPixmaps(const QString& datafilenamepattern, int framecount=0); + bool readCollisionMasks(const QString& filenamepattern); +#endif + + // deprecated + bool operator!(); // Failure check. + bool isValid() const; + + QCanvasPixmap* image(int i) const + { return img ? img[i] : 0; } + void setImage(int i, QCanvasPixmap* p); + uint count() const + { return (uint)framecount; } + +private: +#if defined(Q_DISABLE_COPY) + QCanvasPixmapArray( const QCanvasPixmapArray & ); + QCanvasPixmapArray &operator=( const QCanvasPixmapArray & ); +#endif +#ifndef QT_NO_IMAGEIO + bool readPixmaps(const QString& datafilenamepattern, int framecount, bool maskonly); +#endif + + void reset(); + int framecount; + QCanvasPixmap** img; +}; + + +class QM_EXPORT_CANVAS QCanvasSprite : public QCanvasItem +{ +public: + QCanvasSprite(QCanvasPixmapArray* array, QCanvas* canvas); + + void setSequence(QCanvasPixmapArray* seq); + + virtual ~QCanvasSprite(); + + void move(double x, double y); + virtual void move(double x, double y, int frame); + void setFrame(int); + enum FrameAnimationType { Cycle, Oscillate }; + virtual void setFrameAnimation(FrameAnimationType=Cycle, int step=1, int state=0); + int frame() const + { return frm; } + int frameCount() const + { return images->count(); } + + int rtti() const; + static int RTTI; + + bool collidesWith( const QCanvasItem* ) const; + + QRect boundingRect() const; + + // is there a reason for these to be protected? Lars +//protected: + + int width() const; + int height() const; + + int leftEdge() const; + int topEdge() const; + int rightEdge() const; + int bottomEdge() const; + + int leftEdge(int nx) const; + int topEdge(int ny) const; + int rightEdge(int nx) const; + int bottomEdge(int ny) const; + QCanvasPixmap* image() const + { return images->image(frm); } + virtual QCanvasPixmap* imageAdvanced() const; + QCanvasPixmap* image(int f) const + { return images->image(f); } + virtual void advance(int stage); + +public: + void draw(QPainter& painter); + +private: +#if defined(Q_DISABLE_COPY) + QCanvasSprite( const QCanvasSprite & ); + QCanvasSprite &operator=( const QCanvasSprite & ); +#endif + void addToChunks(); + void removeFromChunks(); + void changeChunks(); + + int frm; + ushort anim_val; + uint anim_state:2; + uint anim_type:14; + bool collidesWith( const QCanvasSprite*, + const QCanvasPolygonalItem*, + const QCanvasRectangle*, + const QCanvasEllipse*, + const QCanvasText* ) const; + + friend bool qt_testCollision( const QCanvasSprite* s1, + const QCanvasSprite* s2 ); + + QCanvasPixmapArray* images; +}; + +class QPolygonalProcessor; + +class QM_EXPORT_CANVAS QCanvasPolygonalItem : public QCanvasItem +{ +public: + QCanvasPolygonalItem(QCanvas* canvas); + virtual ~QCanvasPolygonalItem(); + + bool collidesWith( const QCanvasItem* ) const; + + virtual void setPen(QPen p); + virtual void setBrush(QBrush b); + + QPen pen() const + { return pn; } + QBrush brush() const + { return br; } + + virtual QPointArray areaPoints() const=0; + virtual QPointArray areaPointsAdvanced() const; + QRect boundingRect() const; + + int rtti() const; + static int RTTI; + +protected: + void draw(QPainter &); + virtual void drawShape(QPainter &) = 0; + + bool winding() const; + void setWinding(bool); + + void invalidate(); + bool isValid() const + { return (bool)val; } + +private: + void scanPolygon( const QPointArray& pa, int winding, + QPolygonalProcessor& process ) const; + QPointArray chunks() const; + + bool collidesWith( const QCanvasSprite*, + const QCanvasPolygonalItem*, + const QCanvasRectangle*, + const QCanvasEllipse*, + const QCanvasText* ) const; + + QBrush br; + QPen pn; + uint wind:1; +}; + + +class QM_EXPORT_CANVAS QCanvasRectangle : public QCanvasPolygonalItem +{ +public: + QCanvasRectangle(QCanvas* canvas); + QCanvasRectangle(const QRect&, QCanvas* canvas); + QCanvasRectangle(int x, int y, int width, int height, QCanvas* canvas); + + ~QCanvasRectangle(); + + int width() const; + int height() const; + void setSize(int w, int h); + QSize size() const + { return QSize(w,h); } + QPointArray areaPoints() const; + QRect rect() const + { return QRect(int(x()),int(y()),w,h); } + + bool collidesWith( const QCanvasItem* ) const; + + int rtti() const; + static int RTTI; + +protected: + void drawShape(QPainter &); + QPointArray chunks() const; + +private: + bool collidesWith( const QCanvasSprite*, + const QCanvasPolygonalItem*, + const QCanvasRectangle*, + const QCanvasEllipse*, + const QCanvasText* ) const; + + int w, h; +}; + + +class QM_EXPORT_CANVAS QCanvasPolygon : public QCanvasPolygonalItem +{ +public: + QCanvasPolygon(QCanvas* canvas); + ~QCanvasPolygon(); + void setPoints(QPointArray); + QPointArray points() const; + void moveBy(double dx, double dy); + + QPointArray areaPoints() const; + + int rtti() const; + static int RTTI; + +protected: + void drawShape(QPainter &); + QPointArray poly; +}; + + +class QM_EXPORT_CANVAS QCanvasSpline : public QCanvasPolygon +{ +public: + QCanvasSpline(QCanvas* canvas); + ~QCanvasSpline(); + + void setControlPoints(QPointArray, bool closed=TRUE); + QPointArray controlPoints() const; + bool closed() const; + + int rtti() const; + static int RTTI; + +private: + void recalcPoly(); + QPointArray bez; + bool cl; +}; + + +class QM_EXPORT_CANVAS QCanvasLine : public QCanvasPolygonalItem +{ +public: + QCanvasLine(QCanvas* canvas); + ~QCanvasLine(); + void setPoints(int x1, int y1, int x2, int y2); + + QPoint startPoint() const + { return QPoint(x1,y1); } + QPoint endPoint() const + { return QPoint(x2,y2); } + + int rtti() const; + static int RTTI; + + void setPen(QPen p); + +protected: + void drawShape(QPainter &); + QPointArray areaPoints() const; + +private: + int x1,y1,x2,y2; +}; + + +class QM_EXPORT_CANVAS QCanvasEllipse : public QCanvasPolygonalItem +{ + +public: + QCanvasEllipse( QCanvas* canvas ); + QCanvasEllipse( int width, int height, QCanvas* canvas ); + QCanvasEllipse( int width, int height, int startangle, int angle, + QCanvas* canvas ); + + ~QCanvasEllipse(); + + int width() const; + int height() const; + void setSize(int w, int h); + void setAngles(int start, int length); + int angleStart() const + { return a1; } + int angleLength() const + { return a2; } + QPointArray areaPoints() const; + + bool collidesWith( const QCanvasItem* ) const; + + int rtti() const; + static int RTTI; + +protected: + void drawShape(QPainter &); + +private: + bool collidesWith( const QCanvasSprite*, + const QCanvasPolygonalItem*, + const QCanvasRectangle*, + const QCanvasEllipse*, + const QCanvasText* ) const; + int w, h; + int a1, a2; +}; + + +class QCanvasTextExtra; + +class QM_EXPORT_CANVAS QCanvasText : public QCanvasItem +{ +public: + QCanvasText(QCanvas* canvas); + QCanvasText(const QString&, QCanvas* canvas); + QCanvasText(const QString&, QFont, QCanvas* canvas); + + virtual ~QCanvasText(); + + void setText( const QString& ); + void setFont( const QFont& ); + void setColor( const QColor& ); + QString text() const; + QFont font() const; + QColor color() const; + + void moveBy(double dx, double dy); + + int textFlags() const + { return flags; } + void setTextFlags(int); + + QRect boundingRect() const; + + bool collidesWith( const QCanvasItem* ) const; + + int rtti() const; + static int RTTI; + +protected: + virtual void draw(QPainter&); + +private: +#if defined(Q_DISABLE_COPY) + QCanvasText( const QCanvasText & ); + QCanvasText &operator=( const QCanvasText & ); +#endif + void addToChunks(); + void removeFromChunks(); + void changeChunks(); + + void setRect(); + QRect brect; + QString txt; + int flags; + QFont fnt; + QColor col; + QCanvasTextExtra* extra; + + bool collidesWith( const QCanvasSprite*, + const QCanvasPolygonalItem*, + const QCanvasRectangle*, + const QCanvasEllipse*, + const QCanvasText* ) const; +}; + +#define Q_DEFINED_QCANVAS +#include "qwinexport.h" +#endif // QT_NO_CANVAS + +#endif // QCANVAS_H diff --git a/kjsembed/tools/headers/qdir.h b/kjsembed/tools/headers/qdir.h new file mode 100644 index 00000000..b5e1f5d0 --- /dev/null +++ b/kjsembed/tools/headers/qdir.h @@ -0,0 +1,246 @@ +/**************************************************************************** +** +** +** Definition of QDir class +** +** Created : 950427 +** +** Copyright (C) 1992-2002 Trolltech AS. All rights reserved. +** +** This file is part of the tools module of the Qt GUI Toolkit. +** +** This file may be distributed under the terms of the Q Public License +** as defined by Trolltech AS of Norway and appearing in the file +** LICENSE.QPL included in the packaging of this file. +** +** This file may be distributed and/or modified under the terms of the +** GNU General Public License version 2 as published by the Free Software +** Foundation and appearing in the file LICENSE.GPL included in the +** packaging of this file. +** +** Licensees holding valid Qt Enterprise Edition or Qt Professional Edition +** licenses may use this file in accordance with the Qt Commercial License +** Agreement provided with the Software. +** +** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE +** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. +** +** See http://www.trolltech.com/pricing.html or email sales@trolltech.com for +** information about Qt Commercial License Agreements. +** See http://www.trolltech.com/qpl/ for QPL licensing information. +** See http://www.trolltech.com/gpl/ for GPL licensing information. +** +** Contact info@trolltech.com if any conditions of this licensing are +** not clear to you. +** +**********************************************************************/ + +#ifndef QDIR_H +#define QDIR_H + +#ifndef QT_H +#include "qglobal.h" +#include "qstrlist.h" +#include "qfileinfo.h" +#endif // QT_H + + +#ifndef QT_NO_DIR +typedef QPtrList<QFileInfo> QFileInfoList; +typedef QPtrListIterator<QFileInfo> QFileInfoListIterator; +class QStringList; +template <class T> class QDeepCopy; + + +class Q_EXPORT QDir +{ +public: + enum FilterSpec { Dirs = 0x001, + Files = 0x002, + Drives = 0x004, + NoSymLinks = 0x008, + All = 0x007, + TypeMask = 0x00F, + + Readable = 0x010, + Writable = 0x020, + Executable = 0x040, + RWEMask = 0x070, + + Modified = 0x080, + Hidden = 0x100, + System = 0x200, + AccessMask = 0x3F0, + + DefaultFilter = -1 }; + + enum SortSpec { Name = 0x00, + Time = 0x01, + Size = 0x02, + Unsorted = 0x03, + SortByMask = 0x03, + + DirsFirst = 0x04, + Reversed = 0x08, + IgnoreCase = 0x10, + DefaultSort = -1 }; + + QDir(); + QDir( const QString &path, const QString &nameFilter = QString::null, + int sortSpec = Name | IgnoreCase, int filterSpec = All ); + QDir( const QDir & ); + + virtual ~QDir(); + + QDir &operator=( const QDir & ); + QDir &operator=( const QString &path ); + + virtual void setPath( const QString &path ); + virtual QString path() const; + virtual QString absPath() const; + virtual QString canonicalPath() const; + + virtual QString dirName() const; + virtual QString filePath( const QString &fileName, + bool acceptAbsPath = TRUE ) const; + virtual QString absFilePath( const QString &fileName, + bool acceptAbsPath = TRUE ) const; + + static QString convertSeparators( const QString &pathName ); + + virtual bool cd( const QString &dirName, bool acceptAbsPath = TRUE ); + virtual bool cdUp(); + + QString nameFilter() const; + virtual void setNameFilter( const QString &nameFilter ); + FilterSpec filter() const; + virtual void setFilter( int filterSpec ); + SortSpec sorting() const; + virtual void setSorting( int sortSpec ); + + bool matchAllDirs() const; + virtual void setMatchAllDirs( bool ); + + uint count() const; + QString operator[]( int ) const; + + virtual QStrList encodedEntryList( int filterSpec = DefaultFilter, + int sortSpec = DefaultSort ) const; + virtual QStrList encodedEntryList( const QString &nameFilter, + int filterSpec = DefaultFilter, + int sortSpec = DefaultSort ) const; + virtual QStringList entryList( int filterSpec = DefaultFilter, + int sortSpec = DefaultSort ) const; + virtual QStringList entryList( const QString &nameFilter, + int filterSpec = DefaultFilter, + int sortSpec = DefaultSort ) const; + + virtual const QFileInfoList *entryInfoList( int filterSpec = DefaultFilter, + int sortSpec = DefaultSort ) const; + virtual const QFileInfoList *entryInfoList( const QString &nameFilter, + int filterSpec = DefaultFilter, + int sortSpec = DefaultSort ) const; + + static const QFileInfoList *drives(); + + virtual bool mkdir( const QString &dirName, + bool acceptAbsPath = TRUE ) const; + virtual bool rmdir( const QString &dirName, + bool acceptAbsPath = TRUE ) const; + + virtual bool isReadable() const; + virtual bool exists() const; + virtual bool isRoot() const; + + virtual bool isRelative() const; + virtual void convertToAbs(); + + virtual bool operator==( const QDir & ) const; + virtual bool operator!=( const QDir & ) const; + + virtual bool remove( const QString &fileName, + bool acceptAbsPath = TRUE ); + virtual bool rename( const QString &name, const QString &newName, + bool acceptAbsPaths = TRUE ); + virtual bool exists( const QString &name, + bool acceptAbsPath = TRUE ); + + static char separator(); + + static bool setCurrent( const QString &path ); + static QDir current(); + static QDir home(); + static QDir root(); + static QString currentDirPath(); + static QString homeDirPath(); + static QString rootDirPath(); + + static bool match( const QStringList &filters, const QString &fileName ); + static bool match( const QString &filter, const QString &fileName ); + static QString cleanDirPath( const QString &dirPath ); + static bool isRelativePath( const QString &path ); + void refresh() const; + +private: +#ifdef Q_OS_MAC + typedef struct FSSpec FSSpec; + static FSSpec *make_spec(const QString &); +#endif + void init(); + virtual bool readDirEntries( const QString &nameFilter, + int FilterSpec, int SortSpec ); + + static void slashify( QString & ); + + QString dPath; + QStringList *fList; + QFileInfoList *fiList; + QString nameFilt; + FilterSpec filtS; + SortSpec sortS; + uint dirty : 1; + uint allDirs : 1; + + void detach(); + friend class QDeepCopy< QDir >; +}; + + +inline QString QDir::path() const +{ + return dPath; +} + +inline QString QDir::nameFilter() const +{ + return nameFilt; +} + +inline QDir::FilterSpec QDir::filter() const +{ + return filtS; +} + +inline QDir::SortSpec QDir::sorting() const +{ + return sortS; +} + +inline bool QDir::matchAllDirs() const +{ + return allDirs; +} + +inline bool QDir::operator!=( const QDir &d ) const +{ + return !(*this == d); +} + + +struct QDirSortItem { + QString filename_cache; + QFileInfo* item; +}; + +#endif // QT_NO_DIR +#endif // QDIR_H diff --git a/kjsembed/tools/headers/qpen.h b/kjsembed/tools/headers/qpen.h new file mode 100644 index 00000000..38befc90 --- /dev/null +++ b/kjsembed/tools/headers/qpen.h @@ -0,0 +1,99 @@ +/**************************************************************************** +** +** +** Definition of QPen class +** +** Created : 940112 +** +** Copyright (C) 1992-2000 Trolltech AS. All rights reserved. +** +** This file is part of the kernel module of the Qt GUI Toolkit. +** +** This file may be distributed under the terms of the Q Public License +** as defined by Trolltech AS of Norway and appearing in the file +** LICENSE.QPL included in the packaging of this file. +** +** This file may be distributed and/or modified under the terms of the +** GNU General Public License version 2 as published by the Free Software +** Foundation and appearing in the file LICENSE.GPL included in the +** packaging of this file. +** +** Licensees holding valid Qt Enterprise Edition or Qt Professional Edition +** licenses may use this file in accordance with the Qt Commercial License +** Agreement provided with the Software. +** +** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE +** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. +** +** See http://www.trolltech.com/pricing.html or email sales@trolltech.com for +** information about Qt Commercial License Agreements. +** See http://www.trolltech.com/qpl/ for QPL licensing information. +** See http://www.trolltech.com/gpl/ for GPL licensing information. +** +** Contact info@trolltech.com if any conditions of this licensing are +** not clear to you. +** +**********************************************************************/ + +#ifndef QPEN_H +#define QPEN_H + +#ifndef QT_H +#include "qcolor.h" +#include "qshared.h" +#endif // QT_H + + +class Q_EXPORT QPen: public Qt +{ +public: + QPen(); + QPen( PenStyle ); + QPen( const QColor &color, uint width=0, PenStyle style=SolidLine ); + QPen( const QColor &cl, uint w, PenStyle s, PenCapStyle c, PenJoinStyle j); + QPen( const QPen & ); + ~QPen(); + QPen &operator=( const QPen & ); + + PenStyle style() const { return data->style; } + void setStyle( PenStyle ); + uint width() const { return data->width; } + void setWidth( uint ); + const QColor &color() const { return data->color; } + void setColor( const QColor & ); + PenCapStyle capStyle() const; + void setCapStyle( PenCapStyle ); + PenJoinStyle joinStyle() const; + void setJoinStyle( PenJoinStyle ); + + bool operator==( const QPen &p ) const; + bool operator!=( const QPen &p ) const + { return !(operator==(p)); } + +private: + friend class QPainter; +#ifdef Q_WS_WIN + friend class QFontEngineWin; +#endif + + QPen copy() const; + void detach(); + void init( const QColor &, uint, uint ); + struct QPenData : public QShared { // pen data + PenStyle style; + uint width; + QColor color; + Q_UINT16 linest; + } *data; +}; + + +/***************************************************************************** + QPen stream functions + *****************************************************************************/ +#ifndef QT_NO_DATASTREAM +Q_EXPORT QDataStream &operator<<( QDataStream &, const QPen & ); +Q_EXPORT QDataStream &operator>>( QDataStream &, QPen & ); +#endif + +#endif // QPEN_H diff --git a/kjsembed/tools/headers/qtimer.h b/kjsembed/tools/headers/qtimer.h new file mode 100644 index 00000000..b662470d --- /dev/null +++ b/kjsembed/tools/headers/qtimer.h @@ -0,0 +1,88 @@ +/**************************************************************************** +** +** +** Definition of QTimer class +** +** Created : 931111 +** +** Copyright (C) 1992-2000 Trolltech AS. All rights reserved. +** +** This file is part of the kernel module of the Qt GUI Toolkit. +** +** This file may be distributed under the terms of the Q Public License +** as defined by Trolltech AS of Norway and appearing in the file +** LICENSE.QPL included in the packaging of this file. +** +** This file may be distributed and/or modified under the terms of the +** GNU General Public License version 2 as published by the Free Software +** Foundation and appearing in the file LICENSE.GPL included in the +** packaging of this file. +** +** Licensees holding valid Qt Enterprise Edition or Qt Professional Edition +** licenses may use this file in accordance with the Qt Commercial License +** Agreement provided with the Software. +** +** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE +** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. +** +** See http://www.trolltech.com/pricing.html or email sales@trolltech.com for +** information about Qt Commercial License Agreements. +** See http://www.trolltech.com/qpl/ for QPL licensing information. +** See http://www.trolltech.com/gpl/ for GPL licensing information. +** +** Contact info@trolltech.com if any conditions of this licensing are +** not clear to you. +** +**********************************************************************/ + +#ifndef QTIMER_H +#define QTIMER_H + +#ifndef QT_H +#include "qobject.h" +#endif // QT_H + + +class Q_EXPORT QTimer : public QObject +{ + Q_OBJECT +public: + QTimer( QObject *parent=0, const char *name=0 ); + ~QTimer(); + + bool isActive() const; + + int start( int msec, bool sshot = FALSE ); + void changeInterval( int msec ); + void stop(); + + static void singleShot( int msec, QObject *receiver, const char *member ); + + int timerId() const { return id; } + +signals: + void timeout(); + +protected: + bool event( QEvent * ); + +private: + int id; + uint single : 1; + uint nulltimer : 1; + +private: // Disabled copy constructor and operator= +#if defined(Q_DISABLE_COPY) + QTimer( const QTimer & ); + QTimer &operator=( const QTimer & ); +#endif +}; + + +inline bool QTimer::isActive() const +{ + return id >= 0; +} + + +#endif // QTIMER_H diff --git a/kjsembed/tools/xml/DO_NOT_PRUNE b/kjsembed/tools/xml/DO_NOT_PRUNE new file mode 100644 index 00000000..e69de29b --- /dev/null +++ b/kjsembed/tools/xml/DO_NOT_PRUNE diff --git a/kjsembed/xmlactionclient.cpp b/kjsembed/xmlactionclient.cpp new file mode 100644 index 00000000..eb470f3d --- /dev/null +++ b/kjsembed/xmlactionclient.cpp @@ -0,0 +1,339 @@ +/* + * Copyright (C) 2002-2003, Richard J. Moore <rich@kde.org> + * + * This 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. + * + * This 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 this library; see the file COPYING.LIB. If not, write to + * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, + * Boston, MA 02110-1301, USA. + */ + +#include <qfile.h> +#include <kaction.h> +#include <kdebug.h> +#include <kstdaction.h> + +#include "xmlactionclient.h" +#include "xmlactionclient.moc" + +namespace KJSEmbed { + +// +// XML Tags and Attributes +// + +QString tag_header("header"); +QString tag_action("action"); +QString tag_type( "type" ); +QString tag_label( "label" ); +QString tag_icons( "icons" ); +QString tag_shortcut( "shortcut" ); +QString tag_name( "name" ); +QString tag_group( "group" ); +QString tag_text( "text" ); +QString tag_statustext( "statustext" ); +QString tag_whatsthis( "whatsthis" ); +QString tag_script( "script" ); +QString tag_data( "data" ); +QString tag_item( "item" ); + +QString attr_type( "type" ); +QString attr_src( "src" ); +QString attr_exclusive( "exclusive" ); + +QString type_include( "include" ); +QString type_debug( "debug" ); + +// +// Default Runner +// + +bool XMLActionRunner::run( XMLActionClient *client, const XMLActionClient::XMLActionScript &s ) +{ +// kdWarning() << "Runner:run called, type=" << s.type << " text=" << s.text << " src=" << s.src << endl; + + if ( s.type == type_include ) { + kdDebug(80001) << "IncludeAction: " << s.src << endl; + return client->load( s.src ); + } + else if ( s.type == type_debug ) { + kdDebug(80001) << "DebugAction: " << s.text << endl; + return true; + } + + return false; +} + +// +// Main Client Class +// + +XMLActionClient::XMLActionClient( QObject *parent, const char *name ) + : QObject( parent, name ? name : "XMLActionClient" ), + ac(0), actrun(0) +{ +} + +XMLActionClient::~XMLActionClient() +{ +} + +bool XMLActionClient::load( const QString &filename ) +{ + XMLActionHandler h( this ); + return load( &h, filename ); +} + +bool XMLActionClient::load( XMLActionHandler *hand, const QString &filename ) +{ + QFile f( filename ); + QXmlInputSource src( &f ); + + QXmlSimpleReader reader; + reader.setContentHandler( hand ); + bool ok = reader.parse( src ); + if ( !ok ) { + kdWarning() << "Loading actionset " << filename << " failed, " << hand->errorString() << endl; + } + + return ok; +} + +bool XMLActionClient::bind( const QString &name, const XMLActionScript &s ) +{ +// kdWarning() << "Runner:bind called, name=" << name << " type=" << s.type +// << " text=" << s.text << " src=" << s.src << endl; + + scripts[name] = s; + return true; +} + +bool XMLActionClient::bind( KAction *act, const XMLActionScript &s ) +{ + if ( !act ) + return false; + +// kdWarning() << "Runner:bind called, action=" << act->name() << " type=" << s.type +// << " text=" << s.text << " src=" << s.src << endl; + + connect( act, SIGNAL( activated() ), this, SLOT( action_activated() ) ); + return bind( act->name(), s ); +} + +bool XMLActionClient::run( const QString &name ) +{ + if ( scripts.contains( name ) ) + return run( scripts[name] ); + else + return false; +} + +bool XMLActionClient::run( const XMLActionScript &s ) +{ +// kdWarning() << "Client:run called, type=" << s.type << " text=" << s.text << " src=" << s.src << endl; + + if ( actrun ) + return actrun->run( this, s ); + else + return false; +} + +void XMLActionClient::action_activated() +{ + const QObject *sender = QObject::sender(); + if ( !sender ) + return; + + run( sender->name() ); +} + +// +// SAX Document Handler +// + +XMLActionHandler::XMLActionHandler( XMLActionClient *client ) + : QXmlDefaultHandler(), actclient( client ) +{ +} + +bool XMLActionHandler::characters( const QString &chars ) +{ + cdata = cdata + chars; + return true; +} + + +bool XMLActionHandler::startElement( const QString &, const QString &, const QString &qn, + const QXmlAttributes &attrs ) +{ + cdata = QString::null; + + if ( qn == tag_script ) { + ad.script.type = attrs.value( attr_type ); + ad.script.src = attrs.value( attr_src ); + } + else if ( qn == tag_group ) { + QString ex = attrs.value( attr_exclusive ); + if ( ex == QString("true") ) + ad.exclusive = true; + } + else if ( qn == tag_action ) + inAction = true; + + return true; +} + +bool XMLActionHandler::endElement( const QString &, const QString &, const QString &qn ) +{ + if ( qn == tag_action ) { + defineAction(); + inAction = false; + } + else if ( qn == tag_type ) { + ad.type = cdata; + cdata = QString::null; + } + else if ( qn == tag_label ) { + ad.text = cdata; + cdata = QString::null; + } + else if ( qn == tag_text ) { + // Nothing + } + else if ( qn == tag_icons ) { + ad.icons = cdata; + cdata = QString::null; + } + else if ( qn == tag_shortcut ) { + ad.keys = cdata; + cdata = QString::null; + } + else if ( qn == tag_name ) { + ad.name = cdata.latin1(); + cdata = QString::null; + } + else if ( qn == tag_group ) { + ad.group = cdata.latin1(); + cdata = QString::null; + } + else if ( qn == tag_whatsthis ) { + ad.whatsthis = cdata; + cdata = QString::null; + } + else if ( qn == tag_statustext ) { + ad.status = cdata; + cdata = QString::null; + } + else if ( qn == tag_script ) { + ad.script.text = cdata; + cdata = QString::null; + + if ( !inAction && ad.script.isValid() ) + actclient->run( ad.script ); + } + else if ( qn == tag_item ) { + ad.items += cdata; + cdata = QString::null; + } + + return true; +} + +void XMLActionHandler::defineAction() +{ + if ( ad.name.isEmpty() ) { + kdWarning() << "Attempt to create a KAction without setting a name" << endl; + return; + } + + if ( ad.text.isEmpty() ) + ad.text = ad.name; + + KAction *act = createAction( actclient->actionCollection() ); + if ( act && ad.script.isValid() ) + actclient->bind( act, ad.script ); + + ad.clear(); + cdata = QString::null; +} + +KAction *XMLActionHandler::createAction( KActionCollection *parent ) +{ +// kdDebug(80001) << "Creating Action, type is " << type << endl; +// kdDebug(80001) << "text=" << text << ", icons=" << icons << endl; +// kdDebug(80001) << "keys=" << keys << ", name=" << name << endl; + + if ( !parent ) { + kdWarning() << "Create action called but no parent set" << endl; + return 0; + } + + KAction *act=0; + + if ( ad.type.isEmpty() || (ad.type == "KAction") ) { + act = new KAction( ad.text, ad.icons, ad.keys, 0, 0, parent, ad.name.latin1() ); + } + else if ( ad.type == "KToggleAction" ) { + act = new KToggleAction( ad.text, ad.icons, ad.keys, 0, 0, parent, ad.name.latin1() ); + } + else if ( ad.type == "KRadioAction" ) { + KRadioAction *ra = new KRadioAction( ad.text, ad.icons, ad.keys, 0, 0, parent, ad.name.latin1() ); + if ( ad.exclusive ) + ra->setExclusiveGroup( ad.group ); + + act = ra; + } + else if ( ad.type == "KStdAction" ) { + for ( int i = KStdAction::ActionNone ; i < KStdAction::ConfigureNotifications ; i++ ) { + if ( KStdAction::stdName(static_cast<KStdAction::StdAction>(i)) == ad.name ) + act = KStdAction::create( (KStdAction::StdAction)i, 0, 0, parent ); + } + } + else if ( ad.type == "KListAction" ) { + KListAction *la = new KListAction( ad.text, ad.icons, ad.keys, 0, 0, parent, ad.name.latin1() ); + la->setItems( ad.items ); + ad.items.clear(); + act = la; + } + else if ( ad.type == "KActionMenu" ) { + KActionMenu *am = new KActionMenu( ad.text, ad.icons, parent, ad.name.latin1() ); + + for ( QStringList::Iterator it = ad.items.begin() ; it != ad.items.end() ; ++it ) { + KAction *a = parent->action( (*it).latin1() ); + if ( a ) + am->insert( a ); + } + ad.items.clear(); + act = am; + } + else { + kdWarning() << "Unknown ActionType " << ad.type << endl; + return 0; + } + + if ( !act ) { + kdWarning() << "Unable to create action" << endl; + return act; + } + + if ( !ad.group.isEmpty() ) + act->setGroup( ad.group ); + + act->setStatusText( ad.status ); + act->setWhatsThis( ad.whatsthis ); + + QObject::connect( actclient, SIGNAL( destroyed() ), act, SLOT( deleteLater() ) ); + + return act; +} + +} // namespace KJSEmbed diff --git a/kjsembed/xmlactionclient.h b/kjsembed/xmlactionclient.h new file mode 100644 index 00000000..1af501ab --- /dev/null +++ b/kjsembed/xmlactionclient.h @@ -0,0 +1,232 @@ +// -*- c++ -*- + +/* + * Copyright (C) 2002-2003, Richard J. Moore <rich@kde.org> + * + * This 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. + * + * This 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 this library; see the file COPYING.LIB. If not, write to + * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, + * Boston, MA 02110-1301, USA. + */ + +#ifndef XMLACTIONCLIENT_H +#define XMLACTIONCLIENT_H + +#include <qobject.h> +#include <qxml.h> +#include <qmap.h> + +class KActionCollection; +class KAction; + +namespace KJSEmbed { + +class XMLActionHandler; +class XMLActionRunner; +class XMLActionScript; + +/** + * Loads actions from an XML file using SAX. + * + * @author Richard Moore, rich@kde.org + */ +class XMLActionClient : public QObject +{ + Q_OBJECT + +public: + /** + * Represents a script. + */ + struct XMLActionScript + { + XMLActionScript() {} + XMLActionScript( const XMLActionScript &self ) + : src(self.src), type(self.type), text(self.text) {} + ~XMLActionScript() {} + + /** Returns true iff this instance holds a valid script. */ + bool isValid() const { return !type.isEmpty(); } + + /** + * Clears this script object. After this method has been called, + * isValid() will return false. + */ + void clear() { src = type = text = QString::null; } + + QString src; + QString type; + QString text; + }; + + /** Creates an XMLActionClient. */ + XMLActionClient( QObject *parent=0, const char *name=0 ); + + /** + * Cleans up. When the object is deleted, any actions it has created will + * also be deleted. + */ + virtual ~XMLActionClient(); + + /** Returns the KActionCollection that the actions will be added to. */ + KActionCollection *actionCollection() const { return ac; } + + /** Sets the KActionCollection that the actions will be added to. */ + void setActionCollection( KActionCollection *acts ) { ac = acts; } + + /** Returns the runner for this XMLActionClient. */ + XMLActionRunner *runner() const { return actrun; } + + /** Sets the runner for this XMLActionClient. */ + void setRunner( XMLActionRunner *r ) { actrun = r; } + + /** Loads actions from the named XML file. Returns true on success. */ + bool load( const QString &filename ); + + /** Loads actions from the named XML file. Returns true on success. */ + bool load( XMLActionHandler *handler, const QString &filename ); + + /** Runs the named script. */ + bool run( const QString &name ); + + /** Returns the named script. */ + XMLActionScript script( const QString &name ) const { return scripts[name]; } + + /** Calls XMLActionRunner::run(). */ + bool run( const XMLActionScript &script ); + + /** Binds a name to a script. */ + virtual bool bind( const QString &name, const XMLActionScript &script ); + + /** Binds an action to a script. */ + virtual bool bind( KAction *act, const XMLActionScript &script ); + +protected slots: + /** + * Called when a bound action is activated to invoke the script with the + * sender's name. + */ + void action_activated(); + +private: + KActionCollection *ac; + XMLActionRunner *actrun; + QMap<QString, XMLActionScript> scripts; + class XMLActionClientPrivate *d; +}; + +/** + * Abstract class implemented by classes that can run scripts. + * + * @see XMLActionClient + * @author Richard Moore, rich@kde.org + */ +class XMLActionRunner +{ +public: + /** + * This method should be reimplemented to execute the specified script. + * + * @return true if the script was executed successfully, false otherwise. + */ + virtual bool run( XMLActionClient *client, const XMLActionClient::XMLActionScript &script ); +}; + +/** + * SAX handler for loading actions from XML. + * + * The following tags are supported: + * <pre> + * actionset ( header? action* ) + * header ( name | label | icons | script ) + * action ( (header | name | label | icons | shortcut | group | + * whatsthis | statustext | type | script | data)+ ) + * type ( #CDATA ) + * label ( #CDATA | text ) + * icons ( #CDATA ) + * shortcut ( #CDATA | text ) + * whatsthis ( #CDATA | text ) + * group ( #CDATA ) + * exclusive defaults to false + * name ( #CDATA ) + * text ( #CDATA ) + * data ( item+ ) + * item ( #CDATA | text ) + * script ( #CDATA ) + * type type of script + * src url of script file (optional) + * </pre> + * + * Unknown tags are ignored, so subclasses can define new ones if they + * want to store additional data. + * + * @author Richard Moore, rich@kde.org + */ +class XMLActionHandler : public QXmlDefaultHandler +{ +public: + XMLActionHandler( XMLActionClient *actclient ); + + virtual bool startElement( const QString &ns, const QString &ln, const QString &qn, + const QXmlAttributes &attrs ); + virtual bool endElement( const QString &ns, const QString &ln, const QString &qn ); + virtual bool characters( const QString &chars ); + + /** Called when an action tag is closed. */ + void defineAction(); + + XMLActionClient *client() const { return actclient; } + + /** Creates a KAction based on the values read from the XML. */ + virtual KAction *createAction( KActionCollection *parent ); + +private: + /** + * Structure containing information gathered about an action. + */ + struct XMLActionData { + XMLActionData() { clear(); } + + void clear() { + text = icons = keys = name = group = whatsthis = status = QString::null; + exclusive = false; + script.clear(); + } + + QString type; + QString text; + QString icons; + QString keys; + QString name; + QString group; + bool exclusive; + QString status; + QString whatsthis; + XMLActionClient::XMLActionScript script; + QStringList items; + }; + + XMLActionData *actionData() { return &ad; } + +private: + XMLActionClient *actclient; + QString cdata; + bool inAction; + XMLActionData ad; + class XMLActionHandlerPrivate *d; +}; + +} // namespace KJSEmbed + +#endif // XMLACTIONCLIENT_H + |