Index: ChangeLog
===================================================================
--- ChangeLog	(revision 2121)
+++ ChangeLog	(working copy)
@@ -139,6 +139,29 @@
           def _addRepeatSegment(segment, line, respectPunctuation=True):
           def adjustForRepeats(line):
 
+        * src/orca/scripts/gedit.py:
+          src/orca/scripts/planner.py:
+          src/orca/scripts/liferea.py:
+          src/orca/scripts/Thunderbird.py:
+          src/orca/scripts/acroread.py:
+          src/orca/scripts/gnome-search-tool.py:
+          src/orca/scripts/Evolution.py:
+          src/orca/scripts/StarOffice.py:
+          src/orca/util.py:
+          src/orca/speechgenerator.py:
+          src/orca/default.py:
+          src/orca/Gecko.py:
+          src/orca/where_am_I.py:
+          src/orca/braillegenerator.py:
+          Another partial fix for bug #395548.
+
+          Moved:
+          def __hasLabelForRelation(label):
+          def __isLabeling(label, object):
+          def getDisplayedLabel(object):
+          def isDesiredFocusedItem(obj, rolesList):
+          def speakMisspeltWord(allTokens, badWord):
+
 2007-03-05  Rich Burridge <rich.burridge@sun.com>
 
         * src/orca/debug.py:
Index: src/orca/scripts/gedit.py
===================================================================
--- src/orca/scripts/gedit.py	(revision 2121)
+++ src/orca/scripts/gedit.py	(working copy)
@@ -182,7 +182,7 @@
                 tokens = text.split()
                 allTokens += tokens
 
-            util.speakMisspeltWord(allTokens, badWord)
+            self.speakMisspeltWord(allTokens, badWord)
 
             # Save misspelt word information for comparison purposes
             # next time around.
@@ -210,9 +210,9 @@
                      rolenames.ROLE_DIALOG,
                      rolenames.ROLE_APPLICATION]
 
-        if (util.isDesiredFocusedItem(obj, rolesList1) \
+        if (self.isDesiredFocusedItem(obj, rolesList1) \
             and obj.name == _("Find")) \
-            or (util.isDesiredFocusedItem(obj, rolesList2) \
+            or (self.isDesiredFocusedItem(obj, rolesList2) \
                 and obj.parent.parent.parent.parent.name == _("Find")):
             return True
         else:
@@ -256,7 +256,7 @@
                      rolenames.ROLE_PAGE_TAB,
                      rolenames.ROLE_PAGE_TAB_LIST,
                      rolenames.ROLE_SPLIT_PANE]
-        if util.isDesiredFocusedItem(event.source, rolesList):
+        if self.isDesiredFocusedItem(event.source, rolesList):
             debug.println(self.debugLevel,
                           "gedit.locusOfFocusChanged - text area.")
 
@@ -280,7 +280,7 @@
                      rolenames.ROLE_PANEL,
                      rolenames.ROLE_FILLER,
                      rolenames.ROLE_FRAME]
-        if util.isDesiredFocusedItem(event.source, rolesList):
+        if self.isDesiredFocusedItem(event.source, rolesList):
             frame = event.source.parent.parent.parent.parent
             if frame.name.startswith(_("Check Spelling")):
                 debug.println(self.debugLevel,
@@ -334,7 +334,7 @@
                      rolenames.ROLE_PANEL,
                      rolenames.ROLE_FILLER,
                      rolenames.ROLE_FRAME]
-        if util.isDesiredFocusedItem(event.source, rolesList):
+        if self.isDesiredFocusedItem(event.source, rolesList):
             frame = event.source.parent.parent.parent
             if frame.name.startswith(_("Check Spelling")):
                 debug.println(self.debugLevel,
Index: src/orca/scripts/planner.py
===================================================================
--- src/orca/scripts/planner.py	(revision 2121)
+++ src/orca/scripts/planner.py	(working copy)
@@ -62,7 +62,7 @@
         self._debugGenerator("_getBrailleRegionsForRadioButton", obj)
 
         text = ""
-        text = util.appendString(text, util.getDisplayedLabel(obj))
+        text = util.appendString(text, self.getDisplayedLabel(obj))
         text = util.appendString(text, self.getDisplayedText(obj))
 
         # First special toggle button is the one in the toolbar and
@@ -73,7 +73,7 @@
         #
         roleList = [rolenames.ROLE_TOGGLE_BUTTON, rolenames.ROLE_TOOL_BAR]
 
-        if util.isDesiredFocusedItem(obj, roleList) and not obj.name:
+        if self.isDesiredFocusedItem(obj, roleList) and not obj.name:
             text += _("Display more options")
 
         # Second special case is each one of the four graphics toggle
@@ -88,7 +88,7 @@
                      rolenames.ROLE_FILLER,\
                      rolenames.ROLE_PANEL,\
                      rolenames.ROLE_PANEL]
-        if util.isDesiredFocusedItem(obj, rolesList):
+        if self.isDesiredFocusedItem(obj, rolesList):
             debug.println(debug.LEVEL_FINEST,
                           "planner.onFocus - main window: " \
                           + "one of the four graphic toggle buttons.")
@@ -133,7 +133,7 @@
         roleList=[rolenames.ROLE_TOGGLE_BUTTON,\
                   rolenames.ROLE_TOOL_BAR]
 
-        if util.isDesiredFocusedItem(obj, roleList) and not obj.name:
+        if self.isDesiredFocusedItem(obj, roleList) and not obj.name:
             if not already_focused:
                 tmp.append(_("Display more options"))
                 tmp.extend(self._getDefaultSpeech(obj, already_focused))
@@ -163,7 +163,7 @@
                     rolenames.ROLE_FILLER,\
                     rolenames.ROLE_PANEL,\
                     rolenames.ROLE_PANEL]
