Need help with Dialogs

Need help with Dialogs

Postby reinaldocrespo » Thu May 26, 2011 2: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: Select all  Expand view

   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.
User avatar
reinaldocrespo
 
Posts: 972
Joined: Thu Nov 17, 2005 5:49 pm
Location: Fort Lauderdale, FL

Re: Need help with Dialogs

Postby Marcelo Via Giglio » Thu May 26, 2011 3: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
Marcelo Via Giglio
 
Posts: 1050
Joined: Fri Oct 07, 2005 3:33 pm
Location: Cochabamba - Bolivia

Re: Need help with Dialogs

Postby reinaldocrespo » Thu May 26, 2011 3: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: Select all  Expand view
#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: Select all  Expand view
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.
User avatar
reinaldocrespo
 
Posts: 972
Joined: Thu Nov 17, 2005 5:49 pm
Location: Fort Lauderdale, FL

Re: Need help with Dialogs

Postby Marcelo Via Giglio » Thu May 26, 2011 3:30 pm

Reinaldo,

change in this way

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


and comment

regards

Marcelo
Marcelo Via Giglio
 
Posts: 1050
Joined: Fri Oct 07, 2005 3:33 pm
Location: Cochabamba - Bolivia

Re: Need help with Dialogs

Postby reinaldocrespo » Thu May 26, 2011 3: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.
User avatar
reinaldocrespo
 
Posts: 972
Joined: Thu Nov 17, 2005 5:49 pm
Location: Fort Lauderdale, FL

Re: Need help with Dialogs

Postby reinaldocrespo » Thu May 26, 2011 4: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.
User avatar
reinaldocrespo
 
Posts: 972
Joined: Thu Nov 17, 2005 5:49 pm
Location: Fort Lauderdale, FL

Re: Need help with Dialogs

Postby Marcelo Via Giglio » Thu May 26, 2011 4:23 pm

Reinaldo,

not complete solution, but work
Code: Select all  Expand view
#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
Marcelo Via Giglio
 
Posts: 1050
Joined: Fri Oct 07, 2005 3:33 pm
Location: Cochabamba - Bolivia

Re: Need help with Dialogs

Postby nageswaragunupudi » Fri May 27, 2011 6:02 am

The code can be simplified a lot
Code: Select all  Expand view
#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
User avatar
nageswaragunupudi
 
Posts: 10248
Joined: Sun Nov 19, 2006 5:22 am
Location: India

Re: Need help with Dialogs

Postby fraxzi » Fri May 27, 2011 8: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
User avatar
fraxzi
 
Posts: 811
Joined: Tue May 06, 2008 4:28 am
Location: Philippines

Re: Need help with Dialogs

Postby reinaldocrespo » Fri May 27, 2011 5:49 pm

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



Reinaldo.
User avatar
reinaldocrespo
 
Posts: 972
Joined: Thu Nov 17, 2005 5:49 pm
Location: Fort Lauderdale, FL


Return to FiveWin for Harbour/xHarbour

Who is online

Users browsing this forum: Google [Bot] and 95 guests