Reverting to rev 4901
parent
3abdee7916
commit
518c2655a3
|
@ -19,7 +19,6 @@ missing
|
|||
po-gsv/Makefile.in.in
|
||||
po/Makefile.in.in
|
||||
build/
|
||||
build-15/
|
||||
autom4te.cache/
|
||||
aclocal.m4
|
||||
*~
|
||||
|
|
430
CMakeLists.txt
430
CMakeLists.txt
|
@ -1,231 +1,199 @@
|
|||
cmake_minimum_required(VERSION 3.0)
|
||||
cmake_policy(SET CMP0048 NEW)
|
||||
|
||||
include(cmake/PrecompiledHeader.cmake)
|
||||
|
||||
list(APPEND EXTRA_DIST
|
||||
tools/genenums.py
|
||||
tools/glade2c.py
|
||||
tools/xml2h.py
|
||||
plat/win32/installer.iss.in
|
||||
plat/win32/istrans.sh
|
||||
plat/win32/mingw-configure
|
||||
)
|
||||
|
||||
# zzz
|
||||
# if MOO_OS_WIN32
|
||||
# plat/win32/installer.iss: $(top_srcdir)/plat/win32/installer.iss.in $(top_builddir)/config.status
|
||||
# $(AM_V_at)$(MKDIR_P) plat/win32
|
||||
# $(AM_V_GEN)cd $(top_builddir) && ./config.status --silent --file=plat/win32/installer.iss
|
||||
# installer: plat/win32/installer.iss install
|
||||
# $(MEDIT_INNO_COMPILER) plat/win32/installer.iss
|
||||
# copy:
|
||||
# cp moo/medit.exe "/win/Program Files (x86)/medit/bin/"
|
||||
# bd_tmpdir = medit-win-dist-tmp
|
||||
# bd_distdir = $(PACKAGE)-$(VERSION)
|
||||
# bd_pzip = $(PACKAGE)-portable-$(VERSION)
|
||||
# bd_zip = $(PACKAGE)-$(VERSION)
|
||||
# portable: install
|
||||
# rm -fr $(bd_tmpdir)
|
||||
# mkdir $(bd_tmpdir)
|
||||
# cp -lR ${prefix} $(bd_tmpdir)/$(bd_distdir)
|
||||
# cd $(bd_tmpdir) && zip -r9 $(bd_zip).zip $(bd_distdir)
|
||||
# echo "This file enables portable mode for medit" > $(bd_tmpdir)/$(bd_distdir)/bin/$(MEDIT_PORTABLE_MAGIC_FILE_NAME)
|
||||
# cd $(bd_tmpdir) && zip -r9 $(bd_pzip).zip $(bd_distdir)
|
||||
# mv $(bd_tmpdir)/$(bd_pzip).zip $(bd_tmpdir)/$(bd_zip).zip .
|
||||
# rm -fr $(bd_tmpdir)
|
||||
# bdist: installer portable
|
||||
# endif
|
||||
|
||||
# zzz @MOO_PO_SUBDIRS_RULE@
|
||||
|
||||
set(MOO_MAJOR_VERSION 1)
|
||||
set(MOO_MINOR_VERSION 2)
|
||||
set(MOO_MICRO_VERSION 90)
|
||||
set(_moo_version_suffix_ "-devel")
|
||||
set(MOO_MODULE_MAJOR_VERSION 2)
|
||||
set(MOO_MODULE_MINOR_VERSION 0)
|
||||
set(MOO_VERSION "${MOO_MAJOR_VERSION}.${MOO_MINOR_VERSION}.${MOO_MICRO_VERSION}")
|
||||
set(MOO_DISPLAY_VERSION "${MOO_VERSION}${_moo_version_suffix_}")
|
||||
|
||||
project(medit VERSION ${MOO_VERSION})
|
||||
|
||||
# keep in sync with po/maintain
|
||||
set(MOO_PACKAGE_NAME "medit-1")
|
||||
|
||||
set(MOO_WEBSITE "http://mooedit.sourceforge.net/")
|
||||
set(MOO_WEB_CONTACT "http://mooedit.sourceforge.net/contact.html")
|
||||
set(MOO_EMAIL "emuntyan@users.sourceforge.net")
|
||||
set(MOO_COPYRIGHT "2004-2015 Yevgen Muntyan <${MOO_EMAIL}>")
|
||||
|
||||
set(MOO_PREFS_XML_FILE_NAME "prefs.xml")
|
||||
set(MOO_STATE_XML_FILE_NAME "state.xml")
|
||||
set(MOO_NAMED_SESSION_XML_FILE_NAME "session-%s.xml")
|
||||
set(MOO_SESSION_XML_FILE_NAME "session.xml")
|
||||
set(MEDIT_PORTABLE_MAGIC_FILE_NAME "medit-portable")
|
||||
set(MEDIT_PORTABLE_DATA_DIR "medit-portable-data")
|
||||
set(MEDIT_PORTABLE_CACHE_DIR "medit-portable-cache")
|
||||
|
||||
set(MOO_DATA_DIR "${CMAKE_INSTALL_PREFIX}/share/${MOO_PACKAGE_NAME}")
|
||||
set(MOO_LIB_DIR "${CMAKE_INSTALL_PREFIX}/lib/${MOO_PACKAGE_NAME}")
|
||||
set(MOO_DOC_DIR "${CMAKE_INSTALL_PREFIX}/share/doc/${MOO_PACKAGE_NAME}")
|
||||
set(MOO_HELP_DIR "${MOO_DOC_DIR}/help")
|
||||
set(MOO_TEXT_LANG_FILES_DIR "${MOO_DATA_DIR}/language-specs")
|
||||
set(MOO_PYTHON_PLUGIN_DIR "${MOO_DATA_DIR}/plugins")
|
||||
set(MOO_PYTHON_LIB_DIR "${MOO_DATA_DIR}/python")
|
||||
|
||||
if(CMAKE_COMPILER_IS_GNUCXX)
|
||||
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++14")
|
||||
endif()
|
||||
|
||||
if(WIN32 AND CMAKE_CONFIGURATION_TYPES)
|
||||
set(CMAKE_CONFIGURATION_TYPES Release Debug)
|
||||
set(CMAKE_CONFIGURATION_TYPES "${CMAKE_CONFIGURATION_TYPES}" CACHE STRING
|
||||
"Reset the configurations to what we need" FORCE)
|
||||
endif()
|
||||
|
||||
set(CMAKE_INCLUDE_CURRENT_DIR ON)
|
||||
set(CMAKE_AUTOMOC ON)
|
||||
|
||||
if(WIN32)
|
||||
set(MOO_OS_WIN32 TRUE)
|
||||
else()
|
||||
set(MOO_OS_UNIX TRUE)
|
||||
endif()
|
||||
|
||||
set(MOO_BUILD_FROM_MSVC FALSE CACHE BOOL "Create a win32 build from MSVC gtk build")
|
||||
set(MOO_BUILD_FROM_MINGW ${MOO_OS_WIN32} CACHE BOOL "Create a win32 build from mingw gtk build")
|
||||
|
||||
if(NOT MOO_BUILD_FROM_MINGW AND NOT MOO_BUILD_FROM_MSVC)
|
||||
find_package(PkgConfig REQUIRED)
|
||||
pkg_check_modules(GTK REQUIRED gtk+-2.0)
|
||||
pkg_check_modules(GMODULE REQUIRED gmodule-2.0)
|
||||
#execute_process(
|
||||
# COMMAND ${PKG_CONFIG_EXECUTABLE} --variable=glib_genmarshal glib-2.0
|
||||
# OUTPUT_VARIABLE GLIB_GENMARSHAL
|
||||
# OUTPUT_STRIP_TRAILING_WHITESPACE
|
||||
# RESULT_VARIABLE RESULT)
|
||||
#if(NOT RESULT EQUAL 0)
|
||||
# MESSAGE(FATAL_ERROR "Could not find glib-genmarshal")
|
||||
#endif()
|
||||
execute_process(
|
||||
COMMAND ${PKG_CONFIG_EXECUTABLE} --variable=glib_mkenums glib-2.0
|
||||
OUTPUT_VARIABLE GLIB_MKENUMS
|
||||
OUTPUT_STRIP_TRAILING_WHITESPACE
|
||||
RESULT_VARIABLE RESULT)
|
||||
if(NOT RESULT EQUAL 0)
|
||||
MESSAGE(FATAL_ERROR "Could not find glib-mkenums")
|
||||
endif()
|
||||
|
||||
pkg_check_modules(XLIB x11 xext xrender ice sm)
|
||||
pkg_check_modules(LIBXML2 REQUIRED libxml-2.0)
|
||||
else()
|
||||
|
||||
if(MOO_BUILD_FROM_MINGW)
|
||||
set(MOO_GTK_DIR "C:/Projects/gtk/release/target" CACHE PATH "Gtk root dir")
|
||||
set(MOO_GTK_DIST_DIR "C:/Projects/gtk/release/bdist" CACHE PATH "Gtk binary dir")
|
||||
|
||||
set(GTK_LIBRARIES libgtk-win32-2.0-0 libatk-1.0-0 libgdk-win32-2.0-0 libgdk_pixbuf-2.0-0
|
||||
libpango-1.0-0 libpangocairo-1.0-0 libcairo-2
|
||||
libgio-2.0-0 libgobject-2.0-0 libgmodule-2.0-0 libgthread-2.0-0 libglib-2.0-0 libintl-8
|
||||
libmooglib-0)
|
||||
set(LIBXML2_LIBRARIES "libxml2-2")
|
||||
else()
|
||||
set(MOO_GTK_DIR "C:/gtk-build/gtk/Win32/release" CACHE PATH "Gtk root dir")
|
||||
set(MOO_GTK_DIST_DIR "C:/gtk-build/gtk/bdist" CACHE PATH "Gtk binary dir")
|
||||
|
||||
set(GTK_LIBRARIES atk-1.0 cairo gdk_pixbuf-2.0 gdk-win32-2.0 gio-2.0 glib-2.0 gmodule-2.0 gobject-2.0
|
||||
gthread-2.0 gtk-win32-2.0 iconv intl libffi libpng16 pango-1.0 pangocairo-1.0 pixman-1 zlib1)
|
||||
set(LIBXML2_LIBRARIES libxml2)
|
||||
endif()
|
||||
|
||||
set(CMAKE_INSTALL_PREFIX ${MOO_GTK_DIR} CACHE PATH "CMake install prefix" FORCE)
|
||||
|
||||
include_directories(SYSTEM "${MOO_GTK_DIR}/include")
|
||||
include_directories(SYSTEM "${MOO_GTK_DIR}/include/glib-2.0")
|
||||
include_directories(SYSTEM "${MOO_GTK_DIR}/lib/glib-2.0/include")
|
||||
include_directories(SYSTEM "${MOO_GTK_DIR}/lib/gtk-2.0/include")
|
||||
include_directories(SYSTEM "${MOO_GTK_DIR}/include/gtk-2.0")
|
||||
include_directories(SYSTEM "${MOO_GTK_DIR}/include/gdk-pixbuf-2.0")
|
||||
include_directories(SYSTEM "${MOO_GTK_DIR}/include/pango-1.0")
|
||||
include_directories(SYSTEM "${MOO_GTK_DIR}/include/atk-1.0")
|
||||
include_directories(SYSTEM "${MOO_GTK_DIR}/include/cairo")
|
||||
include_directories(SYSTEM "${MOO_GTK_DIR}/include/libxml2")
|
||||
|
||||
set(GTK_LIBRARY_DIRS "${MOO_GTK_DIR}/lib")
|
||||
|
||||
set(ENV{PATH} "ENV{PATH};${MOO_GTK_DIR}/bin")
|
||||
|
||||
include_directories(SYSTEM "${CMAKE_SOURCE_DIR}/moo/mooutils/moowin32/ms")
|
||||
|
||||
foreach(var CMAKE_C_FLAGS CMAKE_CXX_FLAGS)
|
||||
set(${var} "${${var}} /MP /Zo /wd4996")
|
||||
|
||||
# "C4706: assignment within conditional expression" - it's a good warning, it catches
|
||||
# 'if(x = 5)'. Unfortunately it also complains about 'while ((p = x()))' which is fine
|
||||
# and is used a lot. Additional parentheses don't silence it, unlike with gcc.
|
||||
set(${var} "${${var}} /W4 /WX /wd4244 /wd4800 /wd4100 /wd4127 /wd4054 /wd4055 /wd4306 /wd4706 /wd4125 /wd4389 /wd4152 /wd4505")
|
||||
|
||||
set(${var}_RELEASE "${${var}_RELEASE} /Zi")
|
||||
string(REPLACE "/Ob1" "/Ob2" ${var}_RELWITHDEBINFO "${${var}_RELWITHDEBINFO}")
|
||||
|
||||
if (true)
|
||||
# /MDd means link with the debug crt library, which we don't want; and /D_DEBUG forces
|
||||
# that as well because of some includes; turn them off.
|
||||
string(REPLACE "/MDd" "/MD" ${var}_DEBUG "${${var}_DEBUG}")
|
||||
string(REPLACE "/D_DEBUG" "/DENABLE_DEBUG=1 /DDEBUG=1 /DMOO_DEBUG=1" ${var}_DEBUG "${${var}_DEBUG}")
|
||||
else()
|
||||
string(REPLACE "/D_DEBUG" "/DENABLE_DEBUG=1 /DDEBUG=1 /DMOO_DEBUG=1 /D_DEBUG" ${var}_DEBUG "${${var}_DEBUG}")
|
||||
endif()
|
||||
endforeach()
|
||||
|
||||
set(CMAKE_EXE_LINKER_FLAGS_RELEASE "${CMAKE_EXE_LINKER_FLAGS_RELEASE} /DEBUG /INCREMENTAL")
|
||||
set(CMAKE_MODULE_LINKER_FLAGS_RELEASE "${CMAKE_MODULE_LINKER_FLAGS_RELEASE} /DEBUG /INCREMENTAL")
|
||||
set(CMAKE_SHARED_LINKER_FLAGS_RELEASE "${CMAKE_SHARED_LINKER_FLAGS_RELEASE} /DEBUG /INCREMENTAL")
|
||||
|
||||
endif()
|
||||
|
||||
find_program(GLIB_GENMARSHAL glib-genmarshal)
|
||||
find_program(GDK_PIXBUF_CSOURCE gdk-pixbuf-csource)
|
||||
|
||||
#find_library(LIBM m)
|
||||
|
||||
find_package(Gettext REQUIRED)
|
||||
set(GETTEXT_PACKAGE "${MOO_PACKAGE_NAME}")
|
||||
set(GETTEXT_PACKAGE_GSV "${MOO_PACKAGE_NAME}-gsv")
|
||||
# MOO_INTL
|
||||
|
||||
set(PythonInterp_FIND_VERSION TRUE)
|
||||
set(PythonInterp_FIND_VERSION_MAJOR 2)
|
||||
find_package(PythonInterp REQUIRED)
|
||||
set(MOO_PYTHON "${PYTHON_EXECUTABLE}")
|
||||
|
||||
set(MOO_ENABLE_PYTHON TRUE CACHE BOOL "Use python")
|
||||
|
||||
add_definitions(-DHAVE_CONFIG_H=1 -DXDG_PREFIX=_moo_edit_xdg -DG_LOG_DOMAIN=\"Moo\")
|
||||
#add_definitions(-DGDK_DISABLE_DEPRECATED=1)
|
||||
#add_definitions(-DGTK_DISABLE_DEPRECATED=1)
|
||||
|
||||
if(WIN32)
|
||||
add_definitions(-DUNICODE=1 -D_UNICODE=1 -D__WIN32__=1 -DSTRICT=1 -D_CRT_SECURE_NO_WARNINGS=1 -D_CRT_NONSTDC_NO_WARNINGS=1)
|
||||
set(MOO_NEED_GETTIMEOFDAY TRUE)
|
||||
set(HAVE_UNISTD_H TRUE)
|
||||
set(HAVE_BIND_TEXTDOMAIN_CODESET TRUE)
|
||||
list(APPEND MEDIT_LIBS Shlwapi.lib)
|
||||
endif(WIN32)
|
||||
|
||||
# zzz SUBDIRS = po po-gsv api doc moo
|
||||
add_subdirectory(api)
|
||||
# add_subdirectory(doc)
|
||||
|
||||
#set(ENABLE_NLS TRUE)
|
||||
#add_subdirectory(po)
|
||||
#add_subdirectory(po-gsv)
|
||||
|
||||
add_subdirectory(moo)
|
||||
|
||||
configure_file(${CMAKE_CURRENT_SOURCE_DIR}/config-cmake.h.in ${CMAKE_CURRENT_BINARY_DIR}/config.h)
|
||||
|
||||
if(WIN32)
|
||||
install(DIRECTORY plat/win32/medit-data/bin plat/win32/medit-data/etc DESTINATION "${CMAKE_INSTALL_PREFIX}")
|
||||
endif(WIN32)
|
||||
cmake_minimum_required(VERSION 3.0)
|
||||
cmake_policy(SET CMP0048 NEW)
|
||||
|
||||
list(APPEND EXTRA_DIST
|
||||
tools/genenums.py
|
||||
tools/glade2c.py
|
||||
tools/xml2h.py
|
||||
plat/win32/installer.iss.in
|
||||
plat/win32/istrans.sh
|
||||
plat/win32/mingw-configure
|
||||
)
|
||||
|
||||
# zzz
|
||||
# if MOO_OS_WIN32
|
||||
# plat/win32/installer.iss: $(top_srcdir)/plat/win32/installer.iss.in $(top_builddir)/config.status
|
||||
# $(AM_V_at)$(MKDIR_P) plat/win32
|
||||
# $(AM_V_GEN)cd $(top_builddir) && ./config.status --silent --file=plat/win32/installer.iss
|
||||
# installer: plat/win32/installer.iss install
|
||||
# $(MEDIT_INNO_COMPILER) plat/win32/installer.iss
|
||||
# copy:
|
||||
# cp moo/medit.exe "/win/Program Files (x86)/medit/bin/"
|
||||
# bd_tmpdir = medit-win-dist-tmp
|
||||
# bd_distdir = $(PACKAGE)-$(VERSION)
|
||||
# bd_pzip = $(PACKAGE)-portable-$(VERSION)
|
||||
# bd_zip = $(PACKAGE)-$(VERSION)
|
||||
# portable: install
|
||||
# rm -fr $(bd_tmpdir)
|
||||
# mkdir $(bd_tmpdir)
|
||||
# cp -lR ${prefix} $(bd_tmpdir)/$(bd_distdir)
|
||||
# cd $(bd_tmpdir) && zip -r9 $(bd_zip).zip $(bd_distdir)
|
||||
# echo "This file enables portable mode for medit" > $(bd_tmpdir)/$(bd_distdir)/bin/$(MEDIT_PORTABLE_MAGIC_FILE_NAME)
|
||||
# cd $(bd_tmpdir) && zip -r9 $(bd_pzip).zip $(bd_distdir)
|
||||
# mv $(bd_tmpdir)/$(bd_pzip).zip $(bd_tmpdir)/$(bd_zip).zip .
|
||||
# rm -fr $(bd_tmpdir)
|
||||
# bdist: installer portable
|
||||
# endif
|
||||
|
||||
# zzz @MOO_PO_SUBDIRS_RULE@
|
||||
|
||||
set(MOO_MAJOR_VERSION 1)
|
||||
set(MOO_MINOR_VERSION 2)
|
||||
set(MOO_MICRO_VERSION 90)
|
||||
set(_moo_version_suffix_ "-devel")
|
||||
set(MOO_MODULE_MAJOR_VERSION 2)
|
||||
set(MOO_MODULE_MINOR_VERSION 0)
|
||||
set(MOO_VERSION "${MOO_MAJOR_VERSION}.${MOO_MINOR_VERSION}.${MOO_MICRO_VERSION}")
|
||||
set(MOO_DISPLAY_VERSION "${MOO_VERSION}${_moo_version_suffix_}")
|
||||
|
||||
project(medit VERSION ${MOO_VERSION})
|
||||
|
||||
# keep in sync with po/maintain
|
||||
set(MOO_PACKAGE_NAME "medit-1")
|
||||
|
||||
set(MOO_WEBSITE "http://mooedit.sourceforge.net/")
|
||||
set(MOO_WEB_CONTACT "http://mooedit.sourceforge.net/contact.html")
|
||||
set(MOO_EMAIL "emuntyan@users.sourceforge.net")
|
||||
set(MOO_COPYRIGHT "2004-2015 Yevgen Muntyan <${MOO_EMAIL}>")
|
||||
|
||||
set(MOO_PREFS_XML_FILE_NAME "prefs.xml")
|
||||
set(MOO_STATE_XML_FILE_NAME "state.xml")
|
||||
set(MOO_NAMED_SESSION_XML_FILE_NAME "session-%s.xml")
|
||||
set(MOO_SESSION_XML_FILE_NAME "session.xml")
|
||||
set(MEDIT_PORTABLE_MAGIC_FILE_NAME "medit-portable")
|
||||
set(MEDIT_PORTABLE_DATA_DIR "medit-portable-data")
|
||||
set(MEDIT_PORTABLE_CACHE_DIR "medit-portable-cache")
|
||||
|
||||
set(MOO_DATA_DIR "${CMAKE_INSTALL_PREFIX}/share/${MOO_PACKAGE_NAME}")
|
||||
set(MOO_LIB_DIR "${CMAKE_INSTALL_PREFIX}/lib/${MOO_PACKAGE_NAME}")
|
||||
set(MOO_DOC_DIR "${CMAKE_INSTALL_PREFIX}/share/doc/${MOO_PACKAGE_NAME}")
|
||||
set(MOO_HELP_DIR "${MOO_DOC_DIR}/help")
|
||||
set(MOO_TEXT_LANG_FILES_DIR "${MOO_DATA_DIR}/language-specs")
|
||||
set(MOO_PYTHON_PLUGIN_DIR "${MOO_DATA_DIR}/plugins")
|
||||
set(MOO_PYTHON_LIB_DIR "${MOO_DATA_DIR}/python")
|
||||
|
||||
if(CMAKE_COMPILER_IS_GNUCXX)
|
||||
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++11")
|
||||
endif()
|
||||
|
||||
if(WIN32 AND CMAKE_CONFIGURATION_TYPES)
|
||||
set(CMAKE_CONFIGURATION_TYPES Release Debug)
|
||||
set(CMAKE_CONFIGURATION_TYPES "${CMAKE_CONFIGURATION_TYPES}" CACHE STRING
|
||||
"Reset the configurations to what we need" FORCE)
|
||||
endif()
|
||||
|
||||
set(CMAKE_INCLUDE_CURRENT_DIR ON)
|
||||
set(CMAKE_AUTOMOC ON)
|
||||
|
||||
if(WIN32)
|
||||
set(MOO_OS_WIN32 TRUE)
|
||||
else()
|
||||
set(MOO_OS_UNIX TRUE)
|
||||
endif()
|
||||
|
||||
set(MOO_BUILD_FROM_MINGW ${MOO_OS_WIN32} CACHE BOOL "Create a win32 build from mingw gtk build")
|
||||
|
||||
if(NOT MOO_BUILD_FROM_MINGW)
|
||||
find_package(PkgConfig REQUIRED)
|
||||
pkg_check_modules(GTK REQUIRED gtk+-2.0)
|
||||
pkg_check_modules(GMODULE REQUIRED gmodule-2.0)
|
||||
#execute_process(
|
||||
# COMMAND ${PKG_CONFIG_EXECUTABLE} --variable=glib_genmarshal glib-2.0
|
||||
# OUTPUT_VARIABLE GLIB_GENMARSHAL
|
||||
# OUTPUT_STRIP_TRAILING_WHITESPACE
|
||||
# RESULT_VARIABLE RESULT)
|
||||
#if(NOT RESULT EQUAL 0)
|
||||
# MESSAGE(FATAL_ERROR "Could not find glib-genmarshal")
|
||||
#endif()
|
||||
execute_process(
|
||||
COMMAND ${PKG_CONFIG_EXECUTABLE} --variable=glib_mkenums glib-2.0
|
||||
OUTPUT_VARIABLE GLIB_MKENUMS
|
||||
OUTPUT_STRIP_TRAILING_WHITESPACE
|
||||
RESULT_VARIABLE RESULT)
|
||||
if(NOT RESULT EQUAL 0)
|
||||
MESSAGE(FATAL_ERROR "Could not find glib-mkenums")
|
||||
endif()
|
||||
|
||||
pkg_check_modules(XLIB x11 xext xrender ice sm)
|
||||
pkg_check_modules(LIBXML2 REQUIRED libxml-2.0)
|
||||
else()
|
||||
set(MOO_GTK_DIR "C:/Projects/gtk/release/target" CACHE PATH "Gtk root dir")
|
||||
set(MOO_GTK_DIST_DIR "C:/Projects/gtk/release/bdist" CACHE PATH "Gtk binary dir")
|
||||
|
||||
set(CMAKE_INSTALL_PREFIX ${MOO_GTK_DIR} CACHE PATH "CMake install prefix" FORCE)
|
||||
|
||||
include_directories(SYSTEM "${MOO_GTK_DIR}/include")
|
||||
include_directories(SYSTEM "${MOO_GTK_DIR}/include/glib-2.0")
|
||||
include_directories(SYSTEM "${MOO_GTK_DIR}/lib/glib-2.0/include")
|
||||
include_directories(SYSTEM "${MOO_GTK_DIR}/lib/gtk-2.0/include")
|
||||
include_directories(SYSTEM "${MOO_GTK_DIR}/include/gtk-2.0")
|
||||
include_directories(SYSTEM "${MOO_GTK_DIR}/include/gdk-pixbuf-2.0")
|
||||
include_directories(SYSTEM "${MOO_GTK_DIR}/include/pango-1.0")
|
||||
include_directories(SYSTEM "${MOO_GTK_DIR}/include/atk-1.0")
|
||||
include_directories(SYSTEM "${MOO_GTK_DIR}/include/cairo")
|
||||
include_directories(SYSTEM "${MOO_GTK_DIR}/include/libxml2")
|
||||
|
||||
set(GTK_LIBRARY_DIRS "${MOO_GTK_DIR}/lib")
|
||||
set(GTK_LIBRARIES libgtk-win32-2.0-0 libatk-1.0-0 libgdk-win32-2.0-0 libgdk_pixbuf-2.0-0
|
||||
libpango-1.0-0 libpangocairo-1.0-0 libcairo-2
|
||||
libgio-2.0-0 libgobject-2.0-0 libgmodule-2.0-0 libgthread-2.0-0 libglib-2.0-0 libintl-8)
|
||||
set(LIBXML2_LIBRARIES "libxml2-2")
|
||||
|
||||
set(ENV{PATH} "ENV{PATH};${MOO_GTK_DIR}/bin")
|
||||
|
||||
include_directories(SYSTEM "${CMAKE_SOURCE_DIR}/moo/mooutils/moowin32/ms")
|
||||
|
||||
set(PYGTK_DEFS_DIR ${MOO_GTK_DIR}/share/pygtk/2.0/defs)
|
||||
set(PYGOBJECT_DEFS_DIR ${MOO_GTK_DIR}/share/pygobject/2.0/defs)
|
||||
|
||||
set(PYGTK_INCLUDE_DIR "${MOO_GTK_DIR}/include/pygtk-2.0")
|
||||
include_directories(SYSTEM "${PYGTK_INCLUDE_DIR}")
|
||||
|
||||
foreach(var CMAKE_C_FLAGS CMAKE_CXX_FLAGS)
|
||||
set(${var} "${${var}} /MP /Zo /wd4996")
|
||||
|
||||
# "C4706: assignment within conditional expression" - it's a good warning, it catches
|
||||
# 'if(x = 5)'. Unfortunately it also complains about 'while ((p = x()))' which is fine
|
||||
# and is used a lot. Additional parentheses don't silence it, unlike with gcc.
|
||||
set(${var} "${${var}} /W4 /WX /wd4244 /wd4800 /wd4100 /wd4127 /wd4054 /wd4055 /wd4306 /wd4706 /wd4125 /wd4389 /wd4152 /wd4505")
|
||||
|
||||
set(${var}_RELEASE "${${var}_RELEASE} /Zi")
|
||||
string(REPLACE "/Ob1" "/Ob2" ${var}_RELWITHDEBINFO "${${var}_RELWITHDEBINFO}")
|
||||
string(REPLACE "/MDd" "/MD" ${var}_DEBUG "${${var}_DEBUG}")
|
||||
string(REPLACE "/D_DEBUG" "" ${var}_DEBUG "${${var}_DEBUG}")
|
||||
endforeach()
|
||||
endif()
|
||||
|
||||
find_program(GLIB_GENMARSHAL glib-genmarshal)
|
||||
find_program(GDK_PIXBUF_CSOURCE gdk-pixbuf-csource)
|
||||
|
||||
#find_library(LIBM m)
|
||||
|
||||
find_package(Gettext REQUIRED)
|
||||
set(GETTEXT_PACKAGE "${MOO_PACKAGE_NAME}")
|
||||
set(GETTEXT_PACKAGE_GSV "${MOO_PACKAGE_NAME}-gsv")
|
||||
# MOO_INTL
|
||||
|
||||
set(PythonInterp_FIND_VERSION TRUE)
|
||||
set(PythonInterp_FIND_VERSION_MAJOR 2)
|
||||
find_package(PythonInterp REQUIRED)
|
||||
set(MOO_PYTHON "${PYTHON_EXECUTABLE}")
|
||||
|
||||
set(MOO_ENABLE_PYTHON TRUE CACHE BOOL "Use python")
|
||||
|
||||
configure_file(${CMAKE_CURRENT_SOURCE_DIR}/config-cmake.h.in ${CMAKE_CURRENT_BINARY_DIR}/config.h)
|
||||
add_definitions(-DMOO_COMPILATION=1 -DHAVE_CONFIG_H=1 -DXDG_PREFIX=_moo_edit_xdg -DG_LOG_DOMAIN=\"Moo\")
|
||||
|
||||
if(WIN32)
|
||||
add_definitions(-DUNICODE=1 -D_UNICODE=1 -D__WIN32__=1 -DSTRICT=1 -D_CRT_SECURE_NO_WARNINGS=1 -D_CRT_NONSTDC_NO_WARNINGS=1)
|
||||
add_definitions(-DMOO_NEED_GETTIMEOFDAY=1)
|
||||
add_definitions(-DHAVE_UNISTD_H=1 -DENABLE_NLS=1 -DHAVE_BIND_TEXTDOMAIN_CODESET=1)
|
||||
endif(WIN32)
|
||||
|
||||
# zzz SUBDIRS = po po-gsv api doc moo
|
||||
add_subdirectory(api)
|
||||
# add_subdirectory(doc)
|
||||
#add_subdirectory(po)
|
||||
#add_subdirectory(po-gsv)
|
||||
|
||||
add_subdirectory(moo)
|
||||
|
|
|
@ -9,7 +9,7 @@ EXTRA_DIST = \
|
|||
|
||||
DISTCHECK_CONFIGURE_FLAGS =
|
||||
if MOO_DEV_MODE
|
||||
DISTCHECK_CONFIGURE_FLAGS += MAKEFLAGS=-j4
|
||||
DISTCHECK_CONFIGURE_FLAGS += MAKEFLAGS=-j3
|
||||
endif
|
||||
if MOO_STRICT_MODE
|
||||
DISTCHECK_CONFIGURE_FLAGS += --enable-strict
|
||||
|
|
|
@ -44,22 +44,23 @@ SET(source_files
|
|||
../moo/mooapp/moolinklabel.h
|
||||
../moo/mooedit/mooedit-accels.h
|
||||
../moo/mooedit/mooeditaction.c
|
||||
../moo/mooedit/mooeditaction-factory.cpp
|
||||
../moo/mooedit/mooeditaction-factory.c
|
||||
../moo/mooedit/mooeditaction-factory.h
|
||||
../moo/mooedit/mooeditaction.h
|
||||
../moo/mooedit/mooeditbookmark.cpp
|
||||
../moo/mooedit/mooeditbookmark.c
|
||||
../moo/mooedit/mooeditbookmark.h
|
||||
../moo/mooedit/mooedit.cpp
|
||||
../moo/mooedit/mooedit.c
|
||||
../moo/mooedit/mooeditconfig.c
|
||||
../moo/mooedit/mooeditconfig.h
|
||||
../moo/mooedit/mooeditdialogs.cpp
|
||||
../moo/mooedit/mooeditdialogs.c
|
||||
../moo/mooedit/mooeditdialogs.h
|
||||
../moo/mooedit/mooedit-enum-types.c
|
||||
../moo/mooedit/mooedit-enum-types.h
|
||||
../moo/mooedit/mooedit-enums.h
|
||||
../moo/mooedit/mooeditfileinfo.cpp
|
||||
../moo/mooedit/mooeditfileinfo.c
|
||||
../moo/mooedit/mooeditfileinfo.c
|
||||
../moo/mooedit/mooeditfileinfo.h
|
||||
../moo/mooedit/mooedit-fileops.cpp
|
||||
../moo/mooedit/mooedit-fileops.c
|
||||
../moo/mooedit/mooedit-fileops.h
|
||||
../moo/mooedit/mooeditfiltersettings.c
|
||||
../moo/mooedit/mooeditfiltersettings.h
|
||||
|
@ -73,16 +74,16 @@ SET(source_files
|
|||
../moo/mooedit/mooeditor-private.h
|
||||
../moo/mooedit/mooeditor-tests.c
|
||||
../moo/mooedit/mooeditor-tests.h
|
||||
../moo/mooedit/mooeditprefs.cpp
|
||||
../moo/mooedit/mooeditprefs.c
|
||||
../moo/mooedit/mooeditprefs.h
|
||||
../moo/mooedit/mooeditprefspage.c
|
||||
../moo/mooedit/mooedit-private.h
|
||||
../moo/mooedit/mooedit-script.c
|
||||
../moo/mooedit/mooedit-script.h
|
||||
../moo/mooedit/mooedittab.cpp
|
||||
../moo/mooedit/mooedittab.c
|
||||
../moo/mooedit/mooedittab.h
|
||||
../moo/mooedit/mooedittypes.h
|
||||
../moo/mooedit/mooeditview.cpp
|
||||
../moo/mooedit/mooeditview.c
|
||||
../moo/mooedit/mooeditview.h
|
||||
../moo/mooedit/mooeditview-script.c
|
||||
../moo/mooedit/mooeditview-script.h
|
||||
|
@ -95,7 +96,7 @@ SET(source_files
|
|||
../moo/mooedit/mooindenter.h
|
||||
../moo/mooedit/moolang.c
|
||||
../moo/mooedit/moolang.h
|
||||
../moo/mooedit/moolangmgr.cpp
|
||||
../moo/mooedit/moolangmgr.c
|
||||
../moo/mooedit/moolangmgr.h
|
||||
../moo/mooedit/moolangmgr-private.h
|
||||
../moo/mooedit/moolang-private.h
|
||||
|
@ -136,7 +137,7 @@ SET(source_files
|
|||
../moo/moofileview/moofileentry.h
|
||||
../moo/moofileview/moofile.h
|
||||
../moo/moofileview/moofile-private.h
|
||||
../moo/moofileview/moofilesystem.cpp
|
||||
../moo/moofileview/moofilesystem.c
|
||||
../moo/moofileview/moofilesystem.h
|
||||
../moo/moofileview/moofileview-accels.h
|
||||
../moo/moofileview/moofileview-aux.h
|
||||
|
@ -148,9 +149,9 @@ SET(source_files
|
|||
../moo/moofileview/moofileview-private.h
|
||||
../moo/moofileview/moofileview-tools.c
|
||||
../moo/moofileview/moofileview-tools.h
|
||||
../moo/moofileview/moofolder.cpp
|
||||
../moo/moofileview/moofolder.c
|
||||
../moo/moofileview/moofolder.h
|
||||
../moo/moofileview/moofoldermodel.cpp
|
||||
../moo/moofileview/moofoldermodel.c
|
||||
../moo/moofileview/moofoldermodel.h
|
||||
../moo/moofileview/moofoldermodel-private.h
|
||||
../moo/moofileview/moofolder-private.h
|
||||
|
@ -158,140 +159,140 @@ SET(source_files
|
|||
../moo/moofileview/mooiconview.h
|
||||
../moo/moofileview/mootreeview.c
|
||||
../moo/moofileview/mootreeview.h
|
||||
../moo/mooutils/mooaccelbutton.cpp
|
||||
../moo/mooutils/mooaccelbutton.c
|
||||
../moo/mooutils/mooaccelbutton.h
|
||||
../moo/mooutils/mooaccel.cpp
|
||||
../moo/mooutils/mooaccel.c
|
||||
../moo/mooutils/mooaccel.h
|
||||
../moo/mooutils/mooaccelprefs.cpp
|
||||
../moo/mooutils/mooaccelprefs.c
|
||||
../moo/mooutils/mooaccelprefs.h
|
||||
../moo/mooutils/mooactionbase.cpp
|
||||
../moo/mooutils/mooactionbase.c
|
||||
../moo/mooutils/mooactionbase.h
|
||||
../moo/mooutils/mooactionbase-private.h
|
||||
../moo/mooutils/mooaction.cpp
|
||||
../moo/mooutils/mooactioncollection.cpp
|
||||
../moo/mooutils/mooaction.c
|
||||
../moo/mooutils/mooactioncollection.c
|
||||
../moo/mooutils/mooactioncollection.h
|
||||
../moo/mooutils/mooactionfactory.cpp
|
||||
../moo/mooutils/mooactionfactory.c
|
||||
../moo/mooutils/mooactionfactory.h
|
||||
../moo/mooutils/mooactiongroup.cpp
|
||||
../moo/mooutils/mooactiongroup.c
|
||||
../moo/mooutils/mooactiongroup.h
|
||||
../moo/mooutils/mooaction.h
|
||||
../moo/mooutils/mooaction-private.h
|
||||
../moo/mooutils/mooappinput-common.cpp
|
||||
../moo/mooutils/mooappinput-common.c
|
||||
../moo/mooutils/mooappinput.h
|
||||
../moo/mooutils/mooapp-ipc.cpp
|
||||
../moo/mooutils/mooapp-ipc.c
|
||||
../moo/mooutils/mooapp-ipc.h
|
||||
../moo/mooutils/mooarray.h
|
||||
../moo/mooutils/mooatom.h
|
||||
../moo/mooutils/moobigpaned.cpp
|
||||
../moo/mooutils/moobigpaned.c
|
||||
../moo/mooutils/moobigpaned.h
|
||||
../moo/mooutils/mooclosure.cpp
|
||||
../moo/mooutils/mooclosure.c
|
||||
../moo/mooutils/mooclosure.h
|
||||
../moo/mooutils/moocombo.cpp
|
||||
../moo/mooutils/moocombo.c
|
||||
../moo/mooutils/moocombo.h
|
||||
../moo/mooutils/moocompat.h
|
||||
../moo/mooutils/moodialogs.cpp
|
||||
../moo/mooutils/moodialogs.c
|
||||
../moo/mooutils/moodialogs.h
|
||||
../moo/mooutils/mooeditops.cpp
|
||||
../moo/mooutils/mooeditops.c
|
||||
../moo/mooutils/mooeditops.h
|
||||
../moo/mooutils/mooencodings.cpp
|
||||
../moo/mooutils/mooencodings.c
|
||||
../moo/mooutils/mooencodings-data.h
|
||||
../moo/mooutils/mooencodings.h
|
||||
../moo/mooutils/mooentry.cpp
|
||||
../moo/mooutils/mooentry.c
|
||||
../moo/mooutils/mooentry.h
|
||||
../moo/mooutils/moo-environ.h
|
||||
../moo/mooutils/moofiledialog.cpp
|
||||
../moo/mooutils/moofiledialog.c
|
||||
../moo/mooutils/moofiledialog.h
|
||||
../moo/mooutils/moofileicon.cpp
|
||||
../moo/mooutils/moofileicon.c
|
||||
../moo/mooutils/moofileicon.h
|
||||
../moo/mooutils/moofilewatch.cpp
|
||||
../moo/mooutils/moofilewatch.c
|
||||
../moo/mooutils/moofilewatch.h
|
||||
../moo/mooutils/moofilewriter.cpp
|
||||
../moo/mooutils/moofilewriter.c
|
||||
../moo/mooutils/moofilewriter.h
|
||||
../moo/mooutils/moofilewriter-private.h
|
||||
../moo/mooutils/moofiltermgr.cpp
|
||||
../moo/mooutils/moofiltermgr.c
|
||||
../moo/mooutils/moofiltermgr.h
|
||||
../moo/mooutils/moofontsel.c
|
||||
../moo/mooutils/moofontsel.h
|
||||
../moo/mooutils/mooglade.cpp
|
||||
../moo/mooutils/mooglade.c
|
||||
../moo/mooutils/mooglade.h
|
||||
../moo/mooutils/moohelp.cpp
|
||||
../moo/mooutils/moohelp.c
|
||||
../moo/mooutils/moohelp.h
|
||||
../moo/mooutils/moohistorycombo.cpp
|
||||
../moo/mooutils/moohistorycombo.c
|
||||
../moo/mooutils/moohistorycombo.h
|
||||
../moo/mooutils/moohistorylist.cpp
|
||||
../moo/mooutils/moohistorylist.c
|
||||
../moo/mooutils/moohistorylist.h
|
||||
../moo/mooutils/moohistorymgr.cpp
|
||||
../moo/mooutils/moohistorymgr.c
|
||||
../moo/mooutils/moohistorymgr.h
|
||||
../moo/mooutils/mooi18n.cpp
|
||||
../moo/mooutils/mooi18n.c
|
||||
../moo/mooutils/mooi18n.h
|
||||
../moo/mooutils/moolist.h
|
||||
../moo/mooutils/moomarkup.cpp
|
||||
../moo/mooutils/moomarkup.c
|
||||
../moo/mooutils/moomarkup.h
|
||||
../moo/mooutils/moomenuaction.cpp
|
||||
../moo/mooutils/moomenuaction.c
|
||||
../moo/mooutils/moomenuaction.h
|
||||
../moo/mooutils/moomenu.cpp
|
||||
../moo/mooutils/moomenu.c
|
||||
../moo/mooutils/moomenu.h
|
||||
../moo/mooutils/moomenumgr.cpp
|
||||
../moo/mooutils/moomenumgr.c
|
||||
../moo/mooutils/moomenumgr.h
|
||||
../moo/mooutils/moomenutoolbutton.cpp
|
||||
../moo/mooutils/moomenutoolbutton.c
|
||||
../moo/mooutils/moomenutoolbutton.h
|
||||
../moo/mooutils/moo-mime.cpp
|
||||
../moo/mooutils/moo-mime.c
|
||||
../moo/mooutils/moo-mime.h
|
||||
../moo/mooutils/moonotebook.cpp
|
||||
../moo/mooutils/moonotebook.c
|
||||
../moo/mooutils/moonotebook.h
|
||||
../moo/mooutils/mooonce.h
|
||||
../moo/mooutils/moopane.cpp
|
||||
../moo/mooutils/moopaned.cpp
|
||||
../moo/mooutils/moopane.c
|
||||
../moo/mooutils/moopaned.c
|
||||
../moo/mooutils/moopaned.h
|
||||
../moo/mooutils/moopane.h
|
||||
../moo/mooutils/mooprefs.cpp
|
||||
../moo/mooutils/mooprefsdialog.cpp
|
||||
../moo/mooutils/mooprefs.c
|
||||
../moo/mooutils/mooprefsdialog.c
|
||||
../moo/mooutils/mooprefsdialog.h
|
||||
../moo/mooutils/mooprefs.h
|
||||
../moo/mooutils/mooprefspage.cpp
|
||||
../moo/mooutils/mooprefspage.c
|
||||
../moo/mooutils/mooprefspage.h
|
||||
../moo/mooutils/moospawn.cpp
|
||||
../moo/mooutils/moospawn.c
|
||||
../moo/mooutils/moospawn.h
|
||||
../moo/mooutils/moostock.cpp
|
||||
../moo/mooutils/moostock.c
|
||||
../moo/mooutils/moostock.h
|
||||
../moo/mooutils/moo-test-macros.h
|
||||
../moo/mooutils/moo-test-utils.cpp
|
||||
../moo/mooutils/moo-test-utils.c
|
||||
../moo/mooutils/moo-test-utils.h
|
||||
../moo/mooutils/mootypedecl-macros.h
|
||||
../moo/mooutils/mootype-macros.h
|
||||
../moo/mooutils/moouixml.cpp
|
||||
../moo/mooutils/moouixml.c
|
||||
../moo/mooutils/moouixml.h
|
||||
../moo/mooutils/mooundo.cpp
|
||||
../moo/mooutils/mooundo.c
|
||||
../moo/mooutils/mooundo.h
|
||||
../moo/mooutils/mooutils-debug.h
|
||||
../moo/mooutils/mooutils-enums.c
|
||||
../moo/mooutils/mooutils-enums.h
|
||||
../moo/mooutils/mooutils-file.cpp
|
||||
../moo/mooutils/mooutils-file.c
|
||||
../moo/mooutils/mooutils-file.h
|
||||
../moo/mooutils/mooutils-fs.cpp
|
||||
../moo/mooutils/mooutils-fs.c
|
||||
../moo/mooutils/mooutils-fs.h
|
||||
../moo/mooutils/mooutils-gobject.cpp
|
||||
../moo/mooutils/mooutils-gobject.c
|
||||
../moo/mooutils/mooutils-gobject.h
|
||||
../moo/mooutils/mooutils-gobject-private.h
|
||||
../moo/mooutils/mooutils.h
|
||||
../moo/mooutils/mooutils-macros.h
|
||||
../moo/mooutils/mooutils-mem.h
|
||||
../moo/mooutils/mooutils-messages.h
|
||||
../moo/mooutils/mooutils-misc.cpp
|
||||
../moo/mooutils/mooutils-misc.c
|
||||
../moo/mooutils/mooutils-misc.h
|
||||
../moo/mooutils/mooutils-script.cpp
|
||||
../moo/mooutils/mooutils-script.c
|
||||
../moo/mooutils/mooutils-script.h
|
||||
../moo/mooutils/mooutils-tests.h
|
||||
../moo/mooutils/mooutils-thread.cpp
|
||||
../moo/mooutils/mooutils-thread.c
|
||||
../moo/mooutils/mooutils-thread.h
|
||||
../moo/mooutils/mooutils-treeview.cpp
|
||||
../moo/mooutils/mooutils-treeview.c
|
||||
../moo/mooutils/mooutils-treeview.h
|
||||
../moo/mooutils/mooutils-win32.cpp
|
||||
../moo/mooutils/mooutils-win32.c
|
||||
../moo/mooutils/moowin32/mingw/fnmatch.h
|
||||
../moo/mooutils/moowin32/mingw/netinet/in.h
|
||||
../moo/mooutils/moowin32/ms/sys/time.h
|
||||
../moo/mooutils/moowin32/ms/unistd.h
|
||||
../moo/mooutils/moowindow.cpp
|
||||
../moo/mooutils/moowindow.c
|
||||
../moo/mooutils/moowindow.h
|
||||
../moo/plugins/support/moocmdview.c
|
||||
../moo/plugins/support/moocmdview.h
|
||||
|
@ -343,7 +344,7 @@ LIST(APPEND built_moo_sources moo.xml.stamp)
|
|||
|
||||
FILE(WRITE ${CMAKE_CURRENT_BINARY_DIR}/gengtkxml.cmake
|
||||
"EXECUTE_PROCESS(COMMAND ${MOO_PYTHON} ${CMAKE_CURRENT_SOURCE_DIR}/parsedocs.py
|
||||
--source-file ${CMAKE_SOURCE_DIR}/moo/moolua/gtk-api.c
|
||||
--source-file ${CMAKE_SOURCE_DIR}/moo/moolua/gtk-api.c
|
||||
--source-file ${CMAKE_SOURCE_DIR}/moo/moolua/gtk-api.h
|
||||
--module Gtk
|
||||
--output ${CMAKE_CURRENT_SOURCE_DIR}/gtk.xml
|
||||
|
|
|
@ -204,29 +204,17 @@ class Writer(object):
|
|||
'moo_lua_get_arg_enum (L, %(arg_idx)s, "%(param_name)s", ' + \
|
||||
'%(gtype_id)s);') % dic)
|
||||
elif isinstance(param.type, ArrayType):
|
||||
assert isinstance(param.type.elm_type, Class)
|
||||
dic['gtype_id'] = param.type.elm_type.gtype_id
|
||||
if isinstance(param.type.elm_type, Class):
|
||||
if param.default_value is not None:
|
||||
func_body.start.append(('%(TypeName)s arg%(narg)d = (%(TypeName)s) ' + \
|
||||
'moo_lua_get_arg_object_array_opt (L, %(arg_idx)s, "%(param_name)s", ' + \
|
||||
'%(gtype_id)s);') % dic)
|
||||
else:
|
||||
func_body.start.append(('%(TypeName)s arg%(narg)d = (%(TypeName)s) ' + \
|
||||
'moo_lua_get_arg_object_array (L, %(arg_idx)s, "%(param_name)s", ' + \
|
||||
'%(gtype_id)s);') % dic)
|
||||
func_body.end.append('moo_object_array_free ((MooObjectArray*) arg%(narg)d);' % dic)
|
||||
elif isinstance(param.type.elm_type, Boxed):
|
||||
if param.default_value is not None:
|
||||
func_body.start.append(('%(TypeName)s arg%(narg)d = (%(TypeName)s) ' + \
|
||||
'moo_lua_get_arg_boxed_array_opt (L, %(arg_idx)s, "%(param_name)s", ' + \
|
||||
'%(gtype_id)s);') % dic)
|
||||
else:
|
||||
func_body.start.append(('%(TypeName)s arg%(narg)d = (%(TypeName)s) ' + \
|
||||
'moo_lua_get_arg_boxed_array (L, %(arg_idx)s, "%(param_name)s", ' + \
|
||||
'%(gtype_id)s);') % dic)
|
||||
func_body.end.append('moo_boxed_array_free ((MooPtrArray*) arg%(narg)d, %(gtype_id)s);' % dic)
|
||||
if param.default_value is not None:
|
||||
func_body.start.append(('%(TypeName)s arg%(narg)d = (%(TypeName)s) ' + \
|
||||
'moo_lua_get_arg_object_array_opt (L, %(arg_idx)s, "%(param_name)s", ' + \
|
||||
'%(gtype_id)s);') % dic)
|
||||
else:
|
||||
raise "Arrays are not implemented for this type"
|
||||
func_body.start.append(('%(TypeName)s arg%(narg)d = (%(TypeName)s) ' + \
|
||||
'moo_lua_get_arg_object_array (L, %(arg_idx)s, "%(param_name)s", ' + \
|
||||
'%(gtype_id)s);') % dic)
|
||||
func_body.end.append('moo_object_array_free ((MooObjectArray*) arg%(narg)d);' % dic)
|
||||
elif param.type.name == 'strv':
|
||||
assert param.default_value is None or param.default_value == 'NULL'
|
||||
if param.default_value is not None:
|
||||
|
@ -339,15 +327,10 @@ class Writer(object):
|
|||
func_call = '%s ret = ' % meth.retval.type.name
|
||||
push_ret = 'moo_lua_push_int (L, ret);' % dic
|
||||
elif isinstance(meth.retval.type, ArrayType):
|
||||
assert isinstance(meth.retval.type.elm_type, Class)
|
||||
dic['gtype_id'] = meth.retval.type.elm_type.gtype_id
|
||||
if isinstance(meth.retval.type.elm_type, Class):
|
||||
func_call = 'MooObjectArray *ret = (MooObjectArray*) '
|
||||
push_ret = 'moo_lua_push_object_array (L, ret, %(make_copy)s);' % dic
|
||||
elif isinstance(meth.retval.type.elm_type, Boxed):
|
||||
func_call = 'MooPtrArray *ret = (MooPtrArray*) '
|
||||
push_ret = 'moo_lua_push_boxed_array (L, ret, %(gtype_id)s, %(make_copy)s);' % dic
|
||||
else:
|
||||
raise "Arrays of this type are not implemented"
|
||||
func_call = 'MooObjectArray *ret = (MooObjectArray*) '
|
||||
push_ret = 'moo_lua_push_object_array (L, ret, %(make_copy)s);' % dic
|
||||
elif meth.retval.type.name == 'strv':
|
||||
assert meth.retval.transfer_mode == 'full'
|
||||
func_call = 'char **ret = '
|
||||
|
|
|
@ -1,35 +1,36 @@
|
|||
source_files = \
|
||||
../moo/moolua/medit-lua.h\
|
||||
../moo/moolua/medit-lua.cpp\
|
||||
../moo/mooapp/mooappabout.cpp\
|
||||
../moo/mooapp/mooappabout.c\
|
||||
../moo/mooapp/mooappabout.h\
|
||||
../moo/mooapp/mooapp-accels.h\
|
||||
../moo/mooapp/mooapp.cpp\
|
||||
../moo/mooapp/mooapp.c\
|
||||
../moo/mooapp/mooapp.h\
|
||||
../moo/mooapp/mooapp-info.h\
|
||||
../moo/mooapp/mooapp-private.h\
|
||||
../moo/mooapp/moohtml.cpp\
|
||||
../moo/mooapp/moohtml.c\
|
||||
../moo/mooapp/moohtml.h\
|
||||
../moo/mooapp/moolinklabel.cpp\
|
||||
../moo/mooapp/moolinklabel.c\
|
||||
../moo/mooapp/moolinklabel.h\
|
||||
../moo/mooedit/mooedit-accels.h\
|
||||
../moo/mooedit/mooeditaction.c\
|
||||
../moo/mooedit/mooeditaction-factory.cpp\
|
||||
../moo/mooedit/mooeditaction-factory.c\
|
||||
../moo/mooedit/mooeditaction-factory.h\
|
||||
../moo/mooedit/mooeditaction.h\
|
||||
../moo/mooedit/mooeditbookmark.cpp\
|
||||
../moo/mooedit/mooeditbookmark.c\
|
||||
../moo/mooedit/mooeditbookmark.h\
|
||||
../moo/mooedit/mooedit.cpp\
|
||||
../moo/mooedit/mooedit.c\
|
||||
../moo/mooedit/mooeditconfig.c\
|
||||
../moo/mooedit/mooeditconfig.h\
|
||||
../moo/mooedit/mooeditdialogs.cpp\
|
||||
../moo/mooedit/mooeditdialogs.c\
|
||||
../moo/mooedit/mooeditdialogs.h\
|
||||
../moo/mooedit/mooedit-enum-types.c\
|
||||
../moo/mooedit/mooedit-enum-types.h\
|
||||
../moo/mooedit/mooedit-enums.h\
|
||||
../moo/mooedit/mooeditfileinfo.cpp\
|
||||
../moo/mooedit/mooeditfileinfo.c\
|
||||
../moo/mooedit/mooeditfileinfo.c\
|
||||
../moo/mooedit/mooeditfileinfo.h\
|
||||
../moo/mooedit/mooedit-fileops.cpp\
|
||||
../moo/mooedit/mooedit-fileops.c\
|
||||
../moo/mooedit/mooedit-fileops.h\
|
||||
../moo/mooedit/mooeditfiltersettings.c\
|
||||
../moo/mooedit/mooeditfiltersettings.h\
|
||||
|
@ -43,16 +44,16 @@ source_files = \
|
|||
../moo/mooedit/mooeditor-private.h\
|
||||
../moo/mooedit/mooeditor-tests.c\
|
||||
../moo/mooedit/mooeditor-tests.h\
|
||||
../moo/mooedit/mooeditprefs.cpp\
|
||||
../moo/mooedit/mooeditprefs.c\
|
||||
../moo/mooedit/mooeditprefs.h\
|
||||
../moo/mooedit/mooeditprefspage.c\
|
||||
../moo/mooedit/mooedit-private.h\
|
||||
../moo/mooedit/mooedit-script.c\
|
||||
../moo/mooedit/mooedit-script.h\
|
||||
../moo/mooedit/mooedittab.cpp\
|
||||
../moo/mooedit/mooedittab.c\
|
||||
../moo/mooedit/mooedittab.h\
|
||||
../moo/mooedit/mooedittypes.h\
|
||||
../moo/mooedit/mooeditview.cpp\
|
||||
../moo/mooedit/mooeditview.c\
|
||||
../moo/mooedit/mooeditview.h\
|
||||
../moo/mooedit/mooeditview-script.c\
|
||||
../moo/mooedit/mooeditview-script.h\
|
||||
|
@ -65,7 +66,7 @@ source_files = \
|
|||
../moo/mooedit/mooindenter.h\
|
||||
../moo/mooedit/moolang.c\
|
||||
../moo/mooedit/moolang.h\
|
||||
../moo/mooedit/moolangmgr.cpp\
|
||||
../moo/mooedit/moolangmgr.c\
|
||||
../moo/mooedit/moolangmgr.h\
|
||||
../moo/mooedit/moolangmgr-private.h\
|
||||
../moo/mooedit/moolang-private.h\
|
||||
|
@ -97,171 +98,171 @@ source_files = \
|
|||
../moo/mooedit/mootextview.h\
|
||||
../moo/mooedit/mootextview-input.c\
|
||||
../moo/mooedit/mootextview-private.h\
|
||||
../moo/moofileview/moobookmarkmgr.cpp\
|
||||
../moo/moofileview/moobookmarkmgr.c\
|
||||
../moo/moofileview/moobookmarkmgr.h\
|
||||
../moo/moofileview/moobookmarkview.cpp\
|
||||
../moo/moofileview/moobookmarkview.c\
|
||||
../moo/moofileview/moobookmarkview.h\
|
||||
../moo/moofileview/moofile.cpp\
|
||||
../moo/moofileview/moofileentry.cpp\
|
||||
../moo/moofileview/moofile.c\
|
||||
../moo/moofileview/moofileentry.c\
|
||||
../moo/moofileview/moofileentry.h\
|
||||
../moo/moofileview/moofile.h\
|
||||
../moo/moofileview/moofile-private.h\
|
||||
../moo/moofileview/moofilesystem.cpp\
|
||||
../moo/moofileview/moofilesystem.c\
|
||||
../moo/moofileview/moofilesystem.h\
|
||||
../moo/moofileview/moofileview-accels.h\
|
||||
../moo/moofileview/moofileview-aux.h\
|
||||
../moo/moofileview/moofileview.cpp\
|
||||
../moo/moofileview/moofileview-dialogs.cpp\
|
||||
../moo/moofileview/moofileview.c\
|
||||
../moo/moofileview/moofileview-dialogs.c\
|
||||
../moo/moofileview/moofileview-dialogs.h\
|
||||
../moo/moofileview/moofileview.h\
|
||||
../moo/moofileview/moofileview-impl.h\
|
||||
../moo/moofileview/moofileview-private.h\
|
||||
../moo/moofileview/moofileview-tools.cpp\
|
||||
../moo/moofileview/moofileview-tools.c\
|
||||
../moo/moofileview/moofileview-tools.h\
|
||||
../moo/moofileview/moofolder.cpp\
|
||||
../moo/moofileview/moofolder.c\
|
||||
../moo/moofileview/moofolder.h\
|
||||
../moo/moofileview/moofoldermodel.cpp\
|
||||
../moo/moofileview/moofoldermodel.c\
|
||||
../moo/moofileview/moofoldermodel.h\
|
||||
../moo/moofileview/moofoldermodel-private.h\
|
||||
../moo/moofileview/moofolder-private.h\
|
||||
../moo/moofileview/mooiconview.cpp\
|
||||
../moo/moofileview/mooiconview.c\
|
||||
../moo/moofileview/mooiconview.h\
|
||||
../moo/moofileview/mootreeview.cpp\
|
||||
../moo/moofileview/mootreeview.c\
|
||||
../moo/moofileview/mootreeview.h\
|
||||
../moo/mooutils/mooaccelbutton.cpp\
|
||||
../moo/mooutils/mooaccelbutton.c\
|
||||
../moo/mooutils/mooaccelbutton.h\
|
||||
../moo/mooutils/mooaccel.cpp\
|
||||
../moo/mooutils/mooaccel.c\
|
||||
../moo/mooutils/mooaccel.h\
|
||||
../moo/mooutils/mooaccelprefs.cpp\
|
||||
../moo/mooutils/mooaccelprefs.c\
|
||||
../moo/mooutils/mooaccelprefs.h\
|
||||
../moo/mooutils/mooactionbase.cpp\
|
||||
../moo/mooutils/mooactionbase.c\
|
||||
../moo/mooutils/mooactionbase.h\
|
||||
../moo/mooutils/mooactionbase-private.h\
|
||||
../moo/mooutils/mooaction.cpp\
|
||||
../moo/mooutils/mooactioncollection.cpp\
|
||||
../moo/mooutils/mooaction.c\
|
||||
../moo/mooutils/mooactioncollection.c\
|
||||
../moo/mooutils/mooactioncollection.h\
|
||||
../moo/mooutils/mooactionfactory.cpp\
|
||||
../moo/mooutils/mooactionfactory.c\
|
||||
../moo/mooutils/mooactionfactory.h\
|
||||
../moo/mooutils/mooactiongroup.cpp\
|
||||
../moo/mooutils/mooactiongroup.c\
|
||||
../moo/mooutils/mooactiongroup.h\
|
||||
../moo/mooutils/mooaction.h\
|
||||
../moo/mooutils/mooaction-private.h\
|
||||
../moo/mooutils/mooappinput-common.cpp\
|
||||
../moo/mooutils/mooappinput-common.c\
|
||||
../moo/mooutils/mooappinput.h\
|
||||
../moo/mooutils/mooapp-ipc.cpp\
|
||||
../moo/mooutils/mooapp-ipc.c\
|
||||
../moo/mooutils/mooapp-ipc.h\
|
||||
../moo/mooutils/mooarray.h\
|
||||
../moo/mooutils/mooatom.h\
|
||||
../moo/mooutils/moobigpaned.cpp\
|
||||
../moo/mooutils/moobigpaned.c\
|
||||
../moo/mooutils/moobigpaned.h\
|
||||
../moo/mooutils/mooclosure.cpp\
|
||||
../moo/mooutils/mooclosure.c\
|
||||
../moo/mooutils/mooclosure.h\
|
||||
../moo/mooutils/moocombo.cpp\
|
||||
../moo/mooutils/moocombo.c\
|
||||
../moo/mooutils/moocombo.h\
|
||||
../moo/mooutils/moocompat.h\
|
||||
../moo/mooutils/moodialogs.cpp\
|
||||
../moo/mooutils/moodialogs.c\
|
||||
../moo/mooutils/moodialogs.h\
|
||||
../moo/mooutils/mooeditops.cpp\
|
||||
../moo/mooutils/mooeditops.c\
|
||||
../moo/mooutils/mooeditops.h\
|
||||
../moo/mooutils/mooencodings.cpp\
|
||||
../moo/mooutils/mooencodings.c\
|
||||
../moo/mooutils/mooencodings-data.h\
|
||||
../moo/mooutils/mooencodings.h\
|
||||
../moo/mooutils/mooentry.cpp\
|
||||
../moo/mooutils/mooentry.c\
|
||||
../moo/mooutils/mooentry.h\
|
||||
../moo/mooutils/moo-environ.h\
|
||||
../moo/mooutils/moofiledialog.cpp\
|
||||
../moo/mooutils/moofiledialog.c\
|
||||
../moo/mooutils/moofiledialog.h\
|
||||
../moo/mooutils/moofileicon.cpp\
|
||||
../moo/mooutils/moofileicon.c\
|
||||
../moo/mooutils/moofileicon.h\
|
||||
../moo/mooutils/moofilewatch.cpp\
|
||||
../moo/mooutils/moofilewatch.c\
|
||||
../moo/mooutils/moofilewatch.h\
|
||||
../moo/mooutils/moofilewriter.cpp\
|
||||
../moo/mooutils/moofilewriter.c\
|
||||
../moo/mooutils/moofilewriter.h\
|
||||
../moo/mooutils/moofilewriter-private.h\
|
||||
../moo/mooutils/moofiltermgr.cpp\
|
||||
../moo/mooutils/moofiltermgr.c\
|
||||
../moo/mooutils/moofiltermgr.h\
|
||||
../moo/mooutils/moofontsel.c\
|
||||
../moo/mooutils/moofontsel.h\
|
||||
../moo/mooutils/mooglade.cpp\
|
||||
../moo/mooutils/mooglade.c\
|
||||
../moo/mooutils/mooglade.h\
|
||||
../moo/mooutils/moohelp.cpp\
|
||||
../moo/mooutils/moohelp.c\
|
||||
../moo/mooutils/moohelp.h\
|
||||
../moo/mooutils/moohistorycombo.cpp\
|
||||
../moo/mooutils/moohistorycombo.c\
|
||||
../moo/mooutils/moohistorycombo.h\
|
||||
../moo/mooutils/moohistorylist.cpp\
|
||||
../moo/mooutils/moohistorylist.c\
|
||||
../moo/mooutils/moohistorylist.h\
|
||||
../moo/mooutils/moohistorymgr.cpp\
|
||||
../moo/mooutils/moohistorymgr.c\
|
||||
../moo/mooutils/moohistorymgr.h\
|
||||
../moo/mooutils/mooi18n.cpp\
|
||||
../moo/mooutils/mooi18n.c\
|
||||
../moo/mooutils/mooi18n.h\
|
||||
../moo/mooutils/moolist.h\
|
||||
../moo/mooutils/moomarkup.cpp\
|
||||
../moo/mooutils/moomarkup.c\
|
||||
../moo/mooutils/moomarkup.h\
|
||||
../moo/mooutils/moomenuaction.cpp\
|
||||
../moo/mooutils/moomenuaction.c\
|
||||
../moo/mooutils/moomenuaction.h\
|
||||
../moo/mooutils/moomenu.cpp\
|
||||
../moo/mooutils/moomenu.c\
|
||||
../moo/mooutils/moomenu.h\
|
||||
../moo/mooutils/moomenumgr.cpp\
|
||||
../moo/mooutils/moomenumgr.c\
|
||||
../moo/mooutils/moomenumgr.h\
|
||||
../moo/mooutils/moomenutoolbutton.cpp\
|
||||
../moo/mooutils/moomenutoolbutton.c\
|
||||
../moo/mooutils/moomenutoolbutton.h\
|
||||
../moo/mooutils/moo-mime.cpp\
|
||||
../moo/mooutils/moo-mime.c\
|
||||
../moo/mooutils/moo-mime.h\
|
||||
../moo/mooutils/moonotebook.cpp\
|
||||
../moo/mooutils/moonotebook.c\
|
||||
../moo/mooutils/moonotebook.h\
|
||||
../moo/mooutils/mooonce.h\
|
||||
../moo/mooutils/moopane.cpp\
|
||||
../moo/mooutils/moopaned.cpp\
|
||||
../moo/mooutils/moopane.c\
|
||||
../moo/mooutils/moopaned.c\
|
||||
../moo/mooutils/moopaned.h\
|
||||
../moo/mooutils/moopane.h\
|
||||
../moo/mooutils/mooprefs.cpp\
|
||||
../moo/mooutils/mooprefsdialog.cpp\
|
||||
../moo/mooutils/mooprefs.c\
|
||||
../moo/mooutils/mooprefsdialog.c\
|
||||
../moo/mooutils/mooprefsdialog.h\
|
||||
../moo/mooutils/mooprefs.h\
|
||||
../moo/mooutils/mooprefspage.cpp\
|
||||
../moo/mooutils/mooprefspage.c\
|
||||
../moo/mooutils/mooprefspage.h\
|
||||
../moo/mooutils/moospawn.cpp\
|
||||
../moo/mooutils/moospawn.c\
|
||||
../moo/mooutils/moospawn.h\
|
||||
../moo/mooutils/moostock.cpp\
|
||||
../moo/mooutils/moostock.c\
|
||||
../moo/mooutils/moostock.h\
|
||||
../moo/mooutils/moo-test-macros.h\
|
||||
../moo/mooutils/moo-test-utils.cpp\
|
||||
../moo/mooutils/moo-test-utils.c\
|
||||
../moo/mooutils/moo-test-utils.h\
|
||||
../moo/mooutils/mootypedecl-macros.h\
|
||||
../moo/mooutils/mootype-macros.h\
|
||||
../moo/mooutils/moouixml.cpp\
|
||||
../moo/mooutils/moouixml.c\
|
||||
../moo/mooutils/moouixml.h\
|
||||
../moo/mooutils/mooundo.cpp\
|
||||
../moo/mooutils/mooundo.c\
|
||||
../moo/mooutils/mooundo.h\
|
||||
../moo/mooutils/mooutils-debug.h\
|
||||
../moo/mooutils/mooutils-enums.c\
|
||||
../moo/mooutils/mooutils-enums.h\
|
||||
../moo/mooutils/mooutils-file.cpp\
|
||||
../moo/mooutils/mooutils-file.c\
|
||||
../moo/mooutils/mooutils-file.h\
|
||||
../moo/mooutils/mooutils-fs.cpp\
|
||||
../moo/mooutils/mooutils-fs.c\
|
||||
../moo/mooutils/mooutils-fs.h\
|
||||
../moo/mooutils/mooutils-gobject.cpp\
|
||||
../moo/mooutils/mooutils-gobject.c\
|
||||
../moo/mooutils/mooutils-gobject.h\
|
||||
../moo/mooutils/mooutils-gobject-private.h\
|
||||
../moo/mooutils/mooutils.h\
|
||||
../moo/mooutils/mooutils-macros.h\
|
||||
../moo/mooutils/mooutils-mem.h\
|
||||
../moo/mooutils/mooutils-messages.h\
|
||||
../moo/mooutils/mooutils-misc.cpp\
|
||||
../moo/mooutils/mooutils-misc.c\
|
||||
../moo/mooutils/mooutils-misc.h\
|
||||
../moo/mooutils/mooutils-script.cpp\
|
||||
../moo/mooutils/mooutils-script.c\
|
||||
../moo/mooutils/mooutils-script.h\
|
||||
../moo/mooutils/mooutils-tests.h\
|
||||
../moo/mooutils/mooutils-thread.cpp\
|
||||
../moo/mooutils/mooutils-thread.c\
|
||||
../moo/mooutils/mooutils-thread.h\
|
||||
../moo/mooutils/mooutils-treeview.cpp\
|
||||
../moo/mooutils/mooutils-treeview.c\
|
||||
../moo/mooutils/mooutils-treeview.h\
|
||||
../moo/mooutils/mooutils-win32.cpp\
|
||||
../moo/mooutils/mooutils-win32.c\
|
||||
../moo/mooutils/moowin32/mingw/fnmatch.h\
|
||||
../moo/mooutils/moowin32/mingw/netinet/in.h\
|
||||
../moo/mooutils/moowin32/ms/sys/time.h\
|
||||
../moo/mooutils/moowin32/ms/unistd.h\
|
||||
../moo/mooutils/moowindow.cpp\
|
||||
../moo/mooutils/moowindow.c\
|
||||
../moo/mooutils/moowindow.h\
|
||||
../moo/plugins/support/moocmdview.c\
|
||||
../moo/plugins/support/moocmdview.h\
|
||||
|
|
|
@ -1,222 +0,0 @@
|
|||
# Function for setting up precompiled headers. Usage:
|
||||
#
|
||||
# add_library/executable(target
|
||||
# pchheader.c pchheader.cpp pchheader.h)
|
||||
#
|
||||
# add_precompiled_header(target pchheader.h
|
||||
# [FORCEINCLUDE]
|
||||
# [SOURCE_C pchheader.c]
|
||||
# [SOURCE_CXX pchheader.cpp])
|
||||
#
|
||||
# Options:
|
||||
#
|
||||
# FORCEINCLUDE: Add compiler flags to automatically include the
|
||||
# pchheader.h from every source file. Works with both GCC and
|
||||
# MSVC. This is recommended.
|
||||
#
|
||||
# SOURCE_C/CXX: Specifies the .c/.cpp source file that includes
|
||||
# pchheader.h for generating the pre-compiled header
|
||||
# output. Defaults to pchheader.c. Only required for MSVC.
|
||||
#
|
||||
# Caveats:
|
||||
#
|
||||
# * Its not currently possible to use the same precompiled-header in
|
||||
# more than a single target in the same directory (No way to set
|
||||
# the source file properties differently for each target).
|
||||
#
|
||||
# * MSVC: A source file with the same name as the header must exist
|
||||
# and be included in the target (E.g. header.cpp). Name of file
|
||||
# can be changed using the SOURCE_CXX/SOURCE_C options.
|
||||
#
|
||||
# License:
|
||||
#
|
||||
# Copyright (C) 2009-2013 Lars Christensen <larsch@belunktum.dk>
|
||||
#
|
||||
# Permission is hereby granted, free of charge, to any person
|
||||
# obtaining a copy of this software and associated documentation files
|
||||
# (the 'Software') deal in the Software without restriction,
|
||||
# including without limitation the rights to use, copy, modify, merge,
|
||||
# publish, distribute, sublicense, and/or sell copies of the Software,
|
||||
# and to permit persons to whom the Software is furnished to do so,
|
||||
# subject to the following conditions:
|
||||
#
|
||||
# The above copyright notice and this permission notice shall be
|
||||
# included in all copies or substantial portions of the Software.
|
||||
#
|
||||
# THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND,
|
||||
# EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
||||
# MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
||||
# NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS
|
||||
# BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
|
||||
# ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
|
||||
# CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
# SOFTWARE.
|
||||
|
||||
include(CMakeParseArguments)
|
||||
|
||||
macro(combine_arguments _variable)
|
||||
set(_result "")
|
||||
foreach(_element ${${_variable}})
|
||||
set(_result "${_result} \"${_element}\"")
|
||||
endforeach()
|
||||
string(STRIP "${_result}" _result)
|
||||
set(${_variable} "${_result}")
|
||||
endmacro()
|
||||
|
||||
function(export_all_flags _filename)
|
||||
set(_include_directories "$<TARGET_PROPERTY:${_target},INCLUDE_DIRECTORIES>")
|
||||
set(_compile_definitions "$<TARGET_PROPERTY:${_target},COMPILE_DEFINITIONS>")
|
||||
set(_compile_flags "$<TARGET_PROPERTY:${_target},COMPILE_FLAGS>")
|
||||
set(_compile_options "$<TARGET_PROPERTY:${_target},COMPILE_OPTIONS>")
|
||||
set(_include_directories "$<$<BOOL:${_include_directories}>:-I$<JOIN:${_include_directories},\n-I>\n>")
|
||||
set(_compile_definitions "$<$<BOOL:${_compile_definitions}>:-D$<JOIN:${_compile_definitions},\n-D>\n>")
|
||||
set(_compile_flags "$<$<BOOL:${_compile_flags}>:$<JOIN:${_compile_flags},\n>\n>")
|
||||
set(_compile_options "$<$<BOOL:${_compile_options}>:$<JOIN:${_compile_options},\n>\n>")
|
||||
file(GENERATE OUTPUT "${_filename}" CONTENT "${_compile_definitions}${_include_directories}${_compile_flags}${_compile_options}\n")
|
||||
endfunction()
|
||||
|
||||
function(add_precompiled_header _target _input)
|
||||
cmake_parse_arguments(_PCH "FORCEINCLUDE" "SOURCE_CXX:SOURCE_C" "" ${ARGN})
|
||||
|
||||
get_filename_component(_input_we ${_input} NAME_WE)
|
||||
if(NOT _PCH_SOURCE_CXX)
|
||||
set(_PCH_SOURCE_CXX "${_input_we}.cpp")
|
||||
endif()
|
||||
if(NOT _PCH_SOURCE_C)
|
||||
set(_PCH_SOURCE_C "${_input_we}.c")
|
||||
endif()
|
||||
|
||||
if(MSVC)
|
||||
|
||||
set(_cxx_path "${CMAKE_CFG_INTDIR}/${_target}_cxx_pch")
|
||||
set(_c_path "${CMAKE_CFG_INTDIR}/${_target}_c_pch")
|
||||
make_directory("${_cxx_path}")
|
||||
make_directory("${_c_path}")
|
||||
set(_pch_cxx_header "${_cxx_path}/${_input}")
|
||||
set(_pch_cxx_pch "${_cxx_path}/${_input_we}.pch")
|
||||
set(_pch_c_header "${_c_path}/${_input}")
|
||||
set(_pch_c_pch "${_c_path}/${_input_we}.pch")
|
||||
|
||||
get_target_property(sources ${_target} SOURCES)
|
||||
foreach(_source ${sources})
|
||||
set(_pch_compile_flags "")
|
||||
if(_source MATCHES \\.\(cc|cxx|cpp|c\)$)
|
||||
if(_source MATCHES \\.\(cpp|cxx|cc\)$)
|
||||
set(_pch_header "${_input}")
|
||||
set(_pch "${_pch_cxx_pch}")
|
||||
else()
|
||||
set(_pch_header "${_input}")
|
||||
set(_pch "${_pch_c_pch}")
|
||||
endif()
|
||||
|
||||
if(_source STREQUAL "${_PCH_SOURCE_CXX}")
|
||||
set(_pch_compile_flags "${_pch_compile_flags} \"/Fp${_pch_cxx_pch}\" /Yc${_input}")
|
||||
set(_pch_source_cxx_found TRUE)
|
||||
elseif(_source STREQUAL "${_PCH_SOURCE_C}")
|
||||
set(_pch_compile_flags "${_pch_compile_flags} \"/Fp${_pch_c_pch}\" /Yc${_input}")
|
||||
set(_pch_source_c_found TRUE)
|
||||
else()
|
||||
if(_source MATCHES \\.\(cpp|cxx|cc\)$)
|
||||
set(_pch_compile_flags "${_pch_compile_flags} \"/Fp${_pch_cxx_pch}\" /Yu${_input}")
|
||||
set(_pch_source_cxx_needed TRUE)
|
||||
else()
|
||||
set(_pch_compile_flags "${_pch_compile_flags} \"/Fp${_pch_c_pch}\" /Yu${_input}")
|
||||
set(_pch_source_c_needed TRUE)
|
||||
endif()
|
||||
if(_PCH_FORCEINCLUDE)
|
||||
set(_pch_compile_flags "${_pch_compile_flags} /FI${_input}")
|
||||
endif(_PCH_FORCEINCLUDE)
|
||||
endif()
|
||||
|
||||
get_source_file_property(_object_depends "${_source}" OBJECT_DEPENDS)
|
||||
if(NOT _object_depends)
|
||||
set(_object_depends)
|
||||
endif()
|
||||
if(_PCH_FORCEINCLUDE)
|
||||
if(_source MATCHES \\.\(cc|cxx|cpp\)$)
|
||||
list(APPEND _object_depends "${_pch_header}")
|
||||
else()
|
||||
list(APPEND _object_depends "${_pch_header}")
|
||||
endif()
|
||||
endif()
|
||||
|
||||
set_source_files_properties(${_source} PROPERTIES
|
||||
COMPILE_FLAGS "${_pch_compile_flags}"
|
||||
OBJECT_DEPENDS "${_object_depends}")
|
||||
endif()
|
||||
endforeach()
|
||||
|
||||
if(_pch_source_cxx_needed AND NOT _pch_source_cxx_found)
|
||||
message(FATAL_ERROR "A source file ${_PCH_SOURCE_CXX} for ${_input} is required for MSVC builds. Can be set with the SOURCE_CXX option.")
|
||||
endif()
|
||||
if(_pch_source_c_needed AND NOT _pch_source_c_found)
|
||||
message(FATAL_ERROR "A source file ${_PCH_SOURCE_C} for ${_input} is required for MSVC builds. Can be set with the SOURCE_C option.")
|
||||
endif()
|
||||
endif(MSVC)
|
||||
|
||||
if(CMAKE_COMPILER_IS_GNUCXX)
|
||||
get_filename_component(_name ${_input} NAME)
|
||||
set(_pch_header "${CMAKE_CURRENT_SOURCE_DIR}/${_input}")
|
||||
set(_pch_binary_dir "${CMAKE_CURRENT_BINARY_DIR}/${_target}_pch")
|
||||
set(_pchfile "${_pch_binary_dir}/${_input}")
|
||||
set(_outdir "${CMAKE_CURRENT_BINARY_DIR}/${_target}_pch/${_name}.gch")
|
||||
make_directory(${_outdir})
|
||||
set(_output_cxx "${_outdir}/.c++")
|
||||
set(_output_c "${_outdir}/.c")
|
||||
|
||||
set(_pch_flags_file "${_pch_binary_dir}/compile_flags.rsp")
|
||||
export_all_flags("${_pch_flags_file}")
|
||||
set(_compiler_FLAGS "@${_pch_flags_file}")
|
||||
add_custom_command(
|
||||
OUTPUT "${_pchfile}"
|
||||
COMMAND "${CMAKE_COMMAND}" -E copy "${_pch_header}" "${_pchfile}"
|
||||
DEPENDS "${_pch_header}"
|
||||
COMMENT "Updating ${_name}")
|
||||
add_custom_command(
|
||||
OUTPUT "${_output_cxx}"
|
||||
COMMAND "${CMAKE_CXX_COMPILER}" ${_compiler_FLAGS} -x c++-header -o "${_output_cxx}" "${_pchfile}"
|
||||
DEPENDS "${_pchfile}" "${_pch_flags_file}"
|
||||
COMMENT "Precompiling ${_name} for ${_target} (C++)")
|
||||
add_custom_command(
|
||||
OUTPUT "${_output_c}"
|
||||
COMMAND "${CMAKE_C_COMPILER}" ${_compiler_FLAGS} -x c-header -o "${_output_c}" "${_pchfile}"
|
||||
DEPENDS "${_pchfile}" "${_pch_flags_file}"
|
||||
COMMENT "Precompiling ${_name} for ${_target} (C)")
|
||||
|
||||
get_property(_sources TARGET ${_target} PROPERTY SOURCES)
|
||||
foreach(_source ${_sources})
|
||||
set(_pch_compile_flags "")
|
||||
|
||||
if(_source MATCHES \\.\(cc|cxx|cpp|c\)$)
|
||||
get_source_file_property(_pch_compile_flags "${_source}" COMPILE_FLAGS)
|
||||
if(NOT _pch_compile_flags)
|
||||
set(_pch_compile_flags)
|
||||
endif()
|
||||
separate_arguments(_pch_compile_flags)
|
||||
list(APPEND _pch_compile_flags -Winvalid-pch)
|
||||
if(_PCH_FORCEINCLUDE)
|
||||
list(APPEND _pch_compile_flags -include "${_pchfile}")
|
||||
else(_PCH_FORCEINCLUDE)
|
||||
list(APPEND _pch_compile_flags "-I${_pch_binary_dir}")
|
||||
endif(_PCH_FORCEINCLUDE)
|
||||
|
||||
get_source_file_property(_object_depends "${_source}" OBJECT_DEPENDS)
|
||||
if(NOT _object_depends)
|
||||
set(_object_depends)
|
||||
endif()
|
||||
list(APPEND _object_depends "${_pchfile}")
|
||||
if(_source MATCHES \\.\(cc|cxx|cpp\)$)
|
||||
list(APPEND _object_depends "${_output_cxx}")
|
||||
else()
|
||||
list(APPEND _object_depends "${_output_c}")
|
||||
endif()
|
||||
|
||||
combine_arguments(_pch_compile_flags)
|
||||
message("${_source}" ${_pch_compile_flags})
|
||||
set_source_files_properties(${_source} PROPERTIES
|
||||
COMPILE_FLAGS "${_pch_compile_flags}"
|
||||
OBJECT_DEPENDS "${_object_depends}")
|
||||
endif()
|
||||
endforeach()
|
||||
endif(CMAKE_COMPILER_IS_GNUCXX)
|
||||
endfunction()
|
|
@ -1,48 +1,30 @@
|
|||
#pragma once
|
||||
|
||||
#define MOO_PACKAGE_NAME "@MOO_PACKAGE_NAME@"
|
||||
|
||||
#define MOO_WEBSITE "@MOO_WEBSITE@"
|
||||
#define MOO_WEB_CONTACT "@MOO_WEB_CONTACT@"
|
||||
#define MOO_EMAIL "@MOO_EMAIL@"
|
||||
#define MOO_COPYRIGHT "@MOO_COPYRIGHT@"
|
||||
#define PACKAGE_BUGREPORT "@MOO_EMAIL@"
|
||||
|
||||
#define GETTEXT_PACKAGE "@GETTEXT_PACKAGE@"
|
||||
|
||||
#define MOO_PREFS_XML_FILE_NAME "@MOO_PREFS_XML_FILE_NAME@"
|
||||
#define MOO_STATE_XML_FILE_NAME "@MOO_STATE_XML_FILE_NAME@"
|
||||
#define MOO_NAMED_SESSION_XML_FILE_NAME "@MOO_NAMED_SESSION_XML_FILE_NAME@"
|
||||
#define MOO_SESSION_XML_FILE_NAME "@MOO_SESSION_XML_FILE_NAME@"
|
||||
|
||||
#define MEDIT_PORTABLE_DATA_DIR "@MEDIT_PORTABLE_DATA_DIR@"
|
||||
#define MEDIT_PORTABLE_CACHE_DIR "@MEDIT_PORTABLE_CACHE_DIR@"
|
||||
#define MEDIT_PORTABLE_MAGIC_FILE_NAME "@MEDIT_PORTABLE_MAGIC_FILE_NAME@"
|
||||
|
||||
#define MOO_VERSION "@MOO_VERSION@"
|
||||
#define MOO_DISPLAY_VERSION "@MOO_DISPLAY_VERSION@"
|
||||
#define MOO_MAJOR_VERSION @MOO_MAJOR_VERSION@
|
||||
#define MOO_MICRO_VERSION @MOO_MICRO_VERSION@
|
||||
#define MOO_MINOR_VERSION @MOO_MINOR_VERSION@
|
||||
#define MOO_MODULE_MAJOR_VERSION @MOO_MODULE_MAJOR_VERSION@
|
||||
#define MOO_MODULE_MINOR_VERSION @MOO_MODULE_MINOR_VERSION@
|
||||
|
||||
#cmakedefine MOO_BUILD_FROM_MINGW 1
|
||||
#cmakedefine MOO_BUILD_FROM_MSVC 1
|
||||
|
||||
#cmakedefine MOO_BUILD_CTAGS 1
|
||||
#cmakedefine MOO_ENABLE_COVERAGE 1
|
||||
#cmakedefine MOO_ENABLE_PYTHON 1
|
||||
#cmakedefine MOO_BROKEN_GTK_THEME 1
|
||||
#cmakedefine MOO_NEED_GETTIMEOFDAY 1
|
||||
|
||||
#cmakedefine ENABLE_NLS 1
|
||||
#cmakedefine HAVE_BIND_TEXTDOMAIN_CODESET 1
|
||||
#cmakedefine HAVE_GETC_UNLOCKED 1
|
||||
#cmakedefine HAVE_MMAP 1
|
||||
#cmakedefine HAVE_UNISTD_H 1
|
||||
#cmakedefine HAVE_SYS_UTSNAME_H 1
|
||||
#cmakedefine HAVE_SIGNAL_H 1
|
||||
#cmakedefine HAVE_SYS_WAIT_H 1
|
||||
|
||||
#include <moo-config.h>
|
||||
#pragma once
|
||||
|
||||
#define MOO_PACKAGE_NAME "@MOO_PACKAGE_NAME@"
|
||||
|
||||
#define MOO_DISPLAY_VERSION "@MOO_DISPLAY_VERSION@"
|
||||
|
||||
#define MOO_WEBSITE "@MOO_WEBSITE@"
|
||||
#define MOO_WEB_CONTACT "@MOO_WEB_CONTACT@"
|
||||
#define MOO_EMAIL "@MOO_EMAIL@"
|
||||
#define MOO_COPYRIGHT "@MOO_COPYRIGHT@"
|
||||
#define PACKAGE_BUGREPORT "@MOO_EMAIL@"
|
||||
|
||||
#define GETTEXT_PACKAGE "@GETTEXT_PACKAGE@"
|
||||
|
||||
#define MOO_PREFS_XML_FILE_NAME "@MOO_PREFS_XML_FILE_NAME@"
|
||||
#define MOO_STATE_XML_FILE_NAME "@MOO_STATE_XML_FILE_NAME@"
|
||||
#define MOO_NAMED_SESSION_XML_FILE_NAME "@MOO_NAMED_SESSION_XML_FILE_NAME@"
|
||||
#define MOO_SESSION_XML_FILE_NAME "@MOO_SESSION_XML_FILE_NAME@"
|
||||
|
||||
#define MEDIT_PORTABLE_DATA_DIR "@MEDIT_PORTABLE_DATA_DIR@"
|
||||
#define MEDIT_PORTABLE_CACHE_DIR "@MEDIT_PORTABLE_CACHE_DIR@"
|
||||
#define MEDIT_PORTABLE_MAGIC_FILE_NAME "@MEDIT_PORTABLE_MAGIC_FILE_NAME@"
|
||||
|
||||
#define MOO_VERSION "@MOO_VERSION@"
|
||||
#define MOO_DISPLAY_VERSION "@MOO_DISPLAY_VERSION@"
|
||||
#define MOO_MAJOR_VERSION @MOO_MAJOR_VERSION@
|
||||
#define MOO_MICRO_VERSION @MOO_MICRO_VERSION@
|
||||
#define MOO_MINOR_VERSION @MOO_MINOR_VERSION@
|
||||
#define MOO_MODULE_MAJOR_VERSION @MOO_MODULE_MAJOR_VERSION@
|
||||
#define MOO_MODULE_MINOR_VERSION @MOO_MODULE_MINOR_VERSION@
|
||||
|
|
13
configure.ac
13
configure.ac
|
@ -85,8 +85,10 @@ if test x$MOO_DEV_MODE = "xyes" -a "x$XSLTPROC" = "x"; then
|
|||
fi
|
||||
|
||||
AC_CONFIG_HEADERS([config.h])
|
||||
AH_TOP([#pragma once])
|
||||
AH_BOTTOM([#include <moo-config.h>])
|
||||
AH_TOP([#ifndef __CONFIG_H__
|
||||
#define __CONFIG_H__])
|
||||
AH_BOTTOM([#include <moo-config.h>
|
||||
#endif // __CONFIG_H__])
|
||||
|
||||
MOO_LT_LIB_M
|
||||
|
||||
|
@ -124,6 +126,13 @@ if $MOO_BUILD_MODULE; then
|
|||
fi
|
||||
fi
|
||||
|
||||
if $MOO_BUILD_APP; then
|
||||
AC_DEFINE(MOO_BUILD_APP, 1, [build medit application])
|
||||
fi
|
||||
if $MOO_BUILD_MODULE; then
|
||||
AC_DEFINE(MOO_BUILD_MODULE, 1, [build standalone python module])
|
||||
fi
|
||||
|
||||
AM_CONDITIONAL(MOO_BUILD_APP, [$MOO_BUILD_APP])
|
||||
AM_CONDITIONAL(MOO_BUILD_MODULE, [$MOO_BUILD_MODULE])
|
||||
|
||||
|
|
|
@ -194,6 +194,8 @@ AC_DEFUN_ONCE([MOO_AC_FLAGS],[
|
|||
|
||||
AC_CHECK_FUNCS(mmap)
|
||||
|
||||
AC_DEFINE(MOO_COMPILATION, 1, [must be 1])
|
||||
|
||||
moo_top_src_dir=`cd $srcdir && pwd`
|
||||
MOO_CFLAGS="$MOO_CFLAGS $GTK_CFLAGS"
|
||||
MOO_CXXFLAGS="$MOO_CXXFLAGS $GTK_CFLAGS"
|
||||
|
|
|
@ -24,7 +24,6 @@ AC_DEFUN([MOO_INTL],[
|
|||
AC_SUBST([ENABLE_NLS])
|
||||
if test "$ENABLE_NLS" = "yes"; then
|
||||
_MOO_INTLTOOL
|
||||
AC_DEFINE(ENABLE_NLS, 1)
|
||||
else
|
||||
_MOO_INTLTOOL_NO_NLS
|
||||
fi
|
||||
|
|
|
@ -1,199 +1,170 @@
|
|||
FILE(WRITE ${CMAKE_CURRENT_BINARY_DIR}/genmarshals_h.cmake
|
||||
"EXECUTE_PROCESS(COMMAND ${GLIB_GENMARSHAL} --prefix=_moo_marshal --header ${CMAKE_CURRENT_SOURCE_DIR}/marshals.list
|
||||
RESULT_VARIABLE result
|
||||
OUTPUT_VARIABLE output
|
||||
ERROR_VARIABLE error
|
||||
OUTPUT_FILE marshals.h.tmp)
|
||||
if(NOT result EQUAL 0)
|
||||
MESSAGE(FATAL_ERROR \"Error generating marshals.h: \${output} \${error}\")
|
||||
endif()
|
||||
file(RENAME marshals.h.tmp marshals.h)
|
||||
")
|
||||
add_custom_command(OUTPUT marshals.h
|
||||
COMMAND ${CMAKE_COMMAND} -P genmarshals_h.cmake
|
||||
MAIN_DEPENDENCY marshals.list)
|
||||
LIST(APPEND built_moo_sources marshals.h)
|
||||
|
||||
macro(ADD_GXML input)
|
||||
string(REPLACE ".glade" "-gxml.h" _gxml_output "${input}")
|
||||
string(REPLACE "/glade/" "/" _gxml_output "${_gxml_output}")
|
||||
#message(STATUS "_gxml_output: ${_gxml_output}")
|
||||
add_custom_command(OUTPUT ${_gxml_output}
|
||||
COMMAND ${MOO_PYTHON} ${CMAKE_SOURCE_DIR}/tools/glade2c.py --output=${_gxml_output} ${CMAKE_CURRENT_SOURCE_DIR}/${input}
|
||||
MAIN_DEPENDENCY ${input}
|
||||
DEPENDS ${CMAKE_SOURCE_DIR}/tools/glade2c.py
|
||||
COMMENT "Generating ${_gxml_output} from ${input}")
|
||||
list(APPEND built_moo_sources ${_gxml_output})
|
||||
endmacro(ADD_GXML)
|
||||
|
||||
macro(XML2H _xml2h_input _xml2h_output _xml2h_variable)
|
||||
add_custom_command(OUTPUT ${_xml2h_output}
|
||||
COMMAND ${MOO_PYTHON} ${CMAKE_SOURCE_DIR}/tools/xml2h.py ${CMAKE_CURRENT_SOURCE_DIR}/${_xml2h_input} ${_xml2h_output} ${_xml2h_variable}
|
||||
MAIN_DEPENDENCY ${_xml2h_input}
|
||||
DEPENDS ${CMAKE_SOURCE_DIR}/tools/xml2h.py
|
||||
COMMENT "Generating ${_xml2h_output} from ${_xml2h_input}")
|
||||
list(APPEND built_moo_sources ${_xml2h_output})
|
||||
endmacro(XML2H)
|
||||
|
||||
macro(ADD_UI input)
|
||||
string(REPLACE ".xml" "-ui.h" _ui_output "${input}")
|
||||
# message(STATUS "_ui_output: ${_ui_output}")
|
||||
string(REGEX REPLACE ".*/([^/]*)\\.xml" "\\1" _ui_variable "${input}")
|
||||
XML2H(${input} ${_ui_output} ${_ui_variable}_ui_xml)
|
||||
endmacro(ADD_UI)
|
||||
|
||||
file(MAKE_DIRECTORY
|
||||
${CMAKE_CURRENT_BINARY_DIR}/mooapp
|
||||
${CMAKE_CURRENT_BINARY_DIR}/mooedit
|
||||
${CMAKE_CURRENT_BINARY_DIR}/moofileview
|
||||
${CMAKE_CURRENT_BINARY_DIR}/mooutils
|
||||
${CMAKE_CURRENT_BINARY_DIR}/moolua
|
||||
${CMAKE_CURRENT_BINARY_DIR}/plugins/usertools
|
||||
${CMAKE_CURRENT_BINARY_DIR}/medit-app
|
||||
)
|
||||
|
||||
include_directories(${PROJECT_SOURCE_DIR}/moo/mooutils/moowin32/ms)
|
||||
|
||||
include_directories(
|
||||
${PROJECT_BINARY_DIR}
|
||||
${GTK_INCLUDE_DIRS}
|
||||
${LIBXML2_INCLUDE_DIRS}
|
||||
)
|
||||
link_directories(${GTK_LIBRARY_DIRS} ${GMODULE_LIBRARY_DIRS})
|
||||
|
||||
include(xdgmime/xdgmime.cmake)
|
||||
include(mooutils/mooutils.cmake)
|
||||
include(moocpp/moocpp.cmake)
|
||||
#include(moogpp/moogpp.cmake)
|
||||
include(mooedit/mooedit.cmake)
|
||||
include(moofileview/moofileview.cmake)
|
||||
include(gtksourceview/gtksourceview.cmake)
|
||||
if(NOT MOO_OS_WIN32)
|
||||
include(eggsmclient/eggsmclient.cmake)
|
||||
endif()
|
||||
include(mooapp/mooapp.cmake)
|
||||
include(moolua/moolua.cmake)
|
||||
if(MOO_ENABLE_PYTHON)
|
||||
include(moopython/moopython.cmake)
|
||||
endif()
|
||||
include(plugins/plugins.cmake)
|
||||
include(medit-app/medit-app.cmake)
|
||||
|
||||
SET(MEDIT_SOURCES
|
||||
CMakeLists.txt
|
||||
${moo_sources}
|
||||
${built_moo_sources}
|
||||
)
|
||||
|
||||
macro(ADD_MODULE name)
|
||||
string(REPLACE "-" "_" _escaped_name "${name}")
|
||||
source_group(${name} FILES ${${_escaped_name}_sources} ${${_escaped_name}_extra_files})
|
||||
source_group(${name}\\generated FILES ${built_${_escaped_name}_sources})
|
||||
#source_group(${name} FILES ${${_escaped_name}_sources} ${${_escaped_name}_extra_files})
|
||||
#source_group(${name}\\generated FILES ${built_${_escaped_name}_sources})
|
||||
LIST(APPEND MEDIT_SOURCES ${${_escaped_name}_sources} ${built_${_escaped_name}_sources})
|
||||
LIST(APPEND MEDIT_EXTRA_DIST ${${_escaped_name}_extra_dist} ${${_escaped_name}_extra_files})
|
||||
endmacro(ADD_MODULE)
|
||||
|
||||
ADD_MODULE(xdgmime)
|
||||
ADD_MODULE(eggsmclient)
|
||||
ADD_MODULE(gtksourceview)
|
||||
ADD_MODULE(mooutils)
|
||||
ADD_MODULE(moofileview)
|
||||
ADD_MODULE(mooedit)
|
||||
ADD_MODULE(mooapp)
|
||||
ADD_MODULE(plugins)
|
||||
ADD_MODULE(moolua)
|
||||
ADD_MODULE(moocpp)
|
||||
ADD_MODULE(moogpp)
|
||||
if(MOO_ENABLE_PYTHON)
|
||||
ADD_MODULE(moopython)
|
||||
endif()
|
||||
ADD_MODULE(medit-app)
|
||||
|
||||
source_group(moo REGULAR_EXPRESSION .*)
|
||||
source_group("generated\\sources" REGULAR_EXPRESSION ".*\\.c(pp)?$")
|
||||
source_group("generated\\headers" REGULAR_EXPRESSION ".*\\.h$")
|
||||
source_group("moo\\glade" REGULAR_EXPRESSION ".*\\.glade$")
|
||||
|
||||
set(MOO_USE_PCH TRUE)
|
||||
if(MOO_USE_PCH)
|
||||
set(MEDIT_PCH_SOURCES
|
||||
moo-pch.c
|
||||
moo-pch.cpp
|
||||
moo-pch.h
|
||||
)
|
||||
endif()
|
||||
|
||||
add_executable(medit WIN32
|
||||
${MEDIT_SOURCES}
|
||||
${MEDIT_PCH_SOURCES}
|
||||
)
|
||||
|
||||
if(MOO_USE_PCH)
|
||||
add_precompiled_header(medit
|
||||
moo-pch.h
|
||||
FORCEINCLUDE
|
||||
SOURCE_C moo-pch.c
|
||||
SOURCE_CXX moo-pch.cpp)
|
||||
endif()
|
||||
|
||||
if(MOO_BUILD_FROM_MINGW)
|
||||
LIST(APPEND MEDIT_LIBS libmooglib-0)
|
||||
endif()
|
||||
|
||||
target_link_libraries(medit
|
||||
${GTK_LIBRARIES}
|
||||
${GMODULE_LIBRARIES}
|
||||
${LIBXML2_LIBRARIES}
|
||||
${XLIB_LIBRARIES}
|
||||
#${LIBM}
|
||||
${PYTHON_LIBRARY}
|
||||
${moo_libadd}
|
||||
${MEDIT_LIBS}
|
||||
)
|
||||
|
||||
install(TARGETS medit RUNTIME DESTINATION bin)
|
||||
|
||||
if(MOO_BUILD_FROM_MINGW)
|
||||
# xxx this is wrong, doing it temporarily so it doesn't install python lib every time
|
||||
if(NOT EXISTS "${MOO_GTK_DIST_DIR}/bin/libglib-2.0-0.dll")
|
||||
install(DIRECTORY ${MOO_GTK_DIST_DIR}/bin DESTINATION ${CMAKE_INSTALL_PREFIX})
|
||||
install(DIRECTORY ${MOO_GTK_DIST_DIR}/etc DESTINATION ${CMAKE_INSTALL_PREFIX})
|
||||
install(DIRECTORY ${MOO_GTK_DIST_DIR}/lib DESTINATION ${CMAKE_INSTALL_PREFIX})
|
||||
install(DIRECTORY ${MOO_GTK_DIST_DIR}/share DESTINATION ${CMAKE_INSTALL_PREFIX})
|
||||
endif()
|
||||
|
||||
#install(DIRECTORY ${CMAKE_SOURCE_DIR}/plat/win32/gtk-win/extra/medit-data/bin DESTINATION ${CMAKE_INSTALL_PREFIX})
|
||||
#install(DIRECTORY ${CMAKE_SOURCE_DIR}/plat/win32/gtk-win/extra/medit-data/etc DESTINATION ${CMAKE_INSTALL_PREFIX})
|
||||
endif()
|
||||
|
||||
# zzz
|
||||
# if MOO_OS_UNIX
|
||||
# desktopdir = $(datadir)/applications
|
||||
# desktop_DATA = medit-app/medit.desktop
|
||||
# medit-app/medit.desktop: medit-app/medit.desktop.in @MOO_INTLTOOL_INI_DEPS@
|
||||
# $(AM_V_at)$(MKDIR_P) medit-app
|
||||
# @MOO_INTLTOOL_INI_CMD@
|
||||
# CLEANFILES += medit-app/medit.desktop
|
||||
# endif MOO_OS_UNIX
|
||||
|
||||
# zzz
|
||||
# iconthemedir = $(datadir)/icons/hicolor/48x48/apps
|
||||
# icontheme_DATA = mooutils/pixmaps/medit.png
|
||||
# if MOO_ENABLE_INSTALL_HOOKS
|
||||
# update_icon_cache = gtk-update-icon-cache -f -t $(DESTDIR)$(datadir)/icons/hicolor
|
||||
# install-data-hook: install-data-hook-gtk-icon-cache
|
||||
# install-data-hook-gtk-icon-cache:
|
||||
# @if echo "Updating icon cache" && $(update_icon_cache); then
|
||||
# echo "Done.";
|
||||
# else
|
||||
# echo "*** GTK icon cache not updated. After install, run this:";\
|
||||
# echo $(update_icon_cache);
|
||||
# fi
|
||||
# uninstall-hook: uninstall-data-hook-gtk-icon-cache
|
||||
# uninstall-data-hook-gtk-icon-cache:
|
||||
# @if echo "Updating icon cache" && $(update_icon_cache); then echo "Done."; else echo "Failed."; fi
|
||||
# endif
|
||||
|
||||
# zzz include medit-module/Makefile.incl
|
||||
FILE(WRITE ${CMAKE_CURRENT_BINARY_DIR}/genmarshals_h.cmake
|
||||
"EXECUTE_PROCESS(COMMAND ${GLIB_GENMARSHAL} --prefix=_moo_marshal --header ${CMAKE_CURRENT_SOURCE_DIR}/marshals.list
|
||||
RESULT_VARIABLE result
|
||||
OUTPUT_VARIABLE output
|
||||
ERROR_VARIABLE error
|
||||
OUTPUT_FILE marshals.h.tmp)
|
||||
if(NOT result EQUAL 0)
|
||||
MESSAGE(FATAL_ERROR \"Error generating marshals.h: \${output} \${error}\")
|
||||
endif()
|
||||
file(RENAME marshals.h.tmp marshals.h)
|
||||
")
|
||||
add_custom_command(OUTPUT marshals.h
|
||||
COMMAND ${CMAKE_COMMAND} -P genmarshals_h.cmake
|
||||
MAIN_DEPENDENCY marshals.list)
|
||||
LIST(APPEND built_moo_sources marshals.h)
|
||||
|
||||
macro(ADD_GXML input)
|
||||
string(REPLACE ".glade" "-gxml.h" _gxml_output "${input}")
|
||||
string(REPLACE "/glade/" "/" _gxml_output "${_gxml_output}")
|
||||
#message(STATUS "_gxml_output: ${_gxml_output}")
|
||||
add_custom_command(OUTPUT ${_gxml_output}
|
||||
COMMAND ${MOO_PYTHON} ${CMAKE_SOURCE_DIR}/tools/glade2c.py --output=${_gxml_output} ${CMAKE_CURRENT_SOURCE_DIR}/${input}
|
||||
MAIN_DEPENDENCY ${input}
|
||||
DEPENDS ${CMAKE_SOURCE_DIR}/tools/glade2c.py
|
||||
COMMENT "Generating ${_gxml_output} from ${input}")
|
||||
list(APPEND built_moo_sources ${_gxml_output})
|
||||
endmacro(ADD_GXML)
|
||||
|
||||
macro(XML2H _xml2h_input _xml2h_output _xml2h_variable)
|
||||
add_custom_command(OUTPUT ${_xml2h_output}
|
||||
COMMAND ${MOO_PYTHON} ${CMAKE_SOURCE_DIR}/tools/xml2h.py ${CMAKE_CURRENT_SOURCE_DIR}/${_xml2h_input} ${_xml2h_output} ${_xml2h_variable}
|
||||
MAIN_DEPENDENCY ${_xml2h_input}
|
||||
DEPENDS ${CMAKE_SOURCE_DIR}/tools/xml2h.py
|
||||
COMMENT "Generating ${_xml2h_output} from ${_xml2h_input}")
|
||||
list(APPEND built_moo_sources ${_xml2h_output})
|
||||
endmacro(XML2H)
|
||||
|
||||
macro(ADD_UI input)
|
||||
string(REPLACE ".xml" "-ui.h" _ui_output "${input}")
|
||||
# message(STATUS "_ui_output: ${_ui_output}")
|
||||
string(REGEX REPLACE ".*/([^/]*)\\.xml" "\\1" _ui_variable "${input}")
|
||||
XML2H(${input} ${_ui_output} ${_ui_variable}_ui_xml)
|
||||
endmacro(ADD_UI)
|
||||
|
||||
file(MAKE_DIRECTORY
|
||||
${CMAKE_CURRENT_BINARY_DIR}/mooapp
|
||||
${CMAKE_CURRENT_BINARY_DIR}/mooedit
|
||||
${CMAKE_CURRENT_BINARY_DIR}/moofileview
|
||||
${CMAKE_CURRENT_BINARY_DIR}/mooutils
|
||||
${CMAKE_CURRENT_BINARY_DIR}/moolua
|
||||
${CMAKE_CURRENT_BINARY_DIR}/plugins/usertools
|
||||
${CMAKE_CURRENT_BINARY_DIR}/medit-app
|
||||
)
|
||||
|
||||
include(xdgmime/xdgmime.cmake)
|
||||
include(mooutils/mooutils.cmake)
|
||||
include(mooedit/mooedit.cmake)
|
||||
include(moofileview/moofileview.cmake)
|
||||
include(gtksourceview/gtksourceview.cmake)
|
||||
if(NOT MOO_OS_WIN32)
|
||||
include(eggsmclient/eggsmclient.cmake)
|
||||
endif()
|
||||
include(mooapp/mooapp.cmake)
|
||||
include(moolua/moolua.cmake)
|
||||
if(MOO_ENABLE_PYTHON)
|
||||
include(moopython/moopython.cmake)
|
||||
endif()
|
||||
include(plugins/plugins.cmake)
|
||||
include(medit-app/medit-app.cmake)
|
||||
|
||||
SET(MEDIT_SOURCES
|
||||
CMakeLists.txt
|
||||
${moo_sources}
|
||||
${built_moo_sources}
|
||||
)
|
||||
|
||||
macro(ADD_MODULE name)
|
||||
string(REPLACE "-" "_" _escaped_name "${name}")
|
||||
source_group(${name} FILES ${${_escaped_name}_sources} ${${_escaped_name}_extra_files})
|
||||
source_group(${name}\\generated FILES ${built_${_escaped_name}_sources})
|
||||
#source_group(${name} FILES ${${_escaped_name}_sources} ${${_escaped_name}_extra_files})
|
||||
#source_group(${name}\\generated FILES ${built_${_escaped_name}_sources})
|
||||
LIST(APPEND MEDIT_SOURCES ${${_escaped_name}_sources} ${built_${_escaped_name}_sources})
|
||||
LIST(APPEND MEDIT_EXTRA_DIST ${${_escaped_name}_extra_dist} ${${_escaped_name}_extra_files})
|
||||
endmacro(ADD_MODULE)
|
||||
|
||||
ADD_MODULE(xdgmime)
|
||||
ADD_MODULE(eggsmclient)
|
||||
ADD_MODULE(gtksourceview)
|
||||
ADD_MODULE(mooutils)
|
||||
ADD_MODULE(moofileview)
|
||||
ADD_MODULE(mooedit)
|
||||
ADD_MODULE(mooapp)
|
||||
ADD_MODULE(plugins)
|
||||
ADD_MODULE(moolua)
|
||||
if(MOO_ENABLE_PYTHON)
|
||||
ADD_MODULE(moopython)
|
||||
endif()
|
||||
ADD_MODULE(medit-app)
|
||||
|
||||
include_directories(${PROJECT_SOURCE_DIR}/moo/mooutils/moowin32/ms)
|
||||
|
||||
include_directories(
|
||||
${PROJECT_BINARY_DIR}
|
||||
${GTK_INCLUDE_DIRS}
|
||||
${LIBXML2_INCLUDE_DIRS}
|
||||
)
|
||||
link_directories(${GTK_LIBRARY_DIRS} ${GMODULE_LIBRARY_DIRS})
|
||||
|
||||
source_group(misc REGULAR_EXPRESSION .*)
|
||||
source_group("generated\\sources" REGULAR_EXPRESSION ".*\\.c(pp)?$")
|
||||
source_group("generated\\headers" REGULAR_EXPRESSION ".*\\.h$")
|
||||
source_group("misc\\glade" REGULAR_EXPRESSION ".*\\.glade$")
|
||||
|
||||
add_executable(medit WIN32
|
||||
${MEDIT_SOURCES}
|
||||
)
|
||||
|
||||
target_link_libraries(medit
|
||||
libmooglib-0
|
||||
${GTK_LIBRARIES}
|
||||
${GMODULE_LIBRARIES}
|
||||
${LIBXML2_LIBRARIES}
|
||||
${XLIB_LIBRARIES}
|
||||
#${LIBM}
|
||||
${PYTHON_LIBRARIES}
|
||||
${moo_libadd}
|
||||
${MEDIT_LIBS}
|
||||
)
|
||||
|
||||
install(TARGETS medit RUNTIME DESTINATION bin)
|
||||
|
||||
if(MOO_BUILD_FROM_MINGW)
|
||||
install(DIRECTORY ${MOO_GTK_DIST_DIR}/bin DESTINATION ${CMAKE_INSTALL_PREFIX})
|
||||
install(DIRECTORY ${MOO_GTK_DIST_DIR}/etc DESTINATION ${CMAKE_INSTALL_PREFIX})
|
||||
install(DIRECTORY ${MOO_GTK_DIST_DIR}/lib DESTINATION ${CMAKE_INSTALL_PREFIX})
|
||||
install(DIRECTORY ${MOO_GTK_DIST_DIR}/share DESTINATION ${CMAKE_INSTALL_PREFIX})
|
||||
#install(DIRECTORY ${CMAKE_SOURCE_DIR}/plat/win32/gtk-win/extra/medit-data/bin DESTINATION ${CMAKE_INSTALL_PREFIX})
|
||||
#install(DIRECTORY ${CMAKE_SOURCE_DIR}/plat/win32/gtk-win/extra/medit-data/etc DESTINATION ${CMAKE_INSTALL_PREFIX})
|
||||
endif()
|
||||
|
||||
# zzz
|
||||
# if MOO_OS_UNIX
|
||||
# desktopdir = $(datadir)/applications
|
||||
# desktop_DATA = medit-app/medit.desktop
|
||||
# medit-app/medit.desktop: medit-app/medit.desktop.in @MOO_INTLTOOL_INI_DEPS@
|
||||
# $(AM_V_at)$(MKDIR_P) medit-app
|
||||
# @MOO_INTLTOOL_INI_CMD@
|
||||
# CLEANFILES += medit-app/medit.desktop
|
||||
# endif MOO_OS_UNIX
|
||||
|
||||
# zzz
|
||||
# iconthemedir = $(datadir)/icons/hicolor/48x48/apps
|
||||
# icontheme_DATA = mooutils/pixmaps/medit.png
|
||||
# if MOO_ENABLE_INSTALL_HOOKS
|
||||
# update_icon_cache = gtk-update-icon-cache -f -t $(DESTDIR)$(datadir)/icons/hicolor
|
||||
# install-data-hook: install-data-hook-gtk-icon-cache
|
||||
# install-data-hook-gtk-icon-cache:
|
||||
# @if echo "Updating icon cache" && $(update_icon_cache); then
|
||||
# echo "Done.";
|
||||
# else
|
||||
# echo "*** GTK icon cache not updated. After install, run this:";\
|
||||
# echo $(update_icon_cache);
|
||||
# fi
|
||||
# uninstall-hook: uninstall-data-hook-gtk-icon-cache
|
||||
# uninstall-data-hook-gtk-icon-cache:
|
||||
# @if echo "Updating icon cache" && $(update_icon_cache); then echo "Done."; else echo "Failed."; fi
|
||||
# endif
|
||||
|
||||
# zzz include medit-module/Makefile.incl
|
||||
|
|
|
@ -40,7 +40,6 @@ marshals.h: marshals.list
|
|||
include mooedit/Makefile.incl
|
||||
include xdgmime/Makefile.incl
|
||||
include mooutils/Makefile.incl
|
||||
include moocpp/Makefile.incl
|
||||
include moofileview/Makefile.incl
|
||||
include gtksourceview/Makefile.incl
|
||||
include eggsmclient/Makefile.incl
|
||||
|
|
|
@ -1,26 +0,0 @@
|
|||
moo_sources += \
|
||||
moocpp/gboxed.h \
|
||||
moocpp/gobjectutils.h \
|
||||
moocpp/gobjptr.h \
|
||||
moocpp/gobjref.h \
|
||||
moocpp/gobjinfo.h \
|
||||
moocpp/gobjrawptr.h \
|
||||
moocpp/gobjtypes.h \
|
||||
moocpp/gobjtypes-glib.h \
|
||||
moocpp/gobjtypes-gio.h \
|
||||
moocpp/gobjtypes-gtk.h \
|
||||
moocpp/gobjtypes-glib.cpp \
|
||||
moocpp/gobjtypes-gio.cpp \
|
||||
moocpp/gobjtypes-gtk.cpp \
|
||||
moocpp/gobjwrapper.h \
|
||||
moocpp/gparam.h \
|
||||
moocpp/grefptr.h \
|
||||
moocpp/gutil.h \
|
||||
moocpp/gutil.cpp \
|
||||
moocpp/memutils.h \
|
||||
moocpp/moocpp.h \
|
||||
moocpp/strutils.h \
|
||||
moocpp/strutils.cpp \
|
||||
moocpp/utils.h
|
||||
|
||||
# -%- use-tabs:true, indent-width: 8, strip:true -%-
|
|
@ -1,19 +0,0 @@
|
|||
/*
|
||||
* moocpp/gobj.cpp
|
||||
*
|
||||
* Copyright (C) 2004-2016 by Yevgen Muntyan <emuntyan@users.sourceforge.net>
|
||||
*
|
||||
* This file is part of medit. medit 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.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public
|
||||
* License along with medit. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#pragma once
|
||||
|
||||
#include "moocpp/gobj.h"
|
||||
|
274
moo/gpp/gobj.h
274
moo/gpp/gobj.h
|
@ -1,274 +0,0 @@
|
|||
/*
|
||||
* moocpp/gobj.h
|
||||
*
|
||||
* Copyright (C) 2004-2016 by Yevgen Muntyan <emuntyan@users.sourceforge.net>
|
||||
*
|
||||
* This file is part of medit. medit 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.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public
|
||||
* License along with medit. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#pragma once
|
||||
|
||||
#ifndef __cplusplus
|
||||
#error "This is a C++ header"
|
||||
#endif
|
||||
|
||||
#include <glib-object.h>
|
||||
|
||||
namespace g {
|
||||
|
||||
namespace impl
|
||||
{
|
||||
|
||||
class base
|
||||
{
|
||||
public:
|
||||
virtual ~base() = default;
|
||||
virtual GObject* _gobj() = 0;
|
||||
};
|
||||
|
||||
} // namespace impl
|
||||
|
||||
namespace impl
|
||||
{
|
||||
|
||||
class obj_base
|
||||
{
|
||||
protected:
|
||||
obj_base(GObject* o);
|
||||
~obj_base();
|
||||
|
||||
GObject* _gobj() const { return m_gobj; }
|
||||
|
||||
private:
|
||||
GObject* m_gobj;
|
||||
};
|
||||
|
||||
class internals_accessor;
|
||||
|
||||
} // namespace impl
|
||||
|
||||
struct obj_type_info
|
||||
{
|
||||
obj_type_info(GType g_type);
|
||||
|
||||
GType g_type;
|
||||
};
|
||||
|
||||
struct iface_type_info
|
||||
{
|
||||
iface_type_info(GType g_type);
|
||||
|
||||
GType g_type;
|
||||
};
|
||||
|
||||
#define MOO_GOBJ_CLASS_DECL_BASE(Self, GName, G_TYPE) \
|
||||
friend class g::impl::internals_accessor; \
|
||||
\
|
||||
public: \
|
||||
static const g::obj_type_info type_info; \
|
||||
\
|
||||
using g_class = GName; \
|
||||
\
|
||||
GName *gobj() { return reinterpret_cast<GName*>(_gobj()); } \
|
||||
\
|
||||
operator GName&() { return *gobj(); } \
|
||||
\
|
||||
static g::obj_ptr<Self> wrap_new(GName* o); \
|
||||
|
||||
#define MOO_GOBJ_CLASS_DECL(Self, Parent, GName, G_TYPE) \
|
||||
MOO_GOBJ_CLASS_DECL_BASE(Self, GName, G_TYPE) \
|
||||
protected: \
|
||||
Self() = delete; \
|
||||
explicit Self(GName* o) : Parent(reinterpret_cast<Parent::g_class*>(o)) {} \
|
||||
GObject *_gobj() { return Parent::_gobj(); } \
|
||||
|
||||
|
||||
#define MOO_GOBJ_IFACE_DECL(Self, GName, G_TYPE) \
|
||||
friend class g::impl::internals_accessor; \
|
||||
\
|
||||
public: \
|
||||
static const g::iface_type_info type_info; \
|
||||
\
|
||||
using g_iface = GName; \
|
||||
\
|
||||
GName *gobj() { return reinterpret_cast<GName*>(_gobj()); } \
|
||||
\
|
||||
operator GName&() { return *gobj(); } \
|
||||
\
|
||||
static g::obj_ptr<Self> wrap_new(GName* o); \
|
||||
|
||||
#define MOO_DECLARE_GOBJ_CLASS(Self) \
|
||||
class Self; \
|
||||
using Self##Ptr = g::obj_ptr<Self> \
|
||||
|
||||
#define MOO_DEFINE_SIMPLE_GOBJ_CLASS(Self, Parent, GSelf, G_TYPE) \
|
||||
MOO_DECLARE_GOBJ_CLASS(Self); \
|
||||
class Self : public Parent \
|
||||
{ \
|
||||
MOO_GOBJ_CLASS_DECL(Self, Parent, GSelf, G_TYPE) \
|
||||
}
|
||||
|
||||
|
||||
#define MOO_CUSTOM_GOBJ_CLASS_DECL(Self, Parent) \
|
||||
friend class impl::internals_accessor; \
|
||||
\
|
||||
public: \
|
||||
static const g::obj_type_info type_info; \
|
||||
|
||||
|
||||
namespace impl {
|
||||
|
||||
template<typename T, typename RefUnref>
|
||||
class ref_ptr
|
||||
{
|
||||
public:
|
||||
ref_ptr(T* p = nullptr) : m_p(p) { if (m_p) RefUnref::ref(m_p); }
|
||||
~ref_ptr() { if (m_p) RefUnref::unref(m_p); }
|
||||
|
||||
T* get() const { return m_p; }
|
||||
T* operator->() const { return m_p; }
|
||||
T& operator*() const { return *m_p; }
|
||||
|
||||
void reset() { *this = nullptr; }
|
||||
|
||||
ref_ptr(const ref_ptr& rhs) : ref_ptr(rhs.m_p) {}
|
||||
ref_ptr& operator=(const ref_ptr& rhs) { *this = rhs.m_p; return *this; }
|
||||
ref_ptr(ref_ptr&& rhs) : m_p(rhs.m_p) { rhs.m_p = nullptr; }
|
||||
ref_ptr& operator=(ref_ptr&& rhs) { std::swap(m_p, rhs.m_p); return *this; }
|
||||
ref_ptr& operator=(T* p) { if (m_p != p) { T* tmp = m_p; m_p = p; if (tmp) RefUnref::unref(tmp); if(m_p) RefUnref::ref(m_p); } return *this; }
|
||||
|
||||
template<typename U>
|
||||
ref_ptr(U* p) : ref_ptr(static_cast<T*>(p)) {}
|
||||
template<typename U>
|
||||
ref_ptr& operator=(U* p) { *this = static_cast<T*>(p); return *this; }
|
||||
|
||||
template<typename U>
|
||||
ref_ptr(const ref_ptr<U, RefUnref>& rhs) : ref_ptr(rhs.m_p) {}
|
||||
template<typename U>
|
||||
ref_ptr& operator=(const ref_ptr<U, RefUnref>& rhs) { *this = rhs.get(); return *this; }
|
||||
template<typename U>
|
||||
ref_ptr(ref_ptr<U, RefUnref>&& rhs) : m_p(rhs.m_p) { rhs.m_p = nullptr; }
|
||||
template<typename U>
|
||||
ref_ptr& operator=(ref_ptr<U, RefUnref>&& rhs);
|
||||
|
||||
private:
|
||||
T* m_p;
|
||||
};
|
||||
|
||||
class obj_ref_unref
|
||||
{
|
||||
public:
|
||||
template<typename T>
|
||||
static void ref(T* o) { g_object_ref(o->gobj()); }
|
||||
|
||||
template<typename T>
|
||||
static void unref(T* o) { g_object_unref(o->gobj()); }
|
||||
};
|
||||
|
||||
} // namespace impl
|
||||
|
||||
template<typename T>
|
||||
using obj_ptr = impl::ref_ptr<T, impl::obj_ref_unref>;
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////////////////////
|
||||
//
|
||||
// GObject
|
||||
//
|
||||
|
||||
class Object;
|
||||
using ObjectPtr = obj_ptr<Object>;
|
||||
|
||||
class Object : public impl::obj_base
|
||||
{
|
||||
MOO_GOBJ_CLASS_DECL_BASE(Object, GObject, G_TYPE_OBJECT)
|
||||
|
||||
protected:
|
||||
Object() = delete;
|
||||
explicit Object(GObject* o) : impl::obj_base(o) {}
|
||||
|
||||
public:
|
||||
gulong connect(const char* detailed_signal, GCallback c_handler, void* data);
|
||||
gulong connect_swapped(const char* detailed_signal, GCallback c_handler, void* data);
|
||||
|
||||
void signal_emit_by_name(const char* detailed_signal, ...);
|
||||
void signal_emit(guint signal_id, GQuark detail, ...);
|
||||
|
||||
bool signal_has_handler_pending(guint signal_id, GQuark detail, bool may_be_blocked);
|
||||
gulong signal_connect_closure_by_id(guint signal_id, GQuark detail, GClosure* closure, bool after);
|
||||
gulong signal_connect_closure(const char* detailed_signal, GClosure* closure, bool after);
|
||||
gulong signal_connect_data(const char* detailed_signal, GCallback c_handler, gpointer data, GClosureNotify destroy_data, GConnectFlags connect_flags);
|
||||
void signal_handler_block(gulong handler_id);
|
||||
void signal_handler_unblock(gulong handler_id);
|
||||
void signal_handler_disconnect(gulong handler_id);
|
||||
bool signal_handler_is_connected(gulong handler_id);
|
||||
gulong signal_handler_find(GSignalMatchType mask, guint signal_id, GQuark detail, GClosure* closure, gpointer func, gpointer data);
|
||||
guint signal_handlers_block_matched(GSignalMatchType mask, guint signal_id, GQuark detail, GClosure* closure, gpointer func, gpointer data);
|
||||
guint signal_handlers_unblock_matched(GSignalMatchType mask, guint signal_id, GQuark detail, GClosure* closure, gpointer func, gpointer data);
|
||||
guint signal_handlers_disconnect_matched(GSignalMatchType mask, guint signal_id, GQuark detail, GClosure* closure, gpointer func, gpointer data);
|
||||
guint signal_handlers_disconnect_by_func(GCallback c_handler, void* data);
|
||||
|
||||
#if 0
|
||||
void* get_data(const char* key);
|
||||
void* get_data(GQuark q);
|
||||
void set_data(const char* key, gpointer value, GDestroyNotify destroy = nullptr);
|
||||
void set_data(GQuark q, gpointer value, GDestroyNotify destroy = nullptr);
|
||||
|
||||
void set_property(const char* property_name, const GValue* value);
|
||||
|
||||
template<typename T>
|
||||
void set(const char* prop, const T& value)
|
||||
{
|
||||
g_object_set(gobj(), prop, cpp_vararg_value_fixer<T>::apply(value), nullptr);
|
||||
}
|
||||
|
||||
template<typename T, typename... Args>
|
||||
void set(const char* prop, const T& value, Args&&... args)
|
||||
{
|
||||
set(prop, value);
|
||||
set(std::forward<Args>(args)...);
|
||||
}
|
||||
|
||||
void get(const char* prop, bool& dest)
|
||||
{
|
||||
gboolean val;
|
||||
g_object_get(gobj(), prop, &val, nullptr);
|
||||
dest = val;
|
||||
}
|
||||
|
||||
template<typename T>
|
||||
void get(const char* prop, T&& dest)
|
||||
{
|
||||
g_object_get(gobj(), prop, cpp_vararg_dest_fixer<T>::apply(std::forward<T>(dest)), nullptr);
|
||||
}
|
||||
|
||||
template<typename T, typename... Args>
|
||||
void get(const char* prop, T&& dest, Args&&... args)
|
||||
{
|
||||
get(prop, std::forward<T>(dest));
|
||||
get(std::forward<Args>(args)...);
|
||||
}
|
||||
|
||||
#endif // 0
|
||||
|
||||
void notify(const char* property_name);
|
||||
void freeze_notify();
|
||||
void thaw_notify();
|
||||
};
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////////////////////
|
||||
//
|
||||
// GIface
|
||||
//
|
||||
|
||||
class Iface : public impl::base
|
||||
{
|
||||
};
|
||||
|
||||
} // namespace g
|
|
@ -1,168 +0,0 @@
|
|||
/*
|
||||
* moogpp/gobjectutils.h
|
||||
*
|
||||
* Copyright (C) 2004-2015 by Yevgen Muntyan <emuntyan@users.sourceforge.net>
|
||||
*
|
||||
* This file is part of medit. medit 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.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public
|
||||
* License along with medit. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#pragma once
|
||||
|
||||
#ifndef __cplusplus
|
||||
#error "This is a C++ header"
|
||||
#endif
|
||||
|
||||
#include <memory>
|
||||
#include <utility>
|
||||
|
||||
namespace g {
|
||||
|
||||
template<typename T>
|
||||
inline GType get_g_type();
|
||||
|
||||
template<typename T>
|
||||
inline T* object_ref(T *obj)
|
||||
{
|
||||
return static_cast<T*>(g_object_ref(obj));
|
||||
}
|
||||
|
||||
template<typename T>
|
||||
inline T* object_cast(gpointer obj)
|
||||
{
|
||||
return obj ? reinterpret_cast<T*>(G_TYPE_CHECK_INSTANCE_CAST(g_object_ref(obj), get_g_type<T>(), T)) : nullptr;
|
||||
}
|
||||
|
||||
template<typename T>
|
||||
inline T* object_ref_opt(T *obj)
|
||||
{
|
||||
return obj ? object_cast<T>(g_object_ref(obj)) : nullptr;
|
||||
}
|
||||
|
||||
template<typename T>
|
||||
inline T* object_cast_opt(gpointer obj)
|
||||
{
|
||||
return obj ? object_cast<T>(obj) : nullptr;
|
||||
}
|
||||
|
||||
template<typename T>
|
||||
inline T* object_ref_cast_opt(gpointer obj)
|
||||
{
|
||||
return obj ? object_ref(object_cast<T>(obj)) : nullptr;
|
||||
}
|
||||
|
||||
template<typename T>
|
||||
inline T* new_object()
|
||||
{
|
||||
return object_cast<T>(g_object_new(get_g_type<T>(), nullptr));
|
||||
}
|
||||
|
||||
#if 0
|
||||
|
||||
template<typename CObject>
|
||||
std::vector<gobj_ptr<CObject>> object_list_to_vector (GList* list)
|
||||
{
|
||||
std::vector<gobj_ptr<CObject>> ret;
|
||||
|
||||
for (GList* l = list; l != nullptr; l = l->next)
|
||||
{
|
||||
CObject* o = reinterpret_cast<CObject*>(l->data);
|
||||
g_assert (!o || G_TYPE_CHECK_INSTANCE_TYPE ((o), gobjinfo<CObject>::object_g_type ()));
|
||||
ret.emplace_back (gobj_ptr<CObject>::wrap (o));
|
||||
}
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
template<typename T>
|
||||
class cpp_vararg_value_fixer;
|
||||
|
||||
template<typename T>
|
||||
class cpp_vararg_value_fixer
|
||||
{
|
||||
public:
|
||||
static const T& apply (const T& val) { return val; }
|
||||
};
|
||||
|
||||
template<typename TSrc, typename TDest>
|
||||
class cpp_vararg_value_fixer_convert
|
||||
{
|
||||
public:
|
||||
static TDest apply (const TSrc& val) { return val; }
|
||||
};
|
||||
|
||||
template<> class cpp_vararg_value_fixer<bool> : public cpp_vararg_value_fixer_convert<bool, gboolean>{};
|
||||
template<> class cpp_vararg_value_fixer<gstr> : public cpp_vararg_value_fixer_convert<gstr, const char*>{};
|
||||
template<> class cpp_vararg_value_fixer<gstrp> : public cpp_vararg_value_fixer_convert<gstrp, const char*>{};
|
||||
|
||||
template<typename CObject>
|
||||
class cpp_vararg_value_fixer<gobj_ptr<CObject>>
|
||||
{
|
||||
public:
|
||||
static CObject* apply (const gobj_ptr<CObject>& val) { return val.gobj(); }
|
||||
};
|
||||
|
||||
template<typename CObject>
|
||||
class cpp_vararg_value_fixer<gobj_raw_ptr<CObject>>
|
||||
{
|
||||
public:
|
||||
static CObject* apply (const gobj_raw_ptr<CObject>& val) { return val.gobj (); }
|
||||
};
|
||||
|
||||
template<typename T>
|
||||
class cpp_vararg_value_fixer<objp<T>>
|
||||
{
|
||||
public:
|
||||
static T* apply (objp<T> val) { return val.release (); }
|
||||
};
|
||||
|
||||
|
||||
template<typename T>
|
||||
struct cpp_vararg_dest_fixer
|
||||
{
|
||||
template<typename U>
|
||||
static void* apply (U) = delete;
|
||||
};
|
||||
|
||||
template<typename T>
|
||||
struct cpp_vararg_dest_fixer_passthrough
|
||||
{
|
||||
static T* apply (T* p) { return p; }
|
||||
};
|
||||
|
||||
template<typename T>
|
||||
struct cpp_vararg_dest_fixer_passthrough_ref
|
||||
{
|
||||
static T* apply (T& p) { return &p; }
|
||||
};
|
||||
|
||||
template<> struct cpp_vararg_dest_fixer<int&> : public cpp_vararg_dest_fixer_passthrough_ref<int>{};
|
||||
template<> struct cpp_vararg_dest_fixer<guint&> : public cpp_vararg_dest_fixer_passthrough_ref<guint>{};
|
||||
|
||||
template<>
|
||||
struct cpp_vararg_dest_fixer<gstrp&>
|
||||
{
|
||||
static char** apply (gstrp& s) { return s.pp (); }
|
||||
};
|
||||
|
||||
template<typename T>
|
||||
struct cpp_vararg_dest_fixer<objp<T>&>
|
||||
{
|
||||
static void** apply (objp<T>& o) { return reinterpret_cast<void**>(o.pp ()); }
|
||||
};
|
||||
|
||||
template<typename T>
|
||||
struct cpp_vararg_dest_fixer<gobj_ptr<T>&>
|
||||
{
|
||||
static void** apply (gobj_ptr<T>& o) { return reinterpret_cast<void**>(o.pp ()); }
|
||||
};
|
||||
|
||||
#endif // 0
|
||||
|
||||
} // namespace g
|
|
@ -1,25 +0,0 @@
|
|||
/*
|
||||
* gpp/gobjtypes-gio.cpp
|
||||
*
|
||||
* Copyright (C) 2004-2016 by Yevgen Muntyan <emuntyan@users.sourceforge.net>
|
||||
*
|
||||
* This file is part of medit. medit 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.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public
|
||||
* License along with medit. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#include "moogpp/gobjtypes-gio.h"
|
||||
|
||||
using namespace g;
|
||||
|
||||
FilePtr File::new_for_path(const char* path)
|
||||
{
|
||||
GFile* f = g_file_new_for_path(path);
|
||||
g_return_val_if_fail(f != nullptr, nullptr);
|
||||
return File::wrap_new(f);
|
||||
}
|
|
@ -1,208 +0,0 @@
|
|||
/*
|
||||
* gpp/gobjtypes-gio.h
|
||||
*
|
||||
* Copyright (C) 2004-2016 by Yevgen Muntyan <emuntyan@users.sourceforge.net>
|
||||
*
|
||||
* This file is part of medit. medit 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.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public
|
||||
* License along with medit. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#pragma once
|
||||
|
||||
#ifndef __cplusplus
|
||||
#error "This is a C++ header"
|
||||
#endif
|
||||
|
||||
#include <gio/gio.h>
|
||||
#include <moogpp/gobjtypes-glib.h>
|
||||
|
||||
namespace g {
|
||||
|
||||
class gstr;
|
||||
class gerrp;
|
||||
|
||||
MOO_DECLARE_GOBJ_CLASS(File);
|
||||
MOO_DECLARE_GOBJ_CLASS(OutputStream);
|
||||
MOO_DECLARE_GOBJ_CLASS(FileOutputStream);
|
||||
|
||||
MOO_DEFINE_SIMPLE_GOBJ_CLASS(FileInfo, Object, GFileInfo, G_TYPE_FILE_INFO);
|
||||
MOO_DEFINE_SIMPLE_GOBJ_CLASS(InputStream, Object, GInputStream, G_TYPE_INPUT_STREAM);
|
||||
MOO_DEFINE_SIMPLE_GOBJ_CLASS(FileInputStream, InputStream, GFileInputStream, G_TYPE_FILE_INPUT_STREAM);
|
||||
MOO_DEFINE_SIMPLE_GOBJ_CLASS(IOStream, Object, GIOStream, G_TYPE_IO_STREAM);
|
||||
MOO_DEFINE_SIMPLE_GOBJ_CLASS(FileIOStream, IOStream, GFileIOStream, G_TYPE_FILE_IO_STREAM);
|
||||
|
||||
class File : public Iface
|
||||
{
|
||||
MOO_GOBJ_IFACE_DECL(File, GFile, G_TYPE_FILE)
|
||||
|
||||
public:
|
||||
static g::FilePtr new_for_path (const char* path);
|
||||
static g::FilePtr new_for_uri (const char* uri);
|
||||
static g::FilePtr new_for_commandline_arg (const char* arg);
|
||||
static g::FilePtr parse_name (const char* parse_name);
|
||||
|
||||
g::FilePtr dup ();
|
||||
|
||||
bool equal (g::File& file2);
|
||||
|
||||
gstr get_basename ();
|
||||
gstr get_path();
|
||||
gstr get_uri();
|
||||
gstr get_parse_name();
|
||||
g::FilePtr get_parent ();
|
||||
bool has_parent (g::File& parent);
|
||||
g::FilePtr get_child (const char* name);
|
||||
g::FilePtr get_child_for_display_name (const char* display_name,
|
||||
gerrp& error);
|
||||
bool has_prefix (g::File& prefix);
|
||||
gstr get_relative_path (g::File& descendant);
|
||||
g::FilePtr resolve_relative_path (const char *relative_path);
|
||||
bool is_native ();
|
||||
bool has_uri_scheme (const char *uri_scheme);
|
||||
gstr get_uri_scheme();
|
||||
g::FileInputStreamPtr read (GCancellable* cancellable,
|
||||
gerrp& error);
|
||||
g::FileOutputStreamPtr append_to (GFileCreateFlags flags,
|
||||
GCancellable* cancellable,
|
||||
gerrp& error);
|
||||
g::FileOutputStreamPtr create (GFileCreateFlags flags,
|
||||
GCancellable* cancellable,
|
||||
gerrp& error);
|
||||
g::FileOutputStreamPtr replace (const char *etag,
|
||||
gboolean make_backup,
|
||||
GFileCreateFlags flags,
|
||||
GCancellable* cancellable,
|
||||
gerrp& error);
|
||||
g::FileIOStreamPtr open_readwrite (GCancellable* cancellable,
|
||||
gerrp& error);
|
||||
g::FileIOStreamPtr create_readwrite (GFileCreateFlags flags,
|
||||
GCancellable* cancellable,
|
||||
gerrp& error);
|
||||
g::FileIOStreamPtr replace_readwrite (const char *etag,
|
||||
gboolean make_backup,
|
||||
GFileCreateFlags flags,
|
||||
GCancellable* cancellable,
|
||||
gerrp& error);
|
||||
bool query_exists (GCancellable* cancellable);
|
||||
GFileType query_file_type (GFileQueryInfoFlags flags,
|
||||
GCancellable* cancellable);
|
||||
g::FileInfoPtr query_info (const char *attributes,
|
||||
GFileQueryInfoFlags flags,
|
||||
GCancellable* cancellable,
|
||||
gerrp& error);
|
||||
g::FileInfoPtr query_filesystem_info (const char *attributes,
|
||||
GCancellable* cancellable,
|
||||
gerrp& error);
|
||||
GFileEnumerator* enumerate_children (const char *attributes,
|
||||
GFileQueryInfoFlags flags,
|
||||
GCancellable* cancellable,
|
||||
gerrp& error);
|
||||
g::FilePtr set_display_name (const char* display_name,
|
||||
GCancellable* cancellable,
|
||||
gerrp& error);
|
||||
bool delete_ (GCancellable* cancellable,
|
||||
gerrp& error);
|
||||
bool trash (GCancellable* cancellable,
|
||||
gerrp& error);
|
||||
bool copy (g::File& destination,
|
||||
GFileCopyFlags flags,
|
||||
GCancellable* cancellable,
|
||||
GFileProgressCallback progress_callback,
|
||||
gpointer progress_callback_data,
|
||||
gerrp& error);
|
||||
bool move (g::File& destination,
|
||||
GFileCopyFlags flags,
|
||||
GCancellable* cancellable,
|
||||
GFileProgressCallback progress_callback,
|
||||
gpointer progress_callback_data,
|
||||
gerrp& error);
|
||||
bool make_directory (GCancellable* cancellable,
|
||||
gerrp& error);
|
||||
bool make_directory_with_parents (GCancellable* cancellable,
|
||||
gerrp& error);
|
||||
bool make_symbolic_link (const char *symlink_value,
|
||||
GCancellable* cancellable,
|
||||
gerrp& error);
|
||||
|
||||
bool load_contents (GCancellable* cancellable,
|
||||
char** contents,
|
||||
gsize* length,
|
||||
char** etag_out,
|
||||
gerrp& error);
|
||||
bool replace_contents (const char* contents,
|
||||
gsize length,
|
||||
const char* etag,
|
||||
gboolean make_backup,
|
||||
GFileCreateFlags flags,
|
||||
char** new_etag,
|
||||
GCancellable* cancellable,
|
||||
gerrp& error);
|
||||
};
|
||||
|
||||
class OutputStream : public Object
|
||||
{
|
||||
MOO_GOBJ_CLASS_DECL(OutputStream, Object, GOutputStream, G_TYPE_OUTPUT_STREAM)
|
||||
|
||||
public:
|
||||
gssize write (const void *buffer,
|
||||
gsize count,
|
||||
GCancellable *cancellable,
|
||||
gerrp& error);
|
||||
bool write_all (const void *buffer,
|
||||
gsize count,
|
||||
gsize *bytes_written,
|
||||
GCancellable *cancellable,
|
||||
gerrp& error);
|
||||
gssize splice (g::InputStream source,
|
||||
GOutputStreamSpliceFlags flags,
|
||||
GCancellable *cancellable,
|
||||
gerrp& error);
|
||||
bool flush (GCancellable *cancellable,
|
||||
gerrp& error);
|
||||
bool close (GCancellable *cancellable,
|
||||
gerrp& error);
|
||||
void write_async (const void *buffer,
|
||||
gsize count,
|
||||
int io_priority,
|
||||
GCancellable *cancellable,
|
||||
GAsyncReadyCallback callback,
|
||||
gpointer user_data);
|
||||
gssize write_finish (GAsyncResult *result,
|
||||
gerrp& error);
|
||||
void splice_async (g::InputStream source,
|
||||
GOutputStreamSpliceFlags flags,
|
||||
int io_priority,
|
||||
GCancellable *cancellable,
|
||||
GAsyncReadyCallback callback,
|
||||
gpointer user_data);
|
||||
gssize splice_finish (GAsyncResult *result,
|
||||
gerrp& error);
|
||||
void flush_async (int io_priority,
|
||||
GCancellable *cancellable,
|
||||
GAsyncReadyCallback callback,
|
||||
gpointer user_data);
|
||||
bool flush_finish (GAsyncResult *result,
|
||||
gerrp& error);
|
||||
void close_async (int io_priority,
|
||||
GCancellable *cancellable,
|
||||
GAsyncReadyCallback callback,
|
||||
gpointer user_data);
|
||||
bool close_finish (GAsyncResult *result,
|
||||
gerrp& error);
|
||||
|
||||
bool is_closed ();
|
||||
bool is_closing ();
|
||||
bool has_pending ();
|
||||
bool set_pending (gerrp& error);
|
||||
void clear_pending ();
|
||||
};
|
||||
|
||||
MOO_DEFINE_SIMPLE_GOBJ_CLASS(FileOutputStream, OutputStream, GFileOutputStream, G_TYPE_FILE_OUTPUT_STREAM);
|
||||
|
||||
} // namespace g
|
|
@ -1,50 +0,0 @@
|
|||
/*
|
||||
* moocpp/gobjtypes-glib.cpp
|
||||
*
|
||||
* Copyright (C) 2004-2016 by Yevgen Muntyan <emuntyan@users.sourceforge.net>
|
||||
*
|
||||
* This file is part of medit. medit 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.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public
|
||||
* License along with medit. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#include "moogpp/gobjtypes-glib.h"
|
||||
#include <unordered_map>
|
||||
|
||||
namespace {
|
||||
|
||||
//std::unordered_map<GType, g::obj_type_info*> known_types;
|
||||
//
|
||||
//g::obj_type_info* lookup_type(GType gtyp)
|
||||
//{
|
||||
// auto itr = known_types.find(gtyp);
|
||||
// if (itr == known_types.end())
|
||||
// return nullptr;
|
||||
// else
|
||||
// return itr->second;
|
||||
//}
|
||||
//
|
||||
//g::obj_type_info* get_type(GType gtyp)
|
||||
//{
|
||||
// g::obj_type_info* ti = lookup_type(gtyp);
|
||||
// if (ti)
|
||||
// return ti;
|
||||
//
|
||||
// g_return_val_if_fail(g_type_fundamental(gtyp) == G_TYPE_OBJECT, nullptr);
|
||||
// g_return_val_if_fail(gtyp != G_TYPE_OBJECT, nullptr);
|
||||
//
|
||||
// GType parent = g_type_parent(gtyp);
|
||||
// g::obj_type_info* parent_ti = get_type(parent);
|
||||
//
|
||||
// if (gtyp == G_TYPE_OBJECT)
|
||||
// {
|
||||
//
|
||||
// }
|
||||
//}
|
||||
|
||||
} // namespace
|
|
@ -1,42 +0,0 @@
|
|||
/*
|
||||
* moocpp/gobjtypes-glib.h
|
||||
*
|
||||
* Copyright (C) 2004-2016 by Yevgen Muntyan <emuntyan@users.sourceforge.net>
|
||||
*
|
||||
* This file is part of medit. medit 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.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public
|
||||
* License along with medit. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#pragma once
|
||||
|
||||
#ifndef __cplusplus
|
||||
#error "This is a C++ header"
|
||||
#endif
|
||||
|
||||
#include <moogpp/gobj.h>
|
||||
#include <moogpp/utils.h>
|
||||
|
||||
namespace g {
|
||||
|
||||
class Binding;
|
||||
using BindingPtr = obj_ptr<Binding>;
|
||||
|
||||
class Binding : public Object
|
||||
{
|
||||
MOO_GOBJ_CLASS_DECL(Binding, Object, GBinding, G_TYPE_BINDING)
|
||||
};
|
||||
|
||||
} // namespace g
|
||||
|
||||
MOO_DEFINE_FLAGS(GSignalFlags);
|
||||
MOO_DEFINE_FLAGS(GConnectFlags);
|
||||
MOO_DEFINE_FLAGS(GSpawnFlags);
|
||||
MOO_DEFINE_FLAGS(GLogLevelFlags);
|
||||
MOO_DEFINE_FLAGS(GRegexCompileFlags);
|
||||
MOO_DEFINE_FLAGS(GIOCondition);
|
File diff suppressed because it is too large
Load Diff
|
@ -1,620 +0,0 @@
|
|||
/*
|
||||
* moogpp/gobjtypes-gtk.h
|
||||
*
|
||||
* Copyright (C) 2004-2016 by Yevgen Muntyan <emuntyan@users.sourceforge.net>
|
||||
*
|
||||
* This file is part of medit. medit 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.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public
|
||||
* License along with medit. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#pragma once
|
||||
|
||||
#ifndef __cplusplus
|
||||
#error "This is a C++ header"
|
||||
#endif
|
||||
|
||||
#include <gtk/gtk.h>
|
||||
|
||||
#include "moogpp/gobjtypes-glib.h"
|
||||
#include "moogpp/strutils.h"
|
||||
#include <initializer_list>
|
||||
#include <functional>
|
||||
|
||||
#define MOO_DEFINE_GTK_TYPE(Object, Parent, obj_g_type) \
|
||||
MOO_DEFINE_SIMPLE_GOBJ_CLASS(Object, Parent, Gtk##Object, obj_g_type) \
|
||||
|
||||
#define MOO_DEFINE_GTK_IFACE(Iface, iface_g_type) \
|
||||
MOO_DEFINE_GIFACE_TYPE(Gtk##Iface, iface_g_type) \
|
||||
namespace moo { \
|
||||
namespace gtk { \
|
||||
MOO_GIFACE_TYPEDEFS(Iface, Gtk##Iface) \
|
||||
} \
|
||||
}
|
||||
|
||||
namespace gtk
|
||||
{
|
||||
|
||||
using gstr = g::gstr;
|
||||
using gerrp = g::gerrp;
|
||||
|
||||
MOO_DECLARE_GOBJ_CLASS(Object);
|
||||
MOO_DECLARE_GOBJ_CLASS(Widget);
|
||||
MOO_DECLARE_GOBJ_CLASS(TextView);
|
||||
MOO_DECLARE_GOBJ_CLASS(TreeModel);
|
||||
MOO_DECLARE_GOBJ_CLASS(TreeStore);
|
||||
MOO_DECLARE_GOBJ_CLASS(ListStore);
|
||||
MOO_DECLARE_GOBJ_CLASS(TreeView);
|
||||
MOO_DECLARE_GOBJ_CLASS(TreeViewColumn);
|
||||
MOO_DECLARE_GOBJ_CLASS(CellRenderer);
|
||||
MOO_DECLARE_GOBJ_CLASS(CellRendererText);
|
||||
MOO_DECLARE_GOBJ_CLASS(CellRendererToggle);
|
||||
MOO_DECLARE_GOBJ_CLASS(CellRendererPixbuf);
|
||||
|
||||
MOO_DEFINE_GTK_TYPE(Object, g::Object, GTK_TYPE_OBJECT);
|
||||
MOO_DEFINE_GTK_TYPE(Widget, gtk::Object, GTK_TYPE_WIDGET);
|
||||
|
||||
MOO_DEFINE_GTK_TYPE(Entry, gtk::Widget, GTK_TYPE_ENTRY);
|
||||
MOO_DEFINE_GTK_TYPE(Action, g::Object, GTK_TYPE_ACTION);
|
||||
MOO_DEFINE_GTK_TYPE(TextBuffer, g::Object, GTK_TYPE_TEXT_BUFFER);
|
||||
MOO_DEFINE_GTK_TYPE(TextMark, g::Object, GTK_TYPE_TEXT_MARK);
|
||||
MOO_DEFINE_GTK_TYPE(MenuShell, gtk::Widget, GTK_TYPE_MENU_SHELL);
|
||||
MOO_DEFINE_GTK_TYPE(Menu, gtk::MenuShell, GTK_TYPE_MENU);
|
||||
|
||||
class TextView : public Widget
|
||||
{
|
||||
MOO_GOBJ_CLASS_DECL(TextView, Widget, GtkTextView, GTK_TYPE_TEXT_VIEW)
|
||||
|
||||
public:
|
||||
gtk::TextBuffer get_buffer ();
|
||||
};
|
||||
|
||||
|
||||
class TreeModel : public g::Iface
|
||||
{
|
||||
MOO_GOBJ_IFACE_DECL(TreeModel, GtkTreeModel, GTK_TYPE_TREE_MODEL)
|
||||
|
||||
public:
|
||||
GtkTreeModelFlags get_flags ();
|
||||
int get_n_columns ();
|
||||
GType get_column_type (int index_);
|
||||
|
||||
bool get_iter (GtkTreeIter& iter, const GtkTreePath& path);
|
||||
bool get_iter_from_string (GtkTreeIter& iter, const char* path_string);
|
||||
gstr get_string_from_iter (const GtkTreeIter& iter);
|
||||
bool get_iter_first (GtkTreeIter& iter);
|
||||
GtkTreePath* get_path (const GtkTreeIter& iter);
|
||||
void get_value (const GtkTreeIter& iter, int column, GValue* value);
|
||||
bool iter_next (GtkTreeIter& iter);
|
||||
bool iter_children (GtkTreeIter& iter, const GtkTreeIter& parent);
|
||||
bool iter_has_child (const GtkTreeIter& iter);
|
||||
int iter_n_children (const GtkTreeIter& iter);
|
||||
bool iter_nth_child (GtkTreeIter& iter, const GtkTreeIter& parent, int n);
|
||||
bool iter_parent (GtkTreeIter& iter, const GtkTreeIter& child);
|
||||
|
||||
void get (const GtkTreeIter& iter, int column, bool& dest)
|
||||
{
|
||||
gboolean val;
|
||||
gtk_tree_model_get (gobj (), const_cast<GtkTreeIter*>(&iter), column, &val, -1);
|
||||
dest = val;
|
||||
}
|
||||
|
||||
template<typename T>
|
||||
void get (const GtkTreeIter& iter, int column, T&& dest)
|
||||
{
|
||||
gtk_tree_model_get (gobj (), const_cast<GtkTreeIter*>(&iter), column, cpp_vararg_dest_fixer<T>::apply (std::forward<T> (dest)), -1);
|
||||
}
|
||||
|
||||
template<typename T, typename... Args>
|
||||
void get (const GtkTreeIter& iter, int column, T&& dest, Args&&... args)
|
||||
{
|
||||
get (iter, column, std::forward<T> (dest));
|
||||
get (iter, std::forward<Args> (args)...);
|
||||
}
|
||||
|
||||
// bool TFunc (const GtkTreePath&, const GtkTreeIter&)
|
||||
template<typename TFunc>
|
||||
void foreach (const TFunc& func)
|
||||
{
|
||||
const void* p = &func;
|
||||
gtk_tree_model_foreach (gobj (), foreach_func<TFunc>, const_cast<void*>(p));
|
||||
}
|
||||
|
||||
private:
|
||||
template<typename TFunc>
|
||||
static gboolean foreach_func (GtkTreeModel *model, GtkTreePath *path, GtkTreeIter *iter, gpointer data)
|
||||
{
|
||||
const TFunc& func = *reinterpret_cast<const TFunc*>(data);
|
||||
return func (const_cast<const GtkTreePath&>(*path), const_cast<const GtkTreeIter&>(*iter));
|
||||
}
|
||||
};
|
||||
|
||||
class ListStore : public g::Object, public TreeModel
|
||||
{
|
||||
MOO_GOBJ_CLASS_DECL(ListStore, g::Object, GtkListStore, GTK_TYPE_LIST_STORE)
|
||||
|
||||
public:
|
||||
static gtk::ListStorePtr create (std::initializer_list<GType> types)
|
||||
{
|
||||
return create (types.size (), types.begin ());
|
||||
}
|
||||
|
||||
static gtk::ListStorePtr create (size_t n_columns, std::initializer_list<GType> types)
|
||||
{
|
||||
g_return_val_if_fail (n_columns == types.size (), nullptr);
|
||||
return create (n_columns, types.begin ());
|
||||
}
|
||||
|
||||
static gtk::ListStorePtr create (size_t n_columns, const GType* types);
|
||||
|
||||
template<typename T>
|
||||
void set (const GtkTreeIter& iter, int column, T&& value)
|
||||
{
|
||||
gtk_list_store_set (gobj (), const_cast<GtkTreeIter*>(&iter), column, cpp_vararg_value_fixer<T>::apply (std::forward<T&&> (value)), -1);
|
||||
}
|
||||
|
||||
template<typename T, typename... Args>
|
||||
void set (const GtkTreeIter& iter, int column, T&& value, Args&&... args)
|
||||
{
|
||||
set (iter, column, std::forward<T> (value));
|
||||
set (iter, std::forward<Args> (args)...);
|
||||
}
|
||||
|
||||
void set_value (const GtkTreeIter& iter,
|
||||
int column,
|
||||
GValue* value);
|
||||
void set_valuesv (const GtkTreeIter& iter,
|
||||
int* columns,
|
||||
GValue* values,
|
||||
int n_values);
|
||||
bool remove (GtkTreeIter& iter);
|
||||
void insert (GtkTreeIter& iter,
|
||||
int position);
|
||||
void insert_before (GtkTreeIter& iter,
|
||||
GtkTreeIter& sibling);
|
||||
void insert_after (GtkTreeIter& iter,
|
||||
GtkTreeIter& sibling);
|
||||
//void insert_with_values (GtkTreeIter* iter,
|
||||
// int position,
|
||||
// ...);
|
||||
//void insert_with_values (GtkTreeIter* iter,
|
||||
// int position,
|
||||
// int* columns,
|
||||
// GValue* values,
|
||||
// int n_values);
|
||||
void prepend (GtkTreeIter& iter);
|
||||
void append (GtkTreeIter& iter);
|
||||
void clear ();
|
||||
bool iter_is_valid (const GtkTreeIter& iter);
|
||||
void reorder (int* new_order);
|
||||
void swap (GtkTreeIter& a,
|
||||
GtkTreeIter& b);
|
||||
void move_after (GtkTreeIter& iter,
|
||||
GtkTreeIter& position);
|
||||
void move_before (GtkTreeIter& iter,
|
||||
GtkTreeIter& position);
|
||||
};
|
||||
|
||||
class TreeStore : public g::Object, public TreeModel
|
||||
{
|
||||
MOO_GOBJ_CLASS_DECL(TreeStore, g::Object, GtkTreeStore, GTK_TYPE_TREE_STORE)
|
||||
};
|
||||
|
||||
MOO_DEFINE_GTK_TYPE(Container, Widget, GTK_TYPE_CONTAINER);
|
||||
MOO_DEFINE_GTK_TYPE(TreeView, Container, GTK_TYPE_TREE_VIEW);
|
||||
MOO_DEFINE_GTK_TYPE(TreeViewColumn, Object, GTK_TYPE_TREE_VIEW_COLUMN);
|
||||
MOO_DEFINE_GTK_TYPE(CellRenderer, Object, GTK_TYPE_CELL_RENDERER);
|
||||
MOO_DEFINE_GTK_TYPE(CellRendererText, CellRenderer, GTK_TYPE_CELL_RENDERER_TEXT);
|
||||
MOO_DEFINE_GTK_TYPE(CellRendererPixbuf, CellRenderer, GTK_TYPE_CELL_RENDERER_PIXBUF);
|
||||
MOO_DEFINE_GTK_TYPE(CellRendererToggle, CellRenderer, GTK_TYPE_CELL_RENDERER_TOGGLE);
|
||||
|
||||
#if 0
|
||||
|
||||
template<typename TFunc>
|
||||
class TreeCellDataFunc
|
||||
{
|
||||
public:
|
||||
TreeCellDataFunc (TFunc func) : m_func (std::move (func)) {}
|
||||
~TreeCellDataFunc () {}
|
||||
|
||||
MOO_DISABLE_COPY_OPS (TreeCellDataFunc);
|
||||
|
||||
static void destroy (gpointer d) { delete reinterpret_cast<TreeCellDataFunc*>(d); }
|
||||
|
||||
static void cell_data_func (GtkTreeViewColumn *tree_column,
|
||||
GtkCellRenderer *cell,
|
||||
GtkTreeModel *tree_model,
|
||||
GtkTreeIter *iter,
|
||||
gpointer p);
|
||||
|
||||
private:
|
||||
TFunc m_func;
|
||||
};
|
||||
|
||||
|
||||
template<>
|
||||
class moo::gobj_ref<GtkTreeView> : public virtual moo::gobj_ref_parent<GtkTreeView>
|
||||
{
|
||||
public:
|
||||
MOO_DEFINE_GOBJREF_METHODS (GtkTreeView);
|
||||
|
||||
static gtk::TreeViewPtr create (gtk::TreeModelPtr model);
|
||||
|
||||
gtk::TreeModelPtr get_model ();
|
||||
void set_model (gtk::TreeModelPtr model);
|
||||
GtkTreeSelection* get_selection ();
|
||||
GtkAdjustment* get_hadjustment ();
|
||||
void set_hadjustment (GtkAdjustment* adjustment);
|
||||
GtkAdjustment* get_vadjustment ();
|
||||
void set_vadjustment (GtkAdjustment* adjustment);
|
||||
bool get_headers_visible ();
|
||||
void set_headers_visible (bool headers_visible);
|
||||
void columns_autosize ();
|
||||
bool get_headers_clickable ();
|
||||
void set_headers_clickable (bool setting);
|
||||
void set_rules_hint (bool setting);
|
||||
bool get_rules_hint ();
|
||||
|
||||
/* Column funtions */
|
||||
int append_column (gtk::TreeViewColumn& column);
|
||||
int remove_column (gtk::TreeViewColumn& column);
|
||||
int insert_column (gtk::TreeViewColumn& column,
|
||||
int position);
|
||||
int insert_column_with_attributes (int position,
|
||||
const char* title,
|
||||
gtk::CellRenderer& cell,
|
||||
...) G_GNUC_NULL_TERMINATED;
|
||||
|
||||
template<typename TFunc>
|
||||
int insert_column_with_data_func (int position,
|
||||
const char* title,
|
||||
gtk::CellRenderer& cell,
|
||||
TFunc func);
|
||||
|
||||
gtk::TreeViewColumnPtr get_column (int n);
|
||||
std::vector<gtk::TreeViewColumnPtr> get_columns ();
|
||||
void move_column_after (gtk::TreeViewColumn& column,
|
||||
gtk::TreeViewColumn& base_column);
|
||||
void set_expander_column (gtk::TreeViewColumn& column);
|
||||
gtk::TreeViewColumnPtr get_expander_column ();
|
||||
void set_column_drag_function (GtkTreeViewColumnDropFunc func,
|
||||
gpointer user_data,
|
||||
GDestroyNotify destroy);
|
||||
|
||||
/* Actions */
|
||||
void scroll_to_point (int tree_x,
|
||||
int tree_y);
|
||||
void scroll_to_cell (GtkTreePath* path,
|
||||
gtk::TreeViewColumn& column,
|
||||
bool use_align,
|
||||
float row_align,
|
||||
float col_align);
|
||||
void row_activated (GtkTreePath* path,
|
||||
gtk::TreeViewColumn& column);
|
||||
void expand_all ();
|
||||
void collapse_all ();
|
||||
void expand_to_path (GtkTreePath* path);
|
||||
bool expand_row (GtkTreePath* path,
|
||||
bool open_all);
|
||||
bool collapse_row (GtkTreePath* path);
|
||||
void map_expanded_rows (GtkTreeViewMappingFunc func,
|
||||
gpointer data);
|
||||
bool row_expanded (GtkTreePath* path);
|
||||
void set_reorderable (bool reorderable);
|
||||
bool get_reorderable ();
|
||||
void set_cursor (GtkTreePath* path,
|
||||
gtk::TreeViewColumn& focus_column,
|
||||
bool start_editing);
|
||||
void set_cursor_on_cell (GtkTreePath* path,
|
||||
gtk::TreeViewColumn& focus_column,
|
||||
gtk::CellRenderer& focus_cell,
|
||||
bool start_editing);
|
||||
void get_cursor (GtkTreePath** path,
|
||||
gtk::TreeViewColumnPtr& focus_column);
|
||||
|
||||
/* Layout information */
|
||||
GdkWindow* get_bin_window ();
|
||||
bool get_path_at_pos (int x,
|
||||
int y,
|
||||
GtkTreePath** path,
|
||||
gtk::TreeViewColumnPtr& column,
|
||||
int* cell_x,
|
||||
int* cell_y);
|
||||
void get_cell_area (GtkTreePath* path,
|
||||
gtk::TreeViewColumn& column,
|
||||
GdkRectangle& rect);
|
||||
void get_background_area (GtkTreePath* path,
|
||||
gtk::TreeViewColumn& column,
|
||||
GdkRectangle& rect);
|
||||
void get_visible_rect (GdkRectangle& visible_rect);
|
||||
|
||||
bool get_visible_range (GtkTreePath** start_path,
|
||||
GtkTreePath** end_path);
|
||||
|
||||
/* Drag-and-Drop support */
|
||||
void enable_model_drag_source (GdkModifierType start_button_mask,
|
||||
const GtkTargetEntry* targets,
|
||||
int n_targets,
|
||||
GdkDragAction actions);
|
||||
void enable_model_drag_dest (const GtkTargetEntry* targets,
|
||||
int n_targets,
|
||||
GdkDragAction actions);
|
||||
void unset_rows_drag_source ();
|
||||
void unset_rows_drag_dest ();
|
||||
|
||||
/* These are useful to implement your own custom stuff. */
|
||||
void set_drag_dest_row (GtkTreePath* path,
|
||||
GtkTreeViewDropPosition pos);
|
||||
void get_drag_dest_row (GtkTreePath** path,
|
||||
GtkTreeViewDropPosition* pos);
|
||||
bool get_dest_row_at_pos (int drag_x,
|
||||
int drag_y,
|
||||
GtkTreePath** path,
|
||||
GtkTreeViewDropPosition* pos);
|
||||
GdkPixmap* create_row_drag_icon (GtkTreePath* path);
|
||||
|
||||
/* Interactive search */
|
||||
void set_enable_search (bool enable_search);
|
||||
bool get_enable_search ();
|
||||
int get_search_column ();
|
||||
void set_search_column (int column);
|
||||
GtkTreeViewSearchEqualFunc get_search_equal_func ();
|
||||
void set_search_equal_func (GtkTreeViewSearchEqualFunc search_equal_func,
|
||||
gpointer search_user_data,
|
||||
GDestroyNotify search_destroy);
|
||||
|
||||
GtkEntry* get_search_entry ();
|
||||
void set_search_entry (GtkEntry* entry);
|
||||
GtkTreeViewSearchPositionFunc get_search_position_func ();
|
||||
void set_search_position_func (GtkTreeViewSearchPositionFunc func,
|
||||
gpointer data,
|
||||
GDestroyNotify destroy);
|
||||
|
||||
/* Convert between the different coordinate systems */
|
||||
void convert_widget_to_tree_coords (int wx,
|
||||
int wy,
|
||||
int* tx,
|
||||
int* ty);
|
||||
void convert_tree_to_widget_coords (int tx,
|
||||
int ty,
|
||||
int* wx,
|
||||
int* wy);
|
||||
void convert_widget_to_bin_window_coords (int wx,
|
||||
int wy,
|
||||
int* bx,
|
||||
int* by);
|
||||
void convert_bin_window_to_widget_coords (int bx,
|
||||
int by,
|
||||
int* wx,
|
||||
int* wy);
|
||||
void convert_tree_to_bin_window_coords (int tx,
|
||||
int ty,
|
||||
int* bx,
|
||||
int* by);
|
||||
void convert_bin_window_to_tree_coords (int bx,
|
||||
int by,
|
||||
int* tx,
|
||||
int* ty);
|
||||
|
||||
void set_fixed_height_mode (bool enable);
|
||||
bool get_fixed_height_mode ();
|
||||
void set_hover_selection (bool hover);
|
||||
bool get_hover_selection ();
|
||||
void set_hover_expand (bool expand);
|
||||
bool get_hover_expand ();
|
||||
void set_rubber_banding (bool enable);
|
||||
bool get_rubber_banding ();
|
||||
|
||||
bool is_rubber_banding_active ();
|
||||
|
||||
GtkTreeViewRowSeparatorFunc get_row_separator_func ();
|
||||
void set_row_separator_func (GtkTreeViewRowSeparatorFunc func,
|
||||
gpointer data,
|
||||
GDestroyNotify destroy);
|
||||
|
||||
GtkTreeViewGridLines get_grid_lines ();
|
||||
void set_grid_lines (GtkTreeViewGridLines grid_lines);
|
||||
bool get_enable_tree_lines ();
|
||||
void set_enable_tree_lines (bool enabled);
|
||||
void set_show_expanders (bool enabled);
|
||||
bool get_show_expanders ();
|
||||
void set_level_indentation (int indentation);
|
||||
int get_level_indentation ();
|
||||
|
||||
/* Convenience functions for setting tooltips */
|
||||
void set_tooltip_row (GtkTooltip* tooltip,
|
||||
GtkTreePath* path);
|
||||
void set_tooltip_cell (GtkTooltip* tooltip,
|
||||
GtkTreePath* path,
|
||||
gtk::TreeViewColumn& column,
|
||||
gtk::CellRenderer& cell);
|
||||
bool get_tooltip_context (int* x,
|
||||
int* y,
|
||||
bool keyboard_tip,
|
||||
GtkTreeModel** model,
|
||||
GtkTreePath** path,
|
||||
GtkTreeIter* iter);
|
||||
void set_tooltip_column (int column);
|
||||
int get_tooltip_column ();
|
||||
};
|
||||
|
||||
template<>
|
||||
class moo::gobj_ref<GtkTreeViewColumn> : public virtual moo::gobj_ref_parent<GtkTreeViewColumn>
|
||||
{
|
||||
public:
|
||||
MOO_DEFINE_GOBJREF_METHODS (GtkTreeViewColumn);
|
||||
|
||||
static gtk::TreeViewColumnPtr create ();
|
||||
static gtk::TreeViewColumnPtr create (const char* title,
|
||||
gtk::CellRendererPtr cell,
|
||||
...) G_GNUC_NULL_TERMINATED;
|
||||
|
||||
void pack_start (gtk::CellRenderer& cell,
|
||||
bool expand);
|
||||
void pack_end (gtk::CellRenderer& cell,
|
||||
bool expand);
|
||||
void clear ();
|
||||
std::vector<gtk::CellRendererPtr> get_cell_renderers ();
|
||||
void add_attribute (gtk::CellRenderer& cell,
|
||||
const char* attribute,
|
||||
int column);
|
||||
|
||||
void set_attributes (gtk::CellRenderer& cell_renderer, const char* prop, int column);
|
||||
|
||||
template<typename... Args>
|
||||
void set_attributes (gtk::CellRenderer& cell_renderer, const char* prop, int column, Args&&... args)
|
||||
{
|
||||
set_attributes (cell_renderer, prop, column);
|
||||
set_attributes (cell_renderer, std::forward<Args> (args)...);
|
||||
}
|
||||
|
||||
// void TFunc(gtk::TreeViewColumn, gtk::CellRenderer, gtk::TreeModel, const GtkTreeIter&)
|
||||
template<typename TFunc>
|
||||
inline void set_cell_data_func (gtk::CellRenderer& cell_renderer, TFunc func);
|
||||
|
||||
void clear_attributes (gtk::CellRenderer& cell_renderer);
|
||||
void set_spacing (int spacing);
|
||||
int get_spacing ();
|
||||
void set_visible (bool visible);
|
||||
bool get_visible ();
|
||||
void set_resizable (bool resizable);
|
||||
bool get_resizable ();
|
||||
void set_sizing (GtkTreeViewColumnSizing type);
|
||||
GtkTreeViewColumnSizing get_sizing ();
|
||||
int get_width ();
|
||||
int get_fixed_width ();
|
||||
void set_fixed_width (int fixed_width);
|
||||
void set_min_width (int min_width);
|
||||
int get_min_width ();
|
||||
void set_max_width (int max_width);
|
||||
int get_max_width ();
|
||||
void clicked ();
|
||||
|
||||
/* Options for manipulating the column headers
|
||||
*/
|
||||
void set_title (const char* title);
|
||||
gstr get_title ();
|
||||
void set_expand (bool expand);
|
||||
bool get_expand ();
|
||||
void set_clickable (bool clickable);
|
||||
bool get_clickable ();
|
||||
void set_widget (gtk::WidgetPtr widget);
|
||||
gtk::WidgetPtr get_widget ();
|
||||
void set_alignment (float xalign);
|
||||
float get_alignment ();
|
||||
void set_reorderable (bool reorderable);
|
||||
bool get_reorderable ();
|
||||
|
||||
/* You probably only want to use gtk_tree_view_column_set_sort_column_id. The
|
||||
* other sorting functions exist primarily to let others do their own custom sorting.
|
||||
*/
|
||||
void set_sort_column_id (int sort_column_id);
|
||||
int get_sort_column_id ();
|
||||
void set_sort_indicator (bool setting);
|
||||
bool get_sort_indicator ();
|
||||
void set_sort_order (GtkSortType order);
|
||||
GtkSortType get_sort_order ();
|
||||
|
||||
gtk::TreeViewPtr get_tree_view ();
|
||||
};
|
||||
|
||||
template<>
|
||||
class moo::gobj_ref<GtkCellRenderer> : public virtual moo::gobj_ref_parent<GtkCellRenderer>
|
||||
{
|
||||
public:
|
||||
MOO_DEFINE_GOBJREF_METHODS (GtkCellRenderer);
|
||||
};
|
||||
|
||||
template<>
|
||||
class moo::gobj_ref<GtkCellRendererText> : public virtual moo::gobj_ref_parent<GtkCellRendererText>
|
||||
{
|
||||
public:
|
||||
MOO_DEFINE_GOBJREF_METHODS (GtkCellRendererText);
|
||||
|
||||
static gtk::CellRendererTextPtr create ();
|
||||
|
||||
void set_fixed_height_from_font (int number_of_rows);
|
||||
};
|
||||
|
||||
template<>
|
||||
class moo::gobj_ref<GtkCellRendererToggle> : public virtual moo::gobj_ref_parent<GtkCellRendererToggle>
|
||||
{
|
||||
public:
|
||||
MOO_DEFINE_GOBJREF_METHODS (GtkCellRendererToggle);
|
||||
|
||||
static gtk::CellRendererTogglePtr create ();
|
||||
|
||||
bool get_radio ();
|
||||
void set_radio (bool radio);
|
||||
bool get_active ();
|
||||
void set_active (bool active);
|
||||
};
|
||||
|
||||
template<>
|
||||
class moo::gobj_ref<GtkCellRendererPixbuf> : public virtual moo::gobj_ref_parent<GtkCellRendererPixbuf>
|
||||
{
|
||||
public:
|
||||
MOO_DEFINE_GOBJREF_METHODS (GtkCellRendererPixbuf);
|
||||
|
||||
static gtk::CellRendererPixbufPtr create ();
|
||||
};
|
||||
|
||||
|
||||
template<typename TFunc>
|
||||
inline void
|
||||
TreeCellDataFunc<TFunc>::cell_data_func (GtkTreeViewColumn *tree_column,
|
||||
GtkCellRenderer *cell,
|
||||
GtkTreeModel *tree_model,
|
||||
GtkTreeIter *iter,
|
||||
gpointer p)
|
||||
{
|
||||
g_return_if_fail (GTK_IS_TREE_VIEW_COLUMN (tree_column));
|
||||
g_return_if_fail (GTK_IS_CELL_RENDERER (cell));
|
||||
g_return_if_fail (GTK_IS_TREE_MODEL (tree_model));
|
||||
g_return_if_fail (iter != nullptr);
|
||||
g_return_if_fail (p != nullptr);
|
||||
TreeCellDataFunc& data = *reinterpret_cast<TreeCellDataFunc*>(p);
|
||||
data.m_func (moo::wrap (*tree_column), moo::wrap (*cell), moo::wrap (*tree_model),
|
||||
const_cast<const GtkTreeIter&>(*iter));
|
||||
}
|
||||
|
||||
|
||||
template<typename TFunc>
|
||||
inline int
|
||||
moo::gobj_ref<GtkTreeView>::insert_column_with_data_func (int position,
|
||||
const char* title,
|
||||
gtk::CellRenderer& cell,
|
||||
TFunc func)
|
||||
{
|
||||
TreeCellDataFunc<TFunc> *data = new TreeCellDataFunc<TFunc>{ std::move (func) };
|
||||
return gtk_tree_view_insert_column_with_data_func (gobj (), position, title, cell.gobj (),
|
||||
TreeCellDataFunc<TFunc>::cell_data_func, data,
|
||||
TreeCellDataFunc<TFunc>::destroy);
|
||||
}
|
||||
|
||||
|
||||
// void TFunc(gtk::TreeViewColumn, gtk::CellRenderer, gtk::TreeModel, const GtkTreeIter&)
|
||||
template<typename TFunc>
|
||||
inline void
|
||||
moo::gobj_ref<GtkTreeViewColumn>::set_cell_data_func (gtk::CellRenderer& cell_renderer, TFunc func)
|
||||
{
|
||||
TreeCellDataFunc<TFunc> *data = new TreeCellDataFunc<TFunc>{ std::move (func) };
|
||||
gtk_tree_view_column_set_cell_data_func (gobj (), cell_renderer.gobj (),
|
||||
TreeCellDataFunc<TFunc>::cell_data_func, data,
|
||||
TreeCellDataFunc<TFunc>::destroy);
|
||||
}
|
||||
|
||||
MOO_DEFINE_FLAGS(GdkEventMask);
|
||||
MOO_DEFINE_FLAGS(GdkModifierType);
|
||||
MOO_DEFINE_FLAGS(GtkCellRendererState);
|
||||
MOO_DEFINE_FLAGS(GtkAttachOptions);
|
||||
MOO_DEFINE_FLAGS(GdkDragAction);
|
||||
|
||||
#endif // 0
|
||||
|
||||
} // namespace gtk
|
|
@ -1,62 +0,0 @@
|
|||
/*
|
||||
* moogpp/gparam.h
|
||||
*
|
||||
* Copyright (C) 2004-2016 by Yevgen Muntyan <emuntyan@users.sourceforge.net>
|
||||
*
|
||||
* This file is part of medit. medit 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.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public
|
||||
* License along with medit. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#pragma once
|
||||
|
||||
#ifndef __cplusplus
|
||||
#error "This is a C++ header"
|
||||
#endif
|
||||
|
||||
#include <moogpp/strutils.h>
|
||||
#include <memory>
|
||||
#include <utility>
|
||||
#include <vector>
|
||||
|
||||
namespace g {
|
||||
|
||||
// Bit-compatible with GValue
|
||||
class Value : public GValue
|
||||
{
|
||||
public:
|
||||
Value();
|
||||
~Value();
|
||||
|
||||
Value(Value&&);
|
||||
Value& operator=(Value&&);
|
||||
|
||||
Value(const Value&) = delete;
|
||||
Value& operator=(const Value&) = delete;
|
||||
|
||||
void init(GType type);
|
||||
};
|
||||
|
||||
// Bit-compatible with GParameter
|
||||
class Parameter : public GParameter
|
||||
{
|
||||
public:
|
||||
explicit Parameter(const char* name = nullptr);
|
||||
~Parameter();
|
||||
|
||||
Parameter(Parameter&&);
|
||||
Parameter& operator=(Parameter&&);
|
||||
|
||||
Parameter(const Parameter&) = delete;
|
||||
Parameter& operator=(const Parameter&) = delete;
|
||||
};
|
||||
|
||||
using ValueArray = std::vector<Value>;
|
||||
using ParameterArray = std::vector<Parameter>;
|
||||
|
||||
} // namespace g
|
|
@ -1,130 +0,0 @@
|
|||
/*
|
||||
* moocpp/gutil.cpp
|
||||
*
|
||||
* Copyright (C) 2004-2016 by Yevgen Muntyan <emuntyan@users.sourceforge.net>
|
||||
*
|
||||
* This file is part of medit. medit 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.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public
|
||||
* License along with medit. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#include "moocpp/gutil.h"
|
||||
|
||||
namespace moo {
|
||||
namespace g {
|
||||
|
||||
gstr filename_to_utf8 (const char* opsysstring)
|
||||
{
|
||||
return gstr::wrap_new (g_filename_to_utf8 (opsysstring, -1, nullptr, nullptr, nullptr));
|
||||
}
|
||||
|
||||
gstr filename_from_utf8 (const gchar* utf8string)
|
||||
{
|
||||
return gstr::wrap_new (g_filename_from_utf8 (utf8string, -1, nullptr, nullptr, nullptr));
|
||||
}
|
||||
|
||||
gstr build_filename (const char* c1, const char* c2, const char* c3, const char* c4, const char* c5)
|
||||
{
|
||||
return gstr::wrap_new (g_build_filename (c1, c2, c3, c4, c5, nullptr));
|
||||
}
|
||||
|
||||
gstr filename_to_uri (const char* filename)
|
||||
{
|
||||
return gstr::wrap_new (g_filename_to_uri (filename, nullptr, nullptr));
|
||||
}
|
||||
|
||||
gstr filename_from_uri (const char *uri)
|
||||
{
|
||||
return gstr::wrap_new (g_filename_from_uri (uri, nullptr, nullptr));
|
||||
}
|
||||
|
||||
gstr path_get_dirname (const char* filename)
|
||||
{
|
||||
return gstr::wrap_new (g_path_get_dirname (filename));
|
||||
}
|
||||
|
||||
gstr filename_display_name (const char* filename)
|
||||
{
|
||||
return gstr::wrap_new (g_filename_display_name (filename));
|
||||
}
|
||||
|
||||
gstr filename_display_basename (const char* filename)
|
||||
{
|
||||
return gstr::wrap_new (g_filename_display_basename (filename));
|
||||
}
|
||||
|
||||
bool file_get_contents (const char* path, gstr& data, gsize& data_len, gerrp& error)
|
||||
{
|
||||
gstrp contents;
|
||||
|
||||
if (!g_file_get_contents (path, contents.pp (), &data_len, &error))
|
||||
{
|
||||
data.reset ();
|
||||
return false;
|
||||
}
|
||||
|
||||
data = gstr::wrap_new (contents.release ());
|
||||
return true;
|
||||
}
|
||||
|
||||
gstr uri_escape_string (const char* unescaped, const char* reserved_chars_allowed, bool allow_utf8)
|
||||
{
|
||||
return gstr::wrap_new (g_uri_escape_string (unescaped, reserved_chars_allowed, allow_utf8));
|
||||
}
|
||||
|
||||
gstr get_current_dir ()
|
||||
{
|
||||
return gstr::wrap_new (g_get_current_dir ());
|
||||
}
|
||||
|
||||
gstr locale_to_utf8 (const char* str)
|
||||
{
|
||||
return gstr::wrap_new (g_locale_to_utf8 (str, -1, nullptr, nullptr, nullptr));
|
||||
}
|
||||
|
||||
gstr convert (const char* str, gssize len, const char* to_codeset, const char* from_codeset, gsize& bytes_read, gsize& bytes_written, gerrp& error)
|
||||
{
|
||||
return gstr::wrap_new (g_convert (str, len, to_codeset, from_codeset, &bytes_read, &bytes_written, &error));
|
||||
}
|
||||
|
||||
gstr utf8_normalize (const char* str, GNormalizeMode mode)
|
||||
{
|
||||
return gstr::wrap_new (g_utf8_normalize (str, -1, mode));
|
||||
}
|
||||
|
||||
gstr utf8_strup (const char* str)
|
||||
{
|
||||
return gstr::wrap_new (g_utf8_strup (str, -1));
|
||||
}
|
||||
|
||||
gstr utf8_strdown (const char* str)
|
||||
{
|
||||
return gstr::wrap_new (g_utf8_strdown (str, -1));
|
||||
}
|
||||
|
||||
gstr markup_vprintf_escaped (const char* fmt, va_list args)
|
||||
{
|
||||
return gstr::wrap_new (g_markup_vprintf_escaped (fmt, args));
|
||||
}
|
||||
|
||||
#ifdef __WIN32__
|
||||
|
||||
gstr win32_error_message (guint32 code)
|
||||
{
|
||||
return gstr::wrap_new (g_win32_error_message (code));
|
||||
}
|
||||
|
||||
gstr utf16_to_utf8 (const wchar_t* str)
|
||||
{
|
||||
return gstr::wrap_new (g_utf16_to_utf8 (reinterpret_cast<const gunichar2*>(str), -1, nullptr, nullptr, nullptr));
|
||||
}
|
||||
|
||||
#endif // __WIN32__
|
||||
|
||||
} // namespace g
|
||||
} // namespace moo
|
|
@ -1,62 +0,0 @@
|
|||
/*
|
||||
* moogpp/gutil.h
|
||||
*
|
||||
* Copyright (C) 2004-2016 by Yevgen Muntyan <emuntyan@users.sourceforge.net>
|
||||
*
|
||||
* This file is part of medit. medit 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.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public
|
||||
* License along with medit. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#pragma once
|
||||
|
||||
#ifndef __cplusplus
|
||||
#error "This is a C++ header"
|
||||
#endif
|
||||
|
||||
#include <memory>
|
||||
#include <utility>
|
||||
#include <moogpp/strutils.h>
|
||||
|
||||
namespace g {
|
||||
|
||||
gstr build_filename(const char* c1, const char* c2, const char* c3 = nullptr, const char* c4 = nullptr, const char* c5 = nullptr);
|
||||
gstr filename_to_uri(const char* filename);
|
||||
gstr filename_from_uri(const char *uri);
|
||||
gstr path_get_dirname (const char* filename);
|
||||
gstr path_get_basename (const char* filename);
|
||||
gstr filename_display_name (const char* filename);
|
||||
gstr filename_display_basename (const char* filename);
|
||||
bool file_get_contents (const char* path, gstr& data, gsize& data_len, gerrp& error);
|
||||
gstr uri_escape_string(const char* unescaped, const char* reserved_chars_allowed = nullptr, bool allow_utf8 = false);
|
||||
gstr filename_to_utf8 (const char* opsysstring);
|
||||
gstr filename_from_utf8(const gchar* utf8string);
|
||||
|
||||
gstr get_current_dir();
|
||||
|
||||
gstr locale_to_utf8(const char* str);
|
||||
gstr convert(const char* str, gssize len, const char* to_codeset, const char* from_codeset, gsize& bytes_read, gsize& bytes_written, gerrp& error);
|
||||
|
||||
gstr utf8_normalize(const char* str, GNormalizeMode mode);
|
||||
gstr utf8_strup(const char* str);
|
||||
gstr utf8_strdown(const char* str);
|
||||
|
||||
gstr markup_vprintf_escaped(const char* fmt, va_list args) G_GNUC_PRINTF (1, 0);
|
||||
|
||||
template<typename ...Args>
|
||||
inline gstr markup_printf_escaped (const char* format, Args&& ...args)
|
||||
{
|
||||
return gstr::wrap_new (printf_helper::callv (g_markup_printf_escaped, format, std::forward<Args> (args)...));
|
||||
}
|
||||
|
||||
#ifdef __WIN32__
|
||||
gstr win32_error_message(guint32 code);
|
||||
gstr utf16_to_utf8(const wchar_t* str);
|
||||
#endif // __WIN32__
|
||||
|
||||
} // namespace g
|
|
@ -1,166 +0,0 @@
|
|||
/*
|
||||
* moogpp/memutils.h
|
||||
*
|
||||
* Copyright (C) 2004-2016 by Yevgen Muntyan <emuntyan@users.sourceforge.net>
|
||||
*
|
||||
* This file is part of medit. medit 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.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public
|
||||
* License along with medit. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#pragma once
|
||||
|
||||
#ifndef __cplusplus
|
||||
#error "This is a C++ header"
|
||||
#endif
|
||||
|
||||
#include <algorithm>
|
||||
#include <memory>
|
||||
#include <vector>
|
||||
#include <utility>
|
||||
|
||||
#include <glib.h>
|
||||
|
||||
void extern_g_free(gpointer);
|
||||
void extern_g_object_unref(gpointer);
|
||||
void extern_g_strfreev(char**);
|
||||
|
||||
namespace g {
|
||||
|
||||
enum class mem_transfer
|
||||
{
|
||||
take_ownership,
|
||||
borrow,
|
||||
make_copy
|
||||
};
|
||||
|
||||
template<typename T>
|
||||
class gbuf
|
||||
{
|
||||
public:
|
||||
explicit gbuf(T* p = nullptr) : m_p(p) {}
|
||||
~gbuf() { ::g_free(m_p); }
|
||||
|
||||
void set_new(T* p) { if (m_p != p) { ::g_free(m_p); m_p = p; } }
|
||||
operator const T*() const { return m_p; }
|
||||
T* get() const { return m_p; }
|
||||
T*& _get() { return m_p; }
|
||||
T* operator->() const { return m_p; }
|
||||
|
||||
operator T*() const = delete;
|
||||
T** operator&() = delete;
|
||||
|
||||
T* release() { T* p = m_p; m_p = nullptr; return p; }
|
||||
|
||||
gbuf(const gbuf&) = delete;
|
||||
gbuf& operator=(const gbuf&) = delete;
|
||||
|
||||
gbuf(gbuf&& other) : gbuf() { std::swap(m_p, other.m_p); }
|
||||
gbuf& operator=(gbuf&& other) { std::swap(m_p, other.m_p); return *this; }
|
||||
|
||||
operator bool() const { return m_p != nullptr; }
|
||||
bool operator !() const { return m_p == nullptr; }
|
||||
|
||||
private:
|
||||
T* m_p;
|
||||
};
|
||||
|
||||
#define MOO_DEFINE_STANDARD_PTR_METHODS_INLINE(Self, Super) \
|
||||
Self() : Super() {} \
|
||||
Self(const nullptr_t&) : Super(nullptr) {} \
|
||||
Self(const Self& other) = delete; \
|
||||
Self(Self&& other) : Super(std::move(other)) {} \
|
||||
\
|
||||
Self& operator=(const Self& other) = delete; \
|
||||
\
|
||||
Self& operator=(Self&& other) \
|
||||
{ \
|
||||
static_cast<Super&>(*this) = std::move(static_cast<Super&&>(other)); \
|
||||
return *this; \
|
||||
} \
|
||||
\
|
||||
Self& operator=(const nullptr_t&) \
|
||||
{ \
|
||||
static_cast<Super&>(*this) = nullptr; \
|
||||
return *this; \
|
||||
}
|
||||
|
||||
#define MOO_DECLARE_STANDARD_PTR_METHODS(Self, Super) \
|
||||
Self(); \
|
||||
Self(const nullptr_t&); \
|
||||
Self(const Self& other) = delete; \
|
||||
Self(Self&& other); \
|
||||
Self& operator=(const Self& other) = delete; \
|
||||
Self& operator=(Self&& other); \
|
||||
Self& operator=(const nullptr_t&);
|
||||
|
||||
#define MOO_DEFINE_STANDARD_PTR_METHODS(Self, Super) \
|
||||
Self::Self() : Super() {} \
|
||||
Self::Self(const nullptr_t&) : Super(nullptr) {} \
|
||||
Self::Self(Self&& other) : Super(std::move(other)) {} \
|
||||
\
|
||||
Self& Self::operator=(Self&& other) \
|
||||
{ \
|
||||
static_cast<Super&>(*this) = std::move(static_cast<Super&&>(other)); \
|
||||
return *this; \
|
||||
} \
|
||||
\
|
||||
Self& Self::operator=(const nullptr_t&) \
|
||||
{ \
|
||||
static_cast<Super&>(*this) = nullptr; \
|
||||
return *this; \
|
||||
}
|
||||
|
||||
|
||||
template<typename T>
|
||||
class objp
|
||||
{
|
||||
public:
|
||||
objp (T* p = nullptr) : m_p(p) {}
|
||||
~objp () { delete m_p; }
|
||||
|
||||
template<class... Args>
|
||||
static objp make (Args&&... args)
|
||||
{
|
||||
return objp (new T (std::forward<Args> (args)...));
|
||||
}
|
||||
|
||||
objp (objp&& other) : objp () { *this = std::move (other); }
|
||||
objp& operator=(objp&& other) { std::swap (m_p, other.m_p); return *this; }
|
||||
|
||||
T* get() const { return m_p; }
|
||||
T** pp () { g_return_val_if_fail (m_p == nullptr, nullptr); return &m_p; }
|
||||
T* operator->() const { return m_p; }
|
||||
operator const T*() const { return m_p; }
|
||||
|
||||
operator T*() const = delete;
|
||||
T** operator&() = delete;
|
||||
|
||||
objp(const objp&) = delete;
|
||||
objp& operator=(const objp&) = delete;
|
||||
|
||||
void set (T* p) { if (m_p != p) { delete m_p; m_p = p; } }
|
||||
void reset (T* p = nullptr) { set (p); }
|
||||
T* release () { T* p = m_p; m_p = nullptr; return p; }
|
||||
|
||||
bool operator==(const T* p) const { return m_p == p; }
|
||||
bool operator!=(const T* p) const { return m_p != p; }
|
||||
|
||||
operator bool () const { return m_p != nullptr; }
|
||||
bool operator !() const { return m_p == nullptr; }
|
||||
|
||||
private:
|
||||
T* m_p;
|
||||
};
|
||||
|
||||
} // namespace g
|
||||
|
||||
template<typename T>
|
||||
void g_free(const g::gbuf<T>&) = delete;
|
||||
template<typename T>
|
||||
void g_free (const g::objp<T>&) = delete;
|
|
@ -1,20 +0,0 @@
|
|||
SET(moogpp_sources
|
||||
moogpp/moogpp.cmake
|
||||
moogpp/gobjectutils.h
|
||||
moogpp/gobj.h
|
||||
moogpp/gobj.cpp
|
||||
moogpp/gobjtypes-gio.h
|
||||
moogpp/gobjtypes-gio.cpp
|
||||
moogpp/gobjtypes-glib.h
|
||||
moogpp/gobjtypes-glib.cpp
|
||||
moogpp/gobjtypes-gtk.h
|
||||
moogpp/gobjtypes-gtk.cpp
|
||||
moogpp/gparam.h
|
||||
moogpp/moogpp.h
|
||||
moogpp/gutil.h
|
||||
moogpp/gutil.cpp
|
||||
moogpp/memutils.h
|
||||
moogpp/strutils.h
|
||||
moogpp/strutils.cpp
|
||||
moogpp/utils.h
|
||||
)
|
|
@ -1,32 +0,0 @@
|
|||
/*
|
||||
* moogpp/moogpp.h
|
||||
*
|
||||
* Copyright (C) 2004-2016 by Yevgen Muntyan <emuntyan@users.sourceforge.net>
|
||||
*
|
||||
* This file is part of medit. medit 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.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public
|
||||
* License along with medit. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#pragma once
|
||||
|
||||
#ifndef __cplusplus
|
||||
#error "This is a C++ header"
|
||||
#endif
|
||||
|
||||
#include <gtk/gtk.h>
|
||||
|
||||
#include <moogpp/gparam.h>
|
||||
#include <moogpp/memutils.h>
|
||||
#include <moogpp/gutil.h>
|
||||
#include <moogpp/strutils.h>
|
||||
#include <moogpp/gobjectutils.h>
|
||||
|
||||
#include <moogpp/gobjtypes-glib.h>
|
||||
#include <moogpp/gobjtypes-gio.h>
|
||||
#include <moogpp/gobjtypes-gtk.h>
|
|
@ -1,134 +0,0 @@
|
|||
/*
|
||||
* moocpp/gobjinfo.h
|
||||
*
|
||||
* Copyright (C) 2004-2016 by Yevgen Muntyan <emuntyan@users.sourceforge.net>
|
||||
*
|
||||
* This file is part of medit. medit 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.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public
|
||||
* License along with medit. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#pragma once
|
||||
|
||||
#ifdef __cplusplus
|
||||
|
||||
#include <glib-object.h>
|
||||
#include <type_traits>
|
||||
#include <moocpp/strutils.h>
|
||||
|
||||
namespace moo {
|
||||
|
||||
void init_gobj_system ();
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////////////////////
|
||||
//
|
||||
// gobjinfo
|
||||
//
|
||||
|
||||
template<typename Object, typename Super>
|
||||
struct gobj_is_subclass
|
||||
{
|
||||
static const bool value = false;
|
||||
};
|
||||
|
||||
// Generic implementation, all we know it's a subclass of GObject; we don't
|
||||
// even know its GType. This implementation is needed so that it's possible
|
||||
// to have gobj_ptr<GAnything> without having to define gobjinfo for it.
|
||||
template<typename Object>
|
||||
struct gobjinfo
|
||||
{
|
||||
static const bool is_gobject = true;
|
||||
using object_type = Object;
|
||||
using parent_type = GObject;
|
||||
// object_g_type() is not defined
|
||||
};
|
||||
|
||||
template<>
|
||||
struct gobjinfo<GObject>
|
||||
{
|
||||
static const bool is_gobject = true;
|
||||
using object_type = GObject;
|
||||
static GType object_g_type() { return G_TYPE_OBJECT; }
|
||||
};
|
||||
|
||||
template<typename T>
|
||||
inline GType get_g_type()
|
||||
{
|
||||
return gobjinfo<T>::object_g_type();
|
||||
}
|
||||
|
||||
template<>
|
||||
struct gobj_is_subclass<GObject, GObject>
|
||||
{
|
||||
static const bool value = true;
|
||||
static GObject* down_cast(GObject* o) { return o; }
|
||||
};
|
||||
|
||||
#define MOO_DEFINE_GOBJ_TYPE(Object, Parent, g_type) \
|
||||
namespace moo { \
|
||||
\
|
||||
template<> \
|
||||
struct gobjinfo<Object> \
|
||||
{ \
|
||||
static const bool is_gobject = true; \
|
||||
using object_type = Object; \
|
||||
using parent_type = Parent; \
|
||||
static GType object_g_type() { return g_type; } \
|
||||
}; \
|
||||
\
|
||||
template<> \
|
||||
struct gobj_is_subclass<Object, Object> \
|
||||
{ \
|
||||
static const bool value = true; \
|
||||
static Object* down_cast(Object* o) { return o; } \
|
||||
}; \
|
||||
\
|
||||
template<typename Super> \
|
||||
struct gobj_is_subclass<Object, Super> \
|
||||
{ \
|
||||
static const bool value = true; \
|
||||
static Super* down_cast(Object *o) \
|
||||
{ \
|
||||
static_assert(gobj_is_subclass<Object, Super>::value, \
|
||||
"Super is not a superclass of " #Object); \
|
||||
Parent* p = reinterpret_cast<Parent*>(o); \
|
||||
Super* s = gobj_is_subclass<Parent, Super>::down_cast(p); \
|
||||
return s; \
|
||||
} \
|
||||
}; \
|
||||
} \
|
||||
|
||||
#define MOO_DEFINE_GIFACE_TYPE(Iface, g_type) \
|
||||
MOO_DEFINE_GOBJ_TYPE(Iface, GObject, g_type)
|
||||
|
||||
#define MOO_GOBJ_IMPLEMENTS_IFACE(Object, Iface) \
|
||||
namespace moo { \
|
||||
\
|
||||
template<> \
|
||||
struct gobj_is_subclass<Object, Iface> \
|
||||
{ \
|
||||
static const bool value = true; \
|
||||
static Iface* down_cast(Object *o) \
|
||||
{ \
|
||||
return reinterpret_cast<Iface*>(o); \
|
||||
} \
|
||||
}; \
|
||||
} \
|
||||
|
||||
|
||||
#define MOO_DEFINE_NON_GOBJ_TYPE(Object) \
|
||||
namespace moo { \
|
||||
template<> struct gobjinfo<Object> { static const bool is_gobject = false; }; \
|
||||
}
|
||||
|
||||
template<typename Object>
|
||||
using gobj_parent_type = typename gobjinfo<Object>::parent_type;
|
||||
|
||||
} // namespace moo
|
||||
|
||||
#endif // __cplusplus
|
|
@ -1,313 +0,0 @@
|
|||
/*
|
||||
* moocpp/gobjptr.h
|
||||
*
|
||||
* Copyright (C) 2004-2016 by Yevgen Muntyan <emuntyan@users.sourceforge.net>
|
||||
*
|
||||
* This file is part of medit. medit 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.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public
|
||||
* License along with medit. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#pragma once
|
||||
|
||||
#include "moocpp/gobjrawptr.h"
|
||||
#include "moocpp/grefptr.h"
|
||||
#include "moocpp/gobjectutils.h"
|
||||
|
||||
namespace moo {
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////////////////////
|
||||
//
|
||||
// gobj_ptr
|
||||
//
|
||||
|
||||
template<typename Object>
|
||||
class gobj_ptr
|
||||
{
|
||||
using ref_type = gobj_ref<Object>;
|
||||
|
||||
static_assert(gobjinfo<Object>::is_gobject, "Not a GObject");
|
||||
|
||||
public:
|
||||
gobj_ptr() {}
|
||||
|
||||
gobj_ptr(Object* obj, ref_transfer policy)
|
||||
{
|
||||
assign(obj, policy);
|
||||
}
|
||||
|
||||
gobj_ptr(const nullptr_t&)
|
||||
: gobj_ptr()
|
||||
{
|
||||
}
|
||||
|
||||
static gobj_ptr wrap_new(Object* obj)
|
||||
{
|
||||
return gobj_ptr(obj, ref_transfer::take_ownership);
|
||||
}
|
||||
|
||||
static gobj_ptr wrap(Object* obj)
|
||||
{
|
||||
return gobj_ptr(obj, ref_transfer::make_copy);
|
||||
}
|
||||
|
||||
~gobj_ptr()
|
||||
{
|
||||
reset();
|
||||
}
|
||||
|
||||
void ref(Object* obj)
|
||||
{
|
||||
assign(obj, ref_transfer::make_copy);
|
||||
}
|
||||
|
||||
void set(Object* obj)
|
||||
{
|
||||
assign(obj, ref_transfer::make_copy);
|
||||
}
|
||||
|
||||
void set_new(Object* obj)
|
||||
{
|
||||
assign(obj, ref_transfer::take_ownership);
|
||||
}
|
||||
|
||||
Object* release()
|
||||
{
|
||||
auto* tmp = gobj();
|
||||
m_ref._set_gobj(nullptr);
|
||||
return tmp;
|
||||
}
|
||||
|
||||
void reset()
|
||||
{
|
||||
auto* tmp = gobj();
|
||||
if (tmp)
|
||||
{
|
||||
m_ref._set_gobj(nullptr);
|
||||
g_object_unref(tmp);
|
||||
}
|
||||
}
|
||||
|
||||
// Implicit conversion to non-const Object* is dangerous because there is a lot
|
||||
// of code still which frees/steals objects directly. For example:
|
||||
// FooObject* tmp = x->s;
|
||||
// x->s = NULL;
|
||||
// g_object_unref (tmp);
|
||||
operator const Object* () const { return gobj(); }
|
||||
operator ref_type*() const { return m_ref.self(); }
|
||||
ref_type* operator->() const { return m_ref.self(); }
|
||||
ref_type& operator*() { return m_ref; }
|
||||
const ref_type& operator*() const { return m_ref; }
|
||||
|
||||
// These are nasty. Because of ref_type* conversion this can be converted to void*,
|
||||
// which in turn can be passed to g_object_ref or g_free, etc.
|
||||
operator void*() const = delete;
|
||||
operator const void*() const = delete;
|
||||
|
||||
Object* gobj() const { return m_ref.gobj(); }
|
||||
Object** pp() { return m_ref._pp(); }
|
||||
|
||||
template<typename Super>
|
||||
Super* gobj() const
|
||||
{
|
||||
return gobj_is_subclass<Object, Super>::down_cast(m_ref.gobj());
|
||||
}
|
||||
|
||||
template<typename Super>
|
||||
operator const Super* () const { return gobj<Super>(); }
|
||||
|
||||
template<typename Super>
|
||||
operator gobj_ptr<Super> () const { return gobj_ptr<Super>::wrap (gobj<Super> ()); }
|
||||
|
||||
operator bool() const { return gobj() != nullptr; }
|
||||
bool operator!() const { return gobj() == nullptr; }
|
||||
|
||||
gobj_ptr(const gobj_ptr& other)
|
||||
: gobj_ptr()
|
||||
{
|
||||
ref(other.gobj());
|
||||
}
|
||||
|
||||
gobj_ptr& operator=(const gobj_ptr& other)
|
||||
{
|
||||
ref(other.gobj());
|
||||
return *this;
|
||||
}
|
||||
|
||||
gobj_ptr(gobj_ptr&& other)
|
||||
: gobj_ptr()
|
||||
{
|
||||
m_ref._set_gobj(other.gobj());
|
||||
other.m_ref._set_gobj(nullptr);
|
||||
}
|
||||
|
||||
gobj_ptr& operator=(const nullptr_t&)
|
||||
{
|
||||
reset();
|
||||
return *this;
|
||||
}
|
||||
|
||||
gobj_ptr& operator=(gobj_ptr&& other)
|
||||
{
|
||||
if (gobj() != other.gobj())
|
||||
{
|
||||
assign(other.gobj(), ref_transfer::take_ownership);
|
||||
other.m_ref._set_gobj(nullptr);
|
||||
}
|
||||
|
||||
return *this;
|
||||
}
|
||||
|
||||
private:
|
||||
void assign(Object* obj, ref_transfer policy)
|
||||
{
|
||||
g_assert(!obj || G_IS_OBJECT(obj));
|
||||
|
||||
if (gobj() != obj)
|
||||
{
|
||||
Object* tmp = gobj();
|
||||
m_ref._set_gobj(obj);
|
||||
|
||||
if (obj)
|
||||
{
|
||||
if (policy == ref_transfer::make_copy)
|
||||
g_object_ref(obj);
|
||||
else if (g_object_is_floating(obj))
|
||||
g_object_ref_sink(obj);
|
||||
}
|
||||
|
||||
if (tmp)
|
||||
g_object_unref(tmp);
|
||||
}
|
||||
}
|
||||
|
||||
private:
|
||||
mutable gobj_ref<Object> m_ref;
|
||||
};
|
||||
|
||||
template<typename Object>
|
||||
inline gobj_ptr<Object> wrap_new(Object *obj)
|
||||
{
|
||||
return gobj_ptr<Object>::wrap_new(obj);
|
||||
}
|
||||
|
||||
template<typename Object>
|
||||
inline gobj_ptr<Object> wrap(Object* obj)
|
||||
{
|
||||
return gobj_ptr<Object>::wrap(obj);
|
||||
}
|
||||
|
||||
template<typename Object>
|
||||
inline gobj_ptr<Object> wrap(const gobj_raw_ptr<Object>& obj)
|
||||
{
|
||||
return gobj_ptr<Object>::wrap(obj);
|
||||
}
|
||||
|
||||
template<typename Object>
|
||||
inline gobj_ref<Object> wrap (Object& obj)
|
||||
{
|
||||
return *wrap (&obj);
|
||||
}
|
||||
|
||||
template<typename T, typename ...Args>
|
||||
inline gobj_ptr<T> create_gobj(GType obj_type, Args&& ...args)
|
||||
{
|
||||
return wrap_new(reinterpret_cast<T*>(g_object_new(obj_type, std::forward<Args>(args)...)));
|
||||
}
|
||||
|
||||
template<typename T, typename ...Args>
|
||||
inline gobj_ptr<T> create_gobj(Args&& ...args)
|
||||
{
|
||||
// object_g_type() will produce a compiler error if the type wasn't registered
|
||||
return create_gobj(gobjinfo<T>::object_g_type(), std::forward<Args>(args)...);
|
||||
}
|
||||
|
||||
template<typename T>
|
||||
inline gobj_ptr<T> create_gobj()
|
||||
{
|
||||
// object_g_type() will produce a compiler error if the type wasn't registered
|
||||
return create_gobj<T>(gobjinfo<T>::object_g_type(), nullptr);
|
||||
}
|
||||
|
||||
template<typename Object, typename Super>
|
||||
Object* up_cast (Super* o)
|
||||
{
|
||||
return G_TYPE_CHECK_INSTANCE_CAST ((o), gobjinfo<Object>::object_g_type(), Object);
|
||||
}
|
||||
|
||||
} // namespace moo
|
||||
|
||||
template<typename X>
|
||||
void g_object_unref(const moo::gobj_ptr<X>&) = delete;
|
||||
template<typename X>
|
||||
void g_free(const moo::gobj_ptr<X>&) = delete;
|
||||
|
||||
template<typename X>
|
||||
inline bool operator==(const moo::gobj_ptr<X>& p, const nullptr_t&)
|
||||
{
|
||||
return p.gobj() == nullptr;
|
||||
}
|
||||
|
||||
template<typename X>
|
||||
inline bool operator==(const nullptr_t&, const moo::gobj_ptr<X>& p)
|
||||
{
|
||||
return p.gobj() == nullptr;
|
||||
}
|
||||
|
||||
template<typename X, typename Y>
|
||||
inline bool operator==(const moo::gobj_ptr<X>& p1, const moo::gobj_ptr<Y>& p2)
|
||||
{
|
||||
return p1.gobj() == p2.gobj();
|
||||
}
|
||||
|
||||
template<typename X, typename Y>
|
||||
inline bool operator==(const moo::gobj_ptr<X>& p1, const Y* p2)
|
||||
{
|
||||
return p1.gobj() == p2;
|
||||
}
|
||||
|
||||
template<typename X, typename Y>
|
||||
inline bool operator==(const X* p1, const moo::gobj_ptr<Y>& p2)
|
||||
{
|
||||
return p1 == p2.gobj();
|
||||
}
|
||||
|
||||
template<typename X, typename Y>
|
||||
inline bool operator==(const moo::gobj_ptr<X>& p1, const moo::gobj_raw_ptr<Y>& p2)
|
||||
{
|
||||
return p1.gobj() == p2.gobj();
|
||||
}
|
||||
|
||||
template<typename X, typename Y>
|
||||
inline bool operator==(const moo::gobj_raw_ptr<Y>& p1, const moo::gobj_ptr<X>& p2)
|
||||
{
|
||||
return p1.gobj() == p2.gobj();
|
||||
}
|
||||
|
||||
template<typename X, typename Y>
|
||||
bool operator!=(const moo::gobj_ptr<X>& p1, const moo::gobj_ptr<Y>& p2)
|
||||
{
|
||||
return !(p1 == p2);
|
||||
}
|
||||
|
||||
template<typename X, typename Y>
|
||||
bool operator!=(const moo::gobj_ptr<X>& p1, const Y& p2)
|
||||
{
|
||||
return !(p1 == p2);
|
||||
}
|
||||
|
||||
template<typename X, typename Y>
|
||||
bool operator!=(const X& p1, const moo::gobj_ptr<Y>& p2)
|
||||
{
|
||||
return !(p1 == p2);
|
||||
}
|
||||
|
||||
template<typename X> bool operator==(const moo::gobj_ptr<X>& p1, int) = delete;
|
||||
template<typename X> bool operator==(int, const moo::gobj_ptr<X>& p2) = delete;
|
||||
template<typename X> bool operator!=(const moo::gobj_ptr<X>& p1, int) = delete;
|
||||
template<typename X> bool operator!=(int, const moo::gobj_ptr<X>& p2) = delete;
|
|
@ -1,147 +0,0 @@
|
|||
/*
|
||||
* moocpp/gobjrawptr.h
|
||||
*
|
||||
* Copyright (C) 2004-2016 by Yevgen Muntyan <emuntyan@users.sourceforge.net>
|
||||
*
|
||||
* This file is part of medit. medit 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.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public
|
||||
* License along with medit. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#pragma once
|
||||
|
||||
#include "moocpp/gobjref.h"
|
||||
|
||||
namespace moo {
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////////////////////
|
||||
//
|
||||
// gobj_raw_ptr
|
||||
//
|
||||
|
||||
template<typename Object>
|
||||
class gobj_raw_ptr
|
||||
{
|
||||
using ref_type = gobj_ref<Object>;
|
||||
|
||||
public:
|
||||
gobj_raw_ptr(Object* obj = nullptr) { m_ref._set_gobj(obj); }
|
||||
|
||||
operator Object*() const { return gobj(); }
|
||||
operator GTypeInstance*() const { return reinterpret_cast<GTypeInstance*>(gobj()); }
|
||||
operator gpointer() const { return gobj(); }
|
||||
operator gobj_ref<Object>*() const { return m_ref.self(); }
|
||||
|
||||
ref_type* operator->() const { return m_ref.self(); }
|
||||
ref_type& operator*() const { return m_ref; }
|
||||
|
||||
Object* gobj() const { return m_ref.gobj(); }
|
||||
void set(Object* p) { m_ref._set_gobj(p); }
|
||||
|
||||
template<typename Super>
|
||||
Super* gobj() const
|
||||
{
|
||||
return gobj_is_subclass<Object, Super>::down_cast(m_ref.gobj());
|
||||
}
|
||||
|
||||
template<typename Subclass>
|
||||
void set(Subclass* p)
|
||||
{
|
||||
set(gobj_is_subclass<Subclass, Object>::down_cast(p));
|
||||
}
|
||||
|
||||
operator bool() const { return gobj() != nullptr; }
|
||||
bool operator!() const { return gobj() == nullptr; }
|
||||
|
||||
gobj_raw_ptr(const gobj_raw_ptr& other) = default;
|
||||
gobj_raw_ptr& operator=(const gobj_raw_ptr& other) = default;
|
||||
|
||||
gobj_raw_ptr(gobj_raw_ptr&& other)
|
||||
: m_ref(std::move(other.m_ref))
|
||||
{
|
||||
other.set(nullptr);
|
||||
}
|
||||
|
||||
gobj_raw_ptr& operator=(gobj_raw_ptr&& other)
|
||||
{
|
||||
m_ref = std::move(other.m_ref);
|
||||
return *this;
|
||||
}
|
||||
|
||||
template<typename T>
|
||||
gobj_raw_ptr& operator=(T* p)
|
||||
{
|
||||
set(p);
|
||||
return *this;
|
||||
}
|
||||
|
||||
private:
|
||||
mutable gobj_ref<Object> m_ref;
|
||||
};
|
||||
|
||||
} // namespace moo
|
||||
|
||||
template<typename X>
|
||||
inline bool operator==(const moo::gobj_raw_ptr<X>& p, const nullptr_t&)
|
||||
{
|
||||
return p.gobj() == nullptr;
|
||||
}
|
||||
|
||||
template<typename X>
|
||||
inline bool operator==(const nullptr_t&, const moo::gobj_raw_ptr<X>& p)
|
||||
{
|
||||
return p.gobj() == nullptr;
|
||||
}
|
||||
|
||||
template<typename X>
|
||||
inline bool operator==(const moo::gobj_raw_ptr<X>& p1, const moo::gobj_raw_ptr<X>& p2)
|
||||
{
|
||||
return p1.gobj() == p2.gobj();
|
||||
}
|
||||
|
||||
template<typename X>
|
||||
inline bool operator==(const moo::gobj_raw_ptr<X>& p1, const X* p2)
|
||||
{
|
||||
return p1.gobj() == p2;
|
||||
}
|
||||
|
||||
template<typename X>
|
||||
inline bool operator==(const moo::gobj_raw_ptr<X>& p1, X* p2)
|
||||
{
|
||||
return p1.gobj() == p2;
|
||||
}
|
||||
|
||||
template<typename X>
|
||||
inline bool operator==(const X* p1, const moo::gobj_raw_ptr<X>& p2)
|
||||
{
|
||||
return p1 == p2.gobj();
|
||||
}
|
||||
|
||||
template<typename X>
|
||||
inline bool operator==(X* p1, const moo::gobj_raw_ptr<X>& p2)
|
||||
{
|
||||
return p1 == p2.gobj();
|
||||
}
|
||||
|
||||
template<typename X>
|
||||
bool operator!=(const moo::gobj_raw_ptr<X>& p1, const moo::gobj_raw_ptr<X>& p2)
|
||||
{
|
||||
return !(p1 == p2);
|
||||
}
|
||||
|
||||
template<typename X, typename Y>
|
||||
bool operator!=(const moo::gobj_raw_ptr<X>& p1, const Y& p2)
|
||||
{
|
||||
return !(p1 == p2);
|
||||
}
|
||||
|
||||
template<typename X, typename Y>
|
||||
bool operator!=(const X& p1, const moo::gobj_raw_ptr<Y>& p2)
|
||||
{
|
||||
return !(p1 == p2);
|
||||
}
|
|
@ -1,174 +0,0 @@
|
|||
/*
|
||||
* moocpp/gobjref.h
|
||||
*
|
||||
* Copyright (C) 2004-2016 by Yevgen Muntyan <emuntyan@users.sourceforge.net>
|
||||
*
|
||||
* This file is part of medit. medit 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.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public
|
||||
* License along with medit. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#pragma once
|
||||
|
||||
#include "moocpp/gobjinfo.h"
|
||||
|
||||
namespace moo {
|
||||
|
||||
template<typename Object>
|
||||
class gobj_ref;
|
||||
template<typename Object>
|
||||
class gobj_ptr;
|
||||
template<typename Object>
|
||||
class gobj_raw_ptr;
|
||||
template<typename CObject, typename CppObject>
|
||||
class gobj_wrapper;
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////////////////////
|
||||
//
|
||||
// gobj_ref
|
||||
//
|
||||
|
||||
class gobj_ref_base
|
||||
{
|
||||
protected:
|
||||
gobj_ref_base() : m_gobj(nullptr) {}
|
||||
using object_type = GObject;
|
||||
|
||||
public:
|
||||
gobj_ref_base(const gobj_ref_base&) = default;
|
||||
gobj_ref_base& operator=(const gobj_ref_base&) = default;
|
||||
|
||||
gobj_ref_base(gobj_ref_base&& other)
|
||||
: m_gobj(other.m_gobj)
|
||||
{
|
||||
other.m_gobj = nullptr;
|
||||
}
|
||||
|
||||
gobj_ref_base& operator=(gobj_ref_base&& other)
|
||||
{
|
||||
m_gobj = other.m_gobj;
|
||||
other.m_gobj = nullptr;
|
||||
return *this;
|
||||
}
|
||||
|
||||
GObject* gobj() const { return m_gobj; }
|
||||
operator GObject&() const { return *m_gobj; }
|
||||
operator GTypeInstance&() const { return *reinterpret_cast<GTypeInstance*>(m_gobj); }
|
||||
|
||||
protected:
|
||||
GObject* raw_gobj() const { return const_cast<GObject*>(m_gobj); }
|
||||
|
||||
void** _pp ()
|
||||
{
|
||||
g_return_val_if_fail(m_gobj == nullptr, nullptr);
|
||||
return reinterpret_cast<void**>(&m_gobj);
|
||||
}
|
||||
|
||||
private:
|
||||
template<typename Object> friend class gobj_ptr;
|
||||
template<typename Object> friend class gobj_raw_ptr;
|
||||
template<typename Object> friend class gobj_ref;
|
||||
template<typename CObject, typename CppObject> friend class gobj_wrapper;
|
||||
|
||||
void _set_gobj(gpointer gobj) { m_gobj = reinterpret_cast<GObject*>(gobj); }
|
||||
|
||||
private:
|
||||
GObject* m_gobj;
|
||||
};
|
||||
|
||||
template<>
|
||||
class gobj_ref<GObject>; // : public gobj_ref_base
|
||||
|
||||
#define MOO_DEFINE_GOBJREF_METHODS_IMPL(Object, Super) \
|
||||
using super = Super; \
|
||||
using object_type = Object; \
|
||||
using ptrtype = gobj_ptr<object_type>; \
|
||||
\
|
||||
protected: \
|
||||
friend class gobj_ptr<object_type>; \
|
||||
friend class gobj_raw_ptr<object_type>; \
|
||||
\
|
||||
gobj_ref() {} \
|
||||
\
|
||||
object_type** _pp () \
|
||||
{ \
|
||||
return reinterpret_cast<object_type**>(gobj_ref_base::_pp()); \
|
||||
} \
|
||||
\
|
||||
public: \
|
||||
gobj_ref(object_type& gobj) \
|
||||
{ \
|
||||
super::_set_gobj(&gobj); \
|
||||
} \
|
||||
\
|
||||
object_type* gobj() const \
|
||||
{ \
|
||||
return reinterpret_cast<object_type*>(super::raw_gobj()); \
|
||||
} \
|
||||
\
|
||||
template<typename X> \
|
||||
X* gobj() const \
|
||||
{ \
|
||||
return nc_gobj<X>(); \
|
||||
} \
|
||||
\
|
||||
object_type* nc_gobj() const \
|
||||
{ \
|
||||
return const_cast<object_type*>(gobj()); \
|
||||
} \
|
||||
\
|
||||
template<typename X> \
|
||||
X* nc_gobj() const \
|
||||
{ \
|
||||
object_type* o = const_cast<object_type*>(gobj()); \
|
||||
return gobj_is_subclass<Object, X>::down_cast(o); \
|
||||
} \
|
||||
\
|
||||
gobj_ref* self() { return this; } \
|
||||
const gobj_ref* self() const { return this; } \
|
||||
\
|
||||
operator object_type&() const { return *gobj(); } \
|
||||
gobj_raw_ptr<object_type> operator&() const { return nc_gobj(); } \
|
||||
\
|
||||
gobj_ref(const gobj_ref&) = default; \
|
||||
gobj_ref& operator=(const gobj_ref&) = default; \
|
||||
\
|
||||
gobj_ref(gobj_ref&& other) \
|
||||
: super(std::move(static_cast<super&&>(other))) \
|
||||
{ \
|
||||
} \
|
||||
\
|
||||
gobj_ref& operator=(gobj_ref&& other) \
|
||||
{ \
|
||||
super::operator=(std::move(static_cast<super&&>(other))); \
|
||||
return *this; \
|
||||
}
|
||||
|
||||
#define MOO_DEFINE_GOBJREF_METHODS(Object) \
|
||||
MOO_DEFINE_GOBJREF_METHODS_IMPL(Object, gobj_ref<gobj_parent_type<Object>>)
|
||||
|
||||
|
||||
template<typename Object>
|
||||
using gobj_ref_parent = gobj_ref<gobj_parent_type<Object>>;
|
||||
|
||||
// Generic implementation, falls back to the parent type's gobj_ref implementation
|
||||
// if that's known, or to GObject's one, coming from the generic gobjinfo.
|
||||
template<typename Object>
|
||||
class gobj_ref : public virtual gobj_ref_parent<Object>
|
||||
{
|
||||
public:
|
||||
MOO_DEFINE_GOBJREF_METHODS(Object)
|
||||
};
|
||||
|
||||
} // namespace moo
|
||||
|
||||
// Make sure these aren't called in code ported from pure glib C
|
||||
template<typename X>
|
||||
void g_object_unref(const moo::gobj_ref<X>*) = delete;
|
||||
template<typename X>
|
||||
void g_free(const moo::gobj_ref<X>*) = delete;
|
|
@ -1,330 +0,0 @@
|
|||
/*
|
||||
* moocpp/gobjtypes-gio.cpp
|
||||
*
|
||||
* Copyright (C) 2004-2016 by Yevgen Muntyan <emuntyan@users.sourceforge.net>
|
||||
*
|
||||
* This file is part of medit. medit 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.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public
|
||||
* License along with medit. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#include "moocpp/moocpp.h"
|
||||
|
||||
using namespace moo;
|
||||
using namespace moo::g;
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
//
|
||||
// GFile
|
||||
//
|
||||
|
||||
FilePtr File::new_for_path(const char* path)
|
||||
{
|
||||
return wrap_new(g_file_new_for_path(path));
|
||||
}
|
||||
|
||||
FilePtr File::new_for_uri(const char* uri)
|
||||
{
|
||||
return wrap_new(g_file_new_for_uri(uri));
|
||||
}
|
||||
|
||||
FilePtr File::new_for_commandline_arg(const char* arg)
|
||||
{
|
||||
return wrap_new(g_file_new_for_commandline_arg(arg));
|
||||
}
|
||||
|
||||
FilePtr File::parse_name(const char* parse_name)
|
||||
{
|
||||
return wrap_new(g_file_parse_name(parse_name));
|
||||
}
|
||||
|
||||
FilePtr File::dup()
|
||||
{
|
||||
return FilePtr::wrap_new(g_file_dup(nc_gobj()));
|
||||
}
|
||||
|
||||
bool File::equal(File file2)
|
||||
{
|
||||
return g_file_equal(nc_gobj(), file2.gobj());
|
||||
}
|
||||
|
||||
gstr File::get_basename()
|
||||
{
|
||||
return gstr::wrap_new(g_file_get_basename(nc_gobj()));
|
||||
}
|
||||
|
||||
gstr File::get_path()
|
||||
{
|
||||
return gstr::wrap_new(g_file_get_path(nc_gobj()));
|
||||
}
|
||||
|
||||
gstr File::get_uri()
|
||||
{
|
||||
return gstr::wrap_new(g_file_get_uri(nc_gobj()));
|
||||
}
|
||||
|
||||
gstr File::get_parse_name()
|
||||
{
|
||||
return gstr::wrap_new(g_file_get_parse_name(nc_gobj()));
|
||||
}
|
||||
|
||||
FilePtr File::get_parent()
|
||||
{
|
||||
return FilePtr::wrap_new(g_file_get_parent(nc_gobj()));
|
||||
}
|
||||
|
||||
bool File::has_parent(File parent)
|
||||
{
|
||||
return g_file_has_parent(nc_gobj(), parent.gobj());
|
||||
}
|
||||
|
||||
FilePtr File::get_child(const char* name)
|
||||
{
|
||||
return FilePtr::wrap_new(g_file_get_child(nc_gobj(), name));
|
||||
}
|
||||
|
||||
FilePtr File::get_child_for_display_name(const char* display_name, gerrp& error)
|
||||
{
|
||||
return FilePtr::wrap_new(g_file_get_child_for_display_name(nc_gobj(), display_name, &error));
|
||||
}
|
||||
|
||||
bool File::has_prefix(File prefix)
|
||||
{
|
||||
return g_file_has_prefix(nc_gobj(), prefix.gobj());
|
||||
}
|
||||
|
||||
gstr File::get_relative_path(File descendant)
|
||||
{
|
||||
return gstr::wrap_new(g_file_get_relative_path(nc_gobj(), descendant.gobj()));
|
||||
}
|
||||
|
||||
FilePtr File::resolve_relative_path(const char *relative_path)
|
||||
{
|
||||
return FilePtr::wrap_new(g_file_resolve_relative_path(nc_gobj(), relative_path));
|
||||
}
|
||||
|
||||
bool File::is_native()
|
||||
{
|
||||
return g_file_is_native(nc_gobj());
|
||||
}
|
||||
|
||||
bool File::has_uri_scheme(const char *uri_scheme)
|
||||
{
|
||||
return g_file_has_uri_scheme(nc_gobj(), uri_scheme);
|
||||
}
|
||||
|
||||
gstr File::get_uri_scheme()
|
||||
{
|
||||
return gstr::wrap_new(g_file_get_uri_scheme(nc_gobj()));
|
||||
}
|
||||
|
||||
g::FileInputStreamPtr File::read(GCancellable* cancellable, gerrp& error)
|
||||
{
|
||||
return wrap_new (g_file_read(gobj(), cancellable, &error));
|
||||
}
|
||||
|
||||
g::FileOutputStreamPtr File::append_to(GFileCreateFlags flags, GCancellable* cancellable, gerrp& error)
|
||||
{
|
||||
return wrap_new (g_file_append_to(gobj(), flags, cancellable, &error));
|
||||
}
|
||||
|
||||
g::FileOutputStreamPtr File::create(GFileCreateFlags flags, GCancellable* cancellable, gerrp& error)
|
||||
{
|
||||
return wrap_new (g_file_create(gobj(), flags, cancellable, &error));
|
||||
}
|
||||
|
||||
g::FileOutputStreamPtr File::replace(const char* etag, gboolean make_backup, GFileCreateFlags flags, GCancellable* cancellable, gerrp& error)
|
||||
{
|
||||
return wrap_new (g_file_replace(gobj(), etag, make_backup, flags, cancellable, &error));
|
||||
}
|
||||
|
||||
g::FileIOStreamPtr File::open_readwrite(GCancellable* cancellable, gerrp& error)
|
||||
{
|
||||
return wrap_new (g_file_open_readwrite(gobj(), cancellable, &error));
|
||||
}
|
||||
|
||||
g::FileIOStreamPtr File::create_readwrite(GFileCreateFlags flags, GCancellable* cancellable, gerrp& error)
|
||||
{
|
||||
return wrap_new (g_file_create_readwrite(gobj(), flags, cancellable, &error));
|
||||
}
|
||||
|
||||
g::FileIOStreamPtr File::replace_readwrite(const char* etag, gboolean make_backup, GFileCreateFlags flags, GCancellable* cancellable, gerrp& error)
|
||||
{
|
||||
return wrap_new (g_file_replace_readwrite(gobj(), etag, make_backup, flags, cancellable, &error));
|
||||
}
|
||||
|
||||
bool File::query_exists(GCancellable* cancellable)
|
||||
{
|
||||
return g_file_query_exists(nc_gobj(), cancellable);
|
||||
}
|
||||
|
||||
GFileType File::query_file_type(GFileQueryInfoFlags flags, GCancellable* cancellable)
|
||||
{
|
||||
return g_file_query_file_type(nc_gobj(), flags, cancellable);
|
||||
}
|
||||
|
||||
FileInfoPtr File::query_info(const char *attributes, GFileQueryInfoFlags flags, GCancellable* cancellable, gerrp& error)
|
||||
{
|
||||
return wrap_new(g_file_query_info(nc_gobj(), attributes, flags, cancellable, &error));
|
||||
}
|
||||
|
||||
FileInfoPtr File::query_filesystem_info(const char *attributes, GCancellable* cancellable, gerrp& error)
|
||||
{
|
||||
return wrap_new(g_file_query_filesystem_info(nc_gobj(), attributes, cancellable, &error));
|
||||
}
|
||||
|
||||
GFileEnumerator* File::enumerate_children(const char *attributes, GFileQueryInfoFlags flags, GCancellable* cancellable, gerrp& error)
|
||||
{
|
||||
return g_file_enumerate_children(nc_gobj(), attributes, flags, cancellable, &error);
|
||||
}
|
||||
|
||||
FilePtr File::set_display_name(const char* display_name, GCancellable* cancellable, gerrp& error)
|
||||
{
|
||||
return FilePtr::wrap_new(g_file_set_display_name(nc_gobj(), display_name, cancellable, &error));
|
||||
}
|
||||
|
||||
bool File::delete_(GCancellable* cancellable, gerrp& error)
|
||||
{
|
||||
return g_file_delete(nc_gobj(), cancellable, &error);
|
||||
}
|
||||
|
||||
bool File::trash(GCancellable* cancellable, gerrp& error)
|
||||
{
|
||||
return g_file_trash(nc_gobj(), cancellable, &error);
|
||||
}
|
||||
|
||||
bool File::copy(File destination, GFileCopyFlags flags, GCancellable* cancellable, GFileProgressCallback progress_callback, gpointer progress_callback_data, gerrp& error)
|
||||
{
|
||||
return g_file_copy(nc_gobj(), destination.gobj(), flags, cancellable, progress_callback, progress_callback_data, &error);
|
||||
}
|
||||
|
||||
bool File::move(File destination, GFileCopyFlags flags, GCancellable* cancellable, GFileProgressCallback progress_callback, gpointer progress_callback_data, gerrp& error)
|
||||
{
|
||||
return g_file_move(nc_gobj(), destination.gobj(), flags, cancellable, progress_callback, progress_callback_data, &error);
|
||||
}
|
||||
|
||||
bool File::make_directory(GCancellable* cancellable, gerrp& error)
|
||||
{
|
||||
return g_file_make_directory(nc_gobj(), cancellable, &error);
|
||||
}
|
||||
|
||||
bool File::make_directory_with_parents(GCancellable* cancellable, gerrp& error)
|
||||
{
|
||||
return g_file_make_directory_with_parents(nc_gobj(), cancellable, &error);
|
||||
}
|
||||
|
||||
bool File::make_symbolic_link(const char *symlink_value, GCancellable* cancellable, gerrp& error)
|
||||
{
|
||||
return g_file_make_symbolic_link(nc_gobj(), symlink_value, cancellable, &error);
|
||||
}
|
||||
|
||||
bool File::load_contents(GCancellable* cancellable, char** contents, gsize* length, char** etag_out, gerrp& error)
|
||||
{
|
||||
return g_file_load_contents(nc_gobj(), cancellable, contents, length, etag_out, &error);
|
||||
}
|
||||
|
||||
bool File::replace_contents(const char* contents, gsize length, const char* etag, gboolean make_backup, GFileCreateFlags flags, char** new_etag, GCancellable* cancellable, gerrp& error)
|
||||
{
|
||||
return g_file_replace_contents(nc_gobj(), contents, length, etag, make_backup, flags, new_etag, cancellable, &error);
|
||||
}
|
||||
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
//
|
||||
// GOutputStream
|
||||
//
|
||||
|
||||
gssize OutputStream::write(const void* buffer, gsize count, GCancellable* cancellable, gerrp& error)
|
||||
{
|
||||
return g_output_stream_write(gobj(), buffer, count, cancellable, &error);
|
||||
}
|
||||
|
||||
bool OutputStream::write_all(const void* buffer, gsize count, gsize* bytes_written, GCancellable* cancellable, gerrp& error)
|
||||
{
|
||||
return g_output_stream_write_all(gobj(), buffer, count, bytes_written, cancellable, &error);
|
||||
}
|
||||
|
||||
gssize OutputStream::splice(g::InputStream source, GOutputStreamSpliceFlags flags, GCancellable* cancellable, gerrp& error)
|
||||
{
|
||||
return g_output_stream_splice(gobj(), source.gobj(), flags, cancellable, &error);
|
||||
}
|
||||
|
||||
bool OutputStream::flush(GCancellable* cancellable, gerrp& error)
|
||||
{
|
||||
return g_output_stream_flush(gobj(), cancellable, &error);
|
||||
}
|
||||
|
||||
bool OutputStream::close(GCancellable* cancellable, gerrp& error)
|
||||
{
|
||||
return g_output_stream_close(gobj(), cancellable, &error);
|
||||
}
|
||||
|
||||
void OutputStream::write_async(const void* buffer, gsize count, int io_priority, GCancellable* cancellable, GAsyncReadyCallback callback, gpointer user_data)
|
||||
{
|
||||
g_output_stream_write_async(gobj(), buffer, count, io_priority, cancellable, callback, user_data);
|
||||
}
|
||||
|
||||
gssize OutputStream::write_finish(GAsyncResult* result, gerrp& error)
|
||||
{
|
||||
return g_output_stream_write_finish(gobj(), result, &error);
|
||||
}
|
||||
|
||||
void OutputStream::splice_async(g::InputStream source, GOutputStreamSpliceFlags flags, int io_priority, GCancellable* cancellable, GAsyncReadyCallback callback, gpointer user_data)
|
||||
{
|
||||
g_output_stream_splice_async(gobj(), source.gobj(), flags, io_priority, cancellable, callback, user_data);
|
||||
}
|
||||
|
||||
gssize OutputStream::splice_finish(GAsyncResult* result, gerrp& error)
|
||||
{
|
||||
return g_output_stream_splice_finish(gobj(), result, &error);
|
||||
}
|
||||
|
||||
void OutputStream::flush_async(int io_priority, GCancellable* cancellable, GAsyncReadyCallback callback, gpointer user_data)
|
||||
{
|
||||
g_output_stream_flush_async(gobj(), io_priority, cancellable, callback, user_data);
|
||||
}
|
||||
|
||||
bool OutputStream::flush_finish(GAsyncResult* result, gerrp& error)
|
||||
{
|
||||
return g_output_stream_flush_finish(gobj(), result, &error);
|
||||
}
|
||||
|
||||
void OutputStream::close_async(int io_priority, GCancellable* cancellable, GAsyncReadyCallback callback, gpointer user_data)
|
||||
{
|
||||
g_output_stream_close_async(gobj(), io_priority, cancellable, callback, user_data);
|
||||
}
|
||||
|
||||
bool OutputStream::close_finish(GAsyncResult* result, gerrp& error)
|
||||
{
|
||||
return g_output_stream_close_finish(gobj(), result, &error);
|
||||
}
|
||||
|
||||
bool OutputStream::is_closed()
|
||||
{
|
||||
return g_output_stream_is_closed(gobj());
|
||||
}
|
||||
|
||||
bool OutputStream::is_closing()
|
||||
{
|
||||
return g_output_stream_is_closing(gobj());
|
||||
}
|
||||
|
||||
bool OutputStream::has_pending()
|
||||
{
|
||||
return g_output_stream_has_pending(gobj());
|
||||
}
|
||||
|
||||
bool OutputStream::set_pending(gerrp& error)
|
||||
{
|
||||
return g_output_stream_set_pending(gobj(), &error);
|
||||
}
|
||||
|
||||
void OutputStream::clear_pending()
|
||||
{
|
||||
g_output_stream_clear_pending(gobj());
|
||||
}
|
|
@ -1,225 +0,0 @@
|
|||
/*
|
||||
* moocpp/gobjtypes-gio.h
|
||||
*
|
||||
* Copyright (C) 2004-2016 by Yevgen Muntyan <emuntyan@users.sourceforge.net>
|
||||
*
|
||||
* This file is part of medit. medit 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.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public
|
||||
* License along with medit. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <gio/gio.h>
|
||||
#include <mooglib/moo-glib.h>
|
||||
|
||||
#ifdef __cplusplus
|
||||
|
||||
#include "moocpp/gobjtypes-glib.h"
|
||||
#include "moocpp/strutils.h"
|
||||
|
||||
MOO_DEFINE_GOBJ_TYPE(GFile, GObject, G_TYPE_FILE)
|
||||
MOO_DEFINE_GOBJ_TYPE(GFileInfo, GObject, G_TYPE_FILE_INFO)
|
||||
|
||||
MOO_DEFINE_GOBJ_TYPE(GOutputStream, GObject, G_TYPE_OUTPUT_STREAM)
|
||||
MOO_DEFINE_GOBJ_TYPE(GFileOutputStream, GOutputStream, G_TYPE_FILE_OUTPUT_STREAM)
|
||||
MOO_DEFINE_GOBJ_TYPE(GInputStream, GObject, G_TYPE_INPUT_STREAM)
|
||||
MOO_DEFINE_GOBJ_TYPE(GFileInputStream, GInputStream, G_TYPE_FILE_INPUT_STREAM)
|
||||
MOO_DEFINE_GOBJ_TYPE(GIOStream, GObject, G_TYPE_IO_STREAM)
|
||||
MOO_DEFINE_GOBJ_TYPE(GFileIOStream, GIOStream, G_TYPE_FILE_IO_STREAM)
|
||||
|
||||
MOO_DECLARE_CUSTOM_GOBJ_TYPE(GFile)
|
||||
MOO_DECLARE_CUSTOM_GOBJ_TYPE(GOutputStream)
|
||||
|
||||
namespace moo {
|
||||
|
||||
namespace g {
|
||||
|
||||
MOO_GOBJ_TYPEDEFS(File, GFile);
|
||||
MOO_GOBJ_TYPEDEFS(FileInfo, GFileInfo);
|
||||
MOO_GOBJ_TYPEDEFS(OutputStream, GOutputStream);
|
||||
MOO_GOBJ_TYPEDEFS(FileOutputStream, GFileOutputStream);
|
||||
MOO_GOBJ_TYPEDEFS(InputStream, GInputStream);
|
||||
MOO_GOBJ_TYPEDEFS(FileInputStream, GFileInputStream);
|
||||
MOO_GOBJ_TYPEDEFS(IOStream, GIOStream);
|
||||
MOO_GOBJ_TYPEDEFS(FileIOStream, GFileIOStream);
|
||||
|
||||
} // namespace g
|
||||
|
||||
template<>
|
||||
class gobj_ref<GFile> : public virtual gobj_ref_parent<GFile>
|
||||
{
|
||||
public:
|
||||
MOO_DEFINE_GOBJREF_METHODS(GFile)
|
||||
|
||||
static g::FilePtr new_for_path (const char* path);
|
||||
static g::FilePtr new_for_uri (const char* uri);
|
||||
static g::FilePtr new_for_commandline_arg (const char* arg);
|
||||
static g::FilePtr parse_name (const char* parse_name);
|
||||
|
||||
g::FilePtr dup ();
|
||||
|
||||
bool equal (g::File file2);
|
||||
gstr get_basename ();
|
||||
gstr get_path ();
|
||||
gstr get_uri ();
|
||||
gstr get_parse_name ();
|
||||
g::FilePtr get_parent ();
|
||||
bool has_parent (g::File parent);
|
||||
g::FilePtr get_child (const char* name);
|
||||
g::FilePtr get_child_for_display_name (const char* display_name,
|
||||
gerrp& error);
|
||||
bool has_prefix (g::File prefix);
|
||||
gstr get_relative_path (g::File descendant);
|
||||
g::FilePtr resolve_relative_path (const char *relative_path);
|
||||
bool is_native ();
|
||||
bool has_uri_scheme (const char *uri_scheme);
|
||||
gstr get_uri_scheme ();
|
||||
g::FileInputStreamPtr read (GCancellable* cancellable,
|
||||
gerrp& error);
|
||||
g::FileOutputStreamPtr append_to (GFileCreateFlags flags,
|
||||
GCancellable* cancellable,
|
||||
gerrp& error);
|
||||
g::FileOutputStreamPtr create (GFileCreateFlags flags,
|
||||
GCancellable* cancellable,
|
||||
gerrp& error);
|
||||
g::FileOutputStreamPtr replace (const char *etag,
|
||||
gboolean make_backup,
|
||||
GFileCreateFlags flags,
|
||||
GCancellable* cancellable,
|
||||
gerrp& error);
|
||||
g::FileIOStreamPtr open_readwrite (GCancellable* cancellable,
|
||||
gerrp& error);
|
||||
g::FileIOStreamPtr create_readwrite (GFileCreateFlags flags,
|
||||
GCancellable* cancellable,
|
||||
gerrp& error);
|
||||
g::FileIOStreamPtr replace_readwrite (const char *etag,
|
||||
gboolean make_backup,
|
||||
GFileCreateFlags flags,
|
||||
GCancellable* cancellable,
|
||||
gerrp& error);
|
||||
bool query_exists (GCancellable* cancellable);
|
||||
GFileType query_file_type (GFileQueryInfoFlags flags,
|
||||
GCancellable* cancellable);
|
||||
g::FileInfoPtr query_info (const char *attributes,
|
||||
GFileQueryInfoFlags flags,
|
||||
GCancellable* cancellable,
|
||||
gerrp& error);
|
||||
g::FileInfoPtr query_filesystem_info (const char *attributes,
|
||||
GCancellable* cancellable,
|
||||
gerrp& error);
|
||||
GFileEnumerator* enumerate_children (const char *attributes,
|
||||
GFileQueryInfoFlags flags,
|
||||
GCancellable* cancellable,
|
||||
gerrp& error);
|
||||
g::FilePtr set_display_name (const char* display_name,
|
||||
GCancellable* cancellable,
|
||||
gerrp& error);
|
||||
bool delete_ (GCancellable* cancellable,
|
||||
gerrp& error);
|
||||
bool trash (GCancellable* cancellable,
|
||||
gerrp& error);
|
||||
bool copy (g::File destination,
|
||||
GFileCopyFlags flags,
|
||||
GCancellable* cancellable,
|
||||
GFileProgressCallback progress_callback,
|
||||
gpointer progress_callback_data,
|
||||
gerrp& error);
|
||||
bool move (g::File destination,
|
||||
GFileCopyFlags flags,
|
||||
GCancellable* cancellable,
|
||||
GFileProgressCallback progress_callback,
|
||||
gpointer progress_callback_data,
|
||||
gerrp& error);
|
||||
bool make_directory (GCancellable* cancellable,
|
||||
gerrp& error);
|
||||
bool make_directory_with_parents (GCancellable* cancellable,
|
||||
gerrp& error);
|
||||
bool make_symbolic_link (const char *symlink_value,
|
||||
GCancellable* cancellable,
|
||||
gerrp& error);
|
||||
|
||||
bool load_contents (GCancellable* cancellable,
|
||||
char** contents,
|
||||
gsize* length,
|
||||
char** etag_out,
|
||||
gerrp& error);
|
||||
bool replace_contents (const char* contents,
|
||||
gsize length,
|
||||
const char* etag,
|
||||
gboolean make_backup,
|
||||
GFileCreateFlags flags,
|
||||
char** new_etag,
|
||||
GCancellable* cancellable,
|
||||
gerrp& error);
|
||||
};
|
||||
|
||||
|
||||
template<>
|
||||
class gobj_ref<GOutputStream> : public virtual gobj_ref_parent<GOutputStream>
|
||||
{
|
||||
public:
|
||||
MOO_DEFINE_GOBJREF_METHODS(GOutputStream)
|
||||
|
||||
gssize write (const void *buffer,
|
||||
gsize count,
|
||||
GCancellable *cancellable,
|
||||
gerrp& error);
|
||||
bool write_all (const void *buffer,
|
||||
gsize count,
|
||||
gsize *bytes_written,
|
||||
GCancellable *cancellable,
|
||||
gerrp& error);
|
||||
gssize splice (g::InputStream source,
|
||||
GOutputStreamSpliceFlags flags,
|
||||
GCancellable *cancellable,
|
||||
gerrp& error);
|
||||
bool flush (GCancellable *cancellable,
|
||||
gerrp& error);
|
||||
bool close (GCancellable *cancellable,
|
||||
gerrp& error);
|
||||
void write_async (const void *buffer,
|
||||
gsize count,
|
||||
int io_priority,
|
||||
GCancellable *cancellable,
|
||||
GAsyncReadyCallback callback,
|
||||
gpointer user_data);
|
||||
gssize write_finish (GAsyncResult *result,
|
||||
gerrp& error);
|
||||
void splice_async (g::InputStream source,
|
||||
GOutputStreamSpliceFlags flags,
|
||||
int io_priority,
|
||||
GCancellable *cancellable,
|
||||
GAsyncReadyCallback callback,
|
||||
gpointer user_data);
|
||||
gssize splice_finish (GAsyncResult *result,
|
||||
gerrp& error);
|
||||
void flush_async (int io_priority,
|
||||
GCancellable *cancellable,
|
||||
GAsyncReadyCallback callback,
|
||||
gpointer user_data);
|
||||
bool flush_finish (GAsyncResult *result,
|
||||
gerrp& error);
|
||||
void close_async (int io_priority,
|
||||
GCancellable *cancellable,
|
||||
GAsyncReadyCallback callback,
|
||||
gpointer user_data);
|
||||
bool close_finish (GAsyncResult *result,
|
||||
gerrp& error);
|
||||
|
||||
bool is_closed ();
|
||||
bool is_closing ();
|
||||
bool has_pending ();
|
||||
bool set_pending (gerrp& error);
|
||||
void clear_pending ();
|
||||
};
|
||||
|
||||
|
||||
} // namespace moo
|
||||
|
||||
#endif // __cplusplus
|
|
@ -1,194 +0,0 @@
|
|||
/*
|
||||
* moocpp/gobjtypes-glib.cpp
|
||||
*
|
||||
* Copyright (C) 2004-2016 by Yevgen Muntyan <emuntyan@users.sourceforge.net>
|
||||
*
|
||||
* This file is part of medit. medit 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.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public
|
||||
* License along with medit. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#include "moocpp/moocpp.h"
|
||||
|
||||
using namespace moo;
|
||||
using namespace g;
|
||||
|
||||
void extern_g_free(gpointer p)
|
||||
{
|
||||
g_free(p);
|
||||
}
|
||||
|
||||
void extern_g_object_unref(gpointer o)
|
||||
{
|
||||
g_object_unref(o);
|
||||
}
|
||||
|
||||
void extern_g_strfreev(char** p)
|
||||
{
|
||||
if (p)
|
||||
g_strfreev (p);
|
||||
}
|
||||
|
||||
|
||||
void moo::init_gobj_system ()
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
GQuark gobj_wrapper_base::qdata_key = g_quark_from_static_string ("__moo_gobj_wrapper__");
|
||||
|
||||
gobj_wrapper_base& gobj_wrapper_base::get(Object g)
|
||||
{
|
||||
void* o = g.get_data(qdata_key);
|
||||
g_assert(o != nullptr);
|
||||
return *reinterpret_cast<gobj_wrapper_base*>(o);
|
||||
}
|
||||
|
||||
gobj_wrapper_base::gobj_wrapper_base(gobj_ref<GObject> g)
|
||||
{
|
||||
g.set_data(qdata_key, this, free_qdata);
|
||||
}
|
||||
|
||||
gobj_wrapper_base::~gobj_wrapper_base()
|
||||
{
|
||||
}
|
||||
|
||||
void gobj_wrapper_base::free_qdata(gpointer d)
|
||||
{
|
||||
gobj_wrapper_base* self = reinterpret_cast<gobj_wrapper_base*>(d);
|
||||
delete self;
|
||||
}
|
||||
|
||||
|
||||
gulong Object::connect(const char *detailed_signal, GCallback c_handler, void *data)
|
||||
{
|
||||
return g_signal_connect(gobj(), detailed_signal, c_handler, data);
|
||||
}
|
||||
|
||||
gulong Object::connect_swapped(const char *detailed_signal, GCallback c_handler, void *data)
|
||||
{
|
||||
return g_signal_connect_swapped(gobj(), detailed_signal, c_handler, data);
|
||||
}
|
||||
|
||||
void Object::signal_emit_by_name(const char* detailed_signal, ...)
|
||||
{
|
||||
guint signal_id;
|
||||
GQuark detail;
|
||||
g_return_if_fail(g_signal_parse_name(detailed_signal,
|
||||
G_OBJECT_TYPE(gobj()),
|
||||
&signal_id, &detail,
|
||||
true));
|
||||
|
||||
va_list args;
|
||||
va_start(args, detailed_signal);
|
||||
g_signal_emit_valist(gobj(), signal_id, detail, args);
|
||||
va_end(args);
|
||||
}
|
||||
|
||||
void Object::signal_emit(guint signal_id, GQuark detail, ...)
|
||||
{
|
||||
va_list args;
|
||||
va_start(args, detail);
|
||||
g_signal_emit_valist(gobj(), signal_id, detail, args);
|
||||
va_end(args);
|
||||
}
|
||||
|
||||
bool Object::signal_has_handler_pending(guint signal_id, GQuark detail, bool may_be_blocked)
|
||||
{
|
||||
return g_signal_has_handler_pending(gobj(), signal_id, detail, may_be_blocked);
|
||||
}
|
||||
|
||||
gulong Object::signal_connect_closure_by_id(guint signal_id, GQuark detail, GClosure* closure, bool after)
|
||||
{
|
||||
return g_signal_connect_closure_by_id(gobj(), signal_id, detail, closure, after);
|
||||
}
|
||||
|
||||
gulong Object::signal_connect_closure(const char* detailed_signal, GClosure* closure, bool after)
|
||||
{
|
||||
return g_signal_connect_closure(gobj(), detailed_signal, closure, after);
|
||||
}
|
||||
|
||||
gulong Object::signal_connect_data(const char* detailed_signal, GCallback c_handler, gpointer data, GClosureNotify destroy_data, GConnectFlags connect_flags)
|
||||
{
|
||||
return g_signal_connect_data(gobj(), detailed_signal, c_handler, data, destroy_data, connect_flags);
|
||||
}
|
||||
|
||||
void Object::signal_handler_block(gulong handler_id)
|
||||
{
|
||||
g_signal_handler_block(gobj(), handler_id);
|
||||
}
|
||||
|
||||
void Object::signal_handler_unblock(gulong handler_id)
|
||||
{
|
||||
g_signal_handler_unblock(gobj(), handler_id);
|
||||
}
|
||||
|
||||
void Object::signal_handler_disconnect(gulong handler_id)
|
||||
{
|
||||
g_signal_handler_disconnect(gobj(), handler_id);
|
||||
}
|
||||
|
||||
gulong Object::signal_handler_find(GSignalMatchType mask, guint signal_id, GQuark detail, GClosure* closure, gpointer func, gpointer data)
|
||||
{
|
||||
return g_signal_handler_find(gobj(), mask, signal_id, detail, closure, func, data);
|
||||
}
|
||||
|
||||
guint Object::signal_handlers_block_matched(GSignalMatchType mask, guint signal_id, GQuark detail, GClosure* closure, gpointer func, gpointer data)
|
||||
{
|
||||
return g_signal_handlers_block_matched(gobj(), mask, signal_id, detail, closure, func, data);
|
||||
}
|
||||
|
||||
guint Object::signal_handlers_unblock_matched(GSignalMatchType mask, guint signal_id, GQuark detail, GClosure* closure, gpointer func, gpointer data)
|
||||
{
|
||||
return g_signal_handlers_unblock_matched(gobj(), mask, signal_id, detail, closure, func, data);
|
||||
}
|
||||
|
||||
guint Object::signal_handlers_disconnect_matched(GSignalMatchType mask, guint signal_id, GQuark detail, GClosure* closure, gpointer func, gpointer data)
|
||||
{
|
||||
return g_signal_handlers_disconnect_matched(gobj(), mask, signal_id, detail, closure, func, data);
|
||||
}
|
||||
|
||||
void Object::set_data(const char* key, gpointer value, GDestroyNotify destroy)
|
||||
{
|
||||
g_object_set_data_full(gobj(), key, value, destroy);
|
||||
}
|
||||
|
||||
void Object::set_data(GQuark q, gpointer data, GDestroyNotify destroy)
|
||||
{
|
||||
g_object_set_qdata_full(gobj(), q, data, destroy);
|
||||
}
|
||||
|
||||
void* Object::get_data(const char* key)
|
||||
{
|
||||
return g_object_get_data(gobj(), key);
|
||||
}
|
||||
|
||||
void* Object::get_data(GQuark q)
|
||||
{
|
||||
return g_object_get_qdata(gobj(), q);
|
||||
}
|
||||
|
||||
void Object::set_property(const gchar *property_name, const GValue *value)
|
||||
{
|
||||
g_object_set_property(gobj(), property_name, value);
|
||||
}
|
||||
|
||||
void Object::notify(const char* property_name)
|
||||
{
|
||||
g_object_notify(gobj(), property_name);
|
||||
}
|
||||
|
||||
void Object::freeze_notify()
|
||||
{
|
||||
g_object_freeze_notify(gobj());
|
||||
}
|
||||
|
||||
void Object::thaw_notify()
|
||||
{
|
||||
g_object_thaw_notify(gobj());
|
||||
}
|
|
@ -1,134 +0,0 @@
|
|||
/*
|
||||
* moocpp/gobjtypes-glib.h
|
||||
*
|
||||
* Copyright (C) 2004-2016 by Yevgen Muntyan <emuntyan@users.sourceforge.net>
|
||||
*
|
||||
* This file is part of medit. medit 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.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public
|
||||
* License along with medit. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <glib-object.h>
|
||||
#include <mooglib/moo-glib.h>
|
||||
|
||||
#ifdef __cplusplus
|
||||
|
||||
#include "moocpp/gobjptr.h"
|
||||
#include "moocpp/gobjectutils.h"
|
||||
|
||||
#include <stdarg.h>
|
||||
|
||||
#define MOO_GOBJ_TYPEDEFS(CppObject, CObject) \
|
||||
using CppObject = ::moo::gobj_ref<CObject>; \
|
||||
using CppObject##Ptr = ::moo::gobj_ptr<CObject>; \
|
||||
using CppObject##RawPtr = ::moo::gobj_raw_ptr<CObject>; \
|
||||
|
||||
#define MOO_GIFACE_TYPEDEFS(CppObject, CObject) \
|
||||
MOO_GOBJ_TYPEDEFS(CppObject, CObject)
|
||||
|
||||
#define MOO_DECLARE_CUSTOM_GOBJ_TYPE(CObject) \
|
||||
namespace moo { \
|
||||
template<> class gobj_ref<CObject>; \
|
||||
}
|
||||
|
||||
MOO_DEFINE_FLAGS(GSignalFlags);
|
||||
MOO_DEFINE_FLAGS(GConnectFlags);
|
||||
MOO_DEFINE_FLAGS(GSpawnFlags);
|
||||
MOO_DEFINE_FLAGS(GLogLevelFlags);
|
||||
MOO_DEFINE_FLAGS(GRegexCompileFlags);
|
||||
MOO_DEFINE_FLAGS(GIOCondition);
|
||||
|
||||
namespace moo {
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////////////////////
|
||||
//
|
||||
// GObject
|
||||
//
|
||||
|
||||
template<>
|
||||
class gobj_ref<GObject> : public gobj_ref_base
|
||||
{
|
||||
public:
|
||||
MOO_DEFINE_GOBJREF_METHODS_IMPL(GObject, gobj_ref_base)
|
||||
|
||||
gulong connect (const char* detailed_signal, GCallback c_handler, void* data);
|
||||
gulong connect_swapped (const char* detailed_signal, GCallback c_handler, void* data);
|
||||
|
||||
void signal_emit_by_name (const char* detailed_signal, ...);
|
||||
void signal_emit (guint signal_id, GQuark detail, ...);
|
||||
|
||||
bool signal_has_handler_pending (guint signal_id, GQuark detail, bool may_be_blocked);
|
||||
gulong signal_connect_closure_by_id (guint signal_id, GQuark detail, GClosure* closure, bool after);
|
||||
gulong signal_connect_closure (const char* detailed_signal, GClosure* closure, bool after);
|
||||
gulong signal_connect_data (const char* detailed_signal, GCallback c_handler, gpointer data, GClosureNotify destroy_data, GConnectFlags connect_flags);
|
||||
void signal_handler_block (gulong handler_id);
|
||||
void signal_handler_unblock (gulong handler_id);
|
||||
void signal_handler_disconnect (gulong handler_id);
|
||||
bool signal_handler_is_connected (gulong handler_id);
|
||||
gulong signal_handler_find (GSignalMatchType mask, guint signal_id, GQuark detail, GClosure* closure, gpointer func, gpointer data);
|
||||
guint signal_handlers_block_matched (GSignalMatchType mask, guint signal_id, GQuark detail, GClosure* closure, gpointer func, gpointer data);
|
||||
guint signal_handlers_unblock_matched (GSignalMatchType mask, guint signal_id, GQuark detail, GClosure* closure, gpointer func, gpointer data);
|
||||
guint signal_handlers_disconnect_matched (GSignalMatchType mask, guint signal_id, GQuark detail, GClosure* closure, gpointer func, gpointer data);
|
||||
guint signal_handlers_disconnect_by_func (GCallback c_handler, void* data);
|
||||
|
||||
void* get_data (const char* key);
|
||||
void* get_data (GQuark q);
|
||||
void set_data (const char* key, gpointer value, GDestroyNotify destroy = nullptr);
|
||||
void set_data (GQuark q, gpointer value, GDestroyNotify destroy = nullptr);
|
||||
|
||||
void set_property (const char* property_name, const GValue* value);
|
||||
|
||||
template<typename T>
|
||||
void set (const char* prop, const T& value)
|
||||
{
|
||||
g_object_set (gobj (), prop, cpp_vararg_value_fixer<T>::apply (value), nullptr);
|
||||
}
|
||||
|
||||
template<typename T, typename... Args>
|
||||
void set (const char* prop, const T& value, Args&&... args)
|
||||
{
|
||||
set (prop, value);
|
||||
set (std::forward<Args> (args)...);
|
||||
}
|
||||
|
||||
void get (const char* prop, bool& dest)
|
||||
{
|
||||
gboolean val;
|
||||
g_object_get (gobj (), prop, &val, nullptr);
|
||||
dest = val;
|
||||
}
|
||||
|
||||
template<typename T>
|
||||
void get (const char* prop, T&& dest)
|
||||
{
|
||||
g_object_get (gobj (), prop, cpp_vararg_dest_fixer<T>::apply (std::forward<T> (dest)), nullptr);
|
||||
}
|
||||
|
||||
template<typename T, typename... Args>
|
||||
void get (const char* prop, T&& dest, Args&&... args)
|
||||
{
|
||||
get (prop, std::forward<T> (dest));
|
||||
get (std::forward<Args> (args)...);
|
||||
}
|
||||
|
||||
void notify (const char* property_name);
|
||||
void freeze_notify ();
|
||||
void thaw_notify ();
|
||||
};
|
||||
|
||||
namespace g {
|
||||
|
||||
MOO_GOBJ_TYPEDEFS(Object, GObject);
|
||||
|
||||
} // namespace g
|
||||
|
||||
} // namespace moo
|
||||
|
||||
#endif // __cplusplus
|
File diff suppressed because it is too large
Load Diff
|
@ -1,653 +0,0 @@
|
|||
/*
|
||||
* moocpp/gobjtypes-gtk.h
|
||||
*
|
||||
* Copyright (C) 2004-2016 by Yevgen Muntyan <emuntyan@users.sourceforge.net>
|
||||
*
|
||||
* This file is part of medit. medit 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.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public
|
||||
* License along with medit. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <gtk/gtk.h>
|
||||
#include <mooglib/moo-glib.h>
|
||||
|
||||
#ifdef __cplusplus
|
||||
|
||||
#include "moocpp/gobjtypes-glib.h"
|
||||
#include <initializer_list>
|
||||
#include <functional>
|
||||
|
||||
#define MOO_DEFINE_GTK_TYPE(Object, Parent, obj_g_type) \
|
||||
MOO_DEFINE_GOBJ_TYPE(Gtk##Object, Parent, obj_g_type) \
|
||||
namespace moo { \
|
||||
namespace gtk { \
|
||||
MOO_GOBJ_TYPEDEFS(Object, Gtk##Object) \
|
||||
} \
|
||||
}
|
||||
|
||||
#define MOO_DEFINE_GTK_IFACE(Iface, iface_g_type) \
|
||||
MOO_DEFINE_GIFACE_TYPE(Gtk##Iface, iface_g_type) \
|
||||
namespace moo { \
|
||||
namespace gtk { \
|
||||
MOO_GIFACE_TYPEDEFS(Iface, Gtk##Iface) \
|
||||
} \
|
||||
}
|
||||
|
||||
|
||||
MOO_DECLARE_CUSTOM_GOBJ_TYPE (GtkObject)
|
||||
MOO_DECLARE_CUSTOM_GOBJ_TYPE (GtkWidget)
|
||||
MOO_DECLARE_CUSTOM_GOBJ_TYPE (GtkTextView)
|
||||
MOO_DECLARE_CUSTOM_GOBJ_TYPE (GtkTreeModel)
|
||||
MOO_DECLARE_CUSTOM_GOBJ_TYPE (GtkTreeStore)
|
||||
MOO_DECLARE_CUSTOM_GOBJ_TYPE (GtkListStore)
|
||||
MOO_DECLARE_CUSTOM_GOBJ_TYPE (GtkTreeView)
|
||||
MOO_DECLARE_CUSTOM_GOBJ_TYPE (GtkTreeViewColumn)
|
||||
MOO_DECLARE_CUSTOM_GOBJ_TYPE (GtkCellRenderer)
|
||||
MOO_DECLARE_CUSTOM_GOBJ_TYPE (GtkCellRendererText)
|
||||
MOO_DECLARE_CUSTOM_GOBJ_TYPE (GtkCellRendererToggle)
|
||||
MOO_DECLARE_CUSTOM_GOBJ_TYPE (GtkCellRendererPixbuf)
|
||||
|
||||
|
||||
MOO_DEFINE_GTK_TYPE (Object, GObject, GTK_TYPE_OBJECT)
|
||||
MOO_DEFINE_GTK_TYPE (Widget, GtkObject, GTK_TYPE_WIDGET)
|
||||
|
||||
template<>
|
||||
class moo::gobj_ref<GtkObject> : public virtual moo::gobj_ref_parent<GtkObject>
|
||||
{
|
||||
public:
|
||||
MOO_DEFINE_GOBJREF_METHODS (GtkObject);
|
||||
|
||||
void destroy ();
|
||||
};
|
||||
|
||||
template<>
|
||||
class moo::gobj_ref<GtkWidget> : public virtual moo::gobj_ref_parent<GtkWidget>
|
||||
{
|
||||
public:
|
||||
MOO_DEFINE_GOBJREF_METHODS (GtkWidget);
|
||||
};
|
||||
|
||||
|
||||
MOO_DEFINE_GTK_TYPE(Entry, GtkWidget, GTK_TYPE_ENTRY)
|
||||
MOO_DEFINE_GTK_TYPE(Action, GObject, GTK_TYPE_ACTION)
|
||||
MOO_DEFINE_GTK_TYPE(TextBuffer, GObject, GTK_TYPE_TEXT_BUFFER)
|
||||
MOO_DEFINE_GTK_TYPE(TextMark, GObject, GTK_TYPE_TEXT_MARK)
|
||||
MOO_DEFINE_GTK_TYPE(MenuShell, GtkWidget, GTK_TYPE_MENU_SHELL)
|
||||
MOO_DEFINE_GTK_TYPE(Menu, GtkMenuShell, GTK_TYPE_MENU)
|
||||
|
||||
|
||||
MOO_DEFINE_GTK_TYPE (TextView, GtkWidget, GTK_TYPE_TEXT_VIEW)
|
||||
|
||||
template<>
|
||||
class moo::gobj_ref<GtkTextView> : public virtual moo::gobj_ref_parent<GtkTextView>
|
||||
{
|
||||
public:
|
||||
MOO_DEFINE_GOBJREF_METHODS(GtkTextView);
|
||||
|
||||
gtk::TextBuffer get_buffer ();
|
||||
};
|
||||
|
||||
|
||||
MOO_DEFINE_GTK_IFACE (TreeModel, GTK_TYPE_TREE_MODEL)
|
||||
|
||||
template<>
|
||||
class moo::gobj_ref<GtkTreeModel> : public virtual moo::gobj_ref_parent<GtkTreeModel>
|
||||
{
|
||||
public:
|
||||
MOO_DEFINE_GOBJREF_METHODS (GtkTreeModel);
|
||||
|
||||
GtkTreeModelFlags get_flags ();
|
||||
int get_n_columns ();
|
||||
GType get_column_type (int index_);
|
||||
|
||||
bool get_iter (GtkTreeIter& iter, const GtkTreePath& path);
|
||||
bool get_iter_from_string (GtkTreeIter& iter, const char* path_string);
|
||||
gstr get_string_from_iter (const GtkTreeIter& iter);
|
||||
bool get_iter_first (GtkTreeIter& iter);
|
||||
GtkTreePath* get_path (const GtkTreeIter& iter);
|
||||
void get_value (const GtkTreeIter& iter, int column, GValue* value);
|
||||
bool iter_next (GtkTreeIter& iter);
|
||||
bool iter_children (GtkTreeIter& iter, const GtkTreeIter& parent);
|
||||
bool iter_has_child (const GtkTreeIter& iter);
|
||||
int iter_n_children (const GtkTreeIter& iter);
|
||||
bool iter_nth_child (GtkTreeIter& iter, const GtkTreeIter& parent, int n);
|
||||
bool iter_parent (GtkTreeIter& iter, const GtkTreeIter& child);
|
||||
|
||||
void get (const GtkTreeIter& iter, int column, bool& dest)
|
||||
{
|
||||
gboolean val;
|
||||
gtk_tree_model_get (gobj (), const_cast<GtkTreeIter*>(&iter), column, &val, -1);
|
||||
dest = val;
|
||||
}
|
||||
|
||||
template<typename T>
|
||||
void get (const GtkTreeIter& iter, int column, T&& dest)
|
||||
{
|
||||
gtk_tree_model_get (gobj (), const_cast<GtkTreeIter*>(&iter), column, cpp_vararg_dest_fixer<T>::apply (std::forward<T> (dest)), -1);
|
||||
}
|
||||
|
||||
template<typename T, typename... Args>
|
||||
void get (const GtkTreeIter& iter, int column, T&& dest, Args&&... args)
|
||||
{
|
||||
get (iter, column, std::forward<T> (dest));
|
||||
get (iter, std::forward<Args> (args)...);
|
||||
}
|
||||
|
||||
// bool TFunc (const GtkTreePath&, const GtkTreeIter&)
|
||||
template<typename TFunc>
|
||||
void foreach (const TFunc& func)
|
||||
{
|
||||
const void* p = &func;
|
||||
gtk_tree_model_foreach (gobj (), foreach_func<TFunc>, const_cast<void*>(p));
|
||||
}
|
||||
|
||||
private:
|
||||
template<typename TFunc>
|
||||
static gboolean foreach_func (GtkTreeModel *model, GtkTreePath *path, GtkTreeIter *iter, gpointer data)
|
||||
{
|
||||
const TFunc& func = *reinterpret_cast<const TFunc*>(data);
|
||||
return func (const_cast<const GtkTreePath&>(*path), const_cast<const GtkTreeIter&>(*iter));
|
||||
}
|
||||
};
|
||||
|
||||
MOO_DEFINE_GTK_TYPE (ListStore, GObject, GTK_TYPE_LIST_STORE)
|
||||
MOO_GOBJ_IMPLEMENTS_IFACE (GtkListStore, GtkTreeModel)
|
||||
|
||||
template<>
|
||||
class moo::gobj_ref<GtkListStore>
|
||||
: public virtual moo::gobj_ref_parent<GtkListStore>
|
||||
, public virtual moo::gobj_ref<GtkTreeModel>
|
||||
{
|
||||
public:
|
||||
MOO_DEFINE_GOBJREF_METHODS(GtkListStore);
|
||||
|
||||
static gtk::ListStorePtr create (std::initializer_list<GType> types)
|
||||
{
|
||||
return create (types.size (), types.begin ());
|
||||
}
|
||||
|
||||
static gtk::ListStorePtr create (size_t n_columns, std::initializer_list<GType> types)
|
||||
{
|
||||
g_return_val_if_fail (n_columns == types.size (), nullptr);
|
||||
return create (n_columns, types.begin ());
|
||||
}
|
||||
|
||||
static gtk::ListStorePtr create (size_t n_columns, const GType* types);
|
||||
|
||||
template<typename T>
|
||||
void set (const GtkTreeIter& iter, int column, T&& value)
|
||||
{
|
||||
gtk_list_store_set (gobj (), const_cast<GtkTreeIter*>(&iter), column, cpp_vararg_value_fixer<T>::apply (std::forward<T&&> (value)), -1);
|
||||
}
|
||||
|
||||
template<typename T, typename... Args>
|
||||
void set (const GtkTreeIter& iter, int column, T&& value, Args&&... args)
|
||||
{
|
||||
set (iter, column, std::forward<T> (value));
|
||||
set (iter, std::forward<Args> (args)...);
|
||||
}
|
||||
|
||||
void set_value (const GtkTreeIter& iter,
|
||||
int column,
|
||||
GValue* value);
|
||||
void set_valuesv (const GtkTreeIter& iter,
|
||||
int* columns,
|
||||
GValue* values,
|
||||
int n_values);
|
||||
bool remove (GtkTreeIter& iter);
|
||||
void insert (GtkTreeIter& iter,
|
||||
int position);
|
||||
void insert_before (GtkTreeIter& iter,
|
||||
GtkTreeIter& sibling);
|
||||
void insert_after (GtkTreeIter& iter,
|
||||
GtkTreeIter& sibling);
|
||||
//void insert_with_values (GtkTreeIter* iter,
|
||||
// int position,
|
||||
// ...);
|
||||
//void insert_with_values (GtkTreeIter* iter,
|
||||
// int position,
|
||||
// int* columns,
|
||||
// GValue* values,
|
||||
// int n_values);
|
||||
void prepend (GtkTreeIter& iter);
|
||||
void append (GtkTreeIter& iter);
|
||||
void clear ();
|
||||
bool iter_is_valid (const GtkTreeIter& iter);
|
||||
void reorder (int* new_order);
|
||||
void swap (GtkTreeIter& a,
|
||||
GtkTreeIter& b);
|
||||
void move_after (GtkTreeIter& iter,
|
||||
GtkTreeIter& position);
|
||||
void move_before (GtkTreeIter& iter,
|
||||
GtkTreeIter& position);
|
||||
};
|
||||
|
||||
MOO_DEFINE_GTK_TYPE (TreeStore, GObject, GTK_TYPE_TREE_STORE)
|
||||
MOO_GOBJ_IMPLEMENTS_IFACE (GtkTreeStore, GtkTreeModel)
|
||||
|
||||
template<>
|
||||
class moo::gobj_ref<GtkTreeStore>
|
||||
: public virtual moo::gobj_ref_parent<GtkTreeStore>
|
||||
, public virtual moo::gobj_ref<GtkTreeModel>
|
||||
{
|
||||
public:
|
||||
MOO_DEFINE_GOBJREF_METHODS (GtkTreeStore);
|
||||
};
|
||||
|
||||
MOO_DEFINE_GTK_TYPE (TreeView, GtkContainer, GTK_TYPE_TREE_VIEW)
|
||||
MOO_DEFINE_GTK_TYPE (TreeViewColumn, GtkObject, GTK_TYPE_TREE_VIEW_COLUMN)
|
||||
MOO_DEFINE_GTK_TYPE (CellRenderer, GtkObject, GTK_TYPE_CELL_RENDERER)
|
||||
MOO_DEFINE_GTK_TYPE (CellRendererText, GtkCellRenderer, GTK_TYPE_CELL_RENDERER_TEXT)
|
||||
MOO_DEFINE_GTK_TYPE (CellRendererPixbuf, GtkCellRenderer, GTK_TYPE_CELL_RENDERER_PIXBUF)
|
||||
MOO_DEFINE_GTK_TYPE (CellRendererToggle, GtkCellRenderer, GTK_TYPE_CELL_RENDERER_TOGGLE)
|
||||
|
||||
|
||||
template<typename TFunc>
|
||||
class TreeCellDataFunc
|
||||
{
|
||||
public:
|
||||
TreeCellDataFunc (TFunc func) : m_func (std::move (func)) {}
|
||||
~TreeCellDataFunc () {}
|
||||
|
||||
MOO_DISABLE_COPY_OPS (TreeCellDataFunc);
|
||||
|
||||
static void destroy (gpointer d) { delete reinterpret_cast<TreeCellDataFunc*>(d); }
|
||||
|
||||
static void cell_data_func (GtkTreeViewColumn *tree_column,
|
||||
GtkCellRenderer *cell,
|
||||
GtkTreeModel *tree_model,
|
||||
GtkTreeIter *iter,
|
||||
gpointer p);
|
||||
|
||||
private:
|
||||
TFunc m_func;
|
||||
};
|
||||
|
||||
|
||||
template<>
|
||||
class moo::gobj_ref<GtkTreeView> : public virtual moo::gobj_ref_parent<GtkTreeView>
|
||||
{
|
||||
public:
|
||||
MOO_DEFINE_GOBJREF_METHODS (GtkTreeView);
|
||||
|
||||
static gtk::TreeViewPtr create (gtk::TreeModelPtr model);
|
||||
|
||||
gtk::TreeModelPtr get_model ();
|
||||
void set_model (gtk::TreeModelPtr model);
|
||||
GtkTreeSelection* get_selection ();
|
||||
GtkAdjustment* get_hadjustment ();
|
||||
void set_hadjustment (GtkAdjustment* adjustment);
|
||||
GtkAdjustment* get_vadjustment ();
|
||||
void set_vadjustment (GtkAdjustment* adjustment);
|
||||
bool get_headers_visible ();
|
||||
void set_headers_visible (bool headers_visible);
|
||||
void columns_autosize ();
|
||||
bool get_headers_clickable ();
|
||||
void set_headers_clickable (bool setting);
|
||||
void set_rules_hint (bool setting);
|
||||
bool get_rules_hint ();
|
||||
|
||||
/* Column funtions */
|
||||
int append_column (gtk::TreeViewColumn& column);
|
||||
int remove_column (gtk::TreeViewColumn& column);
|
||||
int insert_column (gtk::TreeViewColumn& column,
|
||||
int position);
|
||||
int insert_column_with_attributes (int position,
|
||||
const char* title,
|
||||
gtk::CellRenderer& cell,
|
||||
...) G_GNUC_NULL_TERMINATED;
|
||||
|
||||
template<typename TFunc>
|
||||
int insert_column_with_data_func (int position,
|
||||
const char* title,
|
||||
gtk::CellRenderer& cell,
|
||||
TFunc func);
|
||||
|
||||
gtk::TreeViewColumnPtr get_column (int n);
|
||||
std::vector<gtk::TreeViewColumnPtr> get_columns ();
|
||||
void move_column_after (gtk::TreeViewColumn& column,
|
||||
gtk::TreeViewColumn& base_column);
|
||||
void set_expander_column (gtk::TreeViewColumn& column);
|
||||
gtk::TreeViewColumnPtr get_expander_column ();
|
||||
void set_column_drag_function (GtkTreeViewColumnDropFunc func,
|
||||
gpointer user_data,
|
||||
GDestroyNotify destroy);
|
||||
|
||||
/* Actions */
|
||||
void scroll_to_point (int tree_x,
|
||||
int tree_y);
|
||||
void scroll_to_cell (GtkTreePath* path,
|
||||
gtk::TreeViewColumn& column,
|
||||
bool use_align,
|
||||
float row_align,
|
||||
float col_align);
|
||||
void row_activated (GtkTreePath* path,
|
||||
gtk::TreeViewColumn& column);
|
||||
void expand_all ();
|
||||
void collapse_all ();
|
||||
void expand_to_path (GtkTreePath* path);
|
||||
bool expand_row (GtkTreePath* path,
|
||||
bool open_all);
|
||||
bool collapse_row (GtkTreePath* path);
|
||||
void map_expanded_rows (GtkTreeViewMappingFunc func,
|
||||
gpointer data);
|
||||
bool row_expanded (GtkTreePath* path);
|
||||
void set_reorderable (bool reorderable);
|
||||
bool get_reorderable ();
|
||||
void set_cursor (GtkTreePath* path,
|
||||
gtk::TreeViewColumn& focus_column,
|
||||
bool start_editing);
|
||||
void set_cursor_on_cell (GtkTreePath* path,
|
||||
gtk::TreeViewColumn& focus_column,
|
||||
gtk::CellRenderer& focus_cell,
|
||||
bool start_editing);
|
||||
void get_cursor (GtkTreePath** path,
|
||||
gtk::TreeViewColumnPtr& focus_column);
|
||||
|
||||
/* Layout information */
|
||||
GdkWindow* get_bin_window ();
|
||||
bool get_path_at_pos (int x,
|
||||
int y,
|
||||
GtkTreePath** path,
|
||||
gtk::TreeViewColumnPtr& column,
|
||||
int* cell_x,
|
||||
int* cell_y);
|
||||
void get_cell_area (GtkTreePath* path,
|
||||
gtk::TreeViewColumn& column,
|
||||
GdkRectangle& rect);
|
||||
void get_background_area (GtkTreePath* path,
|
||||
gtk::TreeViewColumn& column,
|
||||
GdkRectangle& rect);
|
||||
void get_visible_rect (GdkRectangle& visible_rect);
|
||||
|
||||
bool get_visible_range (GtkTreePath** start_path,
|
||||
GtkTreePath** end_path);
|
||||
|
||||
/* Drag-and-Drop support */
|
||||
void enable_model_drag_source (GdkModifierType start_button_mask,
|
||||
const GtkTargetEntry* targets,
|
||||
int n_targets,
|
||||
GdkDragAction actions);
|
||||
void enable_model_drag_dest (const GtkTargetEntry* targets,
|
||||
int n_targets,
|
||||
GdkDragAction actions);
|
||||
void unset_rows_drag_source ();
|
||||
void unset_rows_drag_dest ();
|
||||
|
||||
/* These are useful to implement your own custom stuff. */
|
||||
void set_drag_dest_row (GtkTreePath* path,
|
||||
GtkTreeViewDropPosition pos);
|
||||
void get_drag_dest_row (GtkTreePath** path,
|
||||
GtkTreeViewDropPosition* pos);
|
||||
bool get_dest_row_at_pos (int drag_x,
|
||||
int drag_y,
|
||||
GtkTreePath** path,
|
||||
GtkTreeViewDropPosition* pos);
|
||||
GdkPixmap* create_row_drag_icon (GtkTreePath* path);
|
||||
|
||||
/* Interactive search */
|
||||
void set_enable_search (bool enable_search);
|
||||
bool get_enable_search ();
|
||||
int get_search_column ();
|
||||
void set_search_column (int column);
|
||||
GtkTreeViewSearchEqualFunc get_search_equal_func ();
|
||||
void set_search_equal_func (GtkTreeViewSearchEqualFunc search_equal_func,
|
||||
gpointer search_user_data,
|
||||
GDestroyNotify search_destroy);
|
||||
|
||||
GtkEntry* get_search_entry ();
|
||||
void set_search_entry (GtkEntry* entry);
|
||||
GtkTreeViewSearchPositionFunc get_search_position_func ();
|
||||
void set_search_position_func (GtkTreeViewSearchPositionFunc func,
|
||||
gpointer data,
|
||||
GDestroyNotify destroy);
|
||||
|
||||
/* Convert between the different coordinate systems */
|
||||
void convert_widget_to_tree_coords (int wx,
|
||||
int wy,
|
||||
int* tx,
|
||||
int* ty);
|
||||
void convert_tree_to_widget_coords (int tx,
|
||||
int ty,
|
||||
int* wx,
|
||||
int* wy);
|
||||
void convert_widget_to_bin_window_coords (int wx,
|
||||
int wy,
|
||||
int* bx,
|
||||
int* by);
|
||||
void convert_bin_window_to_widget_coords (int bx,
|
||||
int by,
|
||||
int* wx,
|
||||
int* wy);
|
||||
void convert_tree_to_bin_window_coords (int tx,
|
||||
int ty,
|
||||
int* bx,
|
||||
int* by);
|
||||
void convert_bin_window_to_tree_coords (int bx,
|
||||
int by,
|
||||
int* tx,
|
||||
int* ty);
|
||||
|
||||
void set_fixed_height_mode (bool enable);
|
||||
bool get_fixed_height_mode ();
|
||||
void set_hover_selection (bool hover);
|
||||
bool get_hover_selection ();
|
||||
void set_hover_expand (bool expand);
|
||||
bool get_hover_expand ();
|
||||
void set_rubber_banding (bool enable);
|
||||
bool get_rubber_banding ();
|
||||
|
||||
bool is_rubber_banding_active ();
|
||||
|
||||
GtkTreeViewRowSeparatorFunc get_row_separator_func ();
|
||||
void set_row_separator_func (GtkTreeViewRowSeparatorFunc func,
|
||||
gpointer data,
|
||||
GDestroyNotify destroy);
|
||||
|
||||
GtkTreeViewGridLines get_grid_lines ();
|
||||
void set_grid_lines (GtkTreeViewGridLines grid_lines);
|
||||
bool get_enable_tree_lines ();
|
||||
void set_enable_tree_lines (bool enabled);
|
||||
void set_show_expanders (bool enabled);
|
||||
bool get_show_expanders ();
|
||||
void set_level_indentation (int indentation);
|
||||
int get_level_indentation ();
|
||||
|
||||
/* Convenience functions for setting tooltips */
|
||||
void set_tooltip_row (GtkTooltip* tooltip,
|
||||
GtkTreePath* path);
|
||||
void set_tooltip_cell (GtkTooltip* tooltip,
|
||||
GtkTreePath* path,
|
||||
gtk::TreeViewColumn& column,
|
||||
gtk::CellRenderer& cell);
|
||||
bool get_tooltip_context (int* x,
|
||||
int* y,
|
||||
bool keyboard_tip,
|
||||
GtkTreeModel** model,
|
||||
GtkTreePath** path,
|
||||
GtkTreeIter* iter);
|
||||
void set_tooltip_column (int column);
|
||||
int get_tooltip_column ();
|
||||
};
|
||||
|
||||
template<>
|
||||
class moo::gobj_ref<GtkTreeViewColumn> : public virtual moo::gobj_ref_parent<GtkTreeViewColumn>
|
||||
{
|
||||
public:
|
||||
MOO_DEFINE_GOBJREF_METHODS (GtkTreeViewColumn);
|
||||
|
||||
static gtk::TreeViewColumnPtr create ();
|
||||
static gtk::TreeViewColumnPtr create (const char* title,
|
||||
gtk::CellRendererPtr cell,
|
||||
...) G_GNUC_NULL_TERMINATED;
|
||||
|
||||
void pack_start (gtk::CellRenderer& cell,
|
||||
bool expand);
|
||||
void pack_end (gtk::CellRenderer& cell,
|
||||
bool expand);
|
||||
void clear ();
|
||||
std::vector<gtk::CellRendererPtr> get_cell_renderers ();
|
||||
void add_attribute (gtk::CellRenderer& cell,
|
||||
const char* attribute,
|
||||
int column);
|
||||
|
||||
void set_attributes (gtk::CellRenderer& cell_renderer, const char* prop, int column);
|
||||
|
||||
template<typename... Args>
|
||||
void set_attributes (gtk::CellRenderer& cell_renderer, const char* prop, int column, Args&&... args)
|
||||
{
|
||||
set_attributes (cell_renderer, prop, column);
|
||||
set_attributes (cell_renderer, std::forward<Args> (args)...);
|
||||
}
|
||||
|
||||
// void TFunc(gtk::TreeViewColumn, gtk::CellRenderer, gtk::TreeModel, const GtkTreeIter&)
|
||||
template<typename TFunc>
|
||||
inline void set_cell_data_func (gtk::CellRenderer& cell_renderer, TFunc func);
|
||||
|
||||
void clear_attributes (gtk::CellRenderer& cell_renderer);
|
||||
void set_spacing (int spacing);
|
||||
int get_spacing ();
|
||||
void set_visible (bool visible);
|
||||
bool get_visible ();
|
||||
void set_resizable (bool resizable);
|
||||
bool get_resizable ();
|
||||
void set_sizing (GtkTreeViewColumnSizing type);
|
||||
GtkTreeViewColumnSizing get_sizing ();
|
||||
int get_width ();
|
||||
int get_fixed_width ();
|
||||
void set_fixed_width (int fixed_width);
|
||||
void set_min_width (int min_width);
|
||||
int get_min_width ();
|
||||
void set_max_width (int max_width);
|
||||
int get_max_width ();
|
||||
void clicked ();
|
||||
|
||||
/* Options for manipulating the column headers
|
||||
*/
|
||||
void set_title (const char* title);
|
||||
gstr get_title ();
|
||||
void set_expand (bool expand);
|
||||
bool get_expand ();
|
||||
void set_clickable (bool clickable);
|
||||
bool get_clickable ();
|
||||
void set_widget (gtk::WidgetPtr widget);
|
||||
gtk::WidgetPtr get_widget ();
|
||||
void set_alignment (float xalign);
|
||||
float get_alignment ();
|
||||
void set_reorderable (bool reorderable);
|
||||
bool get_reorderable ();
|
||||
|
||||
/* You probably only want to use gtk_tree_view_column_set_sort_column_id. The
|
||||
* other sorting functions exist primarily to let others do their own custom sorting.
|
||||
*/
|
||||
void set_sort_column_id (int sort_column_id);
|
||||
int get_sort_column_id ();
|
||||
void set_sort_indicator (bool setting);
|
||||
bool get_sort_indicator ();
|
||||
void set_sort_order (GtkSortType order);
|
||||
GtkSortType get_sort_order ();
|
||||
|
||||
gtk::TreeViewPtr get_tree_view ();
|
||||
};
|
||||
|
||||
template<>
|
||||
class moo::gobj_ref<GtkCellRenderer> : public virtual moo::gobj_ref_parent<GtkCellRenderer>
|
||||
{
|
||||
public:
|
||||
MOO_DEFINE_GOBJREF_METHODS (GtkCellRenderer);
|
||||
};
|
||||
|
||||
template<>
|
||||
class moo::gobj_ref<GtkCellRendererText> : public virtual moo::gobj_ref_parent<GtkCellRendererText>
|
||||
{
|
||||
public:
|
||||
MOO_DEFINE_GOBJREF_METHODS (GtkCellRendererText);
|
||||
|
||||
static gtk::CellRendererTextPtr create ();
|
||||
|
||||
void set_fixed_height_from_font (int number_of_rows);
|
||||
};
|
||||
|
||||
template<>
|
||||
class moo::gobj_ref<GtkCellRendererToggle> : public virtual moo::gobj_ref_parent<GtkCellRendererToggle>
|
||||
{
|
||||
public:
|
||||
MOO_DEFINE_GOBJREF_METHODS (GtkCellRendererToggle);
|
||||
|
||||
static gtk::CellRendererTogglePtr create ();
|
||||
|
||||
bool get_radio ();
|
||||
void set_radio (bool radio);
|
||||
bool get_active ();
|
||||
void set_active (bool active);
|
||||
};
|
||||
|
||||
template<>
|
||||
class moo::gobj_ref<GtkCellRendererPixbuf> : public virtual moo::gobj_ref_parent<GtkCellRendererPixbuf>
|
||||
{
|
||||
public:
|
||||
MOO_DEFINE_GOBJREF_METHODS (GtkCellRendererPixbuf);
|
||||
|
||||
static gtk::CellRendererPixbufPtr create ();
|
||||
};
|
||||
|
||||
|
||||
template<typename TFunc>
|
||||
inline void
|
||||
TreeCellDataFunc<TFunc>::cell_data_func (GtkTreeViewColumn *tree_column,
|
||||
GtkCellRenderer *cell,
|
||||
GtkTreeModel *tree_model,
|
||||
GtkTreeIter *iter,
|
||||
gpointer p)
|
||||
{
|
||||
g_return_if_fail (GTK_IS_TREE_VIEW_COLUMN (tree_column));
|
||||
g_return_if_fail (GTK_IS_CELL_RENDERER (cell));
|
||||
g_return_if_fail (GTK_IS_TREE_MODEL (tree_model));
|
||||
g_return_if_fail (iter != nullptr);
|
||||
g_return_if_fail (p != nullptr);
|
||||
TreeCellDataFunc& data = *reinterpret_cast<TreeCellDataFunc*>(p);
|
||||
data.m_func (moo::wrap (*tree_column), moo::wrap (*cell), moo::wrap (*tree_model),
|
||||
const_cast<const GtkTreeIter&>(*iter));
|
||||
}
|
||||
|
||||
|
||||
template<typename TFunc>
|
||||
inline int
|
||||
moo::gobj_ref<GtkTreeView>::insert_column_with_data_func (int position,
|
||||
const char* title,
|
||||
gtk::CellRenderer& cell,
|
||||
TFunc func)
|
||||
{
|
||||
TreeCellDataFunc<TFunc> *data = new TreeCellDataFunc<TFunc>{ std::move (func) };
|
||||
return gtk_tree_view_insert_column_with_data_func (gobj (), position, title, cell.gobj (),
|
||||
TreeCellDataFunc<TFunc>::cell_data_func, data,
|
||||
TreeCellDataFunc<TFunc>::destroy);
|
||||
}
|
||||
|
||||
|
||||
// void TFunc(gtk::TreeViewColumn, gtk::CellRenderer, gtk::TreeModel, const GtkTreeIter&)
|
||||
template<typename TFunc>
|
||||
inline void
|
||||
moo::gobj_ref<GtkTreeViewColumn>::set_cell_data_func (gtk::CellRenderer& cell_renderer, TFunc func)
|
||||
{
|
||||
TreeCellDataFunc<TFunc> *data = new TreeCellDataFunc<TFunc>{ std::move (func) };
|
||||
gtk_tree_view_column_set_cell_data_func (gobj (), cell_renderer.gobj (),
|
||||
TreeCellDataFunc<TFunc>::cell_data_func, data,
|
||||
TreeCellDataFunc<TFunc>::destroy);
|
||||
}
|
||||
|
||||
|
||||
MOO_DEFINE_FLAGS(GdkEventMask);
|
||||
MOO_DEFINE_FLAGS(GdkModifierType);
|
||||
MOO_DEFINE_FLAGS(GtkCellRendererState);
|
||||
MOO_DEFINE_FLAGS(GtkAttachOptions);
|
||||
MOO_DEFINE_FLAGS(GdkDragAction);
|
||||
|
||||
#endif // __cplusplus
|
|
@ -1,20 +0,0 @@
|
|||
/*
|
||||
* moocpp/gobjtypes.h
|
||||
*
|
||||
* Copyright (C) 2004-2016 by Yevgen Muntyan <emuntyan@users.sourceforge.net>
|
||||
*
|
||||
* This file is part of medit. medit 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.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public
|
||||
* License along with medit. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <moocpp/gobjtypes-glib.h>
|
||||
#include <moocpp/gobjtypes-gio.h>
|
||||
#include <moocpp/gobjtypes-gtk.h>
|
|
@ -1,111 +0,0 @@
|
|||
/*
|
||||
* moocpp/gobjwrapper.h
|
||||
*
|
||||
* Copyright (C) 2004-2016 by Yevgen Muntyan <emuntyan@users.sourceforge.net>
|
||||
*
|
||||
* This file is part of medit. medit 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.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public
|
||||
* License along with medit. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#pragma once
|
||||
|
||||
#ifdef __cplusplus
|
||||
|
||||
#include <moocpp/gobjinfo.h>
|
||||
#include <moocpp/gobjref.h>
|
||||
#include <moocpp/grefptr.h>
|
||||
#include <mooutils/mooutils-messages.h>
|
||||
|
||||
namespace moo {
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////////////////////
|
||||
//
|
||||
// gobj_wrapper
|
||||
//
|
||||
|
||||
class gobj_wrapper_base
|
||||
{
|
||||
protected:
|
||||
static gobj_wrapper_base& get(gobj_ref<GObject> g);
|
||||
|
||||
gobj_wrapper_base(gobj_ref<GObject> g);
|
||||
virtual ~gobj_wrapper_base();
|
||||
|
||||
MOO_DISABLE_COPY_OPS(gobj_wrapper_base);
|
||||
|
||||
private:
|
||||
static GQuark qdata_key;
|
||||
static void free_qdata(gpointer d);
|
||||
};
|
||||
|
||||
template<typename CObject, typename CppObject>
|
||||
class gobj_wrapper : public gobj_ref<CObject>, public gobj_wrapper_base
|
||||
{
|
||||
using obj_ref_type = gobj_ref<CObject>;
|
||||
using obj_ptr_type = gobj_ptr<CObject>;
|
||||
|
||||
public:
|
||||
template<typename ...Args>
|
||||
static gref_ptr<CppObject> create(Args&& ...args)
|
||||
{
|
||||
return create<CppObject>(std::forward<Args>(args)...);
|
||||
}
|
||||
|
||||
template<typename Subclass, typename ...Args>
|
||||
static gref_ptr<Subclass> create(Args&& ...args)
|
||||
{
|
||||
obj_ptr_type g = create_gobj<CObject>();
|
||||
gobj_wrapper_data d{g.gobj()};
|
||||
auto o = gref_ptr<Subclass>::create(d, std::forward<Args>(args)...);
|
||||
// Now g and o share the ref count, which is currently owned by the g pointer; steal it.
|
||||
g.release();
|
||||
return o;
|
||||
}
|
||||
|
||||
static CppObject& get(obj_ref_type gobj)
|
||||
{
|
||||
gobj_wrapper_base& b = gobj_wrapper_base::get(gobj);
|
||||
return static_cast<CppObject&>(b);
|
||||
}
|
||||
|
||||
CppObject* operator&() { return static_cast<CppObject*>(this); }
|
||||
|
||||
void ref()
|
||||
{
|
||||
g_object_ref (obj_ref_type::gobj());
|
||||
}
|
||||
|
||||
void unref()
|
||||
{
|
||||
g_object_unref (obj_ref_type::gobj());
|
||||
}
|
||||
|
||||
MOO_DISABLE_COPY_OPS(gobj_wrapper);
|
||||
|
||||
protected:
|
||||
struct gobj_wrapper_data { CObject* g; };
|
||||
|
||||
gobj_wrapper(gobj_wrapper_data& d)
|
||||
: obj_ref_type(*d.g)
|
||||
, gobj_wrapper_base(obj_ref_type(*d.g))
|
||||
{
|
||||
}
|
||||
|
||||
virtual ~gobj_wrapper()
|
||||
{
|
||||
}
|
||||
};
|
||||
|
||||
} // namespace moo
|
||||
|
||||
void g_signal_emit_valist(const moo::gobj_wrapper_base*, guint, GQuark, va_list) = delete;
|
||||
void g_signal_emit(const moo::gobj_wrapper_base*, guint, GQuark, ...) = delete;
|
||||
void g_signal_emit_by_name(const moo::gobj_wrapper_base*, const gchar*, ...) = delete;
|
||||
|
||||
#endif // __cplusplus
|
|
@ -1,193 +0,0 @@
|
|||
/*
|
||||
* moocpp/grefptr.h
|
||||
*
|
||||
* Copyright (C) 2004-2016 by Yevgen Muntyan <emuntyan@users.sourceforge.net>
|
||||
*
|
||||
* This file is part of medit. medit 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.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public
|
||||
* License along with medit. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#pragma once
|
||||
|
||||
#ifdef __cplusplus
|
||||
|
||||
#include "moocpp/utils.h"
|
||||
|
||||
namespace moo {
|
||||
|
||||
template<typename Object>
|
||||
struct obj_ref_unref
|
||||
{
|
||||
static void ref(Object* obj) { obj->ref(); }
|
||||
static void unref(Object* obj) { obj->unref(); }
|
||||
};
|
||||
|
||||
enum class ref_transfer
|
||||
{
|
||||
take_ownership,
|
||||
make_copy,
|
||||
};
|
||||
|
||||
template<typename Object,
|
||||
typename ObjRefUnref = obj_ref_unref<Object>>
|
||||
class gref_ptr
|
||||
{
|
||||
public:
|
||||
gref_ptr() : m_p(nullptr) {}
|
||||
gref_ptr(const nullptr_t&) : gref_ptr() {}
|
||||
|
||||
gref_ptr(Object* obj, ref_transfer policy)
|
||||
: gref_ptr()
|
||||
{
|
||||
assign(obj, policy);
|
||||
}
|
||||
|
||||
template<typename ...Args>
|
||||
static gref_ptr create(Args&& ...args)
|
||||
{
|
||||
return wrap_new(new Object(std::forward<Args>(args)...));
|
||||
}
|
||||
|
||||
static gref_ptr wrap_new(Object* obj)
|
||||
{
|
||||
return gref_ptr(obj, ref_transfer::take_ownership);
|
||||
}
|
||||
|
||||
~gref_ptr()
|
||||
{
|
||||
reset();
|
||||
}
|
||||
|
||||
void ref(Object* obj)
|
||||
{
|
||||
set(obj);
|
||||
}
|
||||
|
||||
void set(Object* obj)
|
||||
{
|
||||
assign(obj, ref_transfer::make_copy);
|
||||
}
|
||||
|
||||
void set_new(Object* obj)
|
||||
{
|
||||
assign(obj, ref_transfer::take_ownership);
|
||||
}
|
||||
|
||||
Object* release()
|
||||
{
|
||||
auto* tmp = m_p;
|
||||
m_p = nullptr;
|
||||
return tmp;
|
||||
}
|
||||
|
||||
void reset()
|
||||
{
|
||||
auto* tmp = m_p;
|
||||
m_p = nullptr;
|
||||
if (tmp)
|
||||
ObjRefUnref::unref(tmp);
|
||||
}
|
||||
|
||||
// Implicit conversion to Object* is dangerous because there is a lot
|
||||
// of code still which frees/steals objects directly. For example:
|
||||
// FooObject* tmp = x->s;
|
||||
// x->s = NULL;
|
||||
// g_object_unref (tmp);
|
||||
operator const Object* () const { return gobj(); }
|
||||
Object* gobj() const { return m_p; }
|
||||
Object& operator*() const { return *gobj(); }
|
||||
Object* operator->() const { return gobj(); }
|
||||
|
||||
// Explicitly forbid other pointer conversions. This way it's still possible to implement
|
||||
// implicit conversions in subclasses, like that to GTypeInstance in gobj_ptr.
|
||||
template<typename T>
|
||||
operator T*() const = delete;
|
||||
|
||||
operator bool() const { return gobj() != nullptr; }
|
||||
bool operator!() const { return gobj() == nullptr; }
|
||||
|
||||
template<typename X>
|
||||
bool operator==(X* other) const
|
||||
{
|
||||
return gobj() == other;
|
||||
}
|
||||
|
||||
template<typename X, typename Y>
|
||||
bool operator==(const gref_ptr<X, Y>& other) const
|
||||
{
|
||||
return gobj() == other.gobj();
|
||||
}
|
||||
|
||||
template<typename X>
|
||||
bool operator!=(const X& anything) const
|
||||
{
|
||||
return !(*this == anything);
|
||||
}
|
||||
|
||||
gref_ptr(const gref_ptr& other)
|
||||
: gref_ptr(other.gobj(), ref_transfer::make_copy)
|
||||
{
|
||||
}
|
||||
|
||||
gref_ptr(gref_ptr&& other)
|
||||
: gref_ptr()
|
||||
{
|
||||
this->m_p = other.m_p;
|
||||
other.m_p = nullptr;
|
||||
}
|
||||
|
||||
gref_ptr& operator=(const gref_ptr& other)
|
||||
{
|
||||
assign(other.gobj(), ref_transfer::make_copy);
|
||||
return *this;
|
||||
}
|
||||
|
||||
// Pointer assignment is easy to misuse
|
||||
template<typename T>
|
||||
gref_ptr& operator=(T* p) = delete;
|
||||
|
||||
gref_ptr& operator=(gref_ptr&& other)
|
||||
{
|
||||
if (gobj() != other.gobj())
|
||||
{
|
||||
assign(other.m_p, ref_transfer::take_ownership);
|
||||
other.m_p = nullptr;
|
||||
}
|
||||
|
||||
return *this;
|
||||
}
|
||||
|
||||
private:
|
||||
void assign(Object* obj, ref_transfer policy)
|
||||
{
|
||||
if (gobj() != obj)
|
||||
{
|
||||
Object* tmp = gobj();
|
||||
m_p = obj;
|
||||
if (obj && (policy == ref_transfer::make_copy))
|
||||
ObjRefUnref::ref(obj);
|
||||
if (tmp)
|
||||
ObjRefUnref::unref(tmp);
|
||||
}
|
||||
}
|
||||
|
||||
private:
|
||||
// This must be a raw pointer, so that zero-initialized gref_ptr is a valid null pointer
|
||||
Object* m_p;
|
||||
};
|
||||
|
||||
// Make sure these aren't called in code ported from pure glib C
|
||||
template<typename X>
|
||||
void g_object_unref(const gref_ptr<X>&) = delete;
|
||||
template<typename X>
|
||||
void g_free(const gref_ptr<X>&) = delete;
|
||||
|
||||
} // namespace moo
|
||||
|
||||
#endif // __cplusplus
|
|
@ -1,562 +0,0 @@
|
|||
/*
|
||||
* moogpp/strutils.cpp
|
||||
*
|
||||
* Copyright (C) 2004-2015 by Yevgen Muntyan <emuntyan@users.sourceforge.net>
|
||||
*
|
||||
* This file is part of medit. medit 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.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public
|
||||
* License along with medit. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#include "moogpp/strutils.h"
|
||||
#include <string.h>
|
||||
|
||||
using namespace g;
|
||||
|
||||
static bool str_equal(const char* s1, const char* s2)
|
||||
{
|
||||
if (!s1 || !*s1)
|
||||
return !s2 || !*s2;
|
||||
else if (!s2)
|
||||
return false;
|
||||
else
|
||||
return strcmp(s1, s2) == 0;
|
||||
}
|
||||
|
||||
bool g::operator==(const gstr& s1, const char* s2)
|
||||
{
|
||||
return str_equal(s1, s2);
|
||||
}
|
||||
|
||||
bool g::operator==(const char* s1, const gstr& s2)
|
||||
{
|
||||
return str_equal(s1, s2);
|
||||
}
|
||||
|
||||
bool g::operator==(const gstr& s1, const gstr& s2)
|
||||
{
|
||||
return str_equal(s1, s2);
|
||||
}
|
||||
|
||||
bool g::operator!=(const gstr& s1, const gstr& s2)
|
||||
{
|
||||
return !(s1 == s2);
|
||||
}
|
||||
|
||||
bool g::operator!=(const gstr& s1, const char* s2)
|
||||
{
|
||||
return !(s1 == s2);
|
||||
}
|
||||
|
||||
bool g::operator!=(const char* s1, const gstr& s2)
|
||||
{
|
||||
return !(s1 == s2);
|
||||
}
|
||||
|
||||
|
||||
class StringData
|
||||
{
|
||||
public:
|
||||
StringData(const char* s)
|
||||
: m_p(g_strdup(s))
|
||||
, m_ref(1)
|
||||
{
|
||||
}
|
||||
|
||||
~StringData()
|
||||
{
|
||||
::g_free(m_p);
|
||||
}
|
||||
|
||||
StringData(const StringData&) = delete;
|
||||
StringData& operator=(const StringData&) = delete;
|
||||
|
||||
char* get() const
|
||||
{
|
||||
return m_p;
|
||||
}
|
||||
|
||||
char* release()
|
||||
{
|
||||
char* ret = m_p;
|
||||
m_p = nullptr;
|
||||
return ret;
|
||||
}
|
||||
|
||||
void ref()
|
||||
{
|
||||
g_atomic_int_inc(&m_ref);
|
||||
}
|
||||
|
||||
void unref()
|
||||
{
|
||||
if (g_atomic_int_dec_and_test(&m_ref))
|
||||
delete this;
|
||||
}
|
||||
|
||||
int ref_count() const
|
||||
{
|
||||
return g_atomic_int_get(&m_ref);
|
||||
}
|
||||
|
||||
private:
|
||||
char* m_p;
|
||||
int m_ref;
|
||||
};
|
||||
|
||||
const gstr gstr::null;
|
||||
|
||||
gstr::gstr()
|
||||
: m_p(nullptr)
|
||||
, m_is_inline(true)
|
||||
, m_is_const(true)
|
||||
{
|
||||
}
|
||||
|
||||
gstr::gstr(const char* s, mem_transfer mt)
|
||||
: gstr()
|
||||
{
|
||||
if (s == nullptr)
|
||||
return;
|
||||
|
||||
if (*s == 0)
|
||||
{
|
||||
if (mt == mem_transfer::take_ownership)
|
||||
::g_free(const_cast<char*>(s));
|
||||
|
||||
mt = mem_transfer::borrow;
|
||||
s = "";
|
||||
}
|
||||
|
||||
switch (mt)
|
||||
{
|
||||
case mem_transfer::borrow:
|
||||
m_is_const = true;
|
||||
m_is_inline = true;
|
||||
m_p = const_cast<char*>(s);
|
||||
break;
|
||||
|
||||
case mem_transfer::make_copy:
|
||||
m_is_const = false;
|
||||
m_is_inline = true;
|
||||
m_p = g_strdup(s);
|
||||
break;
|
||||
|
||||
case mem_transfer::take_ownership:
|
||||
m_is_const = false;
|
||||
m_is_inline = true;
|
||||
m_p = const_cast<char*>(s);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
gstr::gstr(const gstr& other)
|
||||
: gstr()
|
||||
{
|
||||
if (other.m_p == nullptr)
|
||||
return;
|
||||
|
||||
if (other.m_is_const)
|
||||
{
|
||||
g_assert(other.m_is_inline);
|
||||
m_p = other.m_p;
|
||||
m_is_const = true;
|
||||
m_is_inline = true;
|
||||
}
|
||||
else
|
||||
{
|
||||
g_assert(other.m_p != nullptr);
|
||||
g_assert(!other.m_is_const);
|
||||
|
||||
StringData* d;
|
||||
|
||||
if (other.m_is_inline)
|
||||
{
|
||||
d = new StringData(static_cast<const char*>(other));
|
||||
}
|
||||
else
|
||||
{
|
||||
d = reinterpret_cast<StringData*>(other.m_p);
|
||||
d->ref();
|
||||
}
|
||||
|
||||
m_p = d;
|
||||
m_is_inline = false;
|
||||
m_is_const = false;
|
||||
}
|
||||
}
|
||||
|
||||
gstr& gstr::operator=(const gstr& other)
|
||||
{
|
||||
if (this != &other)
|
||||
{
|
||||
gstr tmp(other);
|
||||
*this = std::move(tmp);
|
||||
}
|
||||
|
||||
return *this;
|
||||
}
|
||||
|
||||
gstr::gstr(gstr&& other)
|
||||
: gstr()
|
||||
{
|
||||
*this = std::move(other);
|
||||
}
|
||||
|
||||
gstr& gstr::operator=(gstr&& other)
|
||||
{
|
||||
std::swap(m_is_const, other.m_is_const);
|
||||
std::swap(m_is_inline, other.m_is_inline);
|
||||
std::swap(m_p, other.m_p);
|
||||
return *this;
|
||||
}
|
||||
|
||||
gstr::gstr(gstrp&& s)
|
||||
: gstr(s.release(), mem_transfer::take_ownership)
|
||||
{
|
||||
}
|
||||
|
||||
gstr& gstr::operator= (gstrp&& s)
|
||||
{
|
||||
set_new (s.release ());
|
||||
return *this;
|
||||
}
|
||||
|
||||
gstr::~gstr()
|
||||
{
|
||||
clear();
|
||||
}
|
||||
|
||||
bool gstr::is_null() const
|
||||
{
|
||||
bool ret = (m_p == nullptr);
|
||||
g_assert(!ret || m_is_const == true);
|
||||
g_assert(!ret || m_is_inline == true);
|
||||
return ret;
|
||||
}
|
||||
|
||||
gstr::operator const char*() const
|
||||
{
|
||||
if (m_is_inline)
|
||||
return reinterpret_cast<char*>(m_p);
|
||||
else
|
||||
return reinterpret_cast<StringData*>(m_p)->get();
|
||||
}
|
||||
|
||||
void gstr::assign(const char* s, mem_transfer mt)
|
||||
{
|
||||
gstr tmp(s, mt);
|
||||
*this = std::move(tmp);
|
||||
}
|
||||
|
||||
void gstr::clear()
|
||||
{
|
||||
if (m_p == nullptr)
|
||||
return;
|
||||
|
||||
if (!m_is_const)
|
||||
{
|
||||
g_assert(m_p != nullptr);
|
||||
|
||||
if (m_is_inline)
|
||||
::g_free(m_p);
|
||||
else
|
||||
reinterpret_cast<StringData*>(m_p)->unref();
|
||||
|
||||
m_is_const = true;
|
||||
}
|
||||
|
||||
m_is_inline = true;
|
||||
m_p = nullptr;
|
||||
}
|
||||
|
||||
char* gstr::get_mutable()
|
||||
{
|
||||
if (!m_p)
|
||||
{
|
||||
return nullptr;
|
||||
}
|
||||
else if (m_is_const)
|
||||
{
|
||||
char* s = reinterpret_cast<char*>(m_p);
|
||||
|
||||
if (*s != 0)
|
||||
{
|
||||
set(s);
|
||||
g_assert(!m_is_const);
|
||||
g_assert(m_is_inline);
|
||||
}
|
||||
|
||||
return reinterpret_cast<char*>(m_p);
|
||||
}
|
||||
else if (m_is_inline)
|
||||
{
|
||||
return reinterpret_cast<char*>(m_p);
|
||||
}
|
||||
else
|
||||
{
|
||||
StringData* d = reinterpret_cast<StringData*>(m_p);
|
||||
g_assert(d->get() && *d->get());
|
||||
|
||||
if (d->ref_count() == 1)
|
||||
{
|
||||
return d->get();
|
||||
}
|
||||
else
|
||||
{
|
||||
m_p = g_strdup(d->get());
|
||||
m_is_inline = true;
|
||||
return reinterpret_cast<char*>(m_p);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
char* gstr::release_owned()
|
||||
{
|
||||
if (m_p == nullptr)
|
||||
{
|
||||
return nullptr;
|
||||
}
|
||||
else if (m_is_const)
|
||||
{
|
||||
return g_strdup(get());
|
||||
}
|
||||
else if (m_is_inline)
|
||||
{
|
||||
m_is_const = true;
|
||||
char* p = reinterpret_cast<char*>(m_p);
|
||||
m_p = nullptr;
|
||||
return p;
|
||||
}
|
||||
|
||||
StringData* d = reinterpret_cast<StringData*>(m_p);
|
||||
g_assert(d->get() && *d->get());
|
||||
|
||||
char* p = d->ref_count() == 1 ? d->release() : g_strdup(d->get());
|
||||
|
||||
d->unref();
|
||||
|
||||
m_p = nullptr;
|
||||
m_is_const = true;
|
||||
m_is_inline = true;
|
||||
return p;
|
||||
}
|
||||
|
||||
gstr gstr::vprintf(const char* format, va_list args)
|
||||
{
|
||||
return gstr::wrap_new(g_strdup_vprintf(format, args));
|
||||
}
|
||||
|
||||
|
||||
size_t std::hash<g::gstr>::operator()(const g::gstr& s) const
|
||||
{
|
||||
return g_str_hash (s.is_null () ? "" : s.get ());
|
||||
}
|
||||
|
||||
|
||||
gstrvec g::convert(gstrv v)
|
||||
{
|
||||
char** pv = v.release();
|
||||
|
||||
gstrvec ret;
|
||||
ret.reserve(g_strv_length(pv));
|
||||
|
||||
for (gsize i = 0, c = ret.size(); i < c; ++i)
|
||||
ret.emplace_back(gstr::wrap_new(pv[i]));
|
||||
|
||||
::g_free(pv);
|
||||
return ret;
|
||||
}
|
||||
|
||||
|
||||
gstrv gstrv::convert(gstrvec v)
|
||||
{
|
||||
const gsize c = v.size();
|
||||
char **p = g_new (char*, c + 1);
|
||||
for (gsize i = 0; i < c; ++i)
|
||||
p[i] = v[i].release_owned();
|
||||
p[c] = nullptr;
|
||||
return p;
|
||||
}
|
||||
|
||||
|
||||
strbuilder::strbuilder(const char *init, gssize len)
|
||||
: m_buf(nullptr)
|
||||
, m_result(nullptr)
|
||||
{
|
||||
if (init != nullptr)
|
||||
m_buf = g_string_new_len(init, len);
|
||||
else if (len > 0)
|
||||
m_buf = g_string_sized_new(len);
|
||||
else
|
||||
m_buf = g_string_new(nullptr);
|
||||
}
|
||||
|
||||
strbuilder::strbuilder(gsize reserve)
|
||||
: strbuilder(nullptr, reserve)
|
||||
{
|
||||
}
|
||||
|
||||
strbuilder::~strbuilder()
|
||||
{
|
||||
if (m_buf)
|
||||
g_string_free (m_buf, true);
|
||||
}
|
||||
|
||||
gstr strbuilder::release()
|
||||
{
|
||||
if (m_result)
|
||||
{
|
||||
return gstr::wrap_new(m_result.release());
|
||||
}
|
||||
else if (m_buf)
|
||||
{
|
||||
gstr s = gstr::wrap_new(g_string_free(m_buf, false));
|
||||
m_buf = nullptr;
|
||||
return s;
|
||||
}
|
||||
else
|
||||
{
|
||||
g_return_val_if_reached(gstr::null);
|
||||
}
|
||||
}
|
||||
|
||||
const char* strbuilder::get() const
|
||||
{
|
||||
if (m_buf)
|
||||
{
|
||||
m_result.set_new (g_string_free (m_buf, false));
|
||||
m_buf = nullptr;
|
||||
}
|
||||
|
||||
g_return_val_if_fail(m_result, nullptr);
|
||||
return m_result;
|
||||
}
|
||||
|
||||
void strbuilder::truncate(gsize len)
|
||||
{
|
||||
g_return_if_fail(m_buf);
|
||||
g_string_truncate(m_buf, len);
|
||||
}
|
||||
|
||||
void strbuilder::set_size(gsize len)
|
||||
{
|
||||
g_return_if_fail(m_buf);
|
||||
g_string_set_size(m_buf, len);
|
||||
}
|
||||
|
||||
void strbuilder::append(const char* val, gssize len)
|
||||
{
|
||||
g_return_if_fail(m_buf);
|
||||
g_string_append_len(m_buf, val, len);
|
||||
}
|
||||
|
||||
void strbuilder::append(const gstrp& val)
|
||||
{
|
||||
append(val.get());
|
||||
}
|
||||
|
||||
void strbuilder::append(char c)
|
||||
{
|
||||
g_return_if_fail(m_buf);
|
||||
g_string_append_c(m_buf, c);
|
||||
}
|
||||
|
||||
void strbuilder::append(gunichar wc)
|
||||
{
|
||||
g_return_if_fail(m_buf);
|
||||
g_string_append_unichar(m_buf, wc);
|
||||
}
|
||||
|
||||
void strbuilder::prepend(const char* val, gssize len)
|
||||
{
|
||||
g_return_if_fail(m_buf);
|
||||
g_string_prepend_len(m_buf, val, len);
|
||||
}
|
||||
|
||||
void strbuilder::prepend(const gstrp& val)
|
||||
{
|
||||
prepend(val.get());
|
||||
}
|
||||
|
||||
void strbuilder::prepend(char c)
|
||||
{
|
||||
g_return_if_fail(m_buf);
|
||||
g_string_prepend_c(m_buf, c);
|
||||
}
|
||||
|
||||
void strbuilder::prepend(gunichar wc)
|
||||
{
|
||||
g_return_if_fail(m_buf);
|
||||
g_string_prepend_unichar(m_buf, wc);
|
||||
}
|
||||
|
||||
void strbuilder::insert(gssize pos, const char* val, gssize len)
|
||||
{
|
||||
g_return_if_fail(m_buf);
|
||||
g_string_insert_len(m_buf, pos, val, len);
|
||||
}
|
||||
|
||||
void strbuilder::insert(gssize pos, const gstrp& val)
|
||||
{
|
||||
insert(pos, val.get());
|
||||
}
|
||||
|
||||
void strbuilder::insert(gssize pos, char c)
|
||||
{
|
||||
g_return_if_fail(m_buf);
|
||||
g_string_insert_c(m_buf, pos, c);
|
||||
}
|
||||
|
||||
void strbuilder::insert(gssize pos, gunichar wc)
|
||||
{
|
||||
g_return_if_fail(m_buf);
|
||||
g_string_insert_c(m_buf, pos, wc);
|
||||
}
|
||||
|
||||
void strbuilder::overwrite(gsize pos, const char* val, gssize len)
|
||||
{
|
||||
g_return_if_fail(m_buf);
|
||||
g_string_overwrite_len(m_buf, pos, val, len);
|
||||
}
|
||||
|
||||
void strbuilder::erase(gssize pos, gssize len)
|
||||
{
|
||||
g_return_if_fail(m_buf);
|
||||
g_string_erase(m_buf, pos, len);
|
||||
}
|
||||
|
||||
void strbuilder::ascii_down()
|
||||
{
|
||||
g_return_if_fail(m_buf);
|
||||
g_string_ascii_down(m_buf);
|
||||
}
|
||||
|
||||
void strbuilder::ascii_up()
|
||||
{
|
||||
g_return_if_fail(m_buf);
|
||||
g_string_ascii_up(m_buf);
|
||||
}
|
||||
|
||||
void strbuilder::vprintf(const char* format, va_list args)
|
||||
{
|
||||
g_return_if_fail(m_buf);
|
||||
g_string_vprintf(m_buf, format, args);
|
||||
}
|
||||
|
||||
void strbuilder::append_vprintf(const char* format, va_list args)
|
||||
{
|
||||
g_return_if_fail(m_buf);
|
||||
g_string_append_vprintf(m_buf, format, args);
|
||||
}
|
||||
|
||||
void strbuilder::append_uri_escaped(const char* unescaped, const char* reserved_chars_allowed, bool allow_utf8)
|
||||
{
|
||||
g_return_if_fail(m_buf);
|
||||
g_string_append_uri_escaped(m_buf, unescaped, reserved_chars_allowed, allow_utf8);
|
||||
}
|
|
@ -1,415 +0,0 @@
|
|||
/*
|
||||
* moogpp/strutils.h
|
||||
*
|
||||
* Copyright (C) 2004-2016 by Yevgen Muntyan <emuntyan@users.sourceforge.net>
|
||||
*
|
||||
* This file is part of medit. medit 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.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public
|
||||
* License along with medit. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#pragma once
|
||||
|
||||
#ifndef __cplusplus
|
||||
#error "This is a C++ header"
|
||||
#endif
|
||||
|
||||
#include <moogpp/memutils.h>
|
||||
|
||||
#include <algorithm>
|
||||
#include <utility>
|
||||
#include <functional>
|
||||
#include <vector>
|
||||
#include <unordered_set>
|
||||
#include <unordered_map>
|
||||
#include <type_traits>
|
||||
#include <stdarg.h>
|
||||
|
||||
namespace g {
|
||||
|
||||
class gstr;
|
||||
class gstrp;
|
||||
|
||||
// Replacement for raw char*
|
||||
class gstrp : public gbuf<char>
|
||||
{
|
||||
public:
|
||||
explicit gstrp(char* p = nullptr) : gbuf(p) {}
|
||||
|
||||
gstrp(gstrp&& s) : gbuf(std::move(s)) {}
|
||||
gstrp& operator=(gstrp&& s) { static_cast<gbuf<char>&>(*this) = std::move(s); return *this; }
|
||||
|
||||
char*& p() { return _get(); }
|
||||
char** pp() { return &_get(); }
|
||||
|
||||
gstrp(const gstrp&) = delete;
|
||||
gstrp& operator=(const gstrp&) = delete;
|
||||
|
||||
bool operator==(const char* p) const { return get() == p; }
|
||||
bool operator!=(const char* p) const { return get() != p; }
|
||||
};
|
||||
|
||||
struct printf_helper
|
||||
{
|
||||
template<typename ...Args>
|
||||
struct is_valid_arg
|
||||
{
|
||||
static const bool value = true;
|
||||
};
|
||||
|
||||
template<typename T, class... Args>
|
||||
struct is_valid_arg<T, Args...>
|
||||
{
|
||||
static_assert(std::is_trivial<typename std::remove_reference<T>::type>::value, "An object passed to a printf-like function");
|
||||
static const bool value =
|
||||
std::is_trivial<typename std::remove_reference<T>::type>::value
|
||||
&& is_valid_arg<Args...>::value;
|
||||
};
|
||||
|
||||
template<typename T>
|
||||
static const T& transform_printf_arg (const T& arg);
|
||||
static const char* transform_printf_arg(const gstr& s);
|
||||
static const char* transform_printf_arg(const gstrp& s);
|
||||
|
||||
// gcc seems to actually evaluate what's inside decltype(), and it can't cope with literals or va_list()
|
||||
static const char* dummy_format_string;
|
||||
static va_list dummy_va_list;
|
||||
|
||||
template<typename Func, typename ...Args>
|
||||
static auto call (const Func& func, const char* format, Args&& ...args) -> decltype(func(dummy_format_string))
|
||||
{
|
||||
g_assert (printf_helper::is_valid_arg<decltype(printf_helper::transform_printf_arg (std::forward<Args> (args)))...>::value);
|
||||
return func(format, printf_helper::transform_printf_arg (std::forward<Args> (args))...);
|
||||
}
|
||||
|
||||
template<typename Func, typename ...Args>
|
||||
static auto callv (const Func& func, const char* format, Args&& ...args) -> decltype(func(dummy_format_string, dummy_va_list))
|
||||
{
|
||||
g_assert (printf_helper::is_valid_arg<decltype(printf_helper::transform_printf_arg (std::forward<Args> (args)))...>::value);
|
||||
return call_helper (func, format, printf_helper::transform_printf_arg (std::forward<Args> (args))...);
|
||||
}
|
||||
|
||||
template<typename Func, typename ...Args>
|
||||
static void call_void (const Func& func, const char* format, Args&& ...args)
|
||||
{
|
||||
g_assert (printf_helper::is_valid_arg<decltype(printf_helper::transform_printf_arg (std::forward<Args> (args)))...>::value);
|
||||
func (format, printf_helper::transform_printf_arg (std::forward<Args> (args))...);
|
||||
}
|
||||
|
||||
template<typename Func, typename ...Args>
|
||||
static void callv_void (const Func& func, const char* format, Args&& ...args)
|
||||
{
|
||||
g_assert (printf_helper::is_valid_arg<decltype(printf_helper::transform_printf_arg (std::forward<Args> (args)))...>::value);
|
||||
call_helper_void (func, format, printf_helper::transform_printf_arg (std::forward<Args> (args))...);
|
||||
}
|
||||
|
||||
private:
|
||||
template<typename Func>
|
||||
static auto call_helper (const Func& func, const char* format, ...) -> decltype(func(dummy_format_string, dummy_va_list))
|
||||
{
|
||||
va_list args;
|
||||
va_start(args, format);
|
||||
auto ret = func(format, args);
|
||||
va_end(args);
|
||||
return ret;
|
||||
}
|
||||
|
||||
template<typename Func>
|
||||
static void call_helper_void (const Func& func, const char* format, ...)
|
||||
{
|
||||
va_list args;
|
||||
va_start (args, format);
|
||||
func (format, args);
|
||||
va_end (args);
|
||||
}
|
||||
};
|
||||
|
||||
class gstr
|
||||
{
|
||||
public:
|
||||
gstr();
|
||||
~gstr();
|
||||
gstr(const char* s, mem_transfer mt);
|
||||
gstr(gstrp&& s);
|
||||
|
||||
static const gstr null;
|
||||
|
||||
gstr(const gstr&);
|
||||
gstr& operator=(const gstr&);
|
||||
gstr(gstr&&);
|
||||
gstr& operator=(gstr&&);
|
||||
gstr& operator=(gstrp&&);
|
||||
|
||||
gstr(nullptr_t) : gstr() {}
|
||||
gstr& operator=(nullptr_t) { clear(); return *this; }
|
||||
|
||||
gstr(const gstr&, mem_transfer) = delete;
|
||||
void set(const gstr& s) = delete;
|
||||
void set_const(const gstr& s) = delete;
|
||||
void set_new(const gstr& s) = delete;
|
||||
static gstr wrap(const gstr& s) = delete;
|
||||
static gstr wrap_const(const gstr& s) = delete;
|
||||
static gstr wrap_new(const gstr& s) = delete;
|
||||
|
||||
void set(const char *s) { assign(s, mem_transfer::make_copy); }
|
||||
void set_new(char *s) { assign(s, mem_transfer::take_ownership); }
|
||||
void set_const(const char *s) { assign(s, mem_transfer::borrow); }
|
||||
static gstr wrap(const char *s) { return gstr(s, mem_transfer::make_copy); }
|
||||
static gstr wrap_new(char *s) { return gstr(s, mem_transfer::take_ownership); }
|
||||
static gstr wrap_const(const char *s) { return gstr(s, mem_transfer::borrow); }
|
||||
|
||||
bool is_null() const;
|
||||
|
||||
operator const char*() const;
|
||||
const char* get() const { return static_cast<const char*>(*this); }
|
||||
const char* get_non_null() const { return is_null() ? "" : get(); }
|
||||
|
||||
char* get_mutable();
|
||||
char* release_owned();
|
||||
void clear();
|
||||
void reset() { clear(); }
|
||||
|
||||
char *strdup() const { return g_strdup(*this); }
|
||||
bool empty() const { const char* s = *this; return !s || !*s; }
|
||||
|
||||
// These must not be called, to avoid ambiguity between an empty string and null
|
||||
operator bool() const = delete;
|
||||
bool operator!() const = delete;
|
||||
|
||||
static gstr vprintf(const char* format, va_list args) G_GNUC_PRINTF(1, 0);
|
||||
|
||||
template<typename ...Args>
|
||||
static gstr printf(const char* format, Args&& ...args)
|
||||
{
|
||||
return wrap_new (printf_helper::callv (g_strdup_vprintf, format, std::forward<Args> (args)...));
|
||||
}
|
||||
|
||||
template<typename ...Args>
|
||||
void set_printf (const char* format, Args&& ...args)
|
||||
{
|
||||
set_new (printf_helper::callv (g_strdup_vprintf, format, std::forward<Args> (args)...));
|
||||
}
|
||||
|
||||
private:
|
||||
void assign(const char* s, mem_transfer mt);
|
||||
|
||||
private:
|
||||
void *m_p; // either char* or Data*
|
||||
bool m_is_inline;
|
||||
bool m_is_const;
|
||||
};
|
||||
|
||||
|
||||
template<typename T>
|
||||
inline const T& printf_helper::transform_printf_arg (const T& arg)
|
||||
{
|
||||
g_assert (is_valid_arg<T>::value);
|
||||
return arg;
|
||||
}
|
||||
|
||||
inline const char* printf_helper::transform_printf_arg(const gstr& s)
|
||||
{
|
||||
return s.get ();
|
||||
}
|
||||
|
||||
inline const char* printf_helper::transform_printf_arg(const gstrp& s)
|
||||
{
|
||||
return s.get ();
|
||||
}
|
||||
|
||||
|
||||
using gstrvec = std::vector<gstr>;
|
||||
using gstrset = std::unordered_set<gstr>;
|
||||
using gstrmap = std::unordered_map<gstr, gstr>;
|
||||
|
||||
|
||||
bool operator==(const gstr& s1, const char* s2);
|
||||
bool operator==(const char* s1, const gstr& s2);
|
||||
bool operator==(const gstr& s1, const gstr& s2);
|
||||
bool operator!=(const gstr& s1, const char* s2);
|
||||
bool operator!=(const char* s1, const gstr& s2);
|
||||
bool operator!=(const gstr& s1, const gstr& s2);
|
||||
bool operator==(const gstr&, nullptr_t) = delete;
|
||||
bool operator==(nullptr_t, const gstr&) = delete;
|
||||
|
||||
|
||||
class strv
|
||||
{
|
||||
public:
|
||||
strv(char** p = nullptr) : m_p(p) {}
|
||||
~strv() { ::g_strfreev(m_p); }
|
||||
|
||||
void set(char** p) { if (m_p != p) { ::g_strfreev(m_p); m_p = p; } }
|
||||
void reset(char** p = nullptr) { set(p); }
|
||||
char** get() const { return m_p; }
|
||||
|
||||
static strv convert(gstrvec v);
|
||||
|
||||
gsize size() const { return m_p ? g_strv_length (m_p) : 0; }
|
||||
|
||||
operator char**() const = delete;
|
||||
char*** operator&() = delete;
|
||||
|
||||
char** release() { char** p = m_p; m_p = nullptr; return p; }
|
||||
|
||||
const char* operator[] (gsize i) const { return m_p[i]; }
|
||||
|
||||
strv(const strv&) = delete;
|
||||
strv& operator=(const strv&) = delete;
|
||||
|
||||
strv(strv&& other) : strv() { *this = std::move(other); }
|
||||
strv& operator=(strv&& other) { std::swap(m_p, other.m_p); return *this; }
|
||||
|
||||
strv& operator=(char** p) { set(p); return *this; }
|
||||
|
||||
bool operator==(nullptr_t) const { return m_p == nullptr; }
|
||||
bool operator!=(nullptr_t) const { return m_p != nullptr; }
|
||||
operator bool() const { return m_p != nullptr; }
|
||||
bool operator !() const { return m_p == nullptr; }
|
||||
|
||||
private:
|
||||
char** m_p;
|
||||
};
|
||||
|
||||
gstrvec convert(strv v);
|
||||
|
||||
class gerrp
|
||||
{
|
||||
public:
|
||||
explicit gerrp(GError** errp = nullptr) : m_errp(errp ? errp : &m_local), m_local(nullptr) {}
|
||||
|
||||
~gerrp()
|
||||
{
|
||||
if (m_errp != &m_local)
|
||||
clear();
|
||||
}
|
||||
|
||||
operator bool() const { return (*m_errp) != nullptr; }
|
||||
bool operator!() const { return (*m_errp) == nullptr; }
|
||||
|
||||
GError* get() const { return (*m_errp); }
|
||||
GError* operator->() const { return (*m_errp); }
|
||||
GError** operator&() { return m_errp; }
|
||||
|
||||
//void propagate(GError** dest) { g_propagate_error(dest, m_err); m_err = nullptr; }
|
||||
void clear() { if (*m_errp) g_error_free(*m_errp); *m_errp = nullptr; m_local = nullptr; }
|
||||
|
||||
gerrp(const gerrp&) = delete;
|
||||
gerrp& operator=(const gerrp&) = delete;
|
||||
|
||||
gerrp(gerrp&& other) = delete;
|
||||
|
||||
gerrp& operator=(gerrp&& other)
|
||||
{
|
||||
clear();
|
||||
if (other)
|
||||
g_propagate_error (m_errp, other.get());
|
||||
other.m_errp = &other.m_local;
|
||||
other.m_local = nullptr;
|
||||
return *this;
|
||||
}
|
||||
|
||||
private:
|
||||
GError** m_errp;
|
||||
GError* m_local;
|
||||
};
|
||||
|
||||
|
||||
class strbuilder
|
||||
{
|
||||
public:
|
||||
strbuilder(const char *init = nullptr, gssize len = -1);
|
||||
strbuilder(gsize reserve);
|
||||
~strbuilder();
|
||||
|
||||
gstr release();
|
||||
const char* get() const;
|
||||
|
||||
strbuilder(const strbuilder&) = delete;
|
||||
strbuilder& operator=(const strbuilder&) = delete;
|
||||
|
||||
void truncate(gsize len);
|
||||
void set_size(gsize len);
|
||||
void append(const char* val, gssize len = -1);
|
||||
void append(const gstrp& val);
|
||||
void append(char c);
|
||||
void append(gunichar wc);
|
||||
void prepend(const char* val, gssize len = -1);
|
||||
void prepend(const gstrp& val);
|
||||
void prepend(char c);
|
||||
void prepend(gunichar wc);
|
||||
void insert(gssize pos, const char* val, gssize len = -1);
|
||||
void insert(gssize pos, const gstrp& val);
|
||||
void insert(gssize pos, char c);
|
||||
void insert(gssize pos, gunichar wc);
|
||||
void overwrite(gsize pos, const char* val, gssize len = -1);
|
||||
void erase(gssize pos = 0, gssize len = -1);
|
||||
void ascii_down();
|
||||
void ascii_up();
|
||||
void vprintf(const char* format, va_list args);
|
||||
void append_vprintf(const char* format, va_list args);
|
||||
void append_uri_escaped(const char* unescaped, const char* reserved_chars_allowed = nullptr, bool allow_utf8 = false);
|
||||
|
||||
template<typename ...Args>
|
||||
void printf (const char* format, Args&& ...args)
|
||||
{
|
||||
g_return_if_fail (m_buf);
|
||||
printf_helper::callv_void ([&] (const char* format, va_list args) { g_string_vprintf (m_buf, format, args); },
|
||||
format, std::forward<Args> (args)...);
|
||||
}
|
||||
|
||||
template<typename ...Args>
|
||||
void append_printf (const char* format, Args&& ...args)
|
||||
{
|
||||
g_return_if_fail (m_buf);
|
||||
printf_helper::callv_void ([&] (const char* format, va_list args) { g_string_append_vprintf (m_buf, format, args); },
|
||||
format, std::forward<Args>(args)...);
|
||||
}
|
||||
|
||||
private:
|
||||
mutable GString* m_buf;
|
||||
mutable gstrp m_result;
|
||||
};
|
||||
|
||||
//gstrvec convert(strv v);
|
||||
|
||||
void g_free(const gstr&) = delete;
|
||||
void g_free(const gstrp&) = delete;
|
||||
void g_free(const strv&) = delete;
|
||||
void g_strfreev(const strv&) = delete;
|
||||
|
||||
} // namespace g
|
||||
|
||||
namespace std {
|
||||
|
||||
template<>
|
||||
struct hash<::g::gstr>
|
||||
{
|
||||
size_t operator()(const ::g::gstr& s) const;
|
||||
};
|
||||
|
||||
} // namespace std
|
||||
|
||||
template<typename ...Args>
|
||||
inline void moo_g_print(const char* format, Args&& ...args)
|
||||
{
|
||||
static_assert(g::printf_helper::is_valid_arg<Args...>::value, "Passed an object to g_strdup_printf");
|
||||
g_print (format, std::forward<Args> (args)...);
|
||||
}
|
||||
|
||||
template<typename ...Args>
|
||||
inline char* moo_g_strdup_printf (const char* format, Args&& ...args)
|
||||
{
|
||||
static_assert(g::printf_helper::is_valid_arg<Args...>::value, "Passed an object to g_strdup_printf");
|
||||
return g_strdup_printf (format, std::forward<Args> (args)...);
|
||||
}
|
||||
|
||||
#undef g_strdup_printf
|
||||
#undef g_print
|
||||
#define g_strdup_printf moo_g_strdup_printf
|
||||
#define g_print moo_g_print
|
|
@ -2079,6 +2079,8 @@ idle_worker (GtkSourceContextEngine *ce)
|
|||
|
||||
g_return_val_if_fail (ce->priv->buffer != NULL, FALSE);
|
||||
|
||||
gdk_threads_enter ();
|
||||
|
||||
/* analyze batch of text */
|
||||
update_syntax (ce, NULL, INCREMENTAL_UPDATE_TIME_SLICE);
|
||||
CHECK_TREE (ce);
|
||||
|
@ -2089,6 +2091,8 @@ idle_worker (GtkSourceContextEngine *ce)
|
|||
retval = FALSE;
|
||||
}
|
||||
|
||||
gdk_threads_leave ();
|
||||
|
||||
return retval;
|
||||
}
|
||||
|
||||
|
@ -2105,6 +2109,8 @@ first_update_callback (GtkSourceContextEngine *ce)
|
|||
{
|
||||
g_return_val_if_fail (ce->priv->buffer != NULL, FALSE);
|
||||
|
||||
gdk_threads_enter ();
|
||||
|
||||
/* analyze batch of text */
|
||||
update_syntax (ce, NULL, FIRST_UPDATE_TIME_SLICE);
|
||||
CHECK_TREE (ce);
|
||||
|
@ -2114,6 +2120,8 @@ first_update_callback (GtkSourceContextEngine *ce)
|
|||
if (!all_analyzed (ce))
|
||||
install_idle_worker (ce);
|
||||
|
||||
gdk_threads_leave ();
|
||||
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
|
|
|
@ -692,7 +692,7 @@ apply_cursor_style (GtkSourceStyleScheme *scheme,
|
|||
|
||||
if (primary != NULL && secondary == NULL)
|
||||
{
|
||||
secondary_color = gtk_widget_get_style(widget)->base[GTK_STATE_NORMAL];
|
||||
secondary_color = widget->style->base[GTK_STATE_NORMAL];
|
||||
secondary_color.red = ((gint) secondary_color.red + primary->red) / 2;
|
||||
secondary_color.green = ((gint) secondary_color.green + primary->green) / 2;
|
||||
secondary_color.blue = ((gint) secondary_color.blue + primary->blue) / 2;
|
||||
|
|
|
@ -39,7 +39,7 @@ medit_SOURCES = \
|
|||
medit-app/mem-debug.h \
|
||||
medit-app/run-tests.h \
|
||||
medit-app/parse.h \
|
||||
medit-app/main.cpp \
|
||||
medit-app/main.c \
|
||||
$(moo_sources) \
|
||||
$(plugins_sources)
|
||||
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
/*
|
||||
* main.cpp
|
||||
* medit-app.c
|
||||
*
|
||||
* Copyright (C) 2004-2016 by Yevgen Muntyan <emuntyan@users.sourceforge.net>
|
||||
* Copyright (C) 2004-2010 by Yevgen Muntyan <emuntyan@users.sourceforge.net>
|
||||
*
|
||||
* This file is part of medit. medit is free software; you can
|
||||
* redistribute it and/or modify it under the terms of the
|
||||
|
@ -21,7 +21,6 @@
|
|||
#include "mooutils/mooutils-misc.h"
|
||||
#include "mooutils/mootype-macros.h"
|
||||
#include "plugins/mooplugin-builtin.h"
|
||||
#include "moocpp/moocpp.h"
|
||||
#include <gtk/gtk.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
|
@ -31,12 +30,9 @@
|
|||
#include "run-tests.h"
|
||||
#ifdef GDK_WINDOWING_WIN32
|
||||
#include <gdk/gdkwin32.h>
|
||||
#include <windows.h>
|
||||
#include <windowsx.h>
|
||||
#endif
|
||||
|
||||
using namespace moo;
|
||||
|
||||
static struct MeditOpts {
|
||||
int use_session;
|
||||
int pid;
|
||||
|
@ -45,6 +41,8 @@ static struct MeditOpts {
|
|||
gboolean new_window;
|
||||
gboolean new_tab;
|
||||
gboolean reload;
|
||||
const char *project;
|
||||
gboolean project_mode;
|
||||
int line;
|
||||
const char *encoding;
|
||||
const char *log_file;
|
||||
|
@ -68,20 +66,26 @@ static struct MeditOpts {
|
|||
|
||||
#include "parse.h"
|
||||
|
||||
class MeditApp : public App
|
||||
{
|
||||
public:
|
||||
MeditApp(gobj_wrapper_data& d, const StartupOptions& opts)
|
||||
: App(d, opts)
|
||||
{
|
||||
}
|
||||
typedef MooApp MeditApp;
|
||||
typedef MooAppClass MeditAppClass;
|
||||
MOO_DEFINE_TYPE_STATIC (MeditApp, medit_app, MOO_TYPE_APP)
|
||||
|
||||
protected:
|
||||
void init_plugins() override
|
||||
{
|
||||
moo_plugin_init ();
|
||||
}
|
||||
};
|
||||
static void
|
||||
medit_app_init_plugins (G_GNUC_UNUSED MooApp *app)
|
||||
{
|
||||
moo_plugin_init ();
|
||||
}
|
||||
|
||||
static void
|
||||
medit_app_class_init (MooAppClass *klass)
|
||||
{
|
||||
klass->init_plugins = medit_app_init_plugins;
|
||||
}
|
||||
|
||||
static void
|
||||
medit_app_init (G_GNUC_UNUSED MooApp *app)
|
||||
{
|
||||
}
|
||||
|
||||
static gboolean
|
||||
parse_use_session (const char *option_name,
|
||||
|
@ -123,6 +127,10 @@ static GOptionEntry medit_options[] = {
|
|||
/* help message for command line option --new-window */ N_("Open file(s) in a new window"), NULL },
|
||||
{ "new-tab", 't', 0, G_OPTION_ARG_NONE, &medit_opts.new_tab,
|
||||
/* help message for command line option --new-tab */ N_("Open file(s) in a new tab"), NULL },
|
||||
{ "project", 0, G_OPTION_FLAG_HIDDEN, G_OPTION_ARG_FILENAME, (gpointer) &medit_opts.project,
|
||||
"Open project file FILE", "FILE" },
|
||||
{ "project-mode", 0, G_OPTION_FLAG_HIDDEN, G_OPTION_ARG_NONE, &medit_opts.project_mode,
|
||||
"IDE mode", NULL },
|
||||
{ "line", 'l', 0, G_OPTION_ARG_INT, &medit_opts.line,
|
||||
/* help message for command line option --line=LINE */ N_("Open file and position cursor on line LINE"),
|
||||
/* "LINE" part in --line=LINE */ N_("LINE") },
|
||||
|
@ -173,14 +181,14 @@ check_plus_line_arg (void)
|
|||
char **p;
|
||||
GRegex *re = NULL;
|
||||
|
||||
re = g_regex_new ("^\\+(?P<line>\\d+)", G_REGEX_OPTIMIZE | G_REGEX_DUPNAMES, GRegexMatchFlags(0), NULL);
|
||||
re = g_regex_new ("^\\+(?P<line>\\d+)", G_REGEX_OPTIMIZE | G_REGEX_DUPNAMES, 0, NULL);
|
||||
g_return_if_fail (re != NULL);
|
||||
|
||||
for (p = medit_opts.files; !done && p && *p && **p; ++p)
|
||||
{
|
||||
GMatchInfo *match_info = NULL;
|
||||
|
||||
if (g_regex_match (re, *p, GRegexMatchFlags(0), &match_info))
|
||||
if (g_regex_match (re, *p, 0, &match_info))
|
||||
{
|
||||
int line = 0;
|
||||
char *line_string = g_match_info_fetch_named (match_info, "line");
|
||||
|
@ -251,6 +259,9 @@ post_parse_func (void)
|
|||
if (medit_opts.debug)
|
||||
g_setenv ("MOO_DEBUG", medit_opts.debug, FALSE);
|
||||
|
||||
if (medit_opts.project)
|
||||
medit_opts.project_mode = TRUE;
|
||||
|
||||
check_plus_line_arg ();
|
||||
|
||||
return TRUE;
|
||||
|
@ -320,22 +331,53 @@ get_time_stamp (void)
|
|||
#endif
|
||||
}
|
||||
|
||||
#ifdef __WIN32__
|
||||
static void
|
||||
push_appdir_to_path (void)
|
||||
{
|
||||
gstr appdir = moo_win32_get_app_dir ();
|
||||
g_return_if_fail (!appdir.empty());
|
||||
#ifdef __WIN32__
|
||||
char *appdir;
|
||||
const char *path;
|
||||
char *new_path;
|
||||
|
||||
const char *path = g_getenv ("Path");
|
||||
gstr new_path;
|
||||
appdir = moo_win32_get_app_dir ();
|
||||
g_return_if_fail (appdir != NULL);
|
||||
|
||||
path = g_getenv ("Path");
|
||||
|
||||
if (path)
|
||||
new_path.set_printf ("%s;%s", appdir, path);
|
||||
new_path = g_strdup_printf ("%s;%s", appdir, path);
|
||||
else
|
||||
new_path = std::move (appdir);
|
||||
new_path = g_strdup (appdir);
|
||||
|
||||
g_setenv ("Path", new_path, TRUE);
|
||||
|
||||
g_free (new_path);
|
||||
g_free (appdir);
|
||||
#endif
|
||||
}
|
||||
|
||||
#ifdef MOO_ENABLE_PROJECT
|
||||
static void
|
||||
project_mode (const char *file)
|
||||
{
|
||||
MooPlugin *plugin;
|
||||
|
||||
plugin = (MooPlugin*) moo_plugin_lookup ("ProjectManager");
|
||||
|
||||
if (!plugin)
|
||||
{
|
||||
fputs ("Could not initialize project manager plugin\n", stderr);
|
||||
exit (EXIT_FAILURE);
|
||||
}
|
||||
|
||||
if (file)
|
||||
{
|
||||
char *project = moo_filename_from_locale (file);
|
||||
g_object_set (plugin, "project", project, NULL);
|
||||
g_free (project);
|
||||
}
|
||||
|
||||
moo_plugin_set_enabled (plugin, TRUE);
|
||||
}
|
||||
#endif
|
||||
|
||||
|
@ -367,7 +409,7 @@ _moo_get_toplevel_window_at_pointer (void)
|
|||
if (!window)
|
||||
continue;
|
||||
|
||||
hwnd = (HWND) GDK_WINDOW_HWND (window);
|
||||
hwnd = GDK_WINDOW_HWND (window);
|
||||
GetWindowRect(hwnd, &rect);
|
||||
if (IsWindowVisible(hwnd) && PtInRect(&rect, point))
|
||||
windows = g_slist_prepend (windows, l->data);
|
||||
|
@ -384,7 +426,7 @@ _moo_get_toplevel_window_at_pointer (void)
|
|||
static GdkModifierType
|
||||
get_current_mask (void)
|
||||
{
|
||||
GdkModifierType mask = GdkModifierType(0);
|
||||
GdkModifierType mask = 0;
|
||||
BYTE kbd[256];
|
||||
|
||||
GetKeyboardState (kbd);
|
||||
|
@ -418,7 +460,7 @@ get_pointer (GdkWindow *window,
|
|||
GdkWindow *retval = window;
|
||||
GdkWindow *child = NULL;
|
||||
|
||||
hwnd = (HWND) GDK_WINDOW_HWND (window);
|
||||
hwnd = GDK_WINDOW_HWND (window);
|
||||
GetCursorPos (&point);
|
||||
ScreenToClient (hwnd, &point);
|
||||
|
||||
|
@ -427,7 +469,7 @@ get_pointer (GdkWindow *window,
|
|||
|
||||
hwndc = ChildWindowFromPointEx (hwnd, point, CWP_SKIPINVISIBLE);
|
||||
if (hwndc != NULL && hwndc != hwnd)
|
||||
child = reinterpret_cast<GdkWindow*> (gdk_win32_handle_table_lookup ((GdkNativeWindow) hwndc));
|
||||
child = gdk_win32_handle_table_lookup ((GdkNativeWindow) hwndc);
|
||||
if (child != NULL)
|
||||
retval = child;
|
||||
|
||||
|
@ -541,15 +583,15 @@ hookup_synaptics_touchpad (void)
|
|||
static void
|
||||
unit_test_func (void)
|
||||
{
|
||||
MooTestOptions opts = MOO_TEST_OPTIONS_NONE;
|
||||
MooTestOptions opts = 0;
|
||||
int status;
|
||||
|
||||
if (!medit_opts.ut_uninstalled)
|
||||
opts |= MOO_TEST_INSTALLED;
|
||||
|
||||
status = unit_tests_main (opts, medit_opts.ut_tests, medit_opts.ut_dir, medit_opts.ut_coverage_file);
|
||||
App::instance().set_exit_status (status);
|
||||
App::instance().quit ();
|
||||
moo_app_set_exit_status (moo_app_instance (), status);
|
||||
moo_app_quit (moo_app_instance ());
|
||||
}
|
||||
|
||||
static void
|
||||
|
@ -557,7 +599,7 @@ run_script_func (void)
|
|||
{
|
||||
char **p;
|
||||
for (p = medit_opts.run_script; p && *p; ++p)
|
||||
App::instance().run_script (*p);
|
||||
moo_app_run_script (moo_app_instance(), *p);
|
||||
}
|
||||
|
||||
static void
|
||||
|
@ -580,66 +622,79 @@ install_log_handlers (void)
|
|||
static void
|
||||
setup_portable_mode (void)
|
||||
{
|
||||
gstr appdir = moo_win32_get_app_dir ();
|
||||
g_return_if_fail (!appdir.empty());
|
||||
char *appdir = NULL;
|
||||
char *share = NULL;
|
||||
char *datadir = NULL;
|
||||
char *cachedir = NULL;
|
||||
char *tmp = NULL;
|
||||
|
||||
gstr share = g::build_filename (appdir, "..", "share");
|
||||
g_return_if_fail (!share.empty());
|
||||
appdir = moo_win32_get_app_dir ();
|
||||
g_return_if_fail (appdir != NULL);
|
||||
|
||||
gstr datadir;
|
||||
gstr cachedir;
|
||||
share = g_build_filename (appdir, "..", "share", NULL);
|
||||
g_return_if_fail (share != NULL);
|
||||
|
||||
if (g_file_test (share, G_FILE_TEST_IS_DIR))
|
||||
{
|
||||
datadir = g::build_filename (share, MEDIT_PORTABLE_DATA_DIR);
|
||||
cachedir = g::build_filename (share, MEDIT_PORTABLE_CACHE_DIR);
|
||||
datadir = g_build_filename (share, MEDIT_PORTABLE_DATA_DIR, NULL);
|
||||
cachedir = g_build_filename (share, MEDIT_PORTABLE_CACHE_DIR, NULL);
|
||||
}
|
||||
else
|
||||
{
|
||||
datadir = g::build_filename (appdir, MEDIT_PORTABLE_DATA_DIR);
|
||||
cachedir = g::build_filename (appdir, MEDIT_PORTABLE_CACHE_DIR);
|
||||
datadir = g_build_filename (appdir, MEDIT_PORTABLE_DATA_DIR, NULL);
|
||||
cachedir = g_build_filename (appdir, MEDIT_PORTABLE_CACHE_DIR, NULL);
|
||||
}
|
||||
|
||||
g_return_if_fail (!datadir.empty() && !cachedir.empty());
|
||||
|
||||
gstr tmp = _moo_normalize_file_path (datadir);
|
||||
g_return_if_fail (datadir != NULL && cachedir != NULL);
|
||||
|
||||
tmp = _moo_normalize_file_path (datadir);
|
||||
moo_set_user_data_dir (tmp);
|
||||
g_free (tmp);
|
||||
tmp = NULL;
|
||||
|
||||
tmp = _moo_normalize_file_path (cachedir);
|
||||
moo_set_user_cache_dir (tmp);
|
||||
g_free (tmp);
|
||||
tmp = NULL;
|
||||
|
||||
g_free (cachedir);
|
||||
g_free (datadir);
|
||||
g_free (share);
|
||||
g_free (appdir);
|
||||
}
|
||||
|
||||
static void
|
||||
check_portable_mode (void)
|
||||
{
|
||||
bool portable = medit_opts.portable;
|
||||
gboolean portable = FALSE;
|
||||
char *appdir = NULL;
|
||||
char *magic_file = NULL;
|
||||
|
||||
if (medit_opts.portable)
|
||||
portable = TRUE;
|
||||
|
||||
if (!portable)
|
||||
{
|
||||
gstr appdir = moo_win32_get_app_dir ();
|
||||
g_return_if_fail (!appdir.empty());
|
||||
gstr magic_file = g::build_filename (appdir, MEDIT_PORTABLE_MAGIC_FILE_NAME);
|
||||
g_return_if_fail (!magic_file.empty());
|
||||
appdir = moo_win32_get_app_dir ();
|
||||
g_return_if_fail (appdir != NULL);
|
||||
magic_file = g_build_filename (appdir, MEDIT_PORTABLE_MAGIC_FILE_NAME, NULL);
|
||||
g_return_if_fail (magic_file != NULL);
|
||||
if (g_file_test (magic_file, G_FILE_TEST_EXISTS))
|
||||
portable = TRUE;
|
||||
}
|
||||
|
||||
if (portable)
|
||||
setup_portable_mode ();
|
||||
|
||||
g_free (magic_file);
|
||||
g_free (appdir);
|
||||
}
|
||||
#endif // __WIN32__
|
||||
|
||||
namespace moo
|
||||
{
|
||||
namespace _test
|
||||
{
|
||||
void test();
|
||||
}
|
||||
}
|
||||
|
||||
static int
|
||||
medit_main (int argc, char *argv[])
|
||||
{
|
||||
MooApp *app = NULL;
|
||||
MooEditor *editor;
|
||||
int retval;
|
||||
gboolean new_instance = FALSE;
|
||||
|
@ -650,12 +705,10 @@ medit_main (int argc, char *argv[])
|
|||
GOptionContext *ctx;
|
||||
MooOpenInfoArray *files;
|
||||
|
||||
#ifdef __WIN32__
|
||||
CoInitializeEx(NULL, COINIT_APARTMENTTHREADED | COINIT_DISABLE_OLE1DDE);
|
||||
#endif // __WIN32__
|
||||
|
||||
init_mem_stuff ();
|
||||
moo_thread_init ();
|
||||
#if !GLIB_CHECK_VERSION(2,32,0)
|
||||
g_thread_init (NULL);
|
||||
#endif
|
||||
g_set_prgname ("medit");
|
||||
|
||||
ctx = parse_args (argc, argv);
|
||||
|
@ -678,11 +731,11 @@ medit_main (int argc, char *argv[])
|
|||
check_portable_mode ();
|
||||
#endif
|
||||
|
||||
if (medit_opts.new_app)
|
||||
if (medit_opts.new_app || medit_opts.project_mode)
|
||||
new_instance = TRUE;
|
||||
|
||||
run_input = !medit_opts.new_app || medit_opts.instance_name ||
|
||||
medit_opts.use_session == 1;
|
||||
medit_opts.use_session == 1 || medit_opts.project_mode;
|
||||
|
||||
if (medit_opts.ut)
|
||||
{
|
||||
|
@ -711,7 +764,7 @@ medit_main (int argc, char *argv[])
|
|||
{
|
||||
GString *msg = g_string_new ("e");
|
||||
g_string_append (msg, *p);
|
||||
App::send_msg (name, msg->str, msg->len + 1);
|
||||
moo_app_send_msg (name, msg->str, msg->len + 1);
|
||||
}
|
||||
notify_startup_complete ();
|
||||
exit (0);
|
||||
|
@ -721,7 +774,7 @@ medit_main (int argc, char *argv[])
|
|||
|
||||
if (name)
|
||||
{
|
||||
if (App::send_files (files, stamp, name))
|
||||
if (moo_app_send_files (files, stamp, name))
|
||||
exit (0);
|
||||
|
||||
if (!medit_opts.instance_name)
|
||||
|
@ -732,59 +785,67 @@ medit_main (int argc, char *argv[])
|
|||
}
|
||||
|
||||
if (!new_instance && !medit_opts.instance_name &&
|
||||
App::send_files (files, stamp, NULL))
|
||||
moo_app_send_files (files, stamp, NULL))
|
||||
{
|
||||
notify_startup_complete ();
|
||||
exit (0);
|
||||
}
|
||||
|
||||
#ifdef __WIN32__
|
||||
push_appdir_to_path ();
|
||||
#endif
|
||||
|
||||
gtk_init (NULL, NULL);
|
||||
gdk_threads_init ();
|
||||
gdk_threads_enter ();
|
||||
|
||||
install_log_handlers ();
|
||||
|
||||
MeditApp::StartupOptions sopts;
|
||||
sopts.run_input = run_input;
|
||||
sopts.use_session = medit_opts.use_session;
|
||||
sopts.instance_name.set(medit_opts.instance_name);
|
||||
gref_ptr<MeditApp> app = MeditApp::create<MeditApp>(sopts);
|
||||
app = MOO_APP (g_object_new (medit_app_get_type (),
|
||||
"run-input", run_input,
|
||||
"use-session", medit_opts.use_session,
|
||||
"instance-name", medit_opts.instance_name,
|
||||
(const char*) NULL));
|
||||
|
||||
if (!app->init())
|
||||
if (!moo_app_init (app))
|
||||
{
|
||||
gdk_notify_startup_complete ();
|
||||
return EXIT_FAILURE;
|
||||
g_object_unref (app);
|
||||
exit (EXIT_FAILURE);
|
||||
}
|
||||
|
||||
//moo::_test::test ();
|
||||
|
||||
if (medit_opts.geometry && *medit_opts.geometry)
|
||||
moo_window_set_default_geometry (medit_opts.geometry);
|
||||
|
||||
app->load_session ();
|
||||
if (medit_opts.project_mode)
|
||||
#ifdef MOO_ENABLE_PROJECT
|
||||
project_mode (medit_opts.project);
|
||||
#else
|
||||
{
|
||||
fputs ("medit was built without project support\n", stderr);
|
||||
exit (EXIT_FAILURE);
|
||||
}
|
||||
#endif
|
||||
else
|
||||
moo_app_load_session (app);
|
||||
|
||||
editor = app->get_editor ();
|
||||
editor = moo_app_get_editor (app);
|
||||
if (!moo_editor_get_active_window (editor))
|
||||
moo_editor_new_window (editor);
|
||||
|
||||
if (files)
|
||||
app->open_files (files, stamp);
|
||||
moo_app_open_files (app, files, stamp);
|
||||
|
||||
moo_open_info_array_free (files);
|
||||
g_option_context_free (ctx);
|
||||
|
||||
if (medit_opts.ut)
|
||||
app->connect ("started", G_CALLBACK (unit_test_func), NULL);
|
||||
g_signal_connect (app, "started", G_CALLBACK (unit_test_func), NULL);
|
||||
if (medit_opts.run_script)
|
||||
app->connect ("started", G_CALLBACK (run_script_func), NULL);
|
||||
g_signal_connect (app, "started", G_CALLBACK (run_script_func), NULL);
|
||||
|
||||
retval = app->run ();
|
||||
retval = moo_app_run (app);
|
||||
gdk_threads_leave ();
|
||||
|
||||
#ifdef __WIN32__
|
||||
CoUninitialize();
|
||||
#endif // __WIN32__
|
||||
g_object_unref (app);
|
||||
|
||||
return retval;
|
||||
}
|
|
@ -1,16 +1,16 @@
|
|||
set(medit_app_sources
|
||||
medit-app/medit-app.cmake
|
||||
medit-app/mem-debug.h
|
||||
medit-app/run-tests.h
|
||||
medit-app/parse.h
|
||||
medit-app/main.cpp
|
||||
)
|
||||
|
||||
set(built_medit_app_sources)
|
||||
|
||||
if(MOO_OS_WIN32)
|
||||
set(top_srcdir ${CMAKE_SOURCE_DIR})
|
||||
configure_file(${CMAKE_CURRENT_SOURCE_DIR}/medit-app/medit.rc.in ${CMAKE_CURRENT_BINARY_DIR}/medit-app/medit.rc)
|
||||
list(APPEND built_medit_app_sources ${CMAKE_CURRENT_BINARY_DIR}/medit-app/medit.rc)
|
||||
list(APPEND medit_app_sources ${CMAKE_CURRENT_SOURCE_DIR}/medit-app/medit.rc.in)
|
||||
endif()
|
||||
set(medit_app_sources
|
||||
medit-app/medit-app.cmake
|
||||
medit-app/mem-debug.h
|
||||
medit-app/run-tests.h
|
||||
medit-app/parse.h
|
||||
medit-app/main.c
|
||||
)
|
||||
|
||||
set(built_medit_app_sources)
|
||||
|
||||
if(MOO_OS_WIN32)
|
||||
set(top_srcdir ${CMAKE_SOURCE_DIR})
|
||||
configure_file(${CMAKE_CURRENT_SOURCE_DIR}/medit-app/medit.rc.in ${CMAKE_CURRENT_BINARY_DIR}/medit-app/medit.rc)
|
||||
list(APPEND built_medit_app_sources ${CMAKE_CURRENT_BINARY_DIR}/medit-app/medit.rc)
|
||||
list(APPEND medit_app_sources ${CMAKE_CURRENT_SOURCE_DIR}/medit-app/medit.rc.in)
|
||||
endif()
|
||||
|
|
|
@ -1,6 +1,5 @@
|
|||
#include <errno.h>
|
||||
#include <mooedit/mooeditfileinfo.h>
|
||||
#include "moocpp/moocpp.h"
|
||||
|
||||
static MooOpenInfo *
|
||||
parse_filename (const char *filename)
|
||||
|
@ -29,7 +28,7 @@ parse_filename (const char *filename)
|
|||
{
|
||||
GError *error = NULL;
|
||||
GRegex *re = g_regex_new ("((?P<path>.*):(?P<line>\\d+)?|(?P<path>.*)\\((?P<line>\\d+)\\))$",
|
||||
G_REGEX_OPTIMIZE | G_REGEX_DUPNAMES, GRegexMatchFlags(0), &error);
|
||||
G_REGEX_OPTIMIZE | G_REGEX_DUPNAMES, 0, &error);
|
||||
if (!re)
|
||||
{
|
||||
g_critical ("could not compile regex: %s", error->message);
|
||||
|
@ -39,7 +38,7 @@ parse_filename (const char *filename)
|
|||
{
|
||||
GMatchInfo *match_info = NULL;
|
||||
|
||||
if (g_regex_match (re, filename, GRegexMatchFlags(0), &match_info))
|
||||
if (g_regex_match (re, filename, 0, &match_info))
|
||||
{
|
||||
char *path = g_match_info_fetch_named (match_info, "path");
|
||||
char *line_string = g_match_info_fetch_named (match_info, "line");
|
||||
|
@ -73,7 +72,7 @@ parse_filename (const char *filename)
|
|||
return NULL;
|
||||
}
|
||||
|
||||
info = moo_open_info_new_uri (uri, NULL, line - 1, MOO_OPEN_FLAGS_NONE);
|
||||
info = moo_open_info_new_uri (uri, NULL, line - 1, 0);
|
||||
|
||||
g_free (uri);
|
||||
g_free (freeme1);
|
||||
|
@ -124,7 +123,7 @@ parse_uri (const char *scheme,
|
|||
char *real_uri;
|
||||
|
||||
if (strcmp (scheme, "file") != 0)
|
||||
return moo_open_info_new_uri (uri, NULL, -1, MOO_OPEN_FLAGS_NONE);
|
||||
return moo_open_info_new_uri (uri, NULL, -1, 0);
|
||||
|
||||
question_mark = strchr (uri, '?');
|
||||
|
||||
|
@ -138,7 +137,7 @@ parse_uri (const char *scheme,
|
|||
real_uri = g_strdup (uri);
|
||||
}
|
||||
|
||||
info = moo_open_info_new_uri (real_uri, NULL, -1, MOO_OPEN_FLAGS_NONE);
|
||||
info = moo_open_info_new_uri (real_uri, NULL, -1, 0);
|
||||
|
||||
if (optstring)
|
||||
parse_options_from_uri (optstring, info);
|
||||
|
|
|
@ -1,9 +1,5 @@
|
|||
#pragma once
|
||||
|
||||
#if (defined(DEBUG) && ((!DEBUG) || !(MOO_DEBUG) || !(ENABLE_DEBUG))) || \
|
||||
(!defined(DEBUG) && (defined(MOO_DEBUG) || defined(ENABLE_DEBUG)))
|
||||
# error "DEBUG, MOO_DEBUG, and ENABLE_DEBUG must either be all defined to non-zero or all undefined"
|
||||
#endif
|
||||
#ifndef MOO_CONFIG_H
|
||||
#define MOO_CONFIG_H
|
||||
|
||||
#undef MOO_CL_GCC
|
||||
#undef MOO_CL_MINGW
|
||||
|
@ -63,3 +59,5 @@
|
|||
# define MOO_CDECL __cdecl
|
||||
# define MOO_STDCALL __stdcall
|
||||
#endif
|
||||
|
||||
#endif /* MOO_CONFIG_H */
|
||||
|
|
|
@ -1 +0,0 @@
|
|||
#include "moo-pch.h"
|
|
@ -1 +0,0 @@
|
|||
#include "moo-pch.h"
|
|
@ -1,28 +0,0 @@
|
|||
#pragma once
|
||||
|
||||
#ifdef __cplusplus
|
||||
|
||||
#include <algorithm>
|
||||
#include <memory>
|
||||
#include <string>
|
||||
#include <utility>
|
||||
#include <vector>
|
||||
#include <functional>
|
||||
#include <unordered_set>
|
||||
#include <unordered_map>
|
||||
#include <set>
|
||||
#include <map>
|
||||
|
||||
#endif // __cplusplus
|
||||
|
||||
#ifdef __WIN32__
|
||||
|
||||
#include <windows.h>
|
||||
#include <windowsx.h>
|
||||
#include <commctrl.h>
|
||||
|
||||
#endif // __WIN32__
|
||||
|
||||
#ifdef MOO_ENABLE_PYTHON
|
||||
#include <Python.h>
|
||||
#endif
|
|
@ -1,15 +1,15 @@
|
|||
moo_sources += \
|
||||
mooapp/mooappabout.cpp \
|
||||
mooapp/mooappabout.c \
|
||||
mooapp/mooappabout.h \
|
||||
mooapp/mooapp.cpp \
|
||||
mooapp/mooapp.c \
|
||||
mooapp/mooapp.h \
|
||||
mooapp/mooapp-accels.h \
|
||||
mooapp/mooapp-info.h \
|
||||
mooapp/mooapp-private.h \
|
||||
mooapp/moohtml.h \
|
||||
mooapp/moohtml.cpp \
|
||||
mooapp/moohtml.c \
|
||||
mooapp/moolinklabel.h \
|
||||
mooapp/moolinklabel.cpp
|
||||
mooapp/moolinklabel.c
|
||||
|
||||
EXTRA_DIST += \
|
||||
mooapp/glade/mooappabout-dialog.glade \
|
||||
|
|
File diff suppressed because it is too large
Load Diff
|
@ -1,16 +1,16 @@
|
|||
SET(mooapp_sources
|
||||
mooapp/mooapp.cmake
|
||||
mooapp/mooappabout.cpp
|
||||
mooapp/mooappabout.c
|
||||
mooapp/mooappabout.h
|
||||
mooapp/mooapp.cpp
|
||||
mooapp/mooapp.c
|
||||
mooapp/mooapp.h
|
||||
mooapp/mooapp-accels.h
|
||||
mooapp/mooapp-info.h
|
||||
mooapp/mooapp-private.h
|
||||
mooapp/moohtml.h
|
||||
mooapp/moohtml.cpp
|
||||
mooapp/moohtml.c
|
||||
mooapp/moolinklabel.h
|
||||
mooapp/moolinklabel.cpp
|
||||
mooapp/moolinklabel.c
|
||||
)
|
||||
|
||||
foreach(input_file
|
||||
|
|
File diff suppressed because it is too large
Load Diff
|
@ -1,7 +1,7 @@
|
|||
/*
|
||||
* mooapp/mooapp.h
|
||||
*
|
||||
* Copyright (C) 2004-2016 by Yevgen Muntyan <emuntyan@users.sourceforge.net>
|
||||
* Copyright (C) 2004-2010 by Yevgen Muntyan <emuntyan@users.sourceforge.net>
|
||||
*
|
||||
* This file is part of medit. medit is free software; you can
|
||||
* redistribute it and/or modify it under the terms of the
|
||||
|
@ -13,7 +13,8 @@
|
|||
* License along with medit. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#pragma once
|
||||
#ifndef MOO_APP_H
|
||||
#define MOO_APP_H
|
||||
|
||||
#include <mooedit/mooeditor.h>
|
||||
|
||||
|
@ -28,15 +29,17 @@ G_BEGIN_DECLS
|
|||
#define MOO_APP_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), MOO_TYPE_APP, MooAppClass))
|
||||
|
||||
|
||||
typedef struct MooApp MooApp;
|
||||
typedef struct MooAppClass MooAppClass;
|
||||
typedef struct _MooApp MooApp;
|
||||
typedef struct _MooAppPrivate MooAppPrivate;
|
||||
typedef struct _MooAppClass MooAppClass;
|
||||
|
||||
struct MooApp
|
||||
struct _MooApp
|
||||
{
|
||||
GObject object;
|
||||
GObject parent;
|
||||
MooAppPrivate *priv;
|
||||
};
|
||||
|
||||
struct MooAppClass
|
||||
struct _MooAppClass
|
||||
{
|
||||
GObjectClass parent_class;
|
||||
|
||||
|
@ -57,62 +60,41 @@ struct MooAppClass
|
|||
GType moo_app_get_type (void) G_GNUC_CONST;
|
||||
|
||||
MooApp *moo_app_instance (void);
|
||||
|
||||
gboolean moo_app_init (MooApp *app);
|
||||
int moo_app_run (MooApp *app);
|
||||
gboolean moo_app_quit (MooApp *app);
|
||||
|
||||
void moo_app_set_exit_status (MooApp *app,
|
||||
int value);
|
||||
|
||||
void moo_app_load_session (MooApp *app);
|
||||
|
||||
MooEditor *moo_app_get_editor (MooApp *app);
|
||||
|
||||
void moo_app_prefs_dialog (GtkWidget *parent);
|
||||
void moo_app_about_dialog (GtkWidget *parent);
|
||||
|
||||
char *moo_app_get_system_info (MooApp *app);
|
||||
|
||||
MooUiXml *moo_app_get_ui_xml (MooApp *app);
|
||||
void moo_app_set_ui_xml (MooApp *app,
|
||||
MooUiXml *xml);
|
||||
|
||||
gboolean moo_app_send_msg (const char *pid,
|
||||
const char *data,
|
||||
gssize len);
|
||||
|
||||
gboolean moo_app_send_files (MooOpenInfoArray *files,
|
||||
guint32 stamp,
|
||||
const char *pid);
|
||||
void moo_app_open_files (MooApp *app,
|
||||
MooOpenInfoArray *files,
|
||||
guint32 stamp);
|
||||
void moo_app_run_script (MooApp *app,
|
||||
const char *script);
|
||||
|
||||
|
||||
G_END_DECLS
|
||||
|
||||
#ifdef __cplusplus
|
||||
|
||||
#include <moogpp/moogpp.h>
|
||||
|
||||
namespace moo {
|
||||
MOO_DEFINE_SIMPLE_GOBJ_CLASS(App, g::Object, MooApp, MOO_TYPE_APP);
|
||||
}
|
||||
|
||||
struct MeditApp : public moo::App
|
||||
{
|
||||
MOO_CUSTOM_GOBJ_CLASS_DECL(MeditApp, moo::App)
|
||||
|
||||
public:
|
||||
struct StartupOptions
|
||||
{
|
||||
bool run_input = false;
|
||||
int use_session = -1;
|
||||
g::gstr instance_name;
|
||||
};
|
||||
|
||||
MeditApp(const StartupOptions& opts);
|
||||
~MeditApp();
|
||||
|
||||
static MeditApp& instance();
|
||||
|
||||
bool init();
|
||||
int run();
|
||||
|
||||
bool quit();
|
||||
void set_exit_status(int value);
|
||||
|
||||
void load_session();
|
||||
|
||||
MooEditor* get_editor();
|
||||
|
||||
static g::gstr get_system_info();
|
||||
static void about_dialog(GtkWidget* parent);
|
||||
|
||||
static bool send_msg(const char* pid, const char* data, gssize len);
|
||||
static bool send_files(MooOpenInfoArray* files, guint32 stamp, const char* pid);
|
||||
|
||||
void open_files(MooOpenInfoArray* files, guint32 stamp);
|
||||
void run_script(const char* script);
|
||||
|
||||
protected:
|
||||
virtual void init_plugins() {}
|
||||
|
||||
private:
|
||||
struct Private;
|
||||
Private* p;
|
||||
};
|
||||
|
||||
#endif // __cplusplus
|
||||
#endif /* MOO_APP_H */
|
||||
|
|
|
@ -36,10 +36,8 @@
|
|||
#include <string.h>
|
||||
#include <libxml/xmlversion.h>
|
||||
|
||||
using namespace moo;
|
||||
|
||||
static GtkDialog* about_dialog;
|
||||
static GtkDialog* credits_dialog;
|
||||
static gpointer about_dialog;
|
||||
static gpointer credits_dialog;
|
||||
|
||||
#undef MOO_USE_HTML
|
||||
#define MOO_USE_HTML 1
|
||||
|
@ -92,7 +90,7 @@ show_credits (void)
|
|||
if (credits_dialog)
|
||||
{
|
||||
if (about_dialog)
|
||||
moo_window_set_parent (GTK_WIDGET (credits_dialog), GTK_WIDGET (about_dialog));
|
||||
moo_window_set_parent (credits_dialog, about_dialog);
|
||||
gtk_window_present (GTK_WINDOW (credits_dialog));
|
||||
return;
|
||||
}
|
||||
|
@ -108,7 +106,7 @@ show_credits (void)
|
|||
|
||||
credits_dialog = gxml->CreditsDialog;
|
||||
g_return_if_fail (credits_dialog != NULL);
|
||||
g_object_add_weak_pointer (G_OBJECT (credits_dialog), (void**)&credits_dialog);
|
||||
g_object_add_weak_pointer (G_OBJECT (credits_dialog), &credits_dialog);
|
||||
g_signal_connect (credits_dialog, "response", G_CALLBACK (gtk_widget_destroy), NULL);
|
||||
|
||||
#ifdef MOO_USE_HTML
|
||||
|
@ -128,7 +126,7 @@ show_credits (void)
|
|||
gtk_text_buffer_insert_at_cursor (buffer, MOO_APP_CREDITS, -1);
|
||||
|
||||
if (about_dialog)
|
||||
moo_window_set_parent (GTK_WIDGET (credits_dialog), GTK_WIDGET (about_dialog));
|
||||
moo_window_set_parent (credits_dialog, about_dialog);
|
||||
gtk_window_present (GTK_WINDOW (credits_dialog));
|
||||
}
|
||||
|
||||
|
@ -154,30 +152,31 @@ about_dialog_key_press (GtkWidget *dialog,
|
|||
|
||||
if (event->keyval == GDK_s && (event->state & GDK_CONTROL_MASK))
|
||||
{
|
||||
g::gstr info = App::get_system_info ();
|
||||
if (!info.empty())
|
||||
char *info = moo_app_get_system_info (moo_app_instance ());
|
||||
if (info)
|
||||
gtk_clipboard_set_text (gtk_widget_get_clipboard (dialog, GDK_SELECTION_CLIPBOARD), info, -1);
|
||||
g_free (info);
|
||||
}
|
||||
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
|
||||
static GtkDialog*
|
||||
static GtkWidget *
|
||||
create_about_dialog (void)
|
||||
{
|
||||
AboutDialogXml *gxml;
|
||||
GtkDialog *dialog;
|
||||
GtkWidget *dialog;
|
||||
char *markup;
|
||||
GtkStockItem dummy;
|
||||
|
||||
moo_glade_xml_register_type (MOO_TYPE_LINK_LABEL);
|
||||
gxml = about_dialog_xml_new ();
|
||||
|
||||
dialog = gxml->AboutDialog;
|
||||
dialog = GTK_WIDGET (gxml->AboutDialog);
|
||||
g_signal_connect (dialog, "key-press-event", G_CALLBACK (about_dialog_key_press), NULL);
|
||||
|
||||
g_object_add_weak_pointer (G_OBJECT (dialog), (void**)&about_dialog);
|
||||
g_object_add_weak_pointer (G_OBJECT (dialog), &about_dialog);
|
||||
g_signal_connect (dialog, "delete-event", G_CALLBACK (gtk_widget_hide_on_delete), NULL);
|
||||
|
||||
markup = g_markup_printf_escaped ("<span size=\"xx-large\"><b>%s %s</b></span>",
|
||||
|
@ -209,57 +208,67 @@ create_about_dialog (void)
|
|||
}
|
||||
|
||||
|
||||
void App::about_dialog (GtkWidget *parent)
|
||||
void
|
||||
moo_app_about_dialog (GtkWidget *parent)
|
||||
{
|
||||
if (!::about_dialog)
|
||||
::about_dialog = create_about_dialog ();
|
||||
if (!about_dialog)
|
||||
about_dialog = create_about_dialog ();
|
||||
|
||||
if (parent)
|
||||
parent = gtk_widget_get_toplevel (parent);
|
||||
|
||||
if (parent && GTK_IS_WINDOW (parent))
|
||||
moo_window_set_parent (GTK_WIDGET (::about_dialog), parent);
|
||||
moo_window_set_parent (about_dialog, parent);
|
||||
|
||||
gtk_window_present (GTK_WINDOW (::about_dialog));
|
||||
gtk_window_present (GTK_WINDOW (about_dialog));
|
||||
}
|
||||
|
||||
|
||||
gstr App::get_system_info ()
|
||||
char *
|
||||
moo_app_get_system_info (MooApp *app)
|
||||
{
|
||||
GString *text;
|
||||
char **dirs, **p;
|
||||
char *string;
|
||||
|
||||
strbuilder text;
|
||||
g_return_val_if_fail (MOO_IS_APP (app), NULL);
|
||||
|
||||
text.append_printf ("%s-%s\n", MOO_APP_FULL_NAME, MOO_DISPLAY_VERSION);
|
||||
text.append_printf ("OS: %s\n", get_system_name ());
|
||||
text.append_printf ("GTK version: %u.%u.%u\n",
|
||||
gtk_major_version,
|
||||
gtk_minor_version,
|
||||
gtk_micro_version);
|
||||
text.append_printf ("Built with GTK %d.%d.%d\n",
|
||||
GTK_MAJOR_VERSION,
|
||||
GTK_MINOR_VERSION,
|
||||
GTK_MICRO_VERSION);
|
||||
text = g_string_new (NULL);
|
||||
|
||||
text.append_printf ("libxml2: %s\n", LIBXML_DOTTED_VERSION);
|
||||
g_string_append_printf (text, "%s-%s\n", MOO_APP_FULL_NAME, MOO_DISPLAY_VERSION);
|
||||
|
||||
text.append ("Data dirs: ");
|
||||
string = get_system_name ();
|
||||
g_string_append_printf (text, "OS: %s\n", string);
|
||||
g_free (string);
|
||||
|
||||
g_string_append_printf (text, "GTK version: %u.%u.%u\n",
|
||||
gtk_major_version,
|
||||
gtk_minor_version,
|
||||
gtk_micro_version);
|
||||
g_string_append_printf (text, "Built with GTK %d.%d.%d\n",
|
||||
GTK_MAJOR_VERSION,
|
||||
GTK_MINOR_VERSION,
|
||||
GTK_MICRO_VERSION);
|
||||
|
||||
g_string_append_printf (text, "libxml2: %s\n", LIBXML_DOTTED_VERSION);
|
||||
|
||||
g_string_append (text, "Data dirs: ");
|
||||
dirs = moo_get_data_dirs ();
|
||||
for (p = dirs; p && *p; ++p)
|
||||
text.append_printf ("%s'%s'", p == dirs ? "" : ", ", *p);
|
||||
text.append ("\n");
|
||||
g_string_append_printf (text, "%s'%s'", p == dirs ? "" : ", ", *p);
|
||||
g_string_append (text, "\n");
|
||||
g_strfreev (dirs);
|
||||
|
||||
text.append ("Lib dirs: ");
|
||||
g_string_append (text, "Lib dirs: ");
|
||||
dirs = moo_get_lib_dirs ();
|
||||
for (p = dirs; p && *p; ++p)
|
||||
text.append_printf ("%s'%s'", p == dirs ? "" : ", ", *p);
|
||||
text.append ("\n");
|
||||
g_string_append_printf (text, "%s'%s'", p == dirs ? "" : ", ", *p);
|
||||
g_string_append (text, "\n");
|
||||
g_strfreev (dirs);
|
||||
|
||||
#ifdef MOO_BROKEN_GTK_THEME
|
||||
text.append ("Broken gtk theme: yes\n");
|
||||
g_string_append (text, "Broken gtk theme: yes\n");
|
||||
#endif
|
||||
|
||||
return text.release();
|
||||
return g_string_free (text, FALSE);
|
||||
}
|
|
@ -25,20 +25,16 @@
|
|||
#endif
|
||||
|
||||
#ifdef __WIN32__
|
||||
#include <VersionHelpers.h>
|
||||
#include <windows.h>
|
||||
#endif
|
||||
|
||||
#include <moocpp/moocpp.h>
|
||||
#include <mooglib/moo-glib.h>
|
||||
#include <errno.h>
|
||||
#include <gtk/gtk.h>
|
||||
|
||||
using namespace moo;
|
||||
|
||||
#ifdef __WIN32__
|
||||
|
||||
static gstr
|
||||
static char *
|
||||
get_system_name (void)
|
||||
{
|
||||
OSVERSIONINFOEXW ver;
|
||||
|
@ -47,36 +43,55 @@ get_system_name (void)
|
|||
ver.dwOSVersionInfoSize = sizeof (OSVERSIONINFOW);
|
||||
|
||||
if (!GetVersionExW ((OSVERSIONINFOW*) &ver))
|
||||
return gstr::wrap_const ("Windows");
|
||||
return g_strdup ("Windows");
|
||||
|
||||
switch (ver.dwMajorVersion)
|
||||
{
|
||||
case 4: /* Windows NT 4.0, Windows Me, Windows 98, or Windows 95 */
|
||||
switch (ver.dwMinorVersion)
|
||||
{
|
||||
case 0: /* Windows NT 4.0 or Windows95 */
|
||||
if (ver.dwPlatformId == VER_PLATFORM_WIN32_WINDOWS)
|
||||
return g_strdup ("Windows 95");
|
||||
else
|
||||
return g_strdup ("Windows NT 4.0");
|
||||
|
||||
case 10:
|
||||
return g_strdup ("Windows 98");
|
||||
|
||||
case 90:
|
||||
return g_strdup ("Windows 98");
|
||||
}
|
||||
|
||||
break;
|
||||
|
||||
case 5: /* Windows Server 2003 R2, Windows Server 2003, Windows XP, or Windows 2000 */
|
||||
switch (ver.dwMinorVersion)
|
||||
{
|
||||
case 0:
|
||||
return gstr::wrap_const ("Windows 2000");
|
||||
return g_strdup ("Windows 2000");
|
||||
case 1:
|
||||
return gstr::wrap_const ("Windows XP");
|
||||
return g_strdup ("Windows XP");
|
||||
case 2:
|
||||
return gstr::wrap_const ("Windows Server 2003");
|
||||
return g_strdup ("Windows Server 2003");
|
||||
}
|
||||
|
||||
break;
|
||||
|
||||
case 6:
|
||||
if (!IsWindowsServer())
|
||||
memset (&ver, 0, sizeof (ver));
|
||||
ver.dwOSVersionInfoSize = sizeof (OSVERSIONINFOEXW);
|
||||
|
||||
if (!GetVersionExW ((OSVERSIONINFOW*) &ver) || ver.wProductType == VER_NT_WORKSTATION)
|
||||
{
|
||||
switch (ver.dwMinorVersion)
|
||||
{
|
||||
case 0:
|
||||
return gstr::wrap_const ("Windows Vista");
|
||||
return g_strdup ("Windows Vista");
|
||||
case 1:
|
||||
return gstr::wrap_const ("Windows 7");
|
||||
return g_strdup ("Windows 7");
|
||||
case 2:
|
||||
return gstr::wrap_const ("Windows 8");
|
||||
case 3:
|
||||
return gstr::wrap_const("Windows 8.1");
|
||||
return g_strdup ("Windows 8");
|
||||
}
|
||||
}
|
||||
else
|
||||
|
@ -84,45 +99,23 @@ get_system_name (void)
|
|||
switch (ver.dwMinorVersion)
|
||||
{
|
||||
case 0:
|
||||
return gstr::wrap_const ("Windows Server 2008");
|
||||
return g_strdup ("Windows Server 2008");
|
||||
case 1:
|
||||
return gstr::wrap_const ("Windows Server 2008 R2");
|
||||
return g_strdup ("Windows Server 2008 R2");
|
||||
case 2:
|
||||
return gstr::wrap_const("Windows Server 2012");
|
||||
case 3:
|
||||
return gstr::wrap_const("Windows Server 2012 R2");
|
||||
}
|
||||
}
|
||||
|
||||
break;
|
||||
|
||||
case 10:
|
||||
if (!IsWindowsServer())
|
||||
{
|
||||
switch (ver.dwMinorVersion)
|
||||
{
|
||||
case 0:
|
||||
return gstr::wrap_const("Windows 10");
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
switch (ver.dwMinorVersion)
|
||||
{
|
||||
case 0:
|
||||
return gstr::wrap_const("Windows Server 2016");
|
||||
return g_strdup ("Windows Server 2012");
|
||||
}
|
||||
}
|
||||
|
||||
break;
|
||||
}
|
||||
|
||||
return IsWindowsServer() ? gstr::wrap_const("Windows Server") : gstr::wrap_const("Windows");
|
||||
return g_strdup ("Windows");
|
||||
}
|
||||
|
||||
#elif defined(HAVE_SYS_UTSNAME_H)
|
||||
|
||||
static gstr
|
||||
static char *
|
||||
get_system_name (void)
|
||||
{
|
||||
struct utsname name;
|
||||
|
@ -130,13 +123,13 @@ get_system_name (void)
|
|||
if (uname (&name) != 0)
|
||||
{
|
||||
MGW_ERROR_IF_NOT_SHARED_LIBC
|
||||
mgw_errno_t err = { mgw_errno_value_t (errno) };
|
||||
mgw_errno_t err = { errno };
|
||||
g_critical ("%s", mgw_strerror (err));
|
||||
return gstr::wrap_const ("unknown");
|
||||
return g_strdup ("unknown");
|
||||
}
|
||||
|
||||
return gstr::printf ("%s %s (%s), %s", name.sysname,
|
||||
name.release, name.version, name.machine);
|
||||
return g_strdup_printf ("%s %s (%s), %s", name.sysname,
|
||||
name.release, name.version, name.machine);
|
||||
}
|
||||
|
||||
#else
|
||||
|
|
|
@ -18,7 +18,6 @@
|
|||
#include "marshals.h"
|
||||
#include "mooutils/mooutils-misc.h"
|
||||
#include "mooutils/moocompat.h"
|
||||
#include "moocpp/moocpp.h"
|
||||
#include <gdk/gdkkeysyms.h>
|
||||
#include <gtk/gtk.h>
|
||||
#include <mooglib/moo-glib.h>
|
||||
|
@ -27,8 +26,6 @@
|
|||
|
||||
#include <libxml/HTMLtree.h>
|
||||
|
||||
#include <moocpp/moocpp.h>
|
||||
|
||||
#define DEFAULT_PAR_SPACING 6
|
||||
|
||||
|
||||
|
@ -63,8 +60,6 @@ struct _MooHtmlData {
|
|||
};
|
||||
|
||||
typedef enum {
|
||||
MOO_HTML_ATTR_MASK_NONE = 0,
|
||||
|
||||
MOO_HTML_FG = 1 << 0,
|
||||
MOO_HTML_BG = 1 << 1,
|
||||
MOO_HTML_BOLD = 1 << 2,
|
||||
|
@ -87,8 +82,6 @@ typedef enum {
|
|||
MOO_HTML_FONT_FACE = 1 << 17
|
||||
} MooHtmlAttrMask;
|
||||
|
||||
MOO_DEFINE_FLAGS(MooHtmlAttrMask);
|
||||
|
||||
struct _MooHtmlAttr
|
||||
{
|
||||
MooHtmlAttrMask mask;
|
||||
|
@ -416,15 +409,15 @@ moo_html_get_data (gpointer object)
|
|||
{
|
||||
MooHtmlData *data;
|
||||
|
||||
data = reinterpret_cast<MooHtmlData*>(g_object_get_data(G_OBJECT(object), "moo-html-data"));
|
||||
data = g_object_get_data (object, "moo-html-data");
|
||||
|
||||
if (!data)
|
||||
{
|
||||
init_funcs();
|
||||
data = moo_html_data_new();
|
||||
g_object_set_data_full(G_OBJECT(object), "moo-html-data", data,
|
||||
(GDestroyNotify) moo_html_data_free);
|
||||
g_signal_connect(object, "size-allocate", G_CALLBACK(moo_html_size_allocate_cb), NULL);
|
||||
init_funcs ();
|
||||
data = moo_html_data_new ();
|
||||
g_object_set_data_full (object, "moo-html-data", data,
|
||||
(GDestroyNotify) moo_html_data_free);
|
||||
g_signal_connect (object, "size-allocate", G_CALLBACK (moo_html_size_allocate_cb), NULL);
|
||||
}
|
||||
|
||||
return data;
|
||||
|
@ -978,9 +971,9 @@ moo_html_create_tag (GtkTextView *view,
|
|||
{
|
||||
MooHtmlTag *tag;
|
||||
MooHtmlAttr real_attr;
|
||||
MooHtmlData *data = moo_html_get_data(view);
|
||||
MooHtmlData *data = moo_html_get_data (view);
|
||||
|
||||
g_return_val_if_fail(attr != NULL, NULL);
|
||||
g_return_val_if_fail (attr != NULL, NULL);
|
||||
|
||||
if (!attr->mask && !force)
|
||||
return parent;
|
||||
|
@ -988,22 +981,22 @@ moo_html_create_tag (GtkTextView *view,
|
|||
if (parent && parent->attr)
|
||||
{
|
||||
real_attr = *parent->attr;
|
||||
attr_compose(&real_attr, attr);
|
||||
attr_compose (&real_attr, attr);
|
||||
}
|
||||
else
|
||||
{
|
||||
real_attr = *attr;
|
||||
}
|
||||
|
||||
tag = MOO_HTML_TAG(g_object_new(MOO_TYPE_HTML_TAG, nullptr));
|
||||
gtk_text_tag_table_add(gtk_text_buffer_get_tag_table(gtk_text_view_get_buffer(view)),
|
||||
GTK_TEXT_TAG(tag));
|
||||
g_object_unref(tag);
|
||||
tag = g_object_new (MOO_TYPE_HTML_TAG, (const char*) NULL);
|
||||
gtk_text_tag_table_add (gtk_text_buffer_get_tag_table (gtk_text_view_get_buffer (view)),
|
||||
GTK_TEXT_TAG (tag));
|
||||
g_object_unref (tag);
|
||||
|
||||
if (tag->href)
|
||||
data->href_tags = g_slist_prepend(data->href_tags, tag);
|
||||
data->href_tags = g_slist_prepend (data->href_tags, tag);
|
||||
|
||||
attr_apply(&real_attr, tag, view);
|
||||
attr_apply (&real_attr, tag, view);
|
||||
|
||||
return tag;
|
||||
}
|
||||
|
@ -1091,7 +1084,7 @@ moo_html_motion (GtkWidget *widget,
|
|||
{
|
||||
x = event->x;
|
||||
y = event->y;
|
||||
state = GdkModifierType (event->state);
|
||||
state = event->state;
|
||||
}
|
||||
|
||||
if (state & (GDK_BUTTON1_MASK | GDK_BUTTON2_MASK | GDK_BUTTON3_MASK))
|
||||
|
@ -1159,7 +1152,7 @@ moo_html_get_tag (GtkTextIter *iter)
|
|||
{
|
||||
if (MOO_IS_HTML_TAG (l->data))
|
||||
{
|
||||
tag = MOO_HTML_TAG (l->data);
|
||||
tag = l->data;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
@ -1231,13 +1224,10 @@ moo_html_parse_url (const char *url,
|
|||
g_return_val_if_fail (url != NULL, FALSE);
|
||||
g_return_val_if_fail (scheme && base && anchor, FALSE);
|
||||
|
||||
regex = g_regex_new ("^([a-zA-Z]+:(//)?)?([^#]*)(#(.*))?$",
|
||||
GRegexCompileFlags (0),
|
||||
GRegexMatchFlags (0),
|
||||
nullptr);
|
||||
regex = g_regex_new ("^([a-zA-Z]+:(//)?)?([^#]*)(#(.*))?$", 0, 0, NULL);
|
||||
g_return_val_if_fail (regex != NULL, FALSE);
|
||||
|
||||
if (!g_regex_match (regex, url, GRegexMatchFlags (0), &match_info))
|
||||
if (!g_regex_match (regex, url, 0, &match_info))
|
||||
{
|
||||
g_match_info_free (match_info);
|
||||
g_regex_unref (regex);
|
||||
|
@ -1267,7 +1257,7 @@ moo_html_goto_anchor (GtkTextView *view,
|
|||
|
||||
g_return_val_if_fail (anchor != NULL, FALSE);
|
||||
|
||||
mark = reinterpret_cast<GtkTextMark*> (g_hash_table_lookup (data->anchors, anchor));
|
||||
mark = g_hash_table_lookup (data->anchors, anchor);
|
||||
|
||||
if (!mark)
|
||||
{
|
||||
|
@ -1317,8 +1307,7 @@ moo_html_size_allocate_real (GtkWidget *widget,
|
|||
window = gtk_text_view_get_window (GTK_TEXT_VIEW (widget), GTK_TEXT_WINDOW_TEXT);
|
||||
g_return_if_fail (window != NULL);
|
||||
|
||||
child_width = gdk_window_get_width (window);
|
||||
height = gdk_window_get_height (window);
|
||||
gdk_drawable_get_size (window, &child_width, &height);
|
||||
border_width = gtk_container_get_border_width (GTK_CONTAINER (widget));
|
||||
child_width -= 2 * border_width + 2 * widget->style->xthickness +
|
||||
gtk_text_view_get_left_margin (GTK_TEXT_VIEW (widget)) +
|
||||
|
@ -1327,7 +1316,7 @@ moo_html_size_allocate_real (GtkWidget *widget,
|
|||
|
||||
for (l = data->rulers; l != NULL; l = l->next)
|
||||
{
|
||||
GtkWidget *ruler = GTK_WIDGET (l->data);
|
||||
GtkWidget *ruler = l->data;
|
||||
gtk_widget_set_size_request (ruler, child_width, -1);
|
||||
}
|
||||
}
|
||||
|
@ -1765,7 +1754,7 @@ get_format_elm_attr (xmlNode *node)
|
|||
g_hash_table_insert (elms, (char*) "small", attr);
|
||||
}
|
||||
|
||||
return reinterpret_cast<MooHtmlAttr*> (g_hash_table_lookup (elms, node->name));
|
||||
return g_hash_table_lookup (elms, node->name);
|
||||
}
|
||||
|
||||
|
||||
|
@ -1778,7 +1767,7 @@ static void
|
|||
add_func__ (const char *static_elm_name,
|
||||
ProcessElm func)
|
||||
{
|
||||
g_hash_table_insert (proc_elm_funcs__, (char*) static_elm_name, (void*) func);
|
||||
g_hash_table_insert (proc_elm_funcs__, (char*) static_elm_name, func);
|
||||
}
|
||||
|
||||
static void
|
||||
|
@ -2162,7 +2151,7 @@ process_font_elm (GtkTextView *view,
|
|||
color = GET_PROP (elm, "color");
|
||||
face = GET_PROP (elm, "face");
|
||||
|
||||
attr.mask = MOO_HTML_ATTR_MASK_NONE;
|
||||
attr.mask = 0;
|
||||
attr.font_face = NULL;
|
||||
|
||||
if (size__)
|
|
@ -1,26 +0,0 @@
|
|||
moo_sources += \
|
||||
moocpp/gboxed.h \
|
||||
moocpp/gobjectutils.h \
|
||||
moocpp/gobjptr.h \
|
||||
moocpp/gobjref.h \
|
||||
moocpp/gobjinfo.h \
|
||||
moocpp/gobjrawptr.h \
|
||||
moocpp/gobjtypes.h \
|
||||
moocpp/gobjtypes-glib.h \
|
||||
moocpp/gobjtypes-gio.h \
|
||||
moocpp/gobjtypes-gtk.h \
|
||||
moocpp/gobjtypes-glib.cpp \
|
||||
moocpp/gobjtypes-gio.cpp \
|
||||
moocpp/gobjtypes-gtk.cpp \
|
||||
moocpp/gobjwrapper.h \
|
||||
moocpp/gparam.h \
|
||||
moocpp/grefptr.h \
|
||||
moocpp/gutil.h \
|
||||
moocpp/gutil.cpp \
|
||||
moocpp/memutils.h \
|
||||
moocpp/moocpp.h \
|
||||
moocpp/strutils.h \
|
||||
moocpp/strutils.cpp \
|
||||
moocpp/utils.h
|
||||
|
||||
# -%- use-tabs:true, indent-width: 8, strip:true -%-
|
|
@ -1,58 +0,0 @@
|
|||
/*
|
||||
* moocpp/gboxed.h
|
||||
*
|
||||
* Copyright (C) 2004-2016 by Yevgen Muntyan <emuntyan@users.sourceforge.net>
|
||||
*
|
||||
* This file is part of medit. medit 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.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public
|
||||
* License along with medit. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#pragma once
|
||||
|
||||
#ifndef __cplusplus
|
||||
#error "This is a C++ header"
|
||||
#endif
|
||||
|
||||
#include <memory>
|
||||
#include <utility>
|
||||
#include <mooutils/mootype-macros.h>
|
||||
|
||||
namespace moo {
|
||||
|
||||
template<typename T>
|
||||
class gboxed_helper
|
||||
{
|
||||
public:
|
||||
static T* array_elm_copy(T* obj)
|
||||
{
|
||||
return new T(*obj);
|
||||
}
|
||||
|
||||
static gpointer copy(gpointer p)
|
||||
{
|
||||
return array_elm_copy(reinterpret_cast<T*>(p));
|
||||
}
|
||||
|
||||
static void array_elm_free(T* obj)
|
||||
{
|
||||
delete obj;
|
||||
}
|
||||
|
||||
static void free(gpointer p)
|
||||
{
|
||||
array_elm_free(reinterpret_cast<T*>(p));
|
||||
}
|
||||
};
|
||||
|
||||
#define MOO_DEFINE_BOXED_CPP_TYPE(Object, object) \
|
||||
MOO_DEFINE_BOXED_TYPE(Object, object, \
|
||||
gboxed_helper<Object>::copy, \
|
||||
gboxed_helper<Object>::free)
|
||||
|
||||
} // namespace moo
|
|
@ -1,5 +0,0 @@
|
|||
SET(moocpp_sources
|
||||
moocpp/moocpp.cmake
|
||||
moocpp/moocpp.h
|
||||
moocpp/utils.h
|
||||
)
|
|
@ -1,36 +0,0 @@
|
|||
/*
|
||||
* moocpp/moocpp.h
|
||||
*
|
||||
* Copyright (C) 2004-2016 by Yevgen Muntyan <emuntyan@users.sourceforge.net>
|
||||
*
|
||||
* This file is part of medit. medit 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.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public
|
||||
* License along with medit. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <gtk/gtk.h>
|
||||
#include <mooglib/moo-glib.h>
|
||||
|
||||
#ifdef __cplusplus
|
||||
|
||||
#include <moocpp/gboxed.h>
|
||||
|
||||
#include <moogpp/moogpp.h>
|
||||
|
||||
namespace moo {
|
||||
|
||||
using gstr = g::gstr;
|
||||
using gerrp = g::gerrp;
|
||||
|
||||
}
|
||||
|
||||
#endif __cplusplus
|
||||
|
||||
#include <moocpp/utils.h>
|
|
@ -1,134 +0,0 @@
|
|||
/*
|
||||
* moocpp/gobjinfo.h
|
||||
*
|
||||
* Copyright (C) 2004-2016 by Yevgen Muntyan <emuntyan@users.sourceforge.net>
|
||||
*
|
||||
* This file is part of medit. medit 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.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public
|
||||
* License along with medit. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#pragma once
|
||||
|
||||
#ifdef __cplusplus
|
||||
|
||||
#include <glib-object.h>
|
||||
#include <type_traits>
|
||||
#include <moocpp/strutils.h>
|
||||
|
||||
namespace moo {
|
||||
|
||||
void init_gobj_system ();
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////////////////////
|
||||
//
|
||||
// gobjinfo
|
||||
//
|
||||
|
||||
template<typename Object, typename Super>
|
||||
struct gobj_is_subclass
|
||||
{
|
||||
static const bool value = false;
|
||||
};
|
||||
|
||||
// Generic implementation, all we know it's a subclass of GObject; we don't
|
||||
// even know its GType. This implementation is needed so that it's possible
|
||||
// to have gobj_ptr<GAnything> without having to define gobjinfo for it.
|
||||
template<typename Object>
|
||||
struct gobjinfo
|
||||
{
|
||||
static const bool is_gobject = true;
|
||||
using object_type = Object;
|
||||
using parent_type = GObject;
|
||||
// object_g_type() is not defined
|
||||
};
|
||||
|
||||
template<>
|
||||
struct gobjinfo<GObject>
|
||||
{
|
||||
static const bool is_gobject = true;
|
||||
using object_type = GObject;
|
||||
static GType object_g_type() { return G_TYPE_OBJECT; }
|
||||
};
|
||||
|
||||
template<typename T>
|
||||
inline GType get_g_type()
|
||||
{
|
||||
return gobjinfo<T>::object_g_type();
|
||||
}
|
||||
|
||||
template<>
|
||||
struct gobj_is_subclass<GObject, GObject>
|
||||
{
|
||||
static const bool value = true;
|
||||
static GObject* down_cast(GObject* o) { return o; }
|
||||
};
|
||||
|
||||
#define MOO_DEFINE_GOBJ_TYPE(Object, Parent, g_type) \
|
||||
namespace moo { \
|
||||
\
|
||||
template<> \
|
||||
struct gobjinfo<Object> \
|
||||
{ \
|
||||
static const bool is_gobject = true; \
|
||||
using object_type = Object; \
|
||||
using parent_type = Parent; \
|
||||
static GType object_g_type() { return g_type; } \
|
||||
}; \
|
||||
\
|
||||
template<> \
|
||||
struct gobj_is_subclass<Object, Object> \
|
||||
{ \
|
||||
static const bool value = true; \
|
||||
static Object* down_cast(Object* o) { return o; } \
|
||||
}; \
|
||||
\
|
||||
template<typename Super> \
|
||||
struct gobj_is_subclass<Object, Super> \
|
||||
{ \
|
||||
static const bool value = true; \
|
||||
static Super* down_cast(Object *o) \
|
||||
{ \
|
||||
static_assert(gobj_is_subclass<Object, Super>::value, \
|
||||
"Super is not a superclass of " #Object); \
|
||||
Parent* p = reinterpret_cast<Parent*>(o); \
|
||||
Super* s = gobj_is_subclass<Parent, Super>::down_cast(p); \
|
||||
return s; \
|
||||
} \
|
||||
}; \
|
||||
} \
|
||||
|
||||
#define MOO_DEFINE_GIFACE_TYPE(Iface, g_type) \
|
||||
MOO_DEFINE_GOBJ_TYPE(Iface, GObject, g_type)
|
||||
|
||||
#define MOO_GOBJ_IMPLEMENTS_IFACE(Object, Iface) \
|
||||
namespace moo { \
|
||||
\
|
||||
template<> \
|
||||
struct gobj_is_subclass<Object, Iface> \
|
||||
{ \
|
||||
static const bool value = true; \
|
||||
static Iface* down_cast(Object *o) \
|
||||
{ \
|
||||
return reinterpret_cast<Iface*>(o); \
|
||||
} \
|
||||
}; \
|
||||
} \
|
||||
|
||||
|
||||
#define MOO_DEFINE_NON_GOBJ_TYPE(Object) \
|
||||
namespace moo { \
|
||||
template<> struct gobjinfo<Object> { static const bool is_gobject = false; }; \
|
||||
}
|
||||
|
||||
template<typename Object>
|
||||
using gobj_parent_type = typename gobjinfo<Object>::parent_type;
|
||||
|
||||
} // namespace moo
|
||||
|
||||
#endif // __cplusplus
|
|
@ -1,313 +0,0 @@
|
|||
/*
|
||||
* moocpp/gobjptr.h
|
||||
*
|
||||
* Copyright (C) 2004-2016 by Yevgen Muntyan <emuntyan@users.sourceforge.net>
|
||||
*
|
||||
* This file is part of medit. medit 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.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public
|
||||
* License along with medit. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#pragma once
|
||||
|
||||
#include "moocpp/gobjrawptr.h"
|
||||
#include "moocpp/grefptr.h"
|
||||
#include "moocpp/gobjectutils.h"
|
||||
|
||||
namespace moo {
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////////////////////
|
||||
//
|
||||
// gobj_ptr
|
||||
//
|
||||
|
||||
template<typename Object>
|
||||
class gobj_ptr
|
||||
{
|
||||
using ref_type = gobj_ref<Object>;
|
||||
|
||||
static_assert(gobjinfo<Object>::is_gobject, "Not a GObject");
|
||||
|
||||
public:
|
||||
gobj_ptr() {}
|
||||
|
||||
gobj_ptr(Object* obj, ref_transfer policy)
|
||||
{
|
||||
assign(obj, policy);
|
||||
}
|
||||
|
||||
gobj_ptr(const nullptr_t&)
|
||||
: gobj_ptr()
|
||||
{
|
||||
}
|
||||
|
||||
static gobj_ptr wrap_new(Object* obj)
|
||||
{
|
||||
return gobj_ptr(obj, ref_transfer::take_ownership);
|
||||
}
|
||||
|
||||
static gobj_ptr wrap(Object* obj)
|
||||
{
|
||||
return gobj_ptr(obj, ref_transfer::make_copy);
|
||||
}
|
||||
|
||||
~gobj_ptr()
|
||||
{
|
||||
reset();
|
||||
}
|
||||
|
||||
void ref(Object* obj)
|
||||
{
|
||||
assign(obj, ref_transfer::make_copy);
|
||||
}
|
||||
|
||||
void set(Object* obj)
|
||||
{
|
||||
assign(obj, ref_transfer::make_copy);
|
||||
}
|
||||
|
||||
void set_new(Object* obj)
|
||||
{
|
||||
assign(obj, ref_transfer::take_ownership);
|
||||
}
|
||||
|
||||
Object* release()
|
||||
{
|
||||
auto* tmp = gobj();
|
||||
m_ref._set_gobj(nullptr);
|
||||
return tmp;
|
||||
}
|
||||
|
||||
void reset()
|
||||
{
|
||||
auto* tmp = gobj();
|
||||
if (tmp)
|
||||
{
|
||||
m_ref._set_gobj(nullptr);
|
||||
g_object_unref(tmp);
|
||||
}
|
||||
}
|
||||
|
||||
// Implicit conversion to non-const Object* is dangerous because there is a lot
|
||||
// of code still which frees/steals objects directly. For example:
|
||||
// FooObject* tmp = x->s;
|
||||
// x->s = NULL;
|
||||
// g_object_unref (tmp);
|
||||
operator const Object* () const { return gobj(); }
|
||||
operator ref_type*() const { return m_ref.self(); }
|
||||
ref_type* operator->() const { return m_ref.self(); }
|
||||
ref_type& operator*() { return m_ref; }
|
||||
const ref_type& operator*() const { return m_ref; }
|
||||
|
||||
// These are nasty. Because of ref_type* conversion this can be converted to void*,
|
||||
// which in turn can be passed to g_object_ref or g_free, etc.
|
||||
operator void*() const = delete;
|
||||
operator const void*() const = delete;
|
||||
|
||||
Object* gobj() const { return m_ref.gobj(); }
|
||||
Object** pp() { return m_ref._pp(); }
|
||||
|
||||
template<typename Super>
|
||||
Super* gobj() const
|
||||
{
|
||||
return gobj_is_subclass<Object, Super>::down_cast(m_ref.gobj());
|
||||
}
|
||||
|
||||
template<typename Super>
|
||||
operator const Super* () const { return gobj<Super>(); }
|
||||
|
||||
template<typename Super>
|
||||
operator gobj_ptr<Super> () const { return gobj_ptr<Super>::wrap (gobj<Super> ()); }
|
||||
|
||||
operator bool() const { return gobj() != nullptr; }
|
||||
bool operator!() const { return gobj() == nullptr; }
|
||||
|
||||
gobj_ptr(const gobj_ptr& other)
|
||||
: gobj_ptr()
|
||||
{
|
||||
ref(other.gobj());
|
||||
}
|
||||
|
||||
gobj_ptr& operator=(const gobj_ptr& other)
|
||||
{
|
||||
ref(other.gobj());
|
||||
return *this;
|
||||
}
|
||||
|
||||
gobj_ptr(gobj_ptr&& other)
|
||||
: gobj_ptr()
|
||||
{
|
||||
m_ref._set_gobj(other.gobj());
|
||||
other.m_ref._set_gobj(nullptr);
|
||||
}
|
||||
|
||||
gobj_ptr& operator=(const nullptr_t&)
|
||||
{
|
||||
reset();
|
||||
return *this;
|
||||
}
|
||||
|
||||
gobj_ptr& operator=(gobj_ptr&& other)
|
||||
{
|
||||
if (gobj() != other.gobj())
|
||||
{
|
||||
assign(other.gobj(), ref_transfer::take_ownership);
|
||||
other.m_ref._set_gobj(nullptr);
|
||||
}
|
||||
|
||||
return *this;
|
||||
}
|
||||
|
||||
private:
|
||||
void assign(Object* obj, ref_transfer policy)
|
||||
{
|
||||
g_assert(!obj || G_IS_OBJECT(obj));
|
||||
|
||||
if (gobj() != obj)
|
||||
{
|
||||
Object* tmp = gobj();
|
||||
m_ref._set_gobj(obj);
|
||||
|
||||
if (obj)
|
||||
{
|
||||
if (policy == ref_transfer::make_copy)
|
||||
g_object_ref(obj);
|
||||
else if (g_object_is_floating(obj))
|
||||
g_object_ref_sink(obj);
|
||||
}
|
||||
|
||||
if (tmp)
|
||||
g_object_unref(tmp);
|
||||
}
|
||||
}
|
||||
|
||||
private:
|
||||
mutable gobj_ref<Object> m_ref;
|
||||
};
|
||||
|
||||
template<typename Object>
|
||||
inline gobj_ptr<Object> wrap_new(Object *obj)
|
||||
{
|
||||
return gobj_ptr<Object>::wrap_new(obj);
|
||||
}
|
||||
|
||||
template<typename Object>
|
||||
inline gobj_ptr<Object> wrap(Object* obj)
|
||||
{
|
||||
return gobj_ptr<Object>::wrap(obj);
|
||||
}
|
||||
|
||||
template<typename Object>
|
||||
inline gobj_ptr<Object> wrap(const gobj_raw_ptr<Object>& obj)
|
||||
{
|
||||
return gobj_ptr<Object>::wrap(obj);
|
||||
}
|
||||
|
||||
template<typename Object>
|
||||
inline gobj_ref<Object> wrap (Object& obj)
|
||||
{
|
||||
return *wrap (&obj);
|
||||
}
|
||||
|
||||
template<typename T, typename ...Args>
|
||||
inline gobj_ptr<T> create_gobj(GType obj_type, Args&& ...args)
|
||||
{
|
||||
return wrap_new(reinterpret_cast<T*>(g_object_new(obj_type, std::forward<Args>(args)...)));
|
||||
}
|
||||
|
||||
template<typename T, typename ...Args>
|
||||
inline gobj_ptr<T> create_gobj(Args&& ...args)
|
||||
{
|
||||
// object_g_type() will produce a compiler error if the type wasn't registered
|
||||
return create_gobj(gobjinfo<T>::object_g_type(), std::forward<Args>(args)...);
|
||||
}
|
||||
|
||||
template<typename T>
|
||||
inline gobj_ptr<T> create_gobj()
|
||||
{
|
||||
// object_g_type() will produce a compiler error if the type wasn't registered
|
||||
return create_gobj<T>(gobjinfo<T>::object_g_type(), nullptr);
|
||||
}
|
||||
|
||||
template<typename Object, typename Super>
|
||||
Object* up_cast (Super* o)
|
||||
{
|
||||
return G_TYPE_CHECK_INSTANCE_CAST ((o), gobjinfo<Object>::object_g_type(), Object);
|
||||
}
|
||||
|
||||
} // namespace moo
|
||||
|
||||
template<typename X>
|
||||
void g_object_unref(const moo::gobj_ptr<X>&) = delete;
|
||||
template<typename X>
|
||||
void g_free(const moo::gobj_ptr<X>&) = delete;
|
||||
|
||||
template<typename X>
|
||||
inline bool operator==(const moo::gobj_ptr<X>& p, const nullptr_t&)
|
||||
{
|
||||
return p.gobj() == nullptr;
|
||||
}
|
||||
|
||||
template<typename X>
|
||||
inline bool operator==(const nullptr_t&, const moo::gobj_ptr<X>& p)
|
||||
{
|
||||
return p.gobj() == nullptr;
|
||||
}
|
||||
|
||||
template<typename X, typename Y>
|
||||
inline bool operator==(const moo::gobj_ptr<X>& p1, const moo::gobj_ptr<Y>& p2)
|
||||
{
|
||||
return p1.gobj() == p2.gobj();
|
||||
}
|
||||
|
||||
template<typename X, typename Y>
|
||||
inline bool operator==(const moo::gobj_ptr<X>& p1, const Y* p2)
|
||||
{
|
||||
return p1.gobj() == p2;
|
||||
}
|
||||
|
||||
template<typename X, typename Y>
|
||||
inline bool operator==(const X* p1, const moo::gobj_ptr<Y>& p2)
|
||||
{
|
||||
return p1 == p2.gobj();
|
||||
}
|
||||
|
||||
template<typename X, typename Y>
|
||||
inline bool operator==(const moo::gobj_ptr<X>& p1, const moo::gobj_raw_ptr<Y>& p2)
|
||||
{
|
||||
return p1.gobj() == p2.gobj();
|
||||
}
|
||||
|
||||
template<typename X, typename Y>
|
||||
inline bool operator==(const moo::gobj_raw_ptr<Y>& p1, const moo::gobj_ptr<X>& p2)
|
||||
{
|
||||
return p1.gobj() == p2.gobj();
|
||||
}
|
||||
|
||||
template<typename X, typename Y>
|
||||
bool operator!=(const moo::gobj_ptr<X>& p1, const moo::gobj_ptr<Y>& p2)
|
||||
{
|
||||
return !(p1 == p2);
|
||||
}
|
||||
|
||||
template<typename X, typename Y>
|
||||
bool operator!=(const moo::gobj_ptr<X>& p1, const Y& p2)
|
||||
{
|
||||
return !(p1 == p2);
|
||||
}
|
||||
|
||||
template<typename X, typename Y>
|
||||
bool operator!=(const X& p1, const moo::gobj_ptr<Y>& p2)
|
||||
{
|
||||
return !(p1 == p2);
|
||||
}
|
||||
|
||||
template<typename X> bool operator==(const moo::gobj_ptr<X>& p1, int) = delete;
|
||||
template<typename X> bool operator==(int, const moo::gobj_ptr<X>& p2) = delete;
|
||||
template<typename X> bool operator!=(const moo::gobj_ptr<X>& p1, int) = delete;
|
||||
template<typename X> bool operator!=(int, const moo::gobj_ptr<X>& p2) = delete;
|
|
@ -1,147 +0,0 @@
|
|||
/*
|
||||
* moocpp/gobjrawptr.h
|
||||
*
|
||||
* Copyright (C) 2004-2016 by Yevgen Muntyan <emuntyan@users.sourceforge.net>
|
||||
*
|
||||
* This file is part of medit. medit 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.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public
|
||||
* License along with medit. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#pragma once
|
||||
|
||||
#include "moocpp/gobjref.h"
|
||||
|
||||
namespace moo {
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////////////////////
|
||||
//
|
||||
// gobj_raw_ptr
|
||||
//
|
||||
|
||||
template<typename Object>
|
||||
class gobj_raw_ptr
|
||||
{
|
||||
using ref_type = gobj_ref<Object>;
|
||||
|
||||
public:
|
||||
gobj_raw_ptr(Object* obj = nullptr) { m_ref._set_gobj(obj); }
|
||||
|
||||
operator Object*() const { return gobj(); }
|
||||
operator GTypeInstance*() const { return reinterpret_cast<GTypeInstance*>(gobj()); }
|
||||
operator gpointer() const { return gobj(); }
|
||||
operator gobj_ref<Object>*() const { return m_ref.self(); }
|
||||
|
||||
ref_type* operator->() const { return m_ref.self(); }
|
||||
ref_type& operator*() const { return m_ref; }
|
||||
|
||||
Object* gobj() const { return m_ref.gobj(); }
|
||||
void set(Object* p) { m_ref._set_gobj(p); }
|
||||
|
||||
template<typename Super>
|
||||
Super* gobj() const
|
||||
{
|
||||
return gobj_is_subclass<Object, Super>::down_cast(m_ref.gobj());
|
||||
}
|
||||
|
||||
template<typename Subclass>
|
||||
void set(Subclass* p)
|
||||
{
|
||||
set(gobj_is_subclass<Subclass, Object>::down_cast(p));
|
||||
}
|
||||
|
||||
operator bool() const { return gobj() != nullptr; }
|
||||
bool operator!() const { return gobj() == nullptr; }
|
||||
|
||||
gobj_raw_ptr(const gobj_raw_ptr& other) = default;
|
||||
gobj_raw_ptr& operator=(const gobj_raw_ptr& other) = default;
|
||||
|
||||
gobj_raw_ptr(gobj_raw_ptr&& other)
|
||||
: m_ref(std::move(other.m_ref))
|
||||
{
|
||||
other.set(nullptr);
|
||||
}
|
||||
|
||||
gobj_raw_ptr& operator=(gobj_raw_ptr&& other)
|
||||
{
|
||||
m_ref = std::move(other.m_ref);
|
||||
return *this;
|
||||
}
|
||||
|
||||
template<typename T>
|
||||
gobj_raw_ptr& operator=(T* p)
|
||||
{
|
||||
set(p);
|
||||
return *this;
|
||||
}
|
||||
|
||||
private:
|
||||
mutable gobj_ref<Object> m_ref;
|
||||
};
|
||||
|
||||
} // namespace moo
|
||||
|
||||
template<typename X>
|
||||
inline bool operator==(const moo::gobj_raw_ptr<X>& p, const nullptr_t&)
|
||||
{
|
||||
return p.gobj() == nullptr;
|
||||
}
|
||||
|
||||
template<typename X>
|
||||
inline bool operator==(const nullptr_t&, const moo::gobj_raw_ptr<X>& p)
|
||||
{
|
||||
return p.gobj() == nullptr;
|
||||
}
|
||||
|
||||
template<typename X>
|
||||
inline bool operator==(const moo::gobj_raw_ptr<X>& p1, const moo::gobj_raw_ptr<X>& p2)
|
||||
{
|
||||
return p1.gobj() == p2.gobj();
|
||||
}
|
||||
|
||||
template<typename X>
|
||||
inline bool operator==(const moo::gobj_raw_ptr<X>& p1, const X* p2)
|
||||
{
|
||||
return p1.gobj() == p2;
|
||||
}
|
||||
|
||||
template<typename X>
|
||||
inline bool operator==(const moo::gobj_raw_ptr<X>& p1, X* p2)
|
||||
{
|
||||
return p1.gobj() == p2;
|
||||
}
|
||||
|
||||
template<typename X>
|
||||
inline bool operator==(const X* p1, const moo::gobj_raw_ptr<X>& p2)
|
||||
{
|
||||
return p1 == p2.gobj();
|
||||
}
|
||||
|
||||
template<typename X>
|
||||
inline bool operator==(X* p1, const moo::gobj_raw_ptr<X>& p2)
|
||||
{
|
||||
return p1 == p2.gobj();
|
||||
}
|
||||
|
||||
template<typename X>
|
||||
bool operator!=(const moo::gobj_raw_ptr<X>& p1, const moo::gobj_raw_ptr<X>& p2)
|
||||
{
|
||||
return !(p1 == p2);
|
||||
}
|
||||
|
||||
template<typename X, typename Y>
|
||||
bool operator!=(const moo::gobj_raw_ptr<X>& p1, const Y& p2)
|
||||
{
|
||||
return !(p1 == p2);
|
||||
}
|
||||
|
||||
template<typename X, typename Y>
|
||||
bool operator!=(const X& p1, const moo::gobj_raw_ptr<Y>& p2)
|
||||
{
|
||||
return !(p1 == p2);
|
||||
}
|
|
@ -1,174 +0,0 @@
|
|||
/*
|
||||
* moocpp/gobjref.h
|
||||
*
|
||||
* Copyright (C) 2004-2016 by Yevgen Muntyan <emuntyan@users.sourceforge.net>
|
||||
*
|
||||
* This file is part of medit. medit 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.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public
|
||||
* License along with medit. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#pragma once
|
||||
|
||||
#include "moocpp/gobjinfo.h"
|
||||
|
||||
namespace moo {
|
||||
|
||||
template<typename Object>
|
||||
class gobj_ref;
|
||||
template<typename Object>
|
||||
class gobj_ptr;
|
||||
template<typename Object>
|
||||
class gobj_raw_ptr;
|
||||
template<typename CObject, typename CppObject>
|
||||
class gobj_wrapper;
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////////////////////
|
||||
//
|
||||
// gobj_ref
|
||||
//
|
||||
|
||||
class gobj_ref_base
|
||||
{
|
||||
protected:
|
||||
gobj_ref_base() : m_gobj(nullptr) {}
|
||||
using object_type = GObject;
|
||||
|
||||
public:
|
||||
gobj_ref_base(const gobj_ref_base&) = default;
|
||||
gobj_ref_base& operator=(const gobj_ref_base&) = default;
|
||||
|
||||
gobj_ref_base(gobj_ref_base&& other)
|
||||
: m_gobj(other.m_gobj)
|
||||
{
|
||||
other.m_gobj = nullptr;
|
||||
}
|
||||
|
||||
gobj_ref_base& operator=(gobj_ref_base&& other)
|
||||
{
|
||||
m_gobj = other.m_gobj;
|
||||
other.m_gobj = nullptr;
|
||||
return *this;
|
||||
}
|
||||
|
||||
GObject* gobj() const { return m_gobj; }
|
||||
operator GObject&() const { return *m_gobj; }
|
||||
operator GTypeInstance&() const { return *reinterpret_cast<GTypeInstance*>(m_gobj); }
|
||||
|
||||
protected:
|
||||
GObject* raw_gobj() const { return const_cast<GObject*>(m_gobj); }
|
||||
|
||||
void** _pp ()
|
||||
{
|
||||
g_return_val_if_fail(m_gobj == nullptr, nullptr);
|
||||
return reinterpret_cast<void**>(&m_gobj);
|
||||
}
|
||||
|
||||
private:
|
||||
template<typename Object> friend class gobj_ptr;
|
||||
template<typename Object> friend class gobj_raw_ptr;
|
||||
template<typename Object> friend class gobj_ref;
|
||||
template<typename CObject, typename CppObject> friend class gobj_wrapper;
|
||||
|
||||
void _set_gobj(gpointer gobj) { m_gobj = reinterpret_cast<GObject*>(gobj); }
|
||||
|
||||
private:
|
||||
GObject* m_gobj;
|
||||
};
|
||||
|
||||
template<>
|
||||
class gobj_ref<GObject>; // : public gobj_ref_base
|
||||
|
||||
#define MOO_DEFINE_GOBJREF_METHODS_IMPL(Object, Super) \
|
||||
using super = Super; \
|
||||
using object_type = Object; \
|
||||
using ptrtype = gobj_ptr<object_type>; \
|
||||
\
|
||||
protected: \
|
||||
friend class gobj_ptr<object_type>; \
|
||||
friend class gobj_raw_ptr<object_type>; \
|
||||
\
|
||||
gobj_ref() {} \
|
||||
\
|
||||
object_type** _pp () \
|
||||
{ \
|
||||
return reinterpret_cast<object_type**>(gobj_ref_base::_pp()); \
|
||||
} \
|
||||
\
|
||||
public: \
|
||||
gobj_ref(object_type& gobj) \
|
||||
{ \
|
||||
super::_set_gobj(&gobj); \
|
||||
} \
|
||||
\
|
||||
object_type* gobj() const \
|
||||
{ \
|
||||
return reinterpret_cast<object_type*>(super::raw_gobj()); \
|
||||
} \
|
||||
\
|
||||
template<typename X> \
|
||||
X* gobj() const \
|
||||
{ \
|
||||
return nc_gobj<X>(); \
|
||||
} \
|
||||
\
|
||||
object_type* nc_gobj() const \
|
||||
{ \
|
||||
return const_cast<object_type*>(gobj()); \
|
||||
} \
|
||||
\
|
||||
template<typename X> \
|
||||
X* nc_gobj() const \
|
||||
{ \
|
||||
object_type* o = const_cast<object_type*>(gobj()); \
|
||||
return gobj_is_subclass<Object, X>::down_cast(o); \
|
||||
} \
|
||||
\
|
||||
gobj_ref* self() { return this; } \
|
||||
const gobj_ref* self() const { return this; } \
|
||||
\
|
||||
operator object_type&() const { return *gobj(); } \
|
||||
gobj_raw_ptr<object_type> operator&() const { return nc_gobj(); } \
|
||||
\
|
||||
gobj_ref(const gobj_ref&) = default; \
|
||||
gobj_ref& operator=(const gobj_ref&) = default; \
|
||||
\
|
||||
gobj_ref(gobj_ref&& other) \
|
||||
: super(std::move(static_cast<super&&>(other))) \
|
||||
{ \
|
||||
} \
|
||||
\
|
||||
gobj_ref& operator=(gobj_ref&& other) \
|
||||
{ \
|
||||
super::operator=(std::move(static_cast<super&&>(other))); \
|
||||
return *this; \
|
||||
}
|
||||
|
||||
#define MOO_DEFINE_GOBJREF_METHODS(Object) \
|
||||
MOO_DEFINE_GOBJREF_METHODS_IMPL(Object, gobj_ref<gobj_parent_type<Object>>)
|
||||
|
||||
|
||||
template<typename Object>
|
||||
using gobj_ref_parent = gobj_ref<gobj_parent_type<Object>>;
|
||||
|
||||
// Generic implementation, falls back to the parent type's gobj_ref implementation
|
||||
// if that's known, or to GObject's one, coming from the generic gobjinfo.
|
||||
template<typename Object>
|
||||
class gobj_ref : public virtual gobj_ref_parent<Object>
|
||||
{
|
||||
public:
|
||||
MOO_DEFINE_GOBJREF_METHODS(Object)
|
||||
};
|
||||
|
||||
} // namespace moo
|
||||
|
||||
// Make sure these aren't called in code ported from pure glib C
|
||||
template<typename X>
|
||||
void g_object_unref(const moo::gobj_ref<X>*) = delete;
|
||||
template<typename X>
|
||||
void g_free(const moo::gobj_ref<X>*) = delete;
|
|
@ -1,330 +0,0 @@
|
|||
/*
|
||||
* moocpp/gobjtypes-gio.cpp
|
||||
*
|
||||
* Copyright (C) 2004-2016 by Yevgen Muntyan <emuntyan@users.sourceforge.net>
|
||||
*
|
||||
* This file is part of medit. medit 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.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public
|
||||
* License along with medit. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#include "moocpp/moocpp.h"
|
||||
|
||||
using namespace moo;
|
||||
using namespace moo::g;
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
//
|
||||
// GFile
|
||||
//
|
||||
|
||||
FilePtr File::new_for_path(const char* path)
|
||||
{
|
||||
return wrap_new(g_file_new_for_path(path));
|
||||
}
|
||||
|
||||
FilePtr File::new_for_uri(const char* uri)
|
||||
{
|
||||
return wrap_new(g_file_new_for_uri(uri));
|
||||
}
|
||||
|
||||
FilePtr File::new_for_commandline_arg(const char* arg)
|
||||
{
|
||||
return wrap_new(g_file_new_for_commandline_arg(arg));
|
||||
}
|
||||
|
||||
FilePtr File::parse_name(const char* parse_name)
|
||||
{
|
||||
return wrap_new(g_file_parse_name(parse_name));
|
||||
}
|
||||
|
||||
FilePtr File::dup()
|
||||
{
|
||||
return FilePtr::wrap_new(g_file_dup(nc_gobj()));
|
||||
}
|
||||
|
||||
bool File::equal(File file2)
|
||||
{
|
||||
return g_file_equal(nc_gobj(), file2.gobj());
|
||||
}
|
||||
|
||||
gstr File::get_basename()
|
||||
{
|
||||
return gstr::wrap_new(g_file_get_basename(nc_gobj()));
|
||||
}
|
||||
|
||||
gstr File::get_path()
|
||||
{
|
||||
return gstr::wrap_new(g_file_get_path(nc_gobj()));
|
||||
}
|
||||
|
||||
gstr File::get_uri()
|
||||
{
|
||||
return gstr::wrap_new(g_file_get_uri(nc_gobj()));
|
||||
}
|
||||
|
||||
gstr File::get_parse_name()
|
||||
{
|
||||
return gstr::wrap_new(g_file_get_parse_name(nc_gobj()));
|
||||
}
|
||||
|
||||
FilePtr File::get_parent()
|
||||
{
|
||||
return FilePtr::wrap_new(g_file_get_parent(nc_gobj()));
|
||||
}
|
||||
|
||||
bool File::has_parent(File parent)
|
||||
{
|
||||
return g_file_has_parent(nc_gobj(), parent.gobj());
|
||||
}
|
||||
|
||||
FilePtr File::get_child(const char* name)
|
||||
{
|
||||
return FilePtr::wrap_new(g_file_get_child(nc_gobj(), name));
|
||||
}
|
||||
|
||||
FilePtr File::get_child_for_display_name(const char* display_name, gerrp& error)
|
||||
{
|
||||
return FilePtr::wrap_new(g_file_get_child_for_display_name(nc_gobj(), display_name, &error));
|
||||
}
|
||||
|
||||
bool File::has_prefix(File prefix)
|
||||
{
|
||||
return g_file_has_prefix(nc_gobj(), prefix.gobj());
|
||||
}
|
||||
|
||||
gstr File::get_relative_path(File descendant)
|
||||
{
|
||||
return gstr::wrap_new(g_file_get_relative_path(nc_gobj(), descendant.gobj()));
|
||||
}
|
||||
|
||||
FilePtr File::resolve_relative_path(const char *relative_path)
|
||||
{
|
||||
return FilePtr::wrap_new(g_file_resolve_relative_path(nc_gobj(), relative_path));
|
||||
}
|
||||
|
||||
bool File::is_native()
|
||||
{
|
||||
return g_file_is_native(nc_gobj());
|
||||
}
|
||||
|
||||
bool File::has_uri_scheme(const char *uri_scheme)
|
||||
{
|
||||
return g_file_has_uri_scheme(nc_gobj(), uri_scheme);
|
||||
}
|
||||
|
||||
gstr File::get_uri_scheme()
|
||||
{
|
||||
return gstr::wrap_new(g_file_get_uri_scheme(nc_gobj()));
|
||||
}
|
||||
|
||||
g::FileInputStreamPtr File::read(GCancellable* cancellable, gerrp& error)
|
||||
{
|
||||
return wrap_new (g_file_read(gobj(), cancellable, &error));
|
||||
}
|
||||
|
||||
g::FileOutputStreamPtr File::append_to(GFileCreateFlags flags, GCancellable* cancellable, gerrp& error)
|
||||
{
|
||||
return wrap_new (g_file_append_to(gobj(), flags, cancellable, &error));
|
||||
}
|
||||
|
||||
g::FileOutputStreamPtr File::create(GFileCreateFlags flags, GCancellable* cancellable, gerrp& error)
|
||||
{
|
||||
return wrap_new (g_file_create(gobj(), flags, cancellable, &error));
|
||||
}
|
||||
|
||||
g::FileOutputStreamPtr File::replace(const char* etag, gboolean make_backup, GFileCreateFlags flags, GCancellable* cancellable, gerrp& error)
|
||||
{
|
||||
return wrap_new (g_file_replace(gobj(), etag, make_backup, flags, cancellable, &error));
|
||||
}
|
||||
|
||||
g::FileIOStreamPtr File::open_readwrite(GCancellable* cancellable, gerrp& error)
|
||||
{
|
||||
return wrap_new (g_file_open_readwrite(gobj(), cancellable, &error));
|
||||
}
|
||||
|
||||
g::FileIOStreamPtr File::create_readwrite(GFileCreateFlags flags, GCancellable* cancellable, gerrp& error)
|
||||
{
|
||||
return wrap_new (g_file_create_readwrite(gobj(), flags, cancellable, &error));
|
||||
}
|
||||
|
||||
g::FileIOStreamPtr File::replace_readwrite(const char* etag, gboolean make_backup, GFileCreateFlags flags, GCancellable* cancellable, gerrp& error)
|
||||
{
|
||||
return wrap_new (g_file_replace_readwrite(gobj(), etag, make_backup, flags, cancellable, &error));
|
||||
}
|
||||
|
||||
bool File::query_exists(GCancellable* cancellable)
|
||||
{
|
||||
return g_file_query_exists(nc_gobj(), cancellable);
|
||||
}
|
||||
|
||||
GFileType File::query_file_type(GFileQueryInfoFlags flags, GCancellable* cancellable)
|
||||
{
|
||||
return g_file_query_file_type(nc_gobj(), flags, cancellable);
|
||||
}
|
||||
|
||||
FileInfoPtr File::query_info(const char *attributes, GFileQueryInfoFlags flags, GCancellable* cancellable, gerrp& error)
|
||||
{
|
||||
return wrap_new(g_file_query_info(nc_gobj(), attributes, flags, cancellable, &error));
|
||||
}
|
||||
|
||||
FileInfoPtr File::query_filesystem_info(const char *attributes, GCancellable* cancellable, gerrp& error)
|
||||
{
|
||||
return wrap_new(g_file_query_filesystem_info(nc_gobj(), attributes, cancellable, &error));
|
||||
}
|
||||
|
||||
GFileEnumerator* File::enumerate_children(const char *attributes, GFileQueryInfoFlags flags, GCancellable* cancellable, gerrp& error)
|
||||
{
|
||||
return g_file_enumerate_children(nc_gobj(), attributes, flags, cancellable, &error);
|
||||
}
|
||||
|
||||
FilePtr File::set_display_name(const char* display_name, GCancellable* cancellable, gerrp& error)
|
||||
{
|
||||
return FilePtr::wrap_new(g_file_set_display_name(nc_gobj(), display_name, cancellable, &error));
|
||||
}
|
||||
|
||||
bool File::delete_(GCancellable* cancellable, gerrp& error)
|
||||
{
|
||||
return g_file_delete(nc_gobj(), cancellable, &error);
|
||||
}
|
||||
|
||||
bool File::trash(GCancellable* cancellable, gerrp& error)
|
||||
{
|
||||
return g_file_trash(nc_gobj(), cancellable, &error);
|
||||
}
|
||||
|
||||
bool File::copy(File destination, GFileCopyFlags flags, GCancellable* cancellable, GFileProgressCallback progress_callback, gpointer progress_callback_data, gerrp& error)
|
||||
{
|
||||
return g_file_copy(nc_gobj(), destination.gobj(), flags, cancellable, progress_callback, progress_callback_data, &error);
|
||||
}
|
||||
|
||||
bool File::move(File destination, GFileCopyFlags flags, GCancellable* cancellable, GFileProgressCallback progress_callback, gpointer progress_callback_data, gerrp& error)
|
||||
{
|
||||
return g_file_move(nc_gobj(), destination.gobj(), flags, cancellable, progress_callback, progress_callback_data, &error);
|
||||
}
|
||||
|
||||
bool File::make_directory(GCancellable* cancellable, gerrp& error)
|
||||
{
|
||||
return g_file_make_directory(nc_gobj(), cancellable, &error);
|
||||
}
|
||||
|
||||
bool File::make_directory_with_parents(GCancellable* cancellable, gerrp& error)
|
||||
{
|
||||
return g_file_make_directory_with_parents(nc_gobj(), cancellable, &error);
|
||||
}
|
||||
|
||||
bool File::make_symbolic_link(const char *symlink_value, GCancellable* cancellable, gerrp& error)
|
||||
{
|
||||
return g_file_make_symbolic_link(nc_gobj(), symlink_value, cancellable, &error);
|
||||
}
|
||||
|
||||
bool File::load_contents(GCancellable* cancellable, char** contents, gsize* length, char** etag_out, gerrp& error)
|
||||
{
|
||||
return g_file_load_contents(nc_gobj(), cancellable, contents, length, etag_out, &error);
|
||||
}
|
||||
|
||||
bool File::replace_contents(const char* contents, gsize length, const char* etag, gboolean make_backup, GFileCreateFlags flags, char** new_etag, GCancellable* cancellable, gerrp& error)
|
||||
{
|
||||
return g_file_replace_contents(nc_gobj(), contents, length, etag, make_backup, flags, new_etag, cancellable, &error);
|
||||
}
|
||||
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
//
|
||||
// GOutputStream
|
||||
//
|
||||
|
||||
gssize OutputStream::write(const void* buffer, gsize count, GCancellable* cancellable, gerrp& error)
|
||||
{
|
||||
return g_output_stream_write(gobj(), buffer, count, cancellable, &error);
|
||||
}
|
||||
|
||||
bool OutputStream::write_all(const void* buffer, gsize count, gsize* bytes_written, GCancellable* cancellable, gerrp& error)
|
||||
{
|
||||
return g_output_stream_write_all(gobj(), buffer, count, bytes_written, cancellable, &error);
|
||||
}
|
||||
|
||||
gssize OutputStream::splice(g::InputStream source, GOutputStreamSpliceFlags flags, GCancellable* cancellable, gerrp& error)
|
||||
{
|
||||
return g_output_stream_splice(gobj(), source.gobj(), flags, cancellable, &error);
|
||||
}
|
||||
|
||||
bool OutputStream::flush(GCancellable* cancellable, gerrp& error)
|
||||
{
|
||||
return g_output_stream_flush(gobj(), cancellable, &error);
|
||||
}
|
||||
|
||||
bool OutputStream::close(GCancellable* cancellable, gerrp& error)
|
||||
{
|
||||
return g_output_stream_close(gobj(), cancellable, &error);
|
||||
}
|
||||
|
||||
void OutputStream::write_async(const void* buffer, gsize count, int io_priority, GCancellable* cancellable, GAsyncReadyCallback callback, gpointer user_data)
|
||||
{
|
||||
g_output_stream_write_async(gobj(), buffer, count, io_priority, cancellable, callback, user_data);
|
||||
}
|
||||
|
||||
gssize OutputStream::write_finish(GAsyncResult* result, gerrp& error)
|
||||
{
|
||||
return g_output_stream_write_finish(gobj(), result, &error);
|
||||
}
|
||||
|
||||
void OutputStream::splice_async(g::InputStream source, GOutputStreamSpliceFlags flags, int io_priority, GCancellable* cancellable, GAsyncReadyCallback callback, gpointer user_data)
|
||||
{
|
||||
g_output_stream_splice_async(gobj(), source.gobj(), flags, io_priority, cancellable, callback, user_data);
|
||||
}
|
||||
|
||||
gssize OutputStream::splice_finish(GAsyncResult* result, gerrp& error)
|
||||
{
|
||||
return g_output_stream_splice_finish(gobj(), result, &error);
|
||||
}
|
||||
|
||||
void OutputStream::flush_async(int io_priority, GCancellable* cancellable, GAsyncReadyCallback callback, gpointer user_data)
|
||||
{
|
||||
g_output_stream_flush_async(gobj(), io_priority, cancellable, callback, user_data);
|
||||
}
|
||||
|
||||
bool OutputStream::flush_finish(GAsyncResult* result, gerrp& error)
|
||||
{
|
||||
return g_output_stream_flush_finish(gobj(), result, &error);
|
||||
}
|
||||
|
||||
void OutputStream::close_async(int io_priority, GCancellable* cancellable, GAsyncReadyCallback callback, gpointer user_data)
|
||||
{
|
||||
g_output_stream_close_async(gobj(), io_priority, cancellable, callback, user_data);
|
||||
}
|
||||
|
||||
bool OutputStream::close_finish(GAsyncResult* result, gerrp& error)
|
||||
{
|
||||
return g_output_stream_close_finish(gobj(), result, &error);
|
||||
}
|
||||
|
||||
bool OutputStream::is_closed()
|
||||
{
|
||||
return g_output_stream_is_closed(gobj());
|
||||
}
|
||||
|
||||
bool OutputStream::is_closing()
|
||||
{
|
||||
return g_output_stream_is_closing(gobj());
|
||||
}
|
||||
|
||||
bool OutputStream::has_pending()
|
||||
{
|
||||
return g_output_stream_has_pending(gobj());
|
||||
}
|
||||
|
||||
bool OutputStream::set_pending(gerrp& error)
|
||||
{
|
||||
return g_output_stream_set_pending(gobj(), &error);
|
||||
}
|
||||
|
||||
void OutputStream::clear_pending()
|
||||
{
|
||||
g_output_stream_clear_pending(gobj());
|
||||
}
|
|
@ -1,225 +0,0 @@
|
|||
/*
|
||||
* moocpp/gobjtypes-gio.h
|
||||
*
|
||||
* Copyright (C) 2004-2016 by Yevgen Muntyan <emuntyan@users.sourceforge.net>
|
||||
*
|
||||
* This file is part of medit. medit 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.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public
|
||||
* License along with medit. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <gio/gio.h>
|
||||
#include <mooglib/moo-glib.h>
|
||||
|
||||
#ifdef __cplusplus
|
||||
|
||||
#include "moocpp/gobjtypes-glib.h"
|
||||
#include "moocpp/strutils.h"
|
||||
|
||||
MOO_DEFINE_GOBJ_TYPE(GFile, GObject, G_TYPE_FILE)
|
||||
MOO_DEFINE_GOBJ_TYPE(GFileInfo, GObject, G_TYPE_FILE_INFO)
|
||||
|
||||
MOO_DEFINE_GOBJ_TYPE(GOutputStream, GObject, G_TYPE_OUTPUT_STREAM)
|
||||
MOO_DEFINE_GOBJ_TYPE(GFileOutputStream, GOutputStream, G_TYPE_FILE_OUTPUT_STREAM)
|
||||
MOO_DEFINE_GOBJ_TYPE(GInputStream, GObject, G_TYPE_INPUT_STREAM)
|
||||
MOO_DEFINE_GOBJ_TYPE(GFileInputStream, GInputStream, G_TYPE_FILE_INPUT_STREAM)
|
||||
MOO_DEFINE_GOBJ_TYPE(GIOStream, GObject, G_TYPE_IO_STREAM)
|
||||
MOO_DEFINE_GOBJ_TYPE(GFileIOStream, GIOStream, G_TYPE_FILE_IO_STREAM)
|
||||
|
||||
MOO_DECLARE_CUSTOM_GOBJ_TYPE(GFile)
|
||||
MOO_DECLARE_CUSTOM_GOBJ_TYPE(GOutputStream)
|
||||
|
||||
namespace moo {
|
||||
|
||||
namespace g {
|
||||
|
||||
MOO_GOBJ_TYPEDEFS(File, GFile);
|
||||
MOO_GOBJ_TYPEDEFS(FileInfo, GFileInfo);
|
||||
MOO_GOBJ_TYPEDEFS(OutputStream, GOutputStream);
|
||||
MOO_GOBJ_TYPEDEFS(FileOutputStream, GFileOutputStream);
|
||||
MOO_GOBJ_TYPEDEFS(InputStream, GInputStream);
|
||||
MOO_GOBJ_TYPEDEFS(FileInputStream, GFileInputStream);
|
||||
MOO_GOBJ_TYPEDEFS(IOStream, GIOStream);
|
||||
MOO_GOBJ_TYPEDEFS(FileIOStream, GFileIOStream);
|
||||
|
||||
} // namespace g
|
||||
|
||||
template<>
|
||||
class gobj_ref<GFile> : public virtual gobj_ref_parent<GFile>
|
||||
{
|
||||
public:
|
||||
MOO_DEFINE_GOBJREF_METHODS(GFile)
|
||||
|
||||
static g::FilePtr new_for_path (const char* path);
|
||||
static g::FilePtr new_for_uri (const char* uri);
|
||||
static g::FilePtr new_for_commandline_arg (const char* arg);
|
||||
static g::FilePtr parse_name (const char* parse_name);
|
||||
|
||||
g::FilePtr dup ();
|
||||
|
||||
bool equal (g::File file2);
|
||||
gstr get_basename ();
|
||||
gstr get_path ();
|
||||
gstr get_uri ();
|
||||
gstr get_parse_name ();
|
||||
g::FilePtr get_parent ();
|
||||
bool has_parent (g::File parent);
|
||||
g::FilePtr get_child (const char* name);
|
||||
g::FilePtr get_child_for_display_name (const char* display_name,
|
||||
gerrp& error);
|
||||
bool has_prefix (g::File prefix);
|
||||
gstr get_relative_path (g::File descendant);
|
||||
g::FilePtr resolve_relative_path (const char *relative_path);
|
||||
bool is_native ();
|
||||
bool has_uri_scheme (const char *uri_scheme);
|
||||
gstr get_uri_scheme ();
|
||||
g::FileInputStreamPtr read (GCancellable* cancellable,
|
||||
gerrp& error);
|
||||
g::FileOutputStreamPtr append_to (GFileCreateFlags flags,
|
||||
GCancellable* cancellable,
|
||||
gerrp& error);
|
||||
g::FileOutputStreamPtr create (GFileCreateFlags flags,
|
||||
GCancellable* cancellable,
|
||||
gerrp& error);
|
||||
g::FileOutputStreamPtr replace (const char *etag,
|
||||
gboolean make_backup,
|
||||
GFileCreateFlags flags,
|
||||
GCancellable* cancellable,
|
||||
gerrp& error);
|
||||
g::FileIOStreamPtr open_readwrite (GCancellable* cancellable,
|
||||
gerrp& error);
|
||||
g::FileIOStreamPtr create_readwrite (GFileCreateFlags flags,
|
||||
GCancellable* cancellable,
|
||||
gerrp& error);
|
||||
g::FileIOStreamPtr replace_readwrite (const char *etag,
|
||||
gboolean make_backup,
|
||||
GFileCreateFlags flags,
|
||||
GCancellable* cancellable,
|
||||
gerrp& error);
|
||||
bool query_exists (GCancellable* cancellable);
|
||||
GFileType query_file_type (GFileQueryInfoFlags flags,
|
||||
GCancellable* cancellable);
|
||||
g::FileInfoPtr query_info (const char *attributes,
|
||||
GFileQueryInfoFlags flags,
|
||||
GCancellable* cancellable,
|
||||
gerrp& error);
|
||||
g::FileInfoPtr query_filesystem_info (const char *attributes,
|
||||
GCancellable* cancellable,
|
||||
gerrp& error);
|
||||
GFileEnumerator* enumerate_children (const char *attributes,
|
||||
GFileQueryInfoFlags flags,
|
||||
GCancellable* cancellable,
|
||||
gerrp& error);
|
||||
g::FilePtr set_display_name (const char* display_name,
|
||||
GCancellable* cancellable,
|
||||
gerrp& error);
|
||||
bool delete_ (GCancellable* cancellable,
|
||||
gerrp& error);
|
||||
bool trash (GCancellable* cancellable,
|
||||
gerrp& error);
|
||||
bool copy (g::File destination,
|
||||
GFileCopyFlags flags,
|
||||
GCancellable* cancellable,
|
||||
GFileProgressCallback progress_callback,
|
||||
gpointer progress_callback_data,
|
||||
gerrp& error);
|
||||
bool move (g::File destination,
|
||||
GFileCopyFlags flags,
|
||||
GCancellable* cancellable,
|
||||
GFileProgressCallback progress_callback,
|
||||
gpointer progress_callback_data,
|
||||
gerrp& error);
|
||||
bool make_directory (GCancellable* cancellable,
|
||||
gerrp& error);
|
||||
bool make_directory_with_parents (GCancellable* cancellable,
|
||||
gerrp& error);
|
||||
bool make_symbolic_link (const char *symlink_value,
|
||||
GCancellable* cancellable,
|
||||
gerrp& error);
|
||||
|
||||
bool load_contents (GCancellable* cancellable,
|
||||
char** contents,
|
||||
gsize* length,
|
||||
char** etag_out,
|
||||
gerrp& error);
|
||||
bool replace_contents (const char* contents,
|
||||
gsize length,
|
||||
const char* etag,
|
||||
gboolean make_backup,
|
||||
GFileCreateFlags flags,
|
||||
char** new_etag,
|
||||
GCancellable* cancellable,
|
||||
gerrp& error);
|
||||
};
|
||||
|
||||
|
||||
template<>
|
||||
class gobj_ref<GOutputStream> : public virtual gobj_ref_parent<GOutputStream>
|
||||
{
|
||||
public:
|
||||
MOO_DEFINE_GOBJREF_METHODS(GOutputStream)
|
||||
|
||||
gssize write (const void *buffer,
|
||||
gsize count,
|
||||
GCancellable *cancellable,
|
||||
gerrp& error);
|
||||
bool write_all (const void *buffer,
|
||||
gsize count,
|
||||
gsize *bytes_written,
|
||||
GCancellable *cancellable,
|
||||
gerrp& error);
|
||||
gssize splice (g::InputStream source,
|
||||
GOutputStreamSpliceFlags flags,
|
||||
GCancellable *cancellable,
|
||||
gerrp& error);
|
||||
bool flush (GCancellable *cancellable,
|
||||
gerrp& error);
|
||||
bool close (GCancellable *cancellable,
|
||||
gerrp& error);
|
||||
void write_async (const void *buffer,
|
||||
gsize count,
|
||||
int io_priority,
|
||||
GCancellable *cancellable,
|
||||
GAsyncReadyCallback callback,
|
||||
gpointer user_data);
|
||||
gssize write_finish (GAsyncResult *result,
|
||||
gerrp& error);
|
||||
void splice_async (g::InputStream source,
|
||||
GOutputStreamSpliceFlags flags,
|
||||
int io_priority,
|
||||
GCancellable *cancellable,
|
||||
GAsyncReadyCallback callback,
|
||||
gpointer user_data);
|
||||
gssize splice_finish (GAsyncResult *result,
|
||||
gerrp& error);
|
||||
void flush_async (int io_priority,
|
||||
GCancellable *cancellable,
|
||||
GAsyncReadyCallback callback,
|
||||
gpointer user_data);
|
||||
bool flush_finish (GAsyncResult *result,
|
||||
gerrp& error);
|
||||
void close_async (int io_priority,
|
||||
GCancellable *cancellable,
|
||||
GAsyncReadyCallback callback,
|
||||
gpointer user_data);
|
||||
bool close_finish (GAsyncResult *result,
|
||||
gerrp& error);
|
||||
|
||||
bool is_closed ();
|
||||
bool is_closing ();
|
||||
bool has_pending ();
|
||||
bool set_pending (gerrp& error);
|
||||
void clear_pending ();
|
||||
};
|
||||
|
||||
|
||||
} // namespace moo
|
||||
|
||||
#endif // __cplusplus
|
|
@ -1,194 +0,0 @@
|
|||
/*
|
||||
* moocpp/gobjtypes-glib.cpp
|
||||
*
|
||||
* Copyright (C) 2004-2016 by Yevgen Muntyan <emuntyan@users.sourceforge.net>
|
||||
*
|
||||
* This file is part of medit. medit 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.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public
|
||||
* License along with medit. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#include "moocpp/moocpp.h"
|
||||
|
||||
using namespace moo;
|
||||
using namespace g;
|
||||
|
||||
void extern_g_free(gpointer p)
|
||||
{
|
||||
g_free(p);
|
||||
}
|
||||
|
||||
void extern_g_object_unref(gpointer o)
|
||||
{
|
||||
g_object_unref(o);
|
||||
}
|
||||
|
||||
void extern_g_strfreev(char** p)
|
||||
{
|
||||
if (p)
|
||||
g_strfreev (p);
|
||||
}
|
||||
|
||||
|
||||
void moo::init_gobj_system ()
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
GQuark gobj_wrapper_base::qdata_key = g_quark_from_static_string ("__moo_gobj_wrapper__");
|
||||
|
||||
gobj_wrapper_base& gobj_wrapper_base::get(Object g)
|
||||
{
|
||||
void* o = g.get_data(qdata_key);
|
||||
g_assert(o != nullptr);
|
||||
return *reinterpret_cast<gobj_wrapper_base*>(o);
|
||||
}
|
||||
|
||||
gobj_wrapper_base::gobj_wrapper_base(gobj_ref<GObject> g)
|
||||
{
|
||||
g.set_data(qdata_key, this, free_qdata);
|
||||
}
|
||||
|
||||
gobj_wrapper_base::~gobj_wrapper_base()
|
||||
{
|
||||
}
|
||||
|
||||
void gobj_wrapper_base::free_qdata(gpointer d)
|
||||
{
|
||||
gobj_wrapper_base* self = reinterpret_cast<gobj_wrapper_base*>(d);
|
||||
delete self;
|
||||
}
|
||||
|
||||
|
||||
gulong Object::connect(const char *detailed_signal, GCallback c_handler, void *data)
|
||||
{
|
||||
return g_signal_connect(gobj(), detailed_signal, c_handler, data);
|
||||
}
|
||||
|
||||
gulong Object::connect_swapped(const char *detailed_signal, GCallback c_handler, void *data)
|
||||
{
|
||||
return g_signal_connect_swapped(gobj(), detailed_signal, c_handler, data);
|
||||
}
|
||||
|
||||
void Object::signal_emit_by_name(const char* detailed_signal, ...)
|
||||
{
|
||||
guint signal_id;
|
||||
GQuark detail;
|
||||
g_return_if_fail(g_signal_parse_name(detailed_signal,
|
||||
G_OBJECT_TYPE(gobj()),
|
||||
&signal_id, &detail,
|
||||
true));
|
||||
|
||||
va_list args;
|
||||
va_start(args, detailed_signal);
|
||||
g_signal_emit_valist(gobj(), signal_id, detail, args);
|
||||
va_end(args);
|
||||
}
|
||||
|
||||
void Object::signal_emit(guint signal_id, GQuark detail, ...)
|
||||
{
|
||||
va_list args;
|
||||
va_start(args, detail);
|
||||
g_signal_emit_valist(gobj(), signal_id, detail, args);
|
||||
va_end(args);
|
||||
}
|
||||
|
||||
bool Object::signal_has_handler_pending(guint signal_id, GQuark detail, bool may_be_blocked)
|
||||
{
|
||||
return g_signal_has_handler_pending(gobj(), signal_id, detail, may_be_blocked);
|
||||
}
|
||||
|
||||
gulong Object::signal_connect_closure_by_id(guint signal_id, GQuark detail, GClosure* closure, bool after)
|
||||
{
|
||||
return g_signal_connect_closure_by_id(gobj(), signal_id, detail, closure, after);
|
||||
}
|
||||
|
||||
gulong Object::signal_connect_closure(const char* detailed_signal, GClosure* closure, bool after)
|
||||
{
|
||||
return g_signal_connect_closure(gobj(), detailed_signal, closure, after);
|
||||
}
|
||||
|
||||
gulong Object::signal_connect_data(const char* detailed_signal, GCallback c_handler, gpointer data, GClosureNotify destroy_data, GConnectFlags connect_flags)
|
||||
{
|
||||
return g_signal_connect_data(gobj(), detailed_signal, c_handler, data, destroy_data, connect_flags);
|
||||
}
|
||||
|
||||
void Object::signal_handler_block(gulong handler_id)
|
||||
{
|
||||
g_signal_handler_block(gobj(), handler_id);
|
||||
}
|
||||
|
||||
void Object::signal_handler_unblock(gulong handler_id)
|
||||
{
|
||||
g_signal_handler_unblock(gobj(), handler_id);
|
||||
}
|
||||
|
||||
void Object::signal_handler_disconnect(gulong handler_id)
|
||||
{
|
||||
g_signal_handler_disconnect(gobj(), handler_id);
|
||||
}
|
||||
|
||||
gulong Object::signal_handler_find(GSignalMatchType mask, guint signal_id, GQuark detail, GClosure* closure, gpointer func, gpointer data)
|
||||
{
|
||||
return g_signal_handler_find(gobj(), mask, signal_id, detail, closure, func, data);
|
||||
}
|
||||
|
||||
guint Object::signal_handlers_block_matched(GSignalMatchType mask, guint signal_id, GQuark detail, GClosure* closure, gpointer func, gpointer data)
|
||||
{
|
||||
return g_signal_handlers_block_matched(gobj(), mask, signal_id, detail, closure, func, data);
|
||||
}
|
||||
|
||||
guint Object::signal_handlers_unblock_matched(GSignalMatchType mask, guint signal_id, GQuark detail, GClosure* closure, gpointer func, gpointer data)
|
||||
{
|
||||
return g_signal_handlers_unblock_matched(gobj(), mask, signal_id, detail, closure, func, data);
|
||||
}
|
||||
|
||||
guint Object::signal_handlers_disconnect_matched(GSignalMatchType mask, guint signal_id, GQuark detail, GClosure* closure, gpointer func, gpointer data)
|
||||
{
|
||||
return g_signal_handlers_disconnect_matched(gobj(), mask, signal_id, detail, closure, func, data);
|
||||
}
|
||||
|
||||
void Object::set_data(const char* key, gpointer value, GDestroyNotify destroy)
|
||||
{
|
||||
g_object_set_data_full(gobj(), key, value, destroy);
|
||||
}
|
||||
|
||||
void Object::set_data(GQuark q, gpointer data, GDestroyNotify destroy)
|
||||
{
|
||||
g_object_set_qdata_full(gobj(), q, data, destroy);
|
||||
}
|
||||
|
||||
void* Object::get_data(const char* key)
|
||||
{
|
||||
return g_object_get_data(gobj(), key);
|
||||
}
|
||||
|
||||
void* Object::get_data(GQuark q)
|
||||
{
|
||||
return g_object_get_qdata(gobj(), q);
|
||||
}
|
||||
|
||||
void Object::set_property(const gchar *property_name, const GValue *value)
|
||||
{
|
||||
g_object_set_property(gobj(), property_name, value);
|
||||
}
|
||||
|
||||
void Object::notify(const char* property_name)
|
||||
{
|
||||
g_object_notify(gobj(), property_name);
|
||||
}
|
||||
|
||||
void Object::freeze_notify()
|
||||
{
|
||||
g_object_freeze_notify(gobj());
|
||||
}
|
||||
|
||||
void Object::thaw_notify()
|
||||
{
|
||||
g_object_thaw_notify(gobj());
|
||||
}
|
|
@ -1,134 +0,0 @@
|
|||
/*
|
||||
* moocpp/gobjtypes-glib.h
|
||||
*
|
||||
* Copyright (C) 2004-2016 by Yevgen Muntyan <emuntyan@users.sourceforge.net>
|
||||
*
|
||||
* This file is part of medit. medit 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.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public
|
||||
* License along with medit. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <glib-object.h>
|
||||
#include <mooglib/moo-glib.h>
|
||||
|
||||
#ifdef __cplusplus
|
||||
|
||||
#include "moocpp/gobjptr.h"
|
||||
#include "moocpp/gobjectutils.h"
|
||||
|
||||
#include <stdarg.h>
|
||||
|
||||
#define MOO_GOBJ_TYPEDEFS(CppObject, CObject) \
|
||||
using CppObject = ::moo::gobj_ref<CObject>; \
|
||||
using CppObject##Ptr = ::moo::gobj_ptr<CObject>; \
|
||||
using CppObject##RawPtr = ::moo::gobj_raw_ptr<CObject>; \
|
||||
|
||||
#define MOO_GIFACE_TYPEDEFS(CppObject, CObject) \
|
||||
MOO_GOBJ_TYPEDEFS(CppObject, CObject)
|
||||
|
||||
#define MOO_DECLARE_CUSTOM_GOBJ_TYPE(CObject) \
|
||||
namespace moo { \
|
||||
template<> class gobj_ref<CObject>; \
|
||||
}
|
||||
|
||||
MOO_DEFINE_FLAGS(GSignalFlags);
|
||||
MOO_DEFINE_FLAGS(GConnectFlags);
|
||||
MOO_DEFINE_FLAGS(GSpawnFlags);
|
||||
MOO_DEFINE_FLAGS(GLogLevelFlags);
|
||||
MOO_DEFINE_FLAGS(GRegexCompileFlags);
|
||||
MOO_DEFINE_FLAGS(GIOCondition);
|
||||
|
||||
namespace moo {
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////////////////////
|
||||
//
|
||||
// GObject
|
||||
//
|
||||
|
||||
template<>
|
||||
class gobj_ref<GObject> : public gobj_ref_base
|
||||
{
|
||||
public:
|
||||
MOO_DEFINE_GOBJREF_METHODS_IMPL(GObject, gobj_ref_base)
|
||||
|
||||
gulong connect (const char* detailed_signal, GCallback c_handler, void* data);
|
||||
gulong connect_swapped (const char* detailed_signal, GCallback c_handler, void* data);
|
||||
|
||||
void signal_emit_by_name (const char* detailed_signal, ...);
|
||||
void signal_emit (guint signal_id, GQuark detail, ...);
|
||||
|
||||
bool signal_has_handler_pending (guint signal_id, GQuark detail, bool may_be_blocked);
|
||||
gulong signal_connect_closure_by_id (guint signal_id, GQuark detail, GClosure* closure, bool after);
|
||||
gulong signal_connect_closure (const char* detailed_signal, GClosure* closure, bool after);
|
||||
gulong signal_connect_data (const char* detailed_signal, GCallback c_handler, gpointer data, GClosureNotify destroy_data, GConnectFlags connect_flags);
|
||||
void signal_handler_block (gulong handler_id);
|
||||
void signal_handler_unblock (gulong handler_id);
|
||||
void signal_handler_disconnect (gulong handler_id);
|
||||
bool signal_handler_is_connected (gulong handler_id);
|
||||
gulong signal_handler_find (GSignalMatchType mask, guint signal_id, GQuark detail, GClosure* closure, gpointer func, gpointer data);
|
||||
guint signal_handlers_block_matched (GSignalMatchType mask, guint signal_id, GQuark detail, GClosure* closure, gpointer func, gpointer data);
|
||||
guint signal_handlers_unblock_matched (GSignalMatchType mask, guint signal_id, GQuark detail, GClosure* closure, gpointer func, gpointer data);
|
||||
guint signal_handlers_disconnect_matched (GSignalMatchType mask, guint signal_id, GQuark detail, GClosure* closure, gpointer func, gpointer data);
|
||||
guint signal_handlers_disconnect_by_func (GCallback c_handler, void* data);
|
||||
|
||||
void* get_data (const char* key);
|
||||
void* get_data (GQuark q);
|
||||
void set_data (const char* key, gpointer value, GDestroyNotify destroy = nullptr);
|
||||
void set_data (GQuark q, gpointer value, GDestroyNotify destroy = nullptr);
|
||||
|
||||
void set_property (const char* property_name, const GValue* value);
|
||||
|
||||
template<typename T>
|
||||
void set (const char* prop, const T& value)
|
||||
{
|
||||
g_object_set (gobj (), prop, cpp_vararg_value_fixer<T>::apply (value), nullptr);
|
||||
}
|
||||
|
||||
template<typename T, typename... Args>
|
||||
void set (const char* prop, const T& value, Args&&... args)
|
||||
{
|
||||
set (prop, value);
|
||||
set (std::forward<Args> (args)...);
|
||||
}
|
||||
|
||||
void get (const char* prop, bool& dest)
|
||||
{
|
||||
gboolean val;
|
||||
g_object_get (gobj (), prop, &val, nullptr);
|
||||
dest = val;
|
||||
}
|
||||
|
||||
template<typename T>
|
||||
void get (const char* prop, T&& dest)
|
||||
{
|
||||
g_object_get (gobj (), prop, cpp_vararg_dest_fixer<T>::apply (std::forward<T> (dest)), nullptr);
|
||||
}
|
||||
|
||||
template<typename T, typename... Args>
|
||||
void get (const char* prop, T&& dest, Args&&... args)
|
||||
{
|
||||
get (prop, std::forward<T> (dest));
|
||||
get (std::forward<Args> (args)...);
|
||||
}
|
||||
|
||||
void notify (const char* property_name);
|
||||
void freeze_notify ();
|
||||
void thaw_notify ();
|
||||
};
|
||||
|
||||
namespace g {
|
||||
|
||||
MOO_GOBJ_TYPEDEFS(Object, GObject);
|
||||
|
||||
} // namespace g
|
||||
|
||||
} // namespace moo
|
||||
|
||||
#endif // __cplusplus
|
File diff suppressed because it is too large
Load Diff
|
@ -1,653 +0,0 @@
|
|||
/*
|
||||
* moocpp/gobjtypes-gtk.h
|
||||
*
|
||||
* Copyright (C) 2004-2016 by Yevgen Muntyan <emuntyan@users.sourceforge.net>
|
||||
*
|
||||
* This file is part of medit. medit 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.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public
|
||||
* License along with medit. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <gtk/gtk.h>
|
||||
#include <mooglib/moo-glib.h>
|
||||
|
||||
#ifdef __cplusplus
|
||||
|
||||
#include "moocpp/gobjtypes-glib.h"
|
||||
#include <initializer_list>
|
||||
#include <functional>
|
||||
|
||||
#define MOO_DEFINE_GTK_TYPE(Object, Parent, obj_g_type) \
|
||||
MOO_DEFINE_GOBJ_TYPE(Gtk##Object, Parent, obj_g_type) \
|
||||
namespace moo { \
|
||||
namespace gtk { \
|
||||
MOO_GOBJ_TYPEDEFS(Object, Gtk##Object) \
|
||||
} \
|
||||
}
|
||||
|
||||
#define MOO_DEFINE_GTK_IFACE(Iface, iface_g_type) \
|
||||
MOO_DEFINE_GIFACE_TYPE(Gtk##Iface, iface_g_type) \
|
||||
namespace moo { \
|
||||
namespace gtk { \
|
||||
MOO_GIFACE_TYPEDEFS(Iface, Gtk##Iface) \
|
||||
} \
|
||||
}
|
||||
|
||||
|
||||
MOO_DECLARE_CUSTOM_GOBJ_TYPE (GtkObject)
|
||||
MOO_DECLARE_CUSTOM_GOBJ_TYPE (GtkWidget)
|
||||
MOO_DECLARE_CUSTOM_GOBJ_TYPE (GtkTextView)
|
||||
MOO_DECLARE_CUSTOM_GOBJ_TYPE (GtkTreeModel)
|
||||
MOO_DECLARE_CUSTOM_GOBJ_TYPE (GtkTreeStore)
|
||||
MOO_DECLARE_CUSTOM_GOBJ_TYPE (GtkListStore)
|
||||
MOO_DECLARE_CUSTOM_GOBJ_TYPE (GtkTreeView)
|
||||
MOO_DECLARE_CUSTOM_GOBJ_TYPE (GtkTreeViewColumn)
|
||||
MOO_DECLARE_CUSTOM_GOBJ_TYPE (GtkCellRenderer)
|
||||
MOO_DECLARE_CUSTOM_GOBJ_TYPE (GtkCellRendererText)
|
||||
MOO_DECLARE_CUSTOM_GOBJ_TYPE (GtkCellRendererToggle)
|
||||
MOO_DECLARE_CUSTOM_GOBJ_TYPE (GtkCellRendererPixbuf)
|
||||
|
||||
|
||||
MOO_DEFINE_GTK_TYPE (Object, GObject, GTK_TYPE_OBJECT)
|
||||
MOO_DEFINE_GTK_TYPE (Widget, GtkObject, GTK_TYPE_WIDGET)
|
||||
|
||||
template<>
|
||||
class moo::gobj_ref<GtkObject> : public virtual moo::gobj_ref_parent<GtkObject>
|
||||
{
|
||||
public:
|
||||
MOO_DEFINE_GOBJREF_METHODS (GtkObject);
|
||||
|
||||
void destroy ();
|
||||
};
|
||||
|
||||
template<>
|
||||
class moo::gobj_ref<GtkWidget> : public virtual moo::gobj_ref_parent<GtkWidget>
|
||||
{
|
||||
public:
|
||||
MOO_DEFINE_GOBJREF_METHODS (GtkWidget);
|
||||
};
|
||||
|
||||
|
||||
MOO_DEFINE_GTK_TYPE(Entry, GtkWidget, GTK_TYPE_ENTRY)
|
||||
MOO_DEFINE_GTK_TYPE(Action, GObject, GTK_TYPE_ACTION)
|
||||
MOO_DEFINE_GTK_TYPE(TextBuffer, GObject, GTK_TYPE_TEXT_BUFFER)
|
||||
MOO_DEFINE_GTK_TYPE(TextMark, GObject, GTK_TYPE_TEXT_MARK)
|
||||
MOO_DEFINE_GTK_TYPE(MenuShell, GtkWidget, GTK_TYPE_MENU_SHELL)
|
||||
MOO_DEFINE_GTK_TYPE(Menu, GtkMenuShell, GTK_TYPE_MENU)
|
||||
|
||||
|
||||
MOO_DEFINE_GTK_TYPE (TextView, GtkWidget, GTK_TYPE_TEXT_VIEW)
|
||||
|
||||
template<>
|
||||
class moo::gobj_ref<GtkTextView> : public virtual moo::gobj_ref_parent<GtkTextView>
|
||||
{
|
||||
public:
|
||||
MOO_DEFINE_GOBJREF_METHODS(GtkTextView);
|
||||
|
||||
gtk::TextBuffer get_buffer ();
|
||||
};
|
||||
|
||||
|
||||
MOO_DEFINE_GTK_IFACE (TreeModel, GTK_TYPE_TREE_MODEL)
|
||||
|
||||
template<>
|
||||
class moo::gobj_ref<GtkTreeModel> : public virtual moo::gobj_ref_parent<GtkTreeModel>
|
||||
{
|
||||
public:
|
||||
MOO_DEFINE_GOBJREF_METHODS (GtkTreeModel);
|
||||
|
||||
GtkTreeModelFlags get_flags ();
|
||||
int get_n_columns ();
|
||||
GType get_column_type (int index_);
|
||||
|
||||
bool get_iter (GtkTreeIter& iter, const GtkTreePath& path);
|
||||
bool get_iter_from_string (GtkTreeIter& iter, const char* path_string);
|
||||
gstr get_string_from_iter (const GtkTreeIter& iter);
|
||||
bool get_iter_first (GtkTreeIter& iter);
|
||||
GtkTreePath* get_path (const GtkTreeIter& iter);
|
||||
void get_value (const GtkTreeIter& iter, int column, GValue* value);
|
||||
bool iter_next (GtkTreeIter& iter);
|
||||
bool iter_children (GtkTreeIter& iter, const GtkTreeIter& parent);
|
||||
bool iter_has_child (const GtkTreeIter& iter);
|
||||
int iter_n_children (const GtkTreeIter& iter);
|
||||
bool iter_nth_child (GtkTreeIter& iter, const GtkTreeIter& parent, int n);
|
||||
bool iter_parent (GtkTreeIter& iter, const GtkTreeIter& child);
|
||||
|
||||
void get (const GtkTreeIter& iter, int column, bool& dest)
|
||||
{
|
||||
gboolean val;
|
||||
gtk_tree_model_get (gobj (), const_cast<GtkTreeIter*>(&iter), column, &val, -1);
|
||||
dest = val;
|
||||
}
|
||||
|
||||
template<typename T>
|
||||
void get (const GtkTreeIter& iter, int column, T&& dest)
|
||||
{
|
||||
gtk_tree_model_get (gobj (), const_cast<GtkTreeIter*>(&iter), column, cpp_vararg_dest_fixer<T>::apply (std::forward<T> (dest)), -1);
|
||||
}
|
||||
|
||||
template<typename T, typename... Args>
|
||||
void get (const GtkTreeIter& iter, int column, T&& dest, Args&&... args)
|
||||
{
|
||||
get (iter, column, std::forward<T> (dest));
|
||||
get (iter, std::forward<Args> (args)...);
|
||||
}
|
||||
|
||||
// bool TFunc (const GtkTreePath&, const GtkTreeIter&)
|
||||
template<typename TFunc>
|
||||
void foreach (const TFunc& func)
|
||||
{
|
||||
const void* p = &func;
|
||||
gtk_tree_model_foreach (gobj (), foreach_func<TFunc>, const_cast<void*>(p));
|
||||
}
|
||||
|
||||
private:
|
||||
template<typename TFunc>
|
||||
static gboolean foreach_func (GtkTreeModel *model, GtkTreePath *path, GtkTreeIter *iter, gpointer data)
|
||||
{
|
||||
const TFunc& func = *reinterpret_cast<const TFunc*>(data);
|
||||
return func (const_cast<const GtkTreePath&>(*path), const_cast<const GtkTreeIter&>(*iter));
|
||||
}
|
||||
};
|
||||
|
||||
MOO_DEFINE_GTK_TYPE (ListStore, GObject, GTK_TYPE_LIST_STORE)
|
||||
MOO_GOBJ_IMPLEMENTS_IFACE (GtkListStore, GtkTreeModel)
|
||||
|
||||
template<>
|
||||
class moo::gobj_ref<GtkListStore>
|
||||
: public virtual moo::gobj_ref_parent<GtkListStore>
|
||||
, public virtual moo::gobj_ref<GtkTreeModel>
|
||||
{
|
||||
public:
|
||||
MOO_DEFINE_GOBJREF_METHODS(GtkListStore);
|
||||
|
||||
static gtk::ListStorePtr create (std::initializer_list<GType> types)
|
||||
{
|
||||
return create (types.size (), types.begin ());
|
||||
}
|
||||
|
||||
static gtk::ListStorePtr create (size_t n_columns, std::initializer_list<GType> types)
|
||||
{
|
||||
g_return_val_if_fail (n_columns == types.size (), nullptr);
|
||||
return create (n_columns, types.begin ());
|
||||
}
|
||||
|
||||
static gtk::ListStorePtr create (size_t n_columns, const GType* types);
|
||||
|
||||
template<typename T>
|
||||
void set (const GtkTreeIter& iter, int column, T&& value)
|
||||
{
|
||||
gtk_list_store_set (gobj (), const_cast<GtkTreeIter*>(&iter), column, cpp_vararg_value_fixer<T>::apply (std::forward<T&&> (value)), -1);
|
||||
}
|
||||
|
||||
template<typename T, typename... Args>
|
||||
void set (const GtkTreeIter& iter, int column, T&& value, Args&&... args)
|
||||
{
|
||||
set (iter, column, std::forward<T> (value));
|
||||
set (iter, std::forward<Args> (args)...);
|
||||
}
|
||||
|
||||
void set_value (const GtkTreeIter& iter,
|
||||
int column,
|
||||
GValue* value);
|
||||
void set_valuesv (const GtkTreeIter& iter,
|
||||
int* columns,
|
||||
GValue* values,
|
||||
int n_values);
|
||||
bool remove (GtkTreeIter& iter);
|
||||
void insert (GtkTreeIter& iter,
|
||||
int position);
|
||||
void insert_before (GtkTreeIter& iter,
|
||||
GtkTreeIter& sibling);
|
||||
void insert_after (GtkTreeIter& iter,
|
||||
GtkTreeIter& sibling);
|
||||
//void insert_with_values (GtkTreeIter* iter,
|
||||
// int position,
|
||||
// ...);
|
||||
//void insert_with_values (GtkTreeIter* iter,
|
||||
// int position,
|
||||
// int* columns,
|
||||
// GValue* values,
|
||||
// int n_values);
|
||||
void prepend (GtkTreeIter& iter);
|
||||
void append (GtkTreeIter& iter);
|
||||
void clear ();
|
||||
bool iter_is_valid (const GtkTreeIter& iter);
|
||||
void reorder (int* new_order);
|
||||
void swap (GtkTreeIter& a,
|
||||
GtkTreeIter& b);
|
||||
void move_after (GtkTreeIter& iter,
|
||||
GtkTreeIter& position);
|
||||
void move_before (GtkTreeIter& iter,
|
||||
GtkTreeIter& position);
|
||||
};
|
||||
|
||||
MOO_DEFINE_GTK_TYPE (TreeStore, GObject, GTK_TYPE_TREE_STORE)
|
||||
MOO_GOBJ_IMPLEMENTS_IFACE (GtkTreeStore, GtkTreeModel)
|
||||
|
||||
template<>
|
||||
class moo::gobj_ref<GtkTreeStore>
|
||||
: public virtual moo::gobj_ref_parent<GtkTreeStore>
|
||||
, public virtual moo::gobj_ref<GtkTreeModel>
|
||||
{
|
||||
public:
|
||||
MOO_DEFINE_GOBJREF_METHODS (GtkTreeStore);
|
||||
};
|
||||
|
||||
MOO_DEFINE_GTK_TYPE (TreeView, GtkContainer, GTK_TYPE_TREE_VIEW)
|
||||
MOO_DEFINE_GTK_TYPE (TreeViewColumn, GtkObject, GTK_TYPE_TREE_VIEW_COLUMN)
|
||||
MOO_DEFINE_GTK_TYPE (CellRenderer, GtkObject, GTK_TYPE_CELL_RENDERER)
|
||||
MOO_DEFINE_GTK_TYPE (CellRendererText, GtkCellRenderer, GTK_TYPE_CELL_RENDERER_TEXT)
|
||||
MOO_DEFINE_GTK_TYPE (CellRendererPixbuf, GtkCellRenderer, GTK_TYPE_CELL_RENDERER_PIXBUF)
|
||||
MOO_DEFINE_GTK_TYPE (CellRendererToggle, GtkCellRenderer, GTK_TYPE_CELL_RENDERER_TOGGLE)
|
||||
|
||||
|
||||
template<typename TFunc>
|
||||
class TreeCellDataFunc
|
||||
{
|
||||
public:
|
||||
TreeCellDataFunc (TFunc func) : m_func (std::move (func)) {}
|
||||
~TreeCellDataFunc () {}
|
||||
|
||||
MOO_DISABLE_COPY_OPS (TreeCellDataFunc);
|
||||
|
||||
static void destroy (gpointer d) { delete reinterpret_cast<TreeCellDataFunc*>(d); }
|
||||
|
||||
static void cell_data_func (GtkTreeViewColumn *tree_column,
|
||||
GtkCellRenderer *cell,
|
||||
GtkTreeModel *tree_model,
|
||||
GtkTreeIter *iter,
|
||||
gpointer p);
|
||||
|
||||
private:
|
||||
TFunc m_func;
|
||||
};
|
||||
|
||||
|
||||
template<>
|
||||
class moo::gobj_ref<GtkTreeView> : public virtual moo::gobj_ref_parent<GtkTreeView>
|
||||
{
|
||||
public:
|
||||
MOO_DEFINE_GOBJREF_METHODS (GtkTreeView);
|
||||
|
||||
static gtk::TreeViewPtr create (gtk::TreeModelPtr model);
|
||||
|
||||
gtk::TreeModelPtr get_model ();
|
||||
void set_model (gtk::TreeModelPtr model);
|
||||
GtkTreeSelection* get_selection ();
|
||||
GtkAdjustment* get_hadjustment ();
|
||||
void set_hadjustment (GtkAdjustment* adjustment);
|
||||
GtkAdjustment* get_vadjustment ();
|
||||
void set_vadjustment (GtkAdjustment* adjustment);
|
||||
bool get_headers_visible ();
|
||||
void set_headers_visible (bool headers_visible);
|
||||
void columns_autosize ();
|
||||
bool get_headers_clickable ();
|
||||
void set_headers_clickable (bool setting);
|
||||
void set_rules_hint (bool setting);
|
||||
bool get_rules_hint ();
|
||||
|
||||
/* Column funtions */
|
||||
int append_column (gtk::TreeViewColumn& column);
|
||||
int remove_column (gtk::TreeViewColumn& column);
|
||||
int insert_column (gtk::TreeViewColumn& column,
|
||||
int position);
|
||||
int insert_column_with_attributes (int position,
|
||||
const char* title,
|
||||
gtk::CellRenderer& cell,
|
||||
...) G_GNUC_NULL_TERMINATED;
|
||||
|
||||
template<typename TFunc>
|
||||
int insert_column_with_data_func (int position,
|
||||
const char* title,
|
||||
gtk::CellRenderer& cell,
|
||||
TFunc func);
|
||||
|
||||
gtk::TreeViewColumnPtr get_column (int n);
|
||||
std::vector<gtk::TreeViewColumnPtr> get_columns ();
|
||||
void move_column_after (gtk::TreeViewColumn& column,
|
||||
gtk::TreeViewColumn& base_column);
|
||||
void set_expander_column (gtk::TreeViewColumn& column);
|
||||
gtk::TreeViewColumnPtr get_expander_column ();
|
||||
void set_column_drag_function (GtkTreeViewColumnDropFunc func,
|
||||
gpointer user_data,
|
||||
GDestroyNotify destroy);
|
||||
|
||||
/* Actions */
|
||||
void scroll_to_point (int tree_x,
|
||||
int tree_y);
|
||||
void scroll_to_cell (GtkTreePath* path,
|
||||
gtk::TreeViewColumn& column,
|
||||
bool use_align,
|
||||
float row_align,
|
||||
float col_align);
|
||||
void row_activated (GtkTreePath* path,
|
||||
gtk::TreeViewColumn& column);
|
||||
void expand_all ();
|
||||
void collapse_all ();
|
||||
void expand_to_path (GtkTreePath* path);
|
||||
bool expand_row (GtkTreePath* path,
|
||||
bool open_all);
|
||||
bool collapse_row (GtkTreePath* path);
|
||||
void map_expanded_rows (GtkTreeViewMappingFunc func,
|
||||
gpointer data);
|
||||
bool row_expanded (GtkTreePath* path);
|
||||
void set_reorderable (bool reorderable);
|
||||
bool get_reorderable ();
|
||||
void set_cursor (GtkTreePath* path,
|
||||
gtk::TreeViewColumn& focus_column,
|
||||
bool start_editing);
|
||||
void set_cursor_on_cell (GtkTreePath* path,
|
||||
gtk::TreeViewColumn& focus_column,
|
||||
gtk::CellRenderer& focus_cell,
|
||||
bool start_editing);
|
||||
void get_cursor (GtkTreePath** path,
|
||||
gtk::TreeViewColumnPtr& focus_column);
|
||||
|
||||
/* Layout information */
|
||||
GdkWindow* get_bin_window ();
|
||||
bool get_path_at_pos (int x,
|
||||
int y,
|
||||
GtkTreePath** path,
|
||||
gtk::TreeViewColumnPtr& column,
|
||||
int* cell_x,
|
||||
int* cell_y);
|
||||
void get_cell_area (GtkTreePath* path,
|
||||
gtk::TreeViewColumn& column,
|
||||
GdkRectangle& rect);
|
||||
void get_background_area (GtkTreePath* path,
|
||||
gtk::TreeViewColumn& column,
|
||||
GdkRectangle& rect);
|
||||
void get_visible_rect (GdkRectangle& visible_rect);
|
||||
|
||||
bool get_visible_range (GtkTreePath** start_path,
|
||||
GtkTreePath** end_path);
|
||||
|
||||
/* Drag-and-Drop support */
|
||||
void enable_model_drag_source (GdkModifierType start_button_mask,
|
||||
const GtkTargetEntry* targets,
|
||||
int n_targets,
|
||||
GdkDragAction actions);
|
||||
void enable_model_drag_dest (const GtkTargetEntry* targets,
|
||||
int n_targets,
|
||||
GdkDragAction actions);
|
||||
void unset_rows_drag_source ();
|
||||
void unset_rows_drag_dest ();
|
||||
|
||||
/* These are useful to implement your own custom stuff. */
|
||||
void set_drag_dest_row (GtkTreePath* path,
|
||||
GtkTreeViewDropPosition pos);
|
||||
void get_drag_dest_row (GtkTreePath** path,
|
||||
GtkTreeViewDropPosition* pos);
|
||||
bool get_dest_row_at_pos (int drag_x,
|
||||
int drag_y,
|
||||
GtkTreePath** path,
|
||||
GtkTreeViewDropPosition* pos);
|
||||
GdkPixmap* create_row_drag_icon (GtkTreePath* path);
|
||||
|
||||
/* Interactive search */
|
||||
void set_enable_search (bool enable_search);
|
||||
bool get_enable_search ();
|
||||
int get_search_column ();
|
||||
void set_search_column (int column);
|
||||
GtkTreeViewSearchEqualFunc get_search_equal_func ();
|
||||
void set_search_equal_func (GtkTreeViewSearchEqualFunc search_equal_func,
|
||||
gpointer search_user_data,
|
||||
GDestroyNotify search_destroy);
|
||||
|
||||
GtkEntry* get_search_entry ();
|
||||
void set_search_entry (GtkEntry* entry);
|
||||
GtkTreeViewSearchPositionFunc get_search_position_func ();
|
||||
void set_search_position_func (GtkTreeViewSearchPositionFunc func,
|
||||
gpointer data,
|
||||
GDestroyNotify destroy);
|
||||
|
||||
/* Convert between the different coordinate systems */
|
||||
void convert_widget_to_tree_coords (int wx,
|
||||
int wy,
|
||||
int* tx,
|
||||
int* ty);
|
||||
void convert_tree_to_widget_coords (int tx,
|
||||
int ty,
|
||||
int* wx,
|
||||
int* wy);
|
||||
void convert_widget_to_bin_window_coords (int wx,
|
||||
int wy,
|
||||
int* bx,
|
||||
int* by);
|
||||
void convert_bin_window_to_widget_coords (int bx,
|
||||
int by,
|
||||
int* wx,
|
||||
int* wy);
|
||||
void convert_tree_to_bin_window_coords (int tx,
|
||||
int ty,
|
||||
int* bx,
|
||||
int* by);
|
||||
void convert_bin_window_to_tree_coords (int bx,
|
||||
int by,
|
||||
int* tx,
|
||||
int* ty);
|
||||
|
||||
void set_fixed_height_mode (bool enable);
|
||||
bool get_fixed_height_mode ();
|
||||
void set_hover_selection (bool hover);
|
||||
bool get_hover_selection ();
|
||||
void set_hover_expand (bool expand);
|
||||
bool get_hover_expand ();
|
||||
void set_rubber_banding (bool enable);
|
||||
bool get_rubber_banding ();
|
||||
|
||||
bool is_rubber_banding_active ();
|
||||
|
||||
GtkTreeViewRowSeparatorFunc get_row_separator_func ();
|
||||
void set_row_separator_func (GtkTreeViewRowSeparatorFunc func,
|
||||
gpointer data,
|
||||
GDestroyNotify destroy);
|
||||
|
||||
GtkTreeViewGridLines get_grid_lines ();
|
||||
void set_grid_lines (GtkTreeViewGridLines grid_lines);
|
||||
bool get_enable_tree_lines ();
|
||||
void set_enable_tree_lines (bool enabled);
|
||||
void set_show_expanders (bool enabled);
|
||||
bool get_show_expanders ();
|
||||
void set_level_indentation (int indentation);
|
||||
int get_level_indentation ();
|
||||
|
||||
/* Convenience functions for setting tooltips */
|
||||
void set_tooltip_row (GtkTooltip* tooltip,
|
||||
GtkTreePath* path);
|
||||
void set_tooltip_cell (GtkTooltip* tooltip,
|
||||
GtkTreePath* path,
|
||||
gtk::TreeViewColumn& column,
|
||||
gtk::CellRenderer& cell);
|
||||
bool get_tooltip_context (int* x,
|
||||
int* y,
|
||||
bool keyboard_tip,
|
||||
GtkTreeModel** model,
|
||||
GtkTreePath** path,
|
||||
GtkTreeIter* iter);
|
||||
void set_tooltip_column (int column);
|
||||
int get_tooltip_column ();
|
||||
};
|
||||
|
||||
template<>
|
||||
class moo::gobj_ref<GtkTreeViewColumn> : public virtual moo::gobj_ref_parent<GtkTreeViewColumn>
|
||||
{
|
||||
public:
|
||||
MOO_DEFINE_GOBJREF_METHODS (GtkTreeViewColumn);
|
||||
|
||||
static gtk::TreeViewColumnPtr create ();
|
||||
static gtk::TreeViewColumnPtr create (const char* title,
|
||||
gtk::CellRendererPtr cell,
|
||||
...) G_GNUC_NULL_TERMINATED;
|
||||
|
||||
void pack_start (gtk::CellRenderer& cell,
|
||||
bool expand);
|
||||
void pack_end (gtk::CellRenderer& cell,
|
||||
bool expand);
|
||||
void clear ();
|
||||
std::vector<gtk::CellRendererPtr> get_cell_renderers ();
|
||||
void add_attribute (gtk::CellRenderer& cell,
|
||||
const char* attribute,
|
||||
int column);
|
||||
|
||||
void set_attributes (gtk::CellRenderer& cell_renderer, const char* prop, int column);
|
||||
|
||||
template<typename... Args>
|
||||
void set_attributes (gtk::CellRenderer& cell_renderer, const char* prop, int column, Args&&... args)
|
||||
{
|
||||
set_attributes (cell_renderer, prop, column);
|
||||
set_attributes (cell_renderer, std::forward<Args> (args)...);
|
||||
}
|
||||
|
||||
// void TFunc(gtk::TreeViewColumn, gtk::CellRenderer, gtk::TreeModel, const GtkTreeIter&)
|
||||
template<typename TFunc>
|
||||
inline void set_cell_data_func (gtk::CellRenderer& cell_renderer, TFunc func);
|
||||
|
||||
void clear_attributes (gtk::CellRenderer& cell_renderer);
|
||||
void set_spacing (int spacing);
|
||||
int get_spacing ();
|
||||
void set_visible (bool visible);
|
||||
bool get_visible ();
|
||||
void set_resizable (bool resizable);
|
||||
bool get_resizable ();
|
||||
void set_sizing (GtkTreeViewColumnSizing type);
|
||||
GtkTreeViewColumnSizing get_sizing ();
|
||||
int get_width ();
|
||||
int get_fixed_width ();
|
||||
void set_fixed_width (int fixed_width);
|
||||
void set_min_width (int min_width);
|
||||
int get_min_width ();
|
||||
void set_max_width (int max_width);
|
||||
int get_max_width ();
|
||||
void clicked ();
|
||||
|
||||
/* Options for manipulating the column headers
|
||||
*/
|
||||
void set_title (const char* title);
|
||||
gstr get_title ();
|
||||
void set_expand (bool expand);
|
||||
bool get_expand ();
|
||||
void set_clickable (bool clickable);
|
||||
bool get_clickable ();
|
||||
void set_widget (gtk::WidgetPtr widget);
|
||||
gtk::WidgetPtr get_widget ();
|
||||
void set_alignment (float xalign);
|
||||
float get_alignment ();
|
||||
void set_reorderable (bool reorderable);
|
||||
bool get_reorderable ();
|
||||
|
||||
/* You probably only want to use gtk_tree_view_column_set_sort_column_id. The
|
||||
* other sorting functions exist primarily to let others do their own custom sorting.
|
||||
*/
|
||||
void set_sort_column_id (int sort_column_id);
|
||||
int get_sort_column_id ();
|
||||
void set_sort_indicator (bool setting);
|
||||
bool get_sort_indicator ();
|
||||
void set_sort_order (GtkSortType order);
|
||||
GtkSortType get_sort_order ();
|
||||
|
||||
gtk::TreeViewPtr get_tree_view ();
|
||||
};
|
||||
|
||||
template<>
|
||||
class moo::gobj_ref<GtkCellRenderer> : public virtual moo::gobj_ref_parent<GtkCellRenderer>
|
||||
{
|
||||
public:
|
||||
MOO_DEFINE_GOBJREF_METHODS (GtkCellRenderer);
|
||||
};
|
||||
|
||||
template<>
|
||||
class moo::gobj_ref<GtkCellRendererText> : public virtual moo::gobj_ref_parent<GtkCellRendererText>
|
||||
{
|
||||
public:
|
||||
MOO_DEFINE_GOBJREF_METHODS (GtkCellRendererText);
|
||||
|
||||
static gtk::CellRendererTextPtr create ();
|
||||
|
||||
void set_fixed_height_from_font (int number_of_rows);
|
||||
};
|
||||
|
||||
template<>
|
||||
class moo::gobj_ref<GtkCellRendererToggle> : public virtual moo::gobj_ref_parent<GtkCellRendererToggle>
|
||||
{
|
||||
public:
|
||||
MOO_DEFINE_GOBJREF_METHODS (GtkCellRendererToggle);
|
||||
|
||||
static gtk::CellRendererTogglePtr create ();
|
||||
|
||||
bool get_radio ();
|
||||
void set_radio (bool radio);
|
||||
bool get_active ();
|
||||
void set_active (bool active);
|
||||
};
|
||||
|
||||
template<>
|
||||
class moo::gobj_ref<GtkCellRendererPixbuf> : public virtual moo::gobj_ref_parent<GtkCellRendererPixbuf>
|
||||
{
|
||||
public:
|
||||
MOO_DEFINE_GOBJREF_METHODS (GtkCellRendererPixbuf);
|
||||
|
||||
static gtk::CellRendererPixbufPtr create ();
|
||||
};
|
||||
|
||||
|
||||
template<typename TFunc>
|
||||
inline void
|
||||
TreeCellDataFunc<TFunc>::cell_data_func (GtkTreeViewColumn *tree_column,
|
||||
GtkCellRenderer *cell,
|
||||
GtkTreeModel *tree_model,
|
||||
GtkTreeIter *iter,
|
||||
gpointer p)
|
||||
{
|
||||
g_return_if_fail (GTK_IS_TREE_VIEW_COLUMN (tree_column));
|
||||
g_return_if_fail (GTK_IS_CELL_RENDERER (cell));
|
||||
g_return_if_fail (GTK_IS_TREE_MODEL (tree_model));
|
||||
g_return_if_fail (iter != nullptr);
|
||||
g_return_if_fail (p != nullptr);
|
||||
TreeCellDataFunc& data = *reinterpret_cast<TreeCellDataFunc*>(p);
|
||||
data.m_func (moo::wrap (*tree_column), moo::wrap (*cell), moo::wrap (*tree_model),
|
||||
const_cast<const GtkTreeIter&>(*iter));
|
||||
}
|
||||
|
||||
|
||||
template<typename TFunc>
|
||||
inline int
|
||||
moo::gobj_ref<GtkTreeView>::insert_column_with_data_func (int position,
|
||||
const char* title,
|
||||
gtk::CellRenderer& cell,
|
||||
TFunc func)
|
||||
{
|
||||
TreeCellDataFunc<TFunc> *data = new TreeCellDataFunc<TFunc>{ std::move (func) };
|
||||
return gtk_tree_view_insert_column_with_data_func (gobj (), position, title, cell.gobj (),
|
||||
TreeCellDataFunc<TFunc>::cell_data_func, data,
|
||||
TreeCellDataFunc<TFunc>::destroy);
|
||||
}
|
||||
|
||||
|
||||
// void TFunc(gtk::TreeViewColumn, gtk::CellRenderer, gtk::TreeModel, const GtkTreeIter&)
|
||||
template<typename TFunc>
|
||||
inline void
|
||||
moo::gobj_ref<GtkTreeViewColumn>::set_cell_data_func (gtk::CellRenderer& cell_renderer, TFunc func)
|
||||
{
|
||||
TreeCellDataFunc<TFunc> *data = new TreeCellDataFunc<TFunc>{ std::move (func) };
|
||||
gtk_tree_view_column_set_cell_data_func (gobj (), cell_renderer.gobj (),
|
||||
TreeCellDataFunc<TFunc>::cell_data_func, data,
|
||||
TreeCellDataFunc<TFunc>::destroy);
|
||||
}
|
||||
|
||||
|
||||
MOO_DEFINE_FLAGS(GdkEventMask);
|
||||
MOO_DEFINE_FLAGS(GdkModifierType);
|
||||
MOO_DEFINE_FLAGS(GtkCellRendererState);
|
||||
MOO_DEFINE_FLAGS(GtkAttachOptions);
|
||||
MOO_DEFINE_FLAGS(GdkDragAction);
|
||||
|
||||
#endif // __cplusplus
|
|
@ -1,20 +0,0 @@
|
|||
/*
|
||||
* moocpp/gobjtypes.h
|
||||
*
|
||||
* Copyright (C) 2004-2016 by Yevgen Muntyan <emuntyan@users.sourceforge.net>
|
||||
*
|
||||
* This file is part of medit. medit 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.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public
|
||||
* License along with medit. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <moocpp/gobjtypes-glib.h>
|
||||
#include <moocpp/gobjtypes-gio.h>
|
||||
#include <moocpp/gobjtypes-gtk.h>
|
|
@ -1,111 +0,0 @@
|
|||
/*
|
||||
* moocpp/gobjwrapper.h
|
||||
*
|
||||
* Copyright (C) 2004-2016 by Yevgen Muntyan <emuntyan@users.sourceforge.net>
|
||||
*
|
||||
* This file is part of medit. medit 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.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public
|
||||
* License along with medit. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#pragma once
|
||||
|
||||
#ifdef __cplusplus
|
||||
|
||||
#include <moocpp/gobjinfo.h>
|
||||
#include <moocpp/gobjref.h>
|
||||
#include <moocpp/grefptr.h>
|
||||
#include <mooutils/mooutils-messages.h>
|
||||
|
||||
namespace moo {
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////////////////////
|
||||
//
|
||||
// gobj_wrapper
|
||||
//
|
||||
|
||||
class gobj_wrapper_base
|
||||
{
|
||||
protected:
|
||||
static gobj_wrapper_base& get(gobj_ref<GObject> g);
|
||||
|
||||
gobj_wrapper_base(gobj_ref<GObject> g);
|
||||
virtual ~gobj_wrapper_base();
|
||||
|
||||
MOO_DISABLE_COPY_OPS(gobj_wrapper_base);
|
||||
|
||||
private:
|
||||
static GQuark qdata_key;
|
||||
static void free_qdata(gpointer d);
|
||||
};
|
||||
|
||||
template<typename CObject, typename CppObject>
|
||||
class gobj_wrapper : public gobj_ref<CObject>, public gobj_wrapper_base
|
||||
{
|
||||
using obj_ref_type = gobj_ref<CObject>;
|
||||
using obj_ptr_type = gobj_ptr<CObject>;
|
||||
|
||||
public:
|
||||
template<typename ...Args>
|
||||
static gref_ptr<CppObject> create(Args&& ...args)
|
||||
{
|
||||
return create<CppObject>(std::forward<Args>(args)...);
|
||||
}
|
||||
|
||||
template<typename Subclass, typename ...Args>
|
||||
static gref_ptr<Subclass> create(Args&& ...args)
|
||||
{
|
||||
obj_ptr_type g = create_gobj<CObject>();
|
||||
gobj_wrapper_data d{g.gobj()};
|
||||
auto o = gref_ptr<Subclass>::create(d, std::forward<Args>(args)...);
|
||||
// Now g and o share the ref count, which is currently owned by the g pointer; steal it.
|
||||
g.release();
|
||||
return o;
|
||||
}
|
||||
|
||||
static CppObject& get(obj_ref_type gobj)
|
||||
{
|
||||
gobj_wrapper_base& b = gobj_wrapper_base::get(gobj);
|
||||
return static_cast<CppObject&>(b);
|
||||
}
|
||||
|
||||
CppObject* operator&() { return static_cast<CppObject*>(this); }
|
||||
|
||||
void ref()
|
||||
{
|
||||
g_object_ref (obj_ref_type::gobj());
|
||||
}
|
||||
|
||||
void unref()
|
||||
{
|
||||
g_object_unref (obj_ref_type::gobj());
|
||||
}
|
||||
|
||||
MOO_DISABLE_COPY_OPS(gobj_wrapper);
|
||||
|
||||
protected:
|
||||
struct gobj_wrapper_data { CObject* g; };
|
||||
|
||||
gobj_wrapper(gobj_wrapper_data& d)
|
||||
: obj_ref_type(*d.g)
|
||||
, gobj_wrapper_base(obj_ref_type(*d.g))
|
||||
{
|
||||
}
|
||||
|
||||
virtual ~gobj_wrapper()
|
||||
{
|
||||
}
|
||||
};
|
||||
|
||||
} // namespace moo
|
||||
|
||||
void g_signal_emit_valist(const moo::gobj_wrapper_base*, guint, GQuark, va_list) = delete;
|
||||
void g_signal_emit(const moo::gobj_wrapper_base*, guint, GQuark, ...) = delete;
|
||||
void g_signal_emit_by_name(const moo::gobj_wrapper_base*, const gchar*, ...) = delete;
|
||||
|
||||
#endif // __cplusplus
|
|
@ -1,193 +0,0 @@
|
|||
/*
|
||||
* moocpp/grefptr.h
|
||||
*
|
||||
* Copyright (C) 2004-2016 by Yevgen Muntyan <emuntyan@users.sourceforge.net>
|
||||
*
|
||||
* This file is part of medit. medit 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.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public
|
||||
* License along with medit. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#pragma once
|
||||
|
||||
#ifdef __cplusplus
|
||||
|
||||
#include "moocpp/utils.h"
|
||||
|
||||
namespace moo {
|
||||
|
||||
template<typename Object>
|
||||
struct obj_ref_unref
|
||||
{
|
||||
static void ref(Object* obj) { obj->ref(); }
|
||||
static void unref(Object* obj) { obj->unref(); }
|
||||
};
|
||||
|
||||
enum class ref_transfer
|
||||
{
|
||||
take_ownership,
|
||||
make_copy,
|
||||
};
|
||||
|
||||
template<typename Object,
|
||||
typename ObjRefUnref = obj_ref_unref<Object>>
|
||||
class gref_ptr
|
||||
{
|
||||
public:
|
||||
gref_ptr() : m_p(nullptr) {}
|
||||
gref_ptr(const nullptr_t&) : gref_ptr() {}
|
||||
|
||||
gref_ptr(Object* obj, ref_transfer policy)
|
||||
: gref_ptr()
|
||||
{
|
||||
assign(obj, policy);
|
||||
}
|
||||
|
||||
template<typename ...Args>
|
||||
static gref_ptr create(Args&& ...args)
|
||||
{
|
||||
return wrap_new(new Object(std::forward<Args>(args)...));
|
||||
}
|
||||
|
||||
static gref_ptr wrap_new(Object* obj)
|
||||
{
|
||||
return gref_ptr(obj, ref_transfer::take_ownership);
|
||||
}
|
||||
|
||||
~gref_ptr()
|
||||
{
|
||||
reset();
|
||||
}
|
||||
|
||||
void ref(Object* obj)
|
||||
{
|
||||
set(obj);
|
||||
}
|
||||
|
||||
void set(Object* obj)
|
||||
{
|
||||
assign(obj, ref_transfer::make_copy);
|
||||
}
|
||||
|
||||
void set_new(Object* obj)
|
||||
{
|
||||
assign(obj, ref_transfer::take_ownership);
|
||||
}
|
||||
|
||||
Object* release()
|
||||
{
|
||||
auto* tmp = m_p;
|
||||
m_p = nullptr;
|
||||
return tmp;
|
||||
}
|
||||
|
||||
void reset()
|
||||
{
|
||||
auto* tmp = m_p;
|
||||
m_p = nullptr;
|
||||
if (tmp)
|
||||
ObjRefUnref::unref(tmp);
|
||||
}
|
||||
|
||||
// Implicit conversion to Object* is dangerous because there is a lot
|
||||
// of code still which frees/steals objects directly. For example:
|
||||
// FooObject* tmp = x->s;
|
||||
// x->s = NULL;
|
||||
// g_object_unref (tmp);
|
||||
operator const Object* () const { return gobj(); }
|
||||
Object* gobj() const { return m_p; }
|
||||
Object& operator*() const { return *gobj(); }
|
||||
Object* operator->() const { return gobj(); }
|
||||
|
||||
// Explicitly forbid other pointer conversions. This way it's still possible to implement
|
||||
// implicit conversions in subclasses, like that to GTypeInstance in gobj_ptr.
|
||||
template<typename T>
|
||||
operator T*() const = delete;
|
||||
|
||||
operator bool() const { return gobj() != nullptr; }
|
||||
bool operator!() const { return gobj() == nullptr; }
|
||||
|
||||
template<typename X>
|
||||
bool operator==(X* other) const
|
||||
{
|
||||
return gobj() == other;
|
||||
}
|
||||
|
||||
template<typename X, typename Y>
|
||||
bool operator==(const gref_ptr<X, Y>& other) const
|
||||
{
|
||||
return gobj() == other.gobj();
|
||||
}
|
||||
|
||||
template<typename X>
|
||||
bool operator!=(const X& anything) const
|
||||
{
|
||||
return !(*this == anything);
|
||||
}
|
||||
|
||||
gref_ptr(const gref_ptr& other)
|
||||
: gref_ptr(other.gobj(), ref_transfer::make_copy)
|
||||
{
|
||||
}
|
||||
|
||||
gref_ptr(gref_ptr&& other)
|
||||
: gref_ptr()
|
||||
{
|
||||
this->m_p = other.m_p;
|
||||
other.m_p = nullptr;
|
||||
}
|
||||
|
||||
gref_ptr& operator=(const gref_ptr& other)
|
||||
{
|
||||
assign(other.gobj(), ref_transfer::make_copy);
|
||||
return *this;
|
||||
}
|
||||
|
||||
// Pointer assignment is easy to misuse
|
||||
template<typename T>
|
||||
gref_ptr& operator=(T* p) = delete;
|
||||
|
||||
gref_ptr& operator=(gref_ptr&& other)
|
||||
{
|
||||
if (gobj() != other.gobj())
|
||||
{
|
||||
assign(other.m_p, ref_transfer::take_ownership);
|
||||
other.m_p = nullptr;
|
||||
}
|
||||
|
||||
return *this;
|
||||
}
|
||||
|
||||
private:
|
||||
void assign(Object* obj, ref_transfer policy)
|
||||
{
|
||||
if (gobj() != obj)
|
||||
{
|
||||
Object* tmp = gobj();
|
||||
m_p = obj;
|
||||
if (obj && (policy == ref_transfer::make_copy))
|
||||
ObjRefUnref::ref(obj);
|
||||
if (tmp)
|
||||
ObjRefUnref::unref(tmp);
|
||||
}
|
||||
}
|
||||
|
||||
private:
|
||||
// This must be a raw pointer, so that zero-initialized gref_ptr is a valid null pointer
|
||||
Object* m_p;
|
||||
};
|
||||
|
||||
// Make sure these aren't called in code ported from pure glib C
|
||||
template<typename X>
|
||||
void g_object_unref(const gref_ptr<X>&) = delete;
|
||||
template<typename X>
|
||||
void g_free(const gref_ptr<X>&) = delete;
|
||||
|
||||
} // namespace moo
|
||||
|
||||
#endif // __cplusplus
|
|
@ -1,177 +0,0 @@
|
|||
/*
|
||||
* moocpp/utils.h
|
||||
*
|
||||
* Copyright (C) 2004-2015 by Yevgen Muntyan <emuntyan@users.sourceforge.net>
|
||||
*
|
||||
* This file is part of medit. medit 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.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public
|
||||
* License along with medit. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#pragma once
|
||||
|
||||
#ifndef __cplusplus
|
||||
|
||||
#define MOO_CPP_DECLS(code)
|
||||
#define MOO_CPP_DFLT_PARAM(val)
|
||||
|
||||
#else // __cplusplus
|
||||
|
||||
#define MOO_CPP_DECLS(code) G_END_DECLS code G_BEGIN_DECLS
|
||||
#define MOO_CPP_DFLT_PARAM(val) = val
|
||||
|
||||
#include <algorithm>
|
||||
#include <memory>
|
||||
#include <list>
|
||||
#include <vector>
|
||||
#include <functional>
|
||||
#include <mooglib/moo-glib.h>
|
||||
|
||||
namespace moo {
|
||||
|
||||
#define MOO_DISABLE_COPY_OPS(Object) \
|
||||
Object(const Object&) = delete; \
|
||||
Object& operator=(const Object&) = delete;
|
||||
|
||||
#define MOO_DEFINE_FLAGS(Flags) \
|
||||
inline Flags operator | (Flags f1, Flags f2) { return static_cast<Flags>(static_cast<int>(f1) | f2); } \
|
||||
inline Flags operator & (Flags f1, Flags f2) { return static_cast<Flags>(static_cast<int>(f1) & f2); } \
|
||||
inline Flags& operator |= (Flags& f1, Flags f2) { f1 = f1 | f2; return f1; } \
|
||||
inline Flags& operator &= (Flags& f1, Flags f2) { f1 = f1 & f2; return f1; } \
|
||||
inline Flags operator ~ (Flags f) { return static_cast<Flags>(~static_cast<int>(f)); } \
|
||||
|
||||
template<typename Container, typename U>
|
||||
auto find(const Container& cont, const U& elm) -> decltype(cont.begin())
|
||||
{
|
||||
return std::find(cont.begin(), cont.end(), elm);
|
||||
}
|
||||
|
||||
template<typename Container, typename U>
|
||||
auto find(Container& cont, const U& elm) -> decltype(cont.begin())
|
||||
{
|
||||
return std::find(cont.begin(), cont.end(), elm);
|
||||
}
|
||||
|
||||
template<typename Container, typename UnPr>
|
||||
auto find_if(const Container& cont, const UnPr& pred) -> decltype(cont.begin())
|
||||
{
|
||||
return std::find_if(cont.begin(), cont.end(), pred);
|
||||
}
|
||||
|
||||
template<typename Container, typename U>
|
||||
bool contains(const Container& vec, const U& elm)
|
||||
{
|
||||
return find(vec, elm) != vec.end();
|
||||
}
|
||||
|
||||
template<typename Container, typename U>
|
||||
bool contains_key(const Container& map, const U& elm)
|
||||
{
|
||||
return map.find(elm) != map.end();
|
||||
}
|
||||
|
||||
template<typename Container, typename UnPr>
|
||||
bool any_of(const Container& cont, const UnPr& pred)
|
||||
{
|
||||
return std::any_of(cont.begin(), cont.end(), pred);
|
||||
}
|
||||
|
||||
template<typename Container, typename U>
|
||||
void remove(Container& vec, const U& elm)
|
||||
{
|
||||
auto itr = find(vec, elm);
|
||||
g_return_if_fail(itr != vec.end());
|
||||
vec.erase(itr);
|
||||
}
|
||||
|
||||
template<typename Container, typename UnPr>
|
||||
void remove_if (Container& vec, const UnPr& pr)
|
||||
{
|
||||
auto itr = find_if (vec, pr);
|
||||
g_return_if_fail (itr != vec.end ());
|
||||
vec.erase (itr);
|
||||
}
|
||||
|
||||
// C++14
|
||||
template<class T, class... Args>
|
||||
std::unique_ptr<T> make_unique(Args&&... args)
|
||||
{
|
||||
return std::unique_ptr<T> (new T (std::forward<Args> (args)...));
|
||||
}
|
||||
|
||||
template<class T, class... Args>
|
||||
std::shared_ptr<T> make_shared (Args&&... args)
|
||||
{
|
||||
return std::shared_ptr<T> (new T (std::forward<Args> (args)...));
|
||||
}
|
||||
|
||||
class raii
|
||||
{
|
||||
public:
|
||||
using func_type = std::function<void()>;
|
||||
|
||||
raii(func_type&& f) : m_f(std::move(f)) {}
|
||||
~raii() { if (m_do) m_f(); }
|
||||
|
||||
raii(raii&& other) : m_f(move(other.m_f)) { other.m_do = false; }
|
||||
|
||||
MOO_DISABLE_COPY_OPS(raii);
|
||||
|
||||
private:
|
||||
func_type m_f;
|
||||
bool m_do = true;
|
||||
};
|
||||
|
||||
template<typename Func>
|
||||
raii on_scope_exit(Func&& f)
|
||||
{
|
||||
return raii{ move(f) };
|
||||
}
|
||||
|
||||
template<typename T>
|
||||
class value_restore
|
||||
{
|
||||
public:
|
||||
value_restore(T& x)
|
||||
: m_r(x)
|
||||
, m_v(x)
|
||||
{
|
||||
}
|
||||
|
||||
value_restore(value_restore&& other)
|
||||
: m_r(other.m_r)
|
||||
, m_v(std::move(other.m_v))
|
||||
{
|
||||
other.m_do = false;
|
||||
}
|
||||
|
||||
~value_restore()
|
||||
{
|
||||
if (m_do)
|
||||
m_r = m_v;
|
||||
}
|
||||
|
||||
MOO_DISABLE_COPY_OPS(value_restore);
|
||||
|
||||
private:
|
||||
T& m_r;
|
||||
T m_v;
|
||||
bool m_do = true;
|
||||
};
|
||||
|
||||
template<typename T>
|
||||
value_restore<T> set_temp_value(T& x, const T& tmp_val)
|
||||
{
|
||||
value_restore<T> r(x);
|
||||
x = tmp_val;
|
||||
return r;
|
||||
}
|
||||
|
||||
} // namespace moo
|
||||
|
||||
#endif // __cplusplus
|
|
@ -1,100 +1,100 @@
|
|||
moo_edit_enum_headers = \
|
||||
moo_edit_enum_headers = \
|
||||
mooedit/mooedit-enums.h
|
||||
|
||||
moo_sources += \
|
||||
$(moo_edit_enum_headers) \
|
||||
mooedit/mooeditor.h \
|
||||
mooedit/mootextview.h \
|
||||
mooedit/mootextprint.h \
|
||||
mooedit/mooeditview.h \
|
||||
mooedit/mooeditaction.h \
|
||||
mooedit/mooeditbookmark.h \
|
||||
mooedit/mooeditconfig.h \
|
||||
mooedit/mooeditdialogs.h \
|
||||
mooedit/mooeditfiltersettings.h \
|
||||
mooedit/mooedit.h \
|
||||
mooedit/mooedithistoryitem.h \
|
||||
mooedit/mooeditprefs.h \
|
||||
mooedit/mooedittypes.h \
|
||||
mooedit/mooeditwindow.h \
|
||||
mooedit/mooeditfileinfo.h \
|
||||
mooedit/mooplugin.h \
|
||||
mooedit/mootextbuffer.h \
|
||||
mooedit/mootextfind.h \
|
||||
mooedit/mootextiter.h \
|
||||
mooedit/mootextsearch.h \
|
||||
mooedit/mootextstylescheme.h \
|
||||
mooedit/mooeditview.cpp \
|
||||
mooedit/mooeditview-priv.h \
|
||||
mooedit/mooeditview-impl.h \
|
||||
mooedit/mooeditview-script.cpp \
|
||||
mooedit/mooeditview-script.h \
|
||||
mooedit/mooedit-accels.h \
|
||||
mooedit/mooeditaction.cpp \
|
||||
mooedit/mooeditaction-factory.cpp \
|
||||
mooedit/mooeditaction-factory.h \
|
||||
mooedit/mooeditbookmark.cpp \
|
||||
mooedit/mooedit.cpp \
|
||||
mooedit/mooeditconfig.cpp \
|
||||
mooedit/mooeditdialogs.cpp \
|
||||
mooedit/mooedit-enum-types.c \
|
||||
mooedit/mooedit-enum-types.h \
|
||||
mooedit/mooedit-enums.h \
|
||||
mooedit/mooedit-fileops.cpp \
|
||||
mooedit/mooedit-fileops.h \
|
||||
mooedit/mooeditfiltersettings.cpp \
|
||||
mooedit/mooedithistoryitem.cpp \
|
||||
mooedit/mooedit-impl.h \
|
||||
mooedit/mooedit-script.cpp \
|
||||
mooedit/mooedit-script.h \
|
||||
mooedit/mooeditprefs.cpp \
|
||||
mooedit/mooeditprefspage.cpp \
|
||||
mooedit/mooedit-private.h \
|
||||
mooedit/mooeditprogress.h \
|
||||
mooedit/mooeditprogress.cpp \
|
||||
mooedit/mooedittab.cpp \
|
||||
mooedit/mooedittab.h \
|
||||
mooedit/mooedittab-impl.h \
|
||||
mooedit/mooeditwindow.cpp \
|
||||
mooedit/mooeditwindow-impl.h \
|
||||
mooedit/mooeditfileinfo-impl.h \
|
||||
mooedit/mooeditfileinfo.cpp \
|
||||
mooedit/moofold.cpp \
|
||||
mooedit/moofold.h \
|
||||
mooedit/mooindenter.cpp \
|
||||
mooedit/mooindenter.h \
|
||||
mooedit/moolang.cpp \
|
||||
mooedit/moolang.h \
|
||||
mooedit/moolangmgr.cpp \
|
||||
mooedit/moolangmgr.h \
|
||||
mooedit/moolangmgr-private.h \
|
||||
mooedit/moolang-private.h \
|
||||
mooedit/moolinebuffer.cpp \
|
||||
mooedit/moolinebuffer.h \
|
||||
mooedit/moolinemark.cpp \
|
||||
mooedit/moolinemark.h \
|
||||
mooedit/mooplugin.cpp \
|
||||
mooedit/mooplugin-loader.cpp \
|
||||
mooedit/mooplugin-loader.h \
|
||||
mooedit/mooplugin-macro.h \
|
||||
mooedit/mootextbtree.cpp \
|
||||
mooedit/mootextbtree.h \
|
||||
mooedit/mootextbuffer.cpp \
|
||||
mooedit/mootextfind.cpp \
|
||||
mooedit/mootextprint.cpp \
|
||||
mooedit/mootextprint-private.h \
|
||||
mooedit/mootext-private.h \
|
||||
mooedit/mootextsearch.cpp \
|
||||
mooedit/mootextsearch-private.h \
|
||||
mooedit/mootextstylescheme.cpp \
|
||||
mooedit/mootextview.cpp \
|
||||
mooedit/mootextview-input.cpp \
|
||||
mooedit/mootextview-private.h \
|
||||
mooedit/mooeditor.cpp \
|
||||
mooedit/mooeditor-impl.h \
|
||||
mooedit/mooeditor-private.h \
|
||||
mooedit/mooeditor-tests.cpp \
|
||||
mooedit/mooeditor-tests.h \
|
||||
moo_sources += \
|
||||
$(moo_edit_enum_headers) \
|
||||
mooedit/mooeditor.h \
|
||||
mooedit/mootextview.h \
|
||||
mooedit/mootextprint.h \
|
||||
mooedit/mooeditview.h \
|
||||
mooedit/mooeditaction.h \
|
||||
mooedit/mooeditbookmark.h \
|
||||
mooedit/mooeditconfig.h \
|
||||
mooedit/mooeditdialogs.h \
|
||||
mooedit/mooeditfiltersettings.h \
|
||||
mooedit/mooedit.h \
|
||||
mooedit/mooedithistoryitem.h \
|
||||
mooedit/mooeditprefs.h \
|
||||
mooedit/mooedittypes.h \
|
||||
mooedit/mooeditwindow.h \
|
||||
mooedit/mooeditfileinfo.h \
|
||||
mooedit/mooplugin.h \
|
||||
mooedit/mootextbuffer.h \
|
||||
mooedit/mootextfind.h \
|
||||
mooedit/mootextiter.h \
|
||||
mooedit/mootextsearch.h \
|
||||
mooedit/mootextstylescheme.h \
|
||||
mooedit/mooeditview.c \
|
||||
mooedit/mooeditview-priv.h \
|
||||
mooedit/mooeditview-impl.h \
|
||||
mooedit/mooeditview-script.c \
|
||||
mooedit/mooeditview-script.h \
|
||||
mooedit/mooedit-accels.h \
|
||||
mooedit/mooeditaction.c \
|
||||
mooedit/mooeditaction-factory.c \
|
||||
mooedit/mooeditaction-factory.h \
|
||||
mooedit/mooeditbookmark.c \
|
||||
mooedit/mooedit.c \
|
||||
mooedit/mooeditconfig.c \
|
||||
mooedit/mooeditdialogs.c \
|
||||
mooedit/mooedit-enum-types.c \
|
||||
mooedit/mooedit-enum-types.h \
|
||||
mooedit/mooedit-enums.h \
|
||||
mooedit/mooedit-fileops.c \
|
||||
mooedit/mooedit-fileops.h \
|
||||
mooedit/mooeditfiltersettings.c \
|
||||
mooedit/mooedithistoryitem.c \
|
||||
mooedit/mooedit-impl.h \
|
||||
mooedit/mooedit-script.c \
|
||||
mooedit/mooedit-script.h \
|
||||
mooedit/mooeditprefs.c \
|
||||
mooedit/mooeditprefspage.c \
|
||||
mooedit/mooedit-private.h \
|
||||
mooedit/mooeditprogress.h \
|
||||
mooedit/mooeditprogress.c \
|
||||
mooedit/mooedittab.c \
|
||||
mooedit/mooedittab.h \
|
||||
mooedit/mooedittab-impl.h \
|
||||
mooedit/mooeditwindow.c \
|
||||
mooedit/mooeditwindow-impl.h \
|
||||
mooedit/mooeditfileinfo-impl.h \
|
||||
mooedit/mooeditfileinfo.c \
|
||||
mooedit/moofold.c \
|
||||
mooedit/moofold.h \
|
||||
mooedit/mooindenter.c \
|
||||
mooedit/mooindenter.h \
|
||||
mooedit/moolang.c \
|
||||
mooedit/moolang.h \
|
||||
mooedit/moolangmgr.c \
|
||||
mooedit/moolangmgr.h \
|
||||
mooedit/moolangmgr-private.h \
|
||||
mooedit/moolang-private.h \
|
||||
mooedit/moolinebuffer.c \
|
||||
mooedit/moolinebuffer.h \
|
||||
mooedit/moolinemark.c \
|
||||
mooedit/moolinemark.h \
|
||||
mooedit/mooplugin.c \
|
||||
mooedit/mooplugin-loader.c \
|
||||
mooedit/mooplugin-loader.h \
|
||||
mooedit/mooplugin-macro.h \
|
||||
mooedit/mootextbtree.c \
|
||||
mooedit/mootextbtree.h \
|
||||
mooedit/mootextbuffer.c \
|
||||
mooedit/mootextfind.c \
|
||||
mooedit/mootextprint.c \
|
||||
mooedit/mootextprint-private.h \
|
||||
mooedit/mootext-private.h \
|
||||
mooedit/mootextsearch.c \
|
||||
mooedit/mootextsearch-private.h \
|
||||
mooedit/mootextstylescheme.c \
|
||||
mooedit/mootextview.c \
|
||||
mooedit/mootextview-input.c \
|
||||
mooedit/mootextview-private.h \
|
||||
mooedit/mooeditor.cpp \
|
||||
mooedit/mooeditor-impl.h \
|
||||
mooedit/mooeditor-private.h \
|
||||
mooedit/mooeditor-tests.c \
|
||||
mooedit/mooeditor-tests.h \
|
||||
mooedit/mooeditor-tests.h
|
||||
|
||||
EXTRA_DIST += \
|
||||
|
|
|
@ -137,7 +137,7 @@ G_END_DECLS
|
|||
|
||||
#ifdef __cplusplus
|
||||
|
||||
#include "moocpp/utils.h"
|
||||
#include "mooutils/mooutils-cpp.h"
|
||||
|
||||
MOO_DEFINE_FLAGS(MooEditStatus)
|
||||
MOO_DEFINE_FLAGS(MooOpenFlags)
|
||||
|
|
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
|
@ -1,7 +1,7 @@
|
|||
/*
|
||||
* mooedit-fileops.h
|
||||
*
|
||||
* Copyright (C) 2004-2016 by Yevgen Muntyan <emuntyan@users.sourceforge.net>
|
||||
* Copyright (C) 2004-2010 by Yevgen Muntyan <emuntyan@users.sourceforge.net>
|
||||
*
|
||||
* This file is part of medit. medit is free software; you can
|
||||
* redistribute it and/or modify it under the terms of the
|
||||
|
@ -13,21 +13,16 @@
|
|||
* License along with medit. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#pragma once
|
||||
|
||||
#ifndef __cplusplus
|
||||
#error "This is a C++ header"
|
||||
#endif
|
||||
#ifndef MOO_EDIT_FILE_OPS_H
|
||||
#define MOO_EDIT_FILE_OPS_H
|
||||
|
||||
#include "mooedit/mooedit.h"
|
||||
#include <gio/gio.h>
|
||||
#include "moocpp/utils.h"
|
||||
#include "moogpp/strutils.h"
|
||||
#include "mooutils/mooutils-misc.h"
|
||||
|
||||
G_BEGIN_DECLS
|
||||
|
||||
|
||||
const char *_moo_get_default_encodings (void);
|
||||
G_END_DECLS
|
||||
|
||||
typedef enum {
|
||||
MOO_EDIT_SAVE_FLAGS_NONE = 0,
|
||||
|
@ -43,28 +38,40 @@ enum {
|
|||
MOO_EDIT_FILE_ERROR_NOENT,
|
||||
MOO_EDIT_FILE_ERROR_CANCELLED
|
||||
};
|
||||
MOO_DEFINE_FLAGS(MooEditSaveFlags)
|
||||
|
||||
GQuark _moo_edit_file_error_quark (void) G_GNUC_CONST;
|
||||
|
||||
bool _moo_is_file_error_cancelled (const g::gerrp& error);
|
||||
gboolean _moo_is_file_error_cancelled (GError *error);
|
||||
|
||||
bool _moo_edit_file_is_new (g::File& file);
|
||||
bool _moo_edit_load_file (Edit edit,
|
||||
g::File& file,
|
||||
const g::gstr& init_encoding,
|
||||
const g::gstr& init_cached_encoding,
|
||||
g::gerrp& error);
|
||||
bool _moo_edit_reload_file (Edit edit,
|
||||
const char* encoding,
|
||||
g::gerrp& error);
|
||||
bool _moo_edit_save_file (Edit edit,
|
||||
g::File& floc,
|
||||
const char* encoding,
|
||||
MooEditSaveFlags flags,
|
||||
g::gerrp& error);
|
||||
bool _moo_edit_save_file_copy (Edit edit,
|
||||
g::File& file,
|
||||
const char* encoding,
|
||||
MooEditSaveFlags flags,
|
||||
g::gerrp& error);
|
||||
gboolean _moo_edit_file_is_new (GFile *file);
|
||||
gboolean _moo_edit_load_file (MooEdit *edit,
|
||||
GFile *file,
|
||||
const char *encoding,
|
||||
const char *cached_encoding,
|
||||
GError **error);
|
||||
gboolean _moo_edit_reload_file (MooEdit *edit,
|
||||
const char *encoding,
|
||||
GError **error);
|
||||
gboolean _moo_edit_save_file (MooEdit *edit,
|
||||
GFile *floc,
|
||||
const char *encoding,
|
||||
MooEditSaveFlags flags,
|
||||
GError **error);
|
||||
gboolean _moo_edit_save_file_copy (MooEdit *edit,
|
||||
GFile *file,
|
||||
const char *encoding,
|
||||
MooEditSaveFlags flags,
|
||||
GError **error);
|
||||
|
||||
|
||||
G_END_DECLS
|
||||
|
||||
#ifdef __cplusplus
|
||||
|
||||
#include "mooutils/mooutils-cpp.h"
|
||||
|
||||
MOO_DEFINE_FLAGS(MooEditSaveFlags)
|
||||
|
||||
#endif // __cplusplus
|
||||
|
||||
#endif /* MOO_EDIT_FILE_OPS_H */
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
/*
|
||||
* mooedit-impl.h
|
||||
*
|
||||
* Copyright (C) 2004-2016 by Yevgen Muntyan <emuntyan@users.sourceforge.net>
|
||||
* Copyright (C) 2004-2010 by Yevgen Muntyan <emuntyan@users.sourceforge.net>
|
||||
*
|
||||
* This file is part of medit. medit is free software; you can
|
||||
* redistribute it and/or modify it under the terms of the
|
||||
|
@ -13,77 +13,68 @@
|
|||
* License along with medit. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#pragma once
|
||||
#ifndef MOO_EDIT_IMPL_H
|
||||
#define MOO_EDIT_IMPL_H
|
||||
|
||||
#include "mooedit/moolinemark.h"
|
||||
#include "mooedit/mooeditor.h"
|
||||
#include "mooedit/mootextview.h"
|
||||
#include "mooedit/mooedittypes.h"
|
||||
#include "mooutils/moohistorymgr.h"
|
||||
|
||||
#ifdef __cplusplus
|
||||
#include <moocpp/moocpp.h>
|
||||
#include <vector>
|
||||
|
||||
template<>
|
||||
class moo::gobj_ref<MooEdit> : public virtual moo::gobj_ref_parent<MooEdit>
|
||||
{
|
||||
public:
|
||||
MOO_DEFINE_GOBJREF_METHODS(MooEdit)
|
||||
|
||||
static std::vector<gobj_raw_ptr<MooEdit>> _moo_edit_instances;
|
||||
|
||||
void _add_view (EditView view);
|
||||
void _remove_view (EditView view);
|
||||
void _set_active_view (EditView view);
|
||||
|
||||
bool _is_busy () const;
|
||||
|
||||
void _add_class_actions ();
|
||||
static void _class_init_actions (MooEditClass* klass);
|
||||
|
||||
void _status_changed ();
|
||||
|
||||
void _delete_bookmarks (bool in_destroy);
|
||||
static void _line_mark_moved (MooEdit* doc,
|
||||
MooLineMark* mark);
|
||||
static void _line_mark_deleted (MooEdit* doc,
|
||||
MooLineMark* mark);
|
||||
void _update_bookmarks_style ();
|
||||
|
||||
void _queue_recheck_config ();
|
||||
|
||||
void _closed ();
|
||||
|
||||
void _set_file (g::FileRawPtr file,
|
||||
const char* encoding);
|
||||
void _remove_untitled (Edit doc);
|
||||
|
||||
void _ensure_newline ();
|
||||
|
||||
void _stop_file_watch ();
|
||||
|
||||
void _set_status (MooEditStatus status);
|
||||
|
||||
void _strip_whitespace ();
|
||||
|
||||
MooActionCollection& _get_actions ();
|
||||
|
||||
static g::gstr _get_normalized_name (g::File file);
|
||||
const g::gstr& _get_normalized_name () const;
|
||||
|
||||
MooEditPrivate& get_priv () { return *gobj()->priv; }
|
||||
const MooEditPrivate& get_priv () const { return *gobj()->priv; }
|
||||
MooEditConfig* get_config () const { return gobj()->config; }
|
||||
void set_config (MooEditConfig* cfg) { gobj()->config = cfg; }
|
||||
};
|
||||
|
||||
#endif // __cplusplus
|
||||
#include <gio/gio.h>
|
||||
|
||||
G_BEGIN_DECLS
|
||||
|
||||
#define MOO_EDIT_GOTO_BOOKMARK_ACTION "GoToBookmark"
|
||||
#define MOO_EDIT_IS_BUSY(doc) (_moo_edit_is_busy (doc))
|
||||
|
||||
extern MooEditList *_moo_edit_instances;
|
||||
|
||||
void _moo_edit_add_view (MooEdit *doc,
|
||||
MooEditView *view);
|
||||
void _moo_edit_remove_view (MooEdit *doc,
|
||||
MooEditView *view);
|
||||
void _moo_edit_set_active_view (MooEdit *doc,
|
||||
MooEditView *view);
|
||||
|
||||
gboolean _moo_edit_is_busy (MooEdit *doc);
|
||||
MooEditState _moo_edit_get_state (MooEdit *doc);
|
||||
void _moo_edit_set_progress_text (MooEdit *doc,
|
||||
const char *text);
|
||||
void _moo_edit_set_state (MooEdit *doc,
|
||||
MooEditState state,
|
||||
const char *text,
|
||||
GDestroyNotify cancel,
|
||||
gpointer data);
|
||||
|
||||
char *_moo_file_get_normalized_name (GFile *file);
|
||||
char *_moo_edit_get_normalized_name (MooEdit *edit);
|
||||
|
||||
char *_moo_edit_get_utf8_filename (MooEdit *edit);
|
||||
|
||||
void _moo_edit_add_class_actions (MooEdit *edit);
|
||||
void _moo_edit_check_actions (MooEdit *edit,
|
||||
MooEditView *view);
|
||||
void _moo_edit_class_init_actions (MooEditClass *klass);
|
||||
|
||||
void _moo_edit_status_changed (MooEdit *edit);
|
||||
|
||||
gboolean _moo_edit_has_comments (MooEdit *edit,
|
||||
gboolean *single_line,
|
||||
gboolean *multi_line);
|
||||
|
||||
#define MOO_EDIT_GOTO_BOOKMARK_ACTION "GoToBookmark"
|
||||
void _moo_edit_delete_bookmarks (MooEdit *edit,
|
||||
gboolean in_destroy);
|
||||
void _moo_edit_line_mark_moved (MooEdit *edit,
|
||||
MooLineMark *mark);
|
||||
void _moo_edit_line_mark_deleted (MooEdit *edit,
|
||||
MooLineMark *mark);
|
||||
gboolean _moo_edit_line_mark_clicked (MooTextView *view,
|
||||
int line);
|
||||
void _moo_edit_update_bookmarks_style (MooEdit *edit);
|
||||
|
||||
/***********************************************************************/
|
||||
/* Preferences
|
||||
*/
|
||||
enum {
|
||||
MOO_EDIT_SETTING_LANG,
|
||||
MOO_EDIT_SETTING_INDENT,
|
||||
|
@ -96,30 +87,42 @@ enum {
|
|||
MOO_EDIT_LAST_SETTING
|
||||
};
|
||||
|
||||
void _moo_edit_init_config (void);
|
||||
gboolean _moo_edit_has_comments (MooEdit *edit,
|
||||
gboolean *single_line,
|
||||
gboolean *multi_line);
|
||||
extern guint *_moo_edit_settings;
|
||||
|
||||
void _moo_edit_queue_recheck_config_all (void);
|
||||
void _moo_edit_update_global_config (void);
|
||||
void _moo_edit_update_global_config (void);
|
||||
void _moo_edit_init_config (void);
|
||||
|
||||
void _moo_edit_check_actions (MooEdit* edit,
|
||||
MooEditView* view);
|
||||
void _moo_edit_queue_recheck_config_all (void);
|
||||
void _moo_edit_queue_recheck_config (MooEdit *edit);
|
||||
|
||||
MooEditState _moo_edit_get_state (MooEdit *doc);
|
||||
void _moo_edit_set_progress_text (MooEdit *doc,
|
||||
const char *text);
|
||||
void _moo_edit_set_state (MooEdit *doc,
|
||||
MooEditState state,
|
||||
const char *text,
|
||||
GDestroyNotify cancel,
|
||||
gpointer data);
|
||||
void _moo_edit_closed (MooEdit *edit);
|
||||
|
||||
GdkPixbuf* _moo_edit_get_icon (MooEdit *edit,
|
||||
GtkWidget *widget,
|
||||
GtkIconSize size);
|
||||
/***********************************************************************/
|
||||
/* File operations
|
||||
*/
|
||||
|
||||
const char* _moo_edit_get_default_encoding (void);
|
||||
void _moo_edit_set_file (MooEdit *edit,
|
||||
GFile *file,
|
||||
const char *encoding);
|
||||
const char *_moo_edit_get_default_encoding (void);
|
||||
void _moo_edit_ensure_newline (MooEdit *edit);
|
||||
|
||||
void _moo_edit_stop_file_watch (MooEdit *edit);
|
||||
|
||||
void _moo_edit_set_status (MooEdit *edit,
|
||||
MooEditStatus status);
|
||||
|
||||
GdkPixbuf *_moo_edit_get_icon (MooEdit *edit,
|
||||
GtkWidget *widget,
|
||||
GtkIconSize size);
|
||||
|
||||
MooActionCollection *_moo_edit_get_actions (MooEdit *edit);
|
||||
|
||||
char *_moo_edit_normalize_filename_for_comparison (const char *filename);
|
||||
char *_moo_edit_normalize_uri_for_comparison (const char *uri);
|
||||
|
||||
void _moo_edit_strip_whitespace (MooEdit *edit);
|
||||
|
||||
G_END_DECLS
|
||||
|
||||
#endif /* MOO_EDIT_IMPL_H */
|
||||
|
|
|
@ -13,62 +13,67 @@
|
|||
* License along with medit. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#pragma once
|
||||
#ifndef MOO_EDIT_PRIVATE_H
|
||||
#define MOO_EDIT_PRIVATE_H
|
||||
|
||||
#include "mooedit/mooedit-impl.h"
|
||||
#include "mooedit/mooeditprogress.h"
|
||||
#include "mooedit/mooeditbookmark.h"
|
||||
#include "mooedit/mooeditview-impl.h"
|
||||
#include "moocpp/moocpp.h"
|
||||
|
||||
G_BEGIN_DECLS
|
||||
|
||||
#define MOO_EDIT_IS_UNTITLED(edit) (!(edit)->priv->file)
|
||||
|
||||
struct MooEditPrivate {
|
||||
MooEditPrivate();
|
||||
~MooEditPrivate();
|
||||
MooEditor *editor;
|
||||
|
||||
MooEditor* editor;
|
||||
GtkTextBuffer *buffer;
|
||||
MooEditViewArray *views;
|
||||
MooEditView *active_view;
|
||||
gboolean dead_active_view;
|
||||
|
||||
moo::gobj_ptr<GtkTextBuffer> buffer;
|
||||
std::vector<EditViewPtr> views;
|
||||
EditViewRawPtr active_view;
|
||||
bool dead_active_view;
|
||||
|
||||
gulong changed_handler_id;
|
||||
gulong modified_changed_handler_id;
|
||||
guint apply_config_idle;
|
||||
bool in_recheck_config;
|
||||
gulong changed_handler_id;
|
||||
gulong modified_changed_handler_id;
|
||||
guint apply_config_idle;
|
||||
gboolean in_recheck_config;
|
||||
|
||||
/***********************************************************************/
|
||||
/* Document
|
||||
*/
|
||||
moo::gobj_ptr<GFile> file;
|
||||
g::gstr filename;
|
||||
g::gstr norm_name;
|
||||
g::gstr display_filename;
|
||||
g::gstr display_basename;
|
||||
GFile *file;
|
||||
char *filename;
|
||||
char *norm_name;
|
||||
char *display_filename;
|
||||
char *display_basename;
|
||||
|
||||
g::gstr encoding;
|
||||
MooLineEndType line_end_type;
|
||||
MooEditStatus status;
|
||||
char *encoding;
|
||||
MooLineEndType line_end_type;
|
||||
MooEditStatus status;
|
||||
|
||||
guint file_monitor_id;
|
||||
bool modified_on_disk;
|
||||
bool deleted_from_disk;
|
||||
guint file_monitor_id;
|
||||
gboolean modified_on_disk;
|
||||
gboolean deleted_from_disk;
|
||||
|
||||
// file sync event source ID
|
||||
guint sync_timeout_id;
|
||||
guint sync_timeout_id;
|
||||
|
||||
MooEditState state;
|
||||
moo::gobj_ptr<MooEditProgress> progress;
|
||||
MooEditState state;
|
||||
MooEditProgress *progress;
|
||||
|
||||
/***********************************************************************/
|
||||
/* Bookmarks
|
||||
*/
|
||||
GSList* bookmarks; /* sorted by line number */
|
||||
guint update_bookmarks_idle;
|
||||
bool enable_bookmarks;
|
||||
gboolean enable_bookmarks;
|
||||
GSList *bookmarks; /* sorted by line number */
|
||||
guint update_bookmarks_idle;
|
||||
|
||||
/***********************************************************************/
|
||||
/* Actions
|
||||
*/
|
||||
moo::gobj_ptr<MooActionCollection> actions;
|
||||
MooActionCollection *actions;
|
||||
};
|
||||
|
||||
void _moo_edit_remove_untitled (MooEdit *doc);
|
||||
|
||||
G_END_DECLS
|
||||
|
||||
#endif /* MOO_EDIT_PRIVATE_H */
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
/*
|
||||
* mooedit.cpp
|
||||
* mooedit.c
|
||||
*
|
||||
* Copyright (C) 2004-2015 by Yevgen Muntyan <emuntyan@users.sourceforge.net>
|
||||
* Copyright (C) 2004-2010 by Yevgen Muntyan <emuntyan@users.sourceforge.net>
|
||||
* Copyright (C) 2014 by Ulrich Eckhardt <ulrich.eckhardt@base-42.de>
|
||||
*
|
||||
* This file is part of medit. medit is free software; you can
|
||||
|
@ -55,18 +55,15 @@
|
|||
#include "mooutils/mooatom.h"
|
||||
#include "mooutils/moocompat.h"
|
||||
#include "mooedit/mooeditprogress-gxml.h"
|
||||
#include "moocpp/moocpp.h"
|
||||
#include <string.h>
|
||||
#include <stdlib.h>
|
||||
|
||||
using namespace moo;
|
||||
|
||||
#define KEY_ENCODING "encoding"
|
||||
#define KEY_LINE "line"
|
||||
|
||||
MOO_DEFINE_OBJECT_ARRAY (MooEdit, moo_edit)
|
||||
|
||||
std::vector<EditRawPtr> Edit::_moo_edit_instances;
|
||||
MooEditList *_moo_edit_instances = NULL;
|
||||
static guint moo_edit_apply_config_all_idle;
|
||||
|
||||
static GObject *moo_edit_constructor (GType type,
|
||||
|
@ -270,31 +267,26 @@ moo_edit_class_init (MooEditClass *klass)
|
|||
G_TYPE_NONE, 0);
|
||||
|
||||
_moo_edit_init_config ();
|
||||
Edit::_class_init_actions (klass);
|
||||
}
|
||||
|
||||
|
||||
MooEditPrivate::MooEditPrivate()
|
||||
: line_end_type(MOO_LE_NONE)
|
||||
{
|
||||
buffer.set_new(GTK_TEXT_BUFFER(g_object_new(MOO_TYPE_TEXT_BUFFER, NULL)));
|
||||
actions = wrap_new (moo_action_collection_new ("MooEdit", "MooEdit"));
|
||||
}
|
||||
|
||||
MooEditPrivate::~MooEditPrivate()
|
||||
{
|
||||
_moo_edit_class_init_actions (klass);
|
||||
}
|
||||
|
||||
|
||||
static void
|
||||
moo_edit_init (MooEdit *edit)
|
||||
{
|
||||
init_cpp_private(edit, edit->priv, MOO_TYPE_EDIT);
|
||||
edit->priv = G_TYPE_INSTANCE_GET_PRIVATE (edit, MOO_TYPE_EDIT, MooEditPrivate);
|
||||
|
||||
edit->priv->views = moo_edit_view_array_new ();
|
||||
edit->priv->buffer = g_object_new (MOO_TYPE_TEXT_BUFFER, NULL);
|
||||
|
||||
edit->config = moo_edit_config_new ();
|
||||
g_signal_connect_swapped (edit->config, "notify",
|
||||
G_CALLBACK (config_changed),
|
||||
edit);
|
||||
|
||||
edit->priv->actions = moo_action_collection_new ("MooEdit", "MooEdit");
|
||||
|
||||
edit->priv->line_end_type = MOO_LE_NONE;
|
||||
}
|
||||
|
||||
|
||||
|
@ -303,35 +295,40 @@ moo_edit_constructor (GType type,
|
|||
guint n_construct_properties,
|
||||
GObjectConstructParam *construct_param)
|
||||
{
|
||||
GObject *object = G_OBJECT_CLASS (moo_edit_parent_class)->constructor (
|
||||
GObject *object;
|
||||
MooEdit *doc;
|
||||
MooEditView *view;
|
||||
|
||||
object = G_OBJECT_CLASS (moo_edit_parent_class)->constructor (
|
||||
type, n_construct_properties, construct_param);
|
||||
|
||||
Edit doc = *MOO_EDIT (object);
|
||||
MooEditPrivate& priv = doc.get_priv();
|
||||
doc = MOO_EDIT (object);
|
||||
|
||||
auto view = EditView::_create(doc);
|
||||
g_assert(priv.views.size() == 1 && priv.views[0] == view);
|
||||
view = _moo_edit_view_new (doc);
|
||||
(void) view; g_assert (doc->priv->views->n_elms == 1 && doc->priv->views->elms[0] == view);
|
||||
|
||||
doc._add_class_actions();
|
||||
Edit::_moo_edit_instances.push_back(&doc);
|
||||
_moo_edit_add_class_actions (doc);
|
||||
_moo_edit_instances = moo_edit_list_prepend (_moo_edit_instances, doc);
|
||||
|
||||
priv.changed_handler_id =
|
||||
priv.buffer->connect ("changed",
|
||||
doc->priv->changed_handler_id =
|
||||
g_signal_connect (doc->priv->buffer,
|
||||
"changed",
|
||||
G_CALLBACK (changed_cb),
|
||||
&doc);
|
||||
priv.modified_changed_handler_id =
|
||||
priv.buffer->connect ("modified-changed",
|
||||
doc);
|
||||
doc->priv->modified_changed_handler_id =
|
||||
g_signal_connect (doc->priv->buffer,
|
||||
"modified-changed",
|
||||
G_CALLBACK (modified_changed_cb),
|
||||
&doc);
|
||||
doc);
|
||||
|
||||
doc._set_file(nullptr, nullptr);
|
||||
_moo_edit_set_file (doc, NULL, NULL);
|
||||
|
||||
priv.buffer->connect_swapped ("line-mark-moved",
|
||||
G_CALLBACK (Edit::_line_mark_moved),
|
||||
&doc);
|
||||
priv.buffer->connect_swapped ("line-mark-deleted",
|
||||
G_CALLBACK (Edit::_line_mark_deleted),
|
||||
&doc);
|
||||
g_signal_connect_swapped (doc->priv->buffer, "line-mark-moved",
|
||||
G_CALLBACK (_moo_edit_line_mark_moved),
|
||||
doc);
|
||||
g_signal_connect_swapped (doc->priv->buffer, "line-mark-deleted",
|
||||
G_CALLBACK (_moo_edit_line_mark_deleted),
|
||||
doc);
|
||||
|
||||
return object;
|
||||
}
|
||||
|
@ -342,137 +339,162 @@ moo_edit_finalize (GObject *object)
|
|||
{
|
||||
MooEdit *edit = MOO_EDIT (object);
|
||||
|
||||
finalize_cpp_private(edit, edit->priv);
|
||||
moo_edit_view_array_free (edit->priv->views);
|
||||
g_object_unref (edit->priv->buffer);
|
||||
moo_file_free (edit->priv->file);
|
||||
g_free (edit->priv->filename);
|
||||
g_free (edit->priv->norm_name);
|
||||
g_free (edit->priv->display_filename);
|
||||
g_free (edit->priv->display_basename);
|
||||
g_free (edit->priv->encoding);
|
||||
|
||||
G_OBJECT_CLASS (moo_edit_parent_class)->finalize (object);
|
||||
}
|
||||
|
||||
void Edit::_closed()
|
||||
void
|
||||
_moo_edit_closed (MooEdit *doc)
|
||||
{
|
||||
// this can be called several times
|
||||
if (!contains(_moo_edit_instances, gobj()))
|
||||
return;
|
||||
g_return_if_fail (MOO_IS_EDIT (doc));
|
||||
|
||||
MooEditPrivate& priv = get_priv();
|
||||
moo_assert(priv.state == MOO_EDIT_STATE_NORMAL);
|
||||
moo_assert (doc->priv->state == MOO_EDIT_STATE_NORMAL);
|
||||
|
||||
_remove_untitled(*this);
|
||||
remove(_moo_edit_instances, gobj());
|
||||
_moo_edit_remove_untitled (doc);
|
||||
_moo_edit_instances = moo_edit_list_remove (_moo_edit_instances, doc);
|
||||
|
||||
while (!priv.views.empty())
|
||||
gtk_widget_destroy (priv.views[0].gobj<GtkWidget>());
|
||||
while (!moo_edit_view_array_is_empty (doc->priv->views))
|
||||
gtk_widget_destroy (GTK_WIDGET (doc->priv->views->elms[0]));
|
||||
|
||||
if (get_config())
|
||||
if (doc->config)
|
||||
{
|
||||
g_signal_handlers_disconnect_by_func (get_config(),
|
||||
g_signal_handlers_disconnect_by_func (doc->config,
|
||||
(gpointer) config_changed,
|
||||
gobj());
|
||||
g_object_unref(get_config());
|
||||
set_config(nullptr);
|
||||
doc);
|
||||
g_object_unref (doc->config);
|
||||
doc->config = NULL;
|
||||
}
|
||||
|
||||
if (priv.apply_config_idle)
|
||||
if (doc->priv->apply_config_idle)
|
||||
{
|
||||
g_source_remove (priv.apply_config_idle);
|
||||
priv.apply_config_idle = 0;
|
||||
g_source_remove (doc->priv->apply_config_idle);
|
||||
doc->priv->apply_config_idle = 0;
|
||||
}
|
||||
|
||||
if (priv.file_monitor_id)
|
||||
if (doc->priv->file_monitor_id)
|
||||
{
|
||||
_stop_file_watch();
|
||||
priv.file_monitor_id = 0;
|
||||
_moo_edit_stop_file_watch (doc);
|
||||
doc->priv->file_monitor_id = 0;
|
||||
}
|
||||
|
||||
if (priv.sync_timeout_id)
|
||||
if (doc->priv->sync_timeout_id)
|
||||
{
|
||||
g_source_remove (priv.sync_timeout_id);
|
||||
priv.sync_timeout_id = 0;
|
||||
g_source_remove (doc->priv->sync_timeout_id);
|
||||
doc->priv->sync_timeout_id = 0;
|
||||
}
|
||||
|
||||
if (priv.update_bookmarks_idle)
|
||||
if (doc->priv->update_bookmarks_idle)
|
||||
{
|
||||
g_source_remove (priv.update_bookmarks_idle);
|
||||
priv.update_bookmarks_idle = 0;
|
||||
g_source_remove (doc->priv->update_bookmarks_idle);
|
||||
doc->priv->update_bookmarks_idle = 0;
|
||||
}
|
||||
|
||||
_delete_bookmarks(true);
|
||||
_moo_edit_delete_bookmarks (doc, TRUE);
|
||||
|
||||
priv.actions.reset();
|
||||
if (doc->priv->actions)
|
||||
{
|
||||
g_object_unref (doc->priv->actions);
|
||||
doc->priv->actions = NULL;
|
||||
}
|
||||
}
|
||||
|
||||
static void
|
||||
moo_edit_dispose (GObject *object)
|
||||
{
|
||||
Edit(*MOO_EDIT(object))._closed();
|
||||
G_OBJECT_CLASS(moo_edit_parent_class)->dispose(object);
|
||||
_moo_edit_closed (MOO_EDIT (object));
|
||||
G_OBJECT_CLASS (moo_edit_parent_class)->dispose (object);
|
||||
}
|
||||
|
||||
|
||||
void Edit::_set_active_view(EditView view)
|
||||
void
|
||||
_moo_edit_set_active_view (MooEdit *doc,
|
||||
MooEditView *view)
|
||||
{
|
||||
MooEditPrivate& priv = get_priv();
|
||||
GtkTextBuffer *buffer;
|
||||
|
||||
g_return_if_fail(contains(priv.views, &view));
|
||||
g_return_if_fail (MOO_IS_EDIT (doc));
|
||||
g_return_if_fail (MOO_IS_EDIT_VIEW (view));
|
||||
|
||||
GtkTextBuffer* buffer = moo_edit_get_buffer(gobj());
|
||||
g_return_if_fail (moo_edit_view_array_find (doc->priv->views, view) >= 0);
|
||||
|
||||
if (priv.active_view != nullptr && priv.active_view != &view)
|
||||
buffer = moo_edit_get_buffer (doc);
|
||||
|
||||
if (doc->priv->active_view != NULL && doc->priv->active_view != view)
|
||||
{
|
||||
GtkTextIter iter;
|
||||
GtkTextMark *mark = priv.active_view->_get_fake_cursor_mark();
|
||||
gtk_text_buffer_get_iter_at_mark(buffer, &iter, gtk_text_buffer_get_insert(buffer));
|
||||
gtk_text_buffer_move_mark(buffer, mark, &iter);
|
||||
GtkTextMark *mark = _moo_edit_view_get_fake_cursor_mark (doc->priv->active_view);
|
||||
gtk_text_buffer_get_iter_at_mark (buffer, &iter, gtk_text_buffer_get_insert (buffer));
|
||||
gtk_text_buffer_move_mark (buffer, mark, &iter);
|
||||
}
|
||||
|
||||
if (priv.dead_active_view ||
|
||||
(priv.active_view != nullptr && priv.active_view != &view))
|
||||
if (doc->priv->dead_active_view ||
|
||||
(doc->priv->active_view != NULL && doc->priv->active_view != view))
|
||||
{
|
||||
GtkTextIter iter;
|
||||
GtkTextMark *mark = view._get_fake_cursor_mark();
|
||||
gtk_text_buffer_get_iter_at_mark(buffer, &iter, mark);
|
||||
gtk_text_buffer_place_cursor(buffer, &iter);
|
||||
GtkTextBuffer *buffer = moo_edit_get_buffer (doc);
|
||||
GtkTextMark *mark = _moo_edit_view_get_fake_cursor_mark (view);
|
||||
gtk_text_buffer_get_iter_at_mark (buffer, &iter, mark);
|
||||
gtk_text_buffer_place_cursor (buffer, &iter);
|
||||
}
|
||||
|
||||
priv.active_view = &view;
|
||||
priv.dead_active_view = false;
|
||||
doc->priv->active_view = view;
|
||||
doc->priv->dead_active_view = FALSE;
|
||||
}
|
||||
|
||||
void Edit::_add_view(EditView view)
|
||||
void
|
||||
_moo_edit_add_view (MooEdit *doc,
|
||||
MooEditView *view)
|
||||
{
|
||||
auto& priv = get_priv();
|
||||
g_return_if_fail (MOO_IS_EDIT (doc));
|
||||
g_return_if_fail (MOO_IS_EDIT_VIEW (view));
|
||||
|
||||
g_return_if_fail(!contains(priv.views, &view));
|
||||
g_assert (moo_edit_view_array_find (doc->priv->views, view) < 0);
|
||||
|
||||
priv.views.emplace_back(wrap(&view));
|
||||
g_object_ref_sink (view);
|
||||
moo_edit_view_array_append (doc->priv->views, view);
|
||||
g_object_unref (view);
|
||||
|
||||
_moo_edit_view_apply_prefs(view.gobj());
|
||||
view._apply_config();
|
||||
_moo_edit_view_apply_prefs (view);
|
||||
_moo_edit_view_apply_config (view);
|
||||
}
|
||||
|
||||
void Edit::_remove_view(EditView view)
|
||||
void
|
||||
_moo_edit_remove_view (MooEdit *doc,
|
||||
MooEditView *view)
|
||||
{
|
||||
auto& priv = get_priv();
|
||||
g_return_if_fail (MOO_IS_EDIT (doc));
|
||||
g_return_if_fail (MOO_IS_EDIT_VIEW (view));
|
||||
|
||||
g_return_if_fail(contains(priv.views, &view));
|
||||
g_return_if_fail (moo_edit_view_array_find (doc->priv->views, view) >= 0);
|
||||
|
||||
if (priv.active_view == &view)
|
||||
if (view == doc->priv->active_view)
|
||||
{
|
||||
priv.active_view = NULL;
|
||||
priv.dead_active_view = TRUE;
|
||||
doc->priv->active_view = NULL;
|
||||
doc->priv->dead_active_view = TRUE;
|
||||
}
|
||||
|
||||
g_object_ref (&view);
|
||||
g_object_ref (view);
|
||||
|
||||
remove(priv.views, &view);
|
||||
view._unset_doc();
|
||||
moo_edit_view_array_remove (doc->priv->views, view);
|
||||
_moo_edit_view_unset_doc (view);
|
||||
|
||||
g_object_unref(&view);
|
||||
g_object_unref (view);
|
||||
}
|
||||
|
||||
|
||||
MooActionCollection& Edit::_get_actions()
|
||||
MooActionCollection *
|
||||
_moo_edit_get_actions (MooEdit *doc)
|
||||
{
|
||||
return *get_priv().actions;
|
||||
g_return_val_if_fail (MOO_IS_EDIT (doc), NULL);
|
||||
return doc->priv->actions;
|
||||
}
|
||||
|
||||
|
||||
|
@ -519,7 +541,7 @@ changed_cb (G_GNUC_UNUSED GtkTextBuffer *buffer,
|
|||
g_source_remove(edit->priv->sync_timeout_id);
|
||||
|
||||
// start timer
|
||||
edit->priv->sync_timeout_id = g_timeout_add (500, autosync_callback, edit);
|
||||
edit->priv->sync_timeout_id = gdk_threads_add_timeout (500, autosync_callback, edit);
|
||||
}
|
||||
|
||||
static void
|
||||
|
@ -573,7 +595,7 @@ moo_edit_set_modified (MooEdit *edit,
|
|||
|
||||
modify_status (edit, MOO_EDIT_STATUS_MODIFIED, modified);
|
||||
|
||||
Edit(*edit)._status_changed ();
|
||||
_moo_edit_status_changed (edit);
|
||||
}
|
||||
|
||||
|
||||
|
@ -586,7 +608,7 @@ moo_edit_set_clean (MooEdit *edit,
|
|||
{
|
||||
g_return_if_fail (MOO_IS_EDIT (edit));
|
||||
modify_status (edit, MOO_EDIT_STATUS_CLEAN, clean);
|
||||
Edit(*edit)._status_changed();
|
||||
_moo_edit_status_changed (edit);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -600,18 +622,24 @@ moo_edit_get_clean (MooEdit *edit)
|
|||
}
|
||||
|
||||
|
||||
void Edit::_status_changed()
|
||||
void
|
||||
_moo_edit_status_changed (MooEdit *edit)
|
||||
{
|
||||
signal_emit(signals[DOC_STATUS_CHANGED], 0, NULL);
|
||||
g_return_if_fail (MOO_IS_EDIT (edit));
|
||||
g_signal_emit (edit, signals[DOC_STATUS_CHANGED], 0, NULL);
|
||||
}
|
||||
|
||||
|
||||
void Edit::_set_status(MooEditStatus status)
|
||||
void
|
||||
_moo_edit_set_status (MooEdit *edit,
|
||||
MooEditStatus status)
|
||||
{
|
||||
if (get_priv().status != status)
|
||||
g_return_if_fail (MOO_IS_EDIT (edit));
|
||||
|
||||
if (edit->priv->status != status)
|
||||
{
|
||||
get_priv().status = status;
|
||||
_status_changed();
|
||||
edit->priv->status = status;
|
||||
_moo_edit_status_changed (edit);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -629,9 +657,7 @@ moo_edit_is_empty (MooEdit *edit)
|
|||
|
||||
g_return_val_if_fail (MOO_IS_EDIT (edit), FALSE);
|
||||
|
||||
Edit r = *edit;
|
||||
|
||||
if (r._is_busy () || moo_edit_is_modified (edit) || !moo_edit_is_untitled (edit))
|
||||
if (MOO_EDIT_IS_BUSY (edit) || moo_edit_is_modified (edit) || !MOO_EDIT_IS_UNTITLED (edit))
|
||||
return FALSE;
|
||||
|
||||
gtk_text_buffer_get_bounds (moo_edit_get_buffer (edit), &start, &end);
|
||||
|
@ -646,7 +672,7 @@ gboolean
|
|||
moo_edit_is_untitled (MooEdit *edit)
|
||||
{
|
||||
g_return_val_if_fail (MOO_IS_EDIT (edit), FALSE);
|
||||
return !edit->priv->file;
|
||||
return MOO_EDIT_IS_UNTITLED (edit);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -656,7 +682,7 @@ gboolean
|
|||
moo_edit_is_modified (MooEdit *edit)
|
||||
{
|
||||
g_return_val_if_fail (MOO_IS_EDIT (edit), FALSE);
|
||||
return (moo_edit_get_status (edit) & MOO_EDIT_STATUS_MODIFIED) != MOO_EDIT_STATUS_NORMAL;
|
||||
return (moo_edit_get_status (edit) & MOO_EDIT_STATUS_MODIFIED) != 0;
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -685,7 +711,7 @@ moo_edit_set_property (GObject *object,
|
|||
break;
|
||||
|
||||
case PROP_ENABLE_BOOKMARKS:
|
||||
MooEditBookmark::set_enable_bookmarks(*edit, g_value_get_boolean (value));
|
||||
moo_edit_set_enable_bookmarks (edit, g_value_get_boolean (value));
|
||||
break;
|
||||
|
||||
case PROP_ENCODING:
|
||||
|
@ -753,7 +779,7 @@ GFile *
|
|||
moo_edit_get_file (MooEdit *edit)
|
||||
{
|
||||
g_return_val_if_fail (MOO_IS_EDIT (edit), NULL);
|
||||
return edit->priv->file ? edit->priv->file->dup().release() : NULL;
|
||||
return edit->priv->file ? g_file_dup (edit->priv->file) : NULL;
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -765,12 +791,21 @@ char *
|
|||
moo_edit_get_filename (MooEdit *edit)
|
||||
{
|
||||
g_return_val_if_fail (MOO_IS_EDIT (edit), NULL);
|
||||
return edit->priv->filename.strdup();
|
||||
return g_strdup (edit->priv->filename);
|
||||
}
|
||||
|
||||
const gstr& Edit::_get_normalized_name() const
|
||||
char *
|
||||
_moo_edit_get_normalized_name (MooEdit *edit)
|
||||
{
|
||||
return get_priv().norm_name;
|
||||
g_return_val_if_fail (MOO_IS_EDIT (edit), NULL);
|
||||
return g_strdup (edit->priv->norm_name);
|
||||
}
|
||||
|
||||
char *
|
||||
_moo_edit_get_utf8_filename (MooEdit *edit)
|
||||
{
|
||||
g_return_val_if_fail (MOO_IS_EDIT (edit), NULL);
|
||||
return edit->priv->filename ? g_strdup (edit->priv->display_filename) : NULL;
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -806,7 +841,7 @@ char *
|
|||
moo_edit_get_uri (MooEdit *edit)
|
||||
{
|
||||
g_return_val_if_fail (MOO_IS_EDIT (edit), NULL);
|
||||
return edit->priv->file ? edit->priv->file->get_uri().release_owned() : NULL;
|
||||
return edit->priv->file ? g_file_get_uri (edit->priv->file) : NULL;
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -834,9 +869,9 @@ moo_edit_set_encoding (MooEdit *edit,
|
|||
g_return_if_fail (MOO_IS_EDIT (edit));
|
||||
g_return_if_fail (encoding != NULL);
|
||||
|
||||
if (edit->priv->encoding != encoding)
|
||||
if (!moo_str_equal (encoding, edit->priv->encoding))
|
||||
{
|
||||
edit->priv->encoding.set(encoding);
|
||||
MOO_ASSIGN_STRING (edit->priv->encoding, encoding);
|
||||
g_object_notify (G_OBJECT (edit), "encoding");
|
||||
}
|
||||
}
|
||||
|
@ -873,8 +908,8 @@ moo_edit_get_view (MooEdit *doc)
|
|||
g_return_val_if_fail (MOO_IS_EDIT (doc), NULL);
|
||||
|
||||
if (!doc->priv->active_view)
|
||||
if (!doc->priv->views.empty())
|
||||
doc->priv->active_view = doc->priv->views.back().gobj();
|
||||
if (!moo_edit_view_array_is_empty (doc->priv->views))
|
||||
doc->priv->active_view = doc->priv->views->elms[doc->priv->views->n_elms - 1];
|
||||
|
||||
return doc->priv->active_view;
|
||||
}
|
||||
|
@ -888,13 +923,7 @@ MooEditViewArray *
|
|||
moo_edit_get_views (MooEdit *doc)
|
||||
{
|
||||
g_return_val_if_fail (MOO_IS_EDIT (doc), NULL);
|
||||
|
||||
MooEditViewArray *ret = moo_edit_view_array_new ();
|
||||
moo_edit_view_array_reserve (ret, doc->priv->views.size ());
|
||||
for (const auto& view: doc->priv->views)
|
||||
moo_edit_view_array_append (ret, view.gobj());
|
||||
|
||||
return ret;
|
||||
return moo_edit_view_array_copy (doc->priv->views);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -906,7 +935,7 @@ int
|
|||
moo_edit_get_n_views (MooEdit *doc)
|
||||
{
|
||||
g_return_val_if_fail (MOO_IS_EDIT (doc), 0);
|
||||
return (int) doc->priv->views.size();
|
||||
return (int) moo_edit_view_array_get_size (doc->priv->views);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -926,7 +955,7 @@ GtkTextBuffer *
|
|||
moo_edit_get_buffer (MooEdit *doc)
|
||||
{
|
||||
g_return_val_if_fail (MOO_IS_EDIT (doc), NULL);
|
||||
return doc->priv->buffer.gobj();
|
||||
return doc->priv->buffer;
|
||||
}
|
||||
|
||||
|
||||
|
@ -1178,7 +1207,7 @@ moo_edit_get_lang (MooEdit *doc)
|
|||
{
|
||||
g_return_val_if_fail (MOO_IS_EDIT (doc), NULL);
|
||||
moo_assert (!doc->priv->in_recheck_config);
|
||||
return moo_text_buffer_get_lang (MOO_TEXT_BUFFER (doc->priv->buffer.gobj()));
|
||||
return moo_text_buffer_get_lang (MOO_TEXT_BUFFER (doc->priv->buffer));
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -1210,10 +1239,12 @@ moo_edit_get_lang_id (MooEdit *doc)
|
|||
static gboolean
|
||||
moo_edit_apply_config_all_in_idle (void)
|
||||
{
|
||||
MooEditList *l;
|
||||
|
||||
moo_edit_apply_config_all_idle = 0;
|
||||
|
||||
for (const auto& doc: Edit::_moo_edit_instances)
|
||||
moo_edit_recheck_config (doc);
|
||||
for (l = _moo_edit_instances; l != NULL; l = l->next)
|
||||
moo_edit_recheck_config (l->data);
|
||||
|
||||
return FALSE;
|
||||
}
|
||||
|
@ -1223,7 +1254,7 @@ _moo_edit_queue_recheck_config_all (void)
|
|||
{
|
||||
if (!moo_edit_apply_config_all_idle)
|
||||
moo_edit_apply_config_all_idle =
|
||||
g_idle_add ((GSourceFunc) moo_edit_apply_config_all_in_idle, NULL);
|
||||
gdk_threads_add_idle ((GSourceFunc) moo_edit_apply_config_all_in_idle, NULL);
|
||||
}
|
||||
|
||||
|
||||
|
@ -1235,7 +1266,7 @@ update_lang_config_from_lang_globs (MooEdit *doc)
|
|||
if (doc->priv->file)
|
||||
{
|
||||
MooLangMgr *mgr = moo_lang_mgr_default ();
|
||||
MooLang *lang = moo_lang_mgr_get_lang_for_file (mgr, *doc->priv->file);
|
||||
MooLang *lang = moo_lang_mgr_get_lang_for_file (mgr, doc->priv->file);
|
||||
lang_id = lang ? _moo_lang_id (lang) : NULL;
|
||||
}
|
||||
|
||||
|
@ -1268,17 +1299,18 @@ update_config_from_lang (MooEdit *doc)
|
|||
static void
|
||||
moo_edit_apply_config (MooEdit *doc)
|
||||
{
|
||||
guint i;
|
||||
const char *lang_id = moo_edit_config_get_string (doc->config, "lang");
|
||||
MooLangMgr *mgr = moo_lang_mgr_default ();
|
||||
MooLang *lang = lang_id ? _moo_lang_mgr_find_lang (mgr, lang_id) : NULL;
|
||||
|
||||
moo_text_buffer_set_lang (MOO_TEXT_BUFFER (doc->priv->buffer.gobj()), lang);
|
||||
moo_text_buffer_set_lang (MOO_TEXT_BUFFER (doc->priv->buffer), lang);
|
||||
|
||||
g_object_notify (G_OBJECT (doc), "has-comments");
|
||||
g_object_notify (G_OBJECT (doc), "lang");
|
||||
|
||||
for (const auto& view: doc->priv->views)
|
||||
view->_apply_config();
|
||||
for (i = 0; i < doc->priv->views->n_elms; ++i)
|
||||
_moo_edit_view_apply_config (doc->priv->views->elms[i]);
|
||||
}
|
||||
|
||||
static void
|
||||
|
@ -1328,34 +1360,36 @@ moo_edit_recheck_config_in_idle (MooEdit *edit)
|
|||
return FALSE;
|
||||
}
|
||||
|
||||
void Edit::_queue_recheck_config()
|
||||
void
|
||||
_moo_edit_queue_recheck_config (MooEdit *doc)
|
||||
{
|
||||
auto& priv = get_priv();
|
||||
g_return_if_fail(!priv.in_recheck_config);
|
||||
if (!priv.apply_config_idle)
|
||||
priv.apply_config_idle =
|
||||
g_idle_add_full (G_PRIORITY_HIGH,
|
||||
(GSourceFunc) moo_edit_recheck_config_in_idle,
|
||||
gobj(), NULL);
|
||||
g_return_if_fail (!doc->priv->in_recheck_config);
|
||||
if (!doc->priv->apply_config_idle)
|
||||
doc->priv->apply_config_idle =
|
||||
gdk_threads_add_idle_full (G_PRIORITY_HIGH,
|
||||
(GSourceFunc) moo_edit_recheck_config_in_idle,
|
||||
doc, NULL);
|
||||
}
|
||||
|
||||
static void
|
||||
config_changed (MooEdit *doc)
|
||||
{
|
||||
if (!doc->priv->in_recheck_config)
|
||||
Edit(*doc)._queue_recheck_config();
|
||||
_moo_edit_queue_recheck_config (doc);
|
||||
}
|
||||
|
||||
|
||||
static void
|
||||
moo_edit_apply_prefs (MooEdit *edit)
|
||||
{
|
||||
guint i;
|
||||
|
||||
g_return_if_fail (MOO_IS_EDIT (edit));
|
||||
|
||||
moo_edit_freeze_notify (edit);
|
||||
|
||||
for (const auto& view: edit->priv->views)
|
||||
_moo_edit_view_apply_prefs (view.gobj());
|
||||
for (i = 0; i < edit->priv->views->n_elms; ++i)
|
||||
_moo_edit_view_apply_prefs (edit->priv->views->elms[i]);
|
||||
|
||||
moo_edit_thaw_notify (edit);
|
||||
}
|
||||
|
@ -1363,21 +1397,25 @@ moo_edit_apply_prefs (MooEdit *edit)
|
|||
static void
|
||||
moo_edit_freeze_notify (MooEdit *doc)
|
||||
{
|
||||
guint i;
|
||||
|
||||
g_return_if_fail (MOO_IS_EDIT (doc));
|
||||
|
||||
g_object_freeze_notify (G_OBJECT (doc));
|
||||
|
||||
for (const auto& view: doc->priv->views)
|
||||
view->freeze_notify();
|
||||
for (i = 0; i < doc->priv->views->n_elms; ++i)
|
||||
g_object_freeze_notify (G_OBJECT (doc->priv->views->elms[i]));
|
||||
}
|
||||
|
||||
static void
|
||||
moo_edit_thaw_notify (MooEdit *doc)
|
||||
{
|
||||
guint i;
|
||||
|
||||
g_return_if_fail (MOO_IS_EDIT (doc));
|
||||
|
||||
for (const auto& view: doc->priv->views)
|
||||
view->thaw_notify();
|
||||
for (i = 0; i < doc->priv->views->n_elms; ++i)
|
||||
g_object_thaw_notify (G_OBJECT (doc->priv->views->elms[i]));
|
||||
|
||||
g_object_thaw_notify (G_OBJECT (doc));
|
||||
}
|
||||
|
@ -1465,9 +1503,11 @@ moo_edit_save_copy (MooEdit *doc,
|
|||
}
|
||||
|
||||
|
||||
bool Edit::_is_busy() const
|
||||
gboolean
|
||||
_moo_edit_is_busy (MooEdit *doc)
|
||||
{
|
||||
return _moo_edit_get_state(nc_gobj()) != MOO_EDIT_STATE_NORMAL;
|
||||
g_return_val_if_fail (MOO_IS_EDIT (doc), FALSE);
|
||||
return _moo_edit_get_state (doc) != MOO_EDIT_STATE_NORMAL;
|
||||
}
|
||||
|
||||
MooEditState
|
||||
|
@ -1483,8 +1523,8 @@ _moo_edit_set_progress_text (MooEdit *doc,
|
|||
{
|
||||
g_return_if_fail (MOO_IS_EDIT (doc));
|
||||
g_return_if_fail (doc->priv->state != MOO_EDIT_STATE_NORMAL);
|
||||
g_return_if_fail (doc->priv->progress != nullptr);
|
||||
_moo_edit_progress_set_text (*doc->priv->progress, text);
|
||||
g_return_if_fail (doc->priv->progress != NULL);
|
||||
_moo_edit_progress_set_text (doc->priv->progress, text);
|
||||
}
|
||||
|
||||
void
|
||||
|
@ -1494,6 +1534,7 @@ _moo_edit_set_state (MooEdit *doc,
|
|||
GDestroyNotify cancel,
|
||||
gpointer data)
|
||||
{
|
||||
guint i;
|
||||
MooEditTab *tab;
|
||||
|
||||
g_return_if_fail (MOO_IS_EDIT (doc));
|
||||
|
@ -1501,15 +1542,15 @@ _moo_edit_set_state (MooEdit *doc,
|
|||
doc->priv->state == MOO_EDIT_STATE_NORMAL);
|
||||
|
||||
if (doc->priv->progress)
|
||||
_moo_edit_progress_set_cancel_func (*doc->priv->progress, cancel, data);
|
||||
_moo_edit_progress_set_cancel_func (doc->priv->progress, cancel, data);
|
||||
|
||||
if (state == doc->priv->state)
|
||||
return;
|
||||
|
||||
doc->priv->state = state;
|
||||
|
||||
for (const auto& view: doc->priv->views)
|
||||
gtk_text_view_set_editable (view.gobj<GtkTextView>(), !state);
|
||||
for (i = 0; i < moo_edit_view_array_get_size (doc->priv->views); ++i)
|
||||
gtk_text_view_set_editable (GTK_TEXT_VIEW (doc->priv->views->elms[i]), !state);
|
||||
|
||||
tab = moo_edit_get_tab (doc);
|
||||
|
||||
|
@ -1519,12 +1560,14 @@ _moo_edit_set_state (MooEdit *doc,
|
|||
if (!state)
|
||||
{
|
||||
_moo_edit_tab_destroy_progress (tab);
|
||||
doc->priv->progress = nullptr;
|
||||
g_object_unref (doc->priv->progress);
|
||||
doc->priv->progress = NULL;
|
||||
}
|
||||
else
|
||||
{
|
||||
doc->priv->progress = wrap_new (_moo_edit_tab_create_progress (tab));
|
||||
_moo_edit_progress_start (*doc->priv->progress, text, cancel, data);
|
||||
doc->priv->progress = _moo_edit_tab_create_progress (tab);
|
||||
_moo_edit_progress_start (doc->priv->progress, text, cancel, data);
|
||||
g_object_ref (doc->priv->progress);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -1835,24 +1878,30 @@ moo_edit_uncomment_selection (MooEdit *edit)
|
|||
}
|
||||
|
||||
|
||||
void Edit::_ensure_newline()
|
||||
void
|
||||
_moo_edit_ensure_newline (MooEdit *edit)
|
||||
{
|
||||
GtkTextBuffer *buffer;
|
||||
GtkTextIter iter;
|
||||
|
||||
buffer = moo_edit_get_buffer (gobj());
|
||||
g_return_if_fail (MOO_IS_EDIT (edit));
|
||||
|
||||
buffer = moo_edit_get_buffer (edit);
|
||||
gtk_text_buffer_get_end_iter (buffer, &iter);
|
||||
|
||||
if (!gtk_text_iter_starts_line (&iter))
|
||||
gtk_text_buffer_insert (buffer, &iter, "\n", -1);
|
||||
}
|
||||
|
||||
void Edit::_strip_whitespace()
|
||||
void
|
||||
_moo_edit_strip_whitespace (MooEdit *doc)
|
||||
{
|
||||
GtkTextBuffer *buffer;
|
||||
GtkTextIter iter;
|
||||
|
||||
buffer = moo_edit_get_buffer (gobj());
|
||||
g_return_if_fail (MOO_IS_EDIT (doc));
|
||||
|
||||
buffer = moo_edit_get_buffer (doc);
|
||||
gtk_text_buffer_begin_user_action (buffer);
|
||||
|
||||
for (gtk_text_buffer_get_start_iter (buffer, &iter);
|
||||
|
@ -1860,6 +1909,7 @@ void Edit::_strip_whitespace()
|
|||
gtk_text_iter_forward_line (&iter))
|
||||
{
|
||||
GtkTextIter end;
|
||||
char *slice, *p;
|
||||
gssize len;
|
||||
|
||||
if (gtk_text_iter_ends_line (&iter))
|
||||
|
@ -1868,18 +1918,19 @@ void Edit::_strip_whitespace()
|
|||
end = iter;
|
||||
gtk_text_iter_forward_to_line_end (&end);
|
||||
|
||||
gstr slice = gstr::wrap_new (gtk_text_buffer_get_slice (buffer, &iter, &end, TRUE));
|
||||
slice = gtk_text_buffer_get_slice (buffer, &iter, &end, TRUE);
|
||||
len = strlen (slice);
|
||||
g_assert (len > 0);
|
||||
|
||||
const char *p;
|
||||
for (p = slice.get() + len; p > slice && (p[-1] == ' ' || p[-1] == '\t'); --p) ;
|
||||
for (p = slice + len; p > slice && (p[-1] == ' ' || p[-1] == '\t'); --p) ;
|
||||
|
||||
if (*p)
|
||||
{
|
||||
gtk_text_iter_forward_chars (&iter, g_utf8_pointer_to_offset (slice, p));
|
||||
gtk_text_buffer_delete (buffer, &iter, &end);
|
||||
}
|
||||
|
||||
g_free (slice);
|
||||
}
|
||||
|
||||
gtk_text_buffer_end_user_action (buffer);
|
|
@ -24,48 +24,48 @@ SET(mooedit_sources
|
|||
mooedit/mootextiter.h
|
||||
mooedit/mootextsearch.h
|
||||
mooedit/mootextstylescheme.h
|
||||
mooedit/mooeditview.cpp
|
||||
mooedit/mooeditview.c
|
||||
mooedit/mooeditview-priv.h
|
||||
mooedit/mooeditview-impl.h
|
||||
mooedit/mooeditview-script.c
|
||||
mooedit/mooeditview-script.h
|
||||
mooedit/mooedit-accels.h
|
||||
mooedit/mooeditaction.c
|
||||
mooedit/mooeditaction-factory.cpp
|
||||
mooedit/mooeditaction-factory.c
|
||||
mooedit/mooeditaction-factory.h
|
||||
mooedit/mooeditbookmark.cpp
|
||||
mooedit/mooedit.cpp
|
||||
mooedit/mooeditbookmark.c
|
||||
mooedit/mooedit.c
|
||||
mooedit/mooeditconfig.c
|
||||
mooedit/mooeditdialogs.cpp
|
||||
mooedit/mooeditdialogs.c
|
||||
mooedit/mooedit-enum-types.c
|
||||
mooedit/mooedit-enum-types.h
|
||||
mooedit/mooedit-enums.h
|
||||
mooedit/mooedit-fileops.cpp
|
||||
mooedit/mooedit-fileops.c
|
||||
mooedit/mooedit-fileops.h
|
||||
mooedit/mooeditfiltersettings.c
|
||||
mooedit/mooedithistoryitem.c
|
||||
mooedit/mooedit-impl.h
|
||||
mooedit/mooedit-script.c
|
||||
mooedit/mooedit-script.h
|
||||
mooedit/mooeditprefs.cpp
|
||||
mooedit/mooeditprefs.c
|
||||
mooedit/mooeditprefspage.c
|
||||
mooedit/mooedit-private.h
|
||||
mooedit/mooeditprogress.h
|
||||
mooedit/mooeditprogress.cpp
|
||||
mooedit/mooedittab.cpp
|
||||
mooedit/mooeditprogress.c
|
||||
mooedit/mooedittab.c
|
||||
mooedit/mooedittab.h
|
||||
mooedit/mooedittab-impl.h
|
||||
mooedit/mooeditwindow.c
|
||||
mooedit/mooeditwindow-impl.h
|
||||
mooedit/mooeditfileinfo-impl.h
|
||||
mooedit/mooeditfileinfo.cpp
|
||||
mooedit/mooeditfileinfo.c
|
||||
mooedit/moofold.c
|
||||
mooedit/moofold.h
|
||||
mooedit/mooindenter.c
|
||||
mooedit/mooindenter.h
|
||||
mooedit/moolang.c
|
||||
mooedit/moolang.h
|
||||
mooedit/moolangmgr.cpp
|
||||
mooedit/moolangmgr.c
|
||||
mooedit/moolangmgr.h
|
||||
mooedit/moolangmgr-private.h
|
||||
mooedit/moolang-private.h
|
||||
|
|
|
@ -13,7 +13,8 @@
|
|||
* License along with medit. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#pragma once
|
||||
#ifndef MOO_EDIT_H
|
||||
#define MOO_EDIT_H
|
||||
|
||||
#include <mooedit/mooeditconfig.h>
|
||||
#include <mooedit/mooedit-enums.h>
|
||||
|
@ -121,4 +122,7 @@ gboolean moo_edit_close (MooEdit *edi
|
|||
void moo_edit_comment_selection (MooEdit *edit);
|
||||
void moo_edit_uncomment_selection (MooEdit *edit);
|
||||
|
||||
|
||||
G_END_DECLS
|
||||
|
||||
#endif /* MOO_EDIT_H */
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
/*
|
||||
* mooeditaction-factory.cpp
|
||||
* mooeditaction-factory.c
|
||||
*
|
||||
* Copyright (C) 2004-2016 by Yevgen Muntyan <emuntyan@users.sourceforge.net>
|
||||
* Copyright (C) 2004-2010 by Yevgen Muntyan <emuntyan@users.sourceforge.net>
|
||||
*
|
||||
* This file is part of medit. medit is free software; you can
|
||||
* redistribute it and/or modify it under the terms of the
|
||||
|
@ -206,6 +206,7 @@ moo_edit_class_install_action (MooEditClass *klass,
|
|||
GHashTable *actions;
|
||||
ActionInfo *info;
|
||||
GType type;
|
||||
MooEditList *l;
|
||||
|
||||
g_return_if_fail (MOO_IS_EDIT_CLASS (klass));
|
||||
g_return_if_fail (MOO_IS_ACTION_FACTORY (factory));
|
||||
|
@ -227,15 +228,15 @@ moo_edit_class_install_action (MooEditClass *klass,
|
|||
info = action_info_new (factory, doc_conditions, view_conditions);
|
||||
g_hash_table_insert (actions, g_strdup (action_id), info);
|
||||
|
||||
for (const auto& doc: Edit::_moo_edit_instances)
|
||||
for (l = _moo_edit_instances; l != NULL; l = l->next)
|
||||
{
|
||||
if (g_type_is_a (G_OBJECT_TYPE (doc), type))
|
||||
if (g_type_is_a (G_OBJECT_TYPE (l->data), type))
|
||||
{
|
||||
GtkAction *action = create_action (action_id, info, doc);
|
||||
GtkAction *action = create_action (action_id, info, l->data);
|
||||
|
||||
if (action)
|
||||
{
|
||||
moo_edit_add_action (doc, action);
|
||||
moo_edit_add_action (l->data, action);
|
||||
g_object_unref (action);
|
||||
}
|
||||
}
|
||||
|
@ -420,13 +421,13 @@ error:
|
|||
|
||||
if (doc_conditions)
|
||||
{
|
||||
g_ptr_array_foreach (doc_conditions, (GFunc) extern_g_free, NULL);
|
||||
g_ptr_array_foreach (doc_conditions, (GFunc) g_free, NULL);
|
||||
g_ptr_array_free (doc_conditions, TRUE);
|
||||
}
|
||||
|
||||
if (view_conditions)
|
||||
{
|
||||
g_ptr_array_foreach (view_conditions, (GFunc) extern_g_free, NULL);
|
||||
g_ptr_array_foreach (view_conditions, (GFunc) g_free, NULL);
|
||||
g_ptr_array_free (view_conditions, TRUE);
|
||||
}
|
||||
|
||||
|
@ -520,6 +521,7 @@ moo_edit_class_remove_action (MooEditClass *klass,
|
|||
{
|
||||
GHashTable *actions;
|
||||
GType type;
|
||||
MooEditList *l;
|
||||
|
||||
g_return_if_fail (MOO_IS_EDIT_CLASS (klass));
|
||||
|
||||
|
@ -529,11 +531,9 @@ moo_edit_class_remove_action (MooEditClass *klass,
|
|||
if (actions)
|
||||
g_hash_table_remove (actions, action_id);
|
||||
|
||||
for (const auto& doc: Edit::_moo_edit_instances)
|
||||
{
|
||||
if (g_type_is_a(G_OBJECT_TYPE(doc), type))
|
||||
moo_edit_remove_action(doc, action_id);
|
||||
}
|
||||
for (l = _moo_edit_instances; l != NULL; l = l->next)
|
||||
if (g_type_is_a (G_OBJECT_TYPE (l->data), type))
|
||||
moo_edit_remove_action (l->data, action_id);
|
||||
}
|
||||
|
||||
|
||||
|
@ -541,7 +541,7 @@ GtkActionGroup *
|
|||
moo_edit_get_actions (MooEdit *edit)
|
||||
{
|
||||
g_return_val_if_fail (MOO_IS_EDIT (edit), NULL);
|
||||
return moo_action_collection_get_group (edit->priv->actions.gobj(), NULL);
|
||||
return moo_action_collection_get_group (edit->priv->actions, NULL);
|
||||
}
|
||||
|
||||
|
||||
|
@ -573,18 +573,23 @@ add_action (const char *id,
|
|||
}
|
||||
}
|
||||
|
||||
void Edit::_add_class_actions()
|
||||
void
|
||||
_moo_edit_add_class_actions (MooEdit *edit)
|
||||
{
|
||||
GType type = G_OBJECT_TYPE (gobj());
|
||||
GType type;
|
||||
|
||||
while (true)
|
||||
g_return_if_fail (MOO_IS_EDIT (edit));
|
||||
|
||||
type = G_OBJECT_TYPE (edit);
|
||||
|
||||
while (TRUE)
|
||||
{
|
||||
GHashTable *actions;
|
||||
|
||||
actions = get_actions_hash (type);
|
||||
|
||||
if (actions)
|
||||
g_hash_table_foreach (actions, (GHFunc) add_action, gobj());
|
||||
g_hash_table_foreach (actions, (GHFunc) add_action, edit);
|
||||
|
||||
if (type == MOO_TYPE_EDIT)
|
||||
break;
|
||||
|
@ -601,7 +606,7 @@ create_input_methods_menu_item (GtkAction *action)
|
|||
GtkWidget *item, *menu;
|
||||
gboolean visible = TRUE;
|
||||
|
||||
view = MOO_EDIT_VIEW (g_object_get_data (G_OBJECT (action), "moo-edit-view"));
|
||||
view = g_object_get_data (G_OBJECT (action), "moo-edit-view");
|
||||
g_return_val_if_fail (MOO_IS_EDIT_VIEW (view), NULL);
|
||||
|
||||
item = gtk_menu_item_new ();
|
||||
|
@ -627,7 +632,7 @@ create_special_chars_menu_item (GtkAction *action)
|
|||
GtkWidget *item, *menu;
|
||||
gboolean visible = TRUE;
|
||||
|
||||
view = MOO_EDIT_VIEW (g_object_get_data (G_OBJECT (action), "moo-edit-view"));
|
||||
view = g_object_get_data (G_OBJECT (action), "moo-edit-view");
|
||||
g_return_val_if_fail (MOO_IS_EDIT_VIEW (view), NULL);
|
||||
|
||||
item = gtk_menu_item_new ();
|
||||
|
@ -644,7 +649,8 @@ create_special_chars_menu_item (GtkAction *action)
|
|||
return item;
|
||||
}
|
||||
|
||||
void Edit::_class_init_actions(MooEditClass *klass)
|
||||
void
|
||||
_moo_edit_class_init_actions (MooEditClass *klass)
|
||||
{
|
||||
moo_edit_class_new_action (klass, "Undo",
|
||||
"display-name", GTK_STOCK_UNDO,
|
|
@ -13,6 +13,10 @@
|
|||
* License along with medit. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
/**
|
||||
* class:MooEditBookmark: (parent MooLineMark) (moo.private 1)
|
||||
**/
|
||||
|
||||
#include "mooedit/mooeditbookmark.h"
|
||||
#include "mooedit/mooedit-private.h"
|
||||
#include "mooedit/mootextbuffer.h"
|
||||
|
@ -68,16 +72,22 @@ get_line_count (MooEdit *edit)
|
|||
}
|
||||
|
||||
|
||||
void MooEditBookmark::set_enable_bookmarks(Edit edit, bool enable)
|
||||
void
|
||||
moo_edit_set_enable_bookmarks (MooEdit *edit,
|
||||
gboolean enable)
|
||||
{
|
||||
if (enable != edit.get_priv().enable_bookmarks)
|
||||
g_return_if_fail (MOO_IS_EDIT (edit));
|
||||
|
||||
enable = enable != 0;
|
||||
|
||||
if (enable != edit->priv->enable_bookmarks)
|
||||
{
|
||||
edit.get_priv().enable_bookmarks = enable;
|
||||
edit->priv->enable_bookmarks = enable;
|
||||
|
||||
if (!enable)
|
||||
edit._delete_bookmarks(false);
|
||||
_moo_edit_delete_bookmarks (edit, FALSE);
|
||||
|
||||
edit.notify("enable-bookmarks");
|
||||
g_object_notify (G_OBJECT (edit), "enable-bookmarks");
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -115,7 +125,7 @@ update_bookmarks (MooEdit *edit)
|
|||
new_ = g_slist_prepend (new_, l->data);
|
||||
|
||||
g_slist_foreach (deleted, (GFunc) disconnect_bookmark, NULL);
|
||||
g_slist_foreach (deleted, (GFunc) extern_g_object_unref, NULL);
|
||||
g_slist_foreach (deleted, (GFunc) g_object_unref, NULL);
|
||||
g_slist_free (deleted);
|
||||
|
||||
new_ = g_slist_sort (new_, (GCompareFunc) cmp_bookmarks);
|
||||
|
@ -253,18 +263,15 @@ moo_edit_add_bookmark (MooEdit *edit,
|
|||
guint line,
|
||||
guint no)
|
||||
{
|
||||
guint i;
|
||||
MooEditBookmark *bk;
|
||||
|
||||
g_return_if_fail (MOO_IS_EDIT (edit));
|
||||
g_return_if_fail (line < get_line_count (edit));
|
||||
g_return_if_fail (moo_edit_get_bookmark_at_line (edit, line) == NULL);
|
||||
|
||||
for (const auto& view: edit->priv->views)
|
||||
{
|
||||
view->set ("show-line-marks", TRUE);
|
||||
view->set ("show-line-marks", true);
|
||||
view->set ("show-line-marks", TRUE, "show-line-marks", TRUE);
|
||||
}
|
||||
for (i = 0; i < edit->priv->views->n_elms; ++i)
|
||||
g_object_set (edit->priv->views->elms[i], "show-line-marks", TRUE, (char*) 0);
|
||||
|
||||
bk = MOO_EDIT_BOOKMARK (g_object_new (MOO_TYPE_EDIT_BOOKMARK, "background", get_bookmark_color (edit), (char*) 0));
|
||||
moo_text_buffer_add_line_mark (get_moo_buffer (edit), MOO_LINE_MARK (bk), line);
|
||||
|
@ -304,20 +311,24 @@ disconnect_bookmark (MooEditBookmark *bk)
|
|||
}
|
||||
|
||||
|
||||
void Edit::_line_mark_moved(MooEdit* edit, MooLineMark* mark)
|
||||
void
|
||||
_moo_edit_line_mark_moved (MooEdit *edit,
|
||||
MooLineMark *mark)
|
||||
{
|
||||
if (MOO_IS_EDIT_BOOKMARK (mark) &&
|
||||
g_object_get_data (G_OBJECT (mark), "moo-edit-bookmark") &&
|
||||
!edit->priv->update_bookmarks_idle)
|
||||
{
|
||||
edit->priv->update_bookmarks_idle =
|
||||
g_idle_add ((GSourceFunc) update_bookmarks, edit);
|
||||
gdk_threads_add_idle ((GSourceFunc) update_bookmarks, edit);
|
||||
bookmarks_changed (edit);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void Edit::_line_mark_deleted(MooEdit* edit, MooLineMark* mark)
|
||||
void
|
||||
_moo_edit_line_mark_deleted (MooEdit *edit,
|
||||
MooLineMark *mark)
|
||||
{
|
||||
if (MOO_IS_EDIT_BOOKMARK (mark) &&
|
||||
g_object_get_data (G_OBJECT (mark), "moo-edit-bookmark") &&
|
||||
|
@ -365,12 +376,14 @@ moo_edit_get_bookmarks_in_range (MooEdit *edit,
|
|||
}
|
||||
|
||||
|
||||
void Edit::_delete_bookmarks(bool in_destroy)
|
||||
void
|
||||
_moo_edit_delete_bookmarks (MooEdit *edit,
|
||||
gboolean in_destroy)
|
||||
{
|
||||
auto& priv = get_priv();
|
||||
GSList *bookmarks;
|
||||
|
||||
GSList *bookmarks = priv.bookmarks;
|
||||
priv.bookmarks = NULL;
|
||||
bookmarks = edit->priv->bookmarks;
|
||||
edit->priv->bookmarks = NULL;
|
||||
|
||||
if (bookmarks)
|
||||
{
|
||||
|
@ -379,15 +392,15 @@ void Edit::_delete_bookmarks(bool in_destroy)
|
|||
disconnect_bookmark (MOO_EDIT_BOOKMARK (bookmarks->data));
|
||||
|
||||
if (!in_destroy)
|
||||
moo_text_buffer_delete_line_mark (get_moo_buffer (gobj()),
|
||||
moo_text_buffer_delete_line_mark (get_moo_buffer (edit),
|
||||
MOO_LINE_MARK (bookmarks->data));
|
||||
|
||||
::g_object_unref (bookmarks->data);
|
||||
g_object_unref (bookmarks->data);
|
||||
bookmarks = g_slist_delete_link (bookmarks, bookmarks);
|
||||
}
|
||||
|
||||
if (!in_destroy)
|
||||
bookmarks_changed(gobj());
|
||||
bookmarks_changed (edit);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -482,14 +495,15 @@ get_bookmark_color (MooEdit *doc)
|
|||
return style ? _moo_text_style_get_bg_color (style) : NULL;
|
||||
}
|
||||
|
||||
void Edit::_update_bookmarks_style()
|
||||
void
|
||||
_moo_edit_update_bookmarks_style (MooEdit *edit)
|
||||
{
|
||||
const GSList *bookmarks;
|
||||
const char *color;
|
||||
|
||||
color = get_bookmark_color (gobj());
|
||||
color = get_bookmark_color (edit);
|
||||
|
||||
bookmarks = moo_edit_list_bookmarks (gobj());
|
||||
bookmarks = moo_edit_list_bookmarks (edit);
|
||||
while (bookmarks)
|
||||
{
|
||||
moo_line_mark_set_background (MOO_LINE_MARK (bookmarks->data), color);
|
|
@ -18,9 +18,6 @@
|
|||
|
||||
#include <mooedit/mooedit.h>
|
||||
#include <mooedit/moolinemark.h>
|
||||
#ifdef __cplusplus
|
||||
#include <moocpp/moocpp.h>
|
||||
#endif
|
||||
|
||||
G_BEGIN_DECLS
|
||||
|
||||
|
@ -39,12 +36,6 @@ struct MooEditBookmark
|
|||
{
|
||||
MooLineMark mark;
|
||||
guint no;
|
||||
|
||||
#ifdef __cplusplus
|
||||
static void set_enable_bookmarks (Edit edit,
|
||||
bool enable);
|
||||
static bool get_enable_bookmarks (const Edit& edit);
|
||||
#endif // __cplusplus
|
||||
};
|
||||
|
||||
struct MooEditBookmarkClass
|
||||
|
@ -52,13 +43,12 @@ struct MooEditBookmarkClass
|
|||
MooLineMarkClass mark_class;
|
||||
};
|
||||
|
||||
#ifdef __cplusplus
|
||||
using EditBookmarkPtr = moo::gobj_ptr<MooEditBookmark>;
|
||||
using EditBookmark = moo::gobj_ref<MooEditBookmark>;
|
||||
#endif
|
||||
|
||||
GType moo_edit_bookmark_get_type (void) G_GNUC_CONST;
|
||||
|
||||
void moo_edit_set_enable_bookmarks (MooEdit *edit,
|
||||
gboolean enable);
|
||||
gboolean moo_edit_get_enable_bookmarks (MooEdit *edit);
|
||||
/* list must not be modified */
|
||||
const GSList *moo_edit_list_bookmarks (MooEdit *edit);
|
||||
void moo_edit_toggle_bookmark (MooEdit *edit,
|
||||
|
|
|
@ -17,7 +17,6 @@
|
|||
#include "mooedit/mooeditprefs.h"
|
||||
#include "mooedit/mooedit-fileops.h"
|
||||
#include "mooedit/mooeditfileinfo.h"
|
||||
#include "mooedit/mooedit-impl.h"
|
||||
#include "mooutils/moodialogs.h"
|
||||
#include "mooutils/moostock.h"
|
||||
#include "mooutils/mooi18n.h"
|
||||
|
@ -26,18 +25,10 @@
|
|||
#include "mooedit/mootextfind-prompt-gxml.h"
|
||||
#include "mooedit/mooeditsavemult-gxml.h"
|
||||
#include "mooedit/mootryencoding-gxml.h"
|
||||
#include "moocpp/moocpp.h"
|
||||
#include <gtk/gtk.h>
|
||||
#include <mooglib/moo-glib.h>
|
||||
#include <string.h>
|
||||
#ifdef __WIN32__
|
||||
#include <mooutils/moofiledialog-win32.h>
|
||||
#include <gdk/gdkwin32.h>
|
||||
#endif // __WIN32__
|
||||
|
||||
using namespace moo;
|
||||
|
||||
#ifndef __WIN32__
|
||||
|
||||
MooOpenInfoArray *
|
||||
_moo_edit_open_dialog (GtkWidget *widget,
|
||||
|
@ -45,7 +36,7 @@ _moo_edit_open_dialog (GtkWidget *widget,
|
|||
{
|
||||
MooFileDialog *dialog;
|
||||
const char *encoding;
|
||||
g::FilePtr start;
|
||||
GFile *start = NULL;
|
||||
MooFileArray *files = NULL;
|
||||
MooOpenInfoArray *info_array = NULL;
|
||||
guint i;
|
||||
|
@ -54,17 +45,19 @@ _moo_edit_open_dialog (GtkWidget *widget,
|
|||
|
||||
if (current_doc && moo_prefs_get_bool (moo_edit_setting (MOO_EDIT_PREFS_DIALOGS_OPEN_FOLLOWS_DOC)))
|
||||
{
|
||||
g::FilePtr file(moo_edit_get_file(current_doc), ref_transfer::take_ownership);
|
||||
GFile *file = moo_edit_get_file (current_doc);
|
||||
|
||||
if (file)
|
||||
start = file->get_parent();
|
||||
start = g_file_get_parent (file);
|
||||
|
||||
g_object_unref (file);
|
||||
}
|
||||
|
||||
if (!start)
|
||||
start.set_new(moo_prefs_get_file(moo_edit_setting(MOO_EDIT_PREFS_LAST_DIR)));
|
||||
start = moo_prefs_get_file (moo_edit_setting (MOO_EDIT_PREFS_LAST_DIR));
|
||||
|
||||
dialog = moo_file_dialog_new (MOO_FILE_DIALOG_OPEN, widget,
|
||||
TRUE, GTK_STOCK_OPEN, start.gobj(),
|
||||
TRUE, GTK_STOCK_OPEN, start,
|
||||
NULL);
|
||||
g_object_set (dialog, "enable-encodings", TRUE, NULL);
|
||||
moo_file_dialog_set_help_id (dialog, "dialog-open");
|
||||
|
@ -84,12 +77,14 @@ _moo_edit_open_dialog (GtkWidget *widget,
|
|||
|
||||
info_array = moo_open_info_array_new ();
|
||||
for (i = 0; i < files->n_elms; ++i)
|
||||
moo_open_info_array_take (info_array, moo_open_info_new_file (files->elms[i], encoding, -1, MOO_OPEN_FLAGS_NONE));
|
||||
moo_open_info_array_take (info_array, moo_open_info_new_file (files->elms[i], encoding, -1, 0));
|
||||
|
||||
start.set_new(g_file_get_parent (files->elms[0]));
|
||||
moo_prefs_set_file (moo_edit_setting (MOO_EDIT_PREFS_LAST_DIR), start.gobj());
|
||||
g_object_unref (start);
|
||||
start = g_file_get_parent (files->elms[0]);
|
||||
moo_prefs_set_file (moo_edit_setting (MOO_EDIT_PREFS_LAST_DIR), start);
|
||||
}
|
||||
|
||||
g_object_unref (start);
|
||||
g_object_unref (dialog);
|
||||
moo_file_array_free (files);
|
||||
return info_array;
|
||||
|
@ -103,8 +98,8 @@ _moo_edit_save_as_dialog (MooEdit *doc,
|
|||
const char *encoding;
|
||||
MooFileDialog *dialog;
|
||||
MooSaveInfo *info;
|
||||
g::FilePtr start;
|
||||
g::FilePtr file;
|
||||
GFile *start = NULL;
|
||||
GFile *file = NULL;
|
||||
|
||||
g_return_val_if_fail (MOO_IS_EDIT (doc), NULL);
|
||||
|
||||
|
@ -113,19 +108,20 @@ _moo_edit_save_as_dialog (MooEdit *doc,
|
|||
|
||||
if (moo_prefs_get_bool (moo_edit_setting (MOO_EDIT_PREFS_DIALOGS_OPEN_FOLLOWS_DOC)))
|
||||
{
|
||||
file = wrap_new (moo_edit_get_file (doc));
|
||||
file = moo_edit_get_file (doc);
|
||||
if (file)
|
||||
start = file->get_parent ();
|
||||
start = g_file_get_parent (file);
|
||||
g_object_unref (file);
|
||||
file = NULL;
|
||||
}
|
||||
|
||||
if (!start)
|
||||
start = wrap_new (moo_prefs_get_file (moo_edit_setting (MOO_EDIT_PREFS_LAST_DIR)));
|
||||
start = moo_prefs_get_file (moo_edit_setting (MOO_EDIT_PREFS_LAST_DIR));
|
||||
|
||||
dialog = moo_file_dialog_new (MOO_FILE_DIALOG_SAVE,
|
||||
GTK_WIDGET (moo_edit_get_view (doc)),
|
||||
FALSE, GTK_STOCK_SAVE_AS,
|
||||
start.gobj(), display_basename);
|
||||
start, display_basename);
|
||||
g_object_set (dialog, "enable-encodings", TRUE, NULL);
|
||||
moo_file_dialog_set_encoding (dialog, moo_edit_get_encoding (doc));
|
||||
moo_file_dialog_set_help_id (dialog, "dialog-save");
|
||||
|
@ -135,76 +131,25 @@ _moo_edit_save_as_dialog (MooEdit *doc,
|
|||
if (!moo_file_dialog_run (dialog))
|
||||
{
|
||||
g_object_unref (dialog);
|
||||
g_object_unref (start);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
encoding = moo_file_dialog_get_encoding (dialog);
|
||||
file = moo_file_dialog_get_file (dialog);
|
||||
g_return_val_if_fail (file != nullptr, NULL);
|
||||
info = moo_save_info_new_file (file.gobj(), encoding);
|
||||
g_return_val_if_fail (file != NULL, NULL);
|
||||
info = moo_save_info_new_file (file, encoding);
|
||||
|
||||
start = file->get_parent ();
|
||||
moo_prefs_set_file (moo_edit_setting (MOO_EDIT_PREFS_LAST_DIR), start.gobj());
|
||||
g_object_unref (start);
|
||||
start = g_file_get_parent (file);
|
||||
moo_prefs_set_file (moo_edit_setting (MOO_EDIT_PREFS_LAST_DIR), start);
|
||||
|
||||
g_object_unref (start);
|
||||
g_object_unref (file);
|
||||
g_object_unref (dialog);
|
||||
return info;
|
||||
}
|
||||
|
||||
#else // __WIN32__
|
||||
|
||||
MooOpenInfoArray *
|
||||
_moo_edit_open_dialog(GtkWidget* parent,
|
||||
MooEdit* current_doc)
|
||||
{
|
||||
gstr start_folder;
|
||||
|
||||
if (current_doc && moo_prefs_get_bool(moo_edit_setting(MOO_EDIT_PREFS_DIALOGS_OPEN_FOLLOWS_DOC)))
|
||||
{
|
||||
g::FilePtr file(moo_edit_get_file(current_doc), ref_transfer::take_ownership);
|
||||
|
||||
if (file)
|
||||
start_folder = file->get_parent()->get_path();
|
||||
}
|
||||
|
||||
GtkWidget* toplevel = parent ? gtk_widget_get_toplevel(parent) : nullptr;
|
||||
HWND hwnd = toplevel ? reinterpret_cast<HWND> (GDK_WINDOW_HWND(toplevel->window)) : nullptr;
|
||||
g::gstrvec files = moo_show_win32_file_open_dialog(hwnd, start_folder);
|
||||
if (files.empty())
|
||||
return nullptr;
|
||||
|
||||
MooOpenInfoArray *result = moo_open_info_array_new();
|
||||
for (const gstr& path : files)
|
||||
moo_open_info_array_take(result, moo_open_info_new(path, MOO_ENCODING_AUTO, -1, MOO_OPEN_FLAGS_NONE));
|
||||
return result;
|
||||
}
|
||||
|
||||
|
||||
MooSaveInfo*
|
||||
_moo_edit_save_as_dialog(MooEdit* doc,
|
||||
const char* display_basename)
|
||||
{
|
||||
MooEditView* view = moo_edit_get_view (doc);
|
||||
GtkWidget* toplevel = view ? gtk_widget_get_toplevel(GTK_WIDGET(view)) : nullptr;
|
||||
HWND hwnd = toplevel ? reinterpret_cast<HWND> (GDK_WINDOW_HWND(toplevel->window)) : nullptr;
|
||||
|
||||
gstr start_folder;
|
||||
|
||||
if (moo_prefs_get_bool(moo_edit_setting(MOO_EDIT_PREFS_DIALOGS_OPEN_FOLLOWS_DOC)))
|
||||
{
|
||||
g::FilePtr file = wrap_new(moo_edit_get_file(doc));
|
||||
if (file)
|
||||
start_folder = file->get_parent()->get_path();
|
||||
}
|
||||
|
||||
gstr save_as = moo_show_win32_file_save_as_dialog(hwnd, start_folder, gstr::wrap(display_basename));
|
||||
if (save_as.empty())
|
||||
return nullptr;
|
||||
|
||||
return moo_save_info_new(save_as, nullptr);
|
||||
}
|
||||
|
||||
#endif // __WIN32__
|
||||
|
||||
|
||||
MooSaveChangesResponse
|
||||
_moo_edit_save_changes_dialog (MooEdit *doc)
|
||||
|
@ -225,37 +170,50 @@ enum {
|
|||
NUM_COLUMNS
|
||||
};
|
||||
|
||||
static void
|
||||
name_data_func (G_GNUC_UNUSED GtkTreeViewColumn *column,
|
||||
GtkCellRenderer *cell,
|
||||
GtkTreeModel *model,
|
||||
GtkTreeIter *iter)
|
||||
{
|
||||
MooEdit *doc = NULL;
|
||||
|
||||
gtk_tree_model_get (model, iter, COLUMN_EDIT, &doc, -1);
|
||||
g_return_if_fail (MOO_IS_EDIT (doc));
|
||||
|
||||
g_object_set (cell, "text", moo_edit_get_display_basename (doc), NULL);
|
||||
g_object_unref (doc);
|
||||
}
|
||||
|
||||
|
||||
static void
|
||||
save_toggled (GtkCellRendererToggle *pcell,
|
||||
save_toggled (GtkCellRendererToggle *cell,
|
||||
gchar *path,
|
||||
GtkListStore *pmodel)
|
||||
GtkTreeModel *model)
|
||||
{
|
||||
GtkTreePath *tree_path;
|
||||
GtkTreeIter iter;
|
||||
gboolean save = TRUE;
|
||||
gboolean active;
|
||||
gboolean sensitive;
|
||||
GtkDialog *dialog;
|
||||
|
||||
g_return_if_fail (GTK_IS_LIST_STORE (pmodel));
|
||||
|
||||
gtk::ListStore model (*pmodel);
|
||||
gtk::CellRendererToggle cell (*pcell);
|
||||
g_return_if_fail (GTK_IS_LIST_STORE (model));
|
||||
|
||||
tree_path = gtk_tree_path_new_from_string (path);
|
||||
g_return_if_fail (tree_path != NULL);
|
||||
|
||||
GtkTreeIter iter;
|
||||
model.get_iter (iter, *tree_path);
|
||||
bool save = true;
|
||||
model.get (iter, COLUMN_SAVE, save);
|
||||
gtk_tree_model_get_iter (model, &iter, tree_path);
|
||||
gtk_tree_model_get (model, &iter, COLUMN_SAVE, &save, -1);
|
||||
|
||||
bool active = cell.get_active ();
|
||||
active = gtk_cell_renderer_toggle_get_active (cell);
|
||||
|
||||
if (active == save)
|
||||
model.set (iter, COLUMN_SAVE, !save);
|
||||
gtk_list_store_set (GTK_LIST_STORE (model), &iter, COLUMN_SAVE, !save, -1);
|
||||
|
||||
gtk_tree_path_free (tree_path);
|
||||
|
||||
dialog = GTK_DIALOG (model.get_data ("moo-dialog"));
|
||||
dialog = g_object_get_data (G_OBJECT (model), "moo-dialog");
|
||||
g_return_if_fail (dialog != NULL);
|
||||
|
||||
if (!save)
|
||||
|
@ -265,65 +223,64 @@ save_toggled (GtkCellRendererToggle *pcell,
|
|||
else
|
||||
{
|
||||
sensitive = FALSE;
|
||||
model.get_iter_first (iter);
|
||||
gtk_tree_model_get_iter_first (model, &iter);
|
||||
|
||||
do
|
||||
{
|
||||
model.get (iter, COLUMN_SAVE, save);
|
||||
gtk_tree_model_get (model, &iter, COLUMN_SAVE, &save, -1);
|
||||
if (save)
|
||||
{
|
||||
sensitive = TRUE;
|
||||
break;
|
||||
}
|
||||
}
|
||||
while (model.iter_next (iter));
|
||||
while (gtk_tree_model_iter_next (model, &iter));
|
||||
}
|
||||
|
||||
gtk_dialog_set_response_sensitive (dialog, GTK_RESPONSE_YES, sensitive);
|
||||
}
|
||||
|
||||
static void
|
||||
files_treeview_init (gtk::TreeView treeview, GtkWidget *dialog, MooEditArray *docs)
|
||||
files_treeview_init (GtkTreeView *treeview, GtkWidget *dialog, MooEditArray *docs)
|
||||
{
|
||||
gtk::ListStorePtr store = gtk::ListStore::create ({ G_TYPE_BOOLEAN, MOO_TYPE_EDIT });
|
||||
GtkListStore *store;
|
||||
GtkTreeViewColumn *column;
|
||||
GtkCellRenderer *cell;
|
||||
guint i;
|
||||
|
||||
for (guint i = 0; i < docs->n_elms; ++i)
|
||||
store = gtk_list_store_new (NUM_COLUMNS, G_TYPE_BOOLEAN, MOO_TYPE_EDIT);
|
||||
|
||||
for (i = 0; i < docs->n_elms; ++i)
|
||||
{
|
||||
GtkTreeIter iter;
|
||||
store->append (iter);
|
||||
store->set (iter,
|
||||
COLUMN_SAVE, TRUE,
|
||||
COLUMN_EDIT, docs->elms[i]);
|
||||
gtk_list_store_append (store, &iter);
|
||||
gtk_list_store_set (store, &iter,
|
||||
COLUMN_SAVE, TRUE,
|
||||
COLUMN_EDIT, docs->elms[i],
|
||||
-1);
|
||||
}
|
||||
|
||||
treeview.set_model (store);
|
||||
gtk_tree_view_set_model (treeview, GTK_TREE_MODEL (store));
|
||||
|
||||
gtk::TreeViewColumnPtr column = gtk::TreeViewColumn::create ();
|
||||
treeview.append_column (*column);
|
||||
gtk::CellRendererPtr cell = gtk::CellRendererToggle::create ();
|
||||
column->pack_start (*cell, FALSE);
|
||||
cell->set ("activatable", TRUE);
|
||||
column->add_attribute (*cell, "active", COLUMN_SAVE);
|
||||
cell->connect ("toggled", G_CALLBACK (save_toggled), store.gobj());
|
||||
column = gtk_tree_view_column_new ();
|
||||
gtk_tree_view_append_column (treeview, column);
|
||||
cell = gtk_cell_renderer_toggle_new ();
|
||||
gtk_tree_view_column_pack_start (column, cell, FALSE);
|
||||
g_object_set (cell, "activatable", TRUE, NULL);
|
||||
gtk_tree_view_column_add_attribute (column, cell, "active", COLUMN_SAVE);
|
||||
g_signal_connect (cell, "toggled", G_CALLBACK (save_toggled), store);
|
||||
|
||||
column = gtk::TreeViewColumn::create ();
|
||||
treeview.append_column (*column);
|
||||
cell = gtk::CellRendererText::create ();
|
||||
column->pack_start (*cell, TRUE);
|
||||
column = gtk_tree_view_column_new ();
|
||||
gtk_tree_view_append_column (treeview, column);
|
||||
cell = gtk_cell_renderer_text_new ();
|
||||
gtk_tree_view_column_pack_start (column, cell, TRUE);
|
||||
gtk_tree_view_column_set_cell_data_func (column, cell,
|
||||
(GtkTreeCellDataFunc) name_data_func,
|
||||
NULL, NULL);
|
||||
|
||||
column->set_cell_data_func (*cell,
|
||||
[] (gtk::TreeViewColumn,
|
||||
gtk::CellRenderer cell,
|
||||
gtk::TreeModel model,
|
||||
const GtkTreeIter& iter)
|
||||
{
|
||||
gobj_ptr<MooEdit> doc;
|
||||
model.get (iter, COLUMN_EDIT, doc);
|
||||
g_return_if_fail (MOO_IS_EDIT (doc.gobj ()));
|
||||
cell.set ("text", moo_edit_get_display_basename (doc.gobj ()));
|
||||
});
|
||||
g_object_set_data (G_OBJECT (store), "moo-dialog", dialog);
|
||||
|
||||
store->set_data ("moo-dialog", dialog);
|
||||
g_object_unref (store);
|
||||
}
|
||||
|
||||
|
||||
|
@ -369,7 +326,7 @@ find_widget_for_response (GtkDialog *dialog,
|
|||
|
||||
for (l = children; ret == NULL && l != NULL; l = l->next)
|
||||
{
|
||||
GtkWidget *widget = GTK_WIDGET (l->data);
|
||||
GtkWidget *widget = l->data;
|
||||
int response_here = gtk_dialog_get_response_for_widget (dialog, widget);
|
||||
if (response_here == response)
|
||||
ret = widget;
|
||||
|
@ -383,11 +340,17 @@ MooSaveChangesResponse
|
|||
_moo_edit_save_multiple_changes_dialog (MooEditArray *docs,
|
||||
MooEditArray *to_save)
|
||||
{
|
||||
GtkWidget *dialog;
|
||||
char *msg, *question;
|
||||
int response;
|
||||
MooSaveChangesResponse retval;
|
||||
SaveMultDialogXml *xml;
|
||||
|
||||
g_return_val_if_fail (docs != NULL && docs->n_elms > 1, MOO_SAVE_CHANGES_RESPONSE_CANCEL);
|
||||
g_return_val_if_fail (to_save != NULL, MOO_SAVE_CHANGES_RESPONSE_CANCEL);
|
||||
|
||||
SaveMultDialogXml *xml = save_mult_dialog_xml_new ();
|
||||
GtkWidget *dialog = GTK_WIDGET (xml->SaveMultDialog);
|
||||
xml = save_mult_dialog_xml_new ();
|
||||
dialog = GTK_WIDGET (xml->SaveMultDialog);
|
||||
|
||||
moo_window_set_parent (dialog, GTK_WIDGET (moo_edit_get_view (docs->elms[0])));
|
||||
|
||||
|
@ -404,19 +367,20 @@ _moo_edit_save_multiple_changes_dialog (MooEditArray *docs,
|
|||
GTK_RESPONSE_NO,
|
||||
GTK_RESPONSE_CANCEL, -1);
|
||||
|
||||
gstr question = gstr::printf (dngettext (GETTEXT_PACKAGE,
|
||||
/* Translators: number of documents here is always greater than one, so
|
||||
* ignore singular form (which is simply copy of the plural here) */
|
||||
"There are %u documents with unsaved changes. "
|
||||
"Save changes before closing?",
|
||||
"There are %u documents with unsaved changes. "
|
||||
"Save changes before closing?",
|
||||
docs->n_elms),
|
||||
(guint) docs->n_elms);
|
||||
gstr msg = g::markup_printf_escaped ("<span weight=\"bold\" size=\"larger\">%s</span>", question);
|
||||
question = g_strdup_printf (dngettext (GETTEXT_PACKAGE,
|
||||
/* Translators: number of documents here is always greater than one, so
|
||||
ignore singular form (which is simply copy of the plural here) */
|
||||
"There are %u documents with unsaved changes. "
|
||||
"Save changes before closing?",
|
||||
"There are %u documents with unsaved changes. "
|
||||
"Save changes before closing?",
|
||||
docs->n_elms),
|
||||
(guint) docs->n_elms);
|
||||
msg = g_markup_printf_escaped ("<span weight=\"bold\" size=\"larger\">%s</span>",
|
||||
question);
|
||||
gtk_label_set_markup (xml->label, msg);
|
||||
|
||||
files_treeview_init (wrap (*xml->treeview), dialog, docs);
|
||||
files_treeview_init (xml->treeview, dialog, docs);
|
||||
|
||||
{
|
||||
GtkWidget *button;
|
||||
|
@ -424,8 +388,7 @@ _moo_edit_save_multiple_changes_dialog (MooEditArray *docs,
|
|||
gtk_widget_grab_focus (button);
|
||||
}
|
||||
|
||||
MooSaveChangesResponse retval;
|
||||
int response = gtk_dialog_run (GTK_DIALOG (dialog));
|
||||
response = gtk_dialog_run (GTK_DIALOG (dialog));
|
||||
|
||||
switch (response)
|
||||
{
|
||||
|
@ -438,9 +401,10 @@ _moo_edit_save_multiple_changes_dialog (MooEditArray *docs,
|
|||
break;
|
||||
default:
|
||||
retval = MOO_SAVE_CHANGES_RESPONSE_CANCEL;
|
||||
break;
|
||||
}
|
||||
|
||||
g_free (question);
|
||||
g_free (msg);
|
||||
gtk_widget_destroy (dialog);
|
||||
return retval;
|
||||
}
|
||||
|
@ -450,13 +414,24 @@ _moo_edit_save_multiple_changes_dialog (MooEditArray *docs,
|
|||
/* Error dialogs
|
||||
*/
|
||||
|
||||
void _moo_edit_save_error_dialog(Edit& doc, g::File file, GError *error)
|
||||
void
|
||||
_moo_edit_save_error_dialog (MooEdit *doc,
|
||||
GFile *file,
|
||||
GError *error)
|
||||
{
|
||||
gstr filename = moo_file_get_display_name (file);
|
||||
gstr msg = gstr::printf(_("Could not save file\n%s"), filename);
|
||||
char *filename, *msg = NULL;
|
||||
|
||||
moo_error_dialog(msg, moo_error_message(error),
|
||||
GTK_WIDGET(moo_edit_get_view(doc.gobj())));
|
||||
g_return_if_fail (G_IS_FILE (file));
|
||||
|
||||
filename = moo_file_get_display_name (file);
|
||||
|
||||
msg = g_strdup_printf (_("Could not save file\n%s"), filename);
|
||||
|
||||
moo_error_dialog (msg, moo_error_message (error),
|
||||
GTK_WIDGET (moo_edit_get_view (doc)));
|
||||
|
||||
g_free (msg);
|
||||
g_free (filename);
|
||||
}
|
||||
|
||||
static gboolean
|
||||
|
@ -498,56 +473,67 @@ moo_edit_question_dialog (MooEdit *doc,
|
|||
return res == GTK_RESPONSE_YES;
|
||||
}
|
||||
|
||||
bool _moo_edit_save_error_enc_dialog(Edit& doc,
|
||||
g::File file,
|
||||
const char* encoding)
|
||||
gboolean
|
||||
_moo_edit_save_error_enc_dialog (MooEdit *doc,
|
||||
GFile *file,
|
||||
const char *encoding)
|
||||
{
|
||||
char *filename;
|
||||
char *secondary;
|
||||
gboolean result;
|
||||
|
||||
g_return_val_if_fail (G_IS_FILE (file), FALSE);
|
||||
g_return_val_if_fail (encoding != NULL, FALSE);
|
||||
|
||||
gstr filename = moo_file_get_display_name (file);
|
||||
filename = moo_file_get_display_name (file);
|
||||
|
||||
auto secondary = gstr::printf (
|
||||
_("Could not save file %s in encoding %s. "
|
||||
"Do you want to save it in UTF-8 encoding instead?"),
|
||||
filename, encoding);
|
||||
secondary = g_strdup_printf (_("Could not save file %s in encoding %s. "
|
||||
"Do you want to save it in UTF-8 encoding instead?"),
|
||||
filename, encoding);
|
||||
|
||||
return moo_edit_question_dialog (&doc, _("Save file in UTF-8 encoding?"),
|
||||
secondary, GTK_STOCK_OK, GTK_RESPONSE_YES);
|
||||
result = moo_edit_question_dialog (doc, _("Save file in UTF-8 encoding?"),
|
||||
secondary, GTK_STOCK_OK, GTK_RESPONSE_YES);
|
||||
|
||||
g_free (secondary);
|
||||
g_free (filename);
|
||||
return result;
|
||||
}
|
||||
|
||||
|
||||
MooEditTryEncodingResponse
|
||||
_moo_edit_try_encoding_dialog (g::File file,
|
||||
const char* encoding,
|
||||
/*out*/ gstr& new_encoding)
|
||||
_moo_edit_try_encoding_dialog (G_GNUC_UNUSED GFile *file,
|
||||
const char *encoding,
|
||||
char **new_encoding)
|
||||
{
|
||||
MooEditWindow *window;
|
||||
GtkWidget *dialog;
|
||||
TryEncodingDialogXml *xml;
|
||||
int dialog_response;
|
||||
gstr msg;
|
||||
gstr secondary;
|
||||
char *filename = NULL;
|
||||
char *msg = NULL;
|
||||
char *secondary = NULL;
|
||||
|
||||
gstr filename = moo_file_get_display_name(file);
|
||||
filename = moo_file_get_display_name (file);
|
||||
|
||||
if (!filename.empty())
|
||||
if (filename)
|
||||
{
|
||||
/* Could not open file foo.txt */
|
||||
gstr tmp = gstr::printf(_("Could not open file\n%s"), filename);
|
||||
msg = g::markup_printf_escaped("<b><big>%s</big></b>", tmp);
|
||||
char *tmp = g_strdup_printf (_("Could not open file\n%s"), filename);
|
||||
msg = g_markup_printf_escaped ("<b><big>%s</big></b>", tmp);
|
||||
g_free (tmp);
|
||||
}
|
||||
else
|
||||
{
|
||||
const char *tmp = _("Could not open file");
|
||||
msg = g::markup_printf_escaped("<b><big>%s</big></b>", tmp);
|
||||
msg = g_markup_printf_escaped ("<b><big>%s</big></b>", tmp);
|
||||
}
|
||||
|
||||
if (encoding != NULL)
|
||||
secondary = gstr::printf (_("Could not open file using character encoding %s. "
|
||||
"Try to select another encoding below."), encoding);
|
||||
if (encoding)
|
||||
secondary = g_strdup_printf (_("Could not open file using character encoding %s. "
|
||||
"Try to select another encoding below."), encoding);
|
||||
else
|
||||
secondary = gstr::printf (_("Could not detect file character encoding. "
|
||||
"Try to select an encoding below."));
|
||||
secondary = g_strdup_printf (_("Could not detect file character encoding. "
|
||||
"Try to select an encoding below."));
|
||||
|
||||
xml = try_encoding_dialog_xml_new ();
|
||||
g_return_val_if_fail (xml && xml->TryEncodingDialog, MOO_EDIT_TRY_ENCODING_RESPONSE_CANCEL);
|
||||
|
@ -575,9 +561,11 @@ _moo_edit_try_encoding_dialog (g::File file,
|
|||
|
||||
dialog_response = gtk_dialog_run (GTK_DIALOG (dialog));
|
||||
|
||||
new_encoding.set(_moo_encodings_combo_get_enc (GTK_COMBO_BOX (xml->encoding_combo), MOO_ENCODING_COMBO_OPEN));
|
||||
*new_encoding = g_strdup (_moo_encodings_combo_get_enc (GTK_COMBO_BOX (xml->encoding_combo), MOO_ENCODING_COMBO_OPEN));
|
||||
|
||||
gtk_widget_destroy (dialog);
|
||||
g_free (secondary);
|
||||
g_free (msg);
|
||||
|
||||
return dialog_response == GTK_RESPONSE_OK ?
|
||||
MOO_EDIT_TRY_ENCODING_RESPONSE_TRY_ANOTHER :
|
||||
|
@ -586,26 +574,28 @@ _moo_edit_try_encoding_dialog (g::File file,
|
|||
|
||||
|
||||
void
|
||||
_moo_edit_open_error_dialog (GtkWidget* widget,
|
||||
g::File* file,
|
||||
GError* error)
|
||||
_moo_edit_open_error_dialog (GtkWidget *widget,
|
||||
GFile *file,
|
||||
GError *error)
|
||||
{
|
||||
gstr msg;
|
||||
gstr secondary;
|
||||
char *filename, *msg = NULL;
|
||||
char *secondary;
|
||||
|
||||
g_warn_if_fail (file != nullptr);
|
||||
gstr filename = file ? moo_file_get_display_name (*file) : gstr ();
|
||||
filename = moo_file_get_display_name (file);
|
||||
|
||||
if (!filename.empty())
|
||||
if (filename)
|
||||
/* Could not open file foo.txt */
|
||||
msg.set_printf (_("Could not open file\n%s"), filename);
|
||||
msg = g_strdup_printf (_("Could not open file\n%s"), filename);
|
||||
else
|
||||
msg.set_const (_("Could not open file"));
|
||||
msg = g_strdup (_("Could not open file"));
|
||||
|
||||
if (error)
|
||||
secondary.set (error->message);
|
||||
secondary = error ? g_strdup (error->message) : NULL;
|
||||
|
||||
moo_error_dialog (msg, secondary, widget);
|
||||
|
||||
g_free (msg);
|
||||
g_free (secondary);
|
||||
g_free (filename);
|
||||
}
|
||||
|
||||
|
|
@ -1,7 +1,7 @@
|
|||
/*
|
||||
* mooeditdialogs.h
|
||||
*
|
||||
* Copyright (C) 2004-2016 by Yevgen Muntyan <emuntyan@users.sourceforge.net>
|
||||
* Copyright (C) 2004-2010 by Yevgen Muntyan <emuntyan@users.sourceforge.net>
|
||||
*
|
||||
* This file is part of medit. medit is free software; you can
|
||||
* redistribute it and/or modify it under the terms of the
|
||||
|
@ -13,7 +13,8 @@
|
|||
* License along with medit. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#pragma once
|
||||
#ifndef MOO_EDIT_DIALOGS_H
|
||||
#define MOO_EDIT_DIALOGS_H
|
||||
|
||||
#include "mooutils/moodialogs.h"
|
||||
#include "mooedit/mooedittypes.h"
|
||||
|
@ -38,8 +39,20 @@ MooSaveChangesResponse _moo_edit_save_multiple_changes_dialog (MooEdit
|
|||
gboolean _moo_edit_reload_modified_dialog (MooEdit *doc);
|
||||
gboolean _moo_edit_overwrite_modified_dialog (MooEdit *doc);
|
||||
|
||||
void _moo_edit_save_error_dialog (MooEdit *doc,
|
||||
GFile *file,
|
||||
GError *error);
|
||||
gboolean _moo_edit_save_error_enc_dialog (MooEdit *doc,
|
||||
GFile *file,
|
||||
const char *encoding);
|
||||
void _moo_edit_open_error_dialog (GtkWidget *widget,
|
||||
GFile *file,
|
||||
GError *error);
|
||||
void _moo_edit_reload_error_dialog (MooEdit *doc,
|
||||
GError *error);
|
||||
MooEditTryEncodingResponse _moo_edit_try_encoding_dialog (GFile *file,
|
||||
const char *encoding,
|
||||
char **new_encoding);
|
||||
|
||||
gboolean _moo_text_search_from_start_dialog (GtkWidget *parent,
|
||||
gboolean backwards);
|
||||
|
@ -52,21 +65,4 @@ GtkWidget *_moo_text_prompt_on_replace_dialog (GtkWidg
|
|||
|
||||
G_END_DECLS
|
||||
|
||||
#ifdef __cplusplus
|
||||
|
||||
#include <moocpp/moocpp.h>
|
||||
|
||||
MooEditTryEncodingResponse _moo_edit_try_encoding_dialog (g::File& file,
|
||||
const char* encoding,
|
||||
/*out*/ g::gstr& new_encoding);
|
||||
bool _moo_edit_save_error_enc_dialog (Edit& doc,
|
||||
g::File& file,
|
||||
const char* encoding);
|
||||
void _moo_edit_save_error_dialog (Edit& doc,
|
||||
g::File& file,
|
||||
GError* error);
|
||||
void _moo_edit_open_error_dialog (GtkWidget* widget,
|
||||
g::File& file,
|
||||
GError* error);
|
||||
|
||||
#endif // __cplusplus
|
||||
#endif /* MOO_EDIT_DIALOGS_H */
|
||||
|
|
|
@ -1,74 +1,49 @@
|
|||
#pragma once
|
||||
#ifndef MOO_EDIT_FILE_INFO_IMPL_H
|
||||
#define MOO_EDIT_FILE_INFO_IMPL_H
|
||||
|
||||
#include "mooeditfileinfo.h"
|
||||
#include "moocpp/moocpp.h"
|
||||
|
||||
using namespace moo;
|
||||
G_BEGIN_DECLS
|
||||
|
||||
struct MooOpenInfo
|
||||
{
|
||||
g::FilePtr file;
|
||||
gstr encoding;
|
||||
GObject parent;
|
||||
|
||||
GFile *file;
|
||||
char *encoding;
|
||||
int line;
|
||||
MooOpenFlags flags;
|
||||
|
||||
MooOpenInfo(GFile* file, const char* encoding, int line, MooOpenFlags flags)
|
||||
: file(wrap_new(g_file_dup(file)))
|
||||
, encoding(gstr::wrap(encoding))
|
||||
, line(line)
|
||||
, flags(flags)
|
||||
{
|
||||
}
|
||||
|
||||
MooOpenInfo(const MooOpenInfo& other)
|
||||
: file(other.file->dup())
|
||||
, encoding(other.encoding)
|
||||
, line(other.line)
|
||||
, flags(other.flags)
|
||||
{
|
||||
}
|
||||
|
||||
MooOpenInfo& operator=(const MooOpenInfo&) = delete;
|
||||
MooOpenInfo(MooOpenInfo&&) = delete;
|
||||
MooOpenInfo& operator=(MooOpenInfo&&) = delete;
|
||||
};
|
||||
|
||||
struct MooReloadInfo : public GObject
|
||||
struct MooOpenInfoClass
|
||||
{
|
||||
MooReloadInfo(const char* encoding, int line)
|
||||
: encoding(gstr::wrap(encoding))
|
||||
, line(line)
|
||||
{
|
||||
}
|
||||
GObjectClass parent_class;
|
||||
};
|
||||
|
||||
MooReloadInfo(const MooReloadInfo& other)
|
||||
: encoding(other.encoding)
|
||||
, line(other.line)
|
||||
{
|
||||
}
|
||||
struct MooReloadInfo {
|
||||
GObject parent;
|
||||
|
||||
gstr encoding;
|
||||
char *encoding;
|
||||
int line;
|
||||
|
||||
MooReloadInfo(MooReloadInfo&&) = delete;
|
||||
};
|
||||
|
||||
struct MooSaveInfo : public GObject
|
||||
struct MooReloadInfoClass
|
||||
{
|
||||
g::FilePtr file;
|
||||
gstr encoding;
|
||||
|
||||
MooSaveInfo(GFile* file, const char* encoding)
|
||||
: file(wrap_new(g_file_dup(file)))
|
||||
, encoding(gstr::wrap(encoding))
|
||||
{
|
||||
}
|
||||
|
||||
MooSaveInfo(const MooSaveInfo& other)
|
||||
: file(other.file->dup())
|
||||
, encoding(other.encoding)
|
||||
{
|
||||
}
|
||||
|
||||
MooSaveInfo(MooSaveInfo&&) = delete;
|
||||
GObjectClass parent_class;
|
||||
};
|
||||
|
||||
struct MooSaveInfo {
|
||||
GObject parent;
|
||||
|
||||
GFile *file;
|
||||
char *encoding;
|
||||
};
|
||||
|
||||
struct MooSaveInfoClass
|
||||
{
|
||||
GObjectClass parent_class;
|
||||
};
|
||||
|
||||
G_END_DECLS
|
||||
|
||||
#endif /* MOO_EDIT_FILE_INFO_IMPL_H */
|
||||
|
|
|
@ -0,0 +1,481 @@
|
|||
/**
|
||||
* class:MooOpenInfo: (parent GObject): information for opening a file
|
||||
*
|
||||
* Object which contains filename, character encoding, line
|
||||
* number, and options to use in moo_editor_open_file().
|
||||
**/
|
||||
|
||||
/**
|
||||
* class:MooSaveInfo: (parent GObject): information for saving a file
|
||||
*
|
||||
* Object which contains a filename and character encoding to
|
||||
* use in moo_editor_save() and moo_editor_save_as().
|
||||
**/
|
||||
|
||||
/**
|
||||
* class:MooReloadInfo: (parent GObject): information for reloading a file
|
||||
*
|
||||
* Object which contains character encoding and line number to
|
||||
* use in moo_editor_reload().
|
||||
**/
|
||||
|
||||
#include "mooeditfileinfo-impl.h"
|
||||
#include <mooutils/mooutils-misc.h>
|
||||
|
||||
static void moo_open_info_class_init (MooOpenInfoClass *klass);
|
||||
static void moo_save_info_class_init (MooSaveInfoClass *klass);
|
||||
static void moo_reload_info_class_init (MooReloadInfoClass *klass);
|
||||
|
||||
MOO_DEFINE_OBJECT_ARRAY (MooOpenInfo, moo_open_info)
|
||||
|
||||
G_DEFINE_TYPE (MooOpenInfo, moo_open_info, G_TYPE_OBJECT)
|
||||
G_DEFINE_TYPE (MooSaveInfo, moo_save_info, G_TYPE_OBJECT)
|
||||
G_DEFINE_TYPE (MooReloadInfo, moo_reload_info, G_TYPE_OBJECT)
|
||||
|
||||
/**
|
||||
* moo_open_info_new_file: (static-method-of MooOpenInfo) (moo-kwargs)
|
||||
*
|
||||
* @file:
|
||||
* @encoding: (type const-utf8) (allow-none) (default NULL)
|
||||
* @line: (type index) (default -1)
|
||||
* @flags: (default 0)
|
||||
*
|
||||
* Returns: (transfer full)
|
||||
**/
|
||||
MooOpenInfo *
|
||||
moo_open_info_new_file (GFile *file,
|
||||
const char *encoding,
|
||||
int line,
|
||||
MooOpenFlags flags)
|
||||
{
|
||||
MooOpenInfo *info;
|
||||
|
||||
g_return_val_if_fail (G_IS_FILE (file), NULL);
|
||||
|
||||
info = g_object_new (MOO_TYPE_OPEN_INFO, NULL);
|
||||
|
||||
info->file = g_file_dup (file);
|
||||
info->encoding = g_strdup (encoding);
|
||||
info->line = line;
|
||||
info->flags = flags;
|
||||
|
||||
return info;
|
||||
}
|
||||
|
||||
/**
|
||||
* moo_open_info_new: (constructor-of MooOpenInfo) (moo-kwargs)
|
||||
*
|
||||
* @path: (type const-filename)
|
||||
* @encoding: (type const-utf8) (allow-none) (default NULL)
|
||||
* @line: (type index) (default -1)
|
||||
* @flags: (default 0)
|
||||
*
|
||||
* Returns: (transfer full)
|
||||
**/
|
||||
MooOpenInfo *
|
||||
moo_open_info_new (const char *path,
|
||||
const char *encoding,
|
||||
int line,
|
||||
MooOpenFlags flags)
|
||||
{
|
||||
GFile *file = g_file_new_for_path (path);
|
||||
MooOpenInfo *info = moo_open_info_new_file (file, encoding, line, flags);
|
||||
g_object_unref (file);
|
||||
return info;
|
||||
}
|
||||
|
||||
/**
|
||||
* moo_open_info_new_uri: (static-method-of MooOpenInfo) (moo-kwargs)
|
||||
*
|
||||
* @uri: (type const-utf8)
|
||||
* @encoding: (type const-utf8) (allow-none) (default NULL)
|
||||
* @line: (type index) (default -1)
|
||||
* @flags: (default 0)
|
||||
*
|
||||
* Returns: (transfer full)
|
||||
**/
|
||||
MooOpenInfo *
|
||||
moo_open_info_new_uri (const char *uri,
|
||||
const char *encoding,
|
||||
int line,
|
||||
MooOpenFlags flags)
|
||||
{
|
||||
GFile *file = g_file_new_for_uri (uri);
|
||||
MooOpenInfo *info = moo_open_info_new_file (file, encoding, line, flags);
|
||||
g_object_unref (file);
|
||||
return info;
|
||||
}
|
||||
|
||||
/**
|
||||
* moo_open_info_dup:
|
||||
*
|
||||
* Returns: (transfer full)
|
||||
**/
|
||||
MooOpenInfo *
|
||||
moo_open_info_dup (MooOpenInfo *info)
|
||||
{
|
||||
MooOpenInfo *copy;
|
||||
|
||||
g_return_val_if_fail (info != NULL, NULL);
|
||||
|
||||
copy = moo_open_info_new_file (info->file, info->encoding, info->line, info->flags);
|
||||
g_return_val_if_fail (copy != NULL, NULL);
|
||||
|
||||
return copy;
|
||||
}
|
||||
|
||||
void
|
||||
moo_open_info_free (MooOpenInfo *info)
|
||||
{
|
||||
if (info)
|
||||
g_object_unref (info);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* moo_open_info_get_filename: (moo.private 1)
|
||||
*
|
||||
* Returns: (type filename)
|
||||
**/
|
||||
char *
|
||||
moo_open_info_get_filename (MooOpenInfo *info)
|
||||
{
|
||||
g_return_val_if_fail (MOO_IS_OPEN_INFO (info), NULL);
|
||||
return g_file_get_path (info->file);
|
||||
}
|
||||
|
||||
/**
|
||||
* moo_open_info_get_uri: (moo.private 1)
|
||||
*
|
||||
* Returns: (type utf8)
|
||||
**/
|
||||
char *
|
||||
moo_open_info_get_uri (MooOpenInfo *info)
|
||||
{
|
||||
g_return_val_if_fail (MOO_IS_OPEN_INFO (info), NULL);
|
||||
return g_file_get_uri (info->file);
|
||||
}
|
||||
|
||||
/**
|
||||
* moo_open_info_get_file: (moo.private 1)
|
||||
*
|
||||
* Returns: (transfer full)
|
||||
**/
|
||||
GFile *
|
||||
moo_open_info_get_file (MooOpenInfo *info)
|
||||
{
|
||||
g_return_val_if_fail (MOO_IS_OPEN_INFO (info), NULL);
|
||||
return g_file_dup (info->file);
|
||||
}
|
||||
|
||||
/**
|
||||
* moo_open_info_get_encoding: (moo.private 1)
|
||||
*
|
||||
* Returns: (type const-utf8)
|
||||
**/
|
||||
const char *
|
||||
moo_open_info_get_encoding (MooOpenInfo *info)
|
||||
{
|
||||
g_return_val_if_fail (MOO_IS_OPEN_INFO (info), NULL);
|
||||
return info->encoding;
|
||||
}
|
||||
|
||||
/**
|
||||
* moo_open_info_set_encoding: (moo.private 1)
|
||||
*
|
||||
* @info:
|
||||
* @encoding: (type const-utf8) (allow-none)
|
||||
**/
|
||||
void
|
||||
moo_open_info_set_encoding (MooOpenInfo *info,
|
||||
const char *encoding)
|
||||
{
|
||||
g_return_if_fail (MOO_IS_OPEN_INFO (info));
|
||||
MOO_ASSIGN_STRING (info->encoding, encoding);
|
||||
}
|
||||
|
||||
/**
|
||||
* moo_open_info_get_line:
|
||||
*
|
||||
* Returns: (type index)
|
||||
**/
|
||||
int
|
||||
moo_open_info_get_line (MooOpenInfo *info)
|
||||
{
|
||||
g_return_val_if_fail (MOO_IS_OPEN_INFO (info), -1);
|
||||
return info->line;
|
||||
}
|
||||
|
||||
/**
|
||||
* moo_open_info_set_line:
|
||||
*
|
||||
* @info:
|
||||
* @line: (type index)
|
||||
**/
|
||||
void
|
||||
moo_open_info_set_line (MooOpenInfo *info,
|
||||
int line)
|
||||
{
|
||||
g_return_if_fail (MOO_IS_OPEN_INFO (info));
|
||||
info->line = line;
|
||||
}
|
||||
|
||||
/**
|
||||
* moo_open_info_get_flags:
|
||||
**/
|
||||
MooOpenFlags
|
||||
moo_open_info_get_flags (MooOpenInfo *info)
|
||||
{
|
||||
g_return_val_if_fail (MOO_IS_OPEN_INFO (info), 0);
|
||||
return info->flags;
|
||||
}
|
||||
|
||||
/**
|
||||
* moo_open_info_set_flags:
|
||||
**/
|
||||
void
|
||||
moo_open_info_set_flags (MooOpenInfo *info,
|
||||
MooOpenFlags flags)
|
||||
{
|
||||
g_return_if_fail (MOO_IS_OPEN_INFO (info));
|
||||
info->flags = flags;
|
||||
}
|
||||
|
||||
/**
|
||||
* moo_open_info_add_flags:
|
||||
**/
|
||||
void
|
||||
moo_open_info_add_flags (MooOpenInfo *info,
|
||||
MooOpenFlags flags)
|
||||
{
|
||||
g_return_if_fail (MOO_IS_OPEN_INFO (info));
|
||||
info->flags |= flags;
|
||||
}
|
||||
|
||||
|
||||
static void
|
||||
moo_open_info_finalize (GObject *object)
|
||||
{
|
||||
MooOpenInfo *info = (MooOpenInfo*) object;
|
||||
|
||||
g_object_unref (info->file);
|
||||
g_free (info->encoding);
|
||||
|
||||
G_OBJECT_CLASS (moo_open_info_parent_class)->finalize (object);
|
||||
}
|
||||
|
||||
static void
|
||||
moo_open_info_class_init (MooOpenInfoClass *klass)
|
||||
{
|
||||
G_OBJECT_CLASS (klass)->finalize = moo_open_info_finalize;
|
||||
}
|
||||
|
||||
static void
|
||||
moo_open_info_init (MooOpenInfo *info)
|
||||
{
|
||||
info->line = -1;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* moo_save_info_new_file: (static-method-of MooSaveInfo)
|
||||
*
|
||||
* @file:
|
||||
* @encoding: (type const-utf8) (allow-none) (default NULL)
|
||||
*
|
||||
* Returns: (transfer full)
|
||||
**/
|
||||
MooSaveInfo *
|
||||
moo_save_info_new_file (GFile *file,
|
||||
const char *encoding)
|
||||
{
|
||||
MooSaveInfo *info;
|
||||
|
||||
g_return_val_if_fail (G_IS_FILE (file), NULL);
|
||||
|
||||
info = g_object_new (MOO_TYPE_SAVE_INFO, NULL);
|
||||
|
||||
info->file = g_file_dup (file);
|
||||
info->encoding = g_strdup (encoding);
|
||||
|
||||
return info;
|
||||
}
|
||||
|
||||
/**
|
||||
* moo_save_info_new: (constructor-of MooSaveInfo)
|
||||
*
|
||||
* @path: (type const-filename)
|
||||
* @encoding: (type const-utf8) (allow-none) (default NULL)
|
||||
*
|
||||
* Returns: (transfer full)
|
||||
**/
|
||||
MooSaveInfo *
|
||||
moo_save_info_new (const char *path,
|
||||
const char *encoding)
|
||||
{
|
||||
GFile *file = g_file_new_for_path (path);
|
||||
MooSaveInfo *info = moo_save_info_new_file (file, encoding);
|
||||
g_object_unref (file);
|
||||
return info;
|
||||
}
|
||||
|
||||
/**
|
||||
* moo_save_info_new_uri: (static-method-of MooSaveInfo)
|
||||
*
|
||||
* @uri: (type const-utf8)
|
||||
* @encoding: (type const-utf8) (allow-none) (default NULL)
|
||||
*
|
||||
* Returns: (transfer full)
|
||||
**/
|
||||
MooSaveInfo *
|
||||
moo_save_info_new_uri (const char *uri,
|
||||
const char *encoding)
|
||||
{
|
||||
GFile *file = g_file_new_for_uri (uri);
|
||||
MooSaveInfo *info = moo_save_info_new_file (file, encoding);
|
||||
g_object_unref (file);
|
||||
return info;
|
||||
}
|
||||
|
||||
/**
|
||||
* moo_save_info_dup:
|
||||
*
|
||||
* Returns: (transfer full)
|
||||
**/
|
||||
MooSaveInfo *
|
||||
moo_save_info_dup (MooSaveInfo *info)
|
||||
{
|
||||
MooSaveInfo *copy;
|
||||
|
||||
g_return_val_if_fail (info != NULL, NULL);
|
||||
|
||||
copy = moo_save_info_new_file (info->file, info->encoding);
|
||||
g_return_val_if_fail (copy != NULL, NULL);
|
||||
|
||||
return copy;
|
||||
}
|
||||
|
||||
void
|
||||
moo_save_info_free (MooSaveInfo *info)
|
||||
{
|
||||
if (info)
|
||||
g_object_unref (info);
|
||||
}
|
||||
|
||||
static void
|
||||
moo_save_info_finalize (GObject *object)
|
||||
{
|
||||
MooSaveInfo *info = (MooSaveInfo*) object;
|
||||
|
||||
g_object_unref (info->file);
|
||||
g_free (info->encoding);
|
||||
|
||||
G_OBJECT_CLASS (moo_save_info_parent_class)->finalize (object);
|
||||
}
|
||||
|
||||
static void
|
||||
moo_save_info_class_init (MooSaveInfoClass *klass)
|
||||
{
|
||||
G_OBJECT_CLASS (klass)->finalize = moo_save_info_finalize;
|
||||
}
|
||||
|
||||
static void
|
||||
moo_save_info_init (G_GNUC_UNUSED MooSaveInfo *info)
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* moo_reload_info_new: (constructor-of MooReloadInfo)
|
||||
*
|
||||
* @encoding: (type const-utf8) (allow-none) (default NULL)
|
||||
* @line: (type index) (default -1)
|
||||
**/
|
||||
MooReloadInfo *
|
||||
moo_reload_info_new (const char *encoding,
|
||||
int line)
|
||||
{
|
||||
MooReloadInfo *info;
|
||||
|
||||
info = g_object_new (MOO_TYPE_RELOAD_INFO, NULL);
|
||||
|
||||
info->encoding = g_strdup (encoding);
|
||||
info->line = line;
|
||||
|
||||
return info;
|
||||
}
|
||||
|
||||
/**
|
||||
* moo_reload_info_dup:
|
||||
*
|
||||
* Returns: (transfer full)
|
||||
**/
|
||||
MooReloadInfo *
|
||||
moo_reload_info_dup (MooReloadInfo *info)
|
||||
{
|
||||
MooReloadInfo *copy;
|
||||
|
||||
g_return_val_if_fail (info != NULL, NULL);
|
||||
|
||||
copy = moo_reload_info_new (info->encoding, info->line);
|
||||
g_return_val_if_fail (copy != NULL, NULL);
|
||||
|
||||
return copy;
|
||||
}
|
||||
|
||||
void
|
||||
moo_reload_info_free (MooReloadInfo *info)
|
||||
{
|
||||
if (info)
|
||||
g_object_unref (info);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* moo_reload_info_get_line:
|
||||
*
|
||||
* Returns: (type index)
|
||||
**/
|
||||
int
|
||||
moo_reload_info_get_line (MooReloadInfo *info)
|
||||
{
|
||||
g_return_val_if_fail (MOO_IS_RELOAD_INFO (info), -1);
|
||||
return info->line;
|
||||
}
|
||||
|
||||
/**
|
||||
* moo_reload_info_set_line:
|
||||
*
|
||||
* @info:
|
||||
* @line: (type index)
|
||||
**/
|
||||
void
|
||||
moo_reload_info_set_line (MooReloadInfo *info,
|
||||
int line)
|
||||
{
|
||||
g_return_if_fail (MOO_IS_RELOAD_INFO (info));
|
||||
info->line = line;
|
||||
}
|
||||
|
||||
|
||||
static void
|
||||
moo_reload_info_finalize (GObject *object)
|
||||
{
|
||||
MooReloadInfo *info = (MooReloadInfo*) object;
|
||||
|
||||
g_free (info->encoding);
|
||||
|
||||
G_OBJECT_CLASS (moo_reload_info_parent_class)->finalize (object);
|
||||
}
|
||||
|
||||
static void
|
||||
moo_reload_info_class_init (MooReloadInfoClass *klass)
|
||||
{
|
||||
G_OBJECT_CLASS (klass)->finalize = moo_reload_info_finalize;
|
||||
}
|
||||
|
||||
static void
|
||||
moo_reload_info_init (MooReloadInfo *info)
|
||||
{
|
||||
info->line = -1;
|
||||
}
|
|
@ -1,342 +0,0 @@
|
|||
/**
|
||||
* boxed:MooOpenInfo: information for opening a file
|
||||
*
|
||||
* Object which contains filename, character encoding, line
|
||||
* number, and options to use in moo_editor_open_file().
|
||||
**/
|
||||
|
||||
/**
|
||||
* boxed:MooSaveInfo: information for saving a file
|
||||
*
|
||||
* Object which contains a filename and character encoding to
|
||||
* use in moo_editor_save() and moo_editor_save_as().
|
||||
**/
|
||||
|
||||
/**
|
||||
* boxed:MooReloadInfo: information for reloading a file
|
||||
*
|
||||
* Object which contains character encoding and line number to
|
||||
* use in moo_editor_reload().
|
||||
**/
|
||||
|
||||
#include "mooeditfileinfo-impl.h"
|
||||
#include <mooutils/mooutils-misc.h>
|
||||
#include <moocpp/moocpp.h>
|
||||
|
||||
using namespace moo;
|
||||
|
||||
MOO_DEFINE_BOXED_CPP_TYPE(MooOpenInfo, moo_open_info)
|
||||
MOO_DEFINE_BOXED_CPP_TYPE(MooSaveInfo, moo_save_info)
|
||||
MOO_DEFINE_BOXED_CPP_TYPE(MooReloadInfo, moo_reload_info)
|
||||
|
||||
MOO_DEFINE_PTR_ARRAY_FULL(MooOpenInfoArray, moo_open_info_array, MooOpenInfo,
|
||||
gboxed_helper<MooOpenInfo>::array_elm_copy,
|
||||
gboxed_helper<MooOpenInfo>::array_elm_free)
|
||||
|
||||
/**
|
||||
* moo_open_info_new_file: (static-method-of MooOpenInfo) (moo-kwargs)
|
||||
*
|
||||
* @file:
|
||||
* @encoding: (type const-utf8) (allow-none) (default NULL)
|
||||
* @line: (type index) (default -1)
|
||||
* @flags: (default 0)
|
||||
*
|
||||
* Returns: (transfer full)
|
||||
**/
|
||||
MooOpenInfo *
|
||||
moo_open_info_new_file (GFile *file,
|
||||
const char *encoding,
|
||||
int line,
|
||||
MooOpenFlags flags)
|
||||
{
|
||||
g_return_val_if_fail (G_IS_FILE (file), nullptr);
|
||||
return new MooOpenInfo(file, encoding, line, flags);
|
||||
}
|
||||
|
||||
/**
|
||||
* moo_open_info_new: (constructor-of MooOpenInfo) (moo-kwargs)
|
||||
*
|
||||
* @path: (type const-filename)
|
||||
* @encoding: (type const-utf8) (allow-none) (default NULL)
|
||||
* @line: (type index) (default -1)
|
||||
* @flags: (default 0)
|
||||
*
|
||||
* Returns: (transfer full)
|
||||
**/
|
||||
MooOpenInfo *
|
||||
moo_open_info_new (const char *path,
|
||||
const char *encoding,
|
||||
int line,
|
||||
MooOpenFlags flags)
|
||||
{
|
||||
g::FilePtr file = g::File::new_for_path(path);
|
||||
return moo_open_info_new_file (file.gobj(), encoding, line, flags);
|
||||
}
|
||||
|
||||
/**
|
||||
* moo_open_info_new_uri: (static-method-of MooOpenInfo) (moo-kwargs)
|
||||
*
|
||||
* @uri: (type const-utf8)
|
||||
* @encoding: (type const-utf8) (allow-none) (default NULL)
|
||||
* @line: (type index) (default -1)
|
||||
* @flags: (default 0)
|
||||
*
|
||||
* Returns: (transfer full)
|
||||
**/
|
||||
MooOpenInfo *
|
||||
moo_open_info_new_uri (const char *uri,
|
||||
const char *encoding,
|
||||
int line,
|
||||
MooOpenFlags flags)
|
||||
{
|
||||
g::FilePtr file = g::File::new_for_uri(uri);
|
||||
return moo_open_info_new_file (file.gobj(), encoding, line, flags);
|
||||
}
|
||||
|
||||
/**
|
||||
* moo_open_info_dup:
|
||||
*
|
||||
* Returns: (transfer full)
|
||||
**/
|
||||
MooOpenInfo *
|
||||
moo_open_info_dup (MooOpenInfo *info)
|
||||
{
|
||||
g_return_val_if_fail(info != nullptr, nullptr);
|
||||
return new MooOpenInfo(*info);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* moo_open_info_get_filename: (moo.private 1)
|
||||
*
|
||||
* Returns: (type filename)
|
||||
**/
|
||||
char *
|
||||
moo_open_info_get_filename (MooOpenInfo *info)
|
||||
{
|
||||
g_return_val_if_fail(info != nullptr, nullptr);
|
||||
return info->file->get_path().release_owned();
|
||||
}
|
||||
|
||||
/**
|
||||
* moo_open_info_get_uri: (moo.private 1)
|
||||
*
|
||||
* Returns: (type utf8)
|
||||
**/
|
||||
char *
|
||||
moo_open_info_get_uri (MooOpenInfo *info)
|
||||
{
|
||||
g_return_val_if_fail(info != nullptr, nullptr);
|
||||
return info->file->get_uri().release_owned();
|
||||
}
|
||||
|
||||
/**
|
||||
* moo_open_info_get_file: (moo.private 1)
|
||||
*
|
||||
* Returns: (transfer full)
|
||||
**/
|
||||
GFile *
|
||||
moo_open_info_get_file (MooOpenInfo *info)
|
||||
{
|
||||
g_return_val_if_fail(info != nullptr, nullptr);
|
||||
return info->file->dup().release();
|
||||
}
|
||||
|
||||
/**
|
||||
* moo_open_info_get_encoding: (moo.private 1)
|
||||
*
|
||||
* Returns: (type const-utf8)
|
||||
**/
|
||||
const char *
|
||||
moo_open_info_get_encoding (MooOpenInfo *info)
|
||||
{
|
||||
g_return_val_if_fail(info != nullptr, nullptr);
|
||||
return info->encoding;
|
||||
}
|
||||
|
||||
/**
|
||||
* moo_open_info_set_encoding: (moo.private 1)
|
||||
*
|
||||
* @info:
|
||||
* @encoding: (type const-utf8) (allow-none)
|
||||
**/
|
||||
void
|
||||
moo_open_info_set_encoding (MooOpenInfo *info,
|
||||
const char *encoding)
|
||||
{
|
||||
g_return_if_fail(info != nullptr);
|
||||
info->encoding.set(encoding);
|
||||
}
|
||||
|
||||
/**
|
||||
* moo_open_info_get_line:
|
||||
*
|
||||
* Returns: (type index)
|
||||
**/
|
||||
int
|
||||
moo_open_info_get_line (MooOpenInfo *info)
|
||||
{
|
||||
g_return_val_if_fail(info != nullptr, -1);
|
||||
return info->line;
|
||||
}
|
||||
|
||||
/**
|
||||
* moo_open_info_set_line:
|
||||
*
|
||||
* @info:
|
||||
* @line: (type index)
|
||||
**/
|
||||
void
|
||||
moo_open_info_set_line (MooOpenInfo *info,
|
||||
int line)
|
||||
{
|
||||
g_return_if_fail(info != nullptr);
|
||||
info->line = line;
|
||||
}
|
||||
|
||||
/**
|
||||
* moo_open_info_get_flags:
|
||||
**/
|
||||
MooOpenFlags
|
||||
moo_open_info_get_flags (MooOpenInfo *info)
|
||||
{
|
||||
g_return_val_if_fail(info != nullptr, MOO_OPEN_FLAGS_NONE);
|
||||
return info->flags;
|
||||
}
|
||||
|
||||
/**
|
||||
* moo_open_info_set_flags:
|
||||
**/
|
||||
void
|
||||
moo_open_info_set_flags(MooOpenInfo *info,
|
||||
MooOpenFlags flags)
|
||||
{
|
||||
g_return_if_fail(info != nullptr);
|
||||
info->flags = flags;
|
||||
}
|
||||
|
||||
/**
|
||||
* moo_open_info_add_flags:
|
||||
**/
|
||||
void
|
||||
moo_open_info_add_flags(MooOpenInfo *info,
|
||||
MooOpenFlags flags)
|
||||
{
|
||||
g_return_if_fail(info != nullptr);
|
||||
info->flags |= flags;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* moo_save_info_new_file: (static-method-of MooSaveInfo)
|
||||
*
|
||||
* @file:
|
||||
* @encoding: (type const-utf8) (allow-none) (default NULL)
|
||||
*
|
||||
* Returns: (transfer full)
|
||||
**/
|
||||
MooSaveInfo *
|
||||
moo_save_info_new_file(GFile *file,
|
||||
const char *encoding)
|
||||
{
|
||||
g_return_val_if_fail(G_IS_FILE(file), nullptr);
|
||||
return new MooSaveInfo(file, encoding);
|
||||
}
|
||||
|
||||
/**
|
||||
* moo_save_info_new: (constructor-of MooSaveInfo)
|
||||
*
|
||||
* @path: (type const-filename)
|
||||
* @encoding: (type const-utf8) (allow-none) (default NULL)
|
||||
*
|
||||
* Returns: (transfer full)
|
||||
**/
|
||||
MooSaveInfo *
|
||||
moo_save_info_new(const char *path,
|
||||
const char *encoding)
|
||||
{
|
||||
auto file = g::File::new_for_path(path);
|
||||
MooSaveInfo *info = moo_save_info_new_file(file.gobj(), encoding);
|
||||
return info;
|
||||
}
|
||||
|
||||
/**
|
||||
* moo_save_info_new_uri: (static-method-of MooSaveInfo)
|
||||
*
|
||||
* @uri: (type const-utf8)
|
||||
* @encoding: (type const-utf8) (allow-none) (default NULL)
|
||||
*
|
||||
* Returns: (transfer full)
|
||||
**/
|
||||
MooSaveInfo *
|
||||
moo_save_info_new_uri (const char *uri,
|
||||
const char *encoding)
|
||||
{
|
||||
auto file = g::File::new_for_uri(uri);
|
||||
MooSaveInfo *info = moo_save_info_new_file(file.gobj(), encoding);
|
||||
return info;
|
||||
}
|
||||
|
||||
/**
|
||||
* moo_save_info_dup:
|
||||
*
|
||||
* Returns: (transfer full)
|
||||
**/
|
||||
MooSaveInfo *
|
||||
moo_save_info_dup (MooSaveInfo *info)
|
||||
{
|
||||
g_return_val_if_fail(info != nullptr, nullptr);
|
||||
return new MooSaveInfo(*info);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* moo_reload_info_new: (constructor-of MooReloadInfo)
|
||||
*
|
||||
* @encoding: (type const-utf8) (allow-none) (default NULL)
|
||||
* @line: (type index) (default -1)
|
||||
**/
|
||||
MooReloadInfo *
|
||||
moo_reload_info_new (const char *encoding,
|
||||
int line)
|
||||
{
|
||||
return new MooReloadInfo(encoding, line);
|
||||
}
|
||||
|
||||
/**
|
||||
* moo_reload_info_dup:
|
||||
*
|
||||
* Returns: (transfer full)
|
||||
**/
|
||||
MooReloadInfo *
|
||||
moo_reload_info_dup (MooReloadInfo *info)
|
||||
{
|
||||
g_return_val_if_fail(info != nullptr, nullptr);
|
||||
return new MooReloadInfo(*info);
|
||||
}
|
||||
|
||||
/**
|
||||
* moo_reload_info_get_line:
|
||||
*
|
||||
* Returns: (type index)
|
||||
**/
|
||||
int
|
||||
moo_reload_info_get_line (MooReloadInfo *info)
|
||||
{
|
||||
g_return_val_if_fail (info != nullptr, -1);
|
||||
return info->line;
|
||||
}
|
||||
|
||||
/**
|
||||
* moo_reload_info_set_line:
|
||||
*
|
||||
* @info:
|
||||
* @line: (type index)
|
||||
**/
|
||||
void
|
||||
moo_reload_info_set_line (MooReloadInfo *info,
|
||||
int line)
|
||||
{
|
||||
g_return_if_fail (info != nullptr);
|
||||
info->line = line;
|
||||
}
|
|
@ -1,7 +1,7 @@
|
|||
/*
|
||||
* mooeditfileinfo.h
|
||||
*
|
||||
* Copyright (C) 2004-2016 by Yevgen Muntyan <emuntyan@users.sourceforge.net>
|
||||
* Copyright (C) 2004-2010 by Yevgen Muntyan <emuntyan@users.sourceforge.net>
|
||||
*
|
||||
* This file is part of medit. medit is free software; you can
|
||||
* redistribute it and/or modify it under the terms of the
|
||||
|
@ -13,18 +13,42 @@
|
|||
* License along with medit. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#pragma once
|
||||
#ifndef MOO_EDIT_FILE_INFO_H
|
||||
#define MOO_EDIT_FILE_INFO_H
|
||||
|
||||
#include <gio/gio.h>
|
||||
#include <mooedit/mooedittypes.h>
|
||||
#ifdef __cplusplus
|
||||
#include <moocpp/moocpp.h>
|
||||
#endif
|
||||
|
||||
G_BEGIN_DECLS
|
||||
|
||||
#define MOO_TYPE_OPEN_INFO (moo_open_info_get_type ())
|
||||
#define MOO_OPEN_INFO(object) (G_TYPE_CHECK_INSTANCE_CAST ((object), MOO_TYPE_OPEN_INFO, MooOpenInfo))
|
||||
#define MOO_OPEN_INFO_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), MOO_TYPE_OPEN_INFO, MooOpenInfoClass))
|
||||
#define MOO_IS_OPEN_INFO(object) (G_TYPE_CHECK_INSTANCE_TYPE ((object), MOO_TYPE_OPEN_INFO))
|
||||
#define MOO_IS_OPEN_INFO_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), MOO_TYPE_OPEN_INFO))
|
||||
#define MOO_OPEN_INFO_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), MOO_TYPE_OPEN_INFO, MooOpenInfoClass))
|
||||
|
||||
#define MOO_TYPE_SAVE_INFO (moo_save_info_get_type ())
|
||||
#define MOO_SAVE_INFO(object) (G_TYPE_CHECK_INSTANCE_CAST ((object), MOO_TYPE_SAVE_INFO, MooSaveInfo))
|
||||
#define MOO_SAVE_INFO_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), MOO_TYPE_SAVE_INFO, MooSaveInfoClass))
|
||||
#define MOO_IS_SAVE_INFO(object) (G_TYPE_CHECK_INSTANCE_TYPE ((object), MOO_TYPE_SAVE_INFO))
|
||||
#define MOO_IS_SAVE_INFO_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), MOO_TYPE_SAVE_INFO))
|
||||
#define MOO_SAVE_INFO_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), MOO_TYPE_SAVE_INFO, MooSaveInfoClass))
|
||||
|
||||
#define MOO_TYPE_RELOAD_INFO (moo_reload_info_get_type ())
|
||||
#define MOO_RELOAD_INFO(object) (G_TYPE_CHECK_INSTANCE_CAST ((object), MOO_TYPE_RELOAD_INFO, MooReloadInfo))
|
||||
#define MOO_RELOAD_INFO_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), MOO_TYPE_RELOAD_INFO, MooReloadInfoClass))
|
||||
#define MOO_IS_RELOAD_INFO(object) (G_TYPE_CHECK_INSTANCE_TYPE ((object), MOO_TYPE_RELOAD_INFO))
|
||||
#define MOO_IS_RELOAD_INFO_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), MOO_TYPE_RELOAD_INFO))
|
||||
#define MOO_RELOAD_INFO_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), MOO_TYPE_RELOAD_INFO, MooReloadInfoClass))
|
||||
|
||||
typedef struct MooOpenInfoClass MooOpenInfoClass;
|
||||
typedef struct MooSaveInfoClass MooSaveInfoClass;
|
||||
typedef struct MooReloadInfoClass MooReloadInfoClass;
|
||||
|
||||
GType moo_open_info_get_type (void) G_GNUC_CONST;
|
||||
GType moo_reload_info_get_type (void) G_GNUC_CONST;
|
||||
GType moo_save_info_get_type (void) G_GNUC_CONST;
|
||||
|
||||
MooOpenInfo *moo_open_info_new (const char *path,
|
||||
const char *encoding,
|
||||
|
@ -39,6 +63,7 @@ MooOpenInfo *moo_open_info_new_uri (const char *uri,
|
|||
int line,
|
||||
MooOpenFlags flags);
|
||||
MooOpenInfo *moo_open_info_dup (MooOpenInfo *info);
|
||||
void moo_open_info_free (MooOpenInfo *info);
|
||||
|
||||
char *moo_open_info_get_filename (MooOpenInfo *info);
|
||||
char *moo_open_info_get_uri (MooOpenInfo *info);
|
||||
|
@ -59,6 +84,7 @@ void moo_open_info_add_flags (MooOpenInfo *info,
|
|||
MooReloadInfo *moo_reload_info_new (const char *encoding,
|
||||
int line);
|
||||
MooReloadInfo *moo_reload_info_dup (MooReloadInfo *info);
|
||||
void moo_reload_info_free (MooReloadInfo *info);
|
||||
|
||||
int moo_reload_info_get_line (MooReloadInfo *info);
|
||||
void moo_reload_info_set_line (MooReloadInfo *info,
|
||||
|
@ -71,5 +97,8 @@ MooSaveInfo *moo_save_info_new_file (GFile *file,
|
|||
MooSaveInfo *moo_save_info_new_uri (const char *uri,
|
||||
const char *encoding);
|
||||
MooSaveInfo *moo_save_info_dup (MooSaveInfo *info);
|
||||
void moo_save_info_free (MooSaveInfo *info);
|
||||
|
||||
G_END_DECLS
|
||||
|
||||
#endif /* MOO_EDIT_FILE_INFO_H */
|
||||
|
|
Some files were not shown because too many files have changed in this diff Show More
Loading…
Reference in New Issue