FiveTech Support Forums

FiveWin / Harbour / xBase community
Board index FiveWin for Harbour/xHarbour Need help with Dialogs
Posts: 990
Joined: Thu Nov 17, 2005 05:49 PM
Need help with Dialogs
Posted: Thu May 26, 2011 02:27 AM
Hi.

I need some help. I'd to open a dialog (built from resources) and have for the dialog to pop on the center of a window and not allow dragging outside of its parent window where it belongs.
Code (fw): Select all Collapse
   DEFINE DIALOG oDlg OF oChildWnd RESOURCE "About"  TRANSPARENT COLOR CLR_WHITE , RGB(240,240,240)
...
   ACTIVATE DIALOG oDlg


I especially would like to avoid the dialog from being dragged outside the main window. Any ideas?

Thank you,


Reinaldo.
Posts: 1088
Joined: Fri Oct 07, 2005 03:33 PM
Re: Need help with Dialogs
Posted: Thu May 26, 2011 03:03 AM
Reinaldo,

you try to define function to move the dialog to specific position and assign it to bmoved block of dialog

ACTIVATE DIALOG <oDlg> ;
[ <center: CENTER, CENTERED> ] ;
[ <NonModal: NOWAIT, NOMODAL> ] ;
[ WHEN <uWhen> ] ;
[ VALID <uValid> ] ;
[ ON [ LEFT ] CLICK <uClick> ] ;
[ ON INIT <uInit> ] ;
[ ON MOVE <uMoved> ] ;
[ ON PAINT <uPaint> ] ;
[ ON RIGHT CLICK <uRClicked> ] ;
[ <Resize16: RESIZE16> ] ;

regards

Marcelo
Posts: 990
Joined: Thu Nov 17, 2005 05:49 PM
Re: Need help with Dialogs
Posted: Thu May 26, 2011 03:04 PM
With the reduced sample code I show how you can center a dlg on a window. The problem I now have is that the dialog may be dragged outside of its parent window. It gives the impression that it is not attached to it. The dialog should get cropped as it is dragged outside its owner boundaries.

Try this code and after opening the dialog by clicking on the only menu option, drag the dialog around, you will see that it moves anywhere including outside its parent window.
Code (fw): Select all Collapse
#include "fivewin.ch"

FUNCTION MAIN
    LOCAL oWnd, oMenu
    LOCAL x := 1024
    LOCAL y := 780
    LOCAL xi := INT( x * 0.10 / 2 )
    LOCAL yi := INT( y * 0.10 / 2 )

    x  := INT( x * 0.90 ) + xi
   y  := INT( y * 0.90 ) + yi
    
   MENU oMenu
      MenuItem "Dialog" ACTION ShowDlgOnWnd( "Sample Text", oWnd )
   ENDMENU

   DEFINE WINDOW oWnd MDI FROM yi, xi TO y, x PIXEL Title "Testing Dlg On Wnd" MENU oMenu
    ACTIVATE WINDOW oWnd

RETURN NIL


//-------------------------------------------------------
FUNCTION ShowDlgOnWnd( cText, oOwner )

   LOCAL oDlg, nTop, nLeft 
   LOCAL bCenterDlg

   DEFINE DIALOG oDlg ;
              OF oOwner;
        RESOURCE "SampleDlg" ;
     TRANSPARENT ;
           COLOR CLR_WHITE , RGB(240,240,240)

   bCenterDlg := {|| oOwner:CoorsUpdate(), ;
               nTop := oOwner:nHeight /2 - oDlg:nHeight /2,; 
               nLeft:= oOwner:nWidth / 2 - oDlg:nWidth /2 + oOwner:nLeft,;
               oDlg:Move( nTop, nLeft ) }

   REDEFINE SAY PROMPT cText ID 1 OF oDlg TRANSPARENT COLOR CLR_BLACK
   REDEFINE BUTTONBMP ID 2 OF oDlg BITMAP "exit16" PROMPT "Ok" TEXTRIGHT ACTION oDlg:END()
   
    oDlg:lHelpIcon := .f.
    
   ACTIVATE DIALOG oDlg ON INIT Eval( bCenterDlg )

   RETURN NIL


And this is the resource:
Code (fw): Select all Collapse
SAMPLEDLG DIALOG 6, 15, 232, 58
STYLE DS_SYSMODAL |DS_3DLOOK |DS_SETFONT |DS_MODALFRAME |WS_POPUP |WS_VISIBLE |WS_SYSMENU |WS_DLGFRAME |0x40000000
CAPTION "FW Dialog"
FONT 8, "MS Sans Serif"
LANGUAGE LANG_NEUTRAL, 0
BEGIN
  CONTROL "",1001,"BUTTON",BS_GROUPBOX |WS_CHILD |WS_VISIBLE ,7,2,217,23
  CONTROL "Ok",2,"BUTTON",BS_DEFPUSHBUTTON |BS_VCENTER |BS_CENTER |WS_CHILD |WS_TABSTOP |WS_VISIBLE ,174,33,50,14
  CONTROL "Redefined Text",1,"STATIC",SS_CENTER |WS_CHILD |WS_GROUP |WS_VISIBLE ,9,13,201,8
END


Any ideas?

Thank you,


Reinaldo.
Posts: 1088
Joined: Fri Oct 07, 2005 03:33 PM
Re: Need help with Dialogs
Posted: Thu May 26, 2011 03:30 PM
Reinaldo,

change in this way

Code (fw): Select all Collapse
 ACTIVATE DIALOG oDlg ON INIT Eval( bCenterDlg ) ON MOVE oDlg:Move( nTop, nLeft )


and comment

regards