-        if util.isDesiredFocusedItem(obj, roleList):
+        if self.isDesiredFocusedItem(obj, roleList):
             debug.println(debug.LEVEL_FINEST,
                           "planner.onFocus - main window: " \
                           + "one of the four graphic toggle buttons.")
Index: src/orca/scripts/liferea.py
===================================================================
--- src/orca/scripts/liferea.py	(revision 2121)
+++ src/orca/scripts/liferea.py	(working copy)
@@ -75,7 +75,7 @@
         # We only speak the statusbar's changes when the application is 
         # with the focus and is the "work online/offline button is focused.
         #
-        if util.isDesiredFocusedItem(orca_state.locusOfFocus, rolesList):
+        if self.isDesiredFocusedItem(orca_state.locusOfFocus, rolesList):
             speech.stop()
             speech.speak(event.source.name)
             braille.displayMessage(event.source.name)
@@ -113,7 +113,7 @@
         # hierarchically located in the main window of the application 
         # (frame), inside a filler and inside another filler.
         #
-        if util.isDesiredFocusedItem(event.source, rolesList):
+        if self.isDesiredFocusedItem(event.source, rolesList):
              # If we are focusing this button we construct a utterance and 
              # a braille region to speak/braille "online/offline button".
              # Here we declare utterances and add the localized string 
Index: src/orca/scripts/Thunderbird.py
===================================================================
--- src/orca/scripts/Thunderbird.py	(revision 2121)
+++ src/orca/scripts/Thunderbird.py	(working copy)
@@ -114,7 +114,7 @@
             # Append the text and label. Skip displayed text
             # that starts with "chrome://"
             text = self.getDisplayedText(parent)
-            label = util.getDisplayedLabel(parent)
+            label = self.getDisplayedLabel(parent)
             if text and (text != label) and len(text) \
                 and (not text.startswith("chrome://")):
                 utterances.append(text)
Index: src/orca/scripts/acroread.py
===================================================================
--- src/orca/scripts/acroread.py	(revision 2121)
+++ src/orca/scripts/acroread.py	(working copy)
@@ -156,7 +156,7 @@
                  rolenames.ROLE_UNKNOWN, \
                  rolenames.ROLE_UNKNOWN, \
                  rolenames.ROLE_TABLE]
-    if util.isDesiredFocusedItem(obj, rolesList):
+    if self.isDesiredFocusedItem(obj, rolesList):
         table = obj.parent.parent.parent
         rows = table.childCount
         columns = table.child(0).childCount
@@ -206,7 +206,7 @@
     try:
         while obj.role != rolenames.ROLE_DRAWING_AREA:
             obj = obj.parent
-        if util.isDesiredFocusedItem(obj, rolesList):
+        if self.isDesiredFocusedItem(obj, rolesList):
             inFindToolbar = True
             findToolbarName = self.getFrame(obj).name
     except:
Index: src/orca/scripts/gnome-search-tool.py
===================================================================
--- src/orca/scripts/gnome-search-tool.py	(revision 2121)
+++ src/orca/scripts/gnome-search-tool.py	(working copy)
@@ -124,7 +124,7 @@
         # search progresses, regularly inform the user of this by speaking
         # "Searching" (assuming the search tool has focus).
         #
-        if util.isDesiredFocusedItem(event.source, rolesList) and \
+        if self.isDesiredFocusedItem(event.source, rolesList) and \
            event.source.name == _("Stop") and visible:
             debug.println(self.debugLevel,
                           "gnome-search-tool.onNameChanged - " \
@@ -148,7 +148,7 @@
         # have just stopped a search. Inform the user that the search is
         # complete and tell them how many files were found.
         #
-        if util.isDesiredFocusedItem(event.source, rolesList) and \
+        if self.isDesiredFocusedItem(event.source, rolesList) and \
            event.source.name == _("Find") and visible and self.searching:
             debug.println(self.debugLevel,
                           "gnome-search-tool.onNameChanged - " \
Index: src/orca/scripts/Evolution.py
===================================================================
--- src/orca/scripts/Evolution.py	(revision 2121)
+++ src/orca/scripts/Evolution.py	(working copy)
@@ -379,7 +379,7 @@
         rolesList = [rolenames.ROLE_TEXT, \
                      rolenames.ROLE_PANEL, \
                      rolenames.ROLE_UNKNOWN]
-        if util.isDesiredFocusedItem(event.source, rolesList):
+        if self.isDesiredFocusedItem(event.source, rolesList):
             debug.println(self.debugLevel,
                           "evolution.locusOfFocusChanged - mail view: " \
                           + "current message pane: " \
@@ -427,7 +427,7 @@
                      rolenames.ROLE_PANEL, \
                      rolenames.ROLE_TABLE_CELL]
         if settings.readTableCellRow \
-            and (util.isDesiredFocusedItem(event.source, rolesList)):
+            and (self.isDesiredFocusedItem(event.source, rolesList)):
             debug.println(self.debugLevel,
                           "evolution.locusOfFocusChanged - mail view: " \
                           + "current message pane: " \
@@ -478,7 +478,7 @@
         rolesList = [rolenames.ROLE_TABLE_CELL, \
                      rolenames.ROLE_TREE_TABLE]
         if settings.readTableCellRow \
-            and (util.isDesiredFocusedItem(event.source, rolesList)):
+            and (self.isDesiredFocusedItem(event.source, rolesList)):
             debug.println(self.debugLevel,
                           "evolution.locusOfFocusChanged - mail view: " \
                           + "message header list.")
@@ -662,7 +662,7 @@
 
         rolesList = [rolenames.ROLE_CALENDAR_EVENT, \
                      rolenames.ROLE_CALENDAR_VIEW]
-        if util.isDesiredFocusedItem(event.source, rolesList):
+        if self.isDesiredFocusedItem(event.source, rolesList):
             debug.println(self.debugLevel,
                           "evolution.locusOfFocusChanged - calendar view: " \
                           + "day view: tabbing to day with appts.")
@@ -729,7 +729,7 @@
         rolesList = [rolenames.ROLE_UNKNOWN, \
                      rolenames.ROLE_TABLE, \
                      rolenames.ROLE_CALENDAR_VIEW]
-        if util.isDesiredFocusedItem(event.source, rolesList):
+        if self.isDesiredFocusedItem(event.source, rolesList):
             debug.println(self.debugLevel,
                       "evolution.locusOfFocusChanged - calendar view: " \
                       + "day view: moving with arrow keys.")
@@ -806,7 +806,7 @@
                      rolenames.ROLE_TABLE, \
                      rolenames.ROLE_UNKNOWN, \
                      rolenames.ROLE_SCROLL_PANE]
-        if util.isDesiredFocusedItem(event.source, rolesList):
+        if self.isDesiredFocusedItem(event.source, rolesList):
             debug.println(self.debugLevel,
                       "evolution.locusOfFocusChanged - preferences dialog: " \
                       + "table cell in options list.")
@@ -841,7 +841,7 @@
                      rolenames.ROLE_FILLER, \
                      rolenames.ROLE_FILLER, \
                      rolenames.ROLE_DIALOG]
-        if util.isDesiredFocusedItem(event.source, rolesList):
+        if self.isDesiredFocusedItem(event.source, rolesList):
             debug.println(self.debugLevel,
                           "evolution.locusOfFocusChanged - mail insert " \
                           + "attachment dialog: unlabelled button.")
@@ -869,7 +869,7 @@
                      rolenames.ROLE_PANEL, \
                      rolenames.ROLE_PANEL, \
                      rolenames.ROLE_SCROLL_PANE]
