├── .gitignore ├── CbersApp.pro ├── CbersApp ├── CbersApp.ico ├── CbersApp.pro ├── CbersApp.qrc ├── CbersApp_win32.rc ├── main.cpp ├── mainwindow.cpp ├── mainwindow.h ├── mainwindow.ui ├── pluginmanager.cpp ├── pluginmanager.h ├── ribbonpluginmanager.cpp └── ribbonpluginmanager.h ├── CbersPluginCore ├── CbersPluginCore.pro ├── UICore.cpp ├── UICore.h ├── UIPlugins.h ├── UIPluginsEvents.h ├── cbersplugincore_global.h ├── module.cpp └── pluginconfig.pri ├── CbersUI ├── CbersUI.pro ├── Resource │ ├── office2007_black │ │ ├── AppCaption │ │ │ ├── Btn_HideElements.png │ │ │ ├── Btn_ShowElements.png │ │ │ ├── SysBtn_Close.png │ │ │ ├── SysBtn_Maximize.png │ │ │ ├── SysBtn_Minimize.png │ │ │ └── SysBtn_Restore.png │ │ ├── Black │ │ │ ├── caret-down_ffffff_14.png │ │ │ ├── caret-right_ffffff_14.png │ │ │ ├── check.png │ │ │ ├── cross.svg │ │ │ ├── down_arrow.png │ │ │ ├── eye-blocked.svg │ │ │ ├── eye.svg │ │ │ └── up_arrow.png │ │ └── office2007_black.qss │ └── office2007_blue │ │ ├── AppCaption │ │ ├── Btn_HideElements.png │ │ ├── Btn_ShowElements.png │ │ ├── SysBtn_Close.png │ │ ├── SysBtn_Maximize.png │ │ ├── SysBtn_Minimize.png │ │ └── SysBtn_Restore.png │ │ └── office2007_blue.qss ├── cbersui.qrc ├── cbersui_global.h ├── qribbonbar.cpp ├── qribbonbar.h ├── qribboncategory.cpp ├── qribboncategory.h ├── qribbonpanel.cpp ├── qribbonpanel.h ├── qribbonstylesheetmanager.cpp ├── qribbonstylesheetmanager.h ├── qribbontabwidget.cpp ├── qribbontabwidget.h ├── qseparator.cpp ├── qseparator.h ├── qtitlewidget.cpp └── qtitlewidget.h ├── LICENSE ├── README.md ├── plugins ├── PluginDemo │ ├── CommandPlugin.png │ ├── DockWidgetPlugin.png │ ├── PluginDemo.pro │ ├── ToolPlugin.png │ ├── ViewPlugin.png │ ├── commandplugin.cpp │ ├── commandplugin.h │ ├── dockwidgetplugin.cpp │ ├── dockwidgetplugin.h │ ├── module.cpp │ ├── toolplugin.cpp │ ├── toolplugin.h │ ├── viewplugin.cpp │ └── viewplugin.h └── plugins.pro ├── x3py ├── interface │ └── core │ │ ├── iobject.h │ │ ├── manager │ │ ├── iplugins.h │ │ ├── iworkpath.h │ │ └── x3manager.h │ │ ├── module │ │ ├── classentry.h │ │ ├── classmacro.h │ │ ├── moduleitem.h │ │ ├── modulemacro.h │ │ ├── normalobject.h │ │ ├── pluginimpl.h │ │ ├── plugininc.h │ │ └── singletonobj.h │ │ ├── nonplugin │ │ ├── scanplugins.h │ │ ├── swigext.h │ │ ├── useplugin.h │ │ └── useplugins.h │ │ ├── objptr.h │ │ ├── observer │ │ ├── eventobserver.h │ │ ├── fireevent.h │ │ ├── fireeventex.h │ │ ├── fireobjevent.h │ │ ├── fireobjeventex.h │ │ ├── observerimpl.h │ │ └── observerobject.h │ │ ├── portability │ │ ├── func_s.h │ │ ├── pathstr.h │ │ ├── portimpl.h │ │ ├── uniximpl.h │ │ ├── winimpl.h │ │ ├── x3port.h │ │ ├── x3unix.h │ │ └── x3win.h │ │ └── utilfunc │ │ ├── convstr.h │ │ ├── loadmodule.h │ │ ├── lockcount.h │ │ ├── lockrw.h │ │ ├── readints.h │ │ ├── roundstr.h │ │ ├── safecall.h │ │ ├── scanfiles.h │ │ ├── syserrstr.h │ │ └── vecfunc.h ├── source │ ├── Makefile │ ├── core │ │ ├── Makefile │ │ └── x3manager │ │ │ ├── Makefile │ │ │ ├── module.cpp │ │ │ ├── plugins.cpp │ │ │ ├── plugins.h │ │ │ ├── swig │ │ │ ├── Makefile │ │ │ ├── testx3manager.py │ │ │ └── x3manager.i │ │ │ ├── workpath.cpp │ │ │ └── workpath.h │ └── public │ │ ├── mk │ │ ├── Makefile.libp │ │ ├── Makefile.pln │ │ └── Makefile.qt4 │ │ └── swig │ │ ├── Makefile.plswig │ │ ├── Makefile.swig │ │ ├── observer.i │ │ └── plugin.i └── x3py.pro └── 插件模板 └── qtcreator └── share └── qtcreator └── templates └── wizards ├── CbersPlugin ├── lib.png ├── lib@2x.png ├── module.cpp ├── project.pro └── wizard.json └── classes └── CbersPluginClass ├── file.cpp ├── file.h ├── file.png └── wizard.json /.gitignore: -------------------------------------------------------------------------------- 1 | # Compiled Object files 2 | *.slo 3 | *.lo 4 | *.o 5 | *.obj 6 | 7 | # Precompiled Headers 8 | *.gch 9 | *.pch 10 | 11 | # Compiled Dynamic libraries 12 | *.so 13 | *.dylib 14 | *.dll 15 | 16 | # Fortran module files 17 | *.mod 18 | *.smod 19 | 20 | # Compiled Static libraries 21 | *.lai 22 | *.la 23 | *.a 24 | *.lib 25 | 26 | # Executables 27 | *.exe 28 | *.out 29 | *.app 30 | -------------------------------------------------------------------------------- /CbersApp.pro: -------------------------------------------------------------------------------- 1 | TEMPLATE = subdirs 2 | SUBDIRS = CbersUI x3py CbersPluginCore CbersApp plugins 3 | CbersApp.depends = CbersUI CbersPluginCore plugins 4 | CbersPluginCore.depends = x3py 5 | plugins.depends = CbersPluginCore 6 | -------------------------------------------------------------------------------- /CbersApp/CbersApp.ico: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/longhuan2018/CbersUI/85bfe9f16e0ff17361875461818006efc51d8d28/CbersApp/CbersApp.ico -------------------------------------------------------------------------------- /CbersApp/CbersApp.pro: -------------------------------------------------------------------------------- 1 | #------------------------------------------------- 2 | # 3 | # Project created by QtCreator 2016-09-08T16:10:14 4 | # 5 | #------------------------------------------------- 6 | 7 | QT += core gui opengl xml 8 | 9 | greaterThan(QT_MAJOR_VERSION, 4): QT += widgets 10 | 11 | CONFIG += c++11 12 | 13 | TARGET = CbersApp 14 | TEMPLATE = app 15 | 16 | { 17 | CONFIG(debug, debug|release){ 18 | TARGET = $$join(TARGET,,,d) 19 | 20 | DESTDIR = $$PWD/../bin/debug 21 | } 22 | else{ 23 | DESTDIR = $$PWD/../bin/release 24 | } 25 | } 26 | 27 | 28 | SOURCES += main.cpp\ 29 | mainwindow.cpp \ 30 | pluginmanager.cpp \ 31 | ribbonpluginmanager.cpp 32 | 33 | HEADERS += mainwindow.h \ 34 | pluginmanager.h \ 35 | ribbonpluginmanager.h 36 | 37 | FORMS += mainwindow.ui 38 | 39 | 40 | CONFIG(release, debug|release): LIBS += -L$$PWD/../lib/release/ -lCbersUI 41 | else:CONFIG(debug, debug|release): LIBS += -L$$PWD/../lib/debug/ -lCbersUId 42 | 43 | unix{ 44 | LIBS += -ldl 45 | } 46 | 47 | INCLUDEPATH += $$PWD/../include 48 | INCLUDEPATH += $$PWD/../include/CbersUI 49 | INCLUDEPATH += $$PWD/../include/x3py 50 | INCLUDEPATH += $$PWD/../include/PluginCore 51 | DEPENDPATH += $$PWD/../include 52 | DEPENDPATH += $$PWD/../include/CbersUI 53 | DEPENDPATH += $$PWD/../include/x3py 54 | DEPENDPATH += $$PWD/../include/PluginCore 55 | 56 | win32{ 57 | LIBS += -lDbghelp 58 | } 59 | 60 | SDK_PATH = $$PWD/../ 61 | 62 | win32{ 63 | RC_FILE= CbersApp_win32.rc 64 | } 65 | 66 | RESOURCES += \ 67 | CbersApp.qrc 68 | 69 | TRANSLATION_DIR = $$PWD/../i18n/ 70 | TRANSLATIONS = $$TRANSLATION_DIR/CbersApp_zh_CN.ts 71 | 72 | # Copies the given files to the destination directory 73 | defineReplace(copyToDir) { 74 | files = $$1 75 | DIR = $$2 76 | SRCDIR = $$3 77 | LINK = 78 | 79 | win32:DIR ~= s,/,\\,g 80 | win32{ 81 | LINK += if not exist $$quote($$DIR) ( $$QMAKE_MKDIR $$quote($$DIR) ) $$escape_expand(\\n\\t) 82 | } 83 | unix{ 84 | LINK += $$QMAKE_MKDIR $$quote($$DIR) $$escape_expand(\\n\\t) 85 | } 86 | for(FILE, files) { 87 | !isEmpty(SRCDIR){ 88 | FILE = $$SRCDIR/$$FILE 89 | } 90 | win32:FILE ~= s,/,\\,g 91 | LINK += $$QMAKE_COPY $$quote($$FILE) $$quote($$DIR) $$escape_expand(\\n\\t) 92 | } 93 | return($$LINK) 94 | } 95 | 96 | win32{ 97 | QMAKE_POST_LINK += cd $$quote($$PWD) $$escape_expand(\\n\\t) 98 | } 99 | unix{ 100 | QMAKE_POST_LINK += cd $$quote($$PWD) $$escape_expand(\\n\\t) 101 | } 102 | 103 | # Auto Update And Release TRANSLATIONS 104 | win32:TRANSLATION_DIR ~= s,/,\\,g 105 | win32{ 106 | QMAKE_POST_LINK += if not exist $$quote($$TRANSLATION_DIR) ( $$QMAKE_MKDIR $$quote($$TRANSLATION_DIR) ) $$escape_expand(\\n\\t) 107 | } 108 | unix{ 109 | QMAKE_POST_LINK += $$QMAKE_MKDIR -p $$quote($$TRANSLATION_DIR) $$escape_expand(\\n\\t) 110 | } 111 | 112 | QMAKE_POST_LINK += $(QTDIR)/bin/lupdate $$PWD/CbersApp.pro $$escape_expand(\\n\\t) 113 | QMAKE_POST_LINK += $(QTDIR)/bin/lrelease $$PWD/CbersApp.pro $$escape_expand(\\n\\t) 114 | RELEASE_TRANSLATIONS = $$TRANSLATIONS 115 | RELEASE_TRANSLATIONS ~= s,.ts,.qm,g 116 | QMAKE_POST_LINK += $$copyToDir($$RELEASE_TRANSLATIONS, $$DESTDIR/i18n/) 117 | -------------------------------------------------------------------------------- /CbersApp/CbersApp.qrc: -------------------------------------------------------------------------------- 1 | 2 | 3 | CbersApp.ico 4 | 5 | 6 | -------------------------------------------------------------------------------- /CbersApp/CbersApp_win32.rc: -------------------------------------------------------------------------------- 1 | #include "winver.h" 2 | 3 | IDI_ICON1 ICON "CbersApp.ico" 4 | 5 | VS_VERSION_INFO VERSIONINFO 6 | FILEVERSION 1,0,0,1 7 | PRODUCTVERSION 1,0,0,1 8 | FILEFLAGSMASK 0x3fL 9 | #ifdef _DEBUG 10 | FILEFLAGS 0x1L 11 | #else 12 | FILEFLAGS 0x0L 13 | #endif 14 | FILEOS 0x40004L 15 | FILETYPE 0x0L 16 | FILESUBTYPE 0x0L 17 | BEGIN 18 | BLOCK "StringFileInfo" 19 | BEGIN 20 | BLOCK "080404b0" 21 | BEGIN 22 | VALUE "CompanyName", "CbersApp" 23 | VALUE "FileDescription", "CbersApp" 24 | VALUE "FileVersion", "1.0.0.1" 25 | VALUE "InternalName", "CbersApp.exe" 26 | VALUE "LegalCopyright", "Copyright (C) 2018" 27 | VALUE "OriginalFilename", "CbersApp.exe" 28 | VALUE "ProductName", "CbersApp" 29 | VALUE "ProductVersion", "1.0.0.1" 30 | END 31 | END 32 | BLOCK "VarFileInfo" 33 | BEGIN 34 | VALUE "Translation", 0x804, 1200 35 | END 36 | END -------------------------------------------------------------------------------- /CbersApp/main.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | #include 5 | #include 6 | #include 7 | #include 8 | #include "mainwindow.h" 9 | #include "pluginmanager.h" 10 | #include "x3py/observer/observerimpl.h" 11 | 12 | int main(int argc, char *argv[]) 13 | { 14 | QString configpath = QFileInfo(QString::fromLocal8Bit(argv[0])).absolutePath() + "/config"; 15 | QSettings::setDefaultFormat( QSettings::IniFormat ); 16 | QSettings::setPath( QSettings::IniFormat, QSettings::UserScope, configpath); 17 | 18 | QApplication a(argc, argv); 19 | a.setWindowIcon(QIcon(":/CbersApp.ico")); 20 | 21 | QCoreApplication::setOrganizationName( QObject::tr("CbersApp") ); 22 | QCoreApplication::setOrganizationDomain( QObject::tr("CbersApp") ); 23 | QCoreApplication::setApplicationName( QObject::tr("CbersApp") ); 24 | QCoreApplication::setAttribute( Qt::AA_DontShowIconsInMenus, false ); 25 | 26 | QSettings mySettings; 27 | ////////////////////////////////////////////////////////////// 28 | // Load Translator 29 | QString i18nPath = QApplication::applicationDirPath() + "/i18n"; 30 | QString myUserLocale = mySettings.value( "locale/userLocale", "" ).toString(); 31 | bool myLocaleOverrideFlag = mySettings.value( "locale/overrideFlag", false ).toBool(); 32 | QString myTranslationCode; 33 | if ( !myTranslationCode.isNull() && !myTranslationCode.isEmpty() ) 34 | { 35 | mySettings.setValue( "locale/userLocale", myTranslationCode ); 36 | } 37 | else 38 | { 39 | if ( !myLocaleOverrideFlag || myUserLocale.isEmpty() ) 40 | { 41 | myTranslationCode = QLocale::system().name(); 42 | mySettings.setValue( "locale/userLocale", myTranslationCode ); 43 | } 44 | else 45 | { 46 | myTranslationCode = myUserLocale; 47 | } 48 | } 49 | 50 | QTranslator apptor( 0 ); 51 | QTranslator cbersUItor( 0 ); 52 | QTranslator qttor( 0 ); 53 | if ( myTranslationCode != "C" ) 54 | { 55 | if ( apptor.load( QString( "CbersApp_" ) + myTranslationCode, i18nPath ) ) 56 | { 57 | a.installTranslator( &apptor ); 58 | } 59 | else 60 | { 61 | qWarning( "loading of CbersApp translation failed [%s]", QString( "%1/CbersApp_%2" ).arg( i18nPath ).arg( myTranslationCode ).toLocal8Bit().constData() ); 62 | } 63 | 64 | if ( cbersUItor.load( QString( "CbersUI_" ) + myTranslationCode, i18nPath ) ) 65 | { 66 | a.installTranslator( &cbersUItor ); 67 | } 68 | else 69 | { 70 | qWarning( "loading of CbersUI translation failed [%s]", QString( "%1/CbersUI_%2" ).arg( i18nPath ).arg( myTranslationCode ).toLocal8Bit().constData() ); 71 | } 72 | 73 | if ( qttor.load( QString( "qt_" ) + myTranslationCode, i18nPath ) ) 74 | { 75 | a.installTranslator( &qttor ); 76 | } 77 | else 78 | { 79 | qWarning( "loading of qt translation failed [%s]", QString( "%1_%2" ).arg( i18nPath ).arg( myTranslationCode ).toLocal8Bit().constData() ); 80 | } 81 | } 82 | ////////////////////////////////////////////////////////////// 83 | 84 | if( !CPluginManager::Initialize("CbersPlugins") ) 85 | return -1; 86 | 87 | MainWindow w; 88 | w.showMaximized(); 89 | 90 | return a.exec(); 91 | } 92 | -------------------------------------------------------------------------------- /CbersApp/mainwindow.cpp: -------------------------------------------------------------------------------- 1 | #include "mainwindow.h" 2 | #include "ui_mainwindow.h" 3 | #include 4 | #include 5 | #include "ribbonpluginmanager.h" 6 | #include "qribbonstylesheetmanager.h" 7 | 8 | MainWindow::MainWindow(QWidget *parent) : 9 | QMainWindow(parent), 10 | ui(new Ui::MainWindow) 11 | { 12 | setObjectName("QRibbonMainWindow"); 13 | setWindowFlags( Qt::FramelessWindowHint ); 14 | ui->setupUi(this); 15 | 16 | mRibbonBar = new QRibbonBar(this->centralWidget()); 17 | 18 | mMdiArea = new QMdiArea(this->centralWidget()); 19 | //mMdiArea->setOption(QMdiArea::DontMaximizeSubWindowOnActivation); 20 | mMdiArea->setViewMode(QMdiArea::SubWindowView); 21 | //mMdiArea->setViewMode(QMdiArea::TabbedView); 22 | mMdiArea->setTabShape(QTabWidget::Rounded); 23 | mMdiArea->setTabPosition(QTabWidget::North); 24 | connect(mMdiArea, SIGNAL(subWindowActivated(QMdiSubWindow *)), this, SLOT(subWindowActivated(QMdiSubWindow *))); 25 | 26 | CRibbonPluginManager::getInstance()->Create(this, mRibbonBar, mMdiArea); 27 | setMenuWidget(mRibbonBar); 28 | setCentralWidget(mMdiArea); 29 | 30 | QRibbonStyleSheetManager::instance()->applyStyleSheet("office2007_black"); 31 | //registerHandlers(); 32 | } 33 | 34 | MainWindow::~MainWindow() 35 | { 36 | CRibbonPluginManager::getInstance()->DestroyControl(); 37 | 38 | if( mRibbonBar!=nullptr ) 39 | delete mRibbonBar; 40 | mRibbonBar = nullptr; 41 | 42 | delete ui; 43 | } 44 | 45 | bool MainWindow::OnAnything(x3::IObject* sender, const std::string& eventKey, const QVariant& wParam, const QVariant& lParam) 46 | { 47 | //if( _stricmp(eventKey.c_str(), "scaleChanged")==0 ) 48 | //{ 49 | //} 50 | return true; 51 | } 52 | 53 | void MainWindow::subWindowActivated(QMdiSubWindow* pSubWindow) 54 | { 55 | if( pSubWindow==Q_NULLPTR ) 56 | return; 57 | 58 | QVariant vtData = pSubWindow->property("IUIPlugin"); 59 | if( !vtData.isValid() ) 60 | return; 61 | 62 | x3::Object spCommon((IUIPlugin*)(vtData.toLongLong())); 63 | if( !spCommon.valid() ) 64 | return; 65 | 66 | CRibbonPluginManager::getInstance()->SetViewer(spCommon.p()); 67 | } 68 | -------------------------------------------------------------------------------- /CbersApp/mainwindow.h: -------------------------------------------------------------------------------- 1 | #ifndef MAINWINDOW_H 2 | #define MAINWINDOW_H 3 | 4 | #include 5 | #include 6 | #include 7 | #include 8 | #include 9 | #include 10 | #include 11 | #include 12 | #include 13 | #include "qribbonbar.h" 14 | USING_NAMESPACE_CBERSUI 15 | 16 | #include "UIPluginsEvents.h" 17 | USING_NAMESPACE_CBERSPLUGINS 18 | 19 | namespace Ui { 20 | class MainWindow; 21 | } 22 | 23 | class MainWindow : public QMainWindow, public IAnythingEventObserver 24 | { 25 | Q_OBJECT 26 | 27 | public: 28 | explicit MainWindow(QWidget *parent = 0); 29 | ~MainWindow(); 30 | 31 | public: 32 | // IAnythingEventObserver 33 | virtual bool OnAnything(x3::IObject* sender, const std::string& eventKey, const QVariant& wParam, const QVariant& lParam); 34 | 35 | protected slots: 36 | void subWindowActivated(QMdiSubWindow *); 37 | 38 | private: 39 | Ui::MainWindow *ui; 40 | QRibbonBar* mRibbonBar; 41 | QMdiArea* mMdiArea; 42 | }; 43 | 44 | #endif // MAINWINDOW_H 45 | -------------------------------------------------------------------------------- /CbersApp/mainwindow.ui: -------------------------------------------------------------------------------- 1 | 2 | 3 | MainWindow 4 | 5 | 6 | 7 | 0 8 | 0 9 | 400 10 | 300 11 | 12 | 13 | 14 | MainWindow 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | -------------------------------------------------------------------------------- /CbersApp/pluginmanager.h: -------------------------------------------------------------------------------- 1 | #ifndef CPLUGINMANAGER_H 2 | #define CPLUGINMANAGER_H 3 | #include "x3py/module/plugininc.h" 4 | #include "x3py/objptr.h" 5 | #include "x3py/utilfunc/lockrw.h" 6 | #include "UIPlugins.h" 7 | USING_NAMESPACE_CBERSPLUGINS 8 | 9 | #include 10 | #include 11 | 12 | #define hash_multimap std::multimap 13 | #define hash_map std::map 14 | 15 | class CPluginManager 16 | { 17 | public: 18 | CPluginManager(); 19 | ~CPluginManager(void); 20 | 21 | public: 22 | static bool Initialize(const char* folder = "plugins"); 23 | static bool UnInitialize(); 24 | 25 | public: 26 | bool LoadPlugins(); 27 | bool UnloadPlugins(); 28 | int GetPluginCount(); 29 | bool GetPlugin(int index, int& id, IUIPlugin** ppICommon); 30 | IUIPlugin* FindPlugin(int id); 31 | 32 | int GetViewPluginCount(); 33 | bool GetViewPlugin(int index, IUIView** ppIView); 34 | 35 | protected: 36 | int GetNextID(); 37 | void FreeID(int id); 38 | 39 | public: 40 | static int MINID; 41 | static int MAXID; 42 | 43 | protected: 44 | x3::LockRW_> m_mapPlugin; 45 | x3::LockRW_> m_mapView; 46 | x3::LockRW_> m_mapIdleID; 47 | int m_nNextID; 48 | int m_nLastTool; 49 | }; 50 | 51 | #endif // CPLUGINMANAGER_H 52 | -------------------------------------------------------------------------------- /CbersApp/ribbonpluginmanager.h: -------------------------------------------------------------------------------- 1 | #ifndef RIBBONPLUGINMANAGER_H 2 | #define RIBBONPLUGINMANAGER_H 3 | #include "pluginmanager.h" 4 | #include "qribbonbar.h" 5 | USING_NAMESPACE_CBERSUI 6 | 7 | #include 8 | #include 9 | #include 10 | 11 | class CRibbonPluginManager : public CPluginManager 12 | { 13 | public: 14 | CRibbonPluginManager(); 15 | ~CRibbonPluginManager(void); 16 | 17 | public: 18 | static CRibbonPluginManager* getInstance(); 19 | static void Destroy(); 20 | 21 | private: 22 | static CRibbonPluginManager* s_pManager; 23 | 24 | public: 25 | bool Create(QMainWindow* pFrameWnd, QRibbonBar* pRibbonBar, QMdiArea* pMdiArea); 26 | bool CreateViews(QMainWindow* pFrameWnd, QMdiArea* pMdiArea); 27 | bool CreateControl(QRibbonBar* pRibbonBar, QMainWindow* pFrameWnd); 28 | void SetViewer(x3::IObject* val); 29 | void DestroyControl(); 30 | 31 | protected: 32 | bool AddRibbonButton(QRibbonBar* pRibbonBar, IUIPlugin* pCommon, int id); 33 | QRibbonCategory* FindRibbonCategory(QRibbonBar* pRibbonBar, const QString& lpszCategory); 34 | QRibbonPanel* FindRibbonPanel(QRibbonCategory* pCategory, const QString& lpszCaption); 35 | QRibbonPanel* FindRibbonPanel(QRibbonBar* pRibbonBar, const QString& lpszCategory, const QString& lpszCaption); 36 | 37 | protected: 38 | x3::AnyObject m_spViewer; 39 | }; 40 | 41 | #endif // RIBBONPLUGINMANAGER_H 42 | -------------------------------------------------------------------------------- /CbersPluginCore/CbersPluginCore.pro: -------------------------------------------------------------------------------- 1 | #------------------------------------------------- 2 | # 3 | # Project created by QtCreator 2018-01-04T16:43:03 4 | # 5 | #------------------------------------------------- 6 | 7 | QT -= gui 8 | 9 | TARGET = CbersPluginCore 10 | TEMPLATE = lib 11 | 12 | DEFINES += CBERSPLUGINCORE_LIBRARY 13 | 14 | # The following define makes your compiler emit warnings if you use 15 | # any feature of Qt which as been marked as deprecated (the exact warnings 16 | # depend on your compiler). Please consult the documentation of the 17 | # deprecated API in order to know how to port your code away from it. 18 | DEFINES += QT_DEPRECATED_WARNINGS 19 | 20 | # You can also make your code fail to compile if you use deprecated APIs. 21 | # In order to do so, uncomment the following line. 22 | # You can also select to disable deprecated APIs only up to a certain version of Qt. 23 | #DEFINES += QT_DISABLE_DEPRECATED_BEFORE=0x060000 # disables all the APIs deprecated before Qt 6.0.0 24 | 25 | SOURCES += \ 26 | module.cpp \ 27 | UICore.cpp 28 | 29 | HEADERS +=\ 30 | cbersplugincore_global.h \ 31 | UIPlugins.h \ 32 | UICore.h \ 33 | UIPluginsEvents.h 34 | 35 | PROJECT_PATH = $$PWD 36 | SDK_PATH = $$PROJECT_PATH/../ 37 | #TRANSLATION_LANGS = zh_CN 38 | include( pluginconfig.pri ) 39 | 40 | QMAKE_POST_LINK += $$copyToDir(pluginconfig.pri, $$SDK_PATH/include/, $$PROJECT_PATH) 41 | 42 | -------------------------------------------------------------------------------- /CbersPluginCore/UICore.cpp: -------------------------------------------------------------------------------- 1 | #include "UICore.h" 2 | 3 | BEGIN_NAMESPACE_CBERSPLUGINS 4 | 5 | CUICore::CUICore() 6 | { 7 | 8 | } 9 | 10 | CUICore::~CUICore() 11 | { 12 | clear(); 13 | } 14 | 15 | long CUICore::size() 16 | { 17 | x3::LockRW locker(m_mapData.locker); 18 | return locker.canRead() ? m_mapData.size() : 0; 19 | } 20 | 21 | x3::IObject* CUICore::Find(const char* key) 22 | { 23 | x3::LockRW locker(m_mapData.locker); 24 | IObject* ret = NULL; 25 | if (locker.canRead()) 26 | { 27 | hash_map::const_iterator it = m_mapData.find(key); 28 | ret = (it != m_mapData.end()) ? it->second.p() : NULL; 29 | } 30 | 31 | return ret; 32 | } 33 | 34 | bool CUICore::Add(const char* key, x3::IObject* obj) 35 | { 36 | if( key==NULL || strlen(key)<=0 || obj==NULL ) 37 | return false; 38 | 39 | x3::LockRW locker(m_mapData.locker, true); 40 | bool ret = false; 41 | if (locker.canWrite()) 42 | { 43 | m_mapData[key] = obj; 44 | ret = true; 45 | } 46 | 47 | return ret; 48 | } 49 | 50 | bool CUICore::Remove(const char* key) 51 | { 52 | x3::LockRW locker(m_mapData.locker, true); 53 | bool ret = false; 54 | if (locker.canWrite()) 55 | { 56 | hash_map::iterator it = m_mapData.find(key); 57 | if( it!=m_mapData.end() ) 58 | { 59 | if( it->second.valid() ) 60 | it->second.release(); 61 | m_mapData.erase(it); 62 | ret = true; 63 | } 64 | } 65 | 66 | return ret; 67 | } 68 | 69 | bool CUICore::Remove(x3::IObject* obj) 70 | { 71 | if( obj==nullptr ) 72 | return false; 73 | 74 | x3::LockRW lockcls(m_mapData.locker, true); 75 | bool ret = false; 76 | if (lockcls.canWrite()) 77 | { 78 | hash_map::iterator it = m_mapData.begin(); 79 | while (it != m_mapData.end()) 80 | { 81 | if (it->second == obj) 82 | { 83 | if( it->second.valid() ) 84 | it->second.release(); 85 | m_mapData.erase(it); 86 | it = m_mapData.begin(); 87 | ret = true; 88 | } 89 | else 90 | { 91 | ++it; 92 | } 93 | } 94 | } 95 | 96 | return ret; 97 | } 98 | 99 | void CUICore::clear() 100 | { 101 | x3::LockRW lockcls(m_mapData.locker, true); 102 | if (lockcls.canWrite()) 103 | { 104 | hash_map::iterator it = m_mapData.begin(); 105 | for( ; it!=m_mapData.end(); it++ ) 106 | { 107 | if( it->second.valid() ) 108 | it->second.release(); 109 | } 110 | m_mapData.clear(); 111 | } 112 | } 113 | 114 | END_NAMESPACE_CBERSPLUGINS 115 | -------------------------------------------------------------------------------- /CbersPluginCore/UICore.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | #include "UIPlugins.h" 3 | #include "module/classmacro.h" 4 | #include "utilfunc/lockrw.h" 5 | #include 6 | 7 | #if !defined(_MSC_VER) || _MSC_VER >= 1700 8 | #include 9 | #define hash_multimap std::unordered_multimap 10 | #define hash_map std::unordered_map 11 | #else 12 | #if defined(_MSC_VER) && _MSC_VER > 1200 // VC8/9 13 | #include 14 | using stdext::hash_multimap; 15 | using stdext::hash_map; 16 | #else // VC6, GCC or others 17 | #define hash_multimap std::multimap 18 | #define hash_map std::map 19 | #endif 20 | #endif 21 | 22 | 23 | BEGIN_NAMESPACE_CBERSPLUGINS 24 | 25 | class CUICore : public IUICore 26 | { 27 | X3BEGIN_CLASS_DECLARE(CUICore, clsidUICore) 28 | X3DEFINE_INTERFACE_ENTRY(IUICore) 29 | X3END_CLASS_DECLARE() 30 | 31 | public: 32 | CUICore(); 33 | virtual ~CUICore(); 34 | 35 | public: 36 | virtual long size(); 37 | virtual x3::IObject* Find(const char* key); 38 | virtual bool Add(const char* key, x3::IObject* obj); 39 | virtual bool Remove(const char* key); 40 | virtual bool Remove(x3::IObject* obj); 41 | virtual void clear(); 42 | 43 | protected: 44 | x3::LockRW_ > m_mapData; 45 | }; 46 | 47 | END_NAMESPACE_CBERSPLUGINS 48 | -------------------------------------------------------------------------------- /CbersPluginCore/UIPlugins.h: -------------------------------------------------------------------------------- 1 | #ifndef IPLUGIN_H 2 | #define IPLUGIN_H 3 | #include 4 | #include 5 | #include 6 | #include 7 | #include 8 | #include "module/plugininc.h" 9 | #include "objptr.h" 10 | #include "cbersplugincore_global.h" 11 | 12 | BEGIN_NAMESPACE_CBERSPLUGINS 13 | const char* const clsidUICore = "clsidUICore"; 14 | class IUICore : public x3::IObject 15 | { 16 | X3DEFINE_IID(IUICore); 17 | 18 | public: 19 | virtual long size() = 0; 20 | virtual x3::IObject* Find(const char* key) = 0; 21 | virtual bool Add(const char* key, x3::IObject* obj) = 0; 22 | virtual bool Remove(const char* key) = 0; 23 | virtual bool Remove(x3::IObject* obj) = 0; 24 | virtual void clear() = 0; 25 | }; 26 | 27 | // 插件接口, 所有插件都必须继承该接口 28 | class IUIPlugin : public x3::IObject 29 | { 30 | X3DEFINE_IID(IUIPlugin); 31 | 32 | public: 33 | IUIPlugin() { m_spBuddy = NULL; m_defaultCategory = false; } 34 | 35 | const QString& Name() { return m_strName; } 36 | void Name(const QString& val) { m_strName = val; } 37 | 38 | const QString& Caption() { return m_strCaption; } 39 | void Caption(const QString& val) { m_strCaption = val; } 40 | 41 | const QString& Category() { return m_strCategory; } 42 | void Category(const QString& val) { m_strCategory = val; } 43 | 44 | bool defaultCategory() { return m_defaultCategory; } 45 | void defaultCategory(const bool val) { m_defaultCategory = val; } 46 | 47 | const QString& Tooltip() { return m_strTooltip; } 48 | void Tooltip(const QString& val) { m_strTooltip = val; } 49 | 50 | const QString& Description() { return m_strDescription; } 51 | void Description(const QString& val) { m_strDescription = val; } 52 | 53 | const QString& BitmapName() { return m_strBitmapName; } 54 | void BitmapName(const QString& val) { m_strBitmapName = val; } 55 | 56 | virtual bool readConfig( const QDomNode& node, QDomDocument & document, QString& errorMessage ) 57 | { 58 | return true; 59 | } 60 | 61 | virtual bool writeConfig( const QDomNode& node, QDomDocument & document, QString& errorMessage ) 62 | { 63 | return true; 64 | } 65 | 66 | // 初始化 67 | virtual bool Initialize() = 0; 68 | // 析构 69 | virtual bool UnInitialize() = 0; 70 | virtual bool SetBuddy(x3::IObject* val) = 0;// { m_spBuddy = val; return true; } 71 | 72 | protected: 73 | QString m_strName; 74 | QString m_strCaption; 75 | QString m_strCategory; 76 | QString m_strTooltip; 77 | QString m_strDescription; 78 | QString m_strBitmapName; 79 | x3::AnyObject m_spBuddy; 80 | bool m_defaultCategory; 81 | }; 82 | 83 | // 视图插件 84 | class IUIView : public x3::IObject 85 | { 86 | X3DEFINE_IID(IUIView); 87 | 88 | public: 89 | IUIView() { mMainWindow = nullptr; } 90 | 91 | virtual QWidget* getViewWidget() = 0; 92 | virtual void setMainWindow(QMainWindow* win) { mMainWindow = win; } 93 | virtual QMainWindow* mainWindow() { return mMainWindow; } 94 | 95 | protected: 96 | QMainWindow* mMainWindow; 97 | }; 98 | 99 | // 按钮插件 100 | class IUICommand : public x3::IObject 101 | { 102 | X3DEFINE_IID(IUICommand); 103 | 104 | public: 105 | virtual QWidget* getButtonWidget() { return 0; } 106 | virtual QWidget* getWndWidget() { return 0; } 107 | }; 108 | 109 | 110 | END_NAMESPACE_CBERSPLUGINS 111 | #endif // IPLUGIN_H 112 | -------------------------------------------------------------------------------- /CbersPluginCore/UIPluginsEvents.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | #include 3 | #include "iobject.h" 4 | #include "module/plugininc.h" 5 | #include "observer/fireeventex.h" 6 | #include "observer/fireobjeventex.h" 7 | #include 8 | #include 9 | #include "cbersplugincore_global.h" 10 | 11 | BEGIN_NAMESPACE_CBERSPLUGINS 12 | 13 | #ifndef EVENT_NAMESPACE 14 | #define EVENT_NAMESPACE "CbersEvent" 15 | #endif 16 | 17 | X3DEFINE_OBJEVENT_4Break(EventMouseDown, long, long, long, long, EVENT_NAMESPACE); 18 | X3DEFINE_OBJEVENT_4Break(EventMouseMove, long, long, long, long, EVENT_NAMESPACE); 19 | X3DEFINE_OBJEVENT_4Break(EventMouseUp, long, long, long, long, EVENT_NAMESPACE); 20 | X3DEFINE_OBJEVENT_4Break(EventButtonDblClk, long, long, long, long, EVENT_NAMESPACE); 21 | X3DEFINE_OBJEVENT_5Break(EventMouseWheel, long, long, short, long, long, EVENT_NAMESPACE); 22 | X3DEFINE_OBJEVENT_4Break(EventMouseHover, long, long, long, long, EVENT_NAMESPACE); 23 | X3DEFINE_OBJEVENT_0Break(EventMouseLeave, EVENT_NAMESPACE); 24 | X3DEFINE_OBJEVENT_3Break(EventContextMenu, long, long, long, EVENT_NAMESPACE); 25 | 26 | class IUIMouseResponse : x3::ObserverObject 27 | { 28 | public: 29 | IUIMouseResponse() 30 | { 31 | X3_REGISTER_OBSERVER_OBJECT(EventMouseDown, &IUIMouseResponse::OnMouseDown); 32 | X3_REGISTER_OBSERVER_OBJECT(EventMouseMove, &IUIMouseResponse::OnMouseMove); 33 | X3_REGISTER_OBSERVER_OBJECT(EventMouseUp, &IUIMouseResponse::OnMouseUp); 34 | X3_REGISTER_OBSERVER_OBJECT(EventButtonDblClk, &IUIMouseResponse::OnButtonDblClk); 35 | X3_REGISTER_OBSERVER_OBJECT(EventMouseWheel, &IUIMouseResponse::OnMouseWheel); 36 | X3_REGISTER_OBSERVER_OBJECT(EventMouseHover, &IUIMouseResponse::OnMouseHover); 37 | X3_REGISTER_OBSERVER_OBJECT(EventMouseLeave, &IUIMouseResponse::OnMouseLeave); 38 | X3_REGISTER_OBSERVER_OBJECT(EventContextMenu, &IUIMouseResponse::OnContextMenu); 39 | } 40 | 41 | virtual ~IUIMouseResponse() 42 | { 43 | x3::unregisterObserver(this); 44 | } 45 | 46 | public: 47 | virtual bool OnMouseDown(long button, long shift, long x, long y) { return true; } 48 | virtual bool OnMouseMove(long button, long shift, long x, long y) { return true; } 49 | virtual bool OnMouseUp(long button, long shift, long x, long y) { return true; } 50 | virtual bool OnButtonDblClk(long button, long shift, long x, long y) { return true; } 51 | virtual bool OnMouseWheel(long button, long shift, short zDelta, long x, long y) { return true; } 52 | virtual bool OnMouseHover(long button, long shift, long x, long y) { return true; } 53 | virtual bool OnMouseLeave() { return true; } 54 | virtual bool OnContextMenu(long hWnd,long x, long y) { return true; } 55 | }; 56 | 57 | X3DEFINE_OBJEVENT_2Break(EventKeyDown, long, long, EVENT_NAMESPACE); 58 | X3DEFINE_OBJEVENT_2Break(EventKeyUp, long, long, EVENT_NAMESPACE); 59 | 60 | class IUIKeyResponse : public x3::ObserverObject 61 | { 62 | public: 63 | IUIKeyResponse() 64 | { 65 | X3_REGISTER_OBSERVER_OBJECT(EventKeyDown, &IUIKeyResponse::OnKeyDown); 66 | X3_REGISTER_OBSERVER_OBJECT(EventKeyUp, &IUIKeyResponse::OnKeyUp); 67 | } 68 | 69 | virtual ~IUIKeyResponse() 70 | { 71 | x3::unregisterObserver(this); 72 | } 73 | 74 | public: 75 | virtual bool OnKeyDown(long keyCode, long shift) { return false; } 76 | virtual bool OnKeyUp(long keyCode, long shift) { return false; } 77 | }; 78 | 79 | X3DEFINE_OBJEVENT_4Break(EventAnything, x3::IObject*, const std::string&, const QVariant&, const QVariant&, EVENT_NAMESPACE); 80 | 81 | class IAnythingEventObserver : public x3::ObserverObject 82 | { 83 | public: 84 | IAnythingEventObserver() 85 | { 86 | m_bRegister = false; 87 | } 88 | 89 | virtual ~IAnythingEventObserver() 90 | { 91 | unregisterHandlers(); 92 | } 93 | 94 | public: 95 | // Event 96 | virtual void registerHandlers() 97 | { 98 | if( m_bRegister ) 99 | return; 100 | 101 | X3_REGISTER_OBSERVER_OBJECT(EventAnything, &IAnythingEventObserver::_OnAnything); 102 | m_bRegister = true; 103 | } 104 | 105 | virtual void unregisterHandlers() 106 | { 107 | if( !m_bRegister ) 108 | return; 109 | 110 | x3::unregisterObserver(this); 111 | m_bRegister = false; 112 | } 113 | 114 | virtual void supportsEvent(const std::string& eventKey) 115 | { 116 | if( !eventKey.empty() ) 117 | { 118 | std::string lowerKey = eventKey; 119 | std::transform(eventKey.begin(), eventKey.end(), lowerKey.begin(), tolower); 120 | m_supportedEvents.insert(std::map::value_type(lowerKey, lowerKey)); 121 | } 122 | } 123 | 124 | virtual bool acceptsEvent(const std::string& eventKey) 125 | { 126 | if( eventKey.empty() ) 127 | return false; 128 | 129 | if( m_supportedEvents.size()<=0 ) 130 | return true; 131 | 132 | std::string lowerKey = eventKey; 133 | std::transform(eventKey.begin(), eventKey.end(), lowerKey.begin(), tolower); 134 | return m_supportedEvents.find(lowerKey)!=m_supportedEvents.end(); 135 | } 136 | 137 | // Node Event 138 | virtual bool OnAnything(x3::IObject* sender, const std::string& eventKey, const QVariant& wParam, const QVariant& lParam) { return true; } 139 | 140 | protected: 141 | bool _OnAnything(x3::IObject* sender, const std::string& eventKey, const QVariant& wParam, const QVariant& lParam) 142 | { 143 | if( acceptsEvent(eventKey) ) 144 | OnAnything(sender, eventKey, wParam, lParam); 145 | 146 | return true; 147 | } 148 | 149 | protected: 150 | bool m_bRegister; 151 | std::map m_supportedEvents; 152 | }; 153 | 154 | END_NAMESPACE_CBERSPLUGINS 155 | 156 | -------------------------------------------------------------------------------- /CbersPluginCore/cbersplugincore_global.h: -------------------------------------------------------------------------------- 1 | #ifndef CBERSPLUGINCORE_GLOBAL_H 2 | #define CBERSPLUGINCORE_GLOBAL_H 3 | 4 | #include 5 | 6 | #if defined(CBERSPLUGINCORE_LIBRARY) 7 | # define CBERSPLUGINCORESHARED_EXPORT Q_DECL_EXPORT 8 | #else 9 | # define CBERSPLUGINCORESHARED_EXPORT Q_DECL_IMPORT 10 | #endif 11 | 12 | #define BEGIN_NAMESPACE_CBERSPLUGINS namespace Cbers { namespace Plugins { 13 | #define END_NAMESPACE_CBERSPLUGINS } } 14 | #define USING_NAMESPACE_CBERSPLUGINS using namespace Cbers::Plugins; 15 | 16 | #endif // CBERSPLUGINCORE_GLOBAL_H 17 | -------------------------------------------------------------------------------- /CbersPluginCore/module.cpp: -------------------------------------------------------------------------------- 1 | #include "module/plugininc.h" 2 | #include "module/pluginimpl.h" 3 | #include "module/modulemacro.h" 4 | #include "observer/observerimpl.h" 5 | #include "UICore.h" 6 | 7 | USING_NAMESPACE_CBERSPLUGINS 8 | 9 | XBEGIN_DEFINE_MODULE() 10 | XDEFINE_CLASSMAP_ENTRY_Singleton(CUICore) 11 | XEND_DEFINE_MODULE_DLL() 12 | 13 | OUTAPI bool x3InitializePlugin() 14 | { 15 | return true; 16 | } 17 | 18 | OUTAPI void x3UninitializePlugin() 19 | { 20 | } 21 | -------------------------------------------------------------------------------- /CbersPluginCore/pluginconfig.pri: -------------------------------------------------------------------------------- 1 | #------------------------------------------------- 2 | # 3 | # Project created by QtCreator 2018-01-04T16:43:03 4 | # 5 | #------------------------------------------------- 6 | QT += core xml 7 | greaterThan(QT_MAJOR_VERSION, 4): QT += widgets 8 | 9 | CONFIG += c++11 10 | 11 | TARGET_EXT = .pln 12 | 13 | OUTPUT_INCLUDE_PATH = $$SDK_PATH/include/PluginCore/ 14 | 15 | INCLUDEPATH += $$SDK_PATH/include 16 | INCLUDEPATH += $$SDK_PATH/include/x3py 17 | INCLUDEPATH += $$OUTPUT_INCLUDE_PATH 18 | DEPENDPATH += $$SDK_PATH/include 19 | DEPENDPATH += $$SDK_PATH/include/x3py 20 | DEPENDPATH += $$OUTPUT_INCLUDE_PATH 21 | 22 | { 23 | CONFIG(debug, debug|release){ 24 | DESTDIR = $$SDK_PATH/bin/debug/CbersPlugins 25 | } 26 | else{ 27 | DESTDIR = $$SDK_PATH/bin/release/CbersPlugins 28 | } 29 | } 30 | 31 | !isEmpty(TRANSLATION_LANGS){ 32 | TRANSLATION_DIR = $$SDK_PATH/i18n/ 33 | TRANSLATIONS = 34 | for(LANG, $$TRANSLATION_LANGS) { 35 | TRANSLATIONS += $$TRANSLATION_DIR/$$TARGET_$$LANG.ts 36 | } 37 | } 38 | 39 | # Copies the given files to the destination directory 40 | defineReplace(copyToDir) { 41 | files = $$1 42 | DIR = $$2 43 | SRCDIR = $$3 44 | LINK = 45 | 46 | win32:DIR ~= s,/,\\,g 47 | win32{ 48 | LINK += if not exist $$quote($$DIR) ( $$QMAKE_MKDIR $$quote($$DIR) ) $$escape_expand(\\n\\t) 49 | } 50 | unix{ 51 | LINK += $$QMAKE_MKDIR $$quote($$DIR) $$escape_expand(\\n\\t) 52 | } 53 | for(FILE, files) { 54 | !isEmpty(SRCDIR){ 55 | FILE = $$SRCDIR/$$FILE 56 | } 57 | win32:FILE ~= s,/,\\,g 58 | LINK += $$QMAKE_COPY $$quote($$FILE) $$quote($$DIR) $$escape_expand(\\n\\t) 59 | } 60 | return($$LINK) 61 | } 62 | 63 | !isEmpty(OUTPUT_INCLUDE_PATH){ 64 | win32{ 65 | OUTPUT_INCLUDE_PATH ~= s,/,\\,g 66 | #QMAKE_POST_LINK += if exist $$quote($$OUTPUT_INCLUDE_PATH) ( rmdir /S /Q $$quote($$OUTPUT_INCLUDE_PATH) ) $$escape_expand(\\n\\t) 67 | QMAKE_POST_LINK += cd $$quote($$PROJECT_PATH) $$escape_expand(\\n\\t) 68 | } 69 | unix{ 70 | #QMAKE_POST_LINK += rm -rf $$quote($$OUTPUT_INCLUDE_PATH) $$escape_expand(\\n\\t) 71 | QMAKE_POST_LINK += cd $$quote($$PROJECT_PATH) $$escape_expand(\\n\\t) 72 | } 73 | 74 | QMAKE_POST_LINK += $$copyToDir($$HEADERS, $$OUTPUT_INCLUDE_PATH, $$PROJECT_PATH) 75 | } 76 | 77 | # Auto Update And Release TRANSLATIONS 78 | !isEmpty(TRANSLATION_DIR){ 79 | win32:TRANSLATION_DIR ~= s,/,\\,g 80 | win32{ 81 | QMAKE_POST_LINK += if not exist $$quote($$TRANSLATION_DIR) ( $$QMAKE_MKDIR $$quote($$TRANSLATION_DIR) ) $$escape_expand(\\n\\t) 82 | } 83 | unix{ 84 | QMAKE_POST_LINK += $$QMAKE_MKDIR -p $$quote($$TRANSLATION_DIR) $$escape_expand(\\n\\t) 85 | } 86 | QMAKE_POST_LINK += $(QTDIR)/bin/lupdate $$PROJECT_PATH/$$TARGET.pro $$escape_expand(\\n\\t) 87 | QMAKE_POST_LINK += $(QTDIR)/bin/lrelease $$PROJECT_PATH/$$TARGET.pro $$escape_expand(\\n\\t) 88 | 89 | RELEASE_TRANSLATIONS = $$TRANSLATIONS 90 | RELEASE_TRANSLATIONS ~= s,.ts,.qm,g 91 | QMAKE_POST_LINK += $$copyToDir($$RELEASE_TRANSLATIONS, $$DESTDIR/../i18n/) 92 | } 93 | 94 | unix{ 95 | SRCEXT = .so 96 | DSTEXT = .pln 97 | QMAKE_POST_LINK += mv -f $$quote($$DESTDIR/lib$$TARGET$$SRCEXT) $$quote($$DESTDIR/$$TARGET$$DSTEXT) $$escape_expand(\\n\\t) 98 | } 99 | -------------------------------------------------------------------------------- /CbersUI/CbersUI.pro: -------------------------------------------------------------------------------- 1 | #------------------------------------------------- 2 | # 3 | # Project created by QtCreator 2016-07-12T17:18:16 4 | # 5 | #------------------------------------------------- 6 | QT += core gui 7 | greaterThan(QT_MAJOR_VERSION, 4): QT += widgets 8 | 9 | TEMPLATE = lib 10 | TARGET = CbersUI 11 | 12 | DEFINES += CBERSUI_LIBRARY 13 | 14 | SOURCES += \ 15 | qribbonbar.cpp \ 16 | qribboncategory.cpp \ 17 | qribbonpanel.cpp \ 18 | qribbonstylesheetmanager.cpp \ 19 | qribbontabwidget.cpp \ 20 | qtitlewidget.cpp \ 21 | qseparator.cpp 22 | 23 | HEADERS +=\ 24 | qribbonbar.h \ 25 | qribboncategory.h \ 26 | qribbonpanel.h \ 27 | qribbonstylesheetmanager.h \ 28 | qribbontabwidget.h \ 29 | qtitlewidget.h \ 30 | cbersui_global.h \ 31 | qseparator.h 32 | 33 | { 34 | CONFIG(debug, debug|release){ 35 | TARGET = $$join(TARGET,,,d) 36 | 37 | DESTDIR = $$PWD/../lib/debug 38 | DLLDESTDIR = $$PWD/../bin/debug 39 | } 40 | else{ 41 | DESTDIR = $$PWD/../lib/release 42 | DLLDESTDIR = $$PWD/../bin/release 43 | } 44 | } 45 | 46 | RESOURCES += \ 47 | cbersui.qrc 48 | 49 | TRANSLATION_DIR = $$PWD/../i18n/ 50 | TRANSLATIONS = $$TRANSLATION_DIR/CbersUI_zh_CN.ts 51 | 52 | # Copies the given files to the destination directory 53 | defineReplace(copyToDir) { 54 | files = $$1 55 | DIR = $$2 56 | SRCDIR = $$3 57 | LINK = 58 | 59 | win32:DIR ~= s,/,\\,g 60 | win32{ 61 | LINK += if not exist $$quote($$DIR) ( $$QMAKE_MKDIR $$quote($$DIR) ) $$escape_expand(\\n\\t) 62 | } 63 | unix{ 64 | LINK += $$QMAKE_MKDIR $$quote($$DIR) $$escape_expand(\\n\\t) 65 | } 66 | for(FILE, files) { 67 | !isEmpty(SRCDIR){ 68 | FILE = $$SRCDIR/$$FILE 69 | } 70 | win32:FILE ~= s,/,\\,g 71 | LINK += $$QMAKE_COPY $$quote($$FILE) $$quote($$DIR) $$escape_expand(\\n\\t) 72 | } 73 | return($$LINK) 74 | } 75 | 76 | SDK_PATH = $$PWD/../include/CbersUI/ 77 | win32{ 78 | SDK_PATH ~= s,/,\\,g 79 | QMAKE_POST_LINK += if exist $$quote($$SDK_PATH) ( rmdir /S /Q $$quote($$SDK_PATH) ) $$escape_expand(\\n\\t) 80 | QMAKE_POST_LINK += cd $$quote($$PWD) $$escape_expand(\\n\\t) 81 | } 82 | unix{ 83 | QMAKE_POST_LINK += rm -rf $$quote($$SDK_PATH) $$escape_expand(\\n\\t) 84 | QMAKE_POST_LINK += cd $$quote($$PWD) $$escape_expand(\\n\\t) 85 | } 86 | 87 | QMAKE_POST_LINK += $$copyToDir($$HEADERS, $$SDK_PATH, $$PWD) 88 | 89 | # Auto Update And Release TRANSLATIONS 90 | win32:TRANSLATION_DIR ~= s,/,\\,g 91 | win32{ 92 | QMAKE_POST_LINK += if not exist $$quote($$TRANSLATION_DIR) ( $$QMAKE_MKDIR $$quote($$TRANSLATION_DIR) ) $$escape_expand(\\n\\t) 93 | } 94 | unix{ 95 | QMAKE_POST_LINK += $$QMAKE_MKDIR -p $$quote($$TRANSLATION_DIR) $$escape_expand(\\n\\t) 96 | } 97 | 98 | QMAKE_POST_LINK += $(QTDIR)/bin/lupdate $$PWD/CbersUI.pro $$escape_expand(\\n\\t) 99 | QMAKE_POST_LINK += $(QTDIR)/bin/lrelease $$PWD/CbersUI.pro $$escape_expand(\\n\\t) 100 | 101 | RELEASE_TRANSLATIONS = $$TRANSLATIONS 102 | RELEASE_TRANSLATIONS ~= s,.ts,.qm,g 103 | QMAKE_POST_LINK += $$copyToDir($$RELEASE_TRANSLATIONS, $$DLLDESTDIR/i18n/) 104 | -------------------------------------------------------------------------------- /CbersUI/Resource/office2007_black/AppCaption/Btn_HideElements.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/longhuan2018/CbersUI/85bfe9f16e0ff17361875461818006efc51d8d28/CbersUI/Resource/office2007_black/AppCaption/Btn_HideElements.png -------------------------------------------------------------------------------- /CbersUI/Resource/office2007_black/AppCaption/Btn_ShowElements.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/longhuan2018/CbersUI/85bfe9f16e0ff17361875461818006efc51d8d28/CbersUI/Resource/office2007_black/AppCaption/Btn_ShowElements.png -------------------------------------------------------------------------------- /CbersUI/Resource/office2007_black/AppCaption/SysBtn_Close.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/longhuan2018/CbersUI/85bfe9f16e0ff17361875461818006efc51d8d28/CbersUI/Resource/office2007_black/AppCaption/SysBtn_Close.png -------------------------------------------------------------------------------- /CbersUI/Resource/office2007_black/AppCaption/SysBtn_Maximize.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/longhuan2018/CbersUI/85bfe9f16e0ff17361875461818006efc51d8d28/CbersUI/Resource/office2007_black/AppCaption/SysBtn_Maximize.png -------------------------------------------------------------------------------- /CbersUI/Resource/office2007_black/AppCaption/SysBtn_Minimize.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/longhuan2018/CbersUI/85bfe9f16e0ff17361875461818006efc51d8d28/CbersUI/Resource/office2007_black/AppCaption/SysBtn_Minimize.png -------------------------------------------------------------------------------- /CbersUI/Resource/office2007_black/AppCaption/SysBtn_Restore.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/longhuan2018/CbersUI/85bfe9f16e0ff17361875461818006efc51d8d28/CbersUI/Resource/office2007_black/AppCaption/SysBtn_Restore.png -------------------------------------------------------------------------------- /CbersUI/Resource/office2007_black/Black/caret-down_ffffff_14.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/longhuan2018/CbersUI/85bfe9f16e0ff17361875461818006efc51d8d28/CbersUI/Resource/office2007_black/Black/caret-down_ffffff_14.png -------------------------------------------------------------------------------- /CbersUI/Resource/office2007_black/Black/caret-right_ffffff_14.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/longhuan2018/CbersUI/85bfe9f16e0ff17361875461818006efc51d8d28/CbersUI/Resource/office2007_black/Black/caret-right_ffffff_14.png -------------------------------------------------------------------------------- /CbersUI/Resource/office2007_black/Black/check.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/longhuan2018/CbersUI/85bfe9f16e0ff17361875461818006efc51d8d28/CbersUI/Resource/office2007_black/Black/check.png -------------------------------------------------------------------------------- /CbersUI/Resource/office2007_black/Black/cross.svg: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 19 | 21 | 22 | 24 | image/svg+xml 25 | 27 | 28 | 29 | 30 | 32 | 54 | 59 | 60 | -------------------------------------------------------------------------------- /CbersUI/Resource/office2007_black/Black/down_arrow.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/longhuan2018/CbersUI/85bfe9f16e0ff17361875461818006efc51d8d28/CbersUI/Resource/office2007_black/Black/down_arrow.png -------------------------------------------------------------------------------- /CbersUI/Resource/office2007_black/Black/eye-blocked.svg: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 19 | 21 | 22 | 24 | image/svg+xml 25 | 27 | 28 | 29 | 30 | 32 | 52 | 57 | 62 | 67 | 68 | -------------------------------------------------------------------------------- /CbersUI/Resource/office2007_black/Black/eye.svg: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 19 | 21 | 22 | 24 | image/svg+xml 25 | 27 | 28 | 29 | 30 | 32 | 52 | 56 | 57 | -------------------------------------------------------------------------------- /CbersUI/Resource/office2007_black/Black/up_arrow.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/longhuan2018/CbersUI/85bfe9f16e0ff17361875461818006efc51d8d28/CbersUI/Resource/office2007_black/Black/up_arrow.png -------------------------------------------------------------------------------- /CbersUI/Resource/office2007_blue/AppCaption/Btn_HideElements.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/longhuan2018/CbersUI/85bfe9f16e0ff17361875461818006efc51d8d28/CbersUI/Resource/office2007_blue/AppCaption/Btn_HideElements.png -------------------------------------------------------------------------------- /CbersUI/Resource/office2007_blue/AppCaption/Btn_ShowElements.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/longhuan2018/CbersUI/85bfe9f16e0ff17361875461818006efc51d8d28/CbersUI/Resource/office2007_blue/AppCaption/Btn_ShowElements.png -------------------------------------------------------------------------------- /CbersUI/Resource/office2007_blue/AppCaption/SysBtn_Close.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/longhuan2018/CbersUI/85bfe9f16e0ff17361875461818006efc51d8d28/CbersUI/Resource/office2007_blue/AppCaption/SysBtn_Close.png -------------------------------------------------------------------------------- /CbersUI/Resource/office2007_blue/AppCaption/SysBtn_Maximize.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/longhuan2018/CbersUI/85bfe9f16e0ff17361875461818006efc51d8d28/CbersUI/Resource/office2007_blue/AppCaption/SysBtn_Maximize.png -------------------------------------------------------------------------------- /CbersUI/Resource/office2007_blue/AppCaption/SysBtn_Minimize.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/longhuan2018/CbersUI/85bfe9f16e0ff17361875461818006efc51d8d28/CbersUI/Resource/office2007_blue/AppCaption/SysBtn_Minimize.png -------------------------------------------------------------------------------- /CbersUI/Resource/office2007_blue/AppCaption/SysBtn_Restore.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/longhuan2018/CbersUI/85bfe9f16e0ff17361875461818006efc51d8d28/CbersUI/Resource/office2007_blue/AppCaption/SysBtn_Restore.png -------------------------------------------------------------------------------- /CbersUI/Resource/office2007_blue/office2007_blue.qss: -------------------------------------------------------------------------------- 1 | QMainWindow#QRibbonMainWindow{ 2 | background-color: #BEDAFE; 3 | border: 1px solid rgba(24, 131, 215, 255); 4 | min-width: 100%; 5 | } 6 | QWidget#QRibbonTitleWidget { 7 | background-color: #ffffff; 8 | } 9 | 10 | QPushButton#Btn_ShowElements {border-image: url(:/office2007/Resource/office2007_blue/AppCaption/Btn_ShowElements.png);} 11 | QPushButton#Btn_HideElements {border-image: url(:/office2007/Resource/office2007_blue/AppCaption/Btn_HideElements.png);} 12 | QPushButton#SysBtn_Minimize {border-image: url(:/office2007/Resource/office2007_blue/AppCaption/SysBtn_Minimize.png);} 13 | QPushButton#SysBtn_Minimize:hover {background-color: rgba(229, 229, 229, 255);} 14 | QPushButton#SysBtn_Minimize:pressed {background-color: rgba(202, 202, 202, 255);} 15 | QPushButton#SysBtn_Restore {border-image: url(:/office2007/Resource/office2007_blue/AppCaption/SysBtn_Restore.png);} 16 | QPushButton#SysBtn_Restore:hover {background-color: rgba(229, 229, 229, 255);} 17 | QPushButton#SysBtn_Restore:pressed {background-color: rgba(202, 202, 202, 255);} 18 | QPushButton#SysBtn_Maximize {border-image: url(:/office2007/Resource/office2007_blue/AppCaption/SysBtn_Maximize.png);} 19 | QPushButton#SysBtn_Maximize:hover {background-color: rgba(229, 229, 229, 255);} 20 | QPushButton#SysBtn_Maximize:pressed {background-color: rgba(202, 202, 202, 255);} 21 | QPushButton#SysBtn_Close {border-image: url(:/office2007/Resource/office2007_blue/AppCaption/SysBtn_Close.png);} 22 | QPushButton#SysBtn_Close:hover {background-color: rgba(232, 17, 35, 255);} 23 | QPushButton#SysBtn_Close:pressed {background-color: rgba(241, 112, 122, 255);} 24 | 25 | QTabWidget#QRibbonTabWidget::pane { 26 | background-color: qlineargradient(spread:pad, x1:0, y1:0, x2:0, y2:1, stop:0 rgba(216, 229, 247, 255), stop:0.2 rgba(204, 220, 242, 255), stop:0.8 rgba(178, 202, 234, 255), stop:1 rgba(207, 224, 245, 255)); 27 | border: 1px solid #90B5E4; 28 | border-radius: 5px; 29 | padding: 1px; 30 | } 31 | QTabWidget#QRibbonTabWidget { 32 | background-color: #BEDAFE; 33 | min-width: 100%; 34 | left: 0px; 35 | right: 0px; 36 | } 37 | QTabWidget#QRibbonTabWidget::tab-bar { 38 | left: 5px; 39 | right: 5px; 40 | background-color: #BEDAFE; 41 | min-width: 100%; 42 | } 43 | QTabWidget#QRibbonTabWidget QTabBar::tab { 44 | margin-top: 5px; 45 | min-width: 55px; 46 | background-color: #BEDAFE; 47 | height: 25px; 48 | border: 1px solid #BEDAFE; 49 | color: #4B7CB4; 50 | border-bottom: 0px solid #BEDAFE; 51 | margin-left: 2px; 52 | margin-right: 2px; 53 | } 54 | QTabWidget#QRibbonTabWidget QTabBar::tab:!selected{ 55 | border: 0px; 56 | background-color: transparent; 57 | } 58 | QTabWidget#QRibbonTabWidget QTabBar::tab:selected{ 59 | border: 1px solid #90B5E4; 60 | background-color: qlineargradient(spread:pad, x1:0, y1:0, x2:0, y2:1, stop:0 rgba(255, 255, 255, 255), stop:0.1 rgba(239, 244, 251, 255), stop:1 rgba(231, 239, 249, 255)); 61 | border-bottom: 1px solid #E1EAF5; 62 | border-top-left-radius: 4px; 63 | border-top-right-radius: 4px; 64 | color: #4B7CB4; 65 | } 66 | QTabWidget#QRibbonTabWidget QTabBar::tab:hover{ 67 | border: 1px solid #99BBE8; 68 | background-color: qradialgradient(spread:pad, cx:0.5, cy:0.5, radius:0.75, fx:0.5, fy:-0.5, stop:0 #BEDAFE, stop:0.5 #BEDAFE, stop:1 rgba(255, 197, 115, 168)); 69 | border-top-left-radius: 4px; 70 | border-top-right-radius: 4px; 71 | color: #4B7CB4; 72 | border-bottom: 0px solid rgba(255, 197, 115, 168); 73 | } 74 | QTabWidget#QRibbonTabWidget QTabBar::tab:selected:hover { 75 | background-color: qlineargradient(spread:pad, x1:0, y1:0, x2:0, y2:1, stop:0 rgba(255, 255, 255, 255), stop:0.1 rgba(239, 244, 251, 255), stop:1 rgba(231, 239, 249, 255)); 76 | border-top-left-radius: 4px; 77 | border-top-right-radius: 4px; 78 | border-style: solid; 79 | border-width: 1px; 80 | border-color: rgba(255, 197, 115, 150); 81 | border-bottom: 1px solid #E1EAF5; 82 | } 83 | QTabWidget#QRibbonTabWidget QTabBar::tab:first { 84 | margin-left: 4px; 85 | } 86 | QTabWidget#QRibbonTabWidget QTabBar::tab:last { 87 | margin-right: 4px; 88 | } 89 | QTabWidget#QRibbonTabWidget QGroupBox::title { 90 | position: absolute; 91 | subcontrol-origin: padding; 92 | subcontrol-position: bottom center; 93 | min-width: 10000%; 94 | max-width: 10000%; 95 | border-bottom-left-radius: 3px; 96 | border-bottom-right-radius: 3px; 97 | border: 1px solid #B6C8D8; 98 | border-top-style: none; 99 | border-bottom-style: none; 100 | color: #4B7CB4; 101 | background-color: qlineargradient(x1: 0, y1: 0, x2: 0, y2: 1,stop: 0 #C0D7EF, stop: 1 #BFD7EE); 102 | } 103 | QTabWidget#QRibbonTabWidget QGroupBox { 104 | background-color: qlineargradient(spread:pad, x1:0, y1:0, x2:0, y2:1, stop:0 rgba(218, 229, 242, 255), stop:0.2 rgba(218, 229, 242, 255), stop:0.201 rgba(198, 215, 236, 255), stop:1 rgba(213, 229, 243, 255)); 105 | border: 1px solid #B6C8D8; 106 | border-radius: 3px; 107 | } 108 | QWidget#QRibbonPanelFooter { 109 | background-color: #c2d7f2; 110 | } 111 | QLabel#QRibbonPanelFooterLabel { 112 | color: #4B7CB4; 113 | } 114 | QPushButton#sysIconLabel { 115 | background-color: rgba(229, 229, 229, 0); 116 | } 117 | QPushButton#sysIconLabel:hover { 118 | background-color: rgba(229, 229, 229, 0); 119 | } 120 | QPushButton#sysIconLabel:pressed { 121 | background-color: rgba(202, 202, 202, 0); 122 | } 123 | QPushButton#sysIconLabel::menu-indicator{ 124 | image:none; 125 | } 126 | -------------------------------------------------------------------------------- /CbersUI/cbersui.qrc: -------------------------------------------------------------------------------- 1 | 2 | 3 | Resource/office2007_blue/office2007_blue.qss 4 | Resource/office2007_blue/AppCaption/SysBtn_Close.png 5 | Resource/office2007_blue/AppCaption/SysBtn_Maximize.png 6 | Resource/office2007_blue/AppCaption/SysBtn_Minimize.png 7 | Resource/office2007_blue/AppCaption/SysBtn_Restore.png 8 | Resource/office2007_blue/AppCaption/Btn_HideElements.png 9 | Resource/office2007_blue/AppCaption/Btn_ShowElements.png 10 | Resource/office2007_black/AppCaption/Btn_HideElements.png 11 | Resource/office2007_black/AppCaption/Btn_ShowElements.png 12 | Resource/office2007_black/AppCaption/SysBtn_Close.png 13 | Resource/office2007_black/AppCaption/SysBtn_Maximize.png 14 | Resource/office2007_black/AppCaption/SysBtn_Minimize.png 15 | Resource/office2007_black/AppCaption/SysBtn_Restore.png 16 | Resource/office2007_black/office2007_black.qss 17 | Resource/office2007_black/Black/caret-down_ffffff_14.png 18 | Resource/office2007_black/Black/caret-right_ffffff_14.png 19 | Resource/office2007_black/Black/check.png 20 | Resource/office2007_black/Black/cross.svg 21 | Resource/office2007_black/Black/down_arrow.png 22 | Resource/office2007_black/Black/eye.svg 23 | Resource/office2007_black/Black/eye-blocked.svg 24 | Resource/office2007_black/Black/up_arrow.png 25 | 26 | 27 | -------------------------------------------------------------------------------- /CbersUI/cbersui_global.h: -------------------------------------------------------------------------------- 1 | #ifndef CBERSUI_GLOBAL_H 2 | #define CBERSUI_GLOBAL_H 3 | 4 | #include 5 | 6 | #if defined(CBERSUI_LIBRARY) 7 | # define CBERSUI_EXPORT Q_DECL_EXPORT 8 | #else 9 | # define CBERSUI_EXPORT Q_DECL_IMPORT 10 | #endif 11 | 12 | #if (QT_VERSION >= QT_VERSION_CHECK(5, 0, 0)) 13 | #define BEGIN_NAMESPACE_CBERSUI namespace Cbers { namespace UI { 14 | #define END_NAMESPACE_CBERSUI } } 15 | #define USING_NAMESPACE_CBERSUI using namespace Cbers::UI; 16 | #else 17 | #define BEGIN_NAMESPACE_CBERSUI 18 | #define END_NAMESPACE_CBERSUI 19 | #define USING_NAMESPACE_CBERSUI 20 | #endif 21 | 22 | #endif // CBERSUI_GLOBAL_H 23 | -------------------------------------------------------------------------------- /CbersUI/qribbonbar.h: -------------------------------------------------------------------------------- 1 | #ifndef QRIBBONBAR_H 2 | #define QRIBBONBAR_H 3 | 4 | #include 5 | #include 6 | #include 7 | #include 8 | #include 9 | #include 10 | #include 11 | #include "cbersui_global.h" 12 | #include "qribboncategory.h" 13 | 14 | BEGIN_NAMESPACE_CBERSUI 15 | class CBERSUI_EXPORT QRibbonBar : public QWidget 16 | { 17 | Q_OBJECT 18 | public: 19 | explicit QRibbonBar(QWidget *parent = 0); 20 | virtual ~QRibbonBar(); 21 | 22 | public: 23 | QRibbonCategory* AddCategory(const QString& name, int nInsertAt = -1); 24 | int GetCategoryCount() const; 25 | int GetVisibleCategoryCount() const; 26 | QRibbonCategory* GetCategory(int nIndex) const; 27 | int GetCategoryIndex(QRibbonCategory* pCategory) const; 28 | 29 | void ShowCategory(int nIndex, bool bShow = true); 30 | bool RemoveCategory(int nIndex); 31 | void RemoveAllCategories(); 32 | 33 | virtual bool SetActiveCategory(QRibbonCategory* pCategory); 34 | QRibbonCategory* GetActiveCategory() const; 35 | 36 | QList FindCategoryByName(const QString& name); 37 | 38 | signals: 39 | 40 | public slots: 41 | void showRibbonElements(); 42 | void hideRibbonElements(); 43 | void toggleRibbonElements(bool show); 44 | 45 | protected: 46 | bool eventFilter(QObject *target, QEvent *e); 47 | 48 | protected: 49 | // TabWidget 50 | QTabWidget* mTabWidget; 51 | QList mCategories; 52 | 53 | QPushButton *mStylesButton; 54 | QPushButton *mHelpButton; 55 | 56 | QPushButton *mShowElementsButton; 57 | QPushButton *mHideElementsButton; 58 | 59 | QWidget* mParent; 60 | QWidget* mTitleWidget; 61 | }; 62 | END_NAMESPACE_CBERSUI 63 | #endif // QRIBBONBAR_H 64 | -------------------------------------------------------------------------------- /CbersUI/qribboncategory.cpp: -------------------------------------------------------------------------------- 1 | #include "qribboncategory.h" 2 | #include 3 | #include 4 | USING_NAMESPACE_CBERSUI 5 | 6 | QRibbonCategory::QRibbonCategory(QWidget *parent) : QWidget(parent) 7 | { 8 | setObjectName("QRibbonCategory"); 9 | mHBoxLayout = new QHBoxLayout(); 10 | mHBoxLayout->addStretch(1); 11 | mHBoxLayout->setContentsMargins(0,0,0,0); 12 | mHBoxLayout->setSpacing(2); 13 | setLayout(mHBoxLayout); 14 | } 15 | 16 | QRibbonPanel* QRibbonCategory::addPanel(const QString& name, int nInsertAt) 17 | { 18 | QRibbonPanel* panel = new QRibbonPanel(name, this); 19 | if( nInsertAt<0 ) 20 | { 21 | mHBoxLayout->insertWidget(mPanels.size(), panel); 22 | mPanels.append(panel); 23 | } 24 | else 25 | { 26 | nInsertAt = qMin(nInsertAt, mPanels.size()); 27 | mHBoxLayout->insertWidget(nInsertAt, panel); 28 | mPanels.insert(nInsertAt, panel); 29 | } 30 | 31 | return panel; 32 | } 33 | 34 | bool QRibbonCategory::removePanel(int index, bool bDelete) 35 | { 36 | if( index<0 || index>=mPanels.size() ) 37 | return false; 38 | 39 | QRibbonPanel* panel = mPanels.at(index); 40 | mHBoxLayout->removeWidget(panel); 41 | mPanels.removeAt(index); 42 | if( bDelete ) 43 | panel->deleteLater(); 44 | panel = nullptr; 45 | return true; 46 | } 47 | 48 | int QRibbonCategory::GetPanelIndex(QRibbonPanel* panel) 49 | { 50 | return mPanels.indexOf(panel); 51 | } 52 | 53 | int QRibbonCategory::GetPanelCount() const 54 | { 55 | return mPanels.size(); 56 | } 57 | 58 | QRibbonPanel* QRibbonCategory::GetPanel(int index) 59 | { 60 | if( index<0 || index>=mPanels.size() ) 61 | return nullptr; 62 | 63 | return mPanels.at(index); 64 | } 65 | -------------------------------------------------------------------------------- /CbersUI/qribboncategory.h: -------------------------------------------------------------------------------- 1 | #ifndef QRIBBONCATEGORY_H 2 | #define QRIBBONCATEGORY_H 3 | 4 | #include 5 | #include 6 | #include 7 | #include 8 | #include "cbersui_global.h" 9 | #include "qribbonpanel.h" 10 | 11 | BEGIN_NAMESPACE_CBERSUI 12 | class CBERSUI_EXPORT QRibbonCategory : public QWidget 13 | { 14 | Q_OBJECT 15 | public: 16 | explicit QRibbonCategory(QWidget *parent = 0); 17 | 18 | public: 19 | QRibbonPanel* addPanel(const QString& name, int nInsertAt = -1); 20 | bool removePanel(int index, bool bDelete = true); 21 | int GetPanelIndex(QRibbonPanel* panel); 22 | 23 | int GetPanelCount() const; 24 | QRibbonPanel* GetPanel(int index); 25 | 26 | signals: 27 | 28 | public slots: 29 | 30 | protected: 31 | QHBoxLayout* mHBoxLayout; 32 | QList mPanels; 33 | }; 34 | END_NAMESPACE_CBERSUI 35 | #endif // QRIBBONCATEGORY_H 36 | -------------------------------------------------------------------------------- /CbersUI/qribbonpanel.cpp: -------------------------------------------------------------------------------- 1 | #include "qribbonpanel.h" 2 | #include 3 | #include 4 | #include 5 | #include "qseparator.h" 6 | USING_NAMESPACE_CBERSUI 7 | 8 | QRibbonPanel::QRibbonPanel(const QString& name, QWidget *parent) : QGroupBox(parent) 9 | { 10 | setWindowTitle(name); 11 | setObjectName("QRibbonPanelGroupBox"); 12 | QVBoxLayout* groupBoxLayout = new QVBoxLayout(); 13 | m_pWidgetLayout = new QHBoxLayout(); 14 | m_pWidgetLayout->setSpacing(2); 15 | m_pWidgetLayout->setContentsMargins(0,0,0,0); 16 | groupBoxLayout->addLayout(m_pWidgetLayout); 17 | 18 | { 19 | QWidget* footerWidget = new QWidget(); 20 | footerWidget->setObjectName("QRibbonPanelFooter"); 21 | QHBoxLayout *footerLayout = new QHBoxLayout(); 22 | mTitle = new QLabel(name); 23 | mTitle->setObjectName("QRibbonPanelFooterLabel"); 24 | mTitle->setAlignment(Qt::AlignCenter); 25 | footerLayout->addWidget(mTitle, 0, Qt::AlignCenter); 26 | footerLayout->setContentsMargins(0,0,0,0); 27 | footerWidget->setLayout(footerLayout); 28 | groupBoxLayout->addWidget(footerWidget, 0, Qt::AlignBottom); 29 | } 30 | groupBoxLayout->setContentsMargins(2,0,2,0); 31 | groupBoxLayout->setSpacing(2); 32 | setLayout(groupBoxLayout); 33 | //setMinimumWidth(32); 34 | } 35 | 36 | void QRibbonPanel::Add(QWidget* pElem) 37 | { 38 | if( pElem==nullptr ) 39 | return; 40 | 41 | m_pWidgetLayout->addWidget(pElem); 42 | } 43 | 44 | void QRibbonPanel::AddSeparator() 45 | { 46 | QSeparator* pSeparator = new QSeparator(false); 47 | m_pWidgetLayout->addWidget(pSeparator); 48 | } 49 | 50 | bool QRibbonPanel::Insert(QWidget* pElem, int nIndex) 51 | { 52 | if( pElem==nullptr ) 53 | return false; 54 | 55 | if( nIndex<0 ) 56 | nIndex = 0; 57 | else if( nIndex>mElements.size() ) 58 | nIndex = mElements.size(); 59 | m_pWidgetLayout->insertWidget(nIndex, pElem); 60 | return false; 61 | } 62 | 63 | bool QRibbonPanel::InsertSeparator(int nIndex) 64 | { 65 | if( nIndex<0 ) 66 | nIndex = 0; 67 | else if( nIndex>mElements.size() ) 68 | nIndex = mElements.size(); 69 | 70 | QSeparator* pSeparator = new QSeparator(false); 71 | m_pWidgetLayout->insertWidget(nIndex, pSeparator); 72 | return true; 73 | } 74 | 75 | int QRibbonPanel::GetCount() const 76 | { 77 | return mElements.size(); 78 | } 79 | 80 | bool QRibbonPanel::Remove(int nIndex) 81 | { 82 | if( nIndex<0 || nIndex>mElements.size() ) 83 | return false; 84 | 85 | m_pWidgetLayout->removeWidget(mElements[nIndex]); 86 | mElements.removeAt(nIndex); 87 | return true; 88 | } 89 | 90 | void QRibbonPanel::RemoveAll() 91 | { 92 | for(int i=0; iremoveWidget(mElements[i]); 94 | mElements.clear(); 95 | } 96 | -------------------------------------------------------------------------------- /CbersUI/qribbonpanel.h: -------------------------------------------------------------------------------- 1 | #ifndef QRIBBONPANEL_H 2 | #define QRIBBONPANEL_H 3 | 4 | #include 5 | #include 6 | #include 7 | #include 8 | #include 9 | #include 10 | #include "cbersui_global.h" 11 | 12 | BEGIN_NAMESPACE_CBERSUI 13 | class CBERSUI_EXPORT QRibbonPanel : public QGroupBox 14 | { 15 | Q_OBJECT 16 | public: 17 | explicit QRibbonPanel(const QString& name, QWidget *parent = 0); 18 | 19 | public: 20 | void Add(QWidget* pElem); 21 | void AddSeparator(); 22 | bool Insert(QWidget* pElem, int nIndex); 23 | bool InsertSeparator(int nIndex); 24 | 25 | int GetCount() const; 26 | bool Remove(int nIndex); 27 | void RemoveAll(); 28 | 29 | signals: 30 | 31 | public slots: 32 | 33 | protected: 34 | QHBoxLayout* m_pWidgetLayout; 35 | QLabel* mTitle; 36 | QList mElements; 37 | }; 38 | END_NAMESPACE_CBERSUI 39 | #endif // QRIBBONPANEL_H 40 | -------------------------------------------------------------------------------- /CbersUI/qribbonstylesheetmanager.cpp: -------------------------------------------------------------------------------- 1 | #include "qribbonstylesheetmanager.h" 2 | #include 3 | #include 4 | USING_NAMESPACE_CBERSUI 5 | 6 | QRibbonStyleSheetManager* QRibbonStyleSheetManager::sManager = nullptr; 7 | QRibbonStyleSheetManager::QRibbonStyleSheetManager(QObject *parent) : QObject(parent) 8 | { 9 | addStyleSheet("office2007_blue", loadStyleSheet(":/office2007/Resource/office2007_blue/office2007_blue.qss")); 10 | addStyleSheet("office2007_black", loadStyleSheet(":/office2007/Resource/office2007_black/office2007_black.qss")); 11 | } 12 | 13 | QRibbonStyleSheetManager* QRibbonStyleSheetManager::instance() 14 | { 15 | if( sManager==nullptr ) 16 | sManager = new QRibbonStyleSheetManager(); 17 | return sManager; 18 | } 19 | 20 | QString QRibbonStyleSheetManager::loadStyleSheet(const QString& url) 21 | { 22 | QString styleSheet = ""; 23 | QFile qss(url) ; 24 | if(qss.open(QIODevice::ReadOnly)) 25 | { 26 | styleSheet = qss.readAll(); 27 | qss.close() ; 28 | } 29 | 30 | return styleSheet; 31 | } 32 | 33 | int QRibbonStyleSheetManager::count() 34 | { 35 | return mStyleSheets.count(); 36 | } 37 | 38 | QString QRibbonStyleSheetManager::styleSheet(const QString& name) 39 | { 40 | if( name.isEmpty() ) 41 | return ""; 42 | 43 | return mStyleSheets.value(name.toLower()); 44 | } 45 | 46 | bool QRibbonStyleSheetManager::addStyleSheet(const QString& name, const QString& styleSheet) 47 | { 48 | if( name.isEmpty() || styleSheet.isEmpty() ) 49 | return false; 50 | 51 | mStyleSheets.insert(name.toLower(), styleSheet); 52 | return true; 53 | } 54 | 55 | bool QRibbonStyleSheetManager::removeStyleSheet(const QString& name) 56 | { 57 | return mStyleSheets.remove(name.toLower()); 58 | } 59 | 60 | void QRibbonStyleSheetManager::clear() 61 | { 62 | mStyleSheets.clear(); 63 | } 64 | 65 | bool QRibbonStyleSheetManager::applyStyleSheet(const QString& name) 66 | { 67 | QString style = styleSheet(name); 68 | if( style.isEmpty() ) 69 | return false; 70 | 71 | if( mOldStyleSheet.isEmpty() ) 72 | mOldStyleSheet = qApp->styleSheet(); 73 | 74 | //style += mOldStyleSheet; 75 | qApp->setStyleSheet(style); 76 | return true; 77 | } 78 | -------------------------------------------------------------------------------- /CbersUI/qribbonstylesheetmanager.h: -------------------------------------------------------------------------------- 1 | #ifndef QRIBBONSTYLESHEETMANAGER_H 2 | #define QRIBBONSTYLESHEETMANAGER_H 3 | 4 | #include 5 | #include 6 | #include "cbersui_global.h" 7 | 8 | BEGIN_NAMESPACE_CBERSUI 9 | class CBERSUI_EXPORT QRibbonStyleSheetManager : public QObject 10 | { 11 | Q_OBJECT 12 | 13 | public: 14 | static QRibbonStyleSheetManager* instance(); 15 | int count(); 16 | QString styleSheet(const QString& name); 17 | bool addStyleSheet(const QString& name, const QString& styleSheet); 18 | bool removeStyleSheet(const QString& name); 19 | void clear(); 20 | bool applyStyleSheet(const QString& name); 21 | 22 | protected: 23 | explicit QRibbonStyleSheetManager(QObject *parent = 0); 24 | QString loadStyleSheet(const QString& url); 25 | 26 | signals: 27 | 28 | public slots: 29 | 30 | private: 31 | static QRibbonStyleSheetManager* sManager; 32 | QMap mStyleSheets; 33 | QString mOldStyleSheet; 34 | }; 35 | END_NAMESPACE_CBERSUI 36 | #endif // QRIBBONSTYLESHEETMANAGER_H 37 | -------------------------------------------------------------------------------- /CbersUI/qribbontabwidget.cpp: -------------------------------------------------------------------------------- 1 | #include "qribbontabwidget.h" 2 | #include 3 | #include 4 | USING_NAMESPACE_CBERSUI 5 | 6 | QRibbonTabWidget::QRibbonTabWidget(QWidget *parent) : QTabWidget(parent) 7 | { 8 | mMinHeight = 32; 9 | #ifdef Q_OS_WIN 10 | mMaxHeight = 110; 11 | #else 12 | mMaxHeight = 120; 13 | #endif 14 | 15 | if( tabBar()!=nullptr ) 16 | mMinHeight = tabBar()->geometry().height() + 2; 17 | 18 | setObjectName("QRibbonTabWidget"); 19 | setFixedHeight(mMaxHeight); 20 | mOldSize = size(); 21 | } 22 | 23 | void QRibbonTabWidget::mouseDoubleClickEvent(QMouseEvent *event) 24 | { 25 | if (event->button() == Qt::LeftButton ) 26 | { 27 | QRect tabBarRect; 28 | if( tabBar()!=nullptr ) 29 | { 30 | tabBarRect.setTopLeft(tabBar()->mapToGlobal(tabBar()->geometry().topLeft())); 31 | tabBarRect.setBottomRight(tabBar()->mapToGlobal(tabBar()->geometry().bottomRight())); 32 | } 33 | 34 | QRect widgetRect; 35 | if( currentWidget()!=nullptr ) 36 | { 37 | widgetRect.setTopLeft(currentWidget()->mapToGlobal(currentWidget()->geometry().topLeft())); 38 | widgetRect.setBottomRight(currentWidget()->mapToGlobal(currentWidget()->geometry().bottomRight())); 39 | } 40 | 41 | if( (!tabBarRect.isValid() || !tabBarRect.contains(event->globalPos())) 42 | && (!widgetRect.isValid() || !widgetRect.contains(event->globalPos())) ) 43 | { 44 | showRibbonElements(!mShow); 45 | emit toggled(mShow); 46 | } 47 | } 48 | } 49 | 50 | void QRibbonTabWidget::showRibbonElements(bool show) 51 | { 52 | if( mShow==show ) 53 | return; 54 | 55 | mShow = show; 56 | if( mShow ) 57 | { 58 | setFixedHeight(mMaxHeight); 59 | resize(mOldSize); 60 | } 61 | else 62 | { 63 | mOldSize = size(); 64 | QSize newSize(size().width(), mMinHeight); 65 | setFixedHeight(mMinHeight); 66 | resize(newSize); 67 | } 68 | } 69 | -------------------------------------------------------------------------------- /CbersUI/qribbontabwidget.h: -------------------------------------------------------------------------------- 1 | #ifndef QRIBBONTABWIDGET_H 2 | #define QRIBBONTABWIDGET_H 3 | 4 | #include 5 | #include 6 | #include 7 | #include 8 | #include "cbersui_global.h" 9 | 10 | BEGIN_NAMESPACE_CBERSUI 11 | class CBERSUI_EXPORT QRibbonTabWidget : public QTabWidget 12 | { 13 | Q_OBJECT 14 | public: 15 | explicit QRibbonTabWidget(QWidget *parent = 0); 16 | 17 | void showRibbonElements(bool show); 18 | 19 | protected: 20 | void mouseDoubleClickEvent(QMouseEvent *event); 21 | 22 | signals: 23 | void toggled(bool); 24 | 25 | protected: 26 | bool mShow; 27 | QSize mOldSize; 28 | int mMaxHeight; 29 | int mMinHeight; 30 | }; 31 | END_NAMESPACE_CBERSUI 32 | #endif // QRIBBONTABWIDGET_H 33 | -------------------------------------------------------------------------------- /CbersUI/qseparator.cpp: -------------------------------------------------------------------------------- 1 | #include "qseparator.h" 2 | USING_NAMESPACE_CBERSUI 3 | 4 | QSeparator::QSeparator(bool bVLine, QWidget *parent) : QFrame(parent) 5 | { 6 | setFrameShape(bVLine ? QFrame::VLine : QFrame::HLine); 7 | setFrameShadow(QFrame::Sunken); 8 | } 9 | -------------------------------------------------------------------------------- /CbersUI/qseparator.h: -------------------------------------------------------------------------------- 1 | #ifndef QSEPARATOR_H 2 | #define QSEPARATOR_H 3 | 4 | #include 5 | #include "cbersui_global.h" 6 | BEGIN_NAMESPACE_CBERSUI 7 | 8 | class CBERSUI_EXPORT QSeparator : public QFrame 9 | { 10 | Q_OBJECT 11 | public: 12 | explicit QSeparator(bool bVLine = false, QWidget *parent = 0); 13 | 14 | signals: 15 | 16 | public slots: 17 | }; 18 | 19 | END_NAMESPACE_CBERSUI 20 | #endif // QSEPARATOR_H 21 | -------------------------------------------------------------------------------- /CbersUI/qtitlewidget.h: -------------------------------------------------------------------------------- 1 | #ifndef QTITLEWIDGET_H 2 | #define QTITLEWIDGET_H 3 | 4 | #include 5 | #include 6 | #include 7 | #include 8 | #include 9 | #include 10 | #include 11 | #include 12 | #include "cbersui_global.h" 13 | 14 | BEGIN_NAMESPACE_CBERSUI 15 | class CBERSUI_EXPORT QTitleWidget : public QWidget 16 | { 17 | Q_OBJECT 18 | public: 19 | explicit QTitleWidget(QWidget *parent = 0); 20 | ~QTitleWidget(); 21 | 22 | public: 23 | bool addWidget(QWidget* widget, int index = -1); 24 | bool addExtendedWidget(QWidget* widget, int index = -1); 25 | 26 | protected: 27 | virtual void mouseDoubleClickEvent(QMouseEvent *event); 28 | virtual void mousePressEvent(QMouseEvent *event); 29 | virtual void mouseReleaseEvent(QMouseEvent *event); 30 | virtual void mouseMoveEvent(QMouseEvent *event); 31 | virtual bool eventFilter(QObject *obj, QEvent *event); 32 | 33 | public slots: 34 | void onMinimized(); 35 | void onMaximized(); 36 | void onRestore(); 37 | void onClose(); 38 | void onMove(); 39 | 40 | private: 41 | void updateMaximize(); 42 | 43 | protected: 44 | QPushButton *m_pIconLabel; 45 | QLabel *m_pTitleLabel; 46 | QPushButton *m_pMinimizeButton; 47 | QPushButton *m_pMaximizeButton; 48 | QPushButton *m_pRestoreButton; 49 | QPushButton *m_pCloseButton; 50 | QAction* mMoveAction; 51 | 52 | QHBoxLayout* m_pWidgetLayout; 53 | QHBoxLayout* m_pExtendedLayout; 54 | 55 | private: 56 | bool m_bPressed; 57 | QPoint m_point; 58 | QByteArray m_normalGeometry; 59 | }; 60 | END_NAMESPACE_CBERSUI 61 | #endif // QTITLEWIDGET_H 62 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # CbersUI 2 | QT Ribbon 插件系统 3 | 4 | 特别感谢 一去丶二三里 http://blog.csdn.net/liang19890820, 博主文章中关于QT的讲解非常清楚 5 | 6 | x3py - C++ Plugin Framework 7 | https://github.com/rhcad/x3py 8 | 9 | 使用说明: 10 | 1. 将插件模板中的qtcreator\share内容,拷贝到qtcreator下替换, 使用QtCreator进行编程时,添加了插件工程和类的向导 11 | 2. 新建项目, 选Library中的CbersPlugin Project,将创建一个插件工程 12 | 3. 添加新文件时,选C++中的CbersPlugin Class,将创建不同类型的插件(一个插件工程中,可以包含多个插件) 13 | 4. 打开项目中的module.cpp文件,添加插件的头文件,并在XBEGIN_DEFINE_MODULE下,增加XDEFINE_CLASSMAP_ENTRY(插件类名) -------------------------------------------------------------------------------- /plugins/PluginDemo/CommandPlugin.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/longhuan2018/CbersUI/85bfe9f16e0ff17361875461818006efc51d8d28/plugins/PluginDemo/CommandPlugin.png -------------------------------------------------------------------------------- /plugins/PluginDemo/DockWidgetPlugin.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/longhuan2018/CbersUI/85bfe9f16e0ff17361875461818006efc51d8d28/plugins/PluginDemo/DockWidgetPlugin.png -------------------------------------------------------------------------------- /plugins/PluginDemo/PluginDemo.pro: -------------------------------------------------------------------------------- 1 | TEMPLATE = lib 2 | TARGET = PluginDemo 3 | QT += core 4 | 5 | greaterThan(QT_MAJOR_VERSION, 4): QT += widgets 6 | 7 | # The following define makes your compiler emit warnings if you use 8 | # any feature of Qt which as been marked as deprecated (the exact warnings 9 | # depend on your compiler). Please consult the documentation of the 10 | # deprecated API in order to know how to port your code away from it. 11 | DEFINES += QT_DEPRECATED_WARNINGS 12 | 13 | # You can also make your code fail to compile if you use deprecated APIs. 14 | # In order to do so, uncomment the following line. 15 | # You can also select to disable deprecated APIs only up to a certain version of Qt. 16 | #DEFINES += QT_DISABLE_DEPRECATED_BEFORE=0x060000 # disables all the APIs deprecated before Qt 6.0.0 17 | 18 | # Input 19 | SOURCES += module.cpp \ 20 | viewplugin.cpp \ 21 | dockwidgetplugin.cpp \ 22 | commandplugin.cpp \ 23 | toolplugin.cpp 24 | 25 | HEADERS += \ 26 | viewplugin.h \ 27 | dockwidgetplugin.h \ 28 | commandplugin.h \ 29 | toolplugin.h 30 | PROJECT_PATH = $$PWD 31 | SDK_PATH = $$PROJECT_PATH/../../ 32 | #TRANSLATION_LANGS = zh_CN 33 | include( ../../include/pluginconfig.pri ) 34 | QMAKE_POST_LINK += $$copyToDir($$PROJECT_PATH/*.png, $$DESTDIR/../Skins/) 35 | 36 | DISTFILES += \ 37 | ViewPlugin.png \ 38 | DockWidgetPlugin.png \ 39 | CommandPlugin.png \ 40 | ToolPlugin.png 41 | 42 | FORMS += -------------------------------------------------------------------------------- /plugins/PluginDemo/ToolPlugin.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/longhuan2018/CbersUI/85bfe9f16e0ff17361875461818006efc51d8d28/plugins/PluginDemo/ToolPlugin.png -------------------------------------------------------------------------------- /plugins/PluginDemo/ViewPlugin.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/longhuan2018/CbersUI/85bfe9f16e0ff17361875461818006efc51d8d28/plugins/PluginDemo/ViewPlugin.png -------------------------------------------------------------------------------- /plugins/PluginDemo/commandplugin.cpp: -------------------------------------------------------------------------------- 1 | #include "commandplugin.h" 2 | #include 3 | #include 4 | #include 5 | #include 6 | #include 7 | 8 | CommandPlugin::CommandPlugin(QObject *parent) : QObject(parent) 9 | { 10 | Name(QStringLiteral("CommandPlugin")); 11 | Caption(QStringLiteral("Buttons")); 12 | Category(QStringLiteral("Plugins")); 13 | Tooltip(QStringLiteral("CommandPlugin")); 14 | Description(QStringLiteral("CommandPlugin")); 15 | BitmapName(QStringLiteral("CommandPlugin")); 16 | 17 | 18 | mToolButton = Q_NULLPTR; 19 | mDefaultIcon = true; 20 | 21 | } 22 | 23 | CommandPlugin::~CommandPlugin() 24 | { 25 | UnInitialize(); 26 | } 27 | 28 | // IUIPlugin 29 | bool CommandPlugin::Initialize() 30 | { 31 | mToolButton = new QToolButton(); 32 | mToolButton->setText(Name()); 33 | mToolButton->setToolTip(Tooltip()); 34 | mToolButton->setIconSize(QSize(32, 32)); 35 | mToolButton->setToolButtonStyle(Qt::ToolButtonTextUnderIcon); 36 | mToolButton->setAutoRaise(true); 37 | mToolButton->setMouseTracking(true); 38 | QString strBitmapName = BitmapName(); 39 | QIcon icon; 40 | if( !strBitmapName.isEmpty() ) 41 | { 42 | strBitmapName = QString("%1/Skins/%2.png").arg(QApplication::applicationDirPath()).arg(strBitmapName); 43 | QFileInfo fileInfo(strBitmapName); 44 | if( !fileInfo.exists() ) 45 | { 46 | strBitmapName = QString("%1/Skins/default.png").arg(QApplication::applicationDirPath()); 47 | fileInfo.setFile(strBitmapName); 48 | } 49 | else 50 | mDefaultIcon = false; 51 | 52 | if( fileInfo.exists() ) 53 | icon.addFile(strBitmapName); 54 | } 55 | 56 | if( !icon.isNull() ) 57 | { 58 | mToolButton->setIcon(icon); 59 | } 60 | 61 | mToolButton->setCheckable(false); 62 | this->connect(mToolButton, SIGNAL(clicked()), this, SLOT(clicked())); 63 | 64 | // Only Support appoint Events 65 | //supportsEvent("EventKey"); 66 | registerHandlers(); 67 | return true; 68 | } 69 | 70 | bool CommandPlugin::UnInitialize() 71 | { 72 | if( mToolButton!=Q_NULLPTR ) 73 | delete mToolButton; 74 | mToolButton = Q_NULLPTR; 75 | 76 | unregisterHandlers(); 77 | return true; 78 | } 79 | 80 | bool CommandPlugin::SetBuddy(x3::IObject* val) 81 | { 82 | if( m_spBuddy==val ) 83 | return true; 84 | 85 | m_spBuddy = val; 86 | if( !m_spBuddy.valid() ) 87 | { 88 | mToolButton->setEnabled(false); 89 | return false; 90 | } 91 | 92 | mToolButton->setEnabled(true); 93 | 94 | return true; 95 | } 96 | 97 | bool CommandPlugin::readConfig( const QDomNode& node, QDomDocument & document, QString& errorMessage ) 98 | { 99 | if( !((IUIPlugin*)this)->readConfig(node, document, errorMessage) ) 100 | return false; 101 | 102 | return true; 103 | } 104 | 105 | bool CommandPlugin::writeConfig( const QDomNode& node, QDomDocument & document, QString& errorMessage ) 106 | { 107 | if( !((IUIPlugin*)this)->writeConfig(node, document, errorMessage) ) 108 | return false; 109 | 110 | return true; 111 | } 112 | 113 | // IUICommand 114 | QWidget* CommandPlugin::getButtonWidget() 115 | { 116 | return mToolButton; 117 | } 118 | 119 | QWidget* CommandPlugin::getWndWidget() 120 | { 121 | return Q_NULLPTR; 122 | } 123 | 124 | // IAnythingEventObserver 125 | bool CommandPlugin::OnAnything(x3::IObject* sender, const std::string& eventKey, const QVariant& wParam, const QVariant& lParam) 126 | { 127 | //if( _stricmp(eventKey.c_str(), "EventKey")==0 ) 128 | //{ 129 | //} 130 | return true; 131 | } 132 | 133 | void CommandPlugin::clicked() 134 | { 135 | QMessageBox::information(Q_NULLPTR, "CommandPlugin", "CommandPlugin clicked"); 136 | } 137 | -------------------------------------------------------------------------------- /plugins/PluginDemo/commandplugin.h: -------------------------------------------------------------------------------- 1 | #ifndef COMMANDPLUGIN_H 2 | #define COMMANDPLUGIN_H 3 | #include 4 | #include 5 | 6 | #include "UIPluginsEvents.h" 7 | #include "UIPlugins.h" 8 | USING_NAMESPACE_CBERSPLUGINS 9 | 10 | const char* const clsidCommandPlugin = "clsidCommandPlugin"; 11 | class CommandPlugin : public QObject 12 | , public IUIPlugin 13 | , public IUICommand 14 | , public IAnythingEventObserver 15 | { 16 | Q_OBJECT 17 | X3BEGIN_CLASS_DECLARE(CommandPlugin, clsidCommandPlugin) 18 | X3DEFINE_INTERFACE_ENTRY(IUIPlugin) 19 | X3DEFINE_INTERFACE_ENTRY(IUICommand) 20 | X3END_CLASS_DECLARE() 21 | 22 | public: 23 | explicit CommandPlugin(QObject *parent = 0); 24 | ~CommandPlugin(); 25 | 26 | public: 27 | // IUIPlugin 28 | virtual bool Initialize(); 29 | virtual bool UnInitialize(); 30 | virtual bool SetBuddy(x3::IObject* val); 31 | virtual bool readConfig( const QDomNode& node, QDomDocument & document, QString& errorMessage ); 32 | virtual bool writeConfig( const QDomNode& node, QDomDocument & document, QString& errorMessage ); 33 | 34 | // IUICommand 35 | virtual QWidget* getButtonWidget(); 36 | virtual QWidget* getWndWidget(); 37 | 38 | // IAnythingEventObserver 39 | virtual bool OnAnything(x3::IObject* sender, const std::string& eventKey, const QVariant& wParam, const QVariant& lParam); 40 | 41 | signals: 42 | 43 | public slots: 44 | void clicked(); 45 | 46 | protected: 47 | QToolButton* mToolButton; 48 | bool mDefaultIcon; 49 | }; 50 | 51 | #endif // COMMANDPLUGIN_H -------------------------------------------------------------------------------- /plugins/PluginDemo/dockwidgetplugin.cpp: -------------------------------------------------------------------------------- 1 | #include "dockwidgetplugin.h" 2 | #include "ui_dockwidgetplugin.h" 3 | #include 4 | #include 5 | #include 6 | #include 7 | 8 | DockWidgetPlugin::DockWidgetPlugin(QWidget *parent) : QDockWidget(parent) 9 | { 10 | Name(QStringLiteral("DockWidgetPlugin")); 11 | Caption(QStringLiteral("View")); 12 | Category(QStringLiteral("Plugins")); 13 | Tooltip(QStringLiteral("DockWidgetPlugin")); 14 | Description(QStringLiteral("DockWidgetPlugin")); 15 | BitmapName(QStringLiteral("DockWidgetPlugin")); 16 | 17 | setWindowTitle(Name()); 18 | 19 | mToolButton = Q_NULLPTR; 20 | mDefaultIcon = true; 21 | 22 | } 23 | 24 | DockWidgetPlugin::~DockWidgetPlugin() 25 | { 26 | UnInitialize(); 27 | } 28 | 29 | // IUIPlugin 30 | bool DockWidgetPlugin::Initialize() 31 | { 32 | mToolButton = new QToolButton(); 33 | mToolButton->setText(Name()); 34 | mToolButton->setToolTip(Tooltip()); 35 | mToolButton->setIconSize(QSize(32, 32)); 36 | mToolButton->setToolButtonStyle(Qt::ToolButtonTextUnderIcon); 37 | mToolButton->setAutoRaise(true); 38 | mToolButton->setMouseTracking(true); 39 | QString strBitmapName = BitmapName(); 40 | QIcon icon; 41 | if( !strBitmapName.isEmpty() ) 42 | { 43 | strBitmapName = QString("%1/Skins/%2.png").arg(QApplication::applicationDirPath()).arg(strBitmapName); 44 | QFileInfo fileInfo(strBitmapName); 45 | if( !fileInfo.exists() ) 46 | { 47 | strBitmapName = QString("%1/Skins/default.png").arg(QApplication::applicationDirPath()); 48 | fileInfo.setFile(strBitmapName); 49 | } 50 | else 51 | mDefaultIcon = false; 52 | 53 | if( fileInfo.exists() ) 54 | icon.addFile(strBitmapName); 55 | } 56 | 57 | if( !icon.isNull() ) 58 | { 59 | mToolButton->setIcon(icon); 60 | setWindowIcon(icon); 61 | } 62 | 63 | mToolButton->setCheckable(true); 64 | QAction* actionDockWidget = toggleViewAction(); 65 | actionDockWidget->setIcon(icon); 66 | actionDockWidget->setText(Name()); 67 | actionDockWidget->setToolTip(Tooltip()); 68 | mToolButton->setDefaultAction(actionDockWidget); 69 | this->connect(mToolButton, SIGNAL(toggled(bool)), this, SLOT(toggled(bool))); 70 | 71 | // Only Support appoint Events 72 | //supportsEvent("EventKey"); 73 | registerHandlers(); 74 | return true; 75 | } 76 | 77 | bool DockWidgetPlugin::UnInitialize() 78 | { 79 | if( mToolButton!=Q_NULLPTR ) 80 | delete mToolButton; 81 | mToolButton = Q_NULLPTR; 82 | 83 | unregisterHandlers(); 84 | hide(); 85 | return true; 86 | } 87 | 88 | bool DockWidgetPlugin::SetBuddy(x3::IObject* val) 89 | { 90 | if( m_spBuddy==val ) 91 | return true; 92 | 93 | m_spBuddy = val; 94 | if( !m_spBuddy.valid() ) 95 | { 96 | mToolButton->setEnabled(false); 97 | return false; 98 | } 99 | 100 | mToolButton->setEnabled(true); 101 | 102 | return true; 103 | } 104 | 105 | bool DockWidgetPlugin::readConfig( const QDomNode& node, QDomDocument & document, QString& errorMessage ) 106 | { 107 | if( !((IUIPlugin*)this)->readConfig(node, document, errorMessage) ) 108 | return false; 109 | 110 | return true; 111 | } 112 | 113 | bool DockWidgetPlugin::writeConfig( const QDomNode& node, QDomDocument & document, QString& errorMessage ) 114 | { 115 | if( !((IUIPlugin*)this)->writeConfig(node, document, errorMessage) ) 116 | return false; 117 | 118 | return true; 119 | } 120 | 121 | // IUICommand 122 | QWidget* DockWidgetPlugin::getButtonWidget() 123 | { 124 | return mToolButton; 125 | } 126 | 127 | QWidget* DockWidgetPlugin::getWndWidget() 128 | { 129 | show(); 130 | return this; 131 | } 132 | 133 | // IAnythingEventObserver 134 | bool DockWidgetPlugin::OnAnything(x3::IObject* sender, const std::string& eventKey, const QVariant& wParam, const QVariant& lParam) 135 | { 136 | //if( _stricmp(eventKey.c_str(), "EventKey")==0 ) 137 | //{ 138 | //} 139 | return true; 140 | } 141 | 142 | void DockWidgetPlugin::toggled(bool checked) 143 | { 144 | if( checked ) 145 | { 146 | setVisible(true); 147 | raise(); 148 | } 149 | } 150 | -------------------------------------------------------------------------------- /plugins/PluginDemo/dockwidgetplugin.h: -------------------------------------------------------------------------------- 1 | #ifndef DOCKWIDGETPLUGIN_H 2 | #define DOCKWIDGETPLUGIN_H 3 | #include 4 | #include 5 | 6 | #include "UIPluginsEvents.h" 7 | #include "UIPlugins.h" 8 | USING_NAMESPACE_CBERSPLUGINS 9 | 10 | const char* const clsidDockWidgetPlugin = "clsidDockWidgetPlugin"; 11 | class DockWidgetPlugin : public QDockWidget 12 | , public IUIPlugin 13 | , public IUICommand 14 | , public IAnythingEventObserver 15 | { 16 | Q_OBJECT 17 | X3BEGIN_CLASS_DECLARE(DockWidgetPlugin, clsidDockWidgetPlugin) 18 | X3DEFINE_INTERFACE_ENTRY(IUIPlugin) 19 | X3DEFINE_INTERFACE_ENTRY(IUICommand) 20 | X3END_CLASS_DECLARE() 21 | 22 | public: 23 | explicit DockWidgetPlugin(QWidget *parent = 0); 24 | ~DockWidgetPlugin(); 25 | 26 | public: 27 | // IUIPlugin 28 | virtual bool Initialize(); 29 | virtual bool UnInitialize(); 30 | virtual bool SetBuddy(x3::IObject* val); 31 | virtual bool readConfig( const QDomNode& node, QDomDocument & document, QString& errorMessage ); 32 | virtual bool writeConfig( const QDomNode& node, QDomDocument & document, QString& errorMessage ); 33 | 34 | // IUICommand 35 | virtual QWidget* getButtonWidget(); 36 | virtual QWidget* getWndWidget(); 37 | 38 | // IAnythingEventObserver 39 | virtual bool OnAnything(x3::IObject* sender, const std::string& eventKey, const QVariant& wParam, const QVariant& lParam); 40 | 41 | signals: 42 | 43 | public slots: 44 | void toggled(bool checked); 45 | 46 | protected: 47 | QToolButton* mToolButton; 48 | bool mDefaultIcon; 49 | }; 50 | 51 | #endif // DOCKWIDGETPLUGIN_H 52 | -------------------------------------------------------------------------------- /plugins/PluginDemo/module.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | #include 5 | #include 6 | #include 7 | #include "module/plugininc.h" 8 | #include "module/pluginimpl.h" 9 | #include "module/modulemacro.h" 10 | #include "observer/observerimpl.h" 11 | #include "viewplugin.h" 12 | #include "dockwidgetplugin.h" 13 | #include "commandplugin.h" 14 | #include "toolplugin.h" 15 | 16 | XBEGIN_DEFINE_MODULE() 17 | XDEFINE_CLASSMAP_ENTRY(ViewPlugin) 18 | XDEFINE_CLASSMAP_ENTRY(DockWidgetPlugin) 19 | XDEFINE_CLASSMAP_ENTRY(CommandPlugin) 20 | XDEFINE_CLASSMAP_ENTRY(ToolPlugin) 21 | XEND_DEFINE_MODULE_DLL() 22 | 23 | QTranslator gTranslator; 24 | OUTAPI bool x3InitializePlugin() 25 | { 26 | ////////////////////////////////////////////////////////////// 27 | // Load Translator 28 | QSettings mySettings; 29 | QString i18nPath = QApplication::applicationDirPath() + QDir::separator() + "i18n"; 30 | QString myUserLocale = mySettings.value( "locale/userLocale", "" ).toString(); 31 | bool myLocaleOverrideFlag = mySettings.value( "locale/overrideFlag", false ).toBool(); 32 | QString myTranslationCode; 33 | if ( !myTranslationCode.isNull() && !myTranslationCode.isEmpty() ) 34 | { 35 | mySettings.setValue( "locale/userLocale", myTranslationCode ); 36 | } 37 | else 38 | { 39 | if ( !myLocaleOverrideFlag || myUserLocale.isEmpty() ) 40 | { 41 | myTranslationCode = QLocale::system().name(); 42 | mySettings.setValue( "locale/userLocale", myTranslationCode ); 43 | } 44 | else 45 | { 46 | myTranslationCode = myUserLocale; 47 | } 48 | } 49 | 50 | if ( myTranslationCode != "C" ) 51 | { 52 | if ( gTranslator.load( QString( "PluginDemo_" ) + myTranslationCode, i18nPath ) ) 53 | { 54 | QApplication::installTranslator( &gTranslator ); 55 | } 56 | else 57 | { 58 | qWarning( "loading of PluginDemo translation failed [%s]", QString( "%1/PluginDemo_%2" ).arg( i18nPath ).arg( myTranslationCode ).toLocal8Bit().constData() ); 59 | } 60 | } 61 | ////////////////////////////////////////////////////////////// 62 | return true; 63 | } 64 | 65 | OUTAPI void x3UninitializePlugin() 66 | { 67 | if( !gTranslator.isEmpty() ) 68 | { 69 | QApplication::removeTranslator( &gTranslator ); 70 | } 71 | } 72 | -------------------------------------------------------------------------------- /plugins/PluginDemo/toolplugin.cpp: -------------------------------------------------------------------------------- 1 | #include "toolplugin.h" 2 | #include 3 | #include 4 | #include 5 | #include 6 | #include 7 | 8 | ToolPlugin::ToolPlugin(QObject *parent) : QObject(parent) 9 | { 10 | Name(QStringLiteral("ToolPlugin")); 11 | Caption(QStringLiteral("Buttons")); 12 | Category(QStringLiteral("Plugins")); 13 | Tooltip(QStringLiteral("ToolPlugin")); 14 | Description(QStringLiteral("ToolPlugin")); 15 | BitmapName(QStringLiteral("ToolPlugin")); 16 | 17 | 18 | mToolButton = Q_NULLPTR; 19 | mDefaultIcon = true; 20 | 21 | } 22 | 23 | ToolPlugin::~ToolPlugin() 24 | { 25 | UnInitialize(); 26 | } 27 | 28 | // IUIPlugin 29 | bool ToolPlugin::Initialize() 30 | { 31 | mToolButton = new QToolButton(); 32 | mToolButton->setText(Name()); 33 | mToolButton->setToolTip(Tooltip()); 34 | mToolButton->setIconSize(QSize(32, 32)); 35 | mToolButton->setToolButtonStyle(Qt::ToolButtonTextUnderIcon); 36 | mToolButton->setAutoRaise(true); 37 | mToolButton->setMouseTracking(true); 38 | QString strBitmapName = BitmapName(); 39 | QIcon icon; 40 | if( !strBitmapName.isEmpty() ) 41 | { 42 | strBitmapName = QString("%1/Skins/%2.png").arg(QApplication::applicationDirPath()).arg(strBitmapName); 43 | QFileInfo fileInfo(strBitmapName); 44 | if( !fileInfo.exists() ) 45 | { 46 | strBitmapName = QString("%1/Skins/default.png").arg(QApplication::applicationDirPath()); 47 | fileInfo.setFile(strBitmapName); 48 | } 49 | else 50 | mDefaultIcon = false; 51 | 52 | if( fileInfo.exists() ) 53 | icon.addFile(strBitmapName); 54 | } 55 | 56 | if( !icon.isNull() ) 57 | { 58 | mToolButton->setIcon(icon); 59 | } 60 | 61 | mToolButton->setCheckable(true); 62 | mToolButton->setEnabled(false); 63 | this->connect(mToolButton, SIGNAL(clicked(bool)), this, SLOT(clicked(bool))); 64 | 65 | // Only Support appoint Events 66 | //supportsEvent("EventKey"); 67 | registerHandlers(); 68 | return true; 69 | } 70 | 71 | bool ToolPlugin::UnInitialize() 72 | { 73 | if( mToolButton!=Q_NULLPTR ) 74 | delete mToolButton; 75 | mToolButton = Q_NULLPTR; 76 | 77 | unregisterHandlers(); 78 | return true; 79 | } 80 | 81 | bool ToolPlugin::SetBuddy(x3::IObject* val) 82 | { 83 | if( m_spBuddy==val ) 84 | return true; 85 | 86 | m_spBuddy = val; 87 | if( !m_spBuddy.valid() ) 88 | { 89 | mToolButton->setEnabled(false); 90 | return false; 91 | } 92 | 93 | mToolButton->setEnabled(true); 94 | 95 | return true; 96 | } 97 | 98 | bool ToolPlugin::readConfig( const QDomNode& node, QDomDocument & document, QString& errorMessage ) 99 | { 100 | if( !((IUIPlugin*)this)->readConfig(node, document, errorMessage) ) 101 | return false; 102 | 103 | return true; 104 | } 105 | 106 | bool ToolPlugin::writeConfig( const QDomNode& node, QDomDocument & document, QString& errorMessage ) 107 | { 108 | if( !((IUIPlugin*)this)->writeConfig(node, document, errorMessage) ) 109 | return false; 110 | 111 | return true; 112 | } 113 | 114 | // IUICommand 115 | QWidget* ToolPlugin::getButtonWidget() 116 | { 117 | return mToolButton; 118 | } 119 | 120 | QWidget* ToolPlugin::getWndWidget() 121 | { 122 | return Q_NULLPTR; 123 | } 124 | 125 | // IAnythingEventObserver 126 | bool ToolPlugin::OnAnything(x3::IObject* sender, const std::string& eventKey, const QVariant& wParam, const QVariant& lParam) 127 | { 128 | if( _stricmp(eventKey.c_str(), "toolActived")==0 ) 129 | { 130 | if( sender==(IUIPlugin*)this ) 131 | return true; 132 | } 133 | return true; 134 | } 135 | 136 | void ToolPlugin::clicked(bool checked) 137 | { 138 | QMessageBox::information(Q_NULLPTR, "ToolPlugin", checked ? "ToolPlugin clicked" : "ToolPlugin unclicked"); 139 | } 140 | -------------------------------------------------------------------------------- /plugins/PluginDemo/toolplugin.h: -------------------------------------------------------------------------------- 1 | #ifndef TOOLPLUGIN_H 2 | #define TOOLPLUGIN_H 3 | #include 4 | #include 5 | 6 | #include "UIPluginsEvents.h" 7 | #include "UIPlugins.h" 8 | USING_NAMESPACE_CBERSPLUGINS 9 | 10 | const char* const clsidToolPlugin = "clsidToolPlugin"; 11 | class ToolPlugin : public QObject 12 | , public IUIPlugin 13 | , public IUICommand 14 | , public IAnythingEventObserver 15 | { 16 | Q_OBJECT 17 | X3BEGIN_CLASS_DECLARE(ToolPlugin, clsidToolPlugin) 18 | X3DEFINE_INTERFACE_ENTRY(IUIPlugin) 19 | X3DEFINE_INTERFACE_ENTRY(IUICommand) 20 | X3END_CLASS_DECLARE() 21 | 22 | public: 23 | explicit ToolPlugin(QObject *parent = 0); 24 | ~ToolPlugin(); 25 | 26 | public: 27 | // IUIPlugin 28 | virtual bool Initialize(); 29 | virtual bool UnInitialize(); 30 | virtual bool SetBuddy(x3::IObject* val); 31 | virtual bool readConfig( const QDomNode& node, QDomDocument & document, QString& errorMessage ); 32 | virtual bool writeConfig( const QDomNode& node, QDomDocument & document, QString& errorMessage ); 33 | 34 | // IUICommand 35 | virtual QWidget* getButtonWidget(); 36 | virtual QWidget* getWndWidget(); 37 | 38 | // IAnythingEventObserver 39 | virtual bool OnAnything(x3::IObject* sender, const std::string& eventKey, const QVariant& wParam, const QVariant& lParam); 40 | 41 | signals: 42 | 43 | public slots: 44 | void clicked(bool checked = false); 45 | 46 | protected: 47 | QToolButton* mToolButton; 48 | bool mDefaultIcon; 49 | }; 50 | 51 | #endif // TOOLPLUGIN_H -------------------------------------------------------------------------------- /plugins/PluginDemo/viewplugin.cpp: -------------------------------------------------------------------------------- 1 | #include "viewplugin.h" 2 | #include 3 | #include 4 | #include 5 | #include 6 | 7 | ViewPlugin::ViewPlugin(QWidget *parent) : QWidget(parent) 8 | { 9 | Name(QStringLiteral("ViewPlugin")); 10 | Caption(QStringLiteral("View")); 11 | Category(QStringLiteral("Plugins")); 12 | Tooltip(QStringLiteral("ViewPlugin")); 13 | Description(QStringLiteral("ViewPlugin")); 14 | BitmapName(QStringLiteral("ViewPlugin")); 15 | 16 | setWindowTitle(Name()); 17 | 18 | } 19 | 20 | ViewPlugin::~ViewPlugin() 21 | { 22 | UnInitialize(); 23 | } 24 | 25 | // IUIPlugin 26 | bool ViewPlugin::Initialize() 27 | { 28 | 29 | // Only Support appoint Events 30 | //supportsEvent("EventKey"); 31 | registerHandlers(); 32 | return true; 33 | } 34 | 35 | bool ViewPlugin::UnInitialize() 36 | { 37 | 38 | unregisterHandlers(); 39 | hide(); 40 | return true; 41 | } 42 | 43 | bool ViewPlugin::SetBuddy(x3::IObject* val) 44 | { 45 | if( m_spBuddy==val ) 46 | return true; 47 | 48 | m_spBuddy = val; 49 | if( !m_spBuddy.valid() ) 50 | { 51 | return false; 52 | } 53 | 54 | 55 | return true; 56 | } 57 | 58 | bool ViewPlugin::readConfig( const QDomNode& node, QDomDocument & document, QString& errorMessage ) 59 | { 60 | if( !((IUIPlugin*)this)->readConfig(node, document, errorMessage) ) 61 | return false; 62 | 63 | return true; 64 | } 65 | 66 | bool ViewPlugin::writeConfig( const QDomNode& node, QDomDocument & document, QString& errorMessage ) 67 | { 68 | if( !((IUIPlugin*)this)->writeConfig(node, document, errorMessage) ) 69 | return false; 70 | 71 | return true; 72 | } 73 | 74 | // IUIView 75 | QWidget* ViewPlugin::getViewWidget() 76 | { 77 | return this; 78 | } 79 | 80 | // IAnythingEventObserver 81 | bool ViewPlugin::OnAnything(x3::IObject* sender, const std::string& eventKey, const QVariant& wParam, const QVariant& lParam) 82 | { 83 | //if( _stricmp(eventKey.c_str(), "EventKey")==0 ) 84 | //{ 85 | //} 86 | return true; 87 | } 88 | 89 | -------------------------------------------------------------------------------- /plugins/PluginDemo/viewplugin.h: -------------------------------------------------------------------------------- 1 | #ifndef VIEWPLUGIN_H 2 | #define VIEWPLUGIN_H 3 | #include 4 | 5 | #include "UIPluginsEvents.h" 6 | #include "UIPlugins.h" 7 | USING_NAMESPACE_CBERSPLUGINS 8 | 9 | const char* const clsidViewPlugin = "clsidViewPlugin"; 10 | class ViewPlugin : public QWidget 11 | , public IUIPlugin 12 | , public IUIView 13 | , public IAnythingEventObserver 14 | { 15 | Q_OBJECT 16 | X3BEGIN_CLASS_DECLARE(ViewPlugin, clsidViewPlugin) 17 | X3DEFINE_INTERFACE_ENTRY(IUIPlugin) 18 | X3DEFINE_INTERFACE_ENTRY(IUIView) 19 | X3END_CLASS_DECLARE() 20 | 21 | public: 22 | explicit ViewPlugin(QWidget *parent = 0); 23 | ~ViewPlugin(); 24 | 25 | public: 26 | // IUIPlugin 27 | virtual bool Initialize(); 28 | virtual bool UnInitialize(); 29 | virtual bool SetBuddy(x3::IObject* val); 30 | virtual bool readConfig( const QDomNode& node, QDomDocument & document, QString& errorMessage ); 31 | virtual bool writeConfig( const QDomNode& node, QDomDocument & document, QString& errorMessage ); 32 | 33 | // IUIView 34 | virtual QWidget* getViewWidget(); 35 | 36 | // IAnythingEventObserver 37 | virtual bool OnAnything(x3::IObject* sender, const std::string& eventKey, const QVariant& wParam, const QVariant& lParam); 38 | 39 | signals: 40 | 41 | public slots: 42 | 43 | }; 44 | 45 | #endif // VIEWPLUGIN_H -------------------------------------------------------------------------------- /plugins/plugins.pro: -------------------------------------------------------------------------------- 1 | TEMPLATE = subdirs 2 | SUBDIRS = PluginDemo -------------------------------------------------------------------------------- /x3py/interface/core/iobject.h: -------------------------------------------------------------------------------- 1 | // x3py framework: https://github.com/rhcad/x3py 2 | #ifndef X3_CORE_IOBJECT_H 3 | #define X3_CORE_IOBJECT_H 4 | 5 | #define BEGIN_NAMESPACE_X3 namespace x3 { 6 | #define END_NAMESPACE_X3 } 7 | 8 | BEGIN_NAMESPACE_X3 9 | 10 | #ifndef SWIG 11 | inline long _hashkey(const char* str) 12 | { 13 | unsigned long value = 0; 14 | while (*str) 15 | value = (value<<5) + value + *str++; 16 | return value; 17 | } 18 | #endif 19 | 20 | // IID is unique only in a implement class of a plugin. 21 | #define X3DEFINE_IID(_Interface) \ 22 | public: \ 23 | virtual ~_Interface() {} \ 24 | static const char* getInterfaceName() { return #_Interface; } \ 25 | static long getIID() { static long iid = x3::_hashkey(#_Interface); return iid; } \ 26 | typedef void dummy 27 | 28 | class IObject 29 | { 30 | X3DEFINE_IID(IObject); 31 | #ifndef SWIG 32 | virtual long retainObject() const = 0; 33 | virtual long releaseObject() const = 0; 34 | virtual bool queryObject(long iid, IObject** p) const = 0; 35 | #endif 36 | virtual const char* getClassID() const = 0; 37 | virtual const char* getClassName() const = 0; 38 | }; 39 | 40 | END_NAMESPACE_X3 41 | #endif -------------------------------------------------------------------------------- /x3py/interface/core/manager/iplugins.h: -------------------------------------------------------------------------------- 1 | // x3py framework: https://github.com/rhcad/x3py 2 | #ifndef X3_CORE_IPLUGINS_H 3 | #define X3_CORE_IPLUGINS_H 4 | 5 | #include "x3manager.h" 6 | #include 7 | #include 8 | 9 | BEGIN_NAMESPACE_X3 10 | 11 | class IPlugins : public IObject 12 | { 13 | X3DEFINE_IID(IPlugins); 14 | virtual int getPluginCount() const = 0; 15 | virtual void getPluginFiles(std::vector& files) const = 0; 16 | 17 | virtual int getCLSIDCount() const = 0; 18 | virtual const char* getCLSID(int index) = 0; 19 | 20 | virtual int loadExtraPlugins(const char* folder) = 0; 21 | virtual int unloadExtraPlugins() = 0; 22 | }; 23 | 24 | END_NAMESPACE_X3 25 | #endif 26 | -------------------------------------------------------------------------------- /x3py/interface/core/manager/iworkpath.h: -------------------------------------------------------------------------------- 1 | /*! \file iworkpath.h 2 | * \brief Define interface of getting the application's writable path: IAppWorkPath 3 | * \author Zhang Yungui, X3 C++ PluginFramework 4 | * \date 2012.3.4 5 | */ 6 | #ifndef X3_CORE_IWORKPATH_H 7 | #define X3_CORE_IWORKPATH_H 8 | 9 | #include "x3manager.h" 10 | #include 11 | 12 | BEGIN_NAMESPACE_X3 13 | 14 | /*! \ingroup _GROUP_APPUI_ 15 | * \interface IAppWorkPath 16 | * \brief interface of getting the application's writable path. 17 | * \see x3::clsidManager, x3::getAppWorkPath() 18 | */ 19 | class IAppWorkPath : public IObject 20 | { 21 | public: 22 | X3DEFINE_IID(IAppWorkPath); 23 | 24 | //! Get the application's writable absolute path. 25 | /*! The default path is same as getLocalAppDataPath("x3") if setWorkPath() is not called. 26 | \see getLocalAppDataPath, setWorkPath 27 | */ 28 | virtual std::wstring getWorkPath() = 0; 29 | 30 | //! Set the application's writable absolute path. (call before loading plugins) 31 | /*! \see getLocalAppDataPath, getWorkPath 32 | */ 33 | virtual void setWorkPath(const std::wstring& path) = 0; 34 | 35 | //! Returns path as calling SHGetKnownFolderPath(FOLDERID_LocalAppData, ...) 36 | /*! The path form is "X:\Users\auser\AppData\Local\company\" 37 | or the executable file's folder if failed to call SHGetKnownFolderPath(). 38 | \param company append company name to path if not empty. 39 | \return the absolute path. 40 | */ 41 | virtual std::wstring getLocalAppDataPath(const wchar_t* company) = 0; 42 | 43 | //! Returns the language translation path of the current user. 44 | /*! eg: exepath/translations/chs/subfolder (not end with slash char). 45 | \param subfolder sub folder name in the translation path. 46 | \return the language translation path which not end with slash char. 47 | */ 48 | virtual std::wstring getTranslationsPath(const wchar_t* subfolder) = 0; 49 | 50 | virtual std::wstring getConfigPath(const wchar_t* subfolder) = 0; 51 | }; 52 | 53 | //! \copydoc IAppWorkPath::getWorkPath 54 | //! \ingroup _GROUP_APPUI_ 55 | inline std::wstring getAppWorkPath() 56 | { 57 | return Object(clsidManager)->getWorkPath(); 58 | } 59 | 60 | //! \copydoc IAppWorkPath::getConfigPath 61 | //! \ingroup _GROUP_APPUI_ 62 | inline std::wstring getConfigPath(const wchar_t* subfolder = L"") 63 | { 64 | return Object(clsidManager)->getConfigPath(subfolder); 65 | } 66 | 67 | //! \copydoc IAppWorkPath::getTranslationsPath 68 | //! \ingroup _GROUP_APPUI_ 69 | inline std::wstring getTranslationsPath(const wchar_t* subfolder) 70 | { 71 | return Object(clsidManager)->getTranslationsPath(subfolder); 72 | } 73 | 74 | END_NAMESPACE_X3 75 | #endif -------------------------------------------------------------------------------- /x3py/interface/core/manager/x3manager.h: -------------------------------------------------------------------------------- 1 | // x3py framework: https://github.com/rhcad/x3py 2 | #ifndef X3_CORE_MANAGER_CLSID_H 3 | #define X3_CORE_MANAGER_CLSID_H 4 | 5 | #include 6 | 7 | BEGIN_NAMESPACE_X3 8 | 9 | const char* const clsidManager = "1137fdae-fd69-4d4c-b3d1-e8f57b55f27e"; 10 | 11 | END_NAMESPACE_X3 12 | #endif -------------------------------------------------------------------------------- /x3py/interface/core/module/classentry.h: -------------------------------------------------------------------------------- 1 | // x3py framework: https://github.com/rhcad/x3py 2 | #ifndef X3_CORE_CLASSENTRY_H 3 | #define X3_CORE_CLASSENTRY_H 4 | 5 | #include "iobject.h" 6 | 7 | BEGIN_NAMESPACE_X3 8 | 9 | typedef IObject* (*ObjectCreator)(long iid); 10 | typedef bool (*HASIID)(long iid); 11 | enum { MIN_SINGLETON_TYPE = 10 }; 12 | 13 | class ClassEntry 14 | { 15 | public: 16 | int type; 17 | const char* className; 18 | const char* clsid; 19 | ObjectCreator creator; 20 | HASIID hasiid; 21 | 22 | ClassEntry(int _type, const char* _className, 23 | const char* _clsid, ObjectCreator _creator, HASIID _hasiid) 24 | : type(_type), className(_className), clsid(_clsid) 25 | , creator(_creator), hasiid(_hasiid) 26 | { 27 | } 28 | 29 | ClassEntry() : type(0), className(""), clsid(""), creator(NULL), hasiid(NULL) 30 | { 31 | } 32 | 33 | // see XEND_DEFINE_MODULE, XEND_DEFINE_MODULE_LIB 34 | static const ClassEntry* const classes[]; 35 | }; 36 | 37 | END_NAMESPACE_X3 38 | 39 | // If don't need plugininc.h or portability/*.h on Windows: 40 | #if !defined(OUTAPI) && defined(_WIN32) 41 | #ifndef _WINDEF_ 42 | #define WIN32_LEAN_AND_MEAN 43 | #include 44 | #endif 45 | #define OUTAPI extern "C" __declspec(dllexport) 46 | #define LOCALAPI 47 | #define x3FreeLibrary(h) FreeLibrary(h) 48 | #define x3LoadLibrary(f) LoadLibraryExA(f, NULL, LOAD_WITH_ALTERED_SEARCH_PATH) 49 | #endif // OUTAPI 50 | 51 | #endif -------------------------------------------------------------------------------- /x3py/interface/core/module/classmacro.h: -------------------------------------------------------------------------------- 1 | // x3py framework: https://github.com/rhcad/x3py 2 | #ifndef X3_CORE_CLASSMACRO_H 3 | #define X3_CORE_CLASSMACRO_H 4 | 5 | // X3BEGIN_CLASS_DECLARE(Cls, clsid) 6 | // X3BEGIN_CLASS_DECLARE0(Cls) 7 | // X3DEFINE_INTERFACE_ENTRY(_Interface) 8 | // X3USE_INTERFACE_ENTRY(_BaseClass) 9 | // X3END_CLASS_DECLARE() 10 | 11 | namespace x3 { 12 | LOCALAPI HMODULE getModuleHandle(); 13 | LOCALAPI HMODULE getManagerModule(); 14 | } 15 | 16 | #define X3BEGIN_CLASS_DECLARE0(Cls) \ 17 | public: \ 18 | static bool _queryObject(const Cls* self, long iid, x3::IObject** p) \ 19 | { 20 | 21 | #define X3BEGIN_CLASS_DECLARE(Cls, clsid) \ 22 | public: \ 23 | static const char* _getClassID() { return clsid; } \ 24 | static const char* _getClassName() { return #Cls; } \ 25 | static bool _queryObject(const Cls* self, long iid, x3::IObject** p) \ 26 | { 27 | 28 | #define X3DEFINE_INTERFACE_ENTRY(_Interface) \ 29 | if (iid == _Interface::getIID()) \ 30 | { \ 31 | if (self) { \ 32 | *p = (x3::IObject*)(_Interface*)(self); \ 33 | (*p)->retainObject(); \ 34 | } \ 35 | return true; \ 36 | } 37 | 38 | #define X3USE_INTERFACE_ENTRY(_BaseClass) \ 39 | if (_BaseClass::_queryObject(self, iid, p)) \ 40 | { \ 41 | return true; \ 42 | } 43 | 44 | #define X3END_CLASS_DECLARE() \ 45 | return false; \ 46 | } \ 47 | protected: // Ensure the following constructor is protected. 48 | 49 | #endif -------------------------------------------------------------------------------- /x3py/interface/core/module/moduleitem.h: -------------------------------------------------------------------------------- 1 | // x3py framework: https://github.com/rhcad/x3py 2 | #ifndef X3_CORE_MODULEITEM_H 3 | #define X3_CORE_MODULEITEM_H 4 | 5 | namespace x3 { 6 | 7 | class ModuleItem 8 | { 9 | protected: 10 | ModuleItem() : _index(-1) 11 | { 12 | } 13 | virtual ~ModuleItem() 14 | { 15 | } 16 | 17 | void addModuleItem() 18 | { 19 | _index = InterlockedDecrement(&index()); 20 | if (_index >= 0) 21 | { 22 | items()[_index] = this; // only one thread can do it. 23 | } 24 | } 25 | 26 | public: 27 | static void free() 28 | { 29 | if (items()) 30 | { 31 | for (long i = index(); i < maxCount(); i++) 32 | { 33 | if (i >= 0 && items()[i]) 34 | { 35 | delete items()[i]; 36 | items()[i] = NULL; 37 | } 38 | } 39 | index() = 0; 40 | 41 | delete[] items(); 42 | items() = NULL; 43 | } 44 | } 45 | 46 | static void init(int singletonClassCount) 47 | { 48 | if (!items() && singletonClassCount > 0) 49 | { 50 | maxCount() = (singletonClassCount > maxCount()) 51 | ? singletonClassCount : maxCount(); 52 | index() = maxCount(); 53 | items() = new ModuleItem*[maxCount()]; 54 | } 55 | } 56 | 57 | private: 58 | long _index; // index in the single instance stack. 59 | 60 | static long& maxCount() 61 | { 62 | static long count = 0; 63 | return count; 64 | } 65 | static long& index() 66 | { 67 | static long n = 0; 68 | return n; 69 | } 70 | static ModuleItem**& items() 71 | { 72 | static ModuleItem** p = NULL; 73 | return p; 74 | } 75 | }; 76 | 77 | } // x3 78 | #endif -------------------------------------------------------------------------------- /x3py/interface/core/module/normalobject.h: -------------------------------------------------------------------------------- 1 | // x3py framework: https://github.com/rhcad/x3py 2 | #ifndef X3_CORE_NORMALOBJECT_H 3 | #define X3_CORE_NORMALOBJECT_H 4 | 5 | #include "iobject.h" 6 | 7 | BEGIN_NAMESPACE_X3 8 | 9 | template 10 | class NormalObject : public Cls 11 | { 12 | protected: 13 | NormalObject() : _refcount(1) 14 | { 15 | } 16 | 17 | virtual ~NormalObject() 18 | { 19 | } 20 | 21 | protected: 22 | virtual long retainObject() const 23 | { 24 | return InterlockedIncrement(&_refcount); 25 | } 26 | 27 | virtual long releaseObject() const 28 | { 29 | long ret = InterlockedDecrement(&_refcount); 30 | if (0 == ret) 31 | { 32 | delete this; 33 | } 34 | 35 | return ret; 36 | } 37 | 38 | virtual bool queryObject(long iid, IObject** p) const 39 | { 40 | return Cls::_queryObject(this, iid, p); 41 | } 42 | 43 | virtual const char* getClassID() const 44 | { 45 | return Cls::_getClassID(); 46 | } 47 | 48 | virtual const char* getClassName() const 49 | { 50 | return Cls::_getClassName(); 51 | } 52 | 53 | public: 54 | static IObject* create(long iid) 55 | { 56 | IObject* ret = NULL; 57 | NormalObject* p = new NormalObject(); 58 | 59 | p->queryObject(iid, &ret); 60 | p->releaseObject(); 61 | 62 | return ret; 63 | } 64 | 65 | static bool hasInterface(long iid) 66 | { 67 | return Cls::_queryObject(NULL, iid, NULL); 68 | } 69 | 70 | private: 71 | NormalObject(const NormalObject&); 72 | void operator=(const NormalObject&); 73 | 74 | mutable long _refcount; 75 | }; 76 | 77 | END_NAMESPACE_X3 78 | #endif -------------------------------------------------------------------------------- /x3py/interface/core/module/pluginimpl.h: -------------------------------------------------------------------------------- 1 | #if !defined(X3_CORE_PLUGINIMPL_H) && !defined(_LIB) 2 | #define X3_CORE_PLUGINIMPL_H 3 | 4 | #include "classentry.h" 5 | #include "moduleitem.h" 6 | #ifdef X3_CORE_PORTABILITY_H 7 | #include "../portability/portimpl.h" 8 | #endif 9 | #ifdef X3_LOG_DEBUGR_H_ 10 | #include 11 | #endif 12 | 13 | BEGIN_NAMESPACE_X3 14 | 15 | static HMODULE s_hmod = NULL; 16 | static HMODULE s_manager = NULL; 17 | static bool s_loadmgr = false; 18 | static long s_refcount = 0; 19 | 20 | OUTAPI bool x3InitializePlugin(); 21 | OUTAPI void x3UninitializePlugin(); 22 | 23 | LOCALAPI HMODULE getModuleHandle() 24 | { 25 | return s_hmod; 26 | } 27 | 28 | LOCALAPI HMODULE getManagerModule() 29 | { 30 | return s_manager; 31 | } 32 | 33 | static int getClassCount(int minType = 0) 34 | { 35 | int count = 0; 36 | 37 | for (const ClassEntry* const* arr = ClassEntry::classes; *arr; arr++) 38 | { 39 | for (const ClassEntry* cls = *arr; cls->creator; cls++) 40 | { 41 | if (cls->type >= minType) 42 | count++; 43 | } 44 | } 45 | 46 | return count; 47 | } 48 | 49 | static const char** getClassIDs(const char** clsids, int count) 50 | { 51 | const ClassEntry* const* arr = ClassEntry::classes; 52 | int i = 0; 53 | 54 | for (; *arr && i < count; arr++) 55 | { 56 | for (const ClassEntry* cls = *arr; cls->creator; cls++, i++) 57 | { 58 | clsids[i] = cls->clsid; 59 | } 60 | } 61 | clsids[i] = NULL; 62 | 63 | return clsids; 64 | } 65 | 66 | static bool getDefaultClassID(long iid, const char*& clsid) 67 | { 68 | for (const ClassEntry* const* arr = ClassEntry::classes; *arr; arr++) 69 | { 70 | for (const ClassEntry* cls = *arr; cls->creator; cls++) 71 | { 72 | if (cls->hasiid(iid)) 73 | { 74 | clsid = cls->clsid; 75 | return true; 76 | } 77 | } 78 | } 79 | 80 | return false; 81 | } 82 | 83 | OUTAPI bool x3InternalCreate(const char* clsid, long iid, IObject** p) 84 | { 85 | *p = NULL; 86 | 87 | if (0 == *clsid) 88 | { 89 | getDefaultClassID(iid, clsid); 90 | } 91 | for (const ClassEntry* const* arr = ClassEntry::classes; *arr; arr++) 92 | { 93 | for (const ClassEntry* cls = *arr; cls->creator; cls++) 94 | { 95 | if (strcmp(cls->clsid, clsid) == 0) 96 | { 97 | *p = cls->creator(iid); 98 | return *p != NULL; 99 | } 100 | } 101 | } 102 | 103 | return false; 104 | } 105 | 106 | OUTAPI bool x3FreePlugin() 107 | { 108 | if (--s_refcount != 0) 109 | return false; 110 | 111 | bool needFree = true; 112 | 113 | if (s_manager && s_manager != s_hmod) 114 | { 115 | typedef bool (*CF)(const char*, long, IObject**); 116 | typedef bool (*UF)(CF); 117 | UF uf = (UF)GetProcAddress(s_manager, "x3UnregisterPlugin"); 118 | needFree = !uf || uf(x3InternalCreate); 119 | } 120 | if (needFree) 121 | { 122 | x3UninitializePlugin(); 123 | } 124 | 125 | if (s_loadmgr) 126 | { 127 | x3FreeLibrary(s_manager); 128 | s_loadmgr = false; 129 | } 130 | 131 | ModuleItem::free(); 132 | 133 | return true; 134 | } 135 | 136 | #ifndef X3_CLASS_MAXCOUNT 137 | #define X3_CLASS_MAXCOUNT 64 138 | #endif 139 | #ifndef X3MANAGER_PLNAME 140 | #define X3MANAGER_PLNAME "x3manager.pln" 141 | #endif 142 | 143 | OUTAPI bool x3InitPlugin(HMODULE hmod, HMODULE hmanager) 144 | { 145 | if (++s_refcount != 1) 146 | return true; 147 | 148 | int singletonClassCount = getClassCount(MIN_SINGLETON_TYPE); 149 | ModuleItem::init(singletonClassCount); 150 | 151 | // Call all interfaces' getIID() to set static const value. 152 | const char* tmpclsid; 153 | getDefaultClassID(IObject::getIID(), tmpclsid); 154 | 155 | s_hmod = hmod; 156 | 157 | if (!s_manager) 158 | { 159 | hmanager = hmanager ? hmanager : GetModuleHandleA(X3MANAGER_PLNAME); 160 | if (!hmanager) 161 | { 162 | hmanager = x3LoadLibrary(X3MANAGER_PLNAME); 163 | s_loadmgr = true; 164 | } 165 | s_manager = hmanager; 166 | } 167 | 168 | bool needInit = true; 169 | 170 | if (s_manager && s_manager != s_hmod) 171 | { 172 | typedef bool (*CF)(const char*, long, IObject**); 173 | typedef bool (*RF)(CF, HMODULE, const char**); 174 | RF freg = (RF)GetProcAddress(s_manager, "x3RegisterPlugin"); 175 | 176 | const char* clsids[X3_CLASS_MAXCOUNT + 1] = { NULL }; 177 | needInit = !freg || freg(x3InternalCreate, s_hmod, 178 | getClassIDs(clsids, X3_CLASS_MAXCOUNT)); 179 | } 180 | 181 | return !needInit || x3InitializePlugin(); 182 | } 183 | 184 | #ifndef CREATEOBJECTIMPL 185 | #define CREATEOBJECTIMPL 186 | LOCALAPI bool createObject(const char* clsid, long iid, IObject** p) 187 | { 188 | if (!x3InternalCreate(clsid, iid, p) && s_manager) 189 | { 190 | typedef bool (*F)(const char*, long, IObject**); 191 | F f = (F)GetProcAddress(s_manager, "x3CreateObject"); 192 | return f && f(clsid, iid, p); 193 | } 194 | return *p != NULL; 195 | } 196 | #endif 197 | 198 | #ifndef X3_EXCLUDE_CREATEOBJECT 199 | OUTAPI bool x3CreateObject(const char* clsid, long iid, IObject** p) 200 | { 201 | return x3InternalCreate(clsid, iid, p); 202 | } 203 | #endif 204 | 205 | END_NAMESPACE_X3 206 | #endif 207 | -------------------------------------------------------------------------------- /x3py/interface/core/module/plugininc.h: -------------------------------------------------------------------------------- 1 | #ifndef X3_CORE_PLUGIN_INC_H 2 | #define X3_CORE_PLUGIN_INC_H 3 | 4 | #include 5 | #include 6 | 7 | //#include 8 | //#include 9 | 10 | #endif -------------------------------------------------------------------------------- /x3py/interface/core/module/singletonobj.h: -------------------------------------------------------------------------------- 1 | // x3py framework: https://github.com/rhcad/x3py 2 | #ifndef X3_CORE_SINGLETONOBJECT_H 3 | #define X3_CORE_SINGLETONOBJECT_H 4 | 5 | #include "moduleitem.h" 6 | #include "iobject.h" 7 | 8 | #if !defined(_MSC_VER) || _MSC_VER >= 1700 9 | #include 10 | #endif 11 | 12 | BEGIN_NAMESPACE_X3 13 | 14 | template 15 | class SingletonObject 16 | : public Cls 17 | , public ModuleItem 18 | { 19 | protected: 20 | SingletonObject() : _refcount(1) 21 | { 22 | } 23 | 24 | virtual ~SingletonObject() 25 | { 26 | if (Instance() == this) 27 | { 28 | Instance() = NULL; 29 | } 30 | } 31 | 32 | protected: 33 | virtual long retainObject() const 34 | { 35 | return InterlockedIncrement(&_refcount); 36 | } 37 | 38 | virtual long releaseObject() const 39 | { 40 | return InterlockedDecrement(&_refcount); 41 | } 42 | 43 | virtual bool queryObject(long iid, IObject** p) const 44 | { 45 | return Cls::_queryObject(this, iid, p); 46 | } 47 | 48 | virtual const char* getClassID() const 49 | { 50 | return Cls::_getClassID(); 51 | } 52 | 53 | virtual const char* getClassName() const 54 | { 55 | return Cls::_getClassName(); 56 | } 57 | 58 | public: 59 | static IObject* create(long iid) 60 | { 61 | if (!Instance()) 62 | { 63 | #if !defined(_MSC_VER) || _MSC_VER >= 1700 64 | static std::mutex s_mutex; 65 | std::lock_guard lock(s_mutex); 66 | if (!Instance()) 67 | { 68 | SingletonObject* p = new SingletonObject(); 69 | Instance() = p; 70 | p->addModuleItem(); 71 | } 72 | #else 73 | static long s_count = 0; 74 | SingletonObject* p = new SingletonObject(); 75 | 76 | if (1 == InterlockedIncrement(&s_count)) 77 | { 78 | Instance() = p; 79 | p->addModuleItem(); 80 | } 81 | else 82 | { 83 | delete p; // created by another thread 84 | } 85 | InterlockedDecrement(&s_count); 86 | #endif 87 | } 88 | 89 | IObject* ret = NULL; 90 | Instance()->queryObject(iid, &ret); 91 | 92 | return ret; 93 | } 94 | 95 | static bool hasInterface(long iid) 96 | { 97 | return Cls::_queryObject(NULL, iid, NULL); 98 | } 99 | 100 | private: 101 | SingletonObject(const SingletonObject&); 102 | void operator=(const SingletonObject&); 103 | 104 | mutable long _refcount; 105 | 106 | static SingletonObject*& Instance() 107 | { 108 | static SingletonObject* obj = NULL; 109 | return obj; 110 | } 111 | }; 112 | 113 | END_NAMESPACE_X3 114 | #endif 115 | -------------------------------------------------------------------------------- /x3py/interface/core/nonplugin/scanplugins.h: -------------------------------------------------------------------------------- 1 | // x3py framework: https://github.com/rhcad/x3py 2 | #ifndef X3_NONPLUGIN_SCANPLUGINS_H 3 | #define X3_NONPLUGIN_SCANPLUGINS_H 4 | 5 | #include 6 | #include 7 | 8 | #if defined(X3_CORE_PORTABILITY_H) && !defined(X3_EXCLUDE_CREATEOBJECT) 9 | #include 10 | #endif 11 | 12 | #ifndef PLUGINS_MAXCOUNT 13 | #define PLUGINS_MAXCOUNT 1000 14 | #endif 15 | 16 | namespace x3 { 17 | 18 | static HMODULE s_modules[PLUGINS_MAXCOUNT] = { NULL }; 19 | static int s_nmods = 0; 20 | 21 | static bool loadfilter(const char* filename, const char* ext) 22 | { 23 | if (_stricmp(ext, ".pln") == 0 24 | && GetModuleHandleA(PathFindFileNameA(filename)) == NULL) 25 | { 26 | s_modules[s_nmods] = x3LoadLibrary(filename); 27 | if (s_modules[s_nmods]) 28 | s_nmods++; 29 | } 30 | return s_nmods < PLUGINS_MAXCOUNT; 31 | } 32 | 33 | int loadScanPlugins(const char* folder = "plugins") 34 | { 35 | char path[MAX_PATH]; 36 | 37 | GetModuleFileNameA(NULL, path, MAX_PATH); 38 | PathRemoveFileSpecA(path); 39 | PathAppendA(path, folder); 40 | 41 | // Load x3manager before others, so others can find it in x3InitPlugin(). 42 | if (!GetModuleHandleA("x3manager.pln")) 43 | { 44 | PathAppendA(path, "x3manager.pln"); 45 | loadfilter(path, ".pln"); 46 | PathRemoveFileSpecA(path); 47 | } 48 | 49 | typedef int (*LOADF)(const char*); 50 | LOADF fload = (LOADF)GetProcAddress(GetModuleHandleA("x3manager.pln"), "x3LoadPlugins"); 51 | int extcount = fload ? fload(folder) : 0; 52 | 53 | if (!fload) // load plugins regardless the x3manager plugin. 54 | x3::scanfiles(loadfilter, path, true); 55 | 56 | return s_nmods + extcount; 57 | } 58 | 59 | void unloadScanPlugins() 60 | { 61 | typedef int (*UF)(); 62 | UF uf = (UF)GetProcAddress(GetModuleHandleA("x3manager.pln"), "x3UnloadPlugins"); 63 | if (uf) uf(); 64 | 65 | while (s_nmods > 0) 66 | { 67 | x3FreeLibrary(s_modules[--s_nmods]); 68 | } 69 | } 70 | 71 | #if !defined(X3_EXCLUDE_CREATEOBJECT) && !defined(CREATEOBJECTIMPL) 72 | #define CREATEOBJECTIMPL 73 | 74 | class IObject; 75 | LOCALAPI bool createObject(const char* clsid, long iid, IObject** p) 76 | { 77 | typedef bool (*F)(const char*, long, IObject**); 78 | F f = (F)GetProcAddress(s_modules[0], "x3CreateObject"); 79 | return f && f(clsid, iid, p); 80 | } 81 | HMODULE getManagerModule() { return s_modules[0]; } 82 | #endif // CREATEOBJECTIMPL 83 | 84 | } // x3 85 | #endif 86 | -------------------------------------------------------------------------------- /x3py/interface/core/nonplugin/swigext.h: -------------------------------------------------------------------------------- 1 | // x3py framework: https://github.com/rhcad/x3py 2 | #ifndef X3_NONPLUGIN_SWIG_EXT_H 3 | #define X3_NONPLUGIN_SWIG_EXT_H 4 | 5 | #if defined(SWIGPYTHON) || defined(SWIGCSHARP) || \ 6 | defined(USE_PYTHON) || defined(USE_CSHARP) 7 | #define SELF_PRE "_" 8 | #else 9 | #define SELF_PRE "" 10 | #endif 11 | 12 | #if defined(_WIN32) && (defined(SWIGPYTHON) || defined(USE_PYTHON)) 13 | #define SELF_EXT ".pyd" 14 | #elif !defined(SWIGINLINE) // not in swig wrapper file. 15 | #define SELF_EXT ".pln" 16 | #elif defined(_WIN32) 17 | #define SELF_EXT ".dll" 18 | #else 19 | #define SELF_EXT ".so" 20 | #endif 21 | 22 | // the internal plugin (*.pln) 's relative folder base on the current module. 23 | // 24 | #ifndef PLUGIN_PATH 25 | #ifdef SWIGPYTHON // in python wrapper file. 26 | #define CURMOD_IN_CWDSUBDIR // see x3LoadLibrary() in uniximpl.h 27 | #define PLUGIN_PATH "../../plugins/" // python module has a package 28 | #elif defined(SWIGINLINE) // in swig wrapper file. 29 | #define PLUGIN_PATH "../plugins/" 30 | #else 31 | #define PLUGIN_PATH "" 32 | #endif 33 | #endif // PLUGIN_PATH 34 | 35 | #endif 36 | -------------------------------------------------------------------------------- /x3py/interface/core/nonplugin/useplugin.h: -------------------------------------------------------------------------------- 1 | // x3py framework: https://github.com/rhcad/x3py 2 | #if !defined(X3_NONPLUGIN_USE_PLUGIN_H) && !defined(X3_NONPLUGIN_USE_PLUGINS_H) 3 | #define X3_NONPLUGIN_USE_PLUGIN_H 4 | 5 | #include 6 | #include "swigext.h" 7 | 8 | // PLUGIN_PATH: the internal plugin (*.pln) 's relative folder. 9 | // PLUGIN_NAME: the internal plugin name, no extension and path. 10 | // SELF_MODULE_NAME: file name of the caller module which will load the internal plugin. 11 | // SELF_MODULE: defined when the caller name hasn't PLUGIN_NAME. 12 | 13 | #ifdef PLUGIN_NAME 14 | 15 | #ifndef SELF_MODULE_NAME 16 | #ifndef SELF_MODULE 17 | #define SELF_MODULE_NAME SELF_PRE PLUGIN_NAME SELF_EXT 18 | #else 19 | #define SELF_MODULE_NAME SELF_PRE SELF_MODULE SELF_EXT 20 | #endif 21 | #endif // SELF_MODULE_NAME 22 | 23 | #if defined(X3_CORE_PORTABILITY_H) && !defined(X3_EXCLUDE_CREATEOBJECT) 24 | #include "../portability/portimpl.h" 25 | #endif 26 | 27 | namespace x3 { 28 | 29 | static LoadModuleHelper loader(PLUGIN_PATH PLUGIN_NAME ".pln", 30 | GetModuleHandleA(SELF_MODULE_NAME)); 31 | 32 | #if !defined(X3_EXCLUDE_CREATEOBJECT) && !defined(CREATEOBJECTIMPL) 33 | #define CREATEOBJECTIMPL 34 | 35 | HMODULE getManagerModule() 36 | { 37 | return loader.getModule(); 38 | } 39 | 40 | class IObject; 41 | bool createObject(const char* clsid, long iid, IObject** p) 42 | { 43 | typedef bool (*F)(const char*, long, IObject**); 44 | F f = (F)loader.getFunc("x3CreateObject"); 45 | return f && f(clsid, iid, p); 46 | } 47 | #endif // CREATEOBJECTIMPL 48 | 49 | } // x3 50 | #endif // PLUGIN_NAME 51 | #endif 52 | -------------------------------------------------------------------------------- /x3py/interface/core/nonplugin/useplugins.h: -------------------------------------------------------------------------------- 1 | // x3py framework: https://github.com/rhcad/x3py 2 | #ifndef X3_NONPLUGIN_USE_PLUGINS_H 3 | #define X3_NONPLUGIN_USE_PLUGINS_H 4 | 5 | #include 6 | #include "swigext.h" 7 | 8 | // PLUGIN_PATH: the internal plugin (*.pln) 's relative folder. 9 | // SELF_MODULE_NAME: file name of the caller module which will load the internal plugins. 10 | // SELF_MODULE: used to make SELF_MODULE_NAME. 11 | 12 | #ifndef SELF_MODULE_NAME 13 | #ifndef SELF_MODULE 14 | #define SELF_MODULE_NAME NULL // application file name 15 | #else 16 | #define SELF_MODULE_NAME SELF_PRE SELF_MODULE SELF_EXT 17 | #endif 18 | #endif // SELF_MODULE_NAME 19 | 20 | #if defined(X3_CORE_PORTABILITY_H) && !defined(X3_EXCLUDE_CREATEOBJECT) 21 | #include "../portability/portimpl.h" 22 | #endif 23 | 24 | namespace x3 { 25 | 26 | static LoadModuleHelper* s_plugins[20] = { NULL }; 27 | static int s_nplugin = 0; 28 | 29 | #if !defined(X3_EXCLUDE_CREATEOBJECT) && !defined(CREATEOBJECTIMPL) 30 | #define CREATEOBJECTIMPL 31 | 32 | HMODULE getManagerModule() 33 | { 34 | return s_plugins[0] ? s_plugins[0]->getModule() : NULL; 35 | } 36 | 37 | class IObject; 38 | bool createObject(const char* clsid, long iid, IObject** p) 39 | { 40 | typedef bool (*F)(const char*, long, IObject**); 41 | F f = !s_plugins[0] ? NULL : (F)s_plugins[0]->getFunc("x3CreateObject"); 42 | return f && f(clsid, iid, p); 43 | } 44 | #endif // CREATEOBJECTIMPL 45 | 46 | int loadPlugins(const char* const* plugins, const char* folder = PLUGIN_PATH) 47 | { 48 | HMODULE basemod = GetModuleHandleA(SELF_MODULE_NAME); 49 | 50 | for (int i = 0; s_nplugin < 20 - 1 && plugins[i]; ++i) 51 | { 52 | LoadModuleHelper* p = new LoadModuleHelper(); 53 | if (p->load(plugins[i], basemod, folder)) 54 | { 55 | s_plugins[s_nplugin++] = p; 56 | } 57 | else 58 | { 59 | delete p; 60 | } 61 | } 62 | 63 | return s_nplugin; 64 | } 65 | 66 | void unloadPlugins() 67 | { 68 | for (int i = s_nplugin - 1; i >= 0; i--) 69 | { 70 | delete s_plugins[i]; 71 | s_plugins[i] = NULL; 72 | } 73 | s_nplugin = 0; 74 | } 75 | 76 | /** \code 77 | * const char* plugins[] = { "x3manager.pln", "myplugin.pln", NULL }; 78 | * x3::AutoLoadPlugins autoload(plugins, "plugins"); 79 | * \endcode 80 | */ 81 | struct AutoLoadPlugins 82 | { 83 | AutoLoadPlugins(const char* const* plugins, const char* folder = PLUGIN_PATH) 84 | { 85 | loadPlugins(plugins, folder); 86 | } 87 | ~AutoLoadPlugins() 88 | { 89 | unloadPlugins(); 90 | } 91 | }; 92 | 93 | } // x3 94 | #endif 95 | -------------------------------------------------------------------------------- /x3py/interface/core/objptr.h: -------------------------------------------------------------------------------- 1 | // x3py framework: https://github.com/rhcad/x3py 2 | #ifndef X3_CORE_OBJPTR_H 3 | #define X3_CORE_OBJPTR_H 4 | 5 | #include "iobject.h" 6 | 7 | BEGIN_NAMESPACE_X3 8 | 9 | #ifndef SWIG 10 | LOCALAPI bool createObject(const char* clsid, long iid, IObject** p); 11 | struct NullPointerError {}; 12 | #ifndef X3THROW_NULLPOINTERERROR 13 | #define X3THROW_NULLPOINTERERROR(name) throw x3::NullPointerError() 14 | #endif 15 | #endif // SWIG 16 | 17 | template class Object 18 | { 19 | public: 20 | // if clsid is "" then the actual class id will be used just in the current plugin. 21 | Object(const char* clsid) : _p((I*)0) 22 | { 23 | createObject(clsid, I::getIID(), address()); 24 | } 25 | 26 | Object(const IObject* src) : _p((I*)0) 27 | { 28 | operator=(src); 29 | } 30 | 31 | #if !defined(_MSC_VER) || _MSC_VER > 1200 32 | Object(const Object& src) : _p((I*)0) 33 | { 34 | operator=(src.p()); 35 | } 36 | #endif // not vc6 37 | 38 | bool valid() const 39 | { 40 | return !!_p; 41 | } 42 | 43 | I* p() const 44 | { 45 | return _p; 46 | } 47 | 48 | I* operator->() const 49 | { 50 | if (!_p) { 51 | X3THROW_NULLPOINTERERROR(I::getInterfaceName()); 52 | } 53 | return _p; 54 | } 55 | 56 | #ifndef SWIG // SWIG always call operator->() so must create when constructing. 57 | Object() : _p((I*)0) 58 | { 59 | } 60 | 61 | template 62 | Object(const Object& src) : _p((I*)0) 63 | { 64 | operator=(src.p()); 65 | } 66 | 67 | ~Object() 68 | { 69 | release(); 70 | } 71 | 72 | void release() 73 | { 74 | if (_p) { 75 | _p->releaseObject(); 76 | _p = (I*)0; 77 | } 78 | } 79 | 80 | Object& create(const char* clsid = "") 81 | { 82 | createObject(clsid, I::getIID(), address()); 83 | return *this; 84 | } 85 | 86 | #if !defined(_MSC_VER) || _MSC_VER > 1200 87 | Object& operator=(const Object& src) 88 | { 89 | if (src) 90 | src.p()->retainObject(); 91 | if (_p) 92 | _p->releaseObject(); 93 | _p = src.p(); 94 | 95 | return *this; 96 | } 97 | #endif // not vc6 98 | 99 | template 100 | Object& operator=(const Object& src) 101 | { 102 | if (I::getIID() == I2::getIID() 103 | || I::getIID() == IObject::getIID()) 104 | { 105 | if (src) 106 | src.p()->retainObject(); 107 | if (_p) 108 | _p->releaseObject(); 109 | _p = src.p(); 110 | 111 | return *this; 112 | } 113 | 114 | return operator=(src.p()); 115 | } 116 | 117 | Object& operator=(const IObject* src) 118 | { 119 | if (_p != src) { 120 | release(); 121 | if (I::getIID() == IObject::getIID() && src) { 122 | src->retainObject(); 123 | _p = static_cast(const_cast(src)); 124 | } 125 | else if (src) { 126 | src->queryObject(I::getIID(), address()); 127 | } 128 | } 129 | return *this; 130 | } 131 | 132 | operator bool() const 133 | { 134 | return !!_p; 135 | } 136 | 137 | bool operator!() const 138 | { 139 | return !_p; 140 | } 141 | 142 | bool operator==(const Object& src) const 143 | { 144 | return _p == src._p; 145 | } 146 | 147 | bool operator!=(const Object& src) const 148 | { 149 | return _p != src._p; 150 | } 151 | 152 | IObject** address() 153 | { 154 | release(); 155 | return reinterpret_cast(&_p); 156 | } 157 | #endif // SWIG 158 | 159 | private: 160 | I* _p; 161 | }; 162 | 163 | typedef Object AnyObject; 164 | 165 | END_NAMESPACE_X3 166 | #endif -------------------------------------------------------------------------------- /x3py/interface/core/observer/eventobserver.h: -------------------------------------------------------------------------------- 1 | // x3py framework: https://github.com/rhcad/x3py 2 | // Need to include in module.cpp 3 | // 4 | #ifndef X3_CORE_EVENTOBSERVER_H 5 | #define X3_CORE_EVENTOBSERVER_H 6 | 7 | #include 8 | 9 | namespace x3 { 10 | 11 | bool registerObserver(const char* type, PROC handler); 12 | bool registerObserver(const char* type, ObserverObject* obj, ON_EVENT handler); 13 | void unregisterObserver(ObserverObject* obj); 14 | int fireEvent(const char* type, PROC dispatcher, void* data, bool obj); 15 | 16 | } // x3 17 | 18 | 19 | #ifndef JOIN 20 | # define JOIN(a,b) JOIN1(a,b) 21 | # define JOIN1(a,b) a##b 22 | #endif 23 | 24 | // Declare a event type. 25 | // Return: return type of the handler function, such as void or bool. 26 | // Params: param types of the handler function. eg: (void), (int&), (int, char c). 27 | // Namespace: extra string of event type. 28 | #define X3DEFINE_EVENT(TypeName, Return, Params, Namespace) \ 29 | struct TypeName { \ 30 | static const char* getType() { return #TypeName "." Namespace; } \ 31 | typedef Return (*Handler)Params; \ 32 | } 33 | 34 | // Declare a event type for classes derived from ObserverObject. 35 | #define X3DEFINE_OBJEVENT(TypeName, Return, Params, Namespace) \ 36 | struct TypeName { \ 37 | static const char* getType() { return #TypeName "." Namespace; } \ 38 | typedef Return (x3::ObserverObject::*Handler)Params; \ 39 | } 40 | 41 | // Register a handler function in x3InitializePlugin(). 42 | // handler: local function or static member function. 43 | #define X3_REGISTER_OBSERVER(TypeName, handler) \ 44 | x3::registerObserver(TypeName::getType(), \ 45 | (PROC)static_cast(handler)) 46 | 47 | // Register a member function and object in the constructor function. 48 | // handler: member function of a class derived from x3::ObserverObject. 49 | // Note: must callHandler x3::unregisterObserver(this) in the destructor function. 50 | #define X3_REGISTER_OBSERVER_OBJECT(TypeName, handler) \ 51 | x3::registerObserver(TypeName::getType(), this, \ 52 | (x3::ON_EVENT)static_cast(handler)) 53 | 54 | #endif -------------------------------------------------------------------------------- /x3py/interface/core/observer/fireevent.h: -------------------------------------------------------------------------------- 1 | // x3py framework: https://github.com/rhcad/x3py 2 | #ifndef X3_CORE_FIRE_EVENT_H 3 | #define X3_CORE_FIRE_EVENT_H 4 | 5 | #include 6 | 7 | #define X3DEFINE_EVENT_0(TypeName, Namespace) \ 8 | X3DEFINE_EVENT(TypeName, void, (), Namespace); \ 9 | typedef x3::FireEvent0 Fire ## TypeName 10 | 11 | #define X3DEFINE_EVENT_0Break(TypeName, Namespace) \ 12 | X3DEFINE_EVENT(TypeName, bool, (), Namespace); \ 13 | typedef x3::FireEvent0 Fire ## TypeName 14 | 15 | #define X3DEFINE_EVENT_1(TypeName, ParamT, Namespace) \ 16 | X3DEFINE_EVENT(TypeName, void, (ParamT), Namespace); \ 17 | typedef x3::FireEvent1 Fire ## TypeName 18 | 19 | #define X3DEFINE_EVENT_1Break(TypeName, ParamT, Namespace) \ 20 | X3DEFINE_EVENT(TypeName, bool, (ParamT), Namespace); \ 21 | typedef x3::FireEvent1 Fire ## TypeName 23 | 24 | #define X3DEFINE_EVENT_2(TypeName, Param1, Param2, Namespace) \ 25 | X3DEFINE_EVENT(TypeName, void, (Param1, Param2), Namespace); \ 26 | typedef x3::FireEvent2 Fire ## TypeName 27 | 28 | #define X3DEFINE_EVENT_2Break(TypeName, Param1, Param2, Namespace) \ 29 | X3DEFINE_EVENT(TypeName, bool, (Param1, Param2), Namespace); \ 30 | typedef x3::FireEvent2 Fire ## TypeName 32 | 33 | // ---------------------------------------- 34 | 35 | namespace x3 { 36 | 37 | template class FireEventBase 38 | { 39 | public: 40 | int nhandled; 41 | 42 | bool handled() const { return nhandled > 0; } 43 | 44 | protected: 45 | FireEventBase() : nhandled(0) {} 46 | 47 | typedef bool (*EventDispatcher)(PROC handler, void* data); 48 | 49 | template 50 | void _fireEvent(Dispatcher dispatcher) { 51 | nhandled = fireEvent(EventType::getType(), 52 | (PROC)static_cast(dispatcher), this, false); 53 | } 54 | }; 55 | 56 | // -------------- FireEvent0 -------------- 57 | 58 | struct FireEvent0NotBreak { 59 | template 60 | static bool call(Handler handler) { handler(); return true; } 61 | }; 62 | 63 | struct FireEvent0Break { 64 | template 65 | static bool call(Handler handler) { return !!handler(); } 66 | }; 67 | 68 | template 69 | class FireEvent0 : public FireEventBase 70 | { 71 | public: 72 | typedef FireEventBase Base; 73 | typedef FireEvent0 This; 74 | FireEvent0() {} 75 | This& fireEvent() { Base::_fireEvent(dispatcher); return *this; } 76 | 77 | private: 78 | static bool dispatcher(PROC handler, void*) { 79 | return Break::call((typename EventType::Handler)handler); 80 | } 81 | }; 82 | 83 | // -------------- FireEvent1 -------------- 84 | 85 | struct FireEvent1NotBreak { 86 | template 87 | static bool call(Handler handler, ParamT* param) { 88 | handler(*param); return true; 89 | } 90 | }; 91 | 92 | struct FireEvent1Break { 93 | template 94 | static bool call(Handler handler, ParamT* param) { 95 | return !!handler(*param); 96 | } 97 | }; 98 | 99 | template 100 | class FireEvent1 : public FireEventBase 101 | { 102 | public: 103 | typedef FireEventBase Base; 104 | typedef FireEvent1 This; 105 | ParamT param; 106 | 107 | FireEvent1(ParamT p) : param(p) {} 108 | This& fireEvent() { Base::_fireEvent(dispatcher); return *this; } 109 | 110 | private: 111 | FireEvent1(const This&); 112 | This& operator=(const This&); 113 | FireEvent1(); 114 | 115 | static bool dispatcher(PROC handler, void* data) { 116 | return Break::call((typename EventType::Handler)handler, &((This*)data)->param); 117 | } 118 | }; 119 | 120 | // -------------- FireEvent2 -------------- 121 | 122 | struct FireEvent2NotBreak { 123 | template 124 | static bool call(Handler handler, Param1* param1, Param2* param2) { 125 | handler(*param1, *param2); return true; 126 | } 127 | }; 128 | 129 | struct FireEvent2Break { 130 | template 131 | static bool call(Handler handler, Param1* param1, Param2* param2) { 132 | return !!handler(*param1, *param2); 133 | } 134 | }; 135 | 136 | template 138 | class FireEvent2 : public FireEventBase 139 | { 140 | public: 141 | typedef FireEventBase Base; 142 | typedef FireEvent2 This; 143 | Param1 param1; 144 | Param2 param2; 145 | 146 | FireEvent2(Param1 p1, Param2 p2) : param1(p1), param2(p2) {} 147 | This& fireEvent() { Base::_fireEvent(dispatcher); return *this; } 148 | 149 | private: 150 | FireEvent2(const This&); 151 | This& operator=(const This&); 152 | FireEvent2(); 153 | 154 | static bool dispatcher(PROC handler, void* data) { 155 | This* p = (This*)data; 156 | return Break::call((typename EventType::Handler)handler, &p->param1, &p->param2); 157 | } 158 | }; 159 | 160 | } // x3 161 | #endif -------------------------------------------------------------------------------- /x3py/interface/core/observer/fireobjeventex.h: -------------------------------------------------------------------------------- 1 | // x3py framework: https://github.com/rhcad/x3py 2 | #ifndef X3_CORE_FIRE_OBJECT_EVENTEX_H 3 | #define X3_CORE_FIRE_OBJECT_EVENTEX_H 4 | 5 | #include 6 | 7 | #define X3DEFINE_OBJEVENT_4(TypeName, Param1, Param2, Param3, Param4, Namespace) \ 8 | X3DEFINE_OBJEVENT(TypeName, void, (Param1, Param2, Param3, Param4), Namespace); \ 9 | typedef x3::FireObjectEvent4 Fire ## TypeName 10 | 11 | #define X3DEFINE_OBJEVENT_4Break(TypeName, Param1, Param2, Param3, Param4, Namespace) \ 12 | X3DEFINE_OBJEVENT(TypeName, bool, (Param1, Param2, Param3, Param4), Namespace); \ 13 | typedef x3::FireObjectEvent4 Fire ## TypeName 15 | 16 | #define X3DEFINE_OBJEVENT_5(TypeName, Param1, Param2, Param3, Param4, Param5, Namespace) \ 17 | X3DEFINE_OBJEVENT(TypeName, void, (Param1, Param2, Param3, Param4, Param5), Namespace); \ 18 | typedef x3::FireObjectEvent5 Fire ## TypeName 19 | 20 | #define X3DEFINE_OBJEVENT_5Break(TypeName, Param1, Param2, Param3, Param4, Param5, Namespace) \ 21 | X3DEFINE_OBJEVENT(TypeName, bool, (Param1, Param2, Param3, Param4, Param5), Namespace); \ 22 | typedef x3::FireObjectEvent5 Fire ## TypeName 24 | 25 | // ---------------------------------------- 26 | 27 | namespace x3 { 28 | 29 | // -------------- FireObjectEvent4 -------------- 30 | 31 | struct FireObjectEvent4NotBreak { 32 | template 33 | static bool call(ObserverObject* obj, Handler hd, Param1* p1, Param2* p2, Param3* p3, Param4* p4) { 34 | (obj->*hd)(*p1, *p2, *p3, *p4); return true; 35 | } 36 | }; 37 | 38 | struct FireObjectEvent4Break { 39 | template 40 | static bool call(ObserverObject* obj, Handler hd, Param1* p1, Param2* p2, Param3* p3, Param4* p4) { 41 | return !!(obj->*hd)(*p1, *p2, *p3, *p4); 42 | } 43 | }; 44 | 45 | template 47 | class FireObjectEvent4 : public FireObjEventBase 48 | { 49 | public: 50 | typedef FireObjEventBase Base; 51 | typedef FireObjectEvent4 This; 52 | Param1 param1; 53 | Param2 param2; 54 | Param3 param3; 55 | Param4 param4; 56 | 57 | FireObjectEvent4(Param1 p1, Param2 p2, Param3 p3, Param4 p4) : param1(p1), param2(p2), param3(p3), param4(p4) {} 58 | This& fireEvent() { Base::_fireEvent(dispatcher); return *this; } 59 | 60 | private: 61 | FireObjectEvent4(const This&); 62 | This& operator=(const This&); 63 | FireObjectEvent4(); 64 | 65 | static bool dispatcher(ObserverObject* obj, ON_EVENT hd, void* data) 66 | { 67 | This* p = (This*)data; 68 | typename EventType::Handler handler; 69 | 70 | Base::cast(handler, hd); 71 | return Break::call(obj, handler, &p->param1, &p->param2, &p->param3, &p->param4); 72 | } 73 | }; 74 | 75 | // -------------- FireObjectEvent5 -------------- 76 | 77 | struct FireObjectEvent5NotBreak { 78 | template 79 | static bool call(ObserverObject* obj, Handler hd, Param1* p1, Param2* p2, Param3* p3, Param4* p4, Param5* p5) { 80 | (obj->*hd)(*p1, *p2, *p3, *p4, *p5); return true; 81 | } 82 | }; 83 | 84 | struct FireObjectEvent5Break { 85 | template 86 | static bool call(ObserverObject* obj, Handler hd, Param1* p1, Param2* p2, Param3* p3, Param4* p4, Param5* p5) { 87 | return !!(obj->*hd)(*p1, *p2, *p3, *p4, *p5); 88 | } 89 | }; 90 | 91 | template 93 | class FireObjectEvent5 : public FireObjEventBase 94 | { 95 | public: 96 | typedef FireObjEventBase Base; 97 | typedef FireObjectEvent5 This; 98 | Param1 param1; 99 | Param2 param2; 100 | Param3 param3; 101 | Param4 param4; 102 | Param5 param5; 103 | 104 | FireObjectEvent5(Param1 p1, Param2 p2, Param3 p3, Param4 p4, Param5 p5) : param1(p1), param2(p2), param3(p3), param4(p4), param5(p5) {} 105 | This& fireEvent() { Base::_fireEvent(dispatcher); return *this; } 106 | 107 | private: 108 | FireObjectEvent5(const This&); 109 | This& operator=(const This&); 110 | FireObjectEvent5(); 111 | 112 | static bool dispatcher(ObserverObject* obj, ON_EVENT hd, void* data) 113 | { 114 | This* p = (This*)data; 115 | typename EventType::Handler handler; 116 | 117 | Base::cast(handler, hd); 118 | return Break::call(obj, handler, &p->param1, &p->param2, &p->param3, &p->param4, &p->param5); 119 | } 120 | }; 121 | 122 | } // x3 123 | #endif 124 | -------------------------------------------------------------------------------- /x3py/interface/core/observer/observerimpl.h: -------------------------------------------------------------------------------- 1 | // x3py framework: https://github.com/rhcad/x3py 2 | #ifndef X3_CORE_OBSERVERIMPL_H 3 | #define X3_CORE_OBSERVERIMPL_H 4 | 5 | #include 6 | 7 | #ifndef X3_CORE_PLUGINIMPL_H 8 | #define x3InternalCreate createObject 9 | #endif 10 | 11 | namespace x3 { 12 | 13 | bool registerObserver(const char* type, PROC handler) 14 | { 15 | typedef bool (*CF)(const char*, long, IObject**); 16 | typedef bool (*F)(const char*, PROC, CF); 17 | F f = (F)GetProcAddress(getManagerModule(), "x3RegisterObserver"); 18 | return f && f(type, handler, x3InternalCreate); 19 | } 20 | 21 | bool registerObserver(const char* type, x3::ObserverObject* obj, x3::ON_EVENT handler) 22 | { 23 | typedef bool (*CF)(const char*, long, IObject**); 24 | typedef bool (*F)(const char*, x3::ObserverObject*, x3::ON_EVENT, CF); 25 | F f = (F)GetProcAddress(getManagerModule(), "x3RegisterObserverObject"); 26 | return f && f(type, obj, handler, x3InternalCreate); 27 | } 28 | 29 | void unregisterObserver(x3::ObserverObject* obj) 30 | { 31 | typedef void (*F)(x3::ObserverObject*); 32 | F f = (F)GetProcAddress(getManagerModule(), "x3UnregisterObserverObject"); 33 | if (f) f(obj); 34 | } 35 | 36 | int fireEvent(const char* type, PROC dispatcher, void* data, bool obj) 37 | { 38 | typedef int (*F)(const char*, PROC, void*); 39 | F f = (F)GetProcAddress(getManagerModule(), obj ? "x3FireObjectEvent" : "x3FireEvent"); 40 | return f ? f(type, dispatcher, data) : 0; 41 | } 42 | 43 | } // x3 44 | #endif -------------------------------------------------------------------------------- /x3py/interface/core/observer/observerobject.h: -------------------------------------------------------------------------------- 1 | // x3py framework: https://github.com/rhcad/x3py 2 | #ifndef X3_CORE_OBSERVEROBJECT_H 3 | #define X3_CORE_OBSERVEROBJECT_H 4 | 5 | namespace x3 { 6 | 7 | class ObserverObject 8 | { 9 | public: 10 | virtual ~ObserverObject() {} 11 | }; 12 | 13 | typedef void (ObserverObject::*ON_EVENT)(); 14 | 15 | } // x3 16 | #endif -------------------------------------------------------------------------------- /x3py/interface/core/portability/pathstr.h: -------------------------------------------------------------------------------- 1 | /*! \file pathstr.h 2 | * \brief Included by portimpl.h to implement path functions. 3 | * \author Zhang Yungui, X3 C++ PluginFramework 4 | * \date 2011.5.23 5 | */ 6 | #ifndef X3_PORTABILITY_PATHSTR_IMPL_H 7 | #define X3_PORTABILITY_PATHSTR_IMPL_H 8 | 9 | static inline bool IsPathSlash(char c) 10 | { 11 | return '\\' == c || '/' == c; 12 | } 13 | 14 | char* PathFindFileNameA(const char* path) 15 | { 16 | const char* p1 = path ? strrchr(path, '\\') : NULL; 17 | const char* p2 = path ? strrchr(path, '/') : NULL; 18 | 19 | p1 = !p1 || (p2 && p2 > p1) ? p2 : p1; 20 | 21 | return const_cast(p1 ? p1 + 1 : path); 22 | } 23 | 24 | char* PathFindExtensionA(const char* path) 25 | { 26 | char* p = PathFindFileNameA(path); 27 | char* ext = p ? strrchr(p, '.') : p; 28 | return ext ? ext : p; 29 | } 30 | 31 | bool PathIsRelativeA(const char* path) 32 | { 33 | return path && strrchr(path, ':') == NULL && path[0] != '\\' && path[0] != '/'; 34 | } 35 | 36 | void PathStripPathA(char* path) 37 | { 38 | PathRemoveBackslashA(path); 39 | char* filename = PathFindFileNameA(path); 40 | 41 | if (filename && filename > path) 42 | { 43 | while (*filename) 44 | { 45 | *path++ = *filename++; 46 | } 47 | *path = *filename; 48 | } 49 | } 50 | 51 | void PathRemoveFileSpecA(char* path) 52 | { 53 | PathRemoveBackslashA(path); 54 | char* filename = PathFindFileNameA(path); 55 | 56 | if (filename && filename > path) 57 | { 58 | *(filename - 1) = 0; 59 | } 60 | } 61 | 62 | void PathRemoveExtensionA(char* path) 63 | { 64 | char* dot = path ? strrchr(path, '.') : NULL; 65 | 66 | if (dot) 67 | { 68 | *dot = 0; 69 | } 70 | } 71 | 72 | void PathRemoveBackslashA(char* path) 73 | { 74 | size_t len = path ? strlen(path) : 0; 75 | 76 | if (len > 0 && IsPathSlash(path[len - 1])) 77 | { 78 | path[len - 1] = 0; 79 | } 80 | } 81 | 82 | void PathAppendA(char* path, const char* more) 83 | { 84 | ASSERT(path && more); 85 | 86 | if (path[0] && '.' == more[0] && '.' == more[1]) 87 | { 88 | PathRemoveFileSpecA(path); 89 | PathAppendA(path, more[2] ? more + 3 : more + 2); 90 | return; 91 | } 92 | 93 | size_t len = strlen(path); 94 | 95 | if (len > 0 && !IsPathSlash(path[len - 1]) && *more) 96 | { 97 | strcat(path, "/"); 98 | } 99 | strcat(path, IsPathSlash(*more) ? more + 1 : more); 100 | } 101 | 102 | char* PathAddBackslashA(char* path) 103 | { 104 | size_t len = path ? strlen(path) : 0; 105 | 106 | if (len > 0 && !IsPathSlash(path[len - 1])) 107 | { 108 | strcat(path, "/"); 109 | } 110 | 111 | return path; 112 | } 113 | 114 | void PathRenameExtensionA(char* path, const char* more) 115 | { 116 | ASSERT(path && more); 117 | char* dot = strrchr(path, '.'); 118 | 119 | if (!dot) 120 | { 121 | dot = path + strlen(path); 122 | } 123 | strcpy(dot, more); 124 | } 125 | 126 | #endif -------------------------------------------------------------------------------- /x3py/interface/core/portability/portimpl.h: -------------------------------------------------------------------------------- 1 | // Implement portability functions. 2 | // This file has included by XModuleImpl.h and XComCreator.h 3 | 4 | #ifndef X3_PORTABILITY_IMPL_H 5 | #define X3_PORTABILITY_IMPL_H 6 | 7 | #include "x3port.h" 8 | 9 | #ifndef ASSERT 10 | #define ASSERT(expr) 11 | #define VERIFY(expr) expr 12 | #endif 13 | 14 | #ifndef _INC_SHLWAPI 15 | #include "pathstr.h" 16 | #endif 17 | 18 | #ifdef _WIN32 19 | #include "winimpl.h" 20 | #else 21 | #include "uniximpl.h" 22 | #endif 23 | 24 | #endif -------------------------------------------------------------------------------- /x3py/interface/core/portability/winimpl.h: -------------------------------------------------------------------------------- 1 | // Included by portimpl.h to implement functions on Windows. 2 | 3 | #ifndef X3WIN_PORTABILITY_IMPL_H 4 | #define X3WIN_PORTABILITY_IMPL_H 5 | 6 | #include "x3win.h" 7 | 8 | bool x3FreeLibrary(HMODULE hdll) 9 | { 10 | #ifdef __GNUC__ 11 | typedef void (*F)(); 12 | F f = (F)GetProcAddress(hdll, "x3FreePlugin"); 13 | if (f) f(); 14 | #endif 15 | return !!FreeLibrary(hdll); 16 | } 17 | 18 | HMODULE x3LoadLibrary(const char* filename) 19 | { 20 | HMODULE hdll = LoadLibraryExA(filename, NULL, LOAD_WITH_ALTERED_SEARCH_PATH); 21 | 22 | if( GetProcAddress(hdll, "DllMain")==nullptr ) 23 | { 24 | typedef bool (*F)(HMODULE, HMODULE); 25 | F f = (F)GetProcAddress(hdll, "x3InitPlugin"); 26 | 27 | if (f && !f(hdll, NULL)) 28 | { 29 | x3FreeLibrary(hdll); 30 | hdll = NULL; 31 | } 32 | } 33 | 34 | return hdll; 35 | } 36 | 37 | #endif 38 | -------------------------------------------------------------------------------- /x3py/interface/core/portability/x3port.h: -------------------------------------------------------------------------------- 1 | #ifndef X3_CORE_PORTABILITY_H 2 | #define X3_CORE_PORTABILITY_H 3 | 4 | #if defined(_WIN64) && !defined(_WIN32) 5 | #define _WIN32 6 | #endif 7 | 8 | #ifdef _WIN32 9 | #include "x3win.h" 10 | #else 11 | #include "x3unix.h" 12 | #endif 13 | 14 | #if !defined(_MSC_VER) || _MSC_VER < 1400 15 | #include "func_s.h" 16 | #endif 17 | 18 | HMODULE x3LoadLibrary(const char* filename); 19 | bool x3FreeLibrary(HMODULE hdll); 20 | 21 | #ifndef _INC_SHLWAPI 22 | char* PathFindFileNameA(const char* path); 23 | char* PathFindExtensionA(const char* path); 24 | bool PathIsRelativeA(const char* path); 25 | void PathStripPathA(char* path); 26 | void PathRemoveFileSpecA(char* path); 27 | void PathRemoveExtensionA(char* path); 28 | void PathRemoveBackslashA(char* path); 29 | void PathAppendA(char* path, const char* more); 30 | char* PathAddBackslashA(char* path); 31 | void PathRenameExtensionA(char* path, const char* more); 32 | #endif 33 | 34 | #endif -------------------------------------------------------------------------------- /x3py/interface/core/portability/x3unix.h: -------------------------------------------------------------------------------- 1 | // Included by X3Portability.h to declare functions on linux or macosx. 2 | 3 | #ifndef X3UNIX_PORTABILITY_H 4 | #define X3UNIX_PORTABILITY_H 5 | 6 | #include 7 | #include 8 | #include 9 | 10 | #define OUTAPI extern "C" __attribute__((visibility("default"))) 11 | #if defined(__APPLE__) 12 | #define LOCALAPI 13 | #else 14 | #define LOCALAPI __attribute__((visibility("hidden"))) 15 | #endif 16 | 17 | #ifndef MAX_PATH 18 | #define MAX_PATH 512 19 | #endif 20 | 21 | typedef void* HMODULE; 22 | typedef void* HANDLE; 23 | typedef void* HWND; 24 | typedef void* PROC; 25 | typedef unsigned char BYTE; 26 | typedef unsigned short WORD; 27 | typedef uint32_t DWORD; 28 | typedef unsigned long ULONG; 29 | 30 | long InterlockedIncrement(long* p); 31 | long InterlockedDecrement(long* p); 32 | long InterlockedExchange(long* p, long v); 33 | 34 | bool x3FreeLibrary(HMODULE hdll); 35 | HMODULE x3LoadLibrary(const char* filename); 36 | HMODULE GetModuleHandleA(const char* filename); 37 | PROC GetProcAddress(HMODULE hdll, const char* name); 38 | void GetModuleFileNameA(HMODULE hdll, char* filename, int size); 39 | DWORD GetLastError(); 40 | 41 | int WideCharToMultiByte(int codepage, DWORD flags, 42 | const wchar_t* wstr, int wchars, 43 | char* astr, int achars, 44 | const char* defaultChar, void*); 45 | int MultiByteToWideChar(int codepage, DWORD flags, 46 | const char* astr, int achars, 47 | wchar_t* wstr, int wchars); 48 | 49 | int _stricmp(const char* s1, const char* s2); 50 | int _strnicmp(const char* s1, const char* s2, int count); 51 | 52 | #endif 53 | -------------------------------------------------------------------------------- /x3py/interface/core/portability/x3win.h: -------------------------------------------------------------------------------- 1 | // Included by X3Portability.h to declare functions on Windows. 2 | 3 | #ifndef X3WIN_PORTABILITY_H 4 | #define X3WIN_PORTABILITY_H 5 | 6 | #if !defined(_MSC_VER) || _MSC_VER > 1200 // not VC6 7 | 8 | #ifndef WINVER 9 | #define WINVER 0x0501 // WinXP or later. 10 | #endif 11 | 12 | #ifndef _WIN32_WINNT 13 | #define _WIN32_WINNT WINVER 14 | #endif 15 | #ifndef _WIN32_WINDOWS 16 | #define _WIN32_WINDOWS WINVER 17 | #endif 18 | #ifndef _WIN32_IE 19 | #define _WIN32_IE 0x0600 // IE6 or later. 20 | #endif 21 | 22 | #endif // _MSC_VER 23 | 24 | #ifdef _AFXDLL 25 | #define VC_EXTRALEAN 26 | #define _ATL_CSTRING_EXPLICIT_CONSTRUCTORS 27 | #define _AFX_ALL_WARNINGS 28 | #include // MFC core and standard components 29 | #include // MFC extensions 30 | #ifndef _AFX_NO_OLE_SUPPORT 31 | #include // MFC Automation classes 32 | #endif 33 | #else 34 | #define _WIN32_LEAN_AND_MEAN // Exclude rarely-used stuff from Windows headers 35 | #include // Windows master include file 36 | #endif // _AFXDLL 37 | 38 | #ifdef _MSC_VER 39 | #include // Windows light-weight utility APIs 40 | #pragma comment(lib, "shlwapi.lib") 41 | #endif 42 | 43 | #ifdef __GNUC__ 44 | #define OUTAPI extern "C" __attribute__((dllexport)) 45 | #else 46 | #define OUTAPI extern "C" __declspec(dllexport) 47 | #endif 48 | #define LOCALAPI 49 | 50 | #endif -------------------------------------------------------------------------------- /x3py/interface/core/utilfunc/convstr.h: -------------------------------------------------------------------------------- 1 | // x3c - C++ PluginFramework 2 | //! \file convstr.h 3 | //! \brief Define functions to convert between UNICODE string and ANSI string. 4 | 5 | #ifndef UTILFUNC_CONVSTR_H_ 6 | #define UTILFUNC_CONVSTR_H_ 7 | 8 | #include 9 | #include 10 | 11 | #ifndef CP_UTF8 12 | #define CP_UTF8 65001 13 | #endif 14 | 15 | namespace x3 { 16 | 17 | //! Convert from UNICODE string to ANSI string, x3::w2a. 18 | /*! 19 | \ingroup _GROUP_UTILFUNC 20 | \param s The source UNICODE string to be converted. 21 | \param codepage Code page of the target ANSI string. For example CP_UTF8 is UTF-8 code. 22 | \return The target ANSI string. 23 | */ 24 | inline std::string w2a(const wchar_t* s, int codepage = 0) 25 | { 26 | std::string str; 27 | int wlen = (NULL == s) ? 0 : (int)wcslen(s); 28 | 29 | if (wlen > 0) 30 | { 31 | int len = WideCharToMultiByte(codepage, 0, s, wlen, NULL, 0, NULL, NULL); 32 | str.resize(len); 33 | WideCharToMultiByte(codepage, 0, s, wlen, 34 | const_cast(str.data()), len, NULL, NULL); 35 | } 36 | 37 | return str; 38 | } 39 | 40 | //! Convert from UNICODE string to ANSI string, x3::w2a. 41 | /*! 42 | \ingroup _GROUP_UTILFUNC 43 | \param s The source UNICODE string to be converted. 44 | \param codepage Code page of the target ANSI string. For example CP_UTF8 is UTF-8 code. 45 | \return The target ANSI string. 46 | */ 47 | inline std::string w2a(const std::wstring& s, int codepage = 0) 48 | { 49 | return w2a(s.c_str(), codepage); 50 | } 51 | 52 | //! Convert from ANSI string to UNICODE string, x3::a2w. 53 | /*! 54 | \ingroup _GROUP_UTILFUNC 55 | \param s The source ANSI string to be converted. 56 | \param codepage Code page of the source ANSI string. For example CP_UTF8 is UTF-8 code. 57 | \return UNICODE string 58 | */ 59 | inline std::wstring a2w(const char* s, int codepage = 0) 60 | { 61 | std::wstring wstr; 62 | int len = (NULL == s) ? 0 : (int)strlen(s); 63 | 64 | if (len > 0) 65 | { 66 | int wlen = MultiByteToWideChar(codepage, 0, s, len, NULL, 0); 67 | wstr.resize(wlen); 68 | MultiByteToWideChar(codepage, 0, s, len, 69 | const_cast(wstr.data()), wlen); 70 | } 71 | 72 | return wstr; 73 | } 74 | 75 | //! Convert from ANSI string to UNICODE string, x3::a2w. 76 | /*! 77 | \ingroup _GROUP_UTILFUNC 78 | \param s The source ANSI string to be converted. 79 | \param codepage Code page of the source ANSI string. For example CP_UTF8 is UTF-8 code. 80 | \return UNICODE string 81 | */ 82 | inline std::wstring a2w(const std::string& s, int codepage = 0) 83 | { 84 | return a2w(s.c_str(), codepage); 85 | } 86 | 87 | inline int compare(const std::string& str1, const std::string& str2, bool bCaseSensitive = true) 88 | { 89 | if (bCaseSensitive) 90 | return str1.compare(str2); 91 | else 92 | { 93 | std::string lowStr1 = str1; 94 | std::transform(lowStr1.begin(), lowStr1.end(), lowStr1.begin(), tolower); 95 | std::string lowStr2 = str2; 96 | std::transform(lowStr2.begin(), lowStr2.end(), lowStr2.begin(), tolower); 97 | return lowStr1.compare(lowStr2); 98 | } 99 | } 100 | 101 | inline int compare(const std::wstring& str1, const std::wstring& str2, bool bCaseSensitive = true) 102 | { 103 | if (bCaseSensitive) 104 | return str1.compare(str2); 105 | else 106 | { 107 | std::wstring lowStr1 = str1; 108 | std::transform(lowStr1.begin(), lowStr1.end(), lowStr1.begin(), tolower); 109 | std::wstring lowStr2 = str2; 110 | std::transform(lowStr2.begin(), lowStr2.end(), lowStr2.begin(), tolower); 111 | return lowStr1.compare(lowStr2); 112 | } 113 | } 114 | 115 | #ifdef _UNICODE 116 | inline std::wstring w2t(const wchar_t* s) { return s; } 117 | inline std::wstring w2t(const std::wstring& s) { return s; } 118 | inline std::wstring t2w(const wchar_t* s) { return s; } 119 | inline std::wstring a2t(const char* s) { return w2t(a2w(s)); } 120 | inline std::wstring a2t(const std::string& s) { return w2t(a2w(s)); } 121 | inline std::string t2a(const wchar_t* s) { return w2a(t2w(s)); } 122 | #else 123 | inline std::string w2t(const wchar_t* s) { return w2a(s); } 124 | inline std::string w2t(const std::wstring& s) { return w2a(s); } 125 | inline std::wstring t2w(const char* s) { return a2w(s); } 126 | inline std::string a2t(const char* s) { return std::string(s); } 127 | inline std::string a2t(const std::string& s) { return s; } 128 | inline std::string t2a(const char* s) { return std::string(s); } 129 | #endif 130 | 131 | } 132 | #endif // UTILFUNC_CONVSTR_H_ 133 | -------------------------------------------------------------------------------- /x3py/interface/core/utilfunc/loadmodule.h: -------------------------------------------------------------------------------- 1 | // x3py framework: https://github.com/rhcad/x3py 2 | #ifndef UTILFUNC_LOADDLLHELPER_H_ 3 | #define UTILFUNC_LOADDLLHELPER_H_ 4 | 5 | // If don't need plugininc.h or portability/*.h on Windows: 6 | #if !defined(X3_CORE_PORTABILITY_H) && !defined(x3FreeLibrary) && defined(_WIN32) 7 | #define x3FreeLibrary(h) FreeLibrary(h) 8 | #define x3LoadLibrary(f) LoadLibraryExA(f, NULL, LOAD_WITH_ALTERED_SEARCH_PATH) 9 | #endif 10 | 11 | namespace x3 { 12 | 13 | class LoadModuleHelper 14 | { 15 | public: 16 | LoadModuleHelper(const char* filename = NULL, 17 | HMODULE basemod = NULL, HMODULE* assign = NULL) 18 | : _hmod(NULL), _assign(assign), _loadnew(false) 19 | { 20 | if (filename) 21 | load(filename, basemod); 22 | } 23 | 24 | ~LoadModuleHelper() 25 | { 26 | unload(); 27 | } 28 | 29 | void unload() 30 | { 31 | if (_hmod) 32 | { 33 | if (_loadnew) 34 | x3FreeLibrary(_hmod); 35 | _hmod = NULL; 36 | 37 | if (_assign) 38 | *_assign = NULL; 39 | } 40 | } 41 | 42 | bool load(const char* filename, HMODULE basemod = NULL, const char* folder = "") 43 | { 44 | unload(); 45 | 46 | _hmod = GetModuleHandleA(PathFindFileNameA(filename)); 47 | _loadnew = !_hmod; 48 | 49 | if (!_hmod) 50 | { 51 | char fullname[MAX_PATH] = ""; 52 | 53 | if (PathIsRelativeA(filename)) 54 | { 55 | GetModuleFileNameA(basemod, fullname, MAX_PATH); 56 | PathRemoveFileSpecA(fullname); 57 | PathAppendA(fullname, folder); 58 | PathAppendA(fullname, filename); 59 | _hmod = x3LoadLibrary(fullname); 60 | } 61 | if (!_hmod) 62 | _hmod = x3LoadLibrary(filename); 63 | if (!_hmod) 64 | _hmod = x3LoadLibrary(PathFindFileNameA(filename)); 65 | } 66 | if (_assign) 67 | { 68 | *_assign = _hmod; 69 | } 70 | 71 | return _hmod != NULL; 72 | } 73 | 74 | HMODULE getModule() const 75 | { 76 | return _hmod; 77 | } 78 | 79 | PROC getFunc(const char* name) const 80 | { 81 | return _hmod ? GetProcAddress(_hmod, name) : NULL; 82 | } 83 | 84 | private: 85 | HMODULE _hmod; 86 | HMODULE* _assign; 87 | bool _loadnew; 88 | }; 89 | 90 | } // x3 91 | #endif -------------------------------------------------------------------------------- /x3py/interface/core/utilfunc/lockcount.h: -------------------------------------------------------------------------------- 1 | /*! \file lockcount.h 2 | * \brief Define helper class to auto increment and decrement: x3::LockCount 3 | * \author Zhang Yungui, X3 C++ PluginFramework 4 | * \date 2010.5.19 5 | */ 6 | #ifndef X3_UTILFUNC_LOCKCOUNT_H_ 7 | #define X3_UTILFUNC_LOCKCOUNT_H_ 8 | 9 | namespace x3 { 10 | 11 | //! Helper class to auto increment and decrement. 12 | /*! Use this to declare local variable in functions, 13 | then counter will be auto decreased (--counter;) when leave from the function. 14 | So you can check the counter with initial value to known some status. 15 | \ingroup _GROUP_UTILFUNC 16 | */ 17 | class LockCount 18 | { 19 | public: 20 | //! Auto add counter. 21 | /*! 22 | \param p address of counter, the initial value of counter is usually zero. 23 | */ 24 | LockCount(long* p) : m_count(p) 25 | { 26 | InterlockedIncrement(m_count); 27 | } 28 | 29 | //! Auto decrease counter. 30 | ~LockCount() 31 | { 32 | Unlock(); 33 | } 34 | 35 | //! Auto decrease counter. 36 | void Unlock() 37 | { 38 | if (m_count) 39 | { 40 | InterlockedDecrement(m_count); 41 | m_count = NULL; 42 | } 43 | } 44 | 45 | private: 46 | LockCount(const LockCount&); 47 | void operator=(const LockCount&); 48 | 49 | long* m_count; 50 | }; 51 | 52 | } // x3 53 | #endif -------------------------------------------------------------------------------- /x3py/interface/core/utilfunc/lockrw.h: -------------------------------------------------------------------------------- 1 | #ifndef X3_UTILFUNC_LOCKRW_H_ 2 | #define X3_UTILFUNC_LOCKRW_H_ 3 | 4 | namespace x3 { 5 | 6 | class LockRW 7 | { 8 | public: 9 | struct Data { 10 | long reader; 11 | long writter; 12 | Data() : reader(0), writter(0) {} 13 | }; 14 | 15 | LockRW(Data& data, bool forWrite = false) : _data(data), _type(0) 16 | { 17 | if (forWrite) 18 | { 19 | if (0 == _data.reader && 0 == _data.writter) 20 | { 21 | if (1 == InterlockedIncrement(&_data.writter)) 22 | _type = 2; 23 | else 24 | InterlockedDecrement(&_data.writter); 25 | } 26 | } 27 | if (0 == _type) 28 | { 29 | if (0 == _data.writter) 30 | { 31 | InterlockedIncrement(&_data.reader); 32 | if (0 == _data.writter) 33 | _type = 1; 34 | else 35 | InterlockedDecrement(&_data.reader); 36 | } 37 | } 38 | } 39 | 40 | ~LockRW() 41 | { 42 | free(); 43 | } 44 | 45 | void free() 46 | { 47 | if (1 == _type) 48 | InterlockedDecrement(&_data.reader); 49 | else if (2 == _type) 50 | InterlockedDecrement(&_data.writter); 51 | _type = 0; 52 | } 53 | 54 | bool canRead() const 55 | { 56 | return _type > 0; 57 | } 58 | 59 | bool canWrite() const 60 | { 61 | return 2 == _type; 62 | } 63 | 64 | private: 65 | LockRW(const LockRW&); 66 | LockRW& operator=(const LockRW&); 67 | 68 | Data& _data; 69 | int _type; 70 | }; 71 | 72 | template 73 | struct LockRW_ : public T { 74 | mutable LockRW::Data locker; 75 | }; 76 | 77 | } // x3 78 | #endif -------------------------------------------------------------------------------- /x3py/interface/core/utilfunc/readints.h: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/longhuan2018/CbersUI/85bfe9f16e0ff17361875461818006efc51d8d28/x3py/interface/core/utilfunc/readints.h -------------------------------------------------------------------------------- /x3py/interface/core/utilfunc/roundstr.h: -------------------------------------------------------------------------------- 1 | //! \file roundstr.h 2 | //! \brief Define the function converting and round float-pointing number to string: RoundStr 3 | 4 | #ifndef UTILFUNC_ROUNDSTR_H_ 5 | #define UTILFUNC_ROUNDSTR_H_ 6 | 7 | #include 8 | 9 | namespace x3 { 10 | 11 | //! Returns a numeric string, rounded to the specified precision. 12 | /*! 13 | \ingroup _GROUP_UTILFUNC 14 | \param value float-pointing number to be rounded. 15 | \param decimal a positive number thar value is rounded to the number of decimal places. 16 | \return a numeric string whose zero digits ('0') after number point will be removed. 17 | */ 18 | inline std::wstring RoundStr(double value, int decimal = 4) 19 | { 20 | wchar_t buf[65] = { 0 }; 21 | 22 | wchar_t fmt[] = L"%.2lf"; 23 | if (decimal < 1) decimal = 1; 24 | if (decimal > 5) decimal = 5; 25 | fmt[2] = (wchar_t)(L'0' + decimal); 26 | swprintf_s(buf, 65, fmt, value); 27 | 28 | wchar_t* p = wcschr(buf, L'.'); 29 | if (p != NULL) 30 | { 31 | int i = decimal; 32 | for (; i > 0 && p[i] == L'0'; i--) 33 | p[i] = 0; 34 | if (p[i] == L'.') 35 | p[i] = 0; 36 | } 37 | 38 | return buf; 39 | } 40 | 41 | } // x3 42 | #endif // UTILFUNC_ROUNDSTR_H_ 43 | -------------------------------------------------------------------------------- /x3py/interface/core/utilfunc/safecall.h: -------------------------------------------------------------------------------- 1 | //! \file safecall.h 2 | //! \brief Define functions to call pointer safely. 3 | 4 | #ifndef __APPCORE_SAFECALL_H 5 | #define __APPCORE_SAFECALL_H 6 | 7 | // Validate before call function of pointer, "v" is default return value 8 | #ifndef SafeCall 9 | #define SafeCall(p, f) if (p) p->f 10 | #define SafeCallIf(p, f, v) ((p) ? (p->f) : (v)) 11 | #define WndSafeCall(p, f) if (p && ::IsWindow(p->GetSafeHwnd())) p->f 12 | #endif // SafeCall 13 | 14 | namespace x3 { 15 | 16 | //! Delete pointer object. 17 | /*! 18 | \ingroup _GROUP_UTILFUNC 19 | \param p pointer object created using 'new'. 20 | */ 21 | template 22 | void SafeDelete(T*& p) 23 | { 24 | if (p != NULL) 25 | delete p; 26 | p = NULL; 27 | *(&p) = NULL; 28 | } 29 | 30 | //! Delete pointer array object. 31 | /*! 32 | \ingroup _GROUP_UTILFUNC 33 | \param p pointer array object created using 'new []'. 34 | */ 35 | template 36 | void SafeDeleteArray(T*& p) 37 | { 38 | if (p != NULL) 39 | delete []p; 40 | p = NULL; 41 | } 42 | 43 | //! Delete all elements in a container. 44 | /*! 45 | \ingroup _GROUP_UTILFUNC 46 | \param container STL container variable (vector, list, map). eg: " vector arr; " 47 | */ 48 | template 49 | void DeletePtrInContainer(CONTAINER& container) 50 | { 51 | typename CONTAINER::iterator it = container.begin(); 52 | for(; it != container.end(); ++it) 53 | SafeDelete(*it); 54 | container.resize(0); 55 | } 56 | 57 | } // x3 58 | #endif // __APPCORE_SAFECALL_H 59 | -------------------------------------------------------------------------------- /x3py/interface/core/utilfunc/scanfiles.h: -------------------------------------------------------------------------------- 1 | // x3py framework: https://github.com/rhcad/x3py 2 | #ifndef X3_UTILFUNC_SCANDIR_H 3 | #define X3_UTILFUNC_SCANDIR_H 4 | 5 | #ifndef _WIN32 6 | #include 7 | #include 8 | #include 9 | #endif 10 | 11 | namespace x3 { 12 | 13 | inline int scanfiles(bool (*filter)(const char* filename, const char* ext), 14 | const char* path, bool recursive) 15 | { 16 | int count = 0; 17 | char filename[MAX_PATH]; 18 | bool cancel = false; 19 | 20 | #ifdef _WIN32 21 | lstrcpynA(filename, path, MAX_PATH); 22 | PathAppendA(filename, "*.*"); 23 | 24 | WIN32_FIND_DATAA fd; 25 | HANDLE hfind = ::FindFirstFileA(filename, &fd); 26 | BOOL loop = (hfind != INVALID_HANDLE_VALUE); 27 | 28 | for (; loop && !cancel; loop = ::FindNextFileA(hfind, &fd)) 29 | { 30 | if (fd.dwFileAttributes & (FILE_ATTRIBUTE_HIDDEN | FILE_ATTRIBUTE_SYSTEM)) 31 | { 32 | } 33 | else if (fd.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY) 34 | { 35 | if (fd.cFileName[0] != '.') 36 | { 37 | lstrcpynA(filename, path, MAX_PATH); 38 | PathAppendA(filename, fd.cFileName); 39 | PathAddBackslashA(filename); 40 | 41 | cancel = !filter(filename, ""); 42 | if (recursive && !cancel) 43 | { 44 | count += scanfiles(filter, filename, recursive); 45 | } 46 | } 47 | } 48 | else 49 | { 50 | lstrcpynA(filename, path, MAX_PATH); 51 | PathAppendA(filename, fd.cFileName); 52 | cancel = !filter(filename, PathFindExtensionA(filename)); 53 | count++; 54 | } 55 | } 56 | 57 | ::FindClose(hfind); 58 | #else 59 | std::vector dirs; 60 | struct dirent *dp; 61 | DIR *dirp; 62 | 63 | dirp = opendir(path); 64 | if (dirp) 65 | { 66 | while (!cancel && (dp = readdir(dirp)) != NULL) 67 | { 68 | if (DT_DIR == dp->d_type && dp->d_name[0] != '.') 69 | { 70 | dirs.push_back(dp->d_name); 71 | } 72 | else if (DT_REG == dp->d_type) 73 | { 74 | strncpy(filename, path, MAX_PATH); 75 | PathAppendA(filename, dp->d_name); 76 | cancel = !filter(filename, ""); 77 | count++; 78 | } 79 | } 80 | closedir(dirp); 81 | } 82 | 83 | std::vector::const_iterator it = dirs.begin(); 84 | for (; it != dirs.end() && !cancel; ++it) 85 | { 86 | strncpy(filename, path, MAX_PATH); 87 | PathAppendA(filename, it->c_str()); 88 | PathAddBackslashA(filename); 89 | 90 | cancel = !filter(filename, PathFindExtensionA(filename)); 91 | if (recursive && !cancel) 92 | { 93 | count += scanfiles(filter, filename, recursive); 94 | } 95 | } 96 | #endif 97 | 98 | return count; 99 | } 100 | 101 | } // x3 102 | #endif -------------------------------------------------------------------------------- /x3py/interface/core/utilfunc/syserrstr.h: -------------------------------------------------------------------------------- 1 | //! \file syserrstr.h 2 | //! \brief Define a function to obtains error message strings: GetSystemErrorString. 3 | 4 | #ifndef UTILFUNC_SYSERRSTR_H_ 5 | #define UTILFUNC_SYSERRSTR_H_ 6 | 7 | #include 8 | 9 | namespace x3 { 10 | 11 | //! Obtains error message strings for a error code. 12 | /*! 13 | \ingroup _GROUP_UTILFUNC 14 | \param errorcode the error code returned by GetLastError or HRESULT value. 15 | \return error message strings. 16 | */ 17 | inline std::wstring GetSystemErrorString(unsigned long errorcode) 18 | { 19 | std::wstring retstr; 20 | wchar_t buf[21] = { 0 }; 21 | 22 | if (errorcode != 0) 23 | { 24 | #ifdef FormatMessage 25 | wchar_t* p = NULL; 26 | 27 | ::FormatMessageW(FORMAT_MESSAGE_ALLOCATE_BUFFER | FORMAT_MESSAGE_FROM_SYSTEM, 28 | NULL, errorcode, 29 | MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT), 30 | (wchar_t*)&p, 0, NULL); 31 | 32 | if (p != NULL) 33 | { 34 | retstr = p; 35 | ::LocalFree((HLOCAL)p); 36 | } 37 | #endif 38 | 39 | // define _NEED_STDIO before include PluginInc.h for vc6 or gcc. 40 | swprintf_s(buf, _countof(buf), L"[0x%x]", errorcode); 41 | retstr = buf + retstr; 42 | } 43 | 44 | return retstr; 45 | } 46 | 47 | } // x3 48 | #endif // UTILFUNC_SYSERRSTR_H_ 49 | -------------------------------------------------------------------------------- /x3py/interface/core/utilfunc/vecfunc.h: -------------------------------------------------------------------------------- 1 | //! \file vecfunc.h 2 | //! \brief Define functions of STL container and include frequently-used STL files. 3 | 4 | #ifndef __STL_VECTOR_FUNCTIONS_H 5 | #define __STL_VECTOR_FUNCTIONS_H 6 | 7 | #ifdef _MSC_VER // hide warnings 8 | #pragma warning(disable:4710) // inline function not expanded 9 | #pragma warning(disable:4786) // identifier was truncated 10 | #pragma warning (push, 3) 11 | #pragma warning(disable:4018) // signed/unsigned mismatch 12 | #pragma warning(disable:4702) // unreachable code 13 | #endif 14 | #include 15 | #include 16 | #include 17 | #include 18 | #include 19 | #include 20 | #include 21 | #include 22 | #ifdef _MSC_VER // hide warnings 23 | #pragma warning (pop) 24 | #endif 25 | 26 | namespace x3 { 27 | 28 | #ifdef __AFX_H__ 29 | //! Converts safely from CString variable to std::wstring, avoid null address problem. 30 | inline std::wstring towstr(const CString& str) 31 | { 32 | return str.IsEmpty() ? L"" : (LPCTSTR)str; 33 | } 34 | #endif 35 | 36 | //! Removes an element that match a condition expression in a container. 37 | /*! 38 | \ingroup _GROUP_UTILFUNC 39 | \param arr STL container variable (vector, list, map). eg: " vector arr; " 40 | \param _P The condition expression for matching elements. eg: " std::bind2nd(std::equal_to(), pObj) " 41 | \return the element is removed or not. 42 | \see erase_value, find_if 43 | */ 44 | template inline 45 | bool erase_if(_Ta& arr, _Pr _P) 46 | { 47 | typename _Ta::iterator it = std::find_if(arr.begin(), arr.end(), _P); 48 | bool b = (it != arr.end()); 49 | 50 | if (b) 51 | { 52 | arr.erase(it); 53 | } 54 | 55 | return b; 56 | }; 57 | 58 | //! Removes an element that match a element value in a container. 59 | /*! 60 | \ingroup _GROUP_UTILFUNC 61 | \param arr STL container variable (vector, list, map). eg: " vector arr; " 62 | \param p The element value for matching. It's type is same as the element type of 'arr'. eg: " Ix_xxx* pObj" 63 | \return the element is removed or not. 64 | \see erase_if, find_value 65 | */ 66 | template inline 67 | bool erase_value(_Ta& arr, _Tp& p) 68 | { 69 | return erase_if(arr, std::bind2nd(std::equal_to<_Tp>(), p)); 70 | } 71 | 72 | //! Finds the position index of an element that match a condition expression in a container. 73 | /*! 74 | \ingroup _GROUP_UTILFUNC 75 | \param arr STL vector variable. eg: " vector arr; " 76 | \param _P The condition expression for matching elements. eg: " std::bind2nd(std::equal_to(), pObj) " 77 | \return the position index of an element, or -1 if not found. 78 | \see find_value, has_value 79 | */ 80 | template inline 81 | long find_if(const _Ta& arr, _Pr _P) 82 | { 83 | typename _Ta::const_iterator it = std::find_if(arr.begin(), arr.end(), _P); 84 | return (it != arr.end()) ? (long)(it - arr.begin()) : -1; 85 | } 86 | 87 | //! Finds the position index of an element that match a element value in a container. 88 | /*! 89 | \ingroup _GROUP_UTILFUNC 90 | \param arr STL container variable (vector, list, map). eg: " vector arr; " 91 | \param p The element value for matching. It's type is same as the element type of 'arr'. eg: " Ix_xxx* pObj" 92 | \return the position index of an element, or -1 if not found. 93 | \see has_value, find_if 94 | */ 95 | template inline 96 | long find_value(const _Ta& arr, const _Tp& p) 97 | { 98 | return find_if(arr, std::bind2nd(std::equal_to<_Tp>(), p)); 99 | } 100 | 101 | //! Checks whether a container has an element that match a element value or not. 102 | /*! 103 | \ingroup _GROUP_UTILFUNC 104 | \param arr STL container variable (vector, list, map). eg: " vector arr; " 105 | \param p The element value for matching. It's type is same as the element type of 'arr'. eg: " Ix_xxx* pObj" 106 | \return true if the container has the element. 107 | \see find_value, find_if 108 | */ 109 | template inline 110 | bool has_value(const _Ta& arr, const _Tp& p) 111 | { 112 | typename _Ta::const_iterator it = std::find_if(arr.begin(), arr.end(), 113 | std::bind2nd(std::equal_to<_Tp>(), p)); 114 | return it != arr.end(); 115 | } 116 | 117 | //! Returns element count of a container. 118 | /*! 119 | \ingroup _GROUP_UTILFUNC 120 | \param arr STL container variable (vector, list, map). 121 | \return element count. 122 | */ 123 | template inline 124 | int GetSize(const _Ta& arr) 125 | { 126 | return static_cast(arr.size()); 127 | } 128 | 129 | //! Checks a position index is in range or out of range of a container. 130 | /*! 131 | \ingroup _GROUP_UTILFUNC 132 | \param arr STL vector variable. eg: " vector arr; " 133 | \param index The position index of the element. 134 | \return true if the position index is in range of the container. 135 | */ 136 | template inline 137 | bool IsValidIndexOf(const _Ta& arr, int index) 138 | { 139 | return index >= 0 && index < static_cast(arr.size()); 140 | } 141 | 142 | } // x3 143 | #endif // __STL_VECTOR_FUNCTIONS_H 144 | -------------------------------------------------------------------------------- /x3py/source/Makefile: -------------------------------------------------------------------------------- 1 | # Makefile of packages 2 | 3 | ROOTDIR =.. 4 | include $(ROOTDIR)/config.mk 5 | 6 | SUBDIRS =$(filter-out public, $(subst /,,$(dir $(wildcard */)))) 7 | SWIGSUBDIRS =$(addsuffix .swig, $(SUBDIRS)) 8 | CLEANSUBDIRS =$(addsuffix .clean, $(SUBDIRS)) 9 | 10 | .PHONY: $(SUBDIRS) $(SWIGSUBDIRS) swig 11 | all: $(SUBDIRS) 12 | 13 | $(SUBDIRS): 14 | @ ! test -e $@/Makefile || $(MAKE) -C $@ 15 | 16 | swig: $(SWIGSUBDIRS) 17 | 18 | $(SWIGSUBDIRS): 19 | @$(MAKE) -C $(basename $@) swig 20 | 21 | clean: $(CLEANSUBDIRS) 22 | ifdef touch 23 | touch -c * 24 | endif 25 | 26 | $(CLEANSUBDIRS): 27 | @!(test -e $(basename $@)/Makefile) || $(MAKE) -C $(basename $@) clean 28 | ifdef touch 29 | touch -c $(basename $@)/* 30 | endif 31 | -------------------------------------------------------------------------------- /x3py/source/core/Makefile: -------------------------------------------------------------------------------- 1 | # Makefile of projects in this package 2 | 3 | ROOTDIR =../.. 4 | include $(ROOTDIR)/config.mk 5 | 6 | SUBDIRS =$(filter-out public, $(subst /,,$(dir $(wildcard */)))) 7 | SWIGSUBDIRS =$(addsuffix .swig, $(SUBDIRS)) 8 | CLEANSUBDIRS =$(addsuffix .clean, $(SUBDIRS)) 9 | 10 | .PHONY: $(SUBDIRS) $(SWIGSUBDIRS) swig 11 | all: $(SUBDIRS) 12 | 13 | $(SUBDIRS): 14 | @echo --Making project $@... 15 | @ ! test -e $@/Makefile || $(MAKE) -C $@ 16 | 17 | swig: $(SWIGSUBDIRS) 18 | 19 | $(SWIGSUBDIRS): 20 | @!(test -d $(basename $@)/swig) || $(MAKE) -C $(basename $@)/swig swig 21 | @!(test -e $(basename $@)/$(basename $@).i) || $(MAKE) -C $(basename $@) swig 22 | 23 | clean: $(CLEANSUBDIRS) 24 | 25 | $(CLEANSUBDIRS): 26 | @!(test -e $(basename $@)/Makefile) || $(MAKE) -C $(basename $@) clean 27 | @!(test -d $(basename $@)/swig) || $(MAKE) -C $(basename $@)/swig clean 28 | -------------------------------------------------------------------------------- /x3py/source/core/x3manager/Makefile: -------------------------------------------------------------------------------- 1 | ROOTDIR =../../.. 2 | PROJNAME =x3manager 3 | 4 | include $(ROOTDIR)/config.mk 5 | 6 | ifdef IS_WIN 7 | LIBS += $(LIBFLAG)ole32$(LIBEND) 8 | endif 9 | 10 | include $(SRCPUB_DIR)/mk/Makefile.pln 11 | -------------------------------------------------------------------------------- /x3py/source/core/x3manager/plugins.h: -------------------------------------------------------------------------------- 1 | // x3py framework: https://github.com/rhcad/x3py 2 | #ifndef X3_CORE_PLUGINS_IMPL_H 3 | #define X3_CORE_PLUGINS_IMPL_H 4 | 5 | #include 6 | #include 7 | #include 8 | #include 9 | #include 10 | 11 | #if !defined(_MSC_VER) || _MSC_VER >= 1700 12 | #include 13 | #define hash_multimap std::unordered_multimap 14 | #else 15 | #if defined(_MSC_VER) && _MSC_VER > 1200 // VC8/9 16 | #include 17 | using stdext::hash_multimap; 18 | #else // VC6, GCC or others 19 | #define hash_multimap std::multimap 20 | #endif 21 | #endif 22 | 23 | #define USE_VECTOR_CLSID 24 | 25 | BEGIN_NAMESPACE_X3 26 | 27 | typedef bool (*EventDispatcher)(PROC handler, void* data); 28 | typedef bool (*ObjectEventDispatcher)(ObserverObject*, ON_EVENT, void* data); 29 | typedef bool (*Creator)(const char*, long, IObject**); 30 | 31 | class IRegister : public IObject 32 | { 33 | X3DEFINE_IID(IRegister); 34 | virtual bool registerPlugin(Creator creator, HMODULE hmod, const char** clsids) = 0; 35 | virtual void unregisterPlugin(Creator creator) = 0; 36 | virtual bool createFromOthers(const char* clsid, long iid, IObject** p) = 0; 37 | virtual HMODULE findModuleByFileName(const char* filename) = 0; 38 | 39 | virtual bool registerObserver(const char* type, PROC handler, Creator creator) = 0; 40 | virtual bool registerObserver(const char* type, ObserverObject* obj, 41 | ON_EVENT handler, Creator creator) = 0; 42 | virtual void unregisterObserver(ObserverObject* obj) = 0; 43 | virtual int fireEvent(const char* type, EventDispatcher dispatcher, void* data) = 0; 44 | virtual int fireEvent(const char* type, ObjectEventDispatcher dispatcher, void* data) = 0; 45 | }; 46 | 47 | class CPlugins : public IPlugins 48 | , public IRegister 49 | { 50 | X3BEGIN_CLASS_DECLARE0(CPlugins) 51 | X3DEFINE_INTERFACE_ENTRY(IPlugins) 52 | X3DEFINE_INTERFACE_ENTRY(IRegister) 53 | X3END_CLASS_DECLARE() 54 | protected: 55 | CPlugins(); 56 | virtual ~CPlugins(); 57 | 58 | private: 59 | virtual bool registerPlugin(Creator creator, HMODULE hmod, const char** clsids); 60 | virtual void unregisterPlugin(Creator creator); 61 | virtual bool createFromOthers(const char* clsid, long iid, IObject** p); 62 | virtual HMODULE findModuleByFileName(const char* filename); 63 | 64 | virtual bool registerObserver(const char* type, PROC handler, Creator creator); 65 | virtual bool registerObserver(const char* type, ObserverObject* obj, 66 | ON_EVENT handler, Creator creator); 67 | virtual void unregisterObserver(ObserverObject* obj); 68 | virtual int fireEvent(const char* type, EventDispatcher dispatcher, void* data); 69 | virtual int fireEvent(const char* type, ObjectEventDispatcher dispatcher, void* data); 70 | 71 | virtual int getPluginCount() const; 72 | virtual void getPluginFiles(std::vector& files) const; 73 | virtual Creator findPluginByClassID(const char* clsid) const; 74 | 75 | virtual int getCLSIDCount() const; 76 | virtual const char* getCLSID(int index); 77 | 78 | private: 79 | typedef std::pair Plugin; 80 | typedef hash_multimap CreatorMap; 81 | typedef std::pair CreatorPair; 82 | LockRW_ > _plugins; 83 | LockRW_ _clsmap; 84 | #ifdef USE_VECTOR_CLSID 85 | std::vector _clsids; 86 | #endif 87 | 88 | struct ObserverItem { 89 | Creator creator; 90 | PROC handler; 91 | ObserverObject* obj; 92 | ON_EVENT objhandler; 93 | 94 | ObserverItem() : creator(NULL), handler(NULL), obj(NULL), objhandler(NULL) {} 95 | }; 96 | typedef hash_multimap ObserverMap; 97 | typedef std::pair ObserverPair; 98 | typedef ObserverMap::iterator MAP_IT; 99 | 100 | LockRW_ _observers; 101 | }; 102 | 103 | END_NAMESPACE_X3 104 | #endif 105 | -------------------------------------------------------------------------------- /x3py/source/core/x3manager/swig/Makefile: -------------------------------------------------------------------------------- 1 | ROOTDIR =../../../.. 2 | PKGNAME =core 3 | PROJNAME =x3manager 4 | 5 | include $(ROOTDIR)/config.mk 6 | include $(SRCPUB_DIR)/swig/Makefile.swig 7 | -------------------------------------------------------------------------------- /x3py/source/core/x3manager/swig/testx3manager.py: -------------------------------------------------------------------------------- 1 | # This example illustrates how multiple C++ plugins can be used from Python. 2 | 3 | from core.x3manager import * 4 | import example.plsimple as A 5 | import example.observerex as B 6 | 7 | a = Plugins("") 8 | if not a.valid(): print("The x3manager plugins is not loaded.") 9 | 10 | print("plugin count: %d" % a.getPluginCount()) 11 | 12 | files = Strings() 13 | a.getPluginFiles(files) 14 | for i,f in enumerate(files): print(" %d. %s" % (i+1,f)) 15 | 16 | print("x3manager.Plugins: %s of %s" % (a.getInterfaceName(), a.getClassName())) 17 | 18 | b = A.Simple(A.clsidSimple) 19 | print("Simple(clsidSimple) ok." if b.valid() else "Simple(clsidSimple) fail.") 20 | if b.valid(): 21 | print("Simple(clsidSimple) ok.") 22 | print("clsidSimple: %s of %s" % (a.getInterfaceName(), a.getClassName())) 23 | 24 | c = AnyObject(b.p()) 25 | if c.valid(): 26 | print("AnyObject(anotherobj.p()) ok.") 27 | print("AnyObject: iid=%d, clsid=%s" % (c.getIID(), c.getClassID())) 28 | 29 | print("---loadExtraPlugins---") 30 | p = Plugins("") 31 | print("plugins loaded: %d" % p.loadExtraPlugins("plugins")) 32 | print("plugin count: %d" % p.getPluginCount()) 33 | p.getPluginFiles(files) 34 | for i,f in enumerate(files): print(" %d. %s" % (i+1,f)) 35 | print("plugins unloaded: %d" % p.unloadExtraPlugins()) 36 | #print(list(files)) 37 | -------------------------------------------------------------------------------- /x3py/source/core/x3manager/swig/x3manager.i: -------------------------------------------------------------------------------- 1 | %module x3manager 2 | %{ 3 | #ifndef PLUGIN_NAME 4 | #define PLUGIN_NAME "x3manager" 5 | #endif 6 | %} 7 | %include 8 | 9 | %{ 10 | #include 11 | %} 12 | 13 | %include std_vector.i 14 | %include std_string.i 15 | %template(Strings) std::vector; 16 | 17 | %include 18 | %template(Plugins) x3::Object; 19 | 20 | %include 21 | -------------------------------------------------------------------------------- /x3py/source/core/x3manager/workpath.cpp: -------------------------------------------------------------------------------- 1 | // x3py framework: https://github.com/rhcad/x3py 2 | #include 3 | #include "workpath.h" 4 | #include 5 | 6 | #ifdef WINOLEAPI_ 7 | #pragma comment(lib, "Ole32.lib") 8 | #endif 9 | 10 | BEGIN_NAMESPACE_X3 11 | 12 | static inline void GetBasePath(char* path) 13 | { 14 | GetModuleFileNameA(getModuleHandle(), path, MAX_PATH); 15 | PathRemoveFileSpecA(path); 16 | if (_stricmp("plugins", PathFindFileNameA(path)) == 0) 17 | PathRemoveFileSpecA(path); 18 | } 19 | 20 | std::wstring CWorkPath::getWorkPath() 21 | { 22 | if (m_path.empty()) 23 | { 24 | /*if (isVistaDisk()) 25 | { 26 | m_path = getLocalAppDataPath(L"x3"); 27 | } 28 | else*/ 29 | { 30 | char path[MAX_PATH] = { 0 }; 31 | GetBasePath(path); 32 | PathAddBackslashA(path); 33 | m_path = a2w(path); 34 | } 35 | } 36 | return m_path; 37 | } 38 | 39 | void CWorkPath::setWorkPath(const std::wstring& path) 40 | { 41 | m_path = path; 42 | if (path.size() > 2 43 | && *path.rbegin() != L'/' && *path.rbegin() != L'\\') 44 | { 45 | m_path += L'\\'; 46 | } 47 | } 48 | 49 | std::wstring CWorkPath::getConfigPath(const wchar_t* subfolder) 50 | { 51 | char path[MAX_PATH] = { 0 }; 52 | 53 | GetBasePath(path); 54 | PathAppendA(path, "config"); 55 | if (subfolder && *subfolder) 56 | PathAppendA(path, w2a(subfolder).c_str()); 57 | PathAddBackslashA(path); 58 | 59 | return a2w(path); 60 | } 61 | 62 | std::wstring CWorkPath::getLocalAppDataPath(const wchar_t* company) 63 | { 64 | char path[MAX_PATH] = { 0 }; 65 | 66 | if (getLocalAppDataPath_(path)) 67 | { 68 | char appname[MAX_PATH]; 69 | GetModuleFileNameA(NULL, appname, MAX_PATH); 70 | 71 | if (company) 72 | PathAppendA(path, w2a(company).c_str()); 73 | PathAppendA(path, PathFindFileNameA(appname)); 74 | PathRenameExtensionA(path, ""); 75 | PathAddBackslashA(path); 76 | } 77 | else 78 | { 79 | GetBasePath(path); 80 | PathAddBackslashA(path); 81 | } 82 | 83 | return a2w(path); 84 | } 85 | 86 | std::wstring CWorkPath::getTranslationsPath(const wchar_t* subfolder) 87 | { 88 | char code[4] = "chs"; 89 | char path[MAX_PATH] = { 0 }; 90 | 91 | #ifdef _WIN32 92 | typedef LANGID (WINAPI*PFNGETUSERDEFAULTUILANGUAGE)(); 93 | PFNGETUSERDEFAULTUILANGUAGE pfnGetLang; 94 | 95 | pfnGetLang = (PFNGETUSERDEFAULTUILANGUAGE)::GetProcAddress( 96 | ::GetModuleHandleA("kernel32.dll"), "GetUserDefaultUILanguage"); 97 | if (pfnGetLang != NULL) 98 | { 99 | LANGID langid = pfnGetLang(); 100 | ::GetLocaleInfoA(langid, LOCALE_SABBREVLANGNAME, code, 4); 101 | } 102 | #endif 103 | 104 | GetBasePath(path); 105 | PathAppendA(path, "translations"); 106 | PathAppendA(path, code); 107 | PathAddBackslashA(path); 108 | if (subfolder && *subfolder) 109 | PathAppendA(path, w2a(subfolder).c_str()); 110 | 111 | return a2w(path); 112 | } 113 | 114 | bool CWorkPath::isVistaDisk() 115 | { 116 | bool ret = false; 117 | #ifdef WINOLEAPI_ 118 | OSVERSIONINFO osvi = { sizeof(OSVERSIONINFO) }; 119 | char winpath[MAX_PATH], exepath[MAX_PATH]; 120 | 121 | if (GetVersionEx(&osvi) && osvi.dwMajorVersion >= 6) 122 | { 123 | GetSystemDirectoryA(winpath, MAX_PATH); 124 | GetModuleFileNameA(getModuleHandle(), exepath, MAX_PATH); 125 | ret = (_strnicmp(winpath, exepath, 2) == 0); 126 | } 127 | #endif 128 | return ret; 129 | } 130 | 131 | bool CWorkPath::getLocalAppDataPath_(char* path) 132 | { 133 | bool ret = false; 134 | #ifdef WINOLEAPI_ 135 | // FOLDERID_LocalAppDataGUID {F1B32785-6FBA-4FCF-9D55-7B8E7F157091} 136 | const GUID uuidLocalAppData = {0xF1B32785,0x6FBA,0x4FCF, 137 | {0x9D,0x55,0x7B,0x8E,0x7F,0x15,0x70,0x91}}; 138 | 139 | typedef HRESULT (STDAPICALLTYPE *PFNGET)(REFGUID, DWORD, HANDLE, PWSTR*); 140 | HMODULE hdll = LoadLibraryA("SHELL32.DLL"); 141 | 142 | if (hdll != NULL) 143 | { 144 | PWSTR shpath = NULL; 145 | PFNGET pfn = (PFNGET)GetProcAddress(hdll, "SHGetKnownFolderPath"); 146 | 147 | if (pfn != NULL) 148 | { 149 | pfn(uuidLocalAppData, 0, NULL, &shpath); 150 | } 151 | if (shpath != NULL) 152 | { 153 | strcpy_s(path, MAX_PATH, w2a(shpath).c_str()); 154 | ret = (*path != 0); 155 | CoTaskMemFree(shpath); 156 | } 157 | FreeLibrary(hdll); 158 | } 159 | #endif 160 | return ret; 161 | } 162 | 163 | END_NAMESPACE_X3 164 | -------------------------------------------------------------------------------- /x3py/source/core/x3manager/workpath.h: -------------------------------------------------------------------------------- 1 | // x3py framework: https://github.com/rhcad/x3py 2 | #ifndef X3_CORE_WORKPATH_IMPL_H 3 | #define X3_CORE_WORKPATH_IMPL_H 4 | 5 | #include 6 | #include 7 | 8 | BEGIN_NAMESPACE_X3 9 | 10 | class CWorkPath : public IAppWorkPath 11 | { 12 | X3BEGIN_CLASS_DECLARE0(CWorkPath) 13 | X3DEFINE_INTERFACE_ENTRY(IAppWorkPath) 14 | X3END_CLASS_DECLARE() 15 | protected: 16 | CWorkPath() {} 17 | 18 | private: 19 | virtual std::wstring getWorkPath(); 20 | virtual void setWorkPath(const std::wstring&); 21 | virtual std::wstring getLocalAppDataPath(const wchar_t*); 22 | virtual std::wstring getTranslationsPath(const wchar_t*); 23 | virtual std::wstring getConfigPath(const wchar_t*); 24 | 25 | private: 26 | bool isVistaDisk(); 27 | bool getLocalAppDataPath_(char*); 28 | 29 | std::wstring m_path; 30 | }; 31 | 32 | END_NAMESPACE_X3 33 | #endif -------------------------------------------------------------------------------- /x3py/source/public/mk/Makefile.libp: -------------------------------------------------------------------------------- 1 | # Included by Makefile of static library project. 2 | # x3py framework: https://github.com/rhcad/x3py 3 | 4 | TARGET =$(PLUGINS_DIR)/$(PROJNAME)$(LIBEXT) 5 | SOURCES =$(wildcard *.cpp) 6 | OBJS =$(SOURCES:.cpp=$(OBJEXT)) 7 | 8 | all: $(TARGET) 9 | $(TARGET): $(OBJS) 10 | $(AR) $(ARFLAGS)$@ $(OBJS) 11 | 12 | %.d: %.cpp 13 | $(DEPEND_CC) $@ $(INCLUDES) $< 14 | %$(OBJEXT): %.cpp 15 | $(CPP) $(CPPFLAGS) $(INCLUDES) -c $< 16 | 17 | ifndef clean 18 | include $(SOURCES:.cpp=.d) 19 | endif 20 | 21 | clean: 22 | ifndef SWIG_TYPE 23 | rm -rf *.d *.o *.obj 24 | ifdef cleanall 25 | rm -rf $(TARGET) 26 | endif 27 | ifdef touch 28 | touch -c * 29 | endif 30 | endif 31 | -------------------------------------------------------------------------------- /x3py/source/public/mk/Makefile.pln: -------------------------------------------------------------------------------- 1 | # Included by Makefile of plugin project. 2 | # x3py framework: https://github.com/rhcad/x3py 3 | 4 | ifdef APPTYPE 5 | TARGET =$(INSTALL_DIR)/$(PROJNAME)$(APPEXT) 6 | else 7 | TARGET =$(PLUGINS_DIR)/$(PROJNAME).pln 8 | endif 9 | SOURCES =$(wildcard *.cpp) 10 | OBJS =$(SOURCES:.cpp=$(OBJEXT)) 11 | 12 | ifdef VCBIN 13 | RCFILES =$(wildcard *.rc) 14 | RESFILES =$(RCFILES:.rc=.res) 15 | endif 16 | 17 | all: $(TARGET) 18 | $(TARGET): $(OBJS) $(RESFILES) 19 | $(LINK) $(LDFLAGS) $(OUTFLAG)$@ $(OBJS) $(LIBS) $(RESFILES) 20 | 21 | %.d: %.cpp 22 | $(DEPEND_CC) $@ $(INCLUDES) $< 23 | %$(OBJEXT): %.cpp 24 | $(CPP) $(CPPFLAGS) $(INCLUDES) -c $< 25 | %.res: %.rc 26 | "$(WINSDKBIN)rc" -Fo$@ $(INCLUDES) $(WINSDKINC) $< 27 | 28 | ifndef clean 29 | include $(SOURCES:.cpp=.d) 30 | endif 31 | 32 | clean: 33 | ifndef SWIG_TYPE 34 | rm -rf *.d *.o *.obj *_wrap.* ._* *.res 35 | ifdef cleanall 36 | rm -rf $(TARGET) 37 | endif 38 | ifdef touch 39 | touch -c * 40 | endif 41 | endif 42 | -------------------------------------------------------------------------------- /x3py/source/public/mk/Makefile.qt4: -------------------------------------------------------------------------------- 1 | # Included by Makefile of QT project. 2 | # x3py framework: https://github.com/rhcad/x3py 3 | 4 | ifdef APPTYPE 5 | TARGET =$(INSTALL_DIR)/$(PROJNAME)$(APPEXT) 6 | else 7 | TARGET =$(PLUGINS_DIR)/$(PROJNAME).pln 8 | endif 9 | OBJDIR =._qt 10 | SOURCES =$(wildcard *.cpp) 11 | OBJS =$(addprefix $(OBJDIR)/, $(SOURCES:.cpp=$(OBJEXT))) 12 | 13 | ifndef QT4_INCLUDE 14 | ifdef QTDIR 15 | QT4_INCLUDE =$(QTDIR)/include 16 | QT4_LIB =$(QTDIR)/lib 17 | QT4_BIN =$(QTDIR)/bin/ 18 | endif 19 | endif 20 | 21 | ifdef QT4_INCLUDE 22 | 23 | INCLUDES += -I"$(QT4_INCLUDE)" \ 24 | -I"$(QT4_INCLUDE)/QtCore" \ 25 | -I"$(QT4_INCLUDE)/QtGui" \ 26 | -I"$(QT4_INCLUDE)/QtWidgets" \ 27 | -I"$(QT4_INCLUDE)/qtmain" \ 28 | -I"$(OBJDIR)" \ 29 | -DQT_CORE_LIB -DQT_GUI_LIB 30 | 31 | ifdef VCBIN 32 | RCFILES =$(wildcard *.rc) 33 | RESFILES =$(addprefix $(OBJDIR)/, $(RCFILES:.rc=.res)) 34 | endif 35 | 36 | ifdef IS_WIN 37 | QTLIB_EXT =4$(LIBEND) 38 | else 39 | QTLIB_EXT =$(LIBEND) 40 | endif 41 | 42 | ifdef IS_MACOSX 43 | LIBS += -F$(QT4_LIB) \ 44 | -framework QtCore \ 45 | -framework QtGui \ 46 | -framework QtWidgets \ 47 | -Wl,-rpath,$(QT4_LIB) 48 | else 49 | LIBS += $(LIBPATHFLAG)"$(QT4_LIB)" \ 50 | $(LIBFLAG)QtCore$(QTLIB_EXT) \ 51 | $(LIBFLAG)QtGui$(QTLIB_EXT) 52 | endif 53 | ifdef IS_WIN 54 | LIBS += $(LIBFLAG)qtmain$(LIBEND) 55 | endif 56 | 57 | UIFILES =$(wildcard *.ui) 58 | UIHFILES =$(addprefix $(OBJDIR)/ui_, $(UIFILES:.ui=.h)) 59 | QRCFILES =$(wildcard *.qrc) 60 | QRCCPPS =$(addprefix $(OBJDIR)/qrc_, $(QRCFILES:.qrc=.cpp)) 61 | 62 | all: $(TARGET) 63 | $(TARGET): $(OBJS) $(RESFILES) 64 | $(LINK) $(LDFLAGS) $(OUTFLAG)$@ $(OBJS) $(LIBS) $(RESFILES) 65 | 66 | %.d: %.cpp 67 | $(DEPEND_CC) $@ $(INCLUDES) $< 68 | 69 | $(OBJDIR)/%$(OBJEXT): %.cpp 70 | -@test -d $(OBJDIR) || mkdir $(OBJDIR) 71 | $(CPP) $(CPPFLAGS) $(INCLUDES) $(OFLAG)$@ -c $< 72 | 73 | $(MOCS:.h=.d): %.d: %.cpp $(OBJDIR)/moc_%.cpp $(UIHFILES) $(QRCCPPS) 74 | $(DEPEND_CC) $@ $(INCLUDES) $< 75 | 76 | $(OBJDIR)/ui_%.h: %.ui 77 | -@test -d $(OBJDIR) || mkdir $(OBJDIR) 78 | "$(QT4_BIN)uic" -o $@ $< 79 | 80 | $(OBJDIR)/qrc_%.cpp: %.qrc 81 | -@test -d $(OBJDIR) || mkdir $(OBJDIR) 82 | "$(QT4_BIN)rcc" -name $(basename $<) -no-compress $< -o $@ 83 | 84 | $(OBJDIR)/moc_%.cpp: %.h 85 | -@test -d $(OBJDIR) || mkdir $(OBJDIR) 86 | "$(QT4_BIN)moc" $< -o $@ $(INCLUDES) 87 | 88 | $(OBJDIR)/%.res: %.rc 89 | -@test -d $(OBJDIR) || mkdir $(OBJDIR) 90 | "$(WINSDKBIN)rc" -Fo$@ $(INCLUDES) $(WINSDKINC) $< 91 | 92 | ifndef clean 93 | include $(SOURCES:.cpp=.d) 94 | endif 95 | 96 | else 97 | all: 98 | @echo QT4_INCLUDE not defined. 99 | endif #QT4_INCLUDE 100 | 101 | clean: 102 | ifndef SWIG_TYPE 103 | rm -rf *.d *.o *.obj *_wrap.* ._* 104 | ifdef cleanall 105 | rm -rf $(TARGET) 106 | endif 107 | ifdef touch 108 | touch -c * 109 | endif 110 | endif 111 | -------------------------------------------------------------------------------- /x3py/source/public/swig/Makefile.plswig: -------------------------------------------------------------------------------- 1 | # Included by Makefile of plugin project integrated with swig. 2 | # x3py framework: https://github.com/rhcad/x3py 3 | 4 | ifndef SWIG_TYPE 5 | include $(SRCPUB_DIR)/mk/Makefile.pln 6 | else 7 | 8 | SOURCES =$(wildcard *.cpp) 9 | OBJDIR =._$(SWIG_TYPE)o/ 10 | OBJS =$(addprefix $(OBJDIR), $(SOURCES:.cpp=$(OBJEXT))) 11 | CPPFLAGS += -DPLUGIN_SWIG 12 | 13 | include $(SRCPUB_DIR)/swig/Makefile.swig 14 | 15 | %.d: %.cpp 16 | $(DEPEND_CC) $@ $(INCLUDES) $< 17 | $(OBJDIR)%$(OBJEXT): %.cpp 18 | -@test -d $(OBJDIR) || mkdir $(OBJDIR) 19 | $(CPP) $(CPPFLAGS) $(INCLUDES) -c $< $(OFLAG)$@ 20 | 21 | ifndef clean 22 | include $(SOURCES:.cpp=.d) 23 | endif 24 | 25 | endif #SWIG_TYPE 26 | -------------------------------------------------------------------------------- /x3py/source/public/swig/observer.i: -------------------------------------------------------------------------------- 1 | /* observer.i: included by swig projects which use eventobserver.h .*/ 2 | #ifndef X3_OBSERVER_PLUGIN_SWIGI 3 | #define X3_OBSERVER_PLUGIN_SWIGI 4 | 5 | %{ 6 | #ifndef PLUGIN_NAME 7 | #define PLUGIN_NAME "x3manager" 8 | #endif 9 | %} 10 | %include 11 | 12 | %{ 13 | #ifndef PLUGIN_SWIG 14 | #include 15 | #endif 16 | %} 17 | 18 | %include 19 | 20 | #endif 21 | -------------------------------------------------------------------------------- /x3py/source/public/swig/plugin.i: -------------------------------------------------------------------------------- 1 | /* plugin.i: included by swig projects. 2 | Define PLUGIN_NAME before include this file to auto load internal plugin. 3 | */ 4 | #ifndef X3_PLUGIN_SWIGI 5 | #define X3_PLUGIN_SWIGI 6 | 7 | %{ 8 | #include 9 | 10 | #ifdef PLUGIN_SWIG // pluginimpl.h has been included 11 | #undef PLUGIN_NAME 12 | #define PLUGIN_NAME "x3manager" 13 | #define X3_EXCLUDE_CREATEOBJECT 14 | #endif 15 | #include // load PLUGIN_NAME.pln when not use useplugins.h 16 | 17 | #define X3THROW_NULLPOINTERERROR(name) \ 18 | printf("NullPointerError occurs, interface name: %s\n", name); \ 19 | throw x3::NullPointerError() 20 | #include 21 | %} 22 | 23 | %include 24 | %include 25 | 26 | %template(AnyObject) x3::Object; 27 | 28 | #endif 29 | -------------------------------------------------------------------------------- /x3py/x3py.pro: -------------------------------------------------------------------------------- 1 | #------------------------------------------------- 2 | # 3 | # Project created by QtCreator 2018-01-04T12:31:26 4 | # 5 | #------------------------------------------------- 6 | 7 | QT -= gui 8 | 9 | CONFIG += c++11 10 | 11 | TARGET = x3manager 12 | TEMPLATE = lib 13 | TARGET_EXT = .pln 14 | 15 | DEFINES += X3PY_LIBRARY 16 | 17 | # The following define makes your compiler emit warnings if you use 18 | # any feature of Qt which as been marked as deprecated (the exact warnings 19 | # depend on your compiler). Please consult the documentation of the 20 | # deprecated API in order to know how to port your code away from it. 21 | DEFINES += QT_DEPRECATED_WARNINGS 22 | 23 | # You can also make your code fail to compile if you use deprecated APIs. 24 | # In order to do so, uncomment the following line. 25 | # You can also select to disable deprecated APIs only up to a certain version of Qt. 26 | #DEFINES += QT_DISABLE_DEPRECATED_BEFORE=0x060000 # disables all the APIs deprecated before Qt 6.0.0 27 | 28 | SOURCES += \ 29 | source/core/x3manager/module.cpp \ 30 | source/core/x3manager/plugins.cpp \ 31 | source/core/x3manager/workpath.cpp 32 | 33 | HEADERS +=\ 34 | interface/core/manager/iplugins.h \ 35 | interface/core/manager/iworkpath.h \ 36 | interface/core/manager/x3manager.h \ 37 | interface/core/module/classentry.h \ 38 | interface/core/module/classmacro.h \ 39 | interface/core/module/moduleitem.h \ 40 | interface/core/module/modulemacro.h \ 41 | interface/core/module/normalobject.h \ 42 | interface/core/module/pluginimpl.h \ 43 | interface/core/module/plugininc.h \ 44 | interface/core/module/singletonobj.h \ 45 | interface/core/nonplugin/scanplugins.h \ 46 | interface/core/nonplugin/swigext.h \ 47 | interface/core/nonplugin/useplugin.h \ 48 | interface/core/nonplugin/useplugins.h \ 49 | interface/core/observer/eventobserver.h \ 50 | interface/core/observer/fireevent.h \ 51 | interface/core/observer/fireobjevent.h \ 52 | interface/core/observer/observerimpl.h \ 53 | interface/core/observer/observerobject.h \ 54 | interface/core/portability/func_s.h \ 55 | interface/core/portability/pathstr.h \ 56 | interface/core/portability/portimpl.h \ 57 | interface/core/portability/uniximpl.h \ 58 | interface/core/portability/winimpl.h \ 59 | interface/core/portability/x3port.h \ 60 | interface/core/portability/x3unix.h \ 61 | interface/core/portability/x3win.h \ 62 | interface/core/utilfunc/convstr.h \ 63 | interface/core/utilfunc/loadmodule.h \ 64 | interface/core/utilfunc/lockcount.h \ 65 | interface/core/utilfunc/lockrw.h \ 66 | interface/core/utilfunc/readints.h \ 67 | interface/core/utilfunc/roundstr.h \ 68 | interface/core/utilfunc/safecall.h \ 69 | interface/core/utilfunc/scanfiles.h \ 70 | interface/core/utilfunc/syserrstr.h \ 71 | interface/core/utilfunc/vecfunc.h \ 72 | interface/core/iobject.h \ 73 | interface/core/objptr.h \ 74 | source/core/x3manager/plugins.h \ 75 | source/core/x3manager/workpath.h \ 76 | interface/core/observer/fireeventex.h \ 77 | interface/core/observer/fireobjeventex.h 78 | 79 | { 80 | CONFIG(debug, debug|release){ 81 | DESTDIR = $$PWD/../bin/debug/CbersPlugins 82 | } 83 | else{ 84 | DESTDIR = $$PWD/../bin/release/CbersPlugins 85 | } 86 | } 87 | 88 | INCLUDEPATH += $$PWD/interface/core 89 | DEPENDPATH += $$PWD/interface/core 90 | 91 | # Copies the given files to the destination directory 92 | defineReplace(copyToDir) { 93 | files = $$1 94 | DIR = $$2 95 | SRCDIR = $$3 96 | LINK = 97 | 98 | win32:DIR ~= s,/,\\,g 99 | win32{ 100 | LINK += if not exist $$quote($$DIR) ( $$QMAKE_MKDIR $$quote($$DIR) ) $$escape_expand(\\n\\t) 101 | } 102 | unix{ 103 | LINK += $$QMAKE_MKDIR $$quote($$DIR) $$escape_expand(\\n\\t) 104 | } 105 | for(FILE, files) { 106 | !isEmpty(SRCDIR){ 107 | FILE = $$SRCDIR/$$FILE 108 | } 109 | win32:FILE ~= s,/,\\,g 110 | LINK += $$QMAKE_COPY $$quote($$FILE) $$quote($$DIR) $$escape_expand(\\n\\t) 111 | } 112 | return($$LINK) 113 | } 114 | 115 | SDK_PATH = $$PWD/../include/x3py/ 116 | win32{ 117 | SDK_PATH ~= s,/,\\,g 118 | QMAKE_POST_LINK += if exist $$quote($$SDK_PATH) ( rmdir /S /Q $$quote($$SDK_PATH) ) $$escape_expand(\\n\\t) 119 | QMAKE_POST_LINK += cd $$quote($$PWD) $$escape_expand(\\n\\t) 120 | } 121 | unix{ 122 | QMAKE_POST_LINK += rm -rf $$quote($$SDK_PATH) $$escape_expand(\\n\\t) 123 | QMAKE_POST_LINK += cd $$quote($$PWD) $$escape_expand(\\n\\t) 124 | } 125 | 126 | QMAKE_POST_LINK += $$copyToDir("interface/core/*.h", $$SDK_PATH, $$PWD) 127 | QMAKE_POST_LINK += $$copyToDir("interface/core/manager/*.h", $$SDK_PATH/manager/, $$PWD) 128 | QMAKE_POST_LINK += $$copyToDir("interface/core/module/*.h", $$SDK_PATH/module/, $$PWD) 129 | QMAKE_POST_LINK += $$copyToDir("interface/core/nonplugin/*.h", $$SDK_PATH/nonplugin/, $$PWD) 130 | QMAKE_POST_LINK += $$copyToDir("interface/core/observer/*.h", $$SDK_PATH/observer/, $$PWD) 131 | QMAKE_POST_LINK += $$copyToDir("interface/core/portability/*.h", $$SDK_PATH/portability/, $$PWD) 132 | QMAKE_POST_LINK += $$copyToDir("interface/core/utilfunc/*.h", $$SDK_PATH/utilfunc/, $$PWD) 133 | 134 | unix{ 135 | SRCEXT = .so 136 | DSTEXT = .pln 137 | QMAKE_POST_LINK += mv -f $$quote($$DESTDIR/lib$$TARGET$$SRCEXT) $$quote($$DESTDIR/$$TARGET$$DSTEXT) $$escape_expand(\\n\\t) 138 | } 139 | -------------------------------------------------------------------------------- /插件模板/qtcreator/share/qtcreator/templates/wizards/CbersPlugin/lib.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/longhuan2018/CbersUI/85bfe9f16e0ff17361875461818006efc51d8d28/插件模板/qtcreator/share/qtcreator/templates/wizards/CbersPlugin/lib.png -------------------------------------------------------------------------------- /插件模板/qtcreator/share/qtcreator/templates/wizards/CbersPlugin/lib@2x.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/longhuan2018/CbersUI/85bfe9f16e0ff17361875461818006efc51d8d28/插件模板/qtcreator/share/qtcreator/templates/wizards/CbersPlugin/lib@2x.png -------------------------------------------------------------------------------- /插件模板/qtcreator/share/qtcreator/templates/wizards/CbersPlugin/module.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | #include 5 | #include 6 | #include 7 | #include "module/plugininc.h" 8 | #include "module/pluginimpl.h" 9 | #include "module/modulemacro.h" 10 | #include "observer/observerimpl.h" 11 | //#include "%{ProjectName}.h" 12 | 13 | XBEGIN_DEFINE_MODULE() 14 | //XDEFINE_CLASSMAP_ENTRY(%{ProjectName}) 15 | XEND_DEFINE_MODULE_DLL() 16 | 17 | QTranslator gTranslator; 18 | OUTAPI bool x3InitializePlugin() 19 | { 20 | ////////////////////////////////////////////////////////////// 21 | // Load Translator 22 | QSettings mySettings; 23 | QString i18nPath = QApplication::applicationDirPath() + QDir::separator() + "i18n"; 24 | QString myUserLocale = mySettings.value( "locale/userLocale", "" ).toString(); 25 | bool myLocaleOverrideFlag = mySettings.value( "locale/overrideFlag", false ).toBool(); 26 | QString myTranslationCode; 27 | if ( !myTranslationCode.isNull() && !myTranslationCode.isEmpty() ) 28 | { 29 | mySettings.setValue( "locale/userLocale", myTranslationCode ); 30 | } 31 | else 32 | { 33 | if ( !myLocaleOverrideFlag || myUserLocale.isEmpty() ) 34 | { 35 | myTranslationCode = QLocale::system().name(); 36 | mySettings.setValue( "locale/userLocale", myTranslationCode ); 37 | } 38 | else 39 | { 40 | myTranslationCode = myUserLocale; 41 | } 42 | } 43 | 44 | if ( myTranslationCode != "C" ) 45 | { 46 | if ( gTranslator.load( QString( "%{ProjectName}_" ) + myTranslationCode, i18nPath ) ) 47 | { 48 | QApplication::installTranslator( &gTranslator ); 49 | } 50 | else 51 | { 52 | qWarning( "loading of %{ProjectName} translation failed [%s]", QString( "%1/%{ProjectName}_%2" ).arg( i18nPath ).arg( myTranslationCode ).toLocal8Bit().constData() ); 53 | } 54 | } 55 | ////////////////////////////////////////////////////////////// 56 | return true; 57 | } 58 | 59 | OUTAPI void x3UninitializePlugin() 60 | { 61 | if( !gTranslator.isEmpty() ) 62 | { 63 | QApplication::removeTranslator( &gTranslator ); 64 | } 65 | } 66 | -------------------------------------------------------------------------------- /插件模板/qtcreator/share/qtcreator/templates/wizards/CbersPlugin/project.pro: -------------------------------------------------------------------------------- 1 | TEMPLATE = lib 2 | TARGET = %{ProjectName} 3 | QT += core 4 | 5 | greaterThan(QT_MAJOR_VERSION, 4): QT += widgets 6 | 7 | # The following define makes your compiler emit warnings if you use 8 | # any feature of Qt which as been marked as deprecated (the exact warnings 9 | # depend on your compiler). Please consult the documentation of the 10 | # deprecated API in order to know how to port your code away from it. 11 | DEFINES += QT_DEPRECATED_WARNINGS 12 | 13 | # You can also make your code fail to compile if you use deprecated APIs. 14 | # In order to do so, uncomment the following line. 15 | # You can also select to disable deprecated APIs only up to a certain version of Qt. 16 | #DEFINES += QT_DISABLE_DEPRECATED_BEFORE=0x060000 # disables all the APIs deprecated before Qt 6.0.0 17 | 18 | # Input 19 | SOURCES += \ 20 | module.cpp 21 | 22 | HEADERS += \ 23 | 24 | PROJECT_PATH = $$PWD 25 | SDK_PATH = $$PROJECT_PATH/../../ 26 | #TRANSLATION_LANGS = zh_CN 27 | include( ../../include/pluginconfig.pri ) 28 | QMAKE_POST_LINK += $$copyToDir($$PROJECT_PATH/*.png, $$DESTDIR/../Skins/) -------------------------------------------------------------------------------- /插件模板/qtcreator/share/qtcreator/templates/wizards/CbersPlugin/wizard.json: -------------------------------------------------------------------------------- 1 | { 2 | "version": 1, 3 | "supportedProjectTypes": [ "Qbs.QbsProject", "Qt4ProjectManager.Qt4Project" ], 4 | "id": "CbersPluginProject", 5 | "category": "G.Library", 6 | "trDescription": "Creates a custom SPD plugin.", 7 | "trDisplayName": "CbersPlugin Project", 8 | "trDisplayCategory": "Library", 9 | "icon": "lib.png", 10 | "featuresRequired": [ "QtSupport.Wizards.FeatureDesktop" ], 11 | 12 | "pages": 13 | [ 14 | { 15 | "trDisplayName": "Project Location", 16 | "trShortTitle": "Location", 17 | "typeId": "Project", 18 | "data": { "trDescription": "This wizard creates an empty CbersPlugin Project .pro file." } 19 | }, 20 | { 21 | "trDisplayName": "Project Management", 22 | "trShortTitle": "Summary", 23 | "typeId": "Summary" 24 | } 25 | ], 26 | "generators": 27 | [ 28 | { 29 | "typeId": "File", 30 | "data": 31 | [ 32 | { 33 | "source": "project.pro", 34 | "target": "%{ProjectName}.pro", 35 | "openAsProject": true 36 | }, 37 | { 38 | "source": "module.cpp", 39 | "target": "module.cpp", 40 | "openInEditor": true 41 | } 42 | ] 43 | } 44 | ] 45 | } 46 | -------------------------------------------------------------------------------- /插件模板/qtcreator/share/qtcreator/templates/wizards/classes/CbersPluginClass/file.h: -------------------------------------------------------------------------------- 1 | %{Cpp:LicenseTemplate}\ 2 | #ifndef %{GUARD} 3 | #define %{GUARD} 4 | @if '%{Base}' 5 | #include <%{Base}> 6 | @endif 7 | @if '%{IncludeIUIView}' === '' && ('%{IncludeIUICommand}' || '%{IncludeIUITool}') 8 | #include 9 | @endif 10 | 11 | @if '%{IncludeIUIEvent}' 12 | #include "UIPluginsEvents.h" 13 | @endif 14 | @if '%{IncludeIUIView}' || '%{IncludeIUICommand}' || '%{IncludeIUITool}' 15 | #include "UIPlugins.h" 16 | USING_NAMESPACE_CBERSPLUGINS 17 | @else 18 | @if '%{IncludeIUIEvent}' 19 | USING_NAMESPACE_CBERSPLUGINS 20 | @endif 21 | @endif 22 | %{JS: Cpp.openNamespaces('%{Class}')} 23 | @if '%{IncludeIUIView}' || '%{IncludeIUICommand}' || '%{IncludeIUITool}' 24 | const char* const clsid%{CN} = "clsid%{CN}"; 25 | @endif 26 | @if '%{Base}' 27 | class %{CN} : public %{Base} 28 | @if '%{IncludeIUIView}' || '%{IncludeIUICommand}' || '%{IncludeIUITool}' 29 | , public IUIPlugin 30 | @if '%{IncludeIUIView}' 31 | , public IUIView 32 | @else 33 | @if '%{IncludeIUICommand}' || '%{IncludeIUITool}' 34 | , public IUICommand 35 | @endif 36 | @endif 37 | @endif 38 | @if '%{IncludeIUIEvent}' 39 | , public IAnythingEventObserver 40 | @endif 41 | @else 42 | class %{CN} 43 | @if '%{IncludeIUIView}' || '%{IncludeIUICommand}' || '%{IncludeIUITool}' 44 | : public IUIPlugin 45 | @if '%{IncludeIUIView}' 46 | , public IUIView 47 | @else 48 | @if '%{IncludeIUICommand}' || '%{IncludeIUITool}' 49 | , public IUICommand 50 | @endif 51 | @endif 52 | @if '%{IncludeIUIEvent}' 53 | , public IAnythingEventObserver 54 | @endif 55 | @else 56 | @if '%{IncludeIUIEvent}' 57 | : public IAnythingEventObserver 58 | @endif 59 | @endif 60 | @endif 61 | { 62 | @if %{isQObject} 63 | Q_OBJECT 64 | @endif 65 | @if '%{IncludeIUIView}' || '%{IncludeIUICommand}' || '%{IncludeIUITool}' 66 | X3BEGIN_CLASS_DECLARE(%{CN}, clsid%{CN}) 67 | X3DEFINE_INTERFACE_ENTRY(IUIPlugin) 68 | @if '%{IncludeIUIView}' 69 | X3DEFINE_INTERFACE_ENTRY(IUIView) 70 | @else 71 | @if '%{IncludeIUICommand}' || '%{IncludeIUITool}' 72 | X3DEFINE_INTERFACE_ENTRY(IUICommand) 73 | @endif 74 | @endif 75 | X3END_CLASS_DECLARE() 76 | @endif 77 | 78 | public: 79 | @if '%{Base}' === 'QObject' 80 | explicit %{CN}(QObject *parent = 0); 81 | @elsif '%{Base}' === 'QWidget' || '%{Base}' === 'QMainWindow' || '%{Base}' === 'QDockWidget' || '%{Base}' === 'QTableWidget' 82 | explicit %{CN}(QWidget *parent = 0); 83 | @else 84 | %{CN}(); 85 | @endif 86 | ~%{CN}(); 87 | 88 | public: 89 | @if '%{IncludeIUIView}' || '%{IncludeIUICommand}' || '%{IncludeIUITool}' 90 | // IUIPlugin 91 | virtual bool Initialize(); 92 | virtual bool UnInitialize(); 93 | virtual bool SetBuddy(x3::IObject* val); 94 | virtual bool readConfig( const QDomNode& node, QDomDocument & document, QString& errorMessage ); 95 | virtual bool writeConfig( const QDomNode& node, QDomDocument & document, QString& errorMessage ); 96 | @if '%{IncludeIUIView}' 97 | 98 | // IUIView 99 | virtual QWidget* getViewWidget(); 100 | @else 101 | @if '%{IncludeIUICommand}' || '%{IncludeIUITool}' 102 | 103 | // IUICommand 104 | virtual QWidget* getButtonWidget(); 105 | virtual QWidget* getWndWidget(); 106 | @endif 107 | @endif 108 | @endif 109 | @if '%{IncludeIUIEvent}' 110 | 111 | // IAnythingEventObserver 112 | virtual bool OnAnything(x3::IObject* sender, const std::string& eventKey, const QVariant& wParam, const QVariant& lParam); 113 | @endif 114 | 115 | @if %{isQObject} 116 | signals: 117 | 118 | public slots: 119 | @if '%{IncludeIUIView}' === '' && ('%{IncludeIUICommand}' || '%{IncludeIUITool}') 120 | @if '%{IncludeIUITool}' 121 | void clicked(bool checked = false); 122 | @else 123 | @if '%{Base}' === 'QDockWidget' 124 | void toggled(bool checked); 125 | @else 126 | void clicked(); 127 | @endif 128 | @endif 129 | @endif 130 | @endif 131 | 132 | @if '%{IncludeIUIView}' === '' && ('%{IncludeIUICommand}' || '%{IncludeIUITool}') 133 | protected: 134 | QToolButton* mToolButton; 135 | bool mDefaultIcon; 136 | @endif 137 | }; 138 | %{JS: Cpp.closeNamespaces('%{Class}')} 139 | #endif // %{GUARD}\ 140 | -------------------------------------------------------------------------------- /插件模板/qtcreator/share/qtcreator/templates/wizards/classes/CbersPluginClass/file.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/longhuan2018/CbersUI/85bfe9f16e0ff17361875461818006efc51d8d28/插件模板/qtcreator/share/qtcreator/templates/wizards/classes/CbersPluginClass/file.png --------------------------------------------------------------------------------