Modifying a view that belongs to another controller - model-view-controller

I have a desktop-like application which has 2 controllers: 'Desktop' which represents desktop icons and 'Taskbar' which represents the taskbar where you find buttons to minimize/restore windows already opened, like MS Windows is working.
The problem I currently have is the approach to "how should I display the window". Infact after doubleclicking the icon, I should create a window, and this could happen both on Desktop controller or on Taskbar controller (or maybe directly on the viewport, because they can be dragged anywhere). However, when I create a window, a new button should be created on the taskbar to minimize/restore it.
Because of this, I thought about handling window in the taskbar controller, however I don't know how to reach the Taskbar controller from the Desktop controller.
I have 3 ideas in my mind at the moment:
The Desktop controller directly adds the button to the TaskbarView, but in this way I'm feeling like violating MVC pattern. Also I need to specify TaskbarView in Desktop views.
The Desktop controller after icon doubleclick fires a custom event on the Taskbar controller. In this case the taskbar opens the windows and adds the button, this approach is quite linear but I don't know how to reference a controller from another controller (in this case, from Desktop to Taskbar)
The Ext.Application register for itemdblclick event on Desktop controller. When this event is fired, it redirects (or call a custom event) on Taskbar controller. After this everything keeps going like point 2. In this way I centralize the Routing functionality (like rails), however could also happen that Application object becomes really big. Also I'm using it as a "gigant controller" to route everything, but this is not really a big problem, thinking about rails it does something similar.
The application should not be split in 2 controllers (so Desktop and Taskbar should be one) and everything will be fine. I don't think this approach is correct.
So, my questions are:
Which approach should I use: 1,2,3,4 (or specify if there is something different)?
What a window should belongs to: Desktop controller, Taskbar controller, something else?
Thanks for any answer

I have a similar setup to you. Personally I would go with choice 2. There is a couple ways to deal with this. One is to have a parent that contains both the Desktop and task bar as its children and it can manage the communication between the two. You can create custom events which the parent listens for and directs them to the correct children.
So for example the parent creates both the task bar and desktop and it listen for icon click events on the desktop. When a click event on the icon occurs the parent receives the events and then internally determines what need to be done. In this case it knows that it needs to call the task bar and create the button for the opened window on it.
You could also look at using a a Mediator design pattern in JavaScript to register senders and listeners. So you could sent it up that the desktop is a sender of icon click events and the task bar is a listener of these events. The click on the icon will send an event to all the listeners of it set in the mediator. This way you don't need a parent to manage it. But personal I like the parent better.

Related

Controlling the "Open in ..." button in the Quick Look (preview) panel

The QLPreviewPanel window has a button that will allow the user to open the quick look document they are currently previewing by launching its original application.
Is it possible to (a) disable this button for some documents and (b) learn if the user has clicked that button.
My problem is that some of the QLPreviewItem objects I'm passing to QLPreviewPanel are actually placeholders that aren't intended to be opened, while others are temporary documents that get created spontaneously.
In the later case, I normally delete these when the preview is done, but obviously I don't want to do this if the user has opened them in an application.
I've looked at the API for QLPreviewItem, QLPreviewPanel, and QLPreviewPanelDelegate and don't see any notifications or messages that occur when the user opens an item.
If there's no API, I might just try to hack the UI by searching the QLPreviewPanel for an NSButton and hooking its action, but I don't like hacks and I'm sure this would be a fragile one.

Is there an equivalent of an OnModal message in MFC?

My MFC application has multiple top level (parented to the desktop) windows, any one of which can host an external application which can launch a modal dialog. Is there a way for one the other top level windows to get a notification when any of the others becomes modal?
My specific problem is that one of the my windows is hosting an embedded PDF viewer and when the user clicks print, only the window hosting the viewer is locked, not the others.
When a modal dialog is shown EnableWindow(FALSE) is called for the parent. It is deactivated now and will not accept any mouse input. Also it will not receive the keyboard focus.
When EnableWindow(FALSE) is called WM_ENABLE with wParam==FALSE is sent to the window.
When your parent receives this message you can call EnableWindow(FALSE) for all your other windows too. Recursion might be a problem here, but you can use a private window message or flags to prevent this.
Before the modal dialog closes EnableWndow(TRUE) is called again and WM_ENABLE with wParam==TRUE is sent again.

Make form active

I have application that currently not active. On timer event I need to show this application selection form (yes/no) to user. This form must have keyboard input focus.
What function I must use to make currently not active application form active? SetWindowPos, SetFocus does't help. SetWindowPos - shows form, but is still has no focus.
Probably first of all I need to make whole application active?
When form is shown to user and user has done selection how to bring focus back to application that had it before timer event?
Application is created using MFC.
The answere to your first question is yes, you have to make your whole application active.
To put your window at the top level with input focus you can use BringWindowToTop.
To know wich is the current top window you can call GetTopWindow with NULL.

Is there a way to make changes to the titlebar with GTK2?

I have a desktop application written in Ruby that is using GTK2. It's just a small test application to play with GTK2, but I'm having problems achieving what I want to do. Is there any way using GTK2 to get at the titlebar (apart from setting the title), specifically to either add a button to it (beside the min/max/etc, B in the below diagram) or to add an option to the menu that pops up when you click the icon on the titlebar (A in the below diagram)?
I'm thinking there might not be because GTK is meant to work with many many different window managers, but I just wondered if there was. As a side question, what event does clicking the 'cross' button fire? At the moment if the user clicks that the window disappears but the program doesn't end - I need to capture that event and quit the program.
Thanks for any help, including hitting me over the head and telling me how silly I am.
Note that this is possible in GTK 3.10 and up, by using gtk_window_set_titlebar(). It replaces the window manager's title bar with a custom one. GtkHeaderBar is a good custom title bar class to use.
You can't, however, make it look just like the window manager would, because you won't know which window manager the user is running.
No, the title bar is owned by the window manager and you will typically not have direct access to it.
When the user tries to close the window by clicking the window manager's button, the window will receive the delete event.

Cocoa accessibility API, can I click a window in the background without activating it?

I've been searching forever for a solution to this, so I thought I'd seek out the brainpower of greater minds than mine. I'm developing a Cocoa app that uses the Accessibility API to manipulate another program (it's a hotkey app). The app I'm controlling typically has multiple windows open, with some hidden behind others. What I would like to do, if it's possible, is to send mouse events to windows using the Accessibility API in a way that presses a button in the window without bringing it to the foreground (interact with the window but don't activate it). The reason I'm trying to do this is that sending the mouse event to this other window will force it to the foreground and disrupt the user's interaction with the foremost window.
This is possible on Windows - apparently, because apps similar to mine do it there - but I'm getting the feeling that this isn't possible with Cocoa, given the way the window manager works. Am I mistaken?
Accessibility is higher-level than that. You send, for example, AXPress actions to AXButton objects, but “press” is not necessarily a click—pressing the space bar while a view is focused, for example, is also a “press”. AXPress is a high-level action that means “do your thing”, which obviously has meaning for some views (such as buttons) and not others (such as fields).
Accessibility activating the application does make sense when you look at it from its intended purpose: Assistive devices for disabled users. If the user “presses” something by whatever means, they probably intend to activate the application and work in it.
Quartz Event Services will get you almost there: You can create an event tap for the process you want to control, and you can forge events and send them to a tap. The catch is that you can only send events to a tap when the tap fires—i.e., when the application already has an event to deal with. When it doesn't, you're stuck.

Resources