Top > OOoBasic > Window > UnCloseableDialog

閉じられないダイアログ Edit

以前書いた閉じられないダイアログ。ダイアログエディタで作成したダイアログを利用できないので作成するのが大変過ぎるのが問題点。

この例では Close ボタンを配置して閉じられるようにしてありますが、このボタンをなくすとユーザーの操作で閉じることが出来なくなります。OOo をタスクから終了または別のウィンドウから Exit しないと閉じられません。

  0
  1
  2
  3
  4
  5
  6
  7
  8
  9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
Dim oDlg As Object
 
Sub CreateUnCloseAbleDialog()
  oDoc = StarDesktop.getCurrentComponent()
  
  oParent = oDoc.getCurrentController().getFrame().getContainerWindow()
  oToolkit = oParent.getToolkit()
  
  oAttr = com.sun.star.awt.WindowAttribute
  
  nWindowTypeClass = com.sun.star.awt.WindowClass.SIMPLE
  nAttr = oAttr.MOVEABLE
  sTypeName = "modaldialog"
  
  ' create modaldialog without CLOSEABLE
  oDlg = CreateDialog( oToolkit, oParent, _
      nWindowTypeClass, sTypeName, nAttr, _
      0, 0, 200, 300 )
  
  oContainer = CreateCtr( "Container", 0, 0, 200, 300, _
      Array(), Array() )
  oContainer.createPeer( oToolkit, oDlg )
  oContainer.getModel().BackgroundColor = -1
  
  ' needs close button or something like this to close the dialog
  oButton = CreateCtr( "Button", 100, 250, 75, 35, _
      Array("Label"), Array("Close") )
  oContainer.addControl( "Button", oButton )
  
  oButtonAction = CreateUnoListener("ButtonAction_", _
      "com.sun.star.awt.XActionListener")
  oButton.addActionListener( oButtonAction )
  oButton.ActionCommand = "close"
  
  oDlg.setVisible(True)
  
  oDlg.execute() ' show dialog
  oDlg.dispose()
End Sub
 
 
Sub ButtonAction_actionPerformed( rEvent As com.sun.star.awt.ActionEvent )
  sCmd = rEvent.ActionCommand 
  If sCmd = "close" Then
    oDlg.endExecute()
  End If
End Sub
Sub ButtonAction_disposing( ev As com.sun.star.lang.EventObject )
End Sub
 
 
Function CreateCtr( CtrType, nX, nY, nWidth, nHeight, sNames, vProps )
  Dim oCtr As Object, oCtrModel As Object
  oCtr = createUnoService("com.sun.star.awt.UnoControl" & CtrType )
  oCtrModel = createUnoService("com.sun.star.awt.UnoControl" & CtrType & "Model" )
  oCtrModel.setPropertyValues( sNames, vProps )
  With oCtr
    .setModel( oCtrModel )
    .setPosSize( nX, nY, nWidth, nHeight, _
        com.sun.star.awt.PosSize.POSSIZE )
  End With
  CreateCtr() = oCtr 'model can be got from returned value
End Function
 
Function CreateDialog( oToolkit As Object, oParent As Object, _
  nWindowTypeClass As Long, sTypeName As String, nAttr As Long, _
  nX As Long, nY As Long, nWidth As Long, nHeight As Long ) As Object
  
  aRect = CreateUnoStruct("com.sun.star.awt.Rectangle")
  With aRect
    .X = nX
    .Y = nY
    .Width = nWidth
    .Height = nHeight
  End With
  aWinDesc = CreateUnoStruct("com.sun.star.awt.WindowDescriptor")
  With aWinDesc
    .Type = nWindowTypeClass
    .WindowServiceName = sTypeName
    .ParentIndex = -1
    .Bounds = aRect
    .Parent = oParent
    .WindowAttributes = nAttr
  End With
  CreateDialog = oToolkit.createWindow(aWinDesc)
End Function

Basic ランタイム関数みたいに XML パーサを使ってダイアログのファイルから作成するコードを書けば、◯。


Reload   New Lower page making Edit Freeze Diff Upload Copy Rename   Front page List of pages Search Recent changes Backup   Help   RSS of recent changes