コード例 #1
0
/**
 * clutter_win32_get_stage_from_window:
 * @hwnd: a window handle
 *
 * Gets the stage for a particular window.
 *
 * Return value: The stage or NULL if a stage does not exist for the
 * window.
 *
 * Since: 0.8
 */
ClutterStage *
clutter_win32_get_stage_from_window (HWND hwnd)
{
  /* Check whether the window handle is an instance of the stage
     window class */
  if ((ATOM) GetClassLongPtrW (hwnd, GCW_ATOM)
      == clutter_stage_win32_get_window_class ())
    /* If it is there should be a pointer to the stage in the window
       extra data */
    return CLUTTER_STAGE_WIN32 (GetWindowLongPtrW (hwnd, 0))->wrapper;
  else
    {
      /* Otherwise it might be a foreign window so we should check the
	 stage list */
      ClutterStageManager *stage_manager;
      const GSList        *stages, *l;

      stage_manager = clutter_stage_manager_get_default ();
      stages = clutter_stage_manager_peek_stages (stage_manager);

      for (l = stages; l != NULL; l = l->next)
	{
	  ClutterStage *stage = l->data;
	  ClutterStageWindow *impl;

	  impl = _clutter_stage_get_window (stage);
	  g_assert (CLUTTER_IS_STAGE_WIN32 (impl));

	  if (CLUTTER_STAGE_WIN32 (impl)->hwnd == hwnd)
	    return stage;
	}
    }

  return NULL;
}
コード例 #2
0
static void
clutter_stage_win32_set_fullscreen (ClutterStageWindow *stage_window,
				    gboolean            value)
{
  ClutterStageWin32 *stage_win32 = CLUTTER_STAGE_WIN32 (stage_window);
  HWND hwnd = CLUTTER_STAGE_WIN32 (stage_window)->hwnd;
  LONG old_style = GetWindowLongW (hwnd, GWL_STYLE);
  ClutterStageStateEvent event;

  if (value)
    stage_win32->state |= CLUTTER_STAGE_STATE_FULLSCREEN;
  else
    stage_win32->state &= ~CLUTTER_STAGE_STATE_FULLSCREEN;

  if (hwnd)
    {
      /* Update the window style but preserve the visibility */
      SetWindowLongW (hwnd, GWL_STYLE,
		      get_window_style (stage_win32)
		      | (old_style & WS_VISIBLE));
      /* Update the window size */
      if (value)
	{
	  get_fullscreen_rect (stage_win32);
	  SetWindowPos (hwnd, HWND_TOP,
			stage_win32->fullscreen_rect.left,
			stage_win32->fullscreen_rect.top,
			stage_win32->fullscreen_rect.right
			- stage_win32->fullscreen_rect.left,
			stage_win32->fullscreen_rect.bottom
			- stage_win32->fullscreen_rect.top,
			0);
	}
      else
	{
	  int full_width, full_height;

	  get_full_window_size (stage_win32,
				stage_win32->win_width,
				stage_win32->win_height,
				&full_width, &full_height);

	  SetWindowPos (stage_win32->hwnd, NULL,
			0, 0,
			full_width, full_height,
			SWP_NOZORDER | SWP_NOMOVE);
	}

      CLUTTER_SET_PRIVATE_FLAGS (stage_win32->wrapper,
				 CLUTTER_ACTOR_SYNC_MATRICES);
    }

  /* Report the state change */
  memset (&event, 0, sizeof (event));
  event.type = CLUTTER_STAGE_STATE;
  event.stage = CLUTTER_STAGE (stage_win32->wrapper);
  event.new_state = stage_win32->state;
  event.changed_mask = CLUTTER_STAGE_STATE_FULLSCREEN;
  clutter_event_put ((ClutterEvent *) &event);
}
コード例 #3
0
static void
clutter_stage_win32_set_fullscreen (ClutterStageWindow *stage_window,
				    gboolean            value)
{
  ClutterStageWin32 *stage_win32 = CLUTTER_STAGE_WIN32 (stage_window);
  HWND hwnd = CLUTTER_STAGE_WIN32 (stage_window)->hwnd;
  LONG old_style = GetWindowLongW (hwnd, GWL_STYLE);
  ClutterStageStateEvent event;

  if (hwnd)
    {
      /* Update the window style but preserve the visibility */
      SetWindowLongW (hwnd, GWL_STYLE,
		      get_requested_window_style (stage_win32, value)
		      | (old_style & WS_VISIBLE));
      /* Update the window size */
      if (value)
        {
          get_fullscreen_rect (stage_win32);
          SetWindowPos (hwnd, HWND_TOP,
                        stage_win32->fullscreen_rect.left,
                        stage_win32->fullscreen_rect.top,
                        stage_win32->fullscreen_rect.right
                        - stage_win32->fullscreen_rect.left,
                        stage_win32->fullscreen_rect.bottom
                        - stage_win32->fullscreen_rect.top,
                        0);
        }
      else
        {
          int full_width, full_height;

          get_full_window_size (stage_win32,
                                stage_win32->win_width,
                                stage_win32->win_height,
                                &full_width, &full_height);

          SetWindowPos (stage_win32->hwnd, NULL,
                        0, 0,
                        full_width, full_height,
                        SWP_NOZORDER | SWP_NOMOVE);
        }
    }

  /* Report the state change */
  if (value)
    {
      _clutter_stage_update_state (stage_win32->wrapper,
                                   0,
                                   CLUTTER_STAGE_STATE_FULLSCREEN);
    }
  else
    {
      _clutter_stage_update_state (stage_win32->wrapper,
                                   CLUTTER_STAGE_STATE_FULLSCREEN,
                                   0);
    }
}
コード例 #4
0
static void
clutter_stage_win32_set_user_resize (ClutterStageWindow *stage_window,
				     gboolean            value)
{
  HWND hwnd = CLUTTER_STAGE_WIN32 (stage_window)->hwnd;
  LONG old_style = GetWindowLongW (hwnd, GWL_STYLE);

  /* Update the window style but preserve the visibility */
  SetWindowLongW (hwnd, GWL_STYLE,
		  get_window_style (CLUTTER_STAGE_WIN32 (stage_window))
		  | (old_style & WS_VISIBLE));
  /* Queue a redraw of the frame */
  RedrawWindow (hwnd, NULL, NULL, RDW_FRAME | RDW_INVALIDATE);
}
コード例 #5
0
static void
clutter_stage_win32_dispose (GObject *gobject)
{
  ClutterStageWin32 *stage_win32 = CLUTTER_STAGE_WIN32 (gobject);

  G_OBJECT_CLASS (clutter_stage_win32_parent_class)->dispose (gobject);
}
コード例 #6
0
static void
clutter_stage_win32_unrealize (ClutterActor *actor)
{
  ClutterStageWin32 *stage_win32 = CLUTTER_STAGE_WIN32 (actor);

  CLUTTER_NOTE (BACKEND, "Unrealizing stage");

  if (CLUTTER_ACTOR_CLASS (clutter_stage_win32_parent_class)->unrealize != NULL)
    CLUTTER_ACTOR_CLASS (clutter_stage_win32_parent_class)->unrealize (actor);

  if (stage_win32->client_dc)
    {
      ReleaseDC (stage_win32->hwnd, stage_win32->client_dc);
      stage_win32->client_dc = NULL;
    }

  if (!stage_win32->is_foreign_win && stage_win32->hwnd)
    {
      /* Drop the pointer to this stage in the window so that any
	 further messages won't be processed. The stage might be being
	 destroyed so otherwise the messages would be handled with an
	 invalid stage instance */
      SetWindowLongPtrW (stage_win32->hwnd, 0, (LONG_PTR) 0);
      DestroyWindow (stage_win32->hwnd);
      stage_win32->hwnd = NULL;
    }
}
コード例 #7
0
static CoglFramebuffer *
clutter_stage_win32_get_active_framebuffer (ClutterStageWindow *stage_window)
{
  ClutterStageWin32 *stage_win32 = CLUTTER_STAGE_WIN32 (stage_window);

  return COGL_FRAMEBUFFER (stage_win32->onscreen);
}
コード例 #8
0
static void
clutter_stage_win32_resize (ClutterStageWindow *stage_window,
                            gint                width,
                            gint                height)
{
  ClutterStageWin32 *stage_win32 = CLUTTER_STAGE_WIN32 (stage_window);
  gboolean resize;

  resize = clutter_stage_get_user_resizable (stage_win32->wrapper);

  if (width != stage_win32->win_width || height != stage_win32->win_height)
    {
      /* Ignore size requests if we are in full screen mode */
      if (!_clutter_stage_is_fullscreen (stage_win32->wrapper))
        {
          stage_win32->win_width = width;
          stage_win32->win_height = height;

          if (stage_win32->hwnd != NULL && !stage_win32->is_foreign_win)
            {
              int full_width, full_height;

              get_full_window_size (stage_win32,
                                    width, height,
                                    &full_width, &full_height);

              SetWindowPos (stage_win32->hwnd, NULL,
                            0, 0,
                            full_width, full_height,
                            SWP_NOZORDER | SWP_NOMOVE);
            }
        }
    }
}
コード例 #9
0
static void
clutter_stage_win32_set_cursor_visible (ClutterStageWindow *stage_window,
                                        gboolean            cursor_visible)
{
  ClutterStageWin32 *stage_win32 = CLUTTER_STAGE_WIN32 (stage_window);

  if (stage_win32->is_cursor_visible != cursor_visible)
    {
      POINT cursor_pos;
      RECT client_rect;

      stage_win32->is_cursor_visible = cursor_visible;

      /* If the cursor is already over the client area of the window
         then we need to update it immediately */
      GetCursorPos (&cursor_pos);
      if (WindowFromPoint (cursor_pos) == stage_win32->hwnd &&
          ScreenToClient (stage_win32->hwnd, &cursor_pos) &&
          GetClientRect (stage_win32->hwnd, &client_rect) &&
          cursor_pos.x >= client_rect.left &&
          cursor_pos.y >= client_rect.top &&
          cursor_pos.x < client_rect.right &&
          cursor_pos.y < client_rect.bottom)
        _clutter_stage_win32_update_cursor (stage_win32);
    }
}
コード例 #10
0
static void
clutter_stage_win32_hide (ClutterActor *actor)
{
  ClutterStageWin32 *stage_win32 = CLUTTER_STAGE_WIN32 (actor);

  if (stage_win32->hwnd)
    ShowWindow (stage_win32->hwnd, SW_HIDE);
}
コード例 #11
0
static void
clutter_backend_win32_ensure_context (ClutterBackend *backend, 
				      ClutterStage   *stage)
{
  ClutterStageWin32 *stage_win32 =
    CLUTTER_STAGE_WIN32 (_clutter_stage_get_window (stage));

  cogl_set_framebuffer (COGL_FRAMEBUFFER (stage_win32->onscreen));
}
コード例 #12
0
static void
clutter_stage_win32_unrealize (ClutterStageWindow *stage_window)
{
  ClutterStageWin32 *stage_win32 = CLUTTER_STAGE_WIN32 (stage_window);

  CLUTTER_NOTE (BACKEND, "Unrealizing stage");

  clutter_stage_win32_unprepare_window (stage_win32);
}
コード例 #13
0
static void
clutter_stage_win32_set_accept_focus (ClutterStageWindow *stage_window,
                                      gboolean            accept_focus)
{
  ClutterStageWin32 *stage_win32 = CLUTTER_STAGE_WIN32 (stage_window);

  accept_focus = !!accept_focus;

  stage_win32->accept_focus = accept_focus;
}
コード例 #14
0
/**
 * clutter_win32_set_stage_foreign:
 * @stage: a #ClutterStage
 * @hwnd: an existing window handle
 *
 * Target the #ClutterStage to use an existing external window handle.
 *
 * Return value: %TRUE if foreign window is valid
 *
 * Since: 0.8
 */
