Author Topic: Loose Focus event?  (Read 7783 times)

Offline daniloz

  • Regular
  • ***
  • Posts: 268
Loose Focus event?
« on: February 03, 2011, 11:33:03 am »
Is there an event that is triggered when the C::B app looses focus?

I explain myself: I'd like to write a plugin to save all changed documents whenever C::B looses focus, so I can switch between C::B and my toolchain IDE (VisualDSP++) more easily. :-)

Offline oBFusCATed

  • Developer
  • Lives here!
  • *****
  • Posts: 13413
    • Travis build status
Re: Loose Focus event?
« Reply #1 on: February 03, 2011, 01:20:41 pm »
Look at sdk_events.h if there it isn't you could (probably) register raw wxEvent on the main window.
See here: http://docs.wxwidgets.org/stable/wx_wxactivateevent.html#wxactivateevent
(most of the time I ignore long posts)
[strangers don't send me private messages, I'll ignore them; post a topic in the forum, but first read the rules!]

Offline daniloz

  • Regular
  • ***
  • Posts: 268
Re: Loose Focus event?
« Reply #2 on: February 03, 2011, 01:40:03 pm »
Look at sdk_events.h if there it isn't you could (probably) register raw wxEvent on the main window.
See here: http://docs.wxwidgets.org/stable/wx_wxactivateevent.html#wxactivateevent
You mean, the plugin itself could (probably) register the raw wxEvent on the main window?

Wouldn't it be better to go through a cbEvent, anyway?

Offline Pecan

  • Plugin developer
  • Lives here!
  • ****
  • Posts: 2778
Re: Loose Focus event?
« Reply #3 on: February 03, 2011, 02:33:30 pm »
Google "Event handling overview"



Quote
wxActivateEvent
An activate event is sent when a window or application is being activated or deactivated.

Derived from

wxEvent
wxObject

Include files

<wx/event.h>

Event table macros

To process an activate event, use these event handler macros to direct input to a member function that takes a wxActivateEvent argument.

EVT_ACTIVATE(func)  Process a wxEVT_ACTIVATE event.  
EVT_ACTIVATE_APP(func)  Process a wxEVT_ACTIVATE_APP event.  
EVT_HIBERNATE(func)  Process a hibernate event, supplying the member function. This event applies to wxApp only, and only on Windows SmartPhone and PocketPC. It is generated when the system is low on memory; the application should free up as much memory as possible, and restore full working state when it receives a wxEVT_ACTIVATE or wxEVT_ACTIVATE_APP event.  
Remarks

A top-level window (a dialog or frame) receives an activate event when it is being activated or deactivated. This is indicated visually by the title bar changing colour, and a subwindow gaining the keyboard focus.

An application is activated or deactivated when one of its frames becomes activated, or a frame becomes inactivated resulting in all application frames being inactive.

Please note that usually you should call event.Skip() in your handlers for these events as not doing so can result in strange effects.

See also

Event handling overview, wxApp::IsActive

Members

wxActivateEvent::wxActivateEvent
wxActivateEvent::GetActive


« Last Edit: February 03, 2011, 02:37:30 pm by Pecan »

Offline MortenMacFly

  • Administrator
  • Lives here!
  • *****
  • Posts: 9694
Re: Loose Focus event?
« Reply #4 on: February 03, 2011, 03:34:27 pm »
You mean, the plugin itself could (probably) register the raw wxEvent on the main window?
I don't think that's a good way to do. plugins should never interfere with the core in such way, obviously.

Wouldn't it be better to go through a cbEvent, anyway?
So yes - that's the way to go. If you want to, to can try to design/implement a SDK event accordingly and provide a patch. It shouldn't be too hard. This would mean a change of the SDK API... just for the record.
Compiler logging: Settings->Compiler & Debugger->tab "Other"->Compiler logging="Full command line"
C::B Manual: https://www.codeblocks.org/docs/main_codeblocks_en.html
C::B FAQ: https://wiki.codeblocks.org/index.php?title=FAQ

Offline daniloz

  • Regular
  • ***
  • Posts: 268
Re: Loose Focus event?
« Reply #5 on: February 11, 2011, 10:44:37 am »
Wouldn't it be better to go through a cbEvent, anyway?
So yes - that's the way to go. If you want to, to can try to design/implement a SDK event accordingly and provide a patch. It shouldn't be too hard. This would mean a change of the SDK API... just for the record.
Here is the patch against trunk... it provides two events:
- cbEVT_APP_ACTIVATED: triggered when the C::B window gets the focus
- cbEVT_APP_DEACTIVATED: triggered when the C::B window looses the focus

I've tested them here with my "Save all editors when loosing focus" plugin (still a work in progress, but as soon as it becomes stable, I'll also post-it here) and everything works fine.

I'd really appreciate if you could consider this to go into the "official" C::B. ;-)

Offline daniloz

  • Regular
  • ***
  • Posts: 268
Re: Loose Focus event?
« Reply #6 on: February 13, 2011, 09:21:06 pm »
@morten: Thank you very much for the commit... :-)