-        if util.isDesiredFocusedItem(event.source, rolesList):
+        if self.isDesiredFocusedItem(event.source, rolesList):
             debug.println(self.debugLevel,
                           "evolution.locusOfFocusChanged - mail " \
                           + "compose window: message area.")
@@ -901,7 +901,7 @@
                     rolenames.ROLE_PANEL, \
                     rolenames.ROLE_FILLER, \
                     rolenames.ROLE_DIALOG]
-        if util.isDesiredFocusedItem(event.source, rolesList):
+        if self.isDesiredFocusedItem(event.source, rolesList):
             debug.println(self.debugLevel,
                       "evolution.locusOfFocusChanged - spell checking dialog.")
 
@@ -943,7 +943,7 @@
                     tokens = text.split()
                     allTokens += tokens
 
-                util.speakMisspeltWord(allTokens, badWord)
+                self.speakMisspeltWord(allTokens, badWord)
                 return
 
         # 10) Mail view: message area - attachments.
@@ -967,7 +967,7 @@
                     rolenames.ROLE_TABLE_CELL, \
                     rolenames.ROLE_TABLE, \
                     rolenames.ROLE_PANEL]
-        if util.isDesiredFocusedItem(event.source, rolesList):
+        if self.isDesiredFocusedItem(event.source, rolesList):
             debug.println(self.debugLevel,
                           "evolution.locusOfFocusChanged - " \
                           + "mail message area attachments.")
Index: src/orca/scripts/StarOffice.py
===================================================================
--- src/orca/scripts/StarOffice.py	(revision 2121)
+++ src/orca/scripts/StarOffice.py	(working copy)
@@ -174,7 +174,7 @@
                  rolenames.ROLE_ROOT_PANE, \
                  rolenames.ROLE_FRAME, \
                  rolenames.ROLE_APPLICATION]
-    if util.isDesiredFocusedItem(obj, rolesList):
+    if self.isDesiredFocusedItem(obj, rolesList):
         # We've found a table cell with the correct hierarchy. Now check
         # that we are in a spreadsheet as opposed to the writer application.
         # See bug #382408.
@@ -1026,7 +1026,7 @@
         text = self.getText(paragraph[0], 0, -1)
         allTokens = text.split()
 
-        util.speakMisspeltWord(allTokens, badWord)
+        self.speakMisspeltWord(allTokens, badWord)
 
         # Save misspelt word information for comparison purposes next
         # time around.
@@ -1193,7 +1193,7 @@
                      rolenames.ROLE_PANEL, \
                      rolenames.ROLE_ROOT_PANE, \
                      rolenames.ROLE_FRAME]
-        if util.isDesiredFocusedItem(event.source, rolesList):
+        if self.isDesiredFocusedItem(event.source, rolesList):
             debug.println(self.debugLevel,
                   "StarOffice.locusOfFocusChanged - Writer: text paragraph.")
 
@@ -1259,7 +1259,7 @@
                      rolenames.ROLE_OPTION_PANE, \
                      rolenames.ROLE_DIALOG, \
                      rolenames.ROLE_APPLICATION]
-        if util.isDesiredFocusedItem(event.source, rolesList):
+        if self.isDesiredFocusedItem(event.source, rolesList):
             pane = event.source.parent
             if pane.name.startswith(_("Spellcheck:")):
                 debug.println(self.debugLevel,
@@ -1284,7 +1284,7 @@
                          rolenames.ROLE_OPTION_PANE, \
                          rolenames.ROLE_DIALOG, \
                          rolenames.ROLE_APPLICATION]
-            if util.isDesiredFocusedItem(event.source, rolesList):
+            if self.isDesiredFocusedItem(event.source, rolesList):
                 debug.println(self.debugLevel,
                     "StarOffice.locusOfFocusChanged - Setup dialog: " \
                     + "License Agreement screen: Scroll Down button.")
@@ -1299,7 +1299,7 @@
                          rolenames.ROLE_OPTION_PANE, \
                          rolenames.ROLE_DIALOG, \
                          rolenames.ROLE_APPLICATION]
