/* nsIPropertyBag2 PopRequest (); */
NS_IMETHODIMP sbMockDevice::PopRequest(nsIPropertyBag2 **_retval)
{
  // while it's easier to reuse PeekRequest, that sort of defeats the purpose
  // of testing.
  NS_ENSURE_ARG_POINTER(_retval);

  nsresult rv;

  if (mBatch.empty()) {
    return NS_ERROR_NOT_AVAILABLE;
  }
  nsRefPtr<sbRequestItem> requestItem = *mBatch.begin();
  mBatch.erase(mBatch.begin());


  nsCOMPtr<nsIWritablePropertyBag2> bag =
    do_CreateInstance(NS_HASH_PROPERTY_BAG_CONTRACTID, &rv);
  NS_ENSURE_SUCCESS(rv, rv);

  const PRInt32 batchCount  = mBatch.size();

  rv = bag->SetPropertyAsInt32(NS_LITERAL_STRING("requestType"),
                               requestItem->GetType());
  rv = bag->SetPropertyAsInt32(NS_LITERAL_STRING("batchCount"), batchCount);
  NS_ENSURE_SUCCESS(rv, rv);

  const PRInt32 batchIndex = requestItem->GetBatchIndex();

  rv = bag->SetPropertyAsInt32(NS_LITERAL_STRING("batchIndex"), batchIndex);
  NS_ENSURE_SUCCESS(rv, rv);

  const PRInt32 requestId = requestItem->GetRequestId();

  rv = bag->SetPropertyAsInt32(NS_LITERAL_STRING("itemTransferID"),
                               requestId);
  NS_ENSURE_SUCCESS(rv, rv);

  if (requestItem->GetType() >= sbRequestThreadQueue::USER_REQUEST_TYPES) {
    TransferRequest * transferRequest =
        static_cast<TransferRequest *>(requestItem.get());
    SET_PROP(Interface, item);
    SET_PROP(Interface, list);
    SET_PROP(Interface, data);
    SET_PROP(Uint32, index);
    SET_PROP(Uint32, otherIndex);
  }
  return CallQueryInterface(bag, _retval);
}
Beispiel #2
0
NS_IMETHODIMP
compzillaWindow::GetProperty (PRUint32 iprop, nsIPropertyBag2 **bag2)
{
    *bag2 = nsnull;

    Atom prop = (Atom)iprop;

    nsISupports *bag;
    nsCOMPtr<nsIWritablePropertyBag2> wbag;
    nsCOMPtr<nsIPropertyBag2> rbag;

    nsresult rv = CallCreateInstance("@mozilla.org/hash-property-bag;1", &bag);
    if (NS_FAILED(rv)) {
        return rv;
    }
 
    wbag = do_QueryInterface (bag);
    rbag = do_QueryInterface (bag);

#define SET_BAG() do { \
    NS_ADDREF (rbag); \
    *bag2 = rbag; \
} while (0)