gboolean
clutter_win32_set_stage_foreign (ClutterStage *stage,
                                 HWND          hwnd)
{
    ClutterStageWin32 *stage_win32;
    ClutterStageWindow *impl;
    ClutterActor *actor;
    RECT client_rect;
    ForeignWindowData fwd;

    g_return_val_if_fail (CLUTTER_IS_STAGE (stage), FALSE);
    g_return_val_if_fail (hwnd != NULL, FALSE);

    actor = CLUTTER_ACTOR (stage);

    impl = _clutter_stage_get_window (stage);
    stage_win32 = CLUTTER_STAGE_WIN32 (impl);

    if (!GetClientRect (hwnd, &client_rect))
    {
        g_warning ("Unable to retrieve the new window geometry");
        return FALSE;
    }

    fwd.stage_win32 = stage_win32;
    fwd.hwnd = hwnd;

    /* destroy the old HWND, if we have one and it's ours */
    if (stage_win32->hwnd != NULL && !stage_win32->is_foreign_win)
        fwd.destroy_old_hwnd = TRUE;
    else
        fwd.destroy_old_hwnd = FALSE;

    fwd.geom.x = 0;
    fwd.geom.y = 0;
    fwd.geom.width = client_rect.right - client_rect.left;
    fwd.geom.height = client_rect.bottom - client_rect.top;

    _clutter_actor_rerealize (actor,
                              set_foreign_window_callback,
                              &fwd);

    /* Queue a relayout - so the stage will be allocated the new
     * window size.
     *
     * Note also that when the stage gets allocated the new
     * window size that will result in the stage's
     * priv->viewport being changed, which will in turn result
     * in the Cogl viewport changing when _clutter_do_redraw
     * calls _clutter_stage_maybe_setup_viewport().
     */
    clutter_actor_queue_relayout (CLUTTER_ACTOR (stage));

    return TRUE;
}
コード例 #15
0
static void
clutter_stage_win32_hide (ClutterStageWindow *stage_window)
{
  ClutterStageWin32 *stage_win32 = CLUTTER_STAGE_WIN32 (stage_window);

  if (stage_win32->hwnd)
    {
      clutter_actor_unmap (CLUTTER_ACTOR (stage_win32->wrapper));
      ShowWindow (stage_win32->hwnd, SW_HIDE);
    }
}
コード例 #16
0
static void
clutter_stage_win32_redraw (ClutterStageWindow *stage_window)
{
  ClutterStageWin32 *stage_win32 = CLUTTER_STAGE_WIN32 (stage_window);

  /* this will cause the stage implementation to be painted */
  _clutter_stage_do_paint (stage_win32->wrapper, NULL);
  cogl_flush ();

  if (stage_win32->onscreen)
    cogl_onscreen_swap_buffers (COGL_FRAMEBUFFER (stage_win32->onscreen));
}
コード例 #17
0
/**
 * clutter_win32_get_stage_window:
 * @stage: a #ClutterStage
 *
 * Gets the stage's window handle
 *
 * Return value: An HWND for the stage window.
 *
 * Since: 0.8
 */