-            if util.isDesiredFocusedItem(event.source, rolesList):
+            if self.isDesiredFocusedItem(event.source, rolesList):
                 debug.println(self.debugLevel,
                     "StarOffice.locusOfFocusChanged - Setup dialog: " \
                     + "License Agreement screen: accept button.")
@@ -1312,7 +1312,7 @@
                          rolenames.ROLE_OPTION_PANE, \
                          rolenames.ROLE_DIALOG, \
                          rolenames.ROLE_APPLICATION]
-            if util.isDesiredFocusedItem(event.source, rolesList):
+            if self.isDesiredFocusedItem(event.source, rolesList):
                 debug.println(self.debugLevel,
                     "StarOffice.locusOfFocusChanged - Setup dialog: " \
                     + "Personal Data: Transfer Personal Data check box.")
@@ -1325,7 +1325,7 @@
                         rolenames.ROLE_OPTION_PANE, \
                         rolenames.ROLE_DIALOG, \
                         rolenames.ROLE_APPLICATION]
-            if util.isDesiredFocusedItem(event.source, rolesList) and \
+            if self.isDesiredFocusedItem(event.source, rolesList) and \
                event.source.name == _("First name"):
                 debug.println(self.debugLevel,
                     "StarOffice.locusOfFocusChanged - Setup dialog: " \
@@ -1353,7 +1353,7 @@
                         rolenames.ROLE_OPTION_PANE, \
                         rolenames.ROLE_DIALOG, \
                         rolenames.ROLE_APPLICATION]
-            if util.isDesiredFocusedItem(event.source, rolesList):
+            if self.isDesiredFocusedItem(event.source, rolesList):
                 debug.println(self.debugLevel,
                     "StarOffice.locusOfFocusChanged - Setup dialog: " \
                     + "Registration: Register Now radio button.")
@@ -1372,7 +1372,7 @@
                      rolenames.ROLE_ROOT_PANE, \
                      rolenames.ROLE_FRAME, \
                      rolenames.ROLE_APPLICATION]
-        if util.isDesiredFocusedItem(event.source, rolesList):
+        if self.isDesiredFocusedItem(event.source, rolesList):
             debug.println(self.debugLevel, "StarOffice.locusOfFocusChanged - " \
                           + "Calc: cell editor.")
             return
@@ -1392,7 +1392,7 @@
                      rolenames.ROLE_FRAME, \
                      rolenames.ROLE_APPLICATION]
 
-        if util.isDesiredFocusedItem(event.source, rolesList) \
+        if self.isDesiredFocusedItem(event.source, rolesList) \
             and (not event.source.name or len(event.source.name) == 0):
             debug.println(self.debugLevel, "StarOffice.locusOfFocusChanged - " \
                           + "Calc: name box.")
@@ -1481,7 +1481,7 @@
         rolesList = [rolenames.ROLE_OPTION_PANE, \
                      rolenames.ROLE_DIALOG, \
                      rolenames.ROLE_APPLICATION]
-        if util.isDesiredFocusedItem(event.source, rolesList):
+        if self.isDesiredFocusedItem(event.source, rolesList):
             pane = event.source
             if pane.name.startswith(_("Spellcheck:")):
                 debug.println(self.debugLevel,
@@ -1675,7 +1675,7 @@
                      rolenames.ROLE_ROOT_PANE, \
                      rolenames.ROLE_FRAME, \
                      rolenames.ROLE_APPLICATION]
-        if util.isDesiredFocusedItem(event.source, rolesList):
+        if self.isDesiredFocusedItem(event.source, rolesList):
             if orca_state.locusOfFocus.role == rolenames.ROLE_TABLE_CELL:
                 cell = orca_state.locusOfFocus
 
Index: src/orca/util.py
===================================================================
--- src/orca/util.py	(revision 2121)
+++ src/orca/util.py	(working copy)
@@ -111,57 +111,6 @@
     else:
         return newText
 
