home *** CD-ROM | disk | FTP | other *** search
/ com!online 2001 December / COMCD1201.iso / openoffice / f_0020 / DlgTools.xba < prev    next >
Encoding:
Extensible Markup Language  |  2001-06-15  |  15.2 KB  |  507 lines

  1. <?xml version="1.0" encoding="UTF-8"?>
  2. <!DOCTYPE script:module PUBLIC "-//OpenOffice.org//DTD OfficeDocument 1.0//EN" "module.dtd">
  3. <script:module xmlns:script="http://openoffice.org/2000/script" script:name="DlgTools" script:language="StarBasic">
  4. Option Explicit
  5.  
  6. Global const INC_TABLES        as integer = 1
  7. Global const INC_QUERIES    as integer = 2
  8. Global const INC_FORMS        as integer = 4
  9. Global const INC_REPORTS    as integer = 8
  10.  
  11.  
  12. ' -----------------------------------------------------------------------------
  13. Sub InitDlgTools()
  14.         ' You should call this after your BasicLibraries.LoadLibrary("Tools"). If the lib is loaded for the
  15.     ' first time (after starting the application), LoadLibrary doesn't ensure the
  16.     ' accessibility of the globals declared herein, but a call to any of the methods in
  17.     ' this module does. So you should make this dummy call.
  18.     ' (It's a bug in LoadLibrary, isn't it ?)
  19. End Sub
  20.  
  21. ' -----------------------------------------------------------------------------
  22. Function isVersionColumn(_aFields as Object, _sField as String) as Boolean
  23.     On Local Error goto _return_false_
  24.     isVersionColumn = _aFields.getByName(_sField).IsVersioning
  25.     Exit Function
  26. _return_false_:
  27.     isVersionColumn = false
  28. End Function
  29.  
  30. ' -----------------------------------------------------------------------------
  31.  
  32. ' -----------------------------------------------------------------------------
  33. Function UNOQuoteTableName(sQualifiedName as String, aConn as Object) As String
  34.  
  35.     Dim aMetaData as Object
  36.     Dim sSeparator as String
  37.     Dim sQuoteChar as String
  38.     Dim nSeparatorPos as Integer
  39.  
  40.     aMetaData = aConn.getMetaData()
  41.     sQuoteChar = aMetaData.getInfo(26)    ' 26 = quote character
  42.     sSeparator = aMetaData.getInfo(28)    ' 28 = qualifier separator
  43.  
  44.     Dim sQuotedName As String
  45.  
  46.     Dim nCatalogUsage as Integer
  47.     Dim nSchemaUsage as Integer
  48.     nCatalogUsage = aMetaData.getInfo(12)    ' 12 = position flags for catalog usage
  49.     nSchemaUsage = aMetaData.getInfo(11)    ' 11 = position flags for schema usage
  50.  
  51.     If (nCatalogUsage and 1) <> 0 Then    ' 1 = use catalog names in DML
  52.         nSeparatorPos = InStr(sQualifiedName, sSeparator)
  53.         If nSeparatorPos > 0 Then
  54.             Dim sDBName as String
  55.             sDBName = Mid(sQualifiedName, 1, nSeparatorPos - 1)
  56.             sQuotedName = sQuotedName & sQuoteChar & sDBName & sQuoteChar
  57.             sQuotedName = sQuotedName & sSeparator
  58.             sQualifiedName = Mid(sQualifiedName, nSeparatorPos + 1, Len(sQualifiedName) - nSeparatorPos)
  59.         End If
  60.     End If
  61.  
  62.     If (nSchemaUsage And 1) <> 0 Then    ' 1 = use schema names in DML
  63.         nSeparatorPos = InStr(sQualifiedName, ".")
  64.         If (nSeparatorPos > 0) And (InStr(Mid(sQualifiedName, nSeparatorPos + 1), ".") = 0) Then
  65.             ' there is exactly one "." in sQualifiedName -> it is the separator between the schema and the object name
  66.             sQuotedName = sQuotedName & sQuoteChar & Mid(sQualifiedName, 1, nSeparatorPos - 1) & sQuoteChar
  67.             sQuotedName = sQuotedName & "."
  68.             sQuotedName = sQuotedName & sQuoteChar & Mid(sQualifiedName, nSeparatorPos + 1, Len(sQualifiedName) - nSeparatorPos) & sQuoteChar
  69.         Else
  70.             sQuotedName = sQuotedName & sQuoteChar & sQualifiedName & sQuoteChar
  71.         End If
  72.  
  73.     Else
  74.         sQuotedName = sQuotedName & sQuoteChar & sQualifiedName & sQuoteChar
  75.     End If
  76.  
  77.     UNOQuoteTableName = sQuotedName
  78. End Function
  79.  
  80. ' -----------------------------------------------------------------------------
  81. Function getNames(aNameAccess as Object, aNames as Strings) as String
  82.     Dim i%
  83.     Dim aIterator as Object
  84.     Dim aNameSequence()
  85.     aNameSequence = aNameAccess.getElementNames()
  86.     For i%=lbound(aNameSequence) To ubound(aNameSequence)
  87.         aNames.Add(aNameSequence(i%))
  88.     Next i%
  89.  
  90. '    while aIterator.hasMoreElements()
  91. '        aNames.Add(aIterator.nextElement().Name)
  92. '    Wend
  93. End Function
  94.  
  95. ' -----------------------------------------------------------------------------
  96. Function UNO_GetAllInstalledNamesInDatabase(aDatabase as Object, aNames as Strings, nIncludeFlags as Integer) as Strings
  97.     Application.EnterWait()
  98.     Wait(0)
  99.  
  100.     aNames.Clear()
  101. '    On Local Error Goto OuttaHere
  102.     If (nIncludeFlags And INC_TABLES) <> 0 Then
  103.         getNames(aDatabase.getTables(), aNames)
  104.     End If
  105.     If (nIncludeFlags And INC_QUERIES) <> 0 Then
  106.         getNames(aDatabase.getQueries(), aNames)
  107.     End If
  108.     If (nIncludeFlags And INC_FORMS) <> 0 Then
  109.         getNames(aDatabase.getForms(), aNames)
  110.     End If
  111.     If (nIncludeFlags And INC_REPORTS) <> 0 Then
  112.         getNames(aDatabase.getReports(), aNames)
  113.     End If
  114.  
  115. OuttaHere:
  116.     While (Application.IsWait())
  117.         Application.LeaveWait()
  118.     Wend
  119. End Function
  120.  
  121. Sub ReplaceTokenInString (ByVal TokenToReplace$, ByVal TokenToInsert$, sReplaceIn$)
  122.  
  123.     Dim sLeft$, sRight$
  124.     Dim nActSearchPos%
  125.  
  126.     nActSearchPos% = 1
  127.  
  128.     While (0 <> InStr (nActSearchPos%, sReplaceIn$, TokenToReplace$))
  129.  
  130.         sLeft$ = Left (sReplaceIn$, InStr (nActSearchPos%, sReplaceIn$, TokenToReplace$) - 1)
  131.         nActSearchPos% = Len (sLeft$) + Len (TokenToReplace$) + 1
  132.         sRight = Mid (sReplaceIn$, nActSearchPos%)
  133.  
  134.         sReplaceIn$ = sLeft$ + TokenToInsert$ + sRight$
  135.     Wend
  136. End Sub
  137.  
  138. Sub ReplaceStringInStrings(aStrings As Strings, ByVal sFind$, ByVal sReplace$)
  139.     Dim NewStrings As New Strings
  140.     Dim nCount%
  141.  
  142.     NewStrings.Clear()
  143.     For nCount% = 1 To aStrings.Count()
  144.         NewStrings.Add(aStrings.Item (nCount%))
  145.     Next
  146.  
  147.     aStrings.Clear()
  148.     For nCount% = 1 To NewStrings.Count()
  149.         If (NewStrings.Item (nCount%) = sFind$) Then
  150.             aStrings.Add(sReplace$)
  151.         Else
  152.             aStrings.Add(NewStrings.Item (nCount%))
  153.         End If
  154.     Next
  155.     Erase NewStrings
  156. End Sub
  157.  
  158. Function StrInStrings%(ByVal AvailNames As Strings, ByVal ActiveName$)
  159.     Dim Result%, nCount%
  160.     Dim bNotFound%
  161.  
  162.     bNotFound% = True
  163.     nCount% = 1
  164.     ActiveName$ = UCase(ActiveName$)
  165.     While (nCount%<=AvailNames.Count() And bNotFound%)
  166.         If (UCase(AvailNames.Item(nCount%))=UCase(ActiveName$)) Then
  167.             bNotFound%=False
  168.         Else
  169.             nCount% = nCount% + 1
  170.         End If
  171.     Wend
  172.  
  173.     If (bNotFound%) Then
  174.         StrInStrings% = -1
  175.     Else
  176.         StrInStrings% = nCount%
  177.     End If
  178. End Function
  179.  
  180. Function SuggestTitleStr$(ByVal AvailNames As Strings, ByVal ActiveName$)
  181.  
  182.     Dim nMaxTitleLen%
  183.     nMaxTitleLen = 31
  184.  
  185.     Dim SuggestCount%, index%
  186.     Dim oldName$
  187.  
  188.     oldName$ = ActiveName$
  189.     SuggestCount% = 1
  190.  
  191.     While ((-1 <> StrInStrings%(AvailNames, UCase(ActiveName$)) Or (Len (ActiveName$) > nMaxTitleLen)))
  192.         ActiveName$ = Left (oldName$, 1 + nMaxTitleLen - Len (Str (Trim (SuggestCount%))))
  193.         ActiveName$ = ActiveName$ + Trim(Str(SuggestCount%))
  194.         SuggestCount% = SuggestCount% + 1
  195.     Wend
  196.     SuggestTitleStr$ = ActiveName$
  197. End Function
  198.  
  199. Function SuggestTableTitleStr$(ByVal AvailNames As Strings, ByVal ActiveName$)
  200.     Dim SuggestCount%, index%, nMaxTitleLen&
  201.     Dim oldName$
  202.  
  203.     nMaxTitleLen& = Application.GetDatabaseLimits (1)
  204.     If ((0 = nMaxTitleLen&) Or (50 < nMaxTitleLen&)) Then nMaxTitleLen& = 50
  205.  
  206.     oldName$ = ActiveName$
  207.     SuggestCount% = 1
  208.  
  209.     While ((-1 <> StrInStrings%(AvailNames, UCase (ActiveName$)) Or (Len (ActiveName$) > nMaxTitleLen&)))
  210.         ActiveName$ = Left (oldName$, 1 + nMaxTitleLen& - Len (Str (Trim (SuggestCount%))))
  211.         ActiveName$ = ActiveName$ + Trim(Str(SuggestCount%))
  212.         SuggestCount% = SuggestCount% + 1
  213.     Wend
  214.     SuggestTableTitleStr$ = ActiveName$
  215. End Function
  216.  
  217. Function CheckTitleUnique(ByVal DatabaseTitles(), txtNewTitle As Object, _
  218.                      ByVal sErrTitleExist$, sWizardName$) as Boolean
  219. ' Todo: Abfrage ob bin├ñrer oder textueller Vergleich
  220.     If FieldInArray(DatabaseTitles(), Ubound(DatabaseTitles()),TxtNewTitle) Then
  221. '    If (-1 <> StrInStrings%(DatabaseTitles, UCase(txtNewTitle.Text))) Then
  222.         MsgBox (sErrTitleExist$, 64, sWizardName$)
  223.         txtNewTitle.Text = SuggestTitleStr$(DatabaseTitles, txtNewTitle.Text)
  224.         If ("" = txtNewTitle.Text) Then
  225.             txtNewTitle.Text = txtNewTitle.Tag
  226.         Else
  227.             txtNewTitle.Tag = txtNewTitle.Text
  228.         End If
  229.         txtNewTitle.SetFocus()
  230.         txtNewTitle.tag = "ERROR"
  231.         CheckTitleUnique = False
  232.         Exit Function
  233.     End If
  234.     CheckTitleUnique = True
  235. End Function
  236.  
  237. 'Function CheckTableTitleUnique(ByVal DatabaseTitles As Strings, txtNewTitle As Object, _
  238. '                     ByVal sErrTitleExist$, sWizardName$) As Boolean
  239.  
  240. '    CheckTableTitleUnique = True
  241. '    If (-1 <> StrInStrings%(DatabaseTitles, UCase(txtNewTitle.Text))) Then
  242. '        MsgBox (sErrTitleExist$, 64, sWizardName$)
  243. '        txtNewTitle.Text = SuggestTableTitleStr$(DatabaseTitles, txtNewTitle.Text)
  244. '        If ("" = txtNewTitle.Text) Then
  245. '            txtNewTitle.Text = txtNewTitle.Tag
  246. '        Else
  247. '            txtNewTitle.Tag = txtNewTitle.Text
  248. '        End If
  249. '        txtNewTitle.SetFocus()
  250. '        txtNewTitle.tag = "ERROR"
  251. '        CheckTableTitleUnique = False
  252. '    End If
  253. 'End Function
  254.  
  255. 'Sub CheckFullTitleUnique(ByVal DatabaseTitles As Strings, txtNewTitle As Object, _
  256. '                     ByVal sErrTitleExist$, sWizardName$, vDB as Variant)
  257. '
  258. '    Dim sFullName as String
  259. '    sFullName = UCase(GetFullTableName (txtNewTitle.Text, vDB))
  260. '    If (-1 <> StrInStrings%(DatabaseTitles, sFullName)) Then
  261. '        MsgBox (sErrTitleExist$, 64, sWizardName$)
  262. '        txtNewTitle.Text = SuggestTitleStr$(DatabaseTitles, txtNewTitle.Text)
  263. '        If ("" = txtNewTitle.Text) Then
  264. '            txtNewTitle.Text = txtNewTitle.Tag
  265. '        Else
  266. '            txtNewTitle.Tag = txtNewTitle.Text
  267. '        End If
  268. '        txtNewTitle.SetFocus()
  269. '        txtNewTitle.tag = "ERROR"
  270. '    End If
  271. 'End Sub
  272.  
  273. Sub FixODBCBug()
  274.     On Error Resume Next
  275.     Dim nTempValue
  276.     nTempValue = Application.DataColumnNumber()
  277. End Sub
  278.  
  279.  
  280. '    Dialog tools
  281. Sub PaintPicOnPreview(Preview As Object, ByVal Filename$, ByVal Width%, ByVal Height%, ByVal bDrawFrame%)
  282.  
  283.     Dim Bitmap As Object
  284.     Dim TWIPSPicHeight%, TWIPSPicWidth%, StartX%, StartY%
  285.     Dim bFittingX%, bFittingY%, DlgWidth%, DlgHeight%, nXMove%, nYMove%
  286.     Dim x#, y#
  287.  
  288.     Set Bitmap = LoadPicture (FileName$)
  289.  
  290.     If (1 = GetGUIType()) Then
  291.         DlgHeight% = CInt (Preview.Height * GetDialogZoomFactorY (Preview.Height))
  292.         DlgWidth% = CInt (Preview.Width * GetDialogZoomFactorX (Preview.Width))
  293.         nXMove% = TwipsPerPixelX() * 3
  294.         nYMove% = TwipsPerPixelX() * 3
  295.     Else
  296.         DlgHeight% = CInt ((Preview.Height - TwipsPerPixelY() * 3) * GetDialogZoomFactorY (Preview.Height))
  297.         DlgWidth% = CInt ((Preview.Width - TwipsPerPixelX() * 3) * GetDialogZoomFactorX (Preview.Width))
  298.         nXMove% = 0
  299.         nYMove% = 0
  300.     End If
  301.  
  302.     TWIPSPicWidth% = TwipsPerPixelX() * Width%
  303.     TWIPSPicHeight% = TwipsPerPixelY() * Height%
  304.  
  305.     If (Not ((TWIPSPicWidth% <= DlgWidth%) And (TWIPSPicHeight% <= DlgHeight%))) Then
  306.         x# = (TWIPSPicWidth% / DlgWidth%)
  307.         y# = (TWIPSPicHeight% / DlgHeight%)
  308.         If (x# > y#) Then
  309.             TWIPSPicWidth% = CInt (DlgWidth%)
  310.             TWIPSPicHeight% = CInt (TWIPSPicHeight% / x#)
  311.         Else
  312.             TWIPSPicHeight% = CInt (DlgHeight%)
  313.             TWIPSPicWidth% = CInt (TWIPSPicWidth% / y#)
  314.         End If
  315.     End If
  316.  
  317.     StartX% = CInt ((DlgWidth% / 2) - (TWIPSPicWidth% / 2)) - nXMove%
  318.     StartY% = CInt ((DlgHeight% / 2) - (TWIPSPicHeight% / 2)) - nYMove%
  319.  
  320.     Preview.Cls ()
  321.     Preview.DrawPicture (Bitmap, StartX%, StartY%, StartX% + TWIPSPicWidth%, StartY% + TWIPSPicHeight%)
  322.     IF (bDrawFrame%) Then
  323.         Preview.DrawBox (StartX%, StartY%, StartX% + TWIPSPicWidth%, StartY% + TWIPSPicHeight%)
  324.     End If
  325.  
  326. End Sub
  327.  
  328.  
  329. Function SelectionInListBox%(lb As Object)
  330.     Dim n%,count%
  331.     n%=0
  332.     count%=0
  333.  
  334.     For n%=0 To lb.ListCount()-1
  335.         If lb.Selected(n%) Then
  336.             count% = count% + 1
  337.         End If
  338.     Next
  339.     SelectionInListBox% = Count%
  340. End Function
  341.  
  342.  
  343.  
  344. Sub CopyList_To_Combo(listbox1, listbox2, combobox, ByVal FirstEntry$)
  345.     Dim nCount%
  346.  
  347.     combobox.Clear()
  348.     If (FirstEntry$<>"") Then
  349.         combobox.AddItem(FirstEntry$)
  350.     End If
  351.     For nCount%=0 To listbox1.ListCount()-1
  352.         combobox.AddItem(listbox1.List(nCount%))
  353.     Next
  354.     For nCount%=0 To listbox2.ListCount()-1
  355.         combobox.AddItem(listbox2.List(nCount%))
  356.     Next
  357.     combobox.ListIndex = 0
  358. End Sub
  359.  
  360.  
  361. Sub MoveOrderedSelectedListbox(lbDest As Object, lbSource As Object, OriginalOrder As Strings, ByVal bMoveAll%)
  362.  
  363.     Dim nOriginalPos%, nSourcePos%, nSourceCount%
  364.     Dim bFound%, nFirstSelected%
  365.     Dim sSelected$, sActField$
  366.  
  367.  
  368.     If (bMoveAll%) Then
  369.  
  370.         nFirstSelected% = -1
  371.  
  372.         lbSource.Clear()
  373.         lbDest.Clear()
  374.  
  375.         For nSourceCount% = 1 To OriginalOrder.Count()
  376.             lbDest.AddItem(OriginalOrder.Item(nSourceCount%))
  377.         Next
  378.     Else
  379.  
  380.         nFirstSelected% = -1
  381.  
  382.         For nSourceCount% = 0 To lbSource.ListCount() - 1
  383.  
  384.             nSourcePos% = 0
  385.             nOriginalPos% = 1
  386.  
  387.             If (lbSource.Selected (nSourceCount%)) Then
  388.  
  389.                 If (-1 = nFirstSelected%) Then nFirstSelected% = nSourceCount%
  390.  
  391.                 bFound% = False
  392.                 sSelected$ = lbSource.List(nSourceCount%)
  393.  
  394.                 While ((Not bFound%) And (nOriginalPos% <= OriginalOrder.Count()))
  395.  
  396.                     sActField$ = OriginalOrder.Item(nOriginalPos%)
  397.  
  398.                     If (sSelected$ = sActField$) Then
  399.                         bFound% = True
  400.                         lbDest.AddItem(sSelected$, nSourcePos%)
  401.                     Else
  402.                         If (nSourcePos% < lbDest.ListCount()) Then
  403.                             If (lbDest.List(nSourcePos%) = sActField$) Then
  404.                                 nSourcePos% = nSourcePos% + 1
  405.                             End If
  406.                         End If
  407.                     End If
  408.  
  409.                     If (Not bFound%) Then nOriginalPos% = nOriginalPos% + 1
  410.                 Wend
  411.             End If
  412.         Next
  413.  
  414.         Call RemoveSelected (lbSource)
  415.     End If
  416.  
  417.     '    set selection
  418.     Call SetNewSelection(lbSource, nFirstSelected%)
  419. End Sub
  420.  
  421. Function GetIndexOfItem%(lb As Object, ByVal FindValue$)
  422.     Dim i%
  423.     For i%=0 To lb.ListCount()-1
  424.         If (lb.List(i%)=FindValue$) Then
  425.             GetIndexOfItem% = i%
  426.             Exit Function
  427.         End If
  428.     Next
  429.     '    Not found
  430.     GetIndexOfItem% = -1
  431. End Function
  432.  
  433. Function GetSelectionIndexOfListBox%(lb As Object)
  434.     ' get first selection in listbox
  435.     Dim nCount%
  436.     For nCount% = 0 To lb.ListCount() - 1
  437.         If (lb.Selected(nCount%)) Then
  438.             GetSelectionIndexOfListBox% = nCount%
  439.             Exit Function
  440.         End If
  441.     Next
  442.     GetSelectionIndexOfListBox% = -1
  443. End Function
  444.  
  445. Function ItemInListBox%(lb As Object, ByVal itemName$)
  446.  
  447.     Dim n%
  448.     For n%=0 To lb.ListCount()-1
  449.         If (lb.List(n%)=itemName$) Then
  450.             ItemInListBox% = True
  451.             Exit Function
  452.         End If
  453.     Next
  454.     ItemInListBox% = False
  455. End Function
  456.  
  457. Function GetSelectionsInListBox%(lb As Object)
  458.  
  459.     Dim nResult%, nCount%
  460.  
  461.     nResult% = 0
  462.  
  463.     For nCount% = 0 To lb.ListCount() - 1
  464.  
  465.         If lb.Selected(nCount%) Then
  466.             nResult% = nResult% + 1
  467.         End If
  468.     Next
  469.  
  470.     GetSelectionsInListBox% = nResult%
  471. End Function
  472.  
  473.  
  474. Sub CopyOrderdItemsListBox(lbDest As Object, lbSource As Object, OriginalOrder As Strings)
  475.  
  476.     Dim nCount%, sSelected$
  477.  
  478.     '   Select
  479.     If (-1 < lbDest.ListIndex()) Then
  480.         sSelected$ = lbDest.List(lbDest.ListIndex())
  481.     Else
  482.         sSelected$ = ""
  483.     End If
  484.  
  485.     '   Copy
  486.     lbDest.Clear()
  487.     For nCount% = 1 To OriginalOrder.Count()
  488.         lbDest.AddItem(OriginalOrder.Item(nCount%))
  489.     Next
  490.  
  491.     '   Delete Source
  492.     lbSource.Clear()
  493.  
  494.     '   If there eas a Selection, it will be set
  495.     If ("" <> sSelected$) Then
  496.         nCount% = 0
  497.         While (sSelected$ <> lbDest.List(nCount%))
  498.             nCount% = nCount% + 1
  499.         Wend
  500.         lbDest.Selected(nCount%) = True
  501.     End If
  502.  
  503. End Sub
  504.  
  505.  
  506.  
  507. </script:module>