void MenuBar_Adjust(HELE hEle) //调整布局 { MENUBAR(hEle)->bAdjust=FALSE; menuBar_ *pObject=(menuBar_*)hEle; ele_* pEle=(ele_*)hEle; int top=(pEle->rect.bottom-pEle->rect.top-MENUBAR(hEle)->buttonHeight)/2; int left=5; int width=0; RECT rect; int count=XArray_GetCount(pEle->hArrayEle); for(int i=0;i<count;i++) { HELE hMenuBarBtn=(HELE)(menuBarButon_*)XArray_GetAt( pEle->hArrayEle,i); if(XC_MENUBAR_BUTTON==XC_GetObjectType(hMenuBarBtn)) { XEle_GetRect(hMenuBarBtn,&rect); width=rect.right-rect.left; rect.left=left; rect.right=rect.left+width; rect.top=top; rect.bottom=rect.top+MENUBAR(hEle)->buttonHeight; XEle_SetRect(hMenuBarBtn,&rect); left+=width; } } }
BOOL CALLBACK MenuBar_OnDraw(HELE hEle,HDRAW hDraw) { if(MENUBAR(hEle)->bAdjust) MenuBar_Adjust(hEle); RECT rect; XEle_GetClientRect(hEle,&rect); // if(XEle_IsBkTransparent(hEle)) // Ele_DrawTransparent(hEle,hdc,&rect); // else // { XDraw_FillSolidRect_(hDraw,&rect,((ele_*)hEle)->bkColor); if(MENUBAR(hEle)->hImage) { XDraw_HImageSuper_(hDraw,MENUBAR(hEle)->hImage,&rect); }else { HPEN hPen=XDraw_CreatePen_(hDraw,PS_SOLID,1,RGB(180,180,180)); HGDIOBJ hOld=XDraw_SelectObject_(hDraw,hPen); XDraw_MoveToEx_(hDraw,0,rect.bottom-1,NULL); XDraw_LineTo_(hDraw,rect.right,rect.bottom-1); // SelectObject(hdc,hOld); // DeleteObject(hPen); } // } return TRUE; }
static cb_ret_t menubar_callback (Widget * w, Widget * sender, widget_msg_t msg, int parm, void *data) { WMenuBar *menubar = MENUBAR (w); switch (msg) { /* We do not want the focus unless we have been activated */ case MSG_FOCUS: if (!menubar->is_active) return MSG_NOT_HANDLED; /* Trick to get all the mouse events */ w->lines = LINES; /* Trick to get all of the hotkeys */ widget_want_hotkey (w, 1); menubar_draw (menubar); return MSG_HANDLED; /* We don't want the buttonbar to activate while using the menubar */ case MSG_HOTKEY: case MSG_KEY: if (menubar->is_active) { menubar_handle_key (menubar, parm); return MSG_HANDLED; } return MSG_NOT_HANDLED; case MSG_CURSOR: /* Put the cursor in a suitable place */ return MSG_NOT_HANDLED; case MSG_UNFOCUS: return menubar->is_active ? MSG_NOT_HANDLED : MSG_HANDLED; case MSG_DRAW: if (menubar->is_visible) { menubar_draw (menubar); return MSG_HANDLED; } /* fall through */ case MSG_RESIZE: /* try show menu after screen resize */ send_message (w, sender, MSG_FOCUS, 0, data); return MSG_HANDLED; case MSG_DESTROY: menubar_set_menu (menubar, NULL); return MSG_HANDLED; default: return widget_default_callback (w, sender, msg, parm, data); } }
/// @brief 插入弹出菜单按钮. /// @param hEle 元素句柄. /// @param pText 文本内容. /// @param index 插入位置索引. /// @return 按钮位置索引. int WINAPI XMenuBar_InsertButton(HELE hEle,wchar_t *pText,int index) //插入弹出菜单按钮 { IsMenuBarDebug(hEle,__FUNCTION__); HDC hdc=GetDC(NULL); SIZE size; GetTextExtentPoint32(hdc,pText,wcslen(pText),&size); ReleaseDC(NULL,hdc); HELE hButton=MenuBarBtn_Create(0,0,size.cx+6,MENUBAR(hEle)->buttonHeight,pText); if(FALSE==XEle_AddEle(hEle,hButton,XC_ADDELE_INDEX,NULL,index)) { return -1; } MENUBAR(hEle)->bAdjust=TRUE; return index; }
void classbrowser_show_hide(GtkWidget *widget) { gboolean hidden = get_preferences_manager_classbrowser_status(main_window.prefmg); menubar_set_classbrowser_status(MENUBAR(main_window.menu), hidden); if (hidden == 1) classbrowser_show(); else classbrowser_hide(); }
/// @brief 添加菜单条上的菜单弹出按钮. /// @param hEle 元素句柄. /// @param pText 文本内容. /// @return 按钮位置索引. int WINAPI XMenuBar_AddButton(HELE hEle,wchar_t *pText) { IsMenuBarDebug(hEle,__FUNCTION__); HDC hdc=GetDC(NULL); SIZE size; GetTextExtentPoint32(hdc,pText,wcslen(pText),&size); ReleaseDC(NULL,hdc); HELE hButton=MenuBarBtn_Create(0,0,size.cx+6,MENUBAR(hEle)->buttonHeight,pText); if(FALSE==XEle_AddEle(hEle,hButton)) return -1; XEle_EnableFocus(hButton,FALSE); MENUBAR(hEle)->bAdjust=TRUE; return XArray_GetCount(((ele_*)hEle)->hArrayEle)-1; }
void update_controls(MainWindow *main_window, Documentable *document) { gphpedit_debug(DEBUG_MAIN_WINDOW); if (!document) return ; gboolean read_only, can_modify, preview; g_object_get(document, "read_only", &read_only, "can_modify", &can_modify, "can_preview", &preview, NULL); menubar_update_controls(MENUBAR(main_window->pmenu), can_modify, preview, read_only); toolbar_update_controls(TOOLBAR(main_window->toolbar_main), can_modify, read_only); }
void side_panel_show_hide(MainWindow *main_window) { gboolean hidden; g_object_get(main_window->prefmg, "side_panel_hidden", &hidden, NULL); menubar_set_classbrowser_status(MENUBAR(main_window->pmenu), hidden); if (hidden) side_panel_show(main_window); else side_panel_hide(main_window); }
/// @brief 设置菜单条元素背景贴图. /// @param hEle 元素句柄. /// @param hImage 图片句柄. void WINAPI XMenuBar_SetImage(HELE hEle,HIMAGE hImage) { IsMenuBarDebug(hEle,__FUNCTION__); if(hImage) { IsHImageDebug(hImage,__FUNCTION__); } Image_AddImage(MENUBAR(hEle)->hImage,hImage); }
static int edit_dialog_event (Gpm_Event * event, void *data) { WDialog *h = DIALOG (data); Widget *w; Widget *wh = WIDGET (h); int ret = MOU_UNHANDLED; w = WIDGET (find_menubar (h)); if (event->y == wh->y + 1 && (event->type & GPM_DOWN) != 0 && !MENUBAR (w)->is_active) { /* menubar */ GList *l; GList *top = NULL; int x; /* Try find top fullscreen window */ for (l = h->widgets; l != NULL; l = g_list_next (l)) if (edit_widget_is_editor (WIDGET (l->data)) && ((WEdit *) l->data)->fullscreen) top = l; /* Handle fullscreen/close buttons in the top line */ x = wh->x + wh->cols + 1 - 6; if (top != NULL && event->x >= x) { WEdit *e; e = (WEdit *) top->data; x = event->x - x; if (top != h->current) { /* Window is not active. Activate it */ dlg_set_top_widget (e); } /* Handle buttons */ if (x <= 2) edit_toggle_fullscreen (e); else send_message (h, NULL, MSG_ACTION, CK_Close, NULL); ret = MOU_NORMAL; } if (ret == MOU_UNHANDLED) dlg_select_widget (w); } return ret; }
/// @brief 删除菜单条上的指定弹出菜单按钮,并且销毁,同时该弹出菜单按钮下的弹出菜单也被销毁. /// @param hEle 元素句柄. /// @param index 按钮所在位置索引. void WINAPI XMenuBar_DeleteButton(HELE hEle,int index) //删除菜单项并且销毁,同时该按钮下的弹出菜单也被销毁 { IsMenuBarDebug(hEle,__FUNCTION__); int count = XArray_GetCount(((ele_*)hEle)->hArrayEle); if(index>=0 && index<count) { HELE hDel=(HELE)XArray_GetAt(((ele_*)hEle)->hArrayEle,index); XEle_Destroy(hDel); MENUBAR(hEle)->bAdjust=TRUE; } }
void MenuBar_OnMenuMouseMove(HELE hEle,POINT *pPt) { //pPt:屏幕坐标 menuBar_ *pMenuBar=MENUBAR(hEle); if(pMenuBar->bDown) { POINT pt={pPt->x,pPt->y}; ScreenToClient(((ele_*)hEle)->pWindow->hWnd,&pt); XEle_PointNCWndToEle(hEle,&pt); MenuBar_OnMouseMove(hEle,0,&pt); } }
BOOL CALLBACK MenuBar_OnMouseMove(HELE hEle,UINT flags,POINT *pPt) { menuBar_ *pMenuBar=MENUBAR(hEle); if(pMenuBar->bDown) { POINT pt={pPt->x,pPt->y}; int count=Array_GetCount(((ele_*)hEle)->hArrayEle); for(int i=0; i<count; i++) { ele_ *pChild=Array_GetAtEle(((ele_*)hEle)->hArrayEle,i); if(XC_MENUBAR_BUTTON==XC_GetObjectType(pChild)) { if( PtInRect(&pChild->rect,pt) ) { int menuItemCount=XMenu_GetItemCount(((menuBarButon_*)pChild)->hMenu); if(menuItemCount>0) { if(pMenuBar->pBtnTop!=((menuBarButon_*)pChild)) { if(pMenuBar->pBtnTop) //关闭先前的菜单 { MenuBarBtn_CloseMenu((HELE)pMenuBar->pBtnTop); ((button_*)pMenuBar->pBtnTop)->state=STATE_LEAVE; //修改按钮状态 XEle_RedrawEle((HELE)pMenuBar->pBtnTop); } pMenuBar->pBtnTop=(menuBarButon_*)pChild; ((button_*)pChild)->state=STATE_DOWN; XEle_RedrawEle((HELE)pChild); MenuBarBtn_PopupMenu((HELE)pChild); } } break; } } } } return FALSE; }
//私有方法: void MenuBar_Init(HELE hEle,int x,int y,int cx,int cy,int eleType,HXCGUI hParent) { if(hParent && XC_WINDOW==((object_*)hParent)->type) { Ele_Init(hEle,x,y,cx,cy,eleType,NULL); AddTypeDebug(hEle,XC_MENUBAR); XWnd_AddMenuBar((HWINDOW)hParent,hEle); }else { Ele_Init(hEle,x,y,cx,cy,eleType,hParent); AddTypeDebug(hEle,XC_MENUBAR); } MENUBAR(hEle)->buttonHeight=20; ((ele_*)hEle)->bkColor=RGB(230,230,230); XEle_RegisterMessage(hEle,XM_PAINT,MenuBar_OnDraw); //XEle_RegisterMessage(hEle,XM_MOUSEMOVE,MenuBar_OnMouseMove); //XEle_RegisterEvent(hEle,XE_MENUSELECT,MenuBar_OnEventMenuSelect); //XEle_RegisterEvent(hEle,XE_MENUEXIT,MenuBar_OnEventMenuExit); XEle_RegisterEvent(hEle,XE_DESTROY,MenuBar_OnDestroy); }
WMenuBar * find_menubar (const WDialog * h) { return MENUBAR (find_widget_type (h, menubar_callback)); }
/// @brief 设置菜单条上按钮高度. /// @param hEle 元素句柄. /// @param height 按钮高度. void WINAPI XMenuBar_SetButtonHeight(HELE hEle,int height) { IsMenuBarDebug(hEle,__FUNCTION__); MENUBAR(hEle)->buttonHeight=height; }
static int menubar_event (Gpm_Event * event, void *data) { WMenuBar *menubar = MENUBAR (data); Widget *w = WIDGET (data); gboolean was_active = TRUE; int left_x, right_x, bottom_y; menu_t *menu; Gpm_Event local; if (!mouse_global_in_widget (event, w)) return MOU_UNHANDLED; /* ignore unsupported events */ if ((event->type & (GPM_UP | GPM_DOWN | GPM_DRAG)) == 0) return MOU_NORMAL; /* ignore wheel events if menu is inactive */ if (!menubar->is_active && ((event->buttons & (GPM_B_MIDDLE | GPM_B_UP | GPM_B_DOWN)) != 0)) return MOU_NORMAL; local = mouse_get_local (event, w); if (local.y == 1 && (local.type & GPM_UP) != 0) return MOU_NORMAL; if (!menubar->is_dropped) { if (local.y > 1) { /* mouse click below menubar -- close menu and send focus to widget under mouse */ menubar_finish (menubar); return MOU_UNHANDLED; } menubar->previous_widget = dlg_get_current_widget_id (w->owner); menubar->is_active = TRUE; menubar->is_dropped = TRUE; was_active = FALSE; } /* Mouse operations on the menubar */ if (local.y == 1 || !was_active) { /* wheel events on menubar */ if ((local.buttons & GPM_B_UP) != 0) menubar_left (menubar); else if ((local.buttons & GPM_B_DOWN) != 0) menubar_right (menubar); else { const unsigned int len = g_list_length (menubar->menu); unsigned int new_selection = 0; while ((new_selection < len) && (local.x > MENU (g_list_nth_data (menubar->menu, new_selection))->start_x)) new_selection++; if (new_selection != 0) /* Don't set the invalid value -1 */ new_selection--; if (!was_active) { menubar->selected = new_selection; dlg_select_widget (menubar); } else { menubar_remove (menubar); menubar->selected = new_selection; } menubar_draw (menubar); } return MOU_NORMAL; } if (!menubar->is_dropped || (local.y < 2)) return MOU_NORMAL; /* middle click -- everywhere */ if (((local.buttons & GPM_B_MIDDLE) != 0) && ((local.type & GPM_DOWN) != 0)) { menubar_execute (menubar); return MOU_NORMAL; } /* the mouse operation is on the menus or it is not */ menu = MENU (g_list_nth_data (menubar->menu, menubar->selected)); left_x = menu->start_x; right_x = left_x + menu->max_entry_len + 3; if (right_x > w->cols) { left_x = w->cols - menu->max_entry_len - 3; right_x = w->cols; } bottom_y = g_list_length (menu->entries) + 3; if ((local.x >= left_x) && (local.x <= right_x) && (local.y <= bottom_y)) { int pos = local.y - 3; const menu_entry_t *entry = MENUENTRY (g_list_nth_data (menu->entries, pos)); /* mouse wheel */ if ((local.buttons & GPM_B_UP) != 0 && (local.type & GPM_DOWN) != 0) { menubar_up (menubar); return MOU_NORMAL; } if ((local.buttons & GPM_B_DOWN) != 0 && (local.type & GPM_DOWN) != 0) { menubar_down (menubar); return MOU_NORMAL; } /* ignore events above and below dropped down menu */ if ((pos < 0) || (pos >= bottom_y - 3)) return MOU_NORMAL; if ((entry != NULL) && (entry->command != CK_IgnoreKey)) { menubar_paint_idx (menubar, menu->selected, MENU_ENTRY_COLOR); menu->selected = pos; menubar_paint_idx (menubar, menu->selected, MENU_SELECTED_COLOR); if ((event->type & GPM_UP) != 0) menubar_execute (menubar); } } else if (((local.type & GPM_DOWN) != 0) && ((local.buttons & (GPM_B_UP | GPM_B_DOWN)) == 0)) { /* use click not wheel to close menu */ menubar_finish (menubar); } return MOU_NORMAL; }
void CALLBACK MenuBar_OnDestroy(HELE hEle) //销毁 { if(MENUBAR(hEle)->hImage) XImage_Destroy(MENUBAR(hEle)->hImage); }