#define SET_PROP(_bag, _type, _key, _val) \
    (_bag)->SetPropertyAs##_type (NS_LITERAL_STRING (_key), _val)

    switch (prop) {
        // ICCCM properties

    case XA_WM_NAME:
    case XA_WM_ICON_NAME: {
        // XXX this is missing some massaging, since the WM_NAME
        // property isn't in utf8, but in some locale character set
        // (latin1?  who knows).  Check the gtk+ source on how to
        // handle this.
        nsCAutoString str;
        if (NS_OK == GetUTF8StringProperty (prop, str)) {
            SET_BAG ();
            SET_PROP(wbag, AUTF8String, "text", str);
        }
        break;
    }

    case XA_WM_HINTS: {
        XWMHints *wmHints;

        wmHints = XGetWMHints (mDisplay, mWindow);

        if (wmHints) {
            SET_BAG ();
            SET_PROP(wbag, Int32, "wmHints.flags", wmHints->flags);
            SET_PROP(wbag, Bool, "wmHints.input", wmHints->input);
            SET_PROP(wbag, Int32, "wmHints.initialState", wmHints->initial_state);
            SET_PROP(wbag, Uint32, "wmHints.iconPixmap", wmHints->icon_pixmap);
            SET_PROP(wbag, Uint32, "wmHints.iconWindow", wmHints->icon_window);
            SET_PROP(wbag, Int32, "wmHints.iconX", wmHints->icon_x);
            SET_PROP(wbag, Int32, "wmHints.iconY", wmHints->icon_y);
            SET_PROP(wbag, Uint32, "wmHints.iconMask", wmHints->icon_mask);
            SET_PROP(wbag, Uint32, "wmHints.windowGroup", wmHints->window_group);

            XFree (wmHints);
        }
        break;
    }

    case XA_WM_NORMAL_HINTS: {
        XSizeHints sizeHints;
        long supplied;

        // XXX check return value
        XGetWMNormalHints (mDisplay, mWindow, &sizeHints, &supplied);

        SET_BAG ();

        SET_PROP(wbag, Int32, "sizeHints.flags", sizeHints.flags);

        SET_PROP(wbag, Int32, "sizeHints.x", sizeHints.x);
        SET_PROP(wbag, Int32, "sizeHints.y", sizeHints.y);
        SET_PROP(wbag, Int32, "sizeHints.width", sizeHints.width);
        SET_PROP(wbag, Int32, "sizeHints.height", sizeHints.height);

        SET_PROP(wbag, Int32, "sizeHints.minWidth", sizeHints.min_width);
        SET_PROP(wbag, Int32, "sizeHints.minHeight", sizeHints.min_height);

        SET_PROP(wbag, Int32, "sizeHints.maxWidth", sizeHints.max_width);
        SET_PROP(wbag, Int32, "sizeHints.maxHeight", sizeHints.max_height);

        SET_PROP(wbag, Int32, "sizeHints.widthInc", sizeHints.width_inc);
        SET_PROP(wbag, Int32, "sizeHints.heightInc", sizeHints.height_inc);

        SET_PROP(wbag, Int32, "sizeHints.minAspect.x", sizeHints.min_aspect.x);
        SET_PROP(wbag, Int32, "sizeHints.minAspect.y", sizeHints.min_aspect.y);

        SET_PROP(wbag, Int32, "sizeHints.maxAspect.x", sizeHints.max_aspect.x);
        SET_PROP(wbag, Int32, "sizeHints.maxAspect.y", sizeHints.max_aspect.y);

        if ((supplied & (PBaseSize|PWinGravity)) != 0) {
            SET_PROP(wbag, Int32, "sizeHints.baseWidth", sizeHints.base_width);
            SET_PROP(wbag, Int32, "sizeHints.baseHeight", sizeHints.base_height);

            SET_PROP(wbag, Int32, "sizeHints.winGravity", sizeHints.win_gravity);
        }
        break;
    }
    case XA_WM_CLASS: {
        // 2 strings, separated by a \0

        char *instance, *_class;

        Atom actual_type;
        int format;
        unsigned long nitems;
        unsigned long bytes_after_return;
        unsigned char *data;

        XGetWindowProperty (mDisplay, mWindow, (Atom)prop,
                            0, BUFSIZ, false, XA_STRING,
                            &actual_type, &format, &nitems, &bytes_after_return, 
                            &data);

        instance = (char*)data;
        _class = instance + strlen (instance) + 1;

        SET_BAG ();
        SET_PROP (wbag, ACString, "instanceName", nsCAutoString (instance));
        SET_PROP (wbag, ACString, "className", nsCAutoString (_class));

        XFree (data);

        break;
    }
    case XA_WM_TRANSIENT_FOR: {
        // the parent X window's canvas element
        break;
    }
    case XA_WM_CLIENT_MACHINE: {
        nsCAutoString str;
        if (NS_OK == GetUTF8StringProperty (prop, str)) {
            SET_BAG ();
            SET_PROP(wbag, AUTF8String, "text", str);
        }
    }
    default:
        // ICCCM properties which don't have predefined atoms

        if (prop == atoms.x.WM_COLORMAP_WINDOWS) {
            // if we ever support this, shoot me..
        }
        else if (prop == atoms.x.WM_PROTOCOLS) {
            // an array of Atoms.
        }

        // non - ICCCM properties go here

        // EWMH properties

        else if (prop == atoms.x._NET_WM_NAME
                 || prop == atoms.x._NET_WM_VISIBLE_NAME
                 || prop == atoms.x._NET_WM_ICON_NAME
                 || prop == atoms.x._NET_WM_VISIBLE_ICON_NAME) {
            // utf8 encoded string
            nsCAutoString str;
            if (NS_OK == GetUTF8StringProperty (prop, str)) {
                SET_BAG ();
                SET_PROP(wbag, AUTF8String, "text", str);
            }
        }
        else if (prop == atoms.x._NET_WM_DESKTOP) {
        }
        else if (prop == atoms.x._NET_WM_WINDOW_TYPE) {
            // XXX _NET_WM_WINDOW_TYPE is actually an array of atoms, not just 1.
            // this also needs fixing in the JS.
            PRUint32 atom;
            if (NS_OK == GetAtomProperty (prop, &atom)) {
                SET_BAG ();
                SET_PROP(wbag, Uint32, "atom", atom);
            }
        }
        else if (prop == atoms.x._NET_WM_STATE) {
        }
        else if (prop == atoms.x._NET_WM_ALLOWED_ACTIONS) {
        }
        else if (prop == atoms.x._NET_WM_STRUT) {
            PRUint32 *cards;
            PRUint32 nitems;

            if (NS_OK == GetCardinalListProperty (prop, &cards, 4)) {
                SET_BAG ();
                SET_PROP (wbag, Uint32, "left", cards[0]);
                SET_PROP (wbag, Uint32, "right", cards[1]);
                SET_PROP (wbag, Uint32, "top", cards[2]);
                SET_PROP (wbag, Uint32, "bottom", cards[3]);
            
                XFree (cards);
            }
        }
        else if (prop == atoms.x._NET_WM_STRUT_PARTIAL) {
            PRUint32 *cards;
            PRUint32 nitems;

            if (NS_OK == GetCardinalListProperty (prop, &cards, 12)) {
                SET_BAG ();
                SET_PROP (wbag, Bool, "partial", true);

                SET_PROP (wbag, Uint32, "left", cards[0]);
                SET_PROP (wbag, Uint32, "right", cards[1]);
                SET_PROP (wbag, Uint32, "top", cards[2]);
                SET_PROP (wbag, Uint32, "bottom", cards[3]);

                SET_PROP (wbag, Uint32, "leftStartY", cards[4]);
                SET_PROP (wbag, Uint32, "leftEndY", cards[5]);
                SET_PROP (wbag, Uint32, "rightStartY", cards[6]);
                SET_PROP (wbag, Uint32, "rightEndY", cards[7]);

                SET_PROP (wbag, Uint32, "topStartX", cards[8]);
                SET_PROP (wbag, Uint32, "topEndX", cards[9]);
                SET_PROP (wbag, Uint32, "bottomStartX", cards[10]);
                SET_PROP (wbag, Uint32, "bottomEndX", cards[11]);
                
                XFree (cards);
            }
        }
        else if (prop == atoms.x._NET_WM_ICON_GEOMETRY) {
            PRUint32 *cards;
            PRUint32 nitems;

            if (NS_OK == GetCardinalListProperty (prop, &cards, 4)) {
                SET_BAG ();
                SET_PROP (wbag, Bool, "partial", false);
                SET_PROP(wbag, Uint32, "x", cards[0]);
                SET_PROP(wbag, Uint32, "y", cards[1]);
                SET_PROP(wbag, Uint32, "width", cards[2]);
                SET_PROP(wbag, Uint32, "height", cards[3]);
                XFree (cards);
            }
        }
        else if (prop == atoms.x._NET_WM_ICON) {
            Atom actual_type;
            int format;
            unsigned long nitems;
            unsigned long bytes_after_return;
            unsigned char *data;
            
            if (XGetWindowProperty (mDisplay, mWindow, prop,
                                    0, BUFSIZ, false, XA_CARDINAL,
                                    &actual_type, &format, &nitems, &bytes_after_return, 
                                    &data) == Success) {
                nsCAutoString dataStr;
                dataStr.Assign ((char *) data, (format / 8) * nitems);

                SET_BAG ();
                SET_PROP(wbag, ACString, "data", dataStr);
                XFree (data);
            }
        }
        else if (prop == atoms.x._NET_WM_PID) {
        }
        else if (prop == atoms.x._NET_WM_HANDLED_ICONS) {
        }
        else if (prop == atoms.x._NET_WM_USER_TIME) {
        }
        else if (prop == atoms.x._NET_FRAME_EXTENTS) {
        }

        break;
    }

#undef SET_PROP
#undef SET_BAG

    return NS_OK;
}