It is currently Wed Oct 23, 2019 7:55 pm

All times are UTC + 1 hour




Post new topic Reply to topic  [ 20 posts ]  Go to page Previous  1, 2
Author Message
 Post subject: Re: EventClose on Dock
PostPosted: Wed Sep 04, 2019 4:34 pm 
Offline
Enthusiast
Enthusiast

Joined: Wed Mar 11, 2009 4:06 pm
Posts: 136
Location: NL
Sorry, I was talking in the context of logout. It does work nicely from context menu close, but not from logout.


Top
 Profile  
Reply with quote  
 Post subject: Re: EventClose on Dock
PostPosted: Thu Sep 05, 2019 8:34 am 
Offline
Enthusiast
Enthusiast

Joined: Wed Mar 11, 2009 4:06 pm
Posts: 136
Location: NL
And cannot use WaitEvent/WaitWindowEvent in the callback procedure to keep things responsive too...
WindowEvent() and WaitWindowEvent() can not be called from a 'binded' event callback.


Top
 Profile  
Reply with quote  
 Post subject: Re: EventClose on Dock
PostPosted: Thu Sep 05, 2019 12:31 pm 
Offline
Enthusiast
Enthusiast

Joined: Wed Mar 11, 2009 4:06 pm
Posts: 136
Location: NL
Seems that BindEvent keeps working. Good.


Top
 Profile  
Reply with quote  
 Post subject: Re: EventClose on Dock
PostPosted: Tue Sep 10, 2019 8:50 am 
Offline
Enthusiast
Enthusiast

Joined: Wed Mar 11, 2009 4:06 pm
Posts: 136
Location: NL
Why appWillTerminate is not called in below case?

Code:
EnableExplicit

Prototype Proto_AppNotification(Object, Selector, Sender)
DeclareC AppShouldTerminate(Object, Selector, Sender)
DeclareC AppWillTerminate(Object, Selector, Sender)

Global AppDelegate, AppShouldTerminate_.Proto_AppNotification, AppWillTerminate_.Proto_AppNotification

AppDelegate = CocoaMessage(0, CocoaMessage(0, 0, "NSApplication sharedApplication"), "delegate")
AppShouldTerminate_ = class_replaceMethod_(CocoaMessage(0, AppDelegate, "class"),
                                           sel_registerName_("applicationShouldTerminate:"),
                                           @AppShouldTerminate(), "v@:@")
AppWillTerminate_ = class_replaceMethod_(CocoaMessage(0, AppDelegate, "class"),
                                         sel_registerName_("applicationWillTerminate:"),
                                         @AppWillTerminate(), "v@:@")
; class_addMethod_(CocoaMessage(0, AppDelegate, "class"),
;                                            sel_registerName_("applicationWillTerminate:"),
;                                            @AppWillTerminate(), "v@:@")

ProcedureC AppShouldTerminate(Object, Selector, Sender)
  Debug "AppShouldTerminate"
  If AppShouldTerminate_
    AppShouldTerminate_(Object, Selector, Sender)
  EndIf
  If MessageRequester("Confirmation", "Do you want to terminate the application?",
                      #PB_MessageRequester_YesNo) = #PB_MessageRequester_Yes
    End
  Else
    ProcedureReturn #NO
  EndIf
EndProcedure

ProcedureC AppWillTerminate(Object, Selector, Sender)
  Debug "AppWillTerminate"
  End
EndProcedure

OpenWindow(0, 270, 100, 200, 170, "Test", #PB_Window_MinimizeGadget)

Repeat
Until WaitWindowEvent() = #PB_Event_CloseWindow


And is there anything wrong with the way to do things like this instead or does this break stuff?:
Code:
ProcedureC AppShouldTerminate(Object, Selector, Sender)

   Debug "AppShouldTerminate"

   ProcedureReturn #YES
EndProcedure

ProcedureC AppWillTerminate(Object, Selector, Sender)
  Debug "AppWillTerminate"
  End
EndProcedure

w = OpenWindow(0, 0, 0, 300, 200, "Test")
CocoaMessage(@app, 0, "NSApplication sharedApplication")

myAppDelegateClass = objc_allocateClassPair_(objc_getClass_("NSObject"), "myAppDelegate", 0)
class_addProtocol_(myAppDelegateClass, objc_getProtocol_("NSApplicationDelegate"))

class_addMethod_(myAppDelegateClass, sel_registerName_("applicationShouldTerminate:"), @appShouldTerminate(), "L@:@")
class_addMethod_(myAppDelegateClass, sel_registerName_("applicationWillTerminate:"), @appWillTerminate(), "v@:@")

objc_registerClassPair_(myAppDelegateClass)
myAppDelegate = class_createInstance_(myAppDelegateClass, 0)
CocoaMessage(0, app, "setDelegate:", myAppDelegate)
Repeat
  e = WaitWindowEvent(10)
Until e = #PB_Event_CloseWindow


All code from elsewhere in forum slightly adjusted to fit the case.


Top
 Profile  
Reply with quote  
 Post subject: Re: EventClose on Dock
PostPosted: Tue Sep 10, 2019 9:24 am 
Offline
PureBasic Expert
PureBasic Expert

Joined: Sun Aug 08, 2004 5:21 am
Posts: 3493
Location: Netherlands
Rinzwind wrote:
Why appWillTerminate is not called in below case?

When you place End within the AppShouldTerminate procedure, it already ends the application so AppWillTerminate will never be called.
For some reason when I remove End, it still isn't being called. I have no clue why :?

Rinzwind wrote:
And is there anything wrong with the way to do things like this instead or does this break stuff?:

Yes, this is wrong. Creating you own app delegate is only safe when you create everything yourself (including windows, event loop etc.).
PureBasic already uses an app delegate so if you replace it like this with your own app delegate, it will break things.

_________________
macOS 10.15 Catalina, PB 5.71 x64


Top
 Profile  
Reply with quote  
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 20 posts ]  Go to page Previous  1, 2

All times are UTC + 1 hour


Who is online

Users browsing this forum: No registered users and 1 guest


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
Jump to:  

 


Powered by phpBB © 2008 phpBB Group
subSilver+ theme by Canver Software, sponsor Sanal Modifiye