Marcelo
Posts: 990
Joined: Thu Nov 17, 2005 05:49 PM
Re: Need help with Dialogs
Posted: Thu May 26, 2011 03:59 PM

I had done that. It is ok. But not exactly what a user would expect. I suppose I'll have to live with it. I would much rather if the dialog would begin to get cropped just like a window would if dragged outside its parent boundaries.

Posts: 990
Joined: Thu Nov 17, 2005 05:49 PM
Re: Need help with Dialogs
Posted: Thu May 26, 2011 04:03 PM

... and there is more. If the dialog is a non modal dialog, then the parent window can be dragged while the child dialog will stay put in the same place on the screen. Not what the user would expect. I would much rather for the dialog to move as its parent window is moved giving the correct impression that the dialog is attached to its parent.

Posts: 1088
Joined: Fri Oct 07, 2005 03:33 PM
Re: Need help with Dialogs
Posted: Thu May 26, 2011 04:23 PM
Reinaldo,

not complete solution, but work
Code (fw): Select all Collapse
#include "fivewin.ch"

STATIC oDlg 

FUNCTION MAIN
    LOCAL oWnd, oMenu
    LOCAL x := 1024
    LOCAL y := 780
    LOCAL xi := INT( x * 0.10 / 2 )
    LOCAL yi := INT( y * 0.10 / 2 )

    x  := INT( x * 0.90 ) + xi
   y  := INT( y * 0.90 ) + yi
    
   MENU oMenu
      MenuItem "Dialog" ACTION ShowDlgOnWnd( "Sample Text", oWnd )
   ENDMENU

   DEFINE WINDOW oWnd MDI FROM yi, xi TO y, x PIXEL Title "Testing Dlg On Wnd" MENU oMenu
    ACTIVATE WINDOW oWnd ON MOVE IF( oDlg != NIL, centre( oWnd, oDlg ), NIL )

RETURN NIL


//-------------------------------------------------------
FUNCTION ShowDlgOnWnd( cText, oOwner )

   LOCAL bCenterDlg

   DEFINE DIALOG oDlg ;
              OF oOwner;
        RESOURCE "SampleDlg" ;
     TRANSPARENT ;
           COLOR CLR_WHITE , RGB(240,240,240)

   REDEFINE SAY PROMPT cText ID 1 OF oDlg TRANSPARENT COLOR CLR_BLACK
   REDEFINE BUTTONBMP ID 2 OF oDlg BITMAP "exit16" PROMPT "Ok" TEXTRIGHT ACTION oDlg:END()
   
    oDlg:lHelpIcon := .f.
    
   ACTIVATE DIALOG oDlg ON INIT centre( oOwner, oDlg ) ON MOVE centre( oOwner, oDlg ) NOWAIT

   RETURN NIL


FUNCTION centre( oOwner, oDlg )
LOCAL ntop, nLeft

   oOwner:CoorsUpdate()
   nTop := oOwner:nHeight /2 - oDlg:nHeight /2  + oOwner:nTop
   nLeft:= oOwner:nWidth / 2 - oDlg:nWidth /2 + oOwner:nLeft
   oDlg:Move( nTop, nLeft )

RETURN NIL
Posts: 10733
Joined: Sun Nov 19, 2006 05:22 AM
Re: Need help with Dialogs
Posted: Fri May 27, 2011 06:02 AM
The code can be simplified a lot
Code (fw): Select all Collapse
#include "FiveWin.Ch"

static oCenterDlg
//----------------------------------------------------------------------------//

function Main()

   local oWnd, oBar

   DEFINE WINDOW oWnd MDI
   DEFINE BUTTONBAR oBar OF oWnd 2007
   DEFINE BUTTON OF oBar PROMPT "D" ACTION CenteredDialog( oWnd )
   SET MESSAGE OF oWnd TO '' 2007
   ACTIVATE WINDOW oWnd ;
      ON MOVE   ( If( oCenterDlg == nil,, oCenterDlg:Center( oWnd ) ) ) ;
      ON RESIZE ( If( oCenterDlg == nil,, oCenterDlg:Center( oWnd ) ) )

return nil

static function CenteredDialog( oWnd )

   local oDlg

   DEFINE DIALOG oDlg OF oWnd

   ACTIVATE DIALOG oDlg NOMODAL ;
      ON INIT ( oDlg:Center( oWnd ), oCenterDlg := oDlg, .f. );
      VALID   ( oCenterDlg := nil, .t. )

return nil

In the above sample, the dialg is centered and stays centered when the main window is resized of moved, but not clip the dialog.

For clipping the dialog, we need to set the dialog to an MdiChild and center the MdiChild the same way as in the above sample.
Regards



G. N. Rao.

Hyderabad, India
Posts: 811
Joined: Tue May 06, 2008 04:28 AM
Re: Need help with Dialogs
Posted: Fri May 27, 2011 08:02 AM

Dear Mr. Reinaldo,

Maybe because Dialog behaves at it should.. it will go out of parent..

If your apps is MDI.. make a child dialog (if you have plenty of redefines) and use MDI Child as its parent.. This way your dialog (supposed, within a child MDI) wont go out of parent and behaves the way you want it.

Just my 2cents.

Kind regards,
Frances

Kind Regards,

Frances



Fivewin for xHarbour v18.07

xHarbour v1.2.3.x

BCC 7.3 + PellesC8 ( Resource Compiler only)

ADS 10.1 / MariaDB

Crystal Reports 8.5/9.23 DE

xMate v1.15
Posts: 990
Joined: Thu Nov 17, 2005 05:49 PM
Re: Need help with Dialogs
Posted: Fri May 27, 2011 05:49 PM

Thank you everyone. Your input has help me figure out what works in my app. Again, thank you very much.

Reinaldo.

Continue the discussion