HWND
clutter_win32_get_stage_window (ClutterStage *stage)
{
  ClutterStageWindow *impl;

  g_return_val_if_fail (CLUTTER_IS_STAGE (stage), NULL);

  impl = _clutter_stage_get_window (stage);

  g_return_val_if_fail (CLUTTER_IS_STAGE_WIN32 (impl), NULL);

  return CLUTTER_STAGE_WIN32 (impl)->hwnd;
}
コード例 #18
0
/**
 * clutter_win32_set_stage_foreign:
 * @stage: a #ClutterStage
 * @hwnd: an existing window handle
 *
 * Target the #ClutterStage to use an existing external window handle.
 *
 * Return value: %TRUE if foreign window is valid
 *
 * Since: 0.8
 */
gboolean
clutter_win32_set_stage_foreign (ClutterStage *stage,
				 HWND          hwnd)
{
  ClutterStageWin32 *stage_win32;
  ClutterStageWindow *impl;
  ClutterActor *actor;
  RECT client_rect;
  POINT window_pos;
  ClutterGeometry geom;

  g_return_val_if_fail (CLUTTER_IS_STAGE (stage), FALSE);
  g_return_val_if_fail (hwnd != NULL, FALSE);

  actor = CLUTTER_ACTOR (stage);

  impl = _clutter_stage_get_window (stage);
  stage_win32 = CLUTTER_STAGE_WIN32 (impl);

  /* FIXME this needs updating to use _clutter_actor_rerealize(),
   * see the analogous code in x11 backend. Probably best if
   * win32 maintainer does it so they can be sure it compiles
   * and works.
   */

  clutter_actor_unrealize (actor);

  if (!GetClientRect (hwnd, &client_rect))
    {
      g_warning ("Unable to retrieve the new window geometry");
      return FALSE;
    }
  window_pos.x = client_rect.left;
  window_pos.y = client_rect.right;
  ClientToScreen (hwnd, &window_pos);

  CLUTTER_NOTE (BACKEND, "Setting foreign window (0x%x)", (int) hwnd);

  stage_win32->hwnd = hwnd;
  stage_win32->is_foreign_win = TRUE;

  geom.x = 0;
  geom.y = 0;
  geom.width = client_rect.right - client_rect.left;
  geom.height = client_rect.bottom - client_rect.top;

  clutter_actor_set_geometry (actor, &geom);
  clutter_actor_realize (actor);

  return TRUE;
}
コード例 #19
0
static void
clutter_stage_win32_set_title (ClutterStageWindow *stage_window,
			       const gchar        *title)
{
  ClutterStageWin32 *stage_win32 = CLUTTER_STAGE_WIN32 (stage_window);
  wchar_t *wtitle;

  /* Empty window titles not allowed, so set it to just a period. */
  if (title == NULL || !title[0])
    title = ".";
  
  wtitle = g_utf8_to_utf16 (title, -1, NULL, NULL, NULL);
  SetWindowTextW (stage_win32->hwnd, wtitle);
  g_free (wtitle);
}
コード例 #20
0
static void
clutter_stage_win32_show (ClutterStageWindow *stage_window,
                          gboolean            do_raise)
{
  ClutterStageWin32 *stage_win32 = CLUTTER_STAGE_WIN32 (stage_window);

  if (stage_win32->hwnd)
    {
      ShowWindow (stage_win32->hwnd, do_raise ? SW_SHOW : SW_SHOWNA);

      if (stage_win32->accept_focus)
        SetForegroundWindow (stage_win32->hwnd);

      clutter_actor_map (CLUTTER_ACTOR (stage_win32->wrapper));
    }
}
コード例 #21
0
static void
clutter_stage_win32_get_geometry (ClutterStageWindow *stage_window,
                                  ClutterGeometry    *geometry)
{
    ClutterStageWin32 *stage_win32 = CLUTTER_STAGE_WIN32 (stage_window);

    if ((stage_win32->state & CLUTTER_STAGE_STATE_FULLSCREEN))
    {
        geometry->width = (stage_win32->fullscreen_rect.right
                           - stage_win32->fullscreen_rect.left);
        geometry->height = (stage_win32->fullscreen_rect.bottom
                            - stage_win32->fullscreen_rect.top);
        return;
    }

    geometry->width = stage_win32->win_width;
    geometry->height = stage_win32->win_height;
}
コード例 #22
0
static void
clutter_stage_win32_get_geometry (ClutterStageWindow    *stage_window,
                                  cairo_rectangle_int_t *geometry)
{
  ClutterStageWin32 *stage_win32 = CLUTTER_STAGE_WIN32 (stage_window);

  if (_clutter_stage_is_fullscreen (stage_win32->wrapper))
    {
      geometry->width = stage_win32->fullscreen_rect.right
                      - stage_win32->fullscreen_rect.left;
      geometry->height = stage_win32->fullscreen_rect.bottom
                       - stage_win32->fullscreen_rect.top;
      return;
    }

  geometry->width = stage_win32->win_width;
  geometry->height = stage_win32->win_height;
}
コード例 #23
0
static ClutterStageWindow *
clutter_backend_win32_create_stage (ClutterBackend  *backend,
				    ClutterStage    *wrapper,
				    GError         **error)
{
  ClutterBackendWin32 *backend_win32 = CLUTTER_BACKEND_WIN32 (backend);
  ClutterStageWin32 *stage_win32;
  ClutterStageWindow *stage;

  stage = g_object_new (CLUTTER_TYPE_STAGE_WIN32, NULL);

  /* copy backend data into the stage */
  stage_win32 = CLUTTER_STAGE_WIN32 (stage);
  stage_win32->backend = backend_win32;
  stage_win32->wrapper = wrapper;

  return stage;
}
コード例 #24
0
static void
clutter_stage_win32_dispose (GObject *gobject)
{
  ClutterStageWin32 *stage_win32 = CLUTTER_STAGE_WIN32 (gobject);

  /* Make sure that context and window are destroyed in case unrealize
   * hasn't been called yet.
   */
  if (stage_win32->hwnd)
    clutter_stage_win32_unprepare_window (stage_win32);

  if (stage_win32->wtitle)
    {
      g_free (stage_win32->wtitle);
      stage_win32->wtitle = NULL;
    }

  G_OBJECT_CLASS (clutter_stage_win32_parent_class)->dispose (gobject);
}
コード例 #25
0
static void
clutter_stage_win32_set_title (ClutterStageWindow *stage_window,
			       const gchar        *title)
{
  ClutterStageWin32 *stage_win32 = CLUTTER_STAGE_WIN32 (stage_window);

  /* Empty window titles not allowed, so set it to just a period. */
  if (title == NULL || !title[0])
    title = ".";
  
  if (stage_win32->wtitle != NULL)
    g_free (stage_win32->wtitle);
  stage_win32->wtitle = g_utf8_to_utf16 (title, -1, NULL, NULL, NULL);

  /* If the window is not yet created, the title will be set during the
     window creation */
  if (stage_win32->hwnd != NULL)
    SetWindowTextW (stage_win32->hwnd, stage_win32->wtitle);
}
コード例 #26
0
static void
clutter_stage_win32_allocate (ClutterActor           *self,
			      const ClutterActorBox  *box,
                              ClutterAllocationFlags  flags)
{
  ClutterStageWin32 *stage_win32 = CLUTTER_STAGE_WIN32 (self);
  gint new_width, new_height;

  new_width  = ABS (box->x2 - box->x1);
  new_height = ABS (box->y2 - box->y1);

  if (new_width != stage_win32->win_width ||
      new_height != stage_win32->win_height)
    {
      /* Ignore size requests if we are in full screen mode */
      if ((stage_win32->state & CLUTTER_STAGE_STATE_FULLSCREEN) == 0)
	{
	  stage_win32->win_width = new_width;
	  stage_win32->win_height = new_height;

	  if (stage_win32->hwnd != NULL && !stage_win32->is_foreign_win)
	    {
	      int full_width, full_height;

	      get_full_window_size (stage_win32,
				    new_width, new_height,
				    &full_width, &full_height);

	      SetWindowPos (stage_win32->hwnd, NULL,
			    0, 0,
			    full_width, full_height,
			    SWP_NOZORDER | SWP_NOMOVE);
	    }
	}

      CLUTTER_SET_PRIVATE_FLAGS (stage_win32->wrapper,
				 CLUTTER_ACTOR_SYNC_MATRICES);
    }

  CLUTTER_ACTOR_CLASS (clutter_stage_win32_parent_class)
    ->allocate (self, box, flags);
}
コード例 #27
0
static void
clutter_stage_win32_set_property (GObject      *gobject,
                                  guint         prop_id,
                                  const GValue *value,
                                  GParamSpec   *pspec)
{
  ClutterStageWin32 *self = CLUTTER_STAGE_WIN32 (gobject);

  switch (prop_id)
    {
    case PROP_BACKEND:
      self->backend = g_value_get_object (value);
      break;

    case PROP_WRAPPER:
      self->wrapper = g_value_get_object (value);
      break;

    default:
      G_OBJECT_WARN_INVALID_PROPERTY_ID (gobject, prop_id, pspec);
    }
}
コード例 #28
0
static void
clutter_stage_win32_get_preferred_height (ClutterActor  *self,
					  gfloat         for_width,
					  gfloat        *min_height_p,
					  gfloat        *natural_height_p)
{
  ClutterStageWin32 *stage_win32 = CLUTTER_STAGE_WIN32 (self);
  int height;

  /* If we're in fullscreen mode then return the size of the screen
     instead */
  if ((stage_win32->state & CLUTTER_STAGE_STATE_FULLSCREEN))
    height = stage_win32->fullscreen_rect.bottom
           - stage_win32->fullscreen_rect.top;
  else
    height = stage_win32->win_height;

  if (min_height_p)
    *min_height_p = height;

  if (natural_height_p)
    *natural_height_p = height;
}
コード例 #29
0
static void
clutter_stage_win32_get_preferred_width (ClutterActor  *self,
					 gfloat         for_height,
					 gfloat        *min_width_p,
					 gfloat        *natural_width_p)
{
  ClutterStageWin32 *stage_win32 = CLUTTER_STAGE_WIN32 (self);
  int width;

  /* If we're in fullscreen mode then return the size of the screen
     instead */
  if ((stage_win32->state & CLUTTER_STAGE_STATE_FULLSCREEN))
    width = stage_win32->fullscreen_rect.right
          - stage_win32->fullscreen_rect.left;
  else
    width = stage_win32->win_width;

  if (min_width_p)
    *min_width_p = width;

  if (natural_width_p)
    *natural_width_p = width;
}
コード例 #30
0
static gboolean
message_translate (ClutterBackend *backend,
		   ClutterEvent   *event,
		   const MSG      *msg,
		   gboolean       *call_def_window_proc)
{
  ClutterBackendWin32 *backend_win32;
  ClutterStageWin32   *stage_win32;
  ClutterStage        *stage;
  ClutterStageWindow  *impl;
  gboolean            res;

  backend_win32 = CLUTTER_BACKEND_WIN32 (backend);

  /* Do further processing only on events for the stage window */
  stage = clutter_win32_get_stage_from_window (msg->hwnd);

  if (stage == NULL)
    return FALSE;
  impl        = _clutter_stage_get_window (stage);
  stage_win32 = CLUTTER_STAGE_WIN32 (impl);

  event->any.stage = stage;

  res = TRUE;

  switch (msg->message)
    {
    case WM_SIZE:
      if (!stage_win32->is_foreign_win
	  /* Ignore size changes resulting from the stage being
	     minimized - otherwise the window size will be set to
	     0,0 */
	  && msg->wParam != SIZE_MINIMIZED)
	{
	  WORD new_width = LOWORD (msg->lParam);
	  WORD new_height = HIWORD (msg->lParam);
	  guint old_width, old_height;

	  clutter_actor_get_size (CLUTTER_ACTOR (stage),
				  &old_width, &old_height);

	  if (new_width != old_width || new_height != old_height)
	    clutter_actor_set_size (CLUTTER_ACTOR (stage),
				    new_width, new_height);
	}
      res = FALSE;
      break;

    case WM_SHOWWINDOW:
      if (msg->wParam)
	clutter_stage_win32_map (stage_win32);
      else
	clutter_stage_win32_unmap (stage_win32);
      res = FALSE;
      break;

    case WM_ACTIVATE:
      if (msg->wParam == WA_INACTIVE)
	{
	  if (stage_win32->state & CLUTTER_STAGE_STATE_ACTIVATED)
	    {
	      stage_win32->state &= ~CLUTTER_STAGE_STATE_ACTIVATED;

	      event->type = CLUTTER_STAGE_STATE;
	      event->stage_state.changed_mask = CLUTTER_STAGE_STATE_ACTIVATED;
	      event->stage_state.new_state = stage_win32->state;
	    }
	  else
	    res = FALSE;
	  break;
	}
      else
	{
	  if (!(stage_win32->state & CLUTTER_STAGE_STATE_ACTIVATED))
	    {
	      stage_win32->state |= CLUTTER_STAGE_STATE_ACTIVATED;

	      event->type = CLUTTER_STAGE_STATE;
	      event->stage_state.changed_mask = CLUTTER_STAGE_STATE_ACTIVATED;
	      event->stage_state.new_state = stage_win32->state;
	    }
	  else
	    res = FALSE;
	}
      break;

    case WM_PAINT:
      CLUTTER_NOTE (MULTISTAGE, "expose for stage:%p, redrawing", stage);
      clutter_redraw (stage);
      res = FALSE;
      break;

    case WM_DESTROY:
      CLUTTER_NOTE (EVENT, "WM_DESTROY");
      event->type = CLUTTER_DESTROY_NOTIFY;
      break;

    case WM_CLOSE:
      CLUTTER_NOTE (EVENT, "WM_CLOSE");
      event->type = CLUTTER_DELETE;
      /* The default window proc will destroy the window so we want to
	 prevent this to allow applications to optionally destroy the
	 window themselves */
      if (call_def_window_proc)
	*call_def_window_proc = FALSE;
      break;

    case WM_LBUTTONDOWN:
      make_button_event (msg, event, 1, 1, FALSE);
      break;

    case WM_MBUTTONDOWN:
      make_button_event (msg, event, 2, 1, FALSE);
      break;

    case WM_RBUTTONDOWN:
      make_button_event (msg, event, 3, 1, FALSE);
      break;

    case WM_LBUTTONUP:
      make_button_event (msg, event, 1, 1, TRUE);
      break;

    case WM_MBUTTONUP:
      make_button_event (msg, event, 2, 1, TRUE);
      break;

    case WM_RBUTTONUP:
      make_button_event (msg, event, 3, 1, TRUE);
      break;

    case WM_LBUTTONDBLCLK:
      make_button_event (msg, event, 1, 2, FALSE);
      break;

    case WM_MBUTTONDBLCLK:
      make_button_event (msg, event, 2, 2, FALSE);
      break;

    case WM_RBUTTONDBLCLK:
      make_button_event (msg, event, 3, 2, FALSE);
      break;

    case WM_MOUSEWHEEL:
      stage_win32->scroll_pos += (SHORT) HIWORD (msg->wParam);

      event->type = CLUTTER_SCROLL;
      event->scroll.time = msg->time;
      event->scroll.modifier_state
	= get_modifier_state (LOWORD (msg->wParam));

      /* conversion to window coordinates is required */
      {
	POINT pt = { GET_X_LPARAM (msg->lParam), GET_Y_LPARAM (msg->lParam) };
	ScreenToClient (msg->hwnd, &pt);
	event->scroll.x = pt.x;
	event->scroll.y = pt.y;
      }

      if (stage_win32->scroll_pos >= WHEEL_DELTA)
	{
	  event->scroll.direction = CLUTTER_SCROLL_UP;
	  stage_win32->scroll_pos -= WHEEL_DELTA;
	}
      else if (stage_win32->scroll_pos <= -WHEEL_DELTA)
	{
	  event->scroll.direction = CLUTTER_SCROLL_DOWN;
	  stage_win32->scroll_pos += WHEEL_DELTA;
	}
      else
	res = FALSE;
      break;

    case WM_MOUSEMOVE:
      event->type = CLUTTER_MOTION;
      event->motion.time = msg->time;
      event->motion.x = GET_X_LPARAM (msg->lParam);
      event->motion.y = GET_Y_LPARAM (msg->lParam);
      event->motion.modifier_state = get_modifier_state (msg->wParam);
      break;

    case WM_KEYDOWN:
    case WM_KEYUP:
    case WM_SYSKEYDOWN:
    case WM_SYSKEYUP:
      {
	int scan_code = (msg->lParam >> 16) & 0xff;
	int min = 0, max = CLUTTER_WIN32_KEY_MAP_SIZE, mid;
	BYTE key_states[256];

	/* Get the keyboard modifier states. GetKeyboardState
	   conveniently gets the key state that was current when the
	   last keyboard message read was generated */
	GetKeyboardState(key_states);

	/* Binary chop to check if we have a direct mapping for this
	   key code */
	while (min < max)
	  {
	    mid = (min + max) / 2;
	    if (clutter_win32_key_map[mid].win_sym == msg->wParam)
	      {
		event->key.keyval = clutter_win32_key_map[mid].clutter_sym;
		event->key.unicode_value = 0;
		break;
	      }
	    else if (clutter_win32_key_map[mid].win_sym < msg->wParam)
	      min = mid + 1;
	    else
	      max = mid;
	  }

	/* If we don't have a direct mapping then try getting the
	   unicode value of the key sym */
	if (min >= max)
	  {
	    WCHAR ch;
	    BYTE shift_state[256];

	    /* Translate to a Unicode value, but only take into
	       account the shift key. That way Ctrl+Shift+C will
	       generate a capital C virtual key code with a zero
	       unicode value for example */
	    memset (shift_state, 0, 256);
	    shift_state[VK_SHIFT] = key_states[VK_SHIFT];
	    shift_state[VK_LSHIFT] = key_states[VK_LSHIFT];
	    shift_state[VK_RSHIFT] = key_states[VK_RSHIFT];
	    shift_state[VK_CAPITAL] = key_states[VK_CAPITAL];

	    if (ToUnicode (msg->wParam, scan_code,
			   shift_state, &ch, 1, 0) == 1
		/* The codes in this range directly match the Latin 1
		   codes so we can just use the Unicode value as the
		   key sym */
		&& ch >= 0x20 && ch <= 0xff)
	      event->key.keyval = ch;
	    else
	      /* Otherwise we don't know what the key means but the
		 application might be able to do something with the
		 scan code so we might as well still generate the
		 event */
	      event->key.keyval = CLUTTER_VoidSymbol;

	    /* Get the unicode value of the keypress again using the
	       full modifier state */
	    if (ToUnicode (msg->wParam, scan_code,
			   key_states, &ch, 1, 0) == 1)
		event->key.unicode_value = ch;
	    else
		event->key.unicode_value = 0;
	  }

	event->key.type = msg->message == WM_KEYDOWN
	  || msg->message == WM_SYSKEYDOWN
	  ? CLUTTER_KEY_PRESS : CLUTTER_KEY_RELEASE;
	event->key.time = msg->time;
	event->key.modifier_state = get_key_modifier_state (key_states);
	event->key.hardware_keycode = scan_code;
      }
      break;

    case WM_GETMINMAXINFO:
      {
	MINMAXINFO *min_max_info = (MINMAXINFO *) msg->lParam;
	_clutter_stage_win32_get_min_max_info (stage_win32, min_max_info);
	if (call_def_window_proc)
	  *call_def_window_proc = FALSE;
      }
      break;

    default:
      /* ignore every other message */
      res = FALSE;
      break;
    }

  return res;
}