diff --git a/ewol/context/Context.cpp b/ewol/context/Context.cpp index 2be4fb1b..02e03a64 100644 --- a/ewol/context/Context.cpp +++ b/ewol/context/Context.cpp @@ -564,6 +564,15 @@ void ewol::Context::OS_ClipBoardArrive(enum ewol::context::clipBoard::clipboardL m_msgSystem.post(data); } +void ewol::Context::clipBoardGet(enum ewol::context::clipBoard::clipboardListe _clipboardID) { + // just transmit an event , we have the data in the system + OS_ClipBoardArrive(_clipboardID); +} + +void ewol::Context::clipBoardSet(enum ewol::context::clipBoard::clipboardListe _clipboardID) { + // nothing to do, data is already copyed in the EWOL clipborad center +} + bool ewol::Context::OS_Draw(bool _displayEveryTime) { int64_t currentTime = ewol::getTime(); // this is to prevent the multiple display at the a high frequency ... diff --git a/ewol/context/Context.h b/ewol/context/Context.h index 4962b403..1de2bca3 100644 --- a/ewol/context/Context.h +++ b/ewol/context/Context.h @@ -254,12 +254,12 @@ namespace ewol { * @brief Inform the Gui that we want to have a copy of the clipboard * @param[in] _clipboardID ID of the clipboard (STD/SELECTION) only apear here */ - virtual void clipBoardGet(enum ewol::context::clipBoard::clipboardListe _clipboardID) { }; + virtual void clipBoardGet(enum ewol::context::clipBoard::clipboardListe _clipboardID); /** * @brief Inform the Gui that we are the new owner of the clipboard * @param[in] _clipboardID ID of the clipboard (STD/SELECTION) only apear here */ - virtual void clipBoardSet(enum ewol::context::clipBoard::clipboardListe _clipboardID) { }; + virtual void clipBoardSet(enum ewol::context::clipBoard::clipboardListe _clipboardID); /** * @brief Call by the OS when a clipboard arrive to US (previously requested by a widget) * @param[in] Id of the clipboard diff --git a/ewol/context/MacOs/Context.h b/ewol/context/MacOs/Context.h index 90f37edb..e7a5c474 100644 --- a/ewol/context/MacOs/Context.h +++ b/ewol/context/MacOs/Context.h @@ -23,6 +23,7 @@ namespace MacOs { void setMouseMotion(int32_t _id, float _x, float _y); void setKeyboard(ewol::key::Special _keyboardMode, int32_t _unichar, bool _isDown, bool _isAReapeateKey); void setKeyboardMove(ewol::key::Special& _keyboardMode, enum ewol::key::keyboard _move, bool _isDown, bool _isAReapeateKey); + void stopRequested(); }; #endif \ No newline at end of file diff --git a/ewol/context/MacOs/Context.cpp b/ewol/context/MacOs/Context.mm similarity index 73% rename from ewol/context/MacOs/Context.cpp rename to ewol/context/MacOs/Context.mm index f5f478a7..a25c6eae 100644 --- a/ewol/context/MacOs/Context.cpp +++ b/ewol/context/MacOs/Context.mm @@ -11,6 +11,7 @@ #include #include #include +#include #include #include #include @@ -31,6 +32,7 @@ #include #include +#import int64_t ewol::getTime() { struct timespec now; @@ -52,7 +54,7 @@ int64_t ewol::getTime() { class MacOSInterface : public ewol::Context { private: - ewol::key::Special m_guiKeyBoardMode; + ewol::key::Special m_guiKeyBoardMode; public: MacOSInterface(ewol::context::Application* _application, int32_t _argc, const char* _argv[]) : ewol::Context(_application, _argc, _argv) { @@ -78,12 +80,12 @@ class MacOSInterface : public ewol::Context { OS_SetMouseMotion(_id, vec2(_x, _y)); } void MAC_SetKeyboard(ewol::key::Special _keyboardMode, int32_t _unichar, bool _isDown, bool _isAReapeateKey) { - if (_unichar == u32char::Delete) { + if (char32_t(_unichar) == u32char::Delete) { _unichar = u32char::Suppress; - } else if (_unichar == u32char::Suppress) { + } else if (char32_t(_unichar) == u32char::Suppress) { _unichar = u32char::Delete; } - if (_unichar == u32char::CarrierReturn) { + if (char32_t(_unichar) == u32char::CarrierReturn) { _unichar = u32char::Return; } //EWOL_DEBUG("key: " << _unichar << " up=" << !_isDown); @@ -118,6 +120,40 @@ class MacOSInterface : public ewol::Context { std::string req = "open " + _url; system(req.c_str()); } + void MAC_Stop() { + OS_Stop(); + } + void stop() { + mm_stopApplication(); + } + void clipBoardGet(enum ewol::context::clipBoard::clipboardListe _clipboardID) { + if (_clipboardID == ewol::context::clipBoard::clipboardStd) { + NSPasteboard* myPasteboard = [NSPasteboard generalPasteboard]; + NSString* myString = [myPasteboard stringForType:NSPasteboardTypeString]; + std::string val([myString UTF8String]); + ewol::context::clipBoard::setSystem(_clipboardID, val); + if (val.size() != 0) { + OS_ClipBoardArrive(_clipboardID); + } + } else { + ewol::Context::clipBoardGet(_clipboardID); + } + } + void clipBoardSet(enum ewol::context::clipBoard::clipboardListe _clipboardID) { + if (_clipboardID == ewol::context::clipBoard::clipboardStd) { + NSPasteboard* myPasteboard = [NSPasteboard generalPasteboard]; + [myPasteboard clearContents]; + //EWOL_ERROR(" copy: " << ewol::context::clipBoard::get(_clipboardID)); + NSString *text = [[NSString alloc] initWithUTF8String:ewol::context::clipBoard::get(_clipboardID).c_str()]; + BOOL err = [myPasteboard setString:text forType:NSPasteboardTypeString]; + if (err == FALSE) { + EWOL_ERROR("copy to clipboard can not be done ..."); + } + } else { + ewol::Context::clipBoardSet(_clipboardID); + } + } + }; @@ -168,6 +204,12 @@ void MacOs::setKeyboardMove(ewol::key::Special& _keyboardMode, enum ewol::key::k interface->MAC_SetKeyboardMove(_keyboardMode, _move, _isDown, _isAReapeateKey); } +void MacOs::stopRequested() { + if (interface == nullptr) { + return; + } + interface->MAC_Stop(); +} /** * @brief Main of the program diff --git a/ewol/context/MacOs/Interface.h b/ewol/context/MacOs/Interface.h index 3a412b21..05a7440c 100644 --- a/ewol/context/MacOs/Interface.h +++ b/ewol/context/MacOs/Interface.h @@ -14,7 +14,8 @@ extern "C" { #endif int mm_main(int argc, const char *argv[]); -int mm_run(void); +int mm_run(); +void mm_stopApplication(); #ifdef __cplusplus } diff --git a/ewol/context/MacOs/Interface.mm b/ewol/context/MacOs/Interface.mm index db28e5e0..9d760d30 100644 --- a/ewol/context/MacOs/Interface.mm +++ b/ewol/context/MacOs/Interface.mm @@ -14,6 +14,8 @@ #import #import +id window = nil; + int mm_main(int argc, const char *argv[]) { [NSAutoreleasePool new]; @@ -38,8 +40,13 @@ int mm_main(int argc, const char *argv[]) { // create the label to qui the application : id quitTitle = [@"Quit " stringByAppendingString:appName]; // create the item to quit the appllication with META+q at shortCut + /* id quitMenuItem = [ [ [NSMenuItem alloc] initWithTitle:quitTitle action:@selector(terminate:) keyEquivalent:@"q"] autorelease]; + */ + id quitMenuItem = [ [ [NSMenuItem alloc] initWithTitle:quitTitle + action:@selector(stop:) keyEquivalent:@"q"] autorelease]; + // add the item to the menu: [appMenu addItem:quitMenuItem]; // set the application menu to the main app menu ... @@ -49,9 +56,9 @@ int mm_main(int argc, const char *argv[]) { // -- basic windows creation : // ----------------------- ---------------------------------------- // create a windows of size 800/600 - id window = [ [ [EwolMainWindows alloc] initWithContentRect:NSMakeRect(0, 0, 800, 600) - styleMask:(NSTitledWindowMask|NSMiniaturizableWindowMask|NSClosableWindowMask) backing:NSBackingStoreBuffered defer:NO] - autorelease]; + window = [ [ [EwolMainWindows alloc] initWithContentRect:NSMakeRect(0, 0, 800, 600) + styleMask:(NSTitledWindowMask|NSMiniaturizableWindowMask|NSClosableWindowMask) backing:NSBackingStoreBuffered defer:NO] + autorelease]; [window setAcceptsMouseMovedEvents:YES]; //id window = [ [MacOsAppDelegate alloc] autorelease]; @@ -93,3 +100,12 @@ int mm_run(void) { // return no error return 0; } + +void mm_stopApplication() { + EWOL_INFO("NSApp terminate start."); + [window closeRequestEwol]; + [NSApp stop:nil]; + //[NSApp terminate:nil]; + EWOL_INFO("NSApp terminate done"); +} + diff --git a/ewol/context/MacOs/Windows.h b/ewol/context/MacOs/Windows.h index 33224d19..aacf94ae 100644 --- a/ewol/context/MacOs/Windows.h +++ b/ewol/context/MacOs/Windows.h @@ -31,6 +31,7 @@ // keyboard eevnts: - (void)keyDown:(NSEvent *)theEvent; - (void)flagsChanged:(NSEvent *)theEvent; - +- (void)closeRequestEwol; @end + diff --git a/ewol/context/MacOs/Windows.mm b/ewol/context/MacOs/Windows.mm index 13f23e37..530b4219 100644 --- a/ewol/context/MacOs/Windows.mm +++ b/ewol/context/MacOs/Windows.mm @@ -423,13 +423,21 @@ static ewol::key::Special guiKeyBoardMode; } } +- (void)closeRequestEwol { + EWOL_ERROR("closeRequestEwol: BEGIN"); + [super close]; + EWOL_ERROR("closeRequestEwol: END"); +} + - (void)close { EWOL_ERROR("close:"); + MacOs::stopRequested(); // TODO: add check of close request ... - [super close]; - [NSApp terminate:self]; + //[super close]; + //[NSApp terminate:self]; } @end + diff --git a/ewol/context/clipBoard.cpp b/ewol/context/clipBoard.cpp index cd3377e6..0f8dc979 100644 --- a/ewol/context/clipBoard.cpp +++ b/ewol/context/clipBoard.cpp @@ -17,13 +17,13 @@ /* -note: la copy dans le : +note: copy id data : 0 : copy standard - [1..9] : copy interne - 10 : bouton du milieux + [1..9] : copy internal + 10 : middle button */ //!< Local copy of the clipboards -static std::string mesCopy[ewol::context::clipBoard::clipboardCount]; +static std::string myCopy[ewol::context::clipBoard::clipboardCount]; static const char* clipboardDescriptionString[ewol::context::clipBoard::clipboardCount+1] = { "clipboard0", @@ -54,7 +54,7 @@ std::ostream& ewol::operator <<(std::ostream& _os, const enum ewol::context::cli void ewol::context::clipBoard::init() { EWOL_INFO("Initialyse ClipBoards"); for(int32_t i=0; i ewol::widget::Windows::getSubObjectNamed(const std return nullptr; } +void ewol::widget::Windows::sysOnKill() { + if (onKill() == true) { + getContext().stop(); + } + +} diff --git a/ewol/widget/Windows.h b/ewol/widget/Windows.h index abe01766..b86b69b0 100644 --- a/ewol/widget/Windows.h +++ b/ewol/widget/Windows.h @@ -37,7 +37,7 @@ namespace ewol { void sysDraw(); void sysOnShow() {}; void sysOnHide() {}; - void sysOnKill() {}; + void sysOnKill(); public: virtual void onShow() { }; virtual void onHide() { }; diff --git a/lutin_ewol.py b/lutin_ewol.py index 361349a7..134f76d6 100644 --- a/lutin_ewol.py +++ b/lutin_ewol.py @@ -59,7 +59,7 @@ def create(target): myModule.add_src_file('ewol/context/Android/Context.cpp') elif target.name=="MacOs": myModule.add_src_file([ - 'ewol/context/MacOs/Context.cpp', + 'ewol/context/MacOs/Context.mm', 'ewol/context/MacOs/Interface.mm', 'ewol/context/MacOs/Windows.mm', 'ewol/context/MacOs/OpenglView.mm',