~unity-team/nux/nux.dyn-casting

« back to all changes in this revision

Viewing changes to Nux/WindowCompositor.cpp

  • Committer: Jay Taoko
  • Date: 2011-03-20 04:03:32 UTC
  • Revision ID: jay.taoko@canonical.com-20110320040332-xqz8epaws53qplvc
* Add MenuEventCycle
* Prioritize menu over Grab action

Show diffs side-by-side

added added

removed removed

Lines of Context:
259
259
    // Event processing cycle begins.
260
260
    _inside_event_processing = true;
261
261
 
262
 
    if ((event.e_event == NUX_KEYDOWN) ||
263
 
      (event.e_event == NUX_KEYUP))
264
 
    {
265
 
      Area *keyboard_grab_area = GetKeyboardGrabArea ();
266
 
      if (keyboard_grab_area)
267
 
      {
268
 
        ViewWindowPreEventCycle ();
269
 
        
270
 
        DispatchEventToView (event, (View*) keyboard_grab_area, 0, 0);
271
 
        
272
 
        ViewWindowPostEventCycle ();
273
 
 
274
 
        return;
275
 
      }
276
 
    }
277
 
 
278
262
    if ((event.e_event == NUX_MOUSE_PRESSED) ||
279
263
      (event.e_event == NUX_MOUSE_RELEASED) ||
280
264
      (event.e_event == NUX_MOUSE_MOVE) ||
281
265
      (event.e_event == NUX_MOUSE_WHEEL) ||
282
 
      (event.e_event == NUX_MOUSE_DOUBLECLICK))
 
266
      (event.e_event == NUX_MOUSE_DOUBLECLICK) ||
 
267
      (event.e_event == NUX_KEYDOWN) ||
 
268
      (event.e_event == NUX_KEYUP))
283
269
    {
284
270
      Area *pointer_grab_area = GetPointerGrabArea ();
285
 
      if (pointer_grab_area)
 
271
      Area *keyboard_grab_area = GetKeyboardGrabArea ();
 
272
 
 
273
      if (pointer_grab_area || keyboard_grab_area)
286
274
      {
 
275
        SetCurrentEvent (&event);
 
276
 
 
277
        long ret = 0;
 
278
        long ProcessEventInfo = 0;
 
279
        bool MouseIsOverMenu = 0;
 
280
 
 
281
        // Let the Menus process the event.
 
282
        {
 
283
          ret = MenuEventCycle (event, 0, 0);
 
284
 
 
285
          CleanMenu ();
 
286
 
 
287
          if (ret & eMouseEventSolved)
 
288
          {
 
289
            // If one menu processed the event, then stop all other element from processing it.
 
290
            ProcessEventInfo = eDoNotProcess;
 
291
            MouseIsOverMenu = TRUE;
 
292
 
 
293
            SetCurrentEvent (NULL);
 
294
            return;
 
295
          }
 
296
        }
 
297
        
 
298
        
287
299
        ViewWindowPreEventCycle ();
288
 
 
289
 
        DispatchEventToView (event, (View*) pointer_grab_area, 0, 0);
290
 
 
 
300
        SetProcessingTopView (NUX_STATIC_CAST (BaseWindow*, pointer_grab_area->GetTopLevelViewWindow ()));
 
301
 
 
302
        if (pointer_grab_area &&
 
303
            ((event.e_event == NUX_MOUSE_PRESSED) ||
 
304
            (event.e_event == NUX_MOUSE_RELEASED) ||
 
305
            (event.e_event == NUX_MOUSE_MOVE) ||
 
306
            (event.e_event == NUX_MOUSE_WHEEL) ||
 
307
            (event.e_event == NUX_MOUSE_DOUBLECLICK))
 
308
        )
 
309
        {
 
310
          DispatchEventToView (event, (View*) pointer_grab_area, 0, 0);
 
311
        }
 
312
 
 
313
        if (keyboard_grab_area &&
 
314
            ((event.e_event == NUX_KEYDOWN) ||
 
315
            (event.e_event == NUX_KEYUP))
 
316
        )
 
317
        {
 
318
          ret = DispatchEventToView (event, NUX_STATIC_CAST (View*, keyboard_grab_area), ret, ProcessEventInfo);
 
319
        }
 
320
 
 
321
        SetProcessingTopView (NULL);
291
322
        ViewWindowPostEventCycle ();
 
323
        
 
324
        SetCurrentEvent (NULL);
292
325
 
293
326
        return;
294
327
      }
297
330
    long ret = 0;
298
331
    bool base_window_reshuffling = false; // Will be set to true if the BaseWindow are reshuffled.
299
332
 
300
 
    std::list<MenuPage *>::iterator menu_it;
 
333
    //std::list<MenuPage*>::iterator menu_it;
301
334
 
302
335
    if((event.e_event == NUX_SIZE_CONFIGURATION) ||
303
336
      (event.e_event == NUX_WINDOW_ENTER_FOCUS))
309
342
    }
