Fix messages opening on the wrong screen

Post

Posted
Rating:
#1 (In Topic #924)
Guru
BruceSteers is in the usergroup ‘Guru’
<COLOR color="#00BF00">Here is a fix for if you have an application that runs on one screen but the message windows annoyingly pop open on the other one.</COLOR>
It's also good for if you want message and other modal windows opening up positioned with other forms instead of the default center screen.

my discovery is that modal windows like Message will open on the lowest positioned screen
(this is also the default for a lot of the gambas ide pop-open windows)

So if you have 2 monitors side by side they will always open on the left screen regardless of what screen is the Primary and what screen your application is on.
if you have one screen above the other then it's always the top screen.

I figured out a fix by Creating a Form.class file that has an override for the ShowModal() method.
Not just a fix, a handy feature :)

it checks if there is a calling window and notes it to get Window.Screen info or a form can be explicitly set.

it creates a timer to move the modal window after it's initiated.

The override means it can operate on ANY ShowModal call your application does itself or triggers. (it certainly works for Message() )

Just pop the Form.class into your own projects .src folder to have your own project use it.

See next post for archive

Hoping it helps..
BruceS
Online now: Yes Back to the top

Post

Posted
Rating:
#2
Guru
BruceSteers is in the usergroup ‘Guru’
i've edited it to have a couple of additional properies…

Form.ModalMode
select a mode
can be  MODAL_NORMAL, MODAL_SAMESCREEN, MODAL_WINDOWSTACK, MODAL_WINDOWCENTER

 MODAL_NORMAL, normal gambas mode
 MODAL_SAMESCREEN, move centered on the same screen as the active window
 MODAL_WINDOWSTACK, move to the calling windows TopLeft position
 MODAL_WINDOWCENTER, move centered to the active window

Form.ModalMode_Windows As String[]
to limit the windows it will operate on by checking the Forms name
Eg.
Form.ModalMode_Windows = ["FMessage", "FInputBox"]


Form.ModalUseForm As Form
if for example you set Form.ModalUseForm = FMain then ALL modals will open centered on FMain and not a possible different active window.

Attached is a simple test app to see the different modes on the message box and an InputBox.

Maybe this will help others , or even inspire our Ben to implement something similar in the matrix :)

Attachment
Online now: Yes Back to the top

Post

Posted
Rating:
#3
Guru
BruceSteers is in the usergroup ‘Guru’
Here is an alternative method.

This intercepts the normal ShowModal() method and uses Show() instead and makes the window pseudo-modal

this works better/cleaner than the other method as the modal windows do not open in their usual place then move , they open at the desired location to begin with.

This adds 2 properties to From.class that will center new windows to the current Application.ActiveWindow (as you can test in the test application)
Form.StickyModals
Form.StickyForms

StickyModals intercepts ShowModal() and works on ALL modal windows.
StickyForms intercepts Show() and works on ALL opening forms if their X,Y coords have not been explicitly set.

There's not various styles with this one just to center on the active window.

<COLOR color="#BF00FF">Can anyone tell me if my pseudo ShowModal() method is sufficient in the code below?</COLOR>

Cheers All

Test app in post below

the Form.class  (updates to V0.2)

Code (gambas)

  1.  
  2. ' Gambas class file
  3.  
  4.  
  5.  
  6. Private $bIsPseudoModal As Boolean
  7. Private $iModalValue As Integer
  8.  
  9. '' Make all modal windows center on the active window
  10. Static Property StickyModals As Boolean Use $bStickyModals
  11.  
  12. '' Make all form windows without X,Y set center on the active window
  13. Static Property StickyForms As Boolean Use $bStickyForm
  14.  
  15. '' Make all form windows without X,Y set center on the Mouse position
  16. Static Property StickToMouse As Boolean Use $bStickToMouse
  17.  
  18. '' Make StickyForms and StickyModals stick to a specific window not the active one.
  19. Static Property StickToWindow As Window Use $hStickToWindow
  20.  
  21. Public Sub Show()
  22.  
  23.   Dim XY As Integer = -16 ' gtk uses -16 as a non set position value, qt uses 0
  24.  
  25.   If Me.Parent Then Return
  26.  
  27.   If Component.IsLoaded("gb.qt4") Or If Component.IsLoaded("gb.qt5") Then xy = 0
  28.  
  29.   If $bStickyForm And If Me.X = xy And If Me.Y = xy Then MoveMe
  30.   Super.Show
  31.  
  32.  
  33.  
  34.   If $bStickToMouse Then Me.Move(Mouse.ScreenX - (Me.W / 2), Mouse.ScreenY - (Me.H / 2))
  35.  
  36.   $hWin = Application.ActiveWindow
  37.   If $hStickToWindow And If Object.IsValid($hStickToWindow) Then $hWin = $hStickToWindow
  38.   If Not $hWin And If Not $bStickToMouse Then Return False
  39.  
  40.   If Not $bStickToMouse Then Me.Move($hWin.X + ($hWin.W / 2) - (Me.W / 2), $hWin.Y + ($hWin.H / 2) - (Me.H / 2))
  41.  
  42.  
  43.  
  44.  
  45. Public Sub ShowModal() As Integer
  46.  
  47.   If $bStickyModals Then
  48.     If MoveMe() Then
  49. '      Dim hWin As Window = Application.ActiveWindow
  50.       $bIsPseudoModal = True
  51.       If Not $bStickToMouse Then
  52.       Dim bEnabled As Boolean = $hWin.Enabled
  53.       $hWin.Enabled = False
  54.       Endif
  55.       Me.Utility = True
  56.       Super.Show
  57.       While Object.IsValid(Me)
  58.         Wait 0.1
  59.       Wend
  60.  
  61.       If Object.IsValid($hWin) And If Not $bStickToMouse Then
  62.         $hWin.Enabled = bEnabled
  63.       Endif
  64.  
  65.       Return $iModalValue
  66.  
  67.     Endif
  68.  
  69.   Return Super.ShowModal()
  70.  
  71.  
  72.  
  73.   If $bIsPseudoModal Then
  74.     $iModalValue = Value
  75.   Super.Close(Value)
  76.  
  77.  
  78.  
  79.  
Online now: Yes Back to the top

Post

Posted
Rating:
#4
Avatar
Enthusiast
PJBlack is in the usergroup ‘Enthusiast’
after a very quick test it seems to work as expected ...
Online now: No Back to the top

Post

Posted
Rating:
#5
Guru
BruceSteers is in the usergroup ‘Guru’

PJBlack said

after a very quick test it seems to work as expected …

Cool :)
i just dropped the Form.class into my gambas/comp/src/gb.form/.src source folder and set StickyModals to be true by default.

So now StickyModals is activated across the board on ALL my progs unless i turn it off  :)

I added a property like the other versions Form.ModalUseForm…

Form.StickToWindow = window
if you give that a window it will center on that unless it's gone then it defaults to Activewindow unless that's also gone then it just uses normal ShowModal().

Added property Form.StickToMouse to make modals.forms center at mouse pos. (useful if you have no window to use to center on or if you want a message in your face wherever you may be)

updated test app shows how you can make a message pop up on either the modal window or the main form or with the mouse.

It's a brave new world of windows and messages opening where i want them to , or closer to the area my mouse is probably at :)

Attachment
Online now: Yes Back to the top
1 guest and 0 members have just viewed this.