-def __hasLabelForRelation(label):
-    """Check if label has a LABEL_FOR relation
-
-    Arguments:
-    - label: the label in question
-
-    Returns TRUE if label has a LABEL_FOR relation.
-    """
-    if (not label) or (label.role != rolenames.ROLE_LABEL):
-        return False
-
-    relations = label.relations
-
-    for relation in relations:
-        if relation.getRelationType() \
-               == atspi.Accessibility.RELATION_LABEL_FOR:
-            return True
-
-    return False
-
-
-def __isLabeling(label, object):
-    """Check if label is connected via  LABEL_FOR relation with object
-
-    Arguments:
-    - object: the object in question
-    - labeled: the label in question
-
-    Returns TRUE if label has a relation LABEL_FOR for object.
-    """
-
-    if (not object) \
-       or (not label) \
-       or (label.role != rolenames.ROLE_LABEL):
-        return False
-
-    relations = label.relations
-    if not relations:
-        return False
-
-    for relation in relations:
-        if relation.getRelationType() \
-               == atspi.Accessibility.RELATION_LABEL_FOR:
-
-            for i in range(0, relation.getNTargets()):
-                target = atspi.Accessible.makeAccessible(relation.getTarget(i))
-                if target == object:
-                    return True
-
-    return False
-
 def getUnicodeCurrencySymbols():
     """Return a list of the unicode currency symbols, populating the list
     if this is the first time that this routine has been called.
@@ -201,90 +150,6 @@
 
     return _unicodeCurrencySymbols
 
-def getDisplayedLabel(object):
-    """If there is an object labelling the given object, return the
-    text being displayed for the object labelling this object.
-    Otherwise, return None.
-
-    Argument:
-    - object: the object in question
-
-    Returns the string of the object labelling this object, or None
-    if there is nothing of interest here.
-    """
-
-    # For some reason, some objects are labelled by the same thing
-    # more than once.  Go figure, but we need to check for this.
-    #
-    label = None
-    relations = object.relations
-    allTargets = []
-
-    for relation in relations:
-        if relation.getRelationType() \
-               == atspi.Accessibility.RELATION_LABELLED_BY:
-
-            # The object can be labelled by more than one thing, so we just
-            # get all the labels (from unique objects) and append them
-            # together.  An example of such objects live in the "Basic"
-            # page of the gnome-accessibility-keyboard-properties app.
-            # The "Delay" and "Speed" objects are labelled both by
-            # their names and units.
-            #
-            for i in range(0, relation.getNTargets()):
-                target = atspi.Accessible.makeAccessible(relation.getTarget(i))
-                if not target in allTargets:
-                    allTargets.append(target)
-                    label = appendString(label, getDisplayedText(target))
-
-    # [[[TODO: HACK - we've discovered oddness in hierarchies such as
-    # the gedit Edit->Preferences dialog.  In this dialog, we have
-    # labeled groupings of objects.  The grouping is done via a FILLER
-    # with two children - one child is the overall label, and the
-    # other is the container for the grouped objects.  When we detect
-    # this, we add the label to the overall context.
-    #
-    # We are also looking for objects which have a PANEL or a FILLER as
-    # parent, and its parent has more children. Through these children,
-    # a potential label with LABEL_FOR relation may exists. We want to
-    # present this label.
-    # This case can be seen in FileChooserDemo application, in Open dialog
-    # window, the line with "Look In" label, a combobox and some presentation
-    # buttons.]]]
-    #
-    if not label:
-
-        potentialLabel = None
-        useLabel = False
-        if ((object.role == rolenames.ROLE_FILLER) \
-                or (object.role == rolenames.ROLE_PANEL)) \
-            and (object.childCount == 2):
-
-            potentialLabel = object.child(0)
-            secondChild = object.child(1)
-            useLabel = potentialLabel.role == rolenames.ROLE_LABEL \
-                    and ((secondChild.role == rolenames.ROLE_FILLER) \
-                            or (secondChild.role == rolenames.ROLE_PANEL)) \
-                    and not __hasLabelForRelation(potentialLabel)
-        else:
-            parent = object.parent
-            if parent and \
-                ((parent.role == rolenames.ROLE_FILLER) \
-                        or (parent.role == rolenames.ROLE_PANEL)):
-                for i in range (0, parent.childCount):
-                    try:
-                        potentialLabel = parent.child(i)
-                        useLabel = __isLabeling(potentialLabel, object)
-                        if useLabel:
-                            break
-                    except:
-                        pass
-
-        if useLabel and potentialLabel:
-            label = potentialLabel.name
-
-    return label
-
 def getRealActiveDescendant(obj):
     """Given an object that should be a child of an object that
     manages its descendants, return the child that is the real
@@ -386,52 +251,3 @@
     else:
         orca_state.clickCount = 0
     return orca_state.clickCount+1
-
-def isDesiredFocusedItem(obj, rolesList):
-    """Called to determine if the given object and it's hierarchy of
-       parent objects, each have the desired roles.
-
-    Arguments:
-    - obj: the accessible object to check.
-    - rolesList: the list of desired roles for the components and the
-      hierarchy of its parents.
-
-    Returns True if all roles match.
-    """
-
-    current = obj
-    for i in range(0, len(rolesList)):
-        if (current == None) or (current.role != rolesList[i]):
-            return False
-        current = current.parent
-
-    return True
-
-def speakMisspeltWord(allTokens, badWord):
-    """Called by various spell checking routine to speak the misspelt word,
-       plus the context that it is being used in.
-
-    Arguments:
-    - allTokens: a list of all the words.
-    - badWord: the misspelt word.
-    """
-
-    # Create an utterance to speak consisting of the misspelt
-    # word plus the context where it is used (upto five words
-    # to either side of it).
-    #
-    for i in range(0, len(allTokens)):
-        if allTokens[i].startswith(badWord):
-            min = i - 5
-            if min < 0:
-                min = 0
-            max = i + 5
-            if max > (len(allTokens) - 1):
-                max = len(allTokens) - 1
-
-            utterances = [_("Misspelled word: "), badWord, \
-                          _(" Context is ")] + allTokens[min:max+1]
-
-            # Turn the list of utterances into a string.
-            text = " ".join(utterances)
-            speech.speak(text)
Index: src/orca/speechgenerator.py
===================================================================
--- src/orca/speechgenerator.py	(revision 2121)
+++ src/orca/speechgenerator.py	(working copy)
@@ -200,7 +200,7 @@
             return []
 
     def _getSpeechForObjectLabel(self, obj):
-        label = util.getDisplayedLabel(obj)
+        label = self._script.getDisplayedLabel(obj)
         if label:
             return [label]
         else:
@@ -1376,7 +1376,7 @@
         if frame:
             title = frame.name
         if not title:
-            title = util.getDisplayedLabel(obj)
+            title = self._script.getDisplayedLabel(obj)
 
         utterances = [title]
 
@@ -1573,7 +1573,7 @@
                 # Announce the label and text of the object in the hierarchy.
                 #
                 text = self._script.getDisplayedText(parent)
-                label = util.getDisplayedLabel(parent)
+                label = self._script.getDisplayedLabel(parent)
 
                 # Push announcement of cell after text and label.
                 #
@@ -1597,7 +1597,7 @@
             # we add the label to the overall context.]]]
             #
             if parent.role == rolenames.ROLE_FILLER:
-                label = util.getDisplayedLabel(parent)
+                label = self._script.getDisplayedLabel(parent)
                 if label and len (label):
                     utterances.append(label)
 
Index: src/orca/default.py
===================================================================
--- src/orca/default.py	(revision 2121)
+++ src/orca/default.py	(working copy)
@@ -2562,7 +2562,7 @@
                     break
         elif obj and (obj.role == rolenames.ROLE_PANEL):
             text = self.getDisplayedText(obj)
