Appendix A: QFormMDI
Documentation composant par D.Glodt (c)2000-2003 |
Appendix A: QFormMDI |
|
QFormMDI Composant
QFormEx est identique a un composant QForm avec la fonctionnalité
MDI.
Les composants
standard de rapidq possédant un handle contrôle(Qpanel,QRichEdit,QScrollBox,...)
peuvent être associés aux fenêtres
fille MDI ,
ils ne doivent pas etre visible et leur parent doit être l'objet
lui-même lors de leur déclaration.
Les composants
peuvent être déclarés en tant que variables tableau
ou être de type différent pour chaque fenêtre fille
MDI.
QFormMDI Proprietés
Champs |
Type |
L/E |
Defaut |
|
|
|
|
ChildCaption |
STRING |
LE |
|
|
Texte de la barre de titre de la fenetre
fille active. |
ChildHandle |
LONG |
L |
|
|
Handle de la fenetre fille active |
ChildLeft |
SHORT |
LE |
|
|
Position gauche de la fenetre fille active |
|
|
ChildTop |
SHORT |
LE |
|
|
Position haute de la fenetre fille active |
|
|
ChildWidth |
SHORT |
LE |
|
|
Largeur fenetre fille active |
|
|
ChildHeight |
SHORT |
LE |
|
|
Hauteur fenetre fille active |
|
|
ChildMax |
INTEGER |
LE |
1024 |
|
Nombre maximum de fenetre fille |
|
|
ChildCount |
INTEGER |
L |
|
|
Nombre de fenetre fille |
|
|
ChildIcon |
LONG |
LE |
|
|
Handle icone pour les fenetres fille |
|
|
ChildState |
INTEGER |
LE |
|
|
Etat de la fenetre fille active,peut etre wsNormal,wsMinimized,wsMaximized |
|
wsNormal |
MDIMenu |
LONG |
LE |
|
|
Handle sous menu pour l'insertion des noms de fenetres fille |
|
|
ComponentIndex |
INTEGER |
L |
|
|
Index du composant associé a la fenetre fille active |
|
|
ChildResult |
INTEGER |
LE |
False |
|
Resultat de l'action de fermeture d'une fenetre fille,la valeur est
a true lors de la fermeture et peut etre mis a false lors d'un événement
OnChildClose pour annuler la fermeture si l'application necessite une sauvegarde |
|
|
QFormMDI Methodes
Methode |
Type |
Description |
Parametres |
|
|
|
|
AddChild |
SUB(handle&,Title$,index&,left%,
top%,width%,height%,DefaultSize&) |
Additionne une fenetre fille,handle& est le handle du composant
associé a la fenetre fille,Title$ est le texte de la la barre
de titre de
la fenetre fille,index& est le numéro du composant associé,
DefaultSize& indique si l'on utilise les dimensions par défaut.. |
8 |
CloseChild |
SUB |
Ferme la fenetre fille active |
0 |
CloseAllChild |
SUB |
Ferme toutes les fenetres fille |
0 |
CascadeChild |
SUB |
Positionne toutes les fenetres fille en cascade |
0 |
SetHorzChild |
SUB |
Positionne toutes les fenetres fille en horizontale |
0 |
SetVertChild |
SUB |
Positionne toutes les fenetres fille en verticale |
0 |
IconArrangeChild |
SUB |
Arrangement de toutes les fenetres fille en icone |
0 |
MinimizeAllChild |
SUB |
Réduit en icone toutes les fenetres fille |
0 |
MaximizeAllChild |
SUB |
Met en taille maximum toutes les fenetres fille |
0 |
RestoreChild |
SUB |
Restaure la taille initiale des fenetres fille |
|
ActiveNextChild |
SUB |
Active la fenetre fille suivante |
0 |
ActivePreviousChild |
SUB |
Active la fenetre fille précédente |
0 |
GetChild |
FUNCTION(Title$)& |
Retourne l'index de la fenetre fille correspondant au titre Title$ |
1 |
ChildExist |
FUNCTION(Title$)& |
Retourne l'existence d'une fenetre fille par son titre |
1 |
ActiveChild |
SUB(Index&) |
Active la fenetre fille identifié par index& |
1 |
FreeChild |
FUNCTION(handle&)& |
Retourne l'état associé d'un composant a une fenetre
fille,retourne True si
le composant identifié par handle& n'est pas associé
a une fenetre fille |
1 |
SetDeskBar |
SUB |
L'application sera dans la barre de tache lors de sa réduction |
0 |
QFormMDI Evenements
Evenement |
Type |
Déclenchement |
Parametres |
|
|
|
|
OnChildClose |
(handleChild&,index&,titleChild$) |
Fermeture fenetre fille,le parametre index& est l'index du composant
associé |
3 |
OnChildActive |
(handleChild&,index&,titleChild$) |
Activation fenetre fille |
3 |
OnChildResize |
(handleChild&,index&,titleChild$) |
Redimentionnement fenetre fille |
3 |
QFormMDI Exemple1
$TYPECHECK ON
$include "rapidq.inc"
$include "object\QformMDI.inc"
DECLARE SUB mnuNew_Click
DECLARE SUB mnuOpen_Click
DECLARE SUB mnuClose_Click
DECLARE SUB mnuCloseAll_Click
DECLARE SUB mnuNext_Click
DECLARE SUB mnuPrevious_Click
DECLARE SUB mnuCascade_Click
DECLARE SUB mnuTileHorz_Click
DECLARE SUB mnuTileVert_Click
DECLARE SUB mnuArrange_Click
DECLARE SUB mnuMinAll_Click
DECLARE SUB mnuMaxAll_Click
DECLARE SUB mnuRestAll_Click
DECLARE SUB mnuCut_Click
DECLARE SUB mnuCopy_Click
DECLARE SUB mnuPaste_Click
DECLARE SUB mnuSelectAll_Click
DECLARE SUB show
DECLARE SUB close
DECLARE SUB KeyDown(Key as word,Shift as integer)
DECLARE SUB infos(handleChild as long,index as integer,titleChild as
string)
DECLARE SUB CloseMDI(handleChild as long,index as integer,titleChild
as string)
dim j as integer
dim flag as integer
dim UntitledCount as integer
const VK_F6=117
CREATE Form AS QFormMDI
Caption = "MDI Parent"
Center
Width=Screen.Width/2*1.5
Height=Screen.Height/2*1.5
CREATE mnuMain AS QMAINMENU
CREATE mnuFile AS QMENUITEM
Caption="&File"
CREATE mnuNew AS QMENUITEM
Caption="&New"
OnClick=mnuNew_Click
END CREATE
CREATE mnuOpen AS QMENUITEM
Caption="&Open"
OnClick=mnuOpen_Click
END CREATE
CREATE mnuClose AS QMENUITEM
Caption="&Close"
OnClick=mnuClose_Click
END CREATE
CREATE mnuCloseAll AS QMENUITEM
Caption="Close &All"
OnClick=mnuCloseAll_Click
END CREATE
CREATE mnuNext AS QMENUITEM
Caption="Next"
OnClick=mnuNext_Click
END CREATE
CREATE mnuPrevious AS QMENUITEM
Caption="Previous"
OnClick=mnuPrevious_Click
END CREATE
END CREATE
CREATE mnuEdit as QMENUITEM
Caption="&Edit"
CREATE mnuCut as QMENUITEM
Caption="&Cut"
ShortCut="CTRL+X"
OnClick=mnuCut_Click
END CREATE
CREATE mnuCopy as QMENUITEM
Caption="&Copy"
ShortCut="CTRL+C"
OnClick=mnuCopy_Click
END CREATE
CREATE mnuPaste as QMENUITEM
Caption="&Paste"
ShortCut="CTRL+V"
OnClick=mnuPaste_Click
END CREATE
CREATE Sep2 as QMENUITEM
Caption="-"
END CREATE
CREATE mnuSelectAll as QMENUITEM
Caption="&Select all"
ShortCut="CTRL+A"
OnClick=mnuSelectAll_Click
END CREATE
END CREATE
CREATE mnuWindows AS QMENUITEM
Caption="&Windows"
CREATE mnuCascade AS QMENUITEM
Caption="&Cascade"
OnClick=mnuCascade_Click
END CREATE
CREATE mnuTileHorz AS QMENUITEM
Caption="Tile &Horizontally"
OnClick=mnuTileHorz_Click
END CREATE
CREATE mnuTileVert AS QMENUITEM
Caption="Tile &Vertically"
OnClick=mnuTileVert_Click
END CREATE
CREATE mnuArrange AS QMENUITEM
Caption="&Arrange Icons"
OnClick=mnuArrange_Click
END CREATE
CREATE mnuMinAll AS QMENUITEM
Caption="&Minimize All"
OnClick=mnuMinAll_Click
END CREATE
CREATE mnuMaxAll AS QMENUITEM
Caption="Ma&ximixe All"
OnClick=mnuMaxAll_Click
END CREATE
CREATE mnuRestAll AS QMENUITEM
Caption="&Restore All"
OnClick=mnuRestAll_Click
END CREATE
END CREATE
END CREATE
CREATE Stat AS QSTATUSBAR
END CREATE
KeyPreview=true
MdiMenu=mnuWindows.handle
ChildMax=20
OnChildClose=CloseMDI
OnChildActive=infos
OnClose=Close
OnPaint=Show
OnKeyDown=KeyDown
END CREATE
' Components for MDI
dim edit(20) as qrichedit
dim handleControl as long
for j=0 to 20
edit(j).parent=form
edit(j).visible=false 'must be no visible
edit(j).ScrollBars=3
edit(j).WordWrap=false
next j
Form.SetDeskBar
Form.ShowModal
'Find free component for MDI
Function GetCtl() as integer
dim find as integer
dim h as integer
find=0
for j=0 to 20
if form.FreeChild(edit(j).handle) and find=0 then
h=j
find=1
end if
next j
result=h
End Function
SUB mnuNew_Click
dim index as integer
if form.ChildCount<form.ChildMax then
index=GetCtl()
form.AddChild(edit(index).handle,"Untitled "+STR$(UntitledCount+1),index,0,0,0,0,true)
UntitledCount++
end if
END SUB
SUB mnuOpen_Click
dim index as integer
DIM OD AS QOPENDIALOG
OD.Filter="Text file(*.txt)|*.txt"
if form.ChildCount<form.ChildMax then
IF OD.Execute THEN
IF form.ChildExist(OD.FileName) THEN
form.ActiveChild(form.GetChild(OD.FileName))
EXIT SUB
END IF
index=GetCtl()
edit(index).loadfromfile(OD.FileName)
edit(index).modified=false
form.AddChild(edit(index).handle,OD.FileName,index,0,0,0,0,True)
UntitledCount++
END IF
end if
END SUB
SUB CloseMDI(handleChild as long,index as integer,titleChild as string)
dim msgButton as integer
if edit(index).modified then
msgButton=MessageBox("Fermer fenetre?",titleChild,36)
if msgButton=6 then
edit(index).modified=false
edit(index).clear
form.ChildResult=true
else
form.ChildResult=false
end if
else
edit(index).clear
end if
END SUB
SUB mnuClose_Click
form.CloseChild
if form.ChildCount=0 then stat.simpleText=""
END SUB
SUB mnuCloseAll_Click
form.CloseAllChild
if form.ChildCount=0 then stat.simpleText=""
END SUB
SUB mnuNext_Click
form.ActiveNextChild
END SUB
SUB mnuPrevious_Click
form.ActivePreviousChild
END SUB
SUB mnuCascade_Click
form.CascadeChild
END SUB
SUB mnuTileHorz_Click
form.SetHorzChild
END SUB
SUB mnuTileVert_Click
form.SetVertChild
END SUB
SUB mnuArrange_Click
form.IconArrangeChild
END SUB
SUB mnuMinAll_Click
form.MinimizeAllChild
END SUB
SUB mnuMaxAll_Click
form.MaximizeAllChild
END SUB
SUB mnuRestAll_Click
form.RestoreChild
END SUB
SUB mnuCut_Click
if form.ChildCount>0 then
edit(form.componentIndex).CutToClipBoard
end if
END SUB
SUB mnuCopy_Click
if form.ChildCount>0 then
edit(form.componentIndex).CopyToClipBoard
end if
END SUB
SUB mnuPaste_Click
if form.ChildCount>0 then
edit(form.componentIndex).PasteFromClipBoard
end if
END SUB
SUB mnuSelectAll_Click
if form.ChildCount>0 then
edit(form.componentIndex).SelectAll
end if
END SUB
SUB infos(handleChild as long,index as integer,titleChild as string)
stat.simpleText=titleChild
End Sub
SUB show
dim index as integer
if flag=false then
if form.ChildCount<form.ChildMax then
index=GetCtl()
form.AddChild(edit(index).handle,"Untitled
"+STR$(UntitledCount+1),index,0,0,0,0,true)
UntitledCount++
end if
flag=true
end if
END SUB
Sub Close
form.CloseAllChild
if form.ChildCount>0 then form.modalResult=false
End Sub
Sub KeyDown(key as word,shift as integer)
'next child with Ctrl+F6
if shift=CtrlDown and key=VK_F6 then form.ActiveNextChild
end sub
QFormMDI Exemple2
$TYPECHECK ON
$OPTION ICON "photo.ico"
$include "rapidq.inc"
$Include "Object\QFormMDI.inc"
$Include "Object\QICON.inc"
DECLARE SUB mnuNew_Click
DECLARE SUB mnuOpen_Click
DECLARE SUB mnuClose_Click
DECLARE SUB mnuCloseAll_Click
DECLARE SUB mnuNext_Click
DECLARE SUB mnuPrevious_Click
DECLARE SUB mnuCascade_Click
DECLARE SUB mnuTileHorz_Click
DECLARE SUB mnuTileVert_Click
DECLARE SUB mnuArrange_Click
DECLARE SUB mnuMinAll_Click
DECLARE SUB mnuMaxAll_Click
DECLARE SUB mnuRestAll_Click
DECLARE SUB show
DECLARE SUB close
DECLARE SUB KeyDown(Key as word,Shift as integer)
DECLARE SUB infos(handleChild as long,index as integer,titleChild as
string)
DECLARE SUB CloseMDI(handleChild as long,index as integer,titleChild
as string)
dim j as integer
dim flag as integer
dim UntitledCount as integer
const VK_F6=117
dim icon as Qicon
icon.associated=true
icon.filename=command$(0)
CREATE Form AS QFormMDI
Caption="MDI Parent"
Center
Width=Screen.Width/2*1.5
Height=Screen.Height/2*1.5
ChildIcon=icon.handle
CREATE panel as QPANEL
align=1
height=35
bevelOuter=0
CREATE bt1 as QBUTTON
top=5
left=5
width=25
Hint="Prévious"
ShowHint=true
caption="<<"
OnClick=mnuPrevious_Click
END CREATE
CREATE bt2 as QBUTTON
top=5
left=35
width=25
Hint="Next"
ShowHint=true
caption=">>"
OnClick=mnuNext_Click
END CREATE
END CREATE
CREATE mnuMain AS QMAINMENU
CREATE mnuFile AS QMENUITEM
Caption="&File"
CREATE mnuNew AS QMENUITEM
Caption="&New"
OnClick=mnuNew_Click
END CREATE
CREATE mnuOpen AS QMENUITEM
Caption="&Open"
OnClick=mnuOpen_Click
END CREATE
CREATE mnuClose AS QMENUITEM
Caption="&Close"
OnClick=mnuClose_Click
END CREATE
CREATE mnuCloseAll AS QMENUITEM
Caption="Close &All"
OnClick=mnuCloseAll_Click
END CREATE
CREATE mnuNext AS QMENUITEM
Caption="Next"
OnClick=mnuNext_Click
END CREATE
CREATE mnuPrevious AS QMENUITEM
Caption="Previous"
OnClick=mnuPrevious_Click
END CREATE
END CREATE
CREATE mnuWindows AS QMENUITEM
Caption="&Windows"
CREATE mnuCascade AS QMENUITEM
Caption="&Cascade"
OnClick=mnuCascade_Click
END CREATE
CREATE mnuTileHorz AS QMENUITEM
Caption="Tile &Horizontally"
OnClick=mnuTileHorz_Click
END CREATE
CREATE mnuTileVert AS QMENUITEM
Caption="Tile &Vertically"
OnClick=mnuTileVert_Click
END CREATE
CREATE mnuArrange AS QMENUITEM
Caption="&Arrange Icons"
OnClick=mnuArrange_Click
END CREATE
CREATE mnuMinAll AS QMENUITEM
Caption="&Minimize All"
OnClick=mnuMinAll_Click
END CREATE
CREATE mnuMaxAll AS QMENUITEM
Caption="Ma&ximixe All"
OnClick=mnuMaxAll_Click
END CREATE
CREATE mnuRestAll AS QMENUITEM
Caption="&Restore All"
OnClick=mnuRestAll_Click
END CREATE
END CREATE
END CREATE
CREATE Stat AS QSTATUSBAR
END CREATE
KeyPreview=true
MdiMenu=mnuWindows.handle
ChildMax=20
OnChildClose=CloseMDI
OnChildActive=infos
OnClose=Close
OnKeyDown=KeyDown
END CREATE
'components for MDI
dim edit(20) as qpanel
dim img(20) as qimage
for j=0 to 20
edit(j).parent=form
edit(j).visible=false 'must be no visible
edit(j).bevelOuter=0
edit(j).color=&hffffff
img(j).AutoSize=1
img(j).Parent=edit(j)
next j
Form.SetDeskBar
Form.ShowModal
'Find free component for MDI
Function GetCtl() as integer
dim find as integer
dim h as integer
find=0
for j=0 to 20
if form.FreeChild(edit(j).handle) and find=0 then
h=j
find=1
end if
next j
result=h
End Function
SUB mnuNew_Click
dim index as integer
if form.ChildCount<form.ChildMax then
index=GetCtl()
form.AddChild(edit(index).handle,"Untitled "+STR$(UntitledCount+1),index,0,0,0,0,true)
UntitledCount++
end if
END SUB
SUB mnuOpen_Click
dim index as integer
DIM OD AS QOPENDIALOG
OD.caption="Load image"
OD.Filter="Bitmap file(*.bmp)|*.bmp"
if form.ChildCount<form.ChildMax then
IF OD.Execute THEN
IF form.ChildExist(OD.FileName) THEN
form.ActiveChild(form.GetChild(OD.FileName))
EXIT SUB
END IF
index=GetCtl()
img(index).bmp=OD.FileName
form.AddChild(edit(index).handle,OD.FileName,index,0,0,img(index).width+8,img(index).height+27,False)
UntitledCount++
END IF
end if
END SUB
SUB CloseMDI(handleChild as long,index as integer,titleChild as string)
img(index).handle=0
END SUB
SUB mnuClose_Click
form.CloseChild
if form.ChildCount=0 then stat.simpleText=""
END SUB
SUB mnuCloseAll_Click
form.CloseAllChild
if form.ChildCount=0 then stat.simpleText=""
END SUB
SUB mnuNext_Click
form.ActiveNextChild
END SUB
SUB mnuPrevious_Click
form.ActivePreviousChild
END SUB
SUB mnuCascade_Click
form.CascadeChild
END SUB
SUB mnuTileHorz_Click
form.SetHorzChild
END SUB
SUB mnuTileVert_Click
form.SetVertChild
END SUB
SUB mnuArrange_Click
form.IconArrangeChild
END SUB
SUB mnuMinAll_Click
form.MinimizeAllChild
END SUB
SUB mnuMaxAll_Click
form.MaximizeAllChild
END SUB
SUB mnuRestAll_Click
form.RestoreChild
END SUB
SUB infos(handleChild as long,index as integer,titleChild as string)
stat.simpleText=titleChild
End Sub
Sub Close
form.CloseAllChild
if form.ChildCount>0 then form.modalResult=false
if form.ChildCount=0 then icon.filename=""
End Sub
Sub KeyDown(key as word,shift as integer)
'next child with Ctrl+F6
if shift=CtrlDown and key=VK_F6 then form.ActiveNextChild
end sub
|