示例#1
0
int Window::Register()
{
    Message *msg = new Message(REGISTER);

    msg->AddString( "_type", "window" );
    msg->AddInt( "_port", Port() );
    msg->AddString( "_title", m_title );
    msg->AddRect( "_rect", Frame() );
    msg->AddBool( "_visible", false );
    msg->AddInt( "_flags", m_flags );


    Message *reply = Messenger::SendReceiveMessage( "gui_server", 0, msg );
    if ( reply == NULL )
    {
        delete msg;
        return -1;
    }
    delete msg;

    if ( reply->rc() != 0 )
    {
        delete reply;
        return -1;
    }

    // Good reply.. let's get the information.

    int bad = 0;

    if ( reply->FindInt( "_id", &m_wid ) != 0 ) bad = -1;
    if ( reply->FindInt( "_sid", &m_sid ) != 0 ) bad = -1;
    if ( reply->FindInt( "_did", &m_did ) != 0 ) bad = -1;
    if ( reply->FindRect( "_rect", &m_frame ) != 0 ) bad = -1;

    delete reply;


    // Accept the GUI memory and everything.

    int tmp_pages;
    unsigned int tmp_flags;

    if ( smk_request_shmem( m_sid, (void**)&m_buffer, &tmp_pages, &tmp_flags ) != 0 )
        bad = -1;

    // We now have our GUI buffer, size and ID.

    if ( bad != 0 ) return -1;

    // Registered with desktop port =  m_did

    return 0;
}
示例#2
0
bool Window::ResizeTo( int width, int height )
{
    // within reason.
    if ( (width < 5) || (height < 5) ) return false;

    Rect newFrame = Frame();
    newFrame.right  = newFrame.left + width - 1;
    newFrame.bottom = newFrame.top + height - 1;

    // Send resize request.
    Message *msg = new Message(RESIZE);
    msg->AddInt( "_id", m_wid );
    msg->AddRect( "_rect", newFrame );

    Message *reply = Messenger::SendReceiveMessage( "gui_server",  m_did, msg );

    if ( reply == NULL )
    {
        delete msg;
        return false;
    }
    delete msg;

    if ( reply->rc() != 0 )
    {
        delete reply;
        return false;
    }

    // Good reply.. let's get the information.

    int bad = 0;
    int new_sid;
    if ( reply->FindInt( "_sid", &new_sid ) != 0 ) bad = -1;
    if ( reply->FindRect( "_rect", &newFrame ) != 0 ) bad = -1;
    delete reply;

    if ( bad != 0 ) return -1;

    // --------- Release what used to be.

    if ( m_sid >= 0 ) smk_release_shmem( m_sid );
    m_buffer 	= NULL;
    m_sid 		= new_sid;
    m_frame 	= newFrame;

    // Accept the GUI memory and everything.



    int tmp_pages;
    unsigned int tmp_flags;

    if ( smk_request_shmem( m_sid, (void**)&m_buffer, &tmp_pages, &tmp_flags) != 0 )
    {
        // Freak out...
        exit(-1);
    }

    // ....................


    Draw(Bounds());
    Sync();

    // We now have our GUI buffer, size and ID.
    return true;
}
示例#3
0
status_t ConvertFromAMessage(const os::Message & from, Message & to) 
{
   to.Clear();
   to.what = from.GetCode();

   int numNames = from.GetNumNames();
   for (int32 i=0; i<numNames; i++)
   {
      int type;
      int count;
      std::string name = from.GetName(i);
      if (from.GetNameInfo(name.c_str(), &type, &count) == B_NO_ERROR)
      {
         for (int j=0; j<count; j++)
         {
            const void * nextItem;
            size_t itemSize;
            if (from.FindData(name.c_str(), type, &nextItem, &itemSize, j) != B_NO_ERROR) return B_ERROR;

            // do any necessary translation from the AtheOS data types to Muscle data types
            switch(type)
            {
               case os::T_POINT:
               {
                  const os::Point * p = static_cast<const os::Point *>(nextItem);
                  Point pPoint(p->x, p->y);
                  if (to.AddPoint(name.c_str(), pPoint) != B_NO_ERROR) return B_ERROR;
               }
               break;

               case os::T_RECT:
               {
                  const os::Rect * r = static_cast<const os::Rect *>(nextItem);
                  Rect pRect(r->left, r->top, r->right, r->bottom);
                  if (to.AddRect(name.c_str(), pRect) != B_NO_ERROR) return B_ERROR;
               }
               break;

               case os::T_MESSAGE:
               {
                  os::Message amsg;
                  if (amsg.Unflatten(static_cast<const uint8 *>(nextItem)) != B_NO_ERROR) return B_ERROR;
                  Message * newMsg = newnothrow Message;
                  if (newMsg)
                  {
                     MessageRef msgRef(newMsg);
                     if (ConvertFromAMessage(amsg, *newMsg) != B_NO_ERROR) return B_ERROR;
                     if (to.AddMessage(name.c_str(), msgRef) != B_NO_ERROR) return B_ERROR;
                  }
                  else {WARN_OUT_OF_MEMORY; return B_ERROR;}
               }
               break;

               default:
                  if (to.AddData(name.c_str(), type, nextItem, itemSize) != B_NO_ERROR) return B_ERROR;
               break;
            }

         }
      }
   }
   return B_NO_ERROR;
}