310
343
 
311
344
 
312
 
    if (GetMouseFocusArea() && (event.e_event != NUX_MOUSE_PRESSED) && (!InExclusiveInputMode ()))
 
345
    if (GetMouseFocusArea() && (event.e_event != NUX_MOUSE_PRESSED))
313
346
    {
314
347
      SetCurrentEvent (&event);
315
348
      SetProcessingTopView (GetFocusAreaWindow());
327
360
        SetWidgetDrawingOverlay (NULL, NULL);
328
361
      }
329
362
 
330
 
 
331
 
      // Let all the menu area check the event first. Beside, they are on top of everything else.
 
363
      std::list<MenuPage*>::iterator menu_it;
 
364
      // Let all the menu area check the event first.
332
365
      for (menu_it = m_MenuList->begin(); menu_it != m_MenuList->end(); menu_it++)
333
366
      {
334
367
        // The deepest menu in the menu cascade is in the front of the list.
342
375
    {
343
376
      SetCurrentEvent (&event);
344
377
 
345
 
      if (!InExclusiveInputMode ()) // Menus are not enabled in exclusive mode
346
 
      {
347
 
        if (m_MenuWindow.IsValid())
348
 
        {
349
 
          event.e_x_root = m_MenuWindow->GetBaseX();
350
 
          event.e_y_root = m_MenuWindow->GetBaseY();
351
 
        }
352
 
 
353
 
        // Let all the menu area check the event first. Beside, they are on top of everything else.
354
 
        for (menu_it = m_MenuList->begin(); menu_it != m_MenuList->end(); menu_it++)
355
 
        {
356
 
          // The deepest menu in the menu cascade is in the front of the list.
357
 
          ret = (*menu_it)->ProcessEvent (event, ret, 0);
358
 
        }
359
 
 
360
 
        if ( (event.e_event == NUX_MOUSE_PRESSED) && m_MenuList->size() )
361
 
        {
362
 
          bool inside = false;
363
 
 
364
 
          for (menu_it = m_MenuList->begin(); menu_it != m_MenuList->end(); menu_it++)
365
 
          {
366
 
            Geometry geo = (*menu_it)->GetGeometry();
367
 
 
368
 
            if (PT_IN_BOX ( event.e_x - event.e_x_root, event.e_y - event.e_y_root,
369
 
                            geo.x, geo.x + geo.width, geo.y, geo.y + geo.height ) )
370
 
            {
371
 
              inside = true;
372
 
              break;
373
 
            }
374
 
          }
375
 
 
376
 
          if (inside == false)
377
 
          {
378
 
            (*m_MenuList->begin() )->NotifyMouseDownOutsideMenuCascade (event.e_x - event.e_x_root, event.e_y - event.e_y_root);
379
 
          }
380
 
        }
381
 
 
382
 
        if (m_MenuWindow.IsValid())
383
 
        {
384
 
          event.e_x_root = 0;
385
 
          event.e_y_root = 0;
386
 
        }
387
 
 
388
 
        if ( (event.e_event == NUX_MOUSE_RELEASED) )
389
 
        {
390
 
          SetWidgetDrawingOverlay (NULL, NULL);
391
 
        }
392
 
 
393
 
        if ( (event.e_event == NUX_SIZE_CONFIGURATION) && m_MenuList->size() )
394
 
        {
395
 
          (*m_MenuList->begin() )->NotifyTerminateMenuCascade();
396
 
        }
397
 
      }
398
 
 
 
378
      // Let the Menus process the event.
 
379
      long ret = 0;
399
380
      long ProcessEventInfo = 0;
400
381
      bool MouseIsOverMenu = 0;
401
 
 
402
 
      if (ret & eMouseEventSolved)
403
382
      {
404
 
        // If one menu processed the event, then stop all other element from processing it.
405
 
        ProcessEventInfo = eDoNotProcess;
406
 
        MouseIsOverMenu = TRUE;
 
383
        MenuEventCycle (event, 0, 0);
 
384
 
 
385
        if (ret & eMouseEventSolved)
 
386
        {
 
387
          // If one menu processed the event, then stop all other element from processing it.
 
388
          ProcessEventInfo = eDoNotProcess;
 
389
          MouseIsOverMenu = TRUE;
 
390
        }
407
391
      }
408
392
 
409
 
      /////////////////////////////////////////
410
 
      // Start ViewWindow event processing.
411
 
      /////////////////////////////////////////
412
 
 
 
393
      // Let the ViewWindow process the event.
413
394
      ViewWindowPreEventCycle ();
414
395
 
415
396
      std::list< ObjectWeakPtr<BaseWindow> >::iterator it;
513
494
    EnsureAlwaysOnFrontWindow ();
514
495
  }
515
496
 
 
497
  long WindowCompositor::MenuEventCycle (Event &event, long TraverseInfo, long ProcessEventInfo)
 
498
  {
 
499
    long ret = TraverseInfo;
 
500
    std::list<MenuPage*>::iterator menu_it;
 
501
 
 
502
    if (m_MenuWindow.IsValid())
 
503
    {
 
504
      event.e_x_root = m_MenuWindow->GetBaseX ();
 
505
      event.e_y_root = m_MenuWindow->GetBaseY ();
 
506
    }
 
507
 
 
508
    // Let all the menu area check the event first. Beside, they are on top of everything else.
 
509
    for (menu_it = m_MenuList->begin (); menu_it != m_MenuList->end (); menu_it++)
 
510
    {
 
511
      // The deepest menu in the menu cascade is in the front of the list.
 
512
      ret = (*menu_it)->ProcessEvent (event, ret, ProcessEventInfo);
 
513
    }
 
514
 
 
515
    if ((event.e_event == NUX_MOUSE_PRESSED) && m_MenuList->size ())
 
516
    {
 
517
      bool inside = false;
 
518
 
 
519
      for (menu_it = m_MenuList->begin (); menu_it != m_MenuList->end (); menu_it++)
 
520
      {
 
521
        Geometry geo = (*menu_it)->GetGeometry ();
 
522
 
 
523
        if (PT_IN_BOX (event.e_x - event.e_x_root, event.e_y - event.e_y_root,
 
524
                        geo.x, geo.x + geo.width, geo.y, geo.y + geo.height))
 
525
        {
 
526
          inside = true;
 
527
          break;
 
528
        }
 
529
      }
 
530
 
 
531
      if (inside == false)
 
532
      {
 
533
        (*m_MenuList->begin ())->NotifyMouseDownOutsideMenuCascade (event.e_x - event.e_x_root, event.e_y - event.e_y_root);
 
534
      }
 
535
    }
 
536
 
 
537
    if (m_MenuWindow.IsValid ())
 
538
    {
 
539
      event.e_x_root = 0;
 
540
      event.e_y_root = 0;
 
541
    }
 
542
 
 
543
    if ( (event.e_event == NUX_MOUSE_RELEASED) )
 
544
    {
 
545
      SetWidgetDrawingOverlay (NULL, NULL);
 
546
    }
 
547
 
 
548
    if ( (event.e_event == NUX_SIZE_CONFIGURATION) && m_MenuList->size() )
 
549
    {
 
550
      (*m_MenuList->begin() )->NotifyTerminateMenuCascade();
 
551
    }
 
552
 
 
553
    return ret;
 
554
  }
 
555
 
516
556
  void WindowCompositor::StartModalWindow (ObjectWeakPtr<BaseWindow> window)
517
557
  {
518
558
    if (window == 0)
1425
1465
      m_MenuWindow = NULL;
1426
1466
  }
1427
1467
 
1428
 
  void WindowCompositor::CleanMenu()
 
1468
  void WindowCompositor::CleanMenu ()
1429
1469
  {
1430
1470
    if (m_MenuList->size() == 0)
1431
1471
      return;
1436
1476
    {
1437
1477
      if ( (*menu_it)->IsActive() == false)
1438
1478
      {
 
1479
        if (GetMouseFocusArea () == (*menu_it))
 
1480
        {
 
1481
          SetMouseFocusArea (NULL);
 
1482
        }
 
1483
        if (GetMouseOverArea () == (*menu_it))
 
1484
        {
 
1485
          SetMouseOverArea (NULL);
 
1486
        }
 
1487
        if (GetPreviousMouseOverArea () == (*menu_it))
 
1488
        {
 
1489
          SetPreviousMouseOverArea (NULL);
 
1490
        }                
 
1491
 
1439
1492
        menu_it = m_MenuList->erase (menu_it);
1440
1493
        m_MenuRemoved = true;
1441
1494
      }
1442
1495
      else
 
1496
      {
1443
1497
        menu_it++;
 
1498
      }
1444
1499
    }
1445
1500
 
1446
1501
    if (m_MenuList->size() == 0)
1799
1854
 
1800
1855
    if (GetPointerGrabArea () == area)
1801
1856
    {
1802
 
      nuxDebugMsg (TEXT ("[WindowCompositor::GrabPointerAdd] The area alread has the grab"));
 
1857
      nuxDebugMsg (TEXT ("[WindowCompositor::GrabPointerAdd] The area already has the grab"));
1803
1858
      return result;
1804
1859
    }
1805
1860
    
1861
1916
 
1862
1917
    if (GetKeyboardGrabArea () == area)
1863
1918
    {
1864
 
      nuxDebugMsg (TEXT ("[WindowCompositor::GrabKeyboardAdd] The area alread has the grab"));
 
1919
      nuxDebugMsg (TEXT ("[WindowCompositor::GrabKeyboardAdd] The area already has the grab"));
1865
1920
      return result;
1866
1921
    }
1867
1922