예제 #1
0
LRESULT CWinMenu::OnMenuCommand(WPARAM wParam, LPARAM lParam)
{
	// Relay to parent if any
	if ( m_hParentMenu != NULL )
		::PostMessage( m_hParentMenu, WM_MENUCMD, wParam, lParam );

	// Is it a valid command?
	else if ( wParam != 0 && lParam != NULL )
	{
		::PostMessage( (HWND)lParam, WM_COMMAND, wParam, 0L );
		if ( !m_bAutoDestroy ) UnselectMenu();
		else DestroyWindow();
	} // end else

	// Send to our parent?
	else if ( wParam != 0 )
	{
		::PostMessage( m_hWndMsgTarget, WM_COMMAND, wParam, 0L );
		if ( !m_bAutoDestroy ) UnselectMenu();
		else DestroyWindow();
	} // end else if

	else if ( !m_bAutoDestroy ) UnselectMenu();

	else DestroyWindow();

	return 1;
}
예제 #2
0
void CWinMenu::OnKillFocus(CWnd* pNewWnd) 
{
	CWnd::OnKillFocus(pNewWnd);

	// Ignore refocus
	if ( pNewWnd == this ) return;

	else if ( pNewWnd != NULL )
	{
		// Is our parent getting the focus?
		if ( pNewWnd->GetSafeHwnd() == m_hParentMenu )
			return;

		// Is it one of our child windows getting the focus?
		LPMITEMINFO		pmi = NULL;
		while ( ( pmi = (LPMITEMINFO)m_mitems.GetNext( pmi ) ) != NULL )
			if ( pmi->submenu != NULL )
				if ( pmi->submenu->GetSafeHwnd() == pNewWnd->GetSafeHwnd() )
					return;

	} // end else if

	// Let the parent do it
	if ( m_hParentMenu != NULL )			
		::PostMessage( m_hParentMenu, WM_MENUCMD, 0, 0L );
	
	else if ( !m_bAutoDestroy ) UnselectMenu();
		
	else DestroyWindow();
}
예제 #3
0
void CWinMenu::OnTimer(UINT_PTR nIDEvent) 
{
	if ( nIDEvent == TIMERID )
	{
		POINT	pt;
		RECT	rect;
		GetCursorPos( &pt );
		GetWindowRect( &rect );

		if (	pt.x < rect.left || pt.x > rect.right ||
				pt.y < rect.top || pt.y > rect.bottom )
		{
//			UnselectMenu();

			if ( m_dwDestroyDelay > 3000 )
			{	if ( !m_bAutoDestroy ) UnselectMenu();
				else DestroyWindow();
			} // end if
			else m_dwDestroyDelay++;
		} // end if
		else m_dwDestroyDelay = 0;

	} // end if	

	CWnd::OnTimer(nIDEvent);
}
예제 #4
0
void CWinMenu::OnSysKeyDown(UINT nChar, UINT nRepCnt, UINT nFlags) 
{
	CWnd::OnSysKeyDown(nChar, nRepCnt, nFlags);

	m_menuitem = NULL;
	if ( !m_bAutoDestroy ) UnselectMenu();
	else DestroyWindow();
}
예제 #5
0
void CWinMenu::OnLButtonDown(UINT nFlags, CPoint point) 
{
	BOOL bCmdArea = FALSE;
	LPMITEMINFO	pmi = GetMenuItem( &point, &bCmdArea );

	// Check with toolbar
	if (	pmi != NULL && pmi->toolbar != NULL && 
			pmi->toolbar->OnLButtonDown( nFlags, &point ) ) 
	{	m_tbclick = pmi; pmi = NULL; RedrawWindow(); }
	else m_tbclick = NULL;

	// Clear if not in command area
	if ( !bCmdArea ) pmi = NULL;

	// Process if object clicked
	if ( pmi != NULL && *pmi->name != NULL )
	{
		if ( pmi->cursor != NULL )
		{
			m_menuitem = pmi;
			SetCapture();
			SetCursor( pmi->cursor );
		} // end if

		// Let the parent window handle it if any
		else if ( m_hParentMenu != NULL )
		{
			// Do they expect us to toggle the flag?
			if ( pmi->cmd == 0 && pmi->b != NULL )
				*pmi->b = !(*pmi->b);

			// Let the parent send the command
			::PostMessage( m_hParentMenu, WM_MENUCMD, (WPARAM)pmi->cmd, (LPARAM)m_hWndMsgTarget );

		} // end else if

		// Ignore clicks on sub menu
		else if ( pmi->cmd == MAXDWORD );

		// Send message if there is a target
		else if ( pmi->cmd != 0 && m_hWndMsgTarget != NULL && IsWindow( m_hWndMsgTarget ) )
		{
			::PostMessage( m_hWndMsgTarget, WM_COMMAND, pmi->cmd, NULL );
//			DestroyWindow();

			// Destroy if needed
			if ( !m_bAutoDestroy ) UnselectMenu();
			else PostMessage( WM_CLOSE, 0, 0L );

		} // end if

//		else DestroyWindow();

	} // end if
	
	CWnd::OnLButtonDown(nFlags, point);
}
예제 #6
0
파일: PopupMenu.c 프로젝트: ThomasAdam/fvwm
void EvtMousePopupMenu(struct XObj *xobj, XButtonEvent *EvtButton)
{
  static XEvent event;
  int x,y,hOpt,yMenu,hMenu;
  int x1,y1,x2,y2,oldy;
  int oldvalue = 0;
  int newvalue = 0;
  Window Win1,Win2,WinPop;
  unsigned int modif;
  unsigned long mask;
  unsigned long while_mask;
  XSetWindowAttributes Attr;
  Time start_time = 0;
  KeySym ks;
  unsigned char buf[10];
  Bool End = 1;
  int asc = xobj->Ffont->ascent;

  hOpt = xobj->Ffont->height + 10;
  xobj->value3 = CountOption(xobj->title);
  yMenu = xobj->y - ((xobj->value-1) * hOpt);
  hMenu = xobj->value3 * hOpt;

  /* Creation de la fenetre menu */
  XTranslateCoordinates(dpy, *xobj->ParentWin, Root,
			xobj->x, yMenu, &x, &y, &Win1);
  if (x < 0) x = 0;
  if (y < 0) y = 0;
  if (x+xobj->width > XDisplayWidth(dpy, screen))
    x = XDisplayWidth(dpy, screen) - xobj->width;
  if (y+hMenu > XDisplayHeight(dpy, screen))
    y = XDisplayHeight(dpy, screen) - hMenu;
  mask = 0;
  Attr.background_pixel = xobj->TabColor[back];
  mask |= CWBackPixel;
  Attr.border_pixel = 0;
  mask |= CWBorderPixel;
  Attr.colormap = Pcmap;
  mask |= CWColormap;
  Attr.cursor = XCreateFontCursor(dpy, XC_hand2);
  mask |= CWCursor;             /* Curseur pour la fenetre / Window cursor */
  Attr.override_redirect = True;
  mask |= CWOverrideRedirect;
  WinPop = XCreateWindow(dpy, Root, x, y, xobj->width, hMenu, 0,
			 Pdepth, InputOutput, Pvisual, mask, &Attr);
  if (xobj->colorset >= 0)
    SetWindowBackground(dpy, WinPop, xobj->width, hMenu,
			&Colorset[xobj->colorset], Pdepth,
			xobj->gc, True);
  XMapRaised(dpy, WinPop);

  /* Dessin du menu / Drawing the menu */
  DrawPMenu(xobj, WinPop, hOpt, 0);
  XGrabPointer(dpy, WinPop, True, GRAB_EVMASK, GrabModeAsync, GrabModeAsync,
	       None, None, CurrentTime);
  if (EvtButton == NULL) {
    while_mask = ButtonPress;
  }
  else {
    start_time = EvtButton->time;
    while_mask = ButtonRelease;
  }

  while (End)
  {
    FQueryPointer(dpy, Root, &Win1, &Win2, &x1, &y1, &x2, &y2, &modif);
    /* Determiner l'option courante / Current option */
    y2 = y2 - y;
    x2 = x2 - x;
    oldy = y2;
    /* calcule de xobj->value / compute xobj->value */
    if ((x2 > 0) && (x2 < xobj->width) && (y2 > 0) && (y2 < hMenu))
      newvalue = y2 / hOpt+1;
    else
      newvalue = 0;
    if (newvalue != oldvalue)
    {
      UnselectMenu(xobj, WinPop, hOpt, oldvalue, xobj->width, asc, 0);
      SelectMenu(xobj, WinPop, hOpt, newvalue);
      oldvalue = newvalue;
    }

    FNextEvent(dpy, &event);
    switch (event.type)
    {
    case KeyPress:
      XLookupString(&event.xkey, (char *)buf, sizeof(buf), &ks, NULL);
      if (ks == XK_Escape) {
	newvalue = 0;
	End = 0;
      }
      else if (ks == XK_Return) {
	End = 0;
      }
      else if (ks == XK_Up && y2 >= hOpt) {
	FWarpPointer(dpy, None, None, 0, 0, 0, 0, 0, -hOpt);
      }
      else if (ks == XK_Down && y2 + hOpt <= hMenu) {
	FWarpPointer(dpy, None, None, 0, 0, 0, 0, 0, hOpt);
      }
      break;
    case ButtonPress:
      if (while_mask == ButtonPress)
	End = 0;
      break;
    case ButtonRelease:
      if (start_time != 0 && event.xbutton.time - start_time < MENU_DRAG_TIME) {
	while_mask = ButtonPress;
	start_time = 0;
      }
      if (while_mask == ButtonRelease)
	End = 0;
      break;
    }
  }
#if 0
  do
  {
    FQueryPointer(dpy, Root, &Win1, &Win2, &x1, &y1, &x2, &y2, &modif);
    /* Determiner l'option courante / Current option */
    y2 = y2 - y;
    x2 = x2 - x;
    {
      oldy = y2;
      /* calcule de xobj->value / compute xobj->value */
      if ((x2 > 0) && (x2 < xobj->width) && (y2 > 0) && (y2 < hMenu))
	newvalue = y2 / hOpt+1;
      else
	newvalue = 0;
      if (newvalue != oldvalue)
      {
	UnselectMenu(xobj, WinPop, hOpt, oldvalue, xobj->width, asc, 0);
	SelectMenu(xobj, WinPop, hOpt, newvalue);
	oldvalue = newvalue;
      }
    }
    FD_ZERO(&in_fdset);
    FD_SET(x_fd, &in_fdset);
    select(32, SELECT_FD_SET_CAST &in_fdset, NULL, NULL, NULL);
  }
  while (!FCheckTypedEvent(dpy, while_mask, &event));
#endif
 XUngrabPointer(dpy, CurrentTime);
 XSync(dpy,0);

 XDestroyWindow(dpy, WinPop);
 if (newvalue != 0)
 {
   xobj->value = newvalue;
   SendMsg(xobj, SingleClic);
 }
}
예제 #7
0
파일: PushButton.c 프로젝트: fvwmorg/fvwm
void EvtMousePushButton(struct XObj *xobj, XButtonEvent *EvtButton)
{
	static XEvent event;
	int End = 1;
	unsigned int modif;
	int x1,x2,y1,y2,i;
	Window Win1,Win2,WinPop;
	Window WinBut = 0;
	int In = 0;
	char *str;
	int x,y,hOpt,yMenu,hMenu,wMenu;
	int oldvalue = 0,newvalue;
	unsigned long mask;
	XSetWindowAttributes Attr;

	if (EvtButton->button == Button1)
	{
		i = (xobj->width -
		     FlocaleTextWidth(
			     xobj->Ffont, xobj->title, strlen(xobj->title)))/2;

		while (End)
		{
			FNextEvent(dpy, &event);
			switch (event.type)
			{
			case EnterNotify:
				FQueryPointer(
					dpy, *xobj->ParentWin,
					&Win1, &Win2, &x1, &y1, &x2, &y2,
					&modif);
				if (WinBut == 0)
				{
					WinBut = Win2;
					DrawReliefRect(
						0, 0, xobj->width,
						xobj->height, xobj, shad,
						hili);
					DrawIconStr(
						0,xobj, True,
						PUSH_BUTTON_LCR_OFFSETS, NULL,
						NULL, NULL);
					In = 1;
				}
				else
				{
					if (Win2 == WinBut)
					{
						DrawReliefRect(
							0, 0, xobj->width,
							xobj->height, xobj,
							shad, hili);
						DrawIconStr(
							1, xobj, True,
							PUSH_BUTTON_LCR_OFFSETS,
							NULL, NULL, NULL);
						In = 1;
					}
					else if (In)
					{
						In = 0;
						DrawReliefRect(
							0, 0, xobj->width,
							xobj->height, xobj,
							hili, shad);
						DrawIconStr(
							0, xobj, True,
							PUSH_BUTTON_LCR_OFFSETS,
							NULL, NULL, NULL);
					}
				}
				break;
			case LeaveNotify:
				FQueryPointer(
					dpy, *xobj->ParentWin,
					&Win1, &Win2, &x1, &y1, &x2, &y2,
					&modif);
				if (Win2 == WinBut)
				{
					In = 1;
					DrawReliefRect(
						0, 0, xobj->width,
						xobj->height, xobj, shad,
						hili);
					DrawIconStr(
						1, xobj, True,
						PUSH_BUTTON_LCR_OFFSETS, NULL,
						NULL, NULL);
				}
				else if (In)
				{
					DrawReliefRect(
						0, 0, xobj->width,
						xobj->height, xobj, hili,
						shad);
					DrawIconStr(
						0, xobj, True,
						PUSH_BUTTON_LCR_OFFSETS, NULL,
						NULL, NULL);
					In = 0;
				}
				break;
			case ButtonRelease:
				End = 0;
				DrawReliefRect(
					0, 0, xobj->width, xobj->height, xobj,
					hili, shad);
				DrawIconStr(
					0, xobj, True,
					PUSH_BUTTON_LCR_OFFSETS, NULL, NULL,
					NULL);
				if (In)
				{
					/* Envoie d'un message vide de type
					 * SingleClic pour un clique souris */
					xobj->value = 1;
					SendMsg(xobj, SingleClic);
					xobj->value = 0;
				}
				break;
			}
		}
	}
	/* affichage du popup menu / Drawing the popup menu */
	else if (EvtButton->button == Button3)
	{
		if (xobj->value3 > 1)
		{
			hOpt = xobj->Ffont->height + 10;
			/* Hauteur totale du menu / Total height of the menu */
			hMenu = (xobj->value3 - 1) * hOpt;
			yMenu = xobj->y + xobj->height;
			wMenu = 0;
			for (i = 2 ; i <= xobj->value3; i++)
			{
				str = (char*)GetMenuTitle(xobj->title, i);
				if (wMenu < FlocaleTextWidth(
					    xobj->Ffont, str, strlen(str))+34)
					wMenu = FlocaleTextWidth(
						xobj->Ffont, str,
						strlen(str))+34;
				free(str);
			}

			/* Creation de la fenetre menu / create the menu
			 * window */
			XTranslateCoordinates(dpy, *xobj->ParentWin, Root,
					      xobj->x, yMenu, &x, &y, &Win1);
			if (x<0) x = 0;
			if (y<0) y = 0;
			if (x + wMenu > XDisplayWidth(dpy, screen))
			{
				x = XDisplayWidth(dpy, screen) - wMenu;
			}
			if (y + hMenu > XDisplayHeight(dpy, screen))
			{
				y = y-hMenu-xobj->height;
			}

			mask = 0;
			Attr.background_pixel = xobj->TabColor[back];
			mask |= CWBackPixel;
			Attr.border_pixel  =  0;
			mask |= CWBorderPixel;
			Attr.colormap = Pcmap;
			mask |= CWColormap;
			Attr.cursor = XCreateFontCursor(dpy, XC_hand2);
			mask |= CWCursor;         /* Curseur pour la fenetre */
			Attr.override_redirect = True;
			mask |= CWOverrideRedirect;
			WinPop = XCreateWindow(
				dpy, Root, x, y, wMenu-5, hMenu, 0,
				Pdepth, InputOutput, Pvisual, mask, &Attr);
			if (xobj->colorset >= 0)
				SetWindowBackground(
					dpy, WinPop, wMenu - 5, hMenu,
					&Colorset[xobj->colorset], Pdepth,
					xobj->gc, True);
			XMapRaised(dpy, WinPop);

			/* Dessin du menu */
			DrawPMenu(xobj, WinPop, hOpt, 1);
			do
			{
				FQueryPointer(
					dpy, Root, &Win1, &Win2, &x1, &y1,
					&x2, &y2, &modif);
				/* Determiner l'option courante / Current
				 * option */
				y2 = y2 - y;
				x2 = x2 - x;
				{
					/* calcule de xobj->value / Compute
					 * xobj->value */
					if ((x2 > 0) && (x2 < wMenu) &&
					    (y2 > 0) && (y2 < hMenu))
						newvalue = y2 / hOpt+1;
					else
						newvalue = 0;
					if (newvalue!=oldvalue)
					{
						UnselectMenu(
							xobj, WinPop, hOpt,
							oldvalue, wMenu-5,
							xobj->Ffont->ascent,
							1);
						SelectMenu(
							xobj, WinPop, hOpt,
							newvalue);
						oldvalue = newvalue;
					}
				}
			}
			while (!FCheckTypedEvent(dpy, ButtonRelease, &event));
			XDestroyWindow(dpy, WinPop);
			if (newvalue != 0)
			{
				xobj->value = newvalue;
				SendMsg(xobj, SingleClic);
				xobj->value = 0;
			}
			xobj->DrawObj(xobj, NULL);
		} /* xobj->value3 > 1 */
	} /* EvtButton->button == Button3 */
}
예제 #8
0
void CWinMenu::OnLButtonUp(UINT nFlags, CPoint point) 
{
	BOOL bCmdArea = FALSE;
	LPMITEMINFO	pmi = GetMenuItem( &point, &bCmdArea );
	if ( pmi == NULL ) return;

	// Call up on toolbar
	if ( m_tbclick != NULL ) 
	{
		if ( m_tbclick->toolbar->OnLButtonUp( nFlags, &point ) )
			RedrawWindow(); 
	} // end if

	// Punt if not in command area
	if ( !bCmdArea ) return;

	// Release capture
	ReleaseCapture();
	
	RedrawLastWindow();
	
	// Send message if needed
	if ( m_menuitem != NULL )
	{
		POINT pt;
		pt.x = point.x;
		pt.y = point.y;
		ClientToScreen( &pt );

		// Which window was choosen
		HWND hParent = ::WindowFromPoint( pt );
		if ( m_bAllowChildren )
		{
			if ( hParent != NULL )
			{
				// Check for child windows
				::ScreenToClient( hParent, &pt );
				HWND hChild = ::ChildWindowFromPoint( hParent, pt );
				
				// Which window to use
				if ( hChild != NULL ) m_hDropWnd = hChild;
				else m_hDropWnd = hParent;
					
			} // end if
		} // end if
		else
		{
			// Get topmost window
			while ( hParent != NULL )
			{
				m_hDropWnd = hParent;
				hParent = ::GetParent( hParent );
			} // end while

		} // end else

		// Send message if there is a target
		if ( m_menuitem->cmd != 0 && m_hWndMsgTarget != NULL )
		{
			::PostMessage( m_hWndMsgTarget, WM_COMMAND, m_menuitem->cmd, 0L );
		} // end if

		m_menuitem = NULL;

		// Kill our window if needed
		if ( !m_bAutoDestroy ) UnselectMenu();
		else DestroyWindow();

	} // end if

	CWnd::OnLButtonUp(nFlags, point);
}