-            label = util.getDisplayedLabel(obj)
+            label = self.getDisplayedLabel(obj)
             if not ((label and len(label)) or (text and len(text))):
                 layoutOnly = True
 
@@ -3452,6 +3452,143 @@
 # here so that they can be customized in application scripts if so desired.
 # 
 
+    def __hasLabelForRelation(self, label):
+        """Check if label has a LABEL_FOR relation
+
+        Arguments:
+        - label: the label in question
+
+        Returns TRUE if label has a LABEL_FOR relation.
+        """
+        if (not label) or (label.role != rolenames.ROLE_LABEL):
+            return False
+
+        relations = label.relations
+
+        for relation in relations:
+            if relation.getRelationType() \
+                   == atspi.Accessibility.RELATION_LABEL_FOR:
+                return True    
+
+        return False
+
+
+    def __isLabeling(self, label, object):
+        """Check if label is connected via  LABEL_FOR relation with object
+
+        Arguments:
+        - object: the object in question
+        - labeled: the label in question
+
+        Returns TRUE if label has a relation LABEL_FOR for object.
+        """
+
+        if (not object) \
+           or (not label) \
+           or (label.role != rolenames.ROLE_LABEL):
+            return False
+
+        relations = label.relations
+        if not relations:
+            return False
+
+        for relation in relations:
+            if relation.getRelationType() \
+                   == atspi.Accessibility.RELATION_LABEL_FOR:
+
+                for i in range(0, relation.getNTargets()):
+                    target = atspi.Accessible.makeAccessible(\
+                                                    relation.getTarget(i))
+                    if target == object:
+                        return True
+
+        return False
+
+    def getDisplayedLabel(self, object):
+        """If there is an object labelling the given object, return the
+        text being displayed for the object labelling this object.
+        Otherwise, return None.
+    
+        Argument:
+        - object: the object in question
+    
+        Returns the string of the object labelling this object, or None
+        if there is nothing of interest here.
+        """
+
+        # For some reason, some objects are labelled by the same thing
+        # more than once.  Go figure, but we need to check for this.
+        #
+        label = None
+        relations = object.relations
+        allTargets = []
+
+        for relation in relations:
+            if relation.getRelationType() \
+                   == atspi.Accessibility.RELATION_LABELLED_BY:
+
+                # The object can be labelled by more than one thing, so we just
+                # get all the labels (from unique objects) and append them
+                # together.  An example of such objects live in the "Basic"
+                # page of the gnome-accessibility-keyboard-properties app.
+                # The "Delay" and "Speed" objects are labelled both by
+                # their names and units.
+                #
+                for i in range(0, relation.getNTargets()):
+                    target = atspi.Accessible.makeAccessible(\
+                                                       relation.getTarget(i))
+                    if not target in allTargets:
+                        allTargets.append(target)
+                        label = util.appendString(label, self.getDisplayedText(target))
+
+        # [[[TODO: HACK - we've discovered oddness in hierarchies such as
+        # the gedit Edit->Preferences dialog.  In this dialog, we have
+        # labeled groupings of objects.  The grouping is done via a FILLER
+        # with two children - one child is the overall label, and the
+        # other is the container for the grouped objects.  When we detect
+        # this, we add the label to the overall context.
+        #
+        # We are also looking for objects which have a PANEL or a FILLER as
+        # parent, and its parent has more children. Through these children,
+        # a potential label with LABEL_FOR relation may exists. We want to
+        # present this label.
+        # This case can be seen in FileChooserDemo application, in Open dialog
+        # window, the line with "Look In" label, a combobox and some
+        # presentation buttons.]]]
+        #
+        if not label:
+
+            potentialLabel = None
+            useLabel = False
+            if ((object.role == rolenames.ROLE_FILLER) \
+                    or (object.role == rolenames.ROLE_PANEL)) \
+                and (object.childCount == 2):
+
+                potentialLabel = object.child(0)
+                secondChild = object.child(1)
+                useLabel = potentialLabel.role == rolenames.ROLE_LABEL \
+                        and ((secondChild.role == rolenames.ROLE_FILLER) \
+                                or (secondChild.role == rolenames.ROLE_PANEL)) \
+                        and not self.__hasLabelForRelation(potentialLabel)
+            else:
+                parent = object.parent
+                if parent and \
+                    ((parent.role == rolenames.ROLE_FILLER) \
+                            or (parent.role == rolenames.ROLE_PANEL)):
+                    for i in range (0, parent.childCount):
+                        try:
+                            potentialLabel = parent.child(i)
+                            useLabel = self.__isLabeling(potentialLabel, object)
+                            if useLabel:
+                                break
+                        except:
+                            pass
+
+            if useLabel and potentialLabel:
+                label = potentialLabel.name
+
+        return label
+
     def __getDisplayedTextInComboBox(self, combo):
 
         """Returns the text being displayed in a combo box.  If nothing is
@@ -3579,10 +3716,59 @@
                 if child.role == rolenames.ROLE_LABEL:
                     childText = self.getDisplayedText(child)
                     if childText and len(childText):
-                        displayedText = appendString(displayedText, childText)
+                        displayedText = util.appendString(displayedText, childText)
 
         return displayedText
 
+    def isDesiredFocusedItem(self, obj, rolesList):
+        """Called to determine if the given object and it's hierarchy of
+           parent objects, each have the desired roles.
+
+        Arguments:
+        - obj: the accessible object to check.
+        - rolesList: the list of desired roles for the components and the
+          hierarchy of its parents.
+
+        Returns True if all roles match.
+        """
+
+        current = obj
+        for i in range(0, len(rolesList)):
+            if (current == None) or (current.role != rolesList[i]):
+                return False
+            current = current.parent
+
+        return True
+
+    def speakMisspeltWord(self, allTokens, badWord):
+        """Called by various spell checking routine to speak the misspelt word,
+           plus the context that it is being used in.
+
+        Arguments:
+        - allTokens: a list of all the words.
+        - badWord: the misspelt word.
+        """
+
+        # Create an utterance to speak consisting of the misspelt
+        # word plus the context where it is used (upto five words
+        # to either side of it).
+        #
+        for i in range(0, len(allTokens)):
+            if allTokens[i].startswith(badWord):
+                min = i - 5
+                if min < 0:
+                    min = 0
+                max = i + 5
+                if max > (len(allTokens) - 1):
+                    max = len(allTokens) - 1
+
+                utterances = [_("Misspelled word: "), badWord, \
+                              _(" Context is ")] + allTokens[min:max+1]
+
+                # Turn the list of utterances into a string.
+                text = " ".join(utterances)
+                speech.speak(text)
+
     def textLines(self, obj):
         """Creates a generator that can be used to iterate over each line
         of a text object, starting at the caret offset.
Index: src/orca/Gecko.py
===================================================================
--- src/orca/Gecko.py	(revision 2121)
+++ src/orca/Gecko.py	(working copy)
@@ -170,7 +170,7 @@
         #
         text = ""
         if not self._script.inDocumentContent():
-            text = util.appendString(text, util.getDisplayedLabel(obj))
+            text = util.appendString(text, self.getDisplayedLabel(obj))
             text = util.appendString(text, self.getDisplayedText(obj))
         else:
             isLabelled = False
@@ -221,7 +221,7 @@
         # class - we'll give this thing a name here, and we'll make it
         # be the name of the autocomplete.
         #
-        label = util.getDisplayedLabel(parent)
+        label = self.getDisplayedLabel(parent)
         if not label or not len(label):
             label = parent.name
 
@@ -252,7 +252,7 @@
         # set, we will use it as the label of the combo box.  Otherwise,
         # we'll fall back to the accessible name.
         #
-        label = util.getDisplayedLabel(obj)
+        label = self.getDisplayedLabel(obj)
         if not label:
             label = obj.name
 
@@ -321,7 +321,7 @@
         regions = []
 
         text = ""
-        text = util.appendString(text, util.getDisplayedLabel(obj))
+        text = util.appendString(text, self.getDisplayedLabel(obj))
         text = util.appendString(text, self.getDisplayedText(obj))
 
         # If there's no text for the link, expose part of the
@@ -362,7 +362,7 @@
         regions = []
 
         text = ""
-        text = util.appendString(text, util.getDisplayedLabel(obj))
+        text = util.appendString(text, self.getDisplayedLabel(obj))
         text = util.appendString(text, self.getDisplayedText(obj))
 
         # If there's no text for the link, expose part of the
@@ -456,7 +456,7 @@
         # class - we'll give this thing a name here, and we'll make it
         # be the name of the autocomplete.
         #
-        label = util.getDisplayedLabel(parent)
+        label = self.getDisplayedLabel(parent)
         if not label or not len(label):
             label = parent.name
         utterances.append(label)
@@ -492,7 +492,7 @@
         # set, we will use it as the label of the combo box.  Otherwise,
         # we'll fall back to the accessible name.
         #
-        label = util.getDisplayedLabel(obj)
+        label = self.getDisplayedLabel(obj)
         if not label:
             label = obj.name
 
@@ -706,7 +706,7 @@
             # Finally, put in the text and label (if they exist)
             #
             text = self.getDisplayedText(parent)
-            label = util.getDisplayedLabel(parent)
+            label = self.getDisplayedLabel(parent)
             if text and (text != label) and len(text):
                 utterances.append(text)
             if label and len(label):
@@ -1598,7 +1598,7 @@
                             rolenames.ROLE_PASSWORD_TEXT] \
                 or ((obj.role == rolenames.ROLE_DOCUMENT_FRAME) \
                     and obj.state.count(atspi.Accessibility.STATE_EDITABLE)):
-                label = util.getDisplayedLabel(obj)
+                label = self.getDisplayedLabel(obj)
                 regions = [braille.Text(obj, label)]
                 eol = braille.Region(" $l")
                 regions.append(eol)
@@ -2329,7 +2329,7 @@
         if obj.role in [rolenames.ROLE_IMAGE, rolenames.ROLE_TABLE_CELL]:
             text = self.getDisplayedText(obj)
             if (not text) or (len(text) == 0):
-                text = util.getDisplayedLabel(obj)
+                text = self.getDisplayedLabel(obj)
                 if (not text) or (len(text) == 0):
                     useless = True
 
Index: src/orca/where_am_I.py
===================================================================
--- src/orca/where_am_I.py	(revision 2121)
+++ src/orca/where_am_I.py	(working copy)
@@ -664,7 +664,7 @@
     Returns the label to speak for an object.
     """
     text = ""
-    label = util.getDisplayedLabel(obj)
+    label = orca_state.activeScript.getDisplayedLabel(obj)
     
     if label and label != "None":
         text = _("%s") % label
Index: src/orca/braillegenerator.py
===================================================================
--- src/orca/braillegenerator.py	(revision 2121)
+++ src/orca/braillegenerator.py	(working copy)
@@ -293,7 +293,7 @@
         regions = []
 
         text = ""
-        text = util.appendString(text, util.getDisplayedLabel(obj))
+        text = util.appendString(text, self._script.getDisplayedLabel(obj))
         text = util.appendString(text, self._script.getDisplayedText(obj))
         text = util.appendString(text, self._getTextForValue(obj))
         text = util.appendString(text, self._getTextForRole(obj))
@@ -332,7 +332,7 @@
         self._debugGenerator("_getBrailleRegionsForAnimation", obj)
 
         text = ""
-        text = util.appendString(text, util.getDisplayedLabel(obj))
+        text = util.appendString(text, self._script.getDisplayedLabel(obj))
         text = util.appendString(text, self._script.getDisplayedText(obj))
         text = util.appendString(text, self._getTextForRole(obj))
         text = util.appendString(text, obj.description, ": ")
@@ -375,7 +375,7 @@
         self._debugGenerator("_getBrailleRegionsForCheckBox", obj)
 
         text = ""
-        text = util.appendString(text, util.getDisplayedLabel(obj))
+        text = util.appendString(text, self._script.getDisplayedLabel(obj))
         text = util.appendString(text, self._script.getDisplayedText(obj))
 
         if obj.state.count(atspi.Accessibility.STATE_CHECKED):
@@ -405,7 +405,7 @@
         self._debugGenerator("_getBrailleRegionsForCheckMenuItem", obj)
 
         text = ""
-        text = util.appendString(text, util.getDisplayedLabel(obj))
+        text = util.appendString(text, self._script.getDisplayedLabel(obj))
         text = util.appendString(text, self._script.getDisplayedText(obj))
 
         if obj.state.count(atspi.Accessibility.STATE_CHECKED):
@@ -456,7 +456,7 @@
         regions = []
 
         focusedRegionIndex = 0
-        label = util.getDisplayedLabel(obj)
+        label = self._script.getDisplayedLabel(obj)
         if label and (len(label) > 0):
             regions.append(braille.Region(label + " "))
             focusedRegionIndex = 1
@@ -585,7 +585,7 @@
         self._debugGenerator("_getBrailleRegionsForIcon", obj)
 
         text = ""
-        text = util.appendString(text, util.getDisplayedLabel(obj))
+        text = util.appendString(text, self._script.getDisplayedLabel(obj))
         text = util.appendString(text, self._script.getDisplayedText(obj))
 
         if obj.image:
@@ -660,7 +660,7 @@
         self._debugGenerator("_getBrailleRegionsForMenu", obj)
 
         text = ""
-        text = util.appendString(text, util.getDisplayedLabel(obj))
+        text = util.appendString(text, self._script.getDisplayedLabel(obj))
         text = util.appendString(text, self._script.getDisplayedText(obj))
         text = util.appendString(text, rolenames.getBrailleForRoleName(obj))
 
@@ -703,7 +703,7 @@
         self._debugGenerator("_getBrailleRegionsForMenuItem", obj)
 
         text = ""
-        text = util.appendString(text, util.getDisplayedLabel(obj))
+        text = util.appendString(text, self._script.getDisplayedLabel(obj))
         text = util.appendString(text, self._script.getDisplayedText(obj))
 
         if obj == orca_state.locusOfFocus:
@@ -732,7 +732,7 @@
 
         regions = []
 
-        textRegion = braille.Text(obj, util.getDisplayedLabel(obj))
+        textRegion = braille.Text(obj, self._script.getDisplayedLabel(obj))
         regions.append(textRegion)
 
         eol = braille.Region(" $l")
@@ -769,7 +769,7 @@
         self._debugGenerator("_getBrailleRegionsForPageTab", obj)
 
         text = ""
-        text = util.appendString(text, util.getDisplayedLabel(obj))
+        text = util.appendString(text, self._script.getDisplayedLabel(obj))
         text = util.appendString(text, self._script.getDisplayedText(obj))
 
         if obj == orca_state.locusOfFocus:
@@ -828,7 +828,7 @@
         regions = []
 
         text = ""
-        text = util.appendString(text, util.getDisplayedLabel(obj))
+        text = util.appendString(text, self._script.getDisplayedLabel(obj))
         text = util.appendString(text, self._script.getDisplayedText(obj))
 
         # In Java, some push buttons don't have label and text.
@@ -860,7 +860,7 @@
         self._debugGenerator("_getBrailleRegionsForRadioButton", obj)
 
         text = ""
-        text = util.appendString(text, util.getDisplayedLabel(obj))
+        text = util.appendString(text, self._script.getDisplayedLabel(obj))
         text = util.appendString(text, self._script.getDisplayedText(obj))
 
         # In Java, some toggle buttons don't have label and text.
@@ -897,7 +897,7 @@
         self._debugGenerator("_getBrailleRegionsForRadioMenuItem", obj)
 
         text = ""
-        text = util.appendString(text, util.getDisplayedLabel(obj))
+        text = util.appendString(text, self._script.getDisplayedLabel(obj))
         text = util.appendString(text, self._script.getDisplayedText(obj))
 
         if obj.state.count(atspi.Accessibility.STATE_CHECKED):
@@ -965,7 +965,7 @@
         regions = []
 
         text = ""
-        text = util.appendString(text, util.getDisplayedLabel(obj))
+        text = util.appendString(text, self._script.getDisplayedLabel(obj))
         # Ignore the text on the slider.
         #text = util.appendString(text, self._script.getDisplayedText(obj))
         text = util.appendString(text, self._getTextForValue(obj))
@@ -1203,7 +1203,7 @@
         if frame:
             title = frame.name
         if not title:
-            title = util.getDisplayedLabel(obj)
+            title = self._script.getDisplayedLabel(obj)
 
         text = title
         text = util.appendString(text, rolenames.getBrailleForRoleName(obj))
@@ -1408,7 +1408,7 @@
 
                 # Announce the label and text of the object in the hierarchy.
                 #
-                label = util.getDisplayedLabel(parent)
+                label = self._script.getDisplayedLabel(parent)
                 text = self._script.getDisplayedText(parent)
                 regions.append(braille.Region(" "))
                 result = self.getBrailleRegions(parent, False)
@@ -1423,7 +1423,7 @@
             # we add the label to the overall context.]]]
             #
             if parent.role == rolenames.ROLE_FILLER:
-                label = util.getDisplayedLabel(parent)
+                label = self._script.getDisplayedLabel(parent)
                 if label and len(label) and not label.isspace():
                     regions.append(braille.Region(" "))
                     result = self.getBrailleRegions(parent, False)
