2002-12-25 11:46:50 +00:00
|
|
|
// Menu.cc for FbTk - Fluxbox Toolkit
|
2003-04-20 13:49:26 +00:00
|
|
|
// Copyright (c) 2001 - 2003 Henrik Kinnunen (fluxgen at users.sourceforge.net)
|
2002-12-25 11:46:50 +00:00
|
|
|
//
|
|
|
|
// Basemenu.cc for blackbox - an X11 Window manager
|
|
|
|
// Copyright (c) 1997 - 2000 Brad Hughes (bhughes at tcac.net)
|
|
|
|
//
|
|
|
|
// Permission is hereby granted, free of charge, to any person obtaining a
|
|
|
|
// copy of this software and associated documentation files (the "Software"),
|
|
|
|
// to deal in the Software without restriction, including without limitation
|
|
|
|
// the rights to use, copy, modify, merge, publish, distribute, sublicense,
|
|
|
|
// and/or sell copies of the Software, and to permit persons to whom the
|
|
|
|
// Software is furnished to do so, subject to the following conditions:
|
|
|
|
//
|
|
|
|
// The above copyright notice and this permission notice shall be included in
|
|
|
|
// all copies or substantial portions of the Software.
|
|
|
|
//
|
|
|
|
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
|
|
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
|
|
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
|
|
|
|
// THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
|
|
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
|
|
|
|
// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
|
|
|
|
// DEALINGS IN THE SOFTWARE.
|
|
|
|
|
2003-11-19 12:57:27 +00:00
|
|
|
// $Id: Menu.cc,v 1.41 2003/11/19 12:57:27 rathnor Exp $
|
2002-12-25 11:46:50 +00:00
|
|
|
|
|
|
|
//use GNU extensions
|
|
|
|
#ifndef _GNU_SOURCE
|
|
|
|
#define _GNU_SOURCE
|
|
|
|
#endif // _GNU_SOURCE
|
|
|
|
|
|
|
|
#include "Menu.hh"
|
|
|
|
|
2003-01-12 17:01:02 +00:00
|
|
|
#include "MenuItem.hh"
|
2003-01-10 00:47:59 +00:00
|
|
|
#include "ImageControl.hh"
|
2002-12-25 11:46:50 +00:00
|
|
|
#include "MenuTheme.hh"
|
|
|
|
#include "App.hh"
|
|
|
|
#include "EventManager.hh"
|
2003-04-20 13:49:26 +00:00
|
|
|
#include "Transparent.hh"
|
2002-12-25 11:46:50 +00:00
|
|
|
|
2003-04-20 13:49:26 +00:00
|
|
|
#include <X11/Xatom.h>
|
2003-07-02 05:26:45 +00:00
|
|
|
#include <X11/keysym.h>
|
|
|
|
|
2002-12-25 11:46:50 +00:00
|
|
|
#include <cstdio>
|
|
|
|
#include <cstdlib>
|
|
|
|
#include <cstring>
|
|
|
|
#include <iostream>
|
2003-04-20 13:49:26 +00:00
|
|
|
|
2002-12-25 11:46:50 +00:00
|
|
|
using namespace std;
|
|
|
|
|
2003-04-25 12:32:57 +00:00
|
|
|
namespace {
|
|
|
|
Pixmap getRootPixmap(int screen_num) {
|
|
|
|
Pixmap root_pm = 0;
|
|
|
|
// get root pixmap for transparency
|
|
|
|
Display *disp = FbTk::App::instance()->display();
|
|
|
|
Atom real_type;
|
|
|
|
int real_format;
|
|
|
|
unsigned long items_read, items_left;
|
|
|
|
unsigned int *data;
|
|
|
|
if (XGetWindowProperty(disp, RootWindow(disp, screen_num),
|
|
|
|
XInternAtom(disp, "_XROOTPMAP_ID", false),
|
|
|
|
0L, 1L,
|
|
|
|
false, XA_PIXMAP, &real_type,
|
|
|
|
&real_format, &items_read, &items_left,
|
|
|
|
(unsigned char **) &data) == Success &&
|
|
|
|
items_read) {
|
|
|
|
root_pm = (Pixmap) (*data);
|
|
|
|
XFree(data);
|
|
|
|
}
|
|
|
|
|
|
|
|
return root_pm;
|
|
|
|
}
|
|
|
|
|
|
|
|
}; // end anonymous namespace
|
|
|
|
|
2002-12-25 11:46:50 +00:00
|
|
|
namespace FbTk {
|
|
|
|
|
|
|
|
static Menu *shown = 0;
|
|
|
|
|
2003-07-02 05:26:45 +00:00
|
|
|
Menu *Menu::s_focused = 0;
|
2003-04-20 13:49:26 +00:00
|
|
|
|
2003-01-10 00:47:59 +00:00
|
|
|
Menu::Menu(MenuTheme &tm, int screen_num, ImageControl &imgctrl):
|
2002-12-25 11:46:50 +00:00
|
|
|
m_theme(tm),
|
|
|
|
m_screen_num(screen_num),
|
|
|
|
m_image_ctrl(imgctrl),
|
|
|
|
m_display(FbTk::App::instance()->display()),
|
|
|
|
m_parent(0),
|
|
|
|
m_screen_width(DisplayWidth(m_display, screen_num)),
|
|
|
|
m_screen_height(DisplayHeight(m_display, screen_num)),
|
|
|
|
m_alignment(ALIGNDONTCARE),
|
2003-02-15 01:48:16 +00:00
|
|
|
m_border_width(0),
|
2003-04-26 12:34:48 +00:00
|
|
|
m_themeobserver(*this),
|
2003-04-25 12:32:57 +00:00
|
|
|
m_need_update(true) {
|
2003-02-15 01:48:16 +00:00
|
|
|
|
|
|
|
// make sure we get updated when the theme is reloaded
|
|
|
|
tm.addListener(m_themeobserver);
|
2002-12-25 11:46:50 +00:00
|
|
|
|
|
|
|
title_vis =
|
|
|
|
movable =
|
|
|
|
hide_tree = true;
|
|
|
|
|
|
|
|
shifted =
|
|
|
|
internal_menu =
|
|
|
|
moving =
|
|
|
|
torn =
|
|
|
|
visible = false;
|
|
|
|
|
|
|
|
menu.x =
|
|
|
|
menu.y =
|
|
|
|
menu.x_shift =
|
|
|
|
menu.y_shift =
|
|
|
|
menu.x_move =
|
|
|
|
menu.y_move = 0;
|
|
|
|
|
|
|
|
which_sub =
|
|
|
|
which_press =
|
|
|
|
which_sbl = -1;
|
|
|
|
|
|
|
|
menu.frame_pixmap =
|
|
|
|
menu.title_pixmap =
|
|
|
|
menu.hilite_pixmap =
|
|
|
|
menu.sel_pixmap = None;
|
|
|
|
|
|
|
|
menu.bevel_w = 2;
|
|
|
|
|
|
|
|
menu.width = menu.title_h = menu.item_w = menu.frame_h =
|
|
|
|
m_theme.titleFont().height() + menu.bevel_w * 2;
|
|
|
|
|
|
|
|
menu.sublevels =
|
|
|
|
menu.persub =
|
|
|
|
menu.minsub = 0;
|
|
|
|
|
|
|
|
menu.item_h = m_theme.frameFont().height() + menu.bevel_w;
|
|
|
|
|
|
|
|
menu.height = menu.title_h + 2 + menu.frame_h;
|
2003-04-20 13:49:26 +00:00
|
|
|
|
2003-08-04 12:45:42 +00:00
|
|
|
long event_mask = ButtonPressMask | ButtonReleaseMask |
|
2003-07-02 05:26:45 +00:00
|
|
|
ButtonMotionMask | KeyPressMask | ExposureMask | FocusChangeMask;
|
2002-12-25 11:46:50 +00:00
|
|
|
//create menu window
|
2003-08-04 12:45:42 +00:00
|
|
|
menu.window = FbTk::FbWindow(screen_num,
|
|
|
|
menu.x, menu.y, menu.width, menu.height,
|
|
|
|
event_mask,
|
|
|
|
true); // override redirect
|
|
|
|
|
2003-07-02 05:26:45 +00:00
|
|
|
// strip focus change mask from attrib, since we should only use it with main window
|
2003-08-04 12:45:42 +00:00
|
|
|
event_mask ^= FocusChangeMask;
|
2002-12-25 11:46:50 +00:00
|
|
|
|
|
|
|
FbTk::EventManager &evm = *FbTk::EventManager::instance();
|
|
|
|
evm.add(*this, menu.window);
|
|
|
|
|
2003-08-04 12:45:42 +00:00
|
|
|
|
|
|
|
event_mask |= EnterWindowMask | LeaveWindowMask;
|
2002-12-25 11:46:50 +00:00
|
|
|
//create menu title
|
2003-08-04 12:45:42 +00:00
|
|
|
menu.title = FbTk::FbWindow(menu.window,
|
|
|
|
0, 0, menu.width, menu.height,
|
|
|
|
event_mask);
|
|
|
|
|
2002-12-25 11:46:50 +00:00
|
|
|
evm.add(*this, menu.title);
|
|
|
|
|
2003-08-04 12:45:42 +00:00
|
|
|
event_mask |= PointerMotionMask;
|
|
|
|
menu.frame = FbTk::FbWindow(menu.window,
|
|
|
|
0, menu.title_h,
|
|
|
|
menu.width, menu.frame_h,
|
|
|
|
event_mask);
|
2002-12-25 11:46:50 +00:00
|
|
|
evm.add(*this, menu.frame);
|
2003-01-13 03:04:47 +00:00
|
|
|
// update style
|
|
|
|
reconfigure();
|
2002-12-25 11:46:50 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
Menu::~Menu() {
|
|
|
|
menu.window.hide();
|
|
|
|
|
2003-02-03 13:41:19 +00:00
|
|
|
if (shown && shown->window() == window())
|
2003-04-26 12:34:48 +00:00
|
|
|
shown = 0;
|
2002-12-25 11:46:50 +00:00
|
|
|
|
2003-05-24 12:34:16 +00:00
|
|
|
removeAll();
|
2002-12-25 11:46:50 +00:00
|
|
|
|
|
|
|
if (menu.title_pixmap)
|
|
|
|
m_image_ctrl.removeImage(menu.title_pixmap);
|
|
|
|
|
|
|
|
if (menu.frame_pixmap)
|
|
|
|
m_image_ctrl.removeImage(menu.frame_pixmap);
|
|
|
|
|
|
|
|
if (menu.hilite_pixmap)
|
|
|
|
m_image_ctrl.removeImage(menu.hilite_pixmap);
|
|
|
|
|
|
|
|
if (menu.sel_pixmap)
|
|
|
|
m_image_ctrl.removeImage(menu.sel_pixmap);
|
|
|
|
|
|
|
|
FbTk::EventManager &evm = *FbTk::EventManager::instance();
|
|
|
|
evm.remove(menu.title);
|
|
|
|
evm.remove(menu.frame);
|
|
|
|
evm.remove(menu.window);
|
2003-07-02 05:26:45 +00:00
|
|
|
if (s_focused == this)
|
|
|
|
s_focused = 0;
|
2002-12-25 11:46:50 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
int Menu::insert(const char *label, RefCount<Command> &cmd, int pos) {
|
2003-01-12 17:01:02 +00:00
|
|
|
return insert(new MenuItem(label, cmd), pos);
|
2002-12-25 11:46:50 +00:00
|
|
|
}
|
2003-01-12 17:01:02 +00:00
|
|
|
|
2003-01-09 16:45:21 +00:00
|
|
|
int Menu::insert(const char *label, int pos) {
|
2003-01-12 17:01:02 +00:00
|
|
|
return insert(new MenuItem(label), pos);
|
2002-12-25 11:46:50 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
int Menu::insert(const char *label, Menu *submenu, int pos) {
|
2003-01-12 17:01:02 +00:00
|
|
|
submenu->m_parent = this;
|
|
|
|
return insert(new MenuItem(label, submenu), pos);
|
|
|
|
}
|
|
|
|
|
|
|
|
int Menu::insert(MenuItem *item, int pos) {
|
2002-12-25 11:46:50 +00:00
|
|
|
if (pos == -1) {
|
|
|
|
menuitems.push_back(item);
|
|
|
|
} else {
|
|
|
|
menuitems.insert(menuitems.begin() + pos, item);
|
2003-02-16 15:03:22 +00:00
|
|
|
}
|
2003-04-25 12:32:57 +00:00
|
|
|
m_need_update = true; // we need to redraw the menu
|
2003-02-16 15:03:22 +00:00
|
|
|
return menuitems.size();
|
2002-12-25 11:46:50 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
int Menu::remove(unsigned int index) {
|
|
|
|
if (index >= menuitems.size()) {
|
|
|
|
#ifdef DEBUG
|
|
|
|
std::cout << "Bad index (" << index << ") given to Menu::remove()"
|
|
|
|
<< " -- should be between 0 and " << menuitems.size()
|
|
|
|
<< " inclusive." << std::endl;
|
|
|
|
#endif // DEBUG
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
Menuitems::iterator it = menuitems.begin() + index;
|
|
|
|
MenuItem *item = (*it);
|
|
|
|
|
|
|
|
if (item) {
|
|
|
|
menuitems.erase(it);
|
2003-04-26 14:47:04 +00:00
|
|
|
if ((! internal_menu) && (item->submenu())) {
|
|
|
|
Menu *tmp = item->submenu();
|
|
|
|
// if menu is interal we should just hide it instead
|
|
|
|
// if destroying it
|
|
|
|
if (! tmp->internal_menu) {
|
2003-08-18 11:49:50 +00:00
|
|
|
delete tmp;
|
2003-04-26 14:47:04 +00:00
|
|
|
} else
|
|
|
|
tmp->internal_hide();
|
|
|
|
}
|
|
|
|
|
2002-12-25 11:46:50 +00:00
|
|
|
|
|
|
|
delete item;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (static_cast<unsigned int>(which_sub) == index)
|
|
|
|
which_sub = -1;
|
|
|
|
else if (static_cast<unsigned int>(which_sub) > index)
|
|
|
|
which_sub--;
|
2003-04-25 12:32:57 +00:00
|
|
|
m_need_update = true; // we need to redraw the menu
|
2002-12-25 11:46:50 +00:00
|
|
|
return menuitems.size();
|
|
|
|
}
|
|
|
|
|
2003-01-07 02:10:24 +00:00
|
|
|
void Menu::removeAll() {
|
|
|
|
while (!menuitems.empty()) {
|
2003-05-24 05:49:31 +00:00
|
|
|
remove(0);
|
2003-01-07 02:10:24 +00:00
|
|
|
}
|
2003-04-25 12:32:57 +00:00
|
|
|
m_need_update = true;
|
2003-01-07 02:10:24 +00:00
|
|
|
}
|
|
|
|
|
2002-12-25 11:46:50 +00:00
|
|
|
void Menu::raise() {
|
|
|
|
menu.window.raise();
|
|
|
|
}
|
|
|
|
|
|
|
|
void Menu::lower() {
|
|
|
|
menu.window.lower();
|
|
|
|
}
|
|
|
|
|
2003-07-02 05:26:45 +00:00
|
|
|
void Menu::nextItem() {
|
|
|
|
if (which_press == menuitems.size() - 1)
|
|
|
|
return;
|
|
|
|
|
|
|
|
int old_which_press = which_press;
|
|
|
|
|
|
|
|
if (old_which_press >= 0 &&
|
|
|
|
old_which_press < menuitems.size() &&
|
|
|
|
menuitems[old_which_press] != 0) {
|
|
|
|
if (menuitems[old_which_press]->submenu()) {
|
|
|
|
// we need to do this explicitly on the menu.window
|
|
|
|
// since it might hide the parent if we use Menu::hide
|
|
|
|
menuitems[old_which_press]->submenu()->menu.window.hide();
|
|
|
|
}
|
|
|
|
drawItem(old_which_press, false, true, true);
|
|
|
|
}
|
|
|
|
|
|
|
|
// restore old in case we changed which_press
|
|
|
|
which_press = old_which_press;
|
|
|
|
if (which_press < 0 || which_press >= menuitems.size())
|
|
|
|
which_press = 0;
|
|
|
|
else if (which_press < menuitems.size() - 1)
|
|
|
|
which_press++;
|
|
|
|
|
|
|
|
|
|
|
|
if (menuitems[which_press] == 0)
|
|
|
|
return;
|
|
|
|
|
|
|
|
if (menuitems[which_press]->submenu())
|
|
|
|
drawSubmenu(which_press);
|
|
|
|
else
|
|
|
|
drawItem(which_press, true, true, true);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
void Menu::prevItem() {
|
|
|
|
|
|
|
|
int old_which_press = which_press;
|
|
|
|
|
|
|
|
if (old_which_press >= 0 && old_which_press < menuitems.size()) {
|
|
|
|
if (menuitems[old_which_press]->submenu()) {
|
|
|
|
// we need to do this explicitly on the menu.window
|
|
|
|
// since it might hide the parent if we use Menu::hide
|
|
|
|
menuitems[old_which_press]->submenu()->menu.window.hide();
|
|
|
|
}
|
|
|
|
drawItem(old_which_press, false, true, true);
|
|
|
|
}
|
|
|
|
// restore old in case we changed which_press
|
|
|
|
which_press = old_which_press;
|
|
|
|
|
|
|
|
if (which_press < 0 || which_press >= menuitems.size())
|
|
|
|
which_press = 0;
|
|
|
|
else if (which_press - 1 >= 0)
|
|
|
|
which_press--;
|
|
|
|
|
|
|
|
if (menuitems[which_press] != 0) {
|
|
|
|
if (menuitems[which_press]->submenu())
|
|
|
|
drawSubmenu(which_press);
|
|
|
|
else
|
|
|
|
drawItem(which_press, true, true, true);
|
|
|
|
}
|
|
|
|
|
2003-07-03 12:47:22 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void Menu::enterSubmenu() {
|
|
|
|
if (which_press < 0 || which_press >= menuitems.size())
|
|
|
|
return;
|
|
|
|
|
|
|
|
Menu *submenu = menuitems[which_press]->submenu();
|
|
|
|
if (submenu == 0)
|
|
|
|
return;
|
|
|
|
|
|
|
|
submenu->grabInputFocus();
|
|
|
|
submenu->which_press = -1; // so we land on 0 after nextItem()
|
|
|
|
submenu->nextItem();
|
|
|
|
}
|
|
|
|
|
|
|
|
void Menu::enterParent() {
|
|
|
|
if (which_press < 0 || which_press >= menuitems.size() || parent() == 0)
|
|
|
|
return;
|
2003-07-02 05:26:45 +00:00
|
|
|
|
2003-07-03 12:47:22 +00:00
|
|
|
Menu *submenu = menuitems[which_press]->submenu();
|
|
|
|
if (submenu)
|
|
|
|
submenu->menu.window.hide();
|
|
|
|
|
|
|
|
drawItem(which_press, false, true, true);
|
|
|
|
which_press = -1; // dont select any in this
|
|
|
|
// return focus to parent but keep this window open
|
|
|
|
parent()->grabInputFocus();
|
2003-07-02 05:26:45 +00:00
|
|
|
}
|
|
|
|
|
2003-01-07 02:10:24 +00:00
|
|
|
void Menu::disableTitle() {
|
|
|
|
setTitleVisibility(false);
|
|
|
|
}
|
|
|
|
|
|
|
|
void Menu::enableTitle() {
|
|
|
|
setTitleVisibility(true);
|
|
|
|
}
|
|
|
|
|
2003-07-20 10:41:56 +00:00
|
|
|
void Menu::update(int active_index) {
|
2003-04-25 12:32:57 +00:00
|
|
|
|
2003-01-24 12:19:15 +00:00
|
|
|
if (menu.bevel_w > 10) // clamp to "normal" size
|
|
|
|
menu.bevel_w = 10;
|
|
|
|
if (m_border_width > 20)
|
|
|
|
m_border_width = 20;
|
|
|
|
|
2002-12-25 11:46:50 +00:00
|
|
|
menu.item_h = m_theme.frameFont().height() + menu.bevel_w;
|
2003-08-04 12:45:42 +00:00
|
|
|
menu.title_h = m_theme.titleFont().height() + menu.bevel_w*2;
|
2002-12-25 11:46:50 +00:00
|
|
|
|
2003-01-24 12:19:15 +00:00
|
|
|
if (title_vis) {
|
2003-08-04 12:45:42 +00:00
|
|
|
menu.item_w = m_theme.frameFont().textWidth(menu.label.c_str(), menu.label.size());
|
2002-12-25 11:46:50 +00:00
|
|
|
|
|
|
|
menu.item_w += (menu.bevel_w * 2);
|
|
|
|
} else
|
|
|
|
menu.item_w = 1;
|
|
|
|
|
|
|
|
int ii = 0;
|
|
|
|
Menuitems::iterator it = menuitems.begin();
|
|
|
|
Menuitems::iterator it_end = menuitems.end();
|
|
|
|
for (; it != it_end; ++it) {
|
|
|
|
MenuItem *itmp = (*it);
|
|
|
|
|
|
|
|
const char *s = itmp->label().c_str();
|
|
|
|
int l = itmp->label().size();
|
|
|
|
|
|
|
|
ii = m_theme.frameFont().textWidth(s, l);
|
|
|
|
|
|
|
|
|
|
|
|
ii += (menu.bevel_w * 2) + (menu.item_h * 2);
|
|
|
|
|
|
|
|
menu.item_w = ((menu.item_w < (unsigned int) ii) ? ii : menu.item_w);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (menuitems.size()) {
|
|
|
|
menu.sublevels = 1;
|
|
|
|
|
|
|
|
while (menu.item_h * (menuitems.size() + 1) / menu.sublevels +
|
2003-01-24 12:19:15 +00:00
|
|
|
menu.title_h + m_border_width > m_screen_height) {
|
2002-12-25 11:46:50 +00:00
|
|
|
menu.sublevels++;
|
2003-01-24 12:19:15 +00:00
|
|
|
}
|
2002-12-25 11:46:50 +00:00
|
|
|
|
|
|
|
if (menu.sublevels < menu.minsub)
|
|
|
|
menu.sublevels = menu.minsub;
|
|
|
|
|
|
|
|
menu.persub = menuitems.size() / menu.sublevels;
|
|
|
|
if (menuitems.size() % menu.sublevels) menu.persub++;
|
|
|
|
} else {
|
|
|
|
menu.sublevels = 0;
|
|
|
|
menu.persub = 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
menu.width = (menu.sublevels * (menu.item_w));
|
|
|
|
if (! menu.width) menu.width = menu.item_w;
|
|
|
|
|
|
|
|
menu.frame_h = (menu.item_h * menu.persub);
|
2003-11-19 12:57:27 +00:00
|
|
|
if (menu.frame_h < 0)
|
|
|
|
menu.frame_h = 0;
|
2003-08-04 12:45:42 +00:00
|
|
|
|
2003-11-19 12:57:27 +00:00
|
|
|
menu.height = menu.frame_h;
|
|
|
|
if (title_vis)
|
|
|
|
menu.height += menu.title_h + ((menu.frame_h>0)?menu.title.borderWidth():0);
|
2003-08-04 12:45:42 +00:00
|
|
|
|
|
|
|
if (menu.height < 1)
|
|
|
|
menu.height = 1;
|
2002-12-25 11:46:50 +00:00
|
|
|
|
|
|
|
Pixmap tmp;
|
|
|
|
if (title_vis) {
|
|
|
|
tmp = menu.title_pixmap;
|
|
|
|
const FbTk::Texture &tex = m_theme.titleTexture();
|
|
|
|
if (tex.type() == (FbTk::Texture::FLAT | FbTk::Texture::SOLID)) {
|
|
|
|
menu.title_pixmap = None;
|
|
|
|
menu.title.setBackgroundColor(tex.color());
|
|
|
|
} else {
|
|
|
|
menu.title_pixmap =
|
|
|
|
m_image_ctrl.renderImage(menu.width, menu.title_h, tex);
|
|
|
|
menu.title.setBackgroundPixmap(menu.title_pixmap);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (tmp)
|
|
|
|
m_image_ctrl.removeImage(tmp);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
tmp = menu.frame_pixmap;
|
|
|
|
const FbTk::Texture &frame_tex = m_theme.frameTexture();
|
|
|
|
if (frame_tex.type() == (FbTk::Texture::FLAT | FbTk::Texture::SOLID)) {
|
|
|
|
menu.frame_pixmap = None;
|
|
|
|
} else {
|
|
|
|
menu.frame_pixmap =
|
2003-04-26 12:34:48 +00:00
|
|
|
m_image_ctrl.renderImage(menu.width, menu.frame_h, frame_tex);
|
2002-12-25 11:46:50 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if (tmp)
|
|
|
|
m_image_ctrl.removeImage(tmp);
|
|
|
|
|
|
|
|
tmp = menu.hilite_pixmap;
|
|
|
|
const FbTk::Texture &hilite_tex = m_theme.hiliteTexture();
|
|
|
|
if (hilite_tex.type() == (FbTk::Texture::FLAT | FbTk::Texture::SOLID))
|
|
|
|
menu.hilite_pixmap = None;
|
|
|
|
else
|
|
|
|
menu.hilite_pixmap =
|
|
|
|
m_image_ctrl.renderImage(menu.item_w, menu.item_h, hilite_tex);
|
|
|
|
if (tmp)
|
|
|
|
m_image_ctrl.removeImage(tmp);
|
|
|
|
|
|
|
|
tmp = menu.sel_pixmap;
|
|
|
|
if (hilite_tex.type() == (FbTk::Texture::FLAT | FbTk::Texture::SOLID))
|
|
|
|
menu.sel_pixmap = None;
|
|
|
|
else {
|
|
|
|
int hw = menu.item_h / 2;
|
|
|
|
menu.sel_pixmap =
|
|
|
|
m_image_ctrl.renderImage(hw, hw, hilite_tex);
|
|
|
|
}
|
|
|
|
if (tmp)
|
|
|
|
m_image_ctrl.removeImage(tmp);
|
|
|
|
|
|
|
|
menu.window.resize(menu.width, menu.height);
|
|
|
|
|
2003-01-24 12:19:15 +00:00
|
|
|
if (title_vis) {
|
|
|
|
menu.title.moveResize(-menu.title.borderWidth(), -menu.title.borderWidth(),
|
|
|
|
menu.width + menu.title.borderWidth(), menu.title_h);
|
|
|
|
}
|
2002-12-25 11:46:50 +00:00
|
|
|
|
2003-04-20 13:49:26 +00:00
|
|
|
menu.frame.moveResize(0, ((title_vis) ? menu.title.y() + menu.title.height() +
|
|
|
|
menu.title.borderWidth()*2 : 0),
|
2003-01-24 12:19:15 +00:00
|
|
|
menu.window.width(), menu.frame_h);
|
2003-04-25 12:32:57 +00:00
|
|
|
|
|
|
|
// render pixmaps
|
|
|
|
Display *disp = FbTk::App::instance()->display();
|
|
|
|
|
|
|
|
XWindowAttributes attr;
|
|
|
|
|
|
|
|
if (m_need_update && (m_frame_pm.width() != menu.frame.width() ||
|
|
|
|
m_frame_pm.height() != menu.frame.height() )){
|
|
|
|
XGetWindowAttributes(disp, menu.frame.window(), &attr);
|
|
|
|
m_frame_pm = FbTk::FbPixmap(menu.frame.window(),
|
|
|
|
menu.frame.width(), menu.frame.height(),
|
|
|
|
attr.depth);
|
|
|
|
|
2003-05-04 10:34:09 +00:00
|
|
|
if (m_frame_pm.drawable() == 0) {
|
|
|
|
cerr<<"FbTk::Menu: Warning: Failed to create pixmap ("<<
|
|
|
|
menu.frame.window()<<", "<<menu.frame.width()<<", "<<
|
|
|
|
menu.frame.height()<<
|
|
|
|
", "<<attr.depth<<") !"<<endl;
|
|
|
|
}
|
2003-04-25 12:32:57 +00:00
|
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
menu.frame.setBackgroundPixmap(m_frame_pm.drawable());
|
|
|
|
|
2003-02-23 01:00:02 +00:00
|
|
|
clearWindow();
|
2002-12-25 11:46:50 +00:00
|
|
|
|
|
|
|
if (title_vis && visible)
|
|
|
|
redrawTitle();
|
2003-09-07 14:57:49 +00:00
|
|
|
|
|
|
|
if (active_index >= 0) {
|
2003-04-25 12:32:57 +00:00
|
|
|
for (unsigned int i = 0; visible && i < menuitems.size(); i++) {
|
|
|
|
if (i == (unsigned int)which_sub) {
|
2003-07-20 10:41:56 +00:00
|
|
|
drawItem(i, true, true, false);
|
2003-04-25 12:32:57 +00:00
|
|
|
} else
|
2003-07-21 02:45:27 +00:00
|
|
|
drawItem(i, (i == active_index && isItemEnabled(i)), true, false);
|
2003-04-25 12:32:57 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if (m_parent && visible)
|
|
|
|
m_parent->drawSubmenu(m_parent->which_sub);
|
2002-12-25 11:46:50 +00:00
|
|
|
}
|
2003-09-07 14:57:49 +00:00
|
|
|
|
2003-08-30 01:03:48 +00:00
|
|
|
menu.window.clear();
|
2003-04-25 16:23:59 +00:00
|
|
|
renderTransFrame();
|
2003-04-25 12:32:57 +00:00
|
|
|
|
|
|
|
m_need_update = false;
|
2002-12-25 11:46:50 +00:00
|
|
|
menu.window.showSubwindows();
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void Menu::show() {
|
2003-07-20 08:12:36 +00:00
|
|
|
if (m_need_update)
|
|
|
|
update();
|
2002-12-25 11:46:50 +00:00
|
|
|
menu.window.showSubwindows();
|
|
|
|
menu.window.show();
|
2003-05-17 10:44:32 +00:00
|
|
|
//!! TODO, this should probably be done explicit if one don't want to raise
|
|
|
|
raise();
|
2002-12-25 11:46:50 +00:00
|
|
|
visible = true;
|
|
|
|
|
2003-11-19 12:57:27 +00:00
|
|
|
if (! m_parent && shown != this) {
|
2002-12-25 11:46:50 +00:00
|
|
|
if (shown && (! shown->torn))
|
|
|
|
shown->hide();
|
|
|
|
|
|
|
|
shown = this;
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void Menu::hide() {
|
|
|
|
if ((! torn) && hide_tree && m_parent && m_parent->isVisible()) {
|
|
|
|
Menu *p = m_parent;
|
|
|
|
|
|
|
|
while (p->isVisible() && (! p->torn) && p->m_parent)
|
|
|
|
p = p->m_parent;
|
|
|
|
p->internal_hide();
|
|
|
|
} else
|
|
|
|
internal_hide();
|
2003-07-02 05:26:45 +00:00
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
void Menu::grabInputFocus() {
|
|
|
|
s_focused = this;
|
|
|
|
|
|
|
|
// grab input focus
|
|
|
|
menu.window.setInputFocus(RevertToPointerRoot, CurrentTime);
|
|
|
|
|
2002-12-25 11:46:50 +00:00
|
|
|
}
|
|
|
|
|
2003-07-02 05:26:45 +00:00
|
|
|
|
2003-02-23 01:00:02 +00:00
|
|
|
void Menu::clearWindow() {
|
|
|
|
menu.window.clear();
|
|
|
|
menu.title.clear();
|
|
|
|
menu.frame.clear();
|
|
|
|
}
|
2002-12-25 11:46:50 +00:00
|
|
|
|
|
|
|
void Menu::internal_hide() {
|
|
|
|
if (which_sub >= 0) {
|
|
|
|
MenuItem *tmp = menuitems[which_sub];
|
|
|
|
tmp->submenu()->internal_hide();
|
|
|
|
}
|
|
|
|
|
|
|
|
if (m_parent && (! torn)) {
|
2003-04-20 13:49:26 +00:00
|
|
|
m_parent->drawItem(m_parent->which_sub, false, true);
|
2002-12-25 11:46:50 +00:00
|
|
|
|
|
|
|
m_parent->which_sub = -1;
|
|
|
|
} else if (shown && shown->menu.window == menu.window)
|
|
|
|
shown = (Menu *) 0;
|
|
|
|
|
|
|
|
torn = visible = false;
|
|
|
|
which_sub = which_press = which_sub = -1;
|
|
|
|
|
|
|
|
menu.window.hide();
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void Menu::move(int x, int y) {
|
2003-04-25 12:32:57 +00:00
|
|
|
|
2002-12-25 11:46:50 +00:00
|
|
|
menu.x = x;
|
|
|
|
menu.y = y;
|
|
|
|
menu.window.move(x, y);
|
|
|
|
|
|
|
|
if (which_sub != -1)
|
|
|
|
drawSubmenu(which_sub);
|
2003-04-25 12:32:57 +00:00
|
|
|
|
2003-05-01 14:33:36 +00:00
|
|
|
if (!(m_parent && m_parent->moving) && !torn) {
|
|
|
|
redrawTitle();
|
2003-04-25 16:23:59 +00:00
|
|
|
renderTransFrame();
|
2003-05-01 14:33:36 +00:00
|
|
|
}
|
2002-12-25 11:46:50 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void Menu::redrawTitle() {
|
|
|
|
const char *text = menu.label.c_str();
|
|
|
|
|
|
|
|
const FbTk::Font &font = m_theme.titleFont();
|
|
|
|
int dx = menu.bevel_w, len = menu.label.size();
|
|
|
|
unsigned int l = font.textWidth(text, len) + menu.bevel_w*2;
|
|
|
|
|
|
|
|
switch (m_theme.titleFontJustify()) {
|
|
|
|
case FbTk::RIGHT:
|
|
|
|
dx += menu.width - l;
|
|
|
|
break;
|
|
|
|
|
|
|
|
case FbTk::CENTER:
|
|
|
|
dx += (menu.width - l) / 2;
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
2003-05-01 14:33:36 +00:00
|
|
|
menu.title.clear();
|
2003-08-04 12:45:42 +00:00
|
|
|
font.drawText(menu.title.window(), // drawable
|
2002-12-25 11:46:50 +00:00
|
|
|
screenNumber(),
|
|
|
|
m_theme.titleTextGC(), // graphic context
|
|
|
|
text, len, // text string with lenght
|
|
|
|
dx, font.ascent() + menu.bevel_w); // position
|
2003-04-20 13:49:26 +00:00
|
|
|
|
2003-08-04 12:45:42 +00:00
|
|
|
menu.title.updateTransparent();
|
|
|
|
|
2002-12-25 11:46:50 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void Menu::drawSubmenu(unsigned int index) {
|
|
|
|
if (which_sub >= 0 && static_cast<unsigned int>(which_sub) != index &&
|
|
|
|
static_cast<unsigned int>(which_sub) < menuitems.size()) {
|
|
|
|
MenuItem *itmp = menuitems[which_sub];
|
|
|
|
|
|
|
|
if (! itmp->submenu()->isTorn())
|
|
|
|
itmp->submenu()->internal_hide();
|
|
|
|
}
|
|
|
|
|
2003-04-25 12:32:57 +00:00
|
|
|
if (index >= menuitems.size())
|
|
|
|
return;
|
|
|
|
|
|
|
|
MenuItem *item = menuitems[index];
|
|
|
|
if (item->submenu() && visible && (! item->submenu()->isTorn()) &&
|
|
|
|
item->isEnabled()) {
|
2002-12-25 11:46:50 +00:00
|
|
|
|
2003-04-25 12:32:57 +00:00
|
|
|
if (item->submenu()->m_parent != this)
|
|
|
|
item->submenu()->m_parent = this;
|
2002-12-25 11:46:50 +00:00
|
|
|
|
2003-04-25 12:32:57 +00:00
|
|
|
int sbl = index / menu.persub, i = index - (sbl * menu.persub),
|
|
|
|
x = menu.x +
|
|
|
|
((menu.item_w * (sbl + 1)) + menu.window.borderWidth()), y;
|
2002-12-25 11:46:50 +00:00
|
|
|
|
2003-04-25 12:32:57 +00:00
|
|
|
if (m_alignment == ALIGNTOP) {
|
|
|
|
y = (((shifted) ? menu.y_shift : menu.y) +
|
|
|
|
((title_vis) ? menu.title_h + menu.title.borderWidth() : 0) -
|
|
|
|
((item->submenu()->title_vis) ?
|
|
|
|
item->submenu()->menu.title_h + menu.window.borderWidth() : 0));
|
|
|
|
} else {
|
|
|
|
y = (((shifted) ? menu.y_shift : menu.y) +
|
|
|
|
(menu.item_h * i) +
|
|
|
|
((title_vis) ? menu.title_h + menu.window.borderWidth() : 0) -
|
|
|
|
((item->submenu()->title_vis) ?
|
|
|
|
item->submenu()->menu.title_h + menu.window.borderWidth() : 0));
|
|
|
|
}
|
2002-12-25 11:46:50 +00:00
|
|
|
|
2003-04-25 12:32:57 +00:00
|
|
|
if (m_alignment == ALIGNBOTTOM &&
|
|
|
|
(y + item->submenu()->menu.height) > ((shifted) ? menu.y_shift :
|
|
|
|
menu.y) + menu.height) {
|
|
|
|
y = (((shifted) ? menu.y_shift : menu.y) +
|
|
|
|
menu.height - item->submenu()->menu.height);
|
|
|
|
}
|
2002-12-25 11:46:50 +00:00
|
|
|
|
2003-04-25 12:32:57 +00:00
|
|
|
if ((x + item->submenu()->width()) > m_screen_width) {
|
|
|
|
x = ((shifted) ? menu.x_shift : menu.x) -
|
|
|
|
item->submenu()->width() - menu.window.borderWidth();
|
|
|
|
}
|
2002-12-25 11:46:50 +00:00
|
|
|
|
2003-04-25 12:32:57 +00:00
|
|
|
if (x < 0)
|
|
|
|
x = 0;
|
2002-12-25 11:46:50 +00:00
|
|
|
|
2003-04-25 12:32:57 +00:00
|
|
|
if ((y + item->submenu()->height()) > m_screen_height) {
|
|
|
|
y = m_screen_height - item->submenu()->height() -
|
|
|
|
menu.window.borderWidth() * 2;
|
|
|
|
}
|
2002-12-25 11:46:50 +00:00
|
|
|
|
2003-04-25 12:32:57 +00:00
|
|
|
if (y < 0)
|
|
|
|
y = 0;
|
2002-12-25 11:46:50 +00:00
|
|
|
|
2003-04-25 12:32:57 +00:00
|
|
|
item->submenu()->move(x, y);
|
|
|
|
if (! moving)
|
|
|
|
drawItem(index, true);
|
2002-12-25 11:46:50 +00:00
|
|
|
|
2003-04-25 12:32:57 +00:00
|
|
|
if (! item->submenu()->isVisible()) {
|
|
|
|
item->submenu()->show();
|
|
|
|
item->submenu()->raise();
|
|
|
|
}
|
2002-12-25 11:46:50 +00:00
|
|
|
|
2003-04-25 12:32:57 +00:00
|
|
|
item->submenu()->moving = moving;
|
|
|
|
which_sub = index;
|
|
|
|
} else
|
|
|
|
which_sub = -1;
|
|
|
|
|
2002-12-25 11:46:50 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
bool Menu::hasSubmenu(unsigned int index) const {
|
|
|
|
if (index >= menuitems.size()) //boundary check
|
|
|
|
return false;
|
|
|
|
|
|
|
|
if (!menuitems[index]->submenu()) //has submenu?
|
|
|
|
return false;
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2003-04-20 13:49:26 +00:00
|
|
|
void Menu::drawItem(unsigned int index, bool highlight, bool clear, bool render_trans,
|
2003-05-04 10:34:09 +00:00
|
|
|
int x, int y, unsigned int w, unsigned int h) {
|
2003-01-12 17:01:02 +00:00
|
|
|
if (index >= menuitems.size() || menuitems.size() == 0 ||
|
|
|
|
menu.persub == 0)
|
2002-12-25 11:46:50 +00:00
|
|
|
return;
|
|
|
|
|
|
|
|
MenuItem *item = menuitems[index];
|
|
|
|
if (! item) return;
|
2003-01-12 17:01:02 +00:00
|
|
|
|
2002-12-25 11:46:50 +00:00
|
|
|
bool dotext = true, dohilite = true, dosel = true;
|
|
|
|
const char *text = item->label().c_str();
|
2003-01-12 17:01:02 +00:00
|
|
|
int sbl = index / menu.persub, i = index - (sbl * menu.persub);
|
2002-12-25 11:46:50 +00:00
|
|
|
int item_x = (sbl * menu.item_w), item_y = (i * menu.item_h);
|
|
|
|
int hilite_x = item_x, hilite_y = item_y, hoff_x = 0, hoff_y = 0;
|
|
|
|
int text_x = 0, text_y = 0, len = strlen(text), sel_x = 0, sel_y = 0;
|
|
|
|
unsigned int hilite_w = menu.item_w, hilite_h = menu.item_h, text_w = 0, text_h = 0;
|
|
|
|
unsigned int half_w = menu.item_h / 2, quarter_w = menu.item_h / 4;
|
|
|
|
const FbTk::Font &font = m_theme.frameFont();
|
|
|
|
if (text) {
|
|
|
|
text_w = font.textWidth(text, len);
|
|
|
|
|
|
|
|
text_y = item_y + menu.bevel_w/2 + font.ascent();
|
|
|
|
|
|
|
|
switch(m_theme.frameFontJustify()) {
|
|
|
|
case FbTk::LEFT:
|
|
|
|
text_x = item_x + menu.bevel_w + menu.item_h + 1;
|
|
|
|
break;
|
|
|
|
|
|
|
|
case FbTk::RIGHT:
|
|
|
|
text_x = item_x + menu.item_w - (menu.item_h + menu.bevel_w + text_w);
|
|
|
|
break;
|
|
|
|
default: //center
|
|
|
|
text_x = item_x + ((menu.item_w + 1 - text_w) / 2);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
text_h = menu.item_h - menu.bevel_w;
|
|
|
|
}
|
|
|
|
|
|
|
|
GC gc =
|
|
|
|
((highlight || item->isSelected()) ? m_theme.hiliteTextGC() :
|
|
|
|
m_theme.frameTextGC());
|
|
|
|
GC tgc =
|
|
|
|
(highlight ? m_theme.hiliteTextGC() :
|
2003-04-25 12:32:57 +00:00
|
|
|
(item->isEnabled() ? m_theme.frameTextGC() : m_theme.disableTextGC() ) );
|
2002-12-25 11:46:50 +00:00
|
|
|
|
|
|
|
sel_x = item_x;
|
|
|
|
|
|
|
|
if (m_theme.bulletPos() == FbTk::RIGHT)
|
|
|
|
sel_x += (menu.item_w - menu.item_h - menu.bevel_w);
|
|
|
|
|
|
|
|
sel_x += quarter_w;
|
|
|
|
sel_y = item_y + quarter_w;
|
2003-01-12 17:01:02 +00:00
|
|
|
|
2002-12-25 11:46:50 +00:00
|
|
|
if (clear) {
|
2003-08-27 14:14:04 +00:00
|
|
|
FbTk::GContext def_gc(menu.frame.window());
|
2003-04-25 12:32:57 +00:00
|
|
|
if (menu.frame_pixmap == 0) {
|
2003-08-27 14:14:04 +00:00
|
|
|
def_gc.setForeground(m_theme.frameTexture().color());
|
|
|
|
m_frame_pm.fillRectangle(def_gc.gc(), item_x, item_y, menu.item_w, menu.item_h);
|
2003-08-18 11:49:50 +00:00
|
|
|
|
2003-04-25 12:32:57 +00:00
|
|
|
} else {
|
|
|
|
|
2003-08-27 14:14:04 +00:00
|
|
|
m_frame_pm.copyArea(menu.frame_pixmap, def_gc.gc(),
|
2003-04-25 12:32:57 +00:00
|
|
|
item_x, item_y,
|
2003-04-28 01:32:47 +00:00
|
|
|
item_x, item_y,
|
|
|
|
menu.item_w, menu.item_h);
|
2003-04-25 12:32:57 +00:00
|
|
|
}
|
2002-12-25 11:46:50 +00:00
|
|
|
} else if (! (x == y && y == -1 && w == h && h == 0)) {
|
|
|
|
// calculate the which part of the hilite to redraw
|
|
|
|
if (! (std::max(item_x, x) <= (signed) std::min(item_x + menu.item_w, x + w) &&
|
|
|
|
std::max(item_y, y) <= (signed) std::min(item_y + menu.item_h, y + h))) {
|
|
|
|
dohilite = False;
|
|
|
|
} else {
|
|
|
|
hilite_x = std::max(item_x, x);
|
|
|
|
hilite_y = std::max(item_y, y);
|
|
|
|
hilite_w = std::min(item_x + menu.item_w, x + w) - hilite_x;
|
|
|
|
hilite_h = std::min(item_y + menu.item_h, y + h) - hilite_y;
|
|
|
|
hoff_x = hilite_x % menu.item_w;
|
|
|
|
hoff_y = hilite_y % menu.item_h;
|
|
|
|
}
|
|
|
|
|
|
|
|
// check if we need to redraw the text
|
|
|
|
int text_ry = item_y + (menu.bevel_w / 2);
|
|
|
|
if (! (std::max(text_x, x) <= (signed) std::min(text_x + text_w, x + w) &&
|
|
|
|
std::max(text_ry, y) <= (signed) std::min(text_ry + text_h, y + h)))
|
2003-04-25 12:32:57 +00:00
|
|
|
dotext = false;
|
2002-12-25 11:46:50 +00:00
|
|
|
|
|
|
|
// check if we need to redraw the select pixmap/menu bullet
|
|
|
|
if (! (std::max(sel_x, x) <= (signed) std::min(sel_x + half_w, x + w) &&
|
|
|
|
std::max(sel_y, y) <= (signed) std::min(sel_y + half_w, y + h)))
|
2003-04-25 12:32:57 +00:00
|
|
|
dosel = false;
|
2002-12-25 11:46:50 +00:00
|
|
|
|
|
|
|
}
|
2003-08-27 14:14:04 +00:00
|
|
|
|
2002-12-25 11:46:50 +00:00
|
|
|
if (dohilite && highlight && (menu.hilite_pixmap != ParentRelative)) {
|
|
|
|
if (menu.hilite_pixmap) {
|
2003-04-25 12:32:57 +00:00
|
|
|
m_frame_pm.copyArea(menu.hilite_pixmap,
|
|
|
|
m_theme.hiliteGC(), hoff_x, hoff_y,
|
2003-04-28 01:32:47 +00:00
|
|
|
hilite_x, hilite_y,
|
|
|
|
hilite_w, hilite_h);
|
2003-04-25 12:32:57 +00:00
|
|
|
} else {
|
|
|
|
m_frame_pm.fillRectangle(m_theme.hiliteGC(),
|
|
|
|
hilite_x, hilite_y, hilite_w, hilite_h);
|
2002-12-25 11:46:50 +00:00
|
|
|
}
|
2003-04-25 12:32:57 +00:00
|
|
|
|
2002-12-25 11:46:50 +00:00
|
|
|
}
|
|
|
|
|
2003-08-27 14:14:04 +00:00
|
|
|
|
|
|
|
if (item->isToggleItem() && item->isSelected() &&
|
|
|
|
menu.sel_pixmap != ParentRelative) {
|
|
|
|
if (m_theme.selectedPixmap().pixmap().drawable()) {
|
|
|
|
// enable clip mask
|
|
|
|
XSetClipMask(FbTk::App::instance()->display(),
|
|
|
|
gc,
|
|
|
|
m_theme.selectedPixmap().mask().drawable());
|
|
|
|
XSetClipOrigin(FbTk::App::instance()->display(),
|
|
|
|
gc, sel_x, item_y);
|
|
|
|
// copy bullet pixmap to frame
|
|
|
|
m_frame_pm.copyArea(m_theme.selectedPixmap().pixmap().drawable(),
|
|
|
|
gc,
|
|
|
|
0, 0,
|
|
|
|
sel_x, item_y,
|
|
|
|
m_theme.selectedPixmap().width(),
|
|
|
|
m_theme.selectedPixmap().height());
|
|
|
|
// disable clip mask
|
|
|
|
XSetClipMask(FbTk::App::instance()->display(),
|
|
|
|
gc,
|
|
|
|
None);
|
2002-12-25 11:46:50 +00:00
|
|
|
} else {
|
2003-08-27 14:14:04 +00:00
|
|
|
if (menu.sel_pixmap) {
|
|
|
|
m_frame_pm.copyArea(highlight ? menu.frame_pixmap : menu.sel_pixmap,
|
|
|
|
m_theme.hiliteGC(),
|
|
|
|
0, 0,
|
|
|
|
sel_x, sel_y,
|
|
|
|
half_w, half_w);
|
|
|
|
} else {
|
|
|
|
m_frame_pm.fillRectangle(m_theme.hiliteGC(),
|
|
|
|
sel_x, sel_y, half_w, half_w);
|
|
|
|
}
|
2002-12-25 11:46:50 +00:00
|
|
|
}
|
2003-04-25 12:32:57 +00:00
|
|
|
|
2003-08-27 14:14:04 +00:00
|
|
|
} else if (item->isToggleItem() && m_theme.unselectedPixmap().pixmap().drawable() != 0) {
|
|
|
|
// enable clip mask
|
|
|
|
XSetClipMask(FbTk::App::instance()->display(),
|
|
|
|
gc,
|
|
|
|
m_theme.unselectedPixmap().mask().drawable());
|
|
|
|
XSetClipOrigin(FbTk::App::instance()->display(),
|
|
|
|
gc, sel_x, item_y);
|
|
|
|
// copy bullet pixmap to frame
|
|
|
|
m_frame_pm.copyArea(m_theme.unselectedPixmap().pixmap().drawable(),
|
|
|
|
gc,
|
|
|
|
0, 0,
|
|
|
|
sel_x, item_y,
|
|
|
|
m_theme.unselectedPixmap().width(),
|
|
|
|
m_theme.unselectedPixmap().height());
|
|
|
|
// disable clip mask
|
|
|
|
XSetClipMask(FbTk::App::instance()->display(),
|
|
|
|
gc,
|
|
|
|
None);
|
2002-12-25 11:46:50 +00:00
|
|
|
}
|
2003-08-27 14:14:04 +00:00
|
|
|
|
2002-12-25 11:46:50 +00:00
|
|
|
if (dotext && text) {
|
2003-04-25 12:32:57 +00:00
|
|
|
m_theme.frameFont().drawText(m_frame_pm.drawable(), // drawable
|
2002-12-25 11:46:50 +00:00
|
|
|
screenNumber(),
|
|
|
|
tgc,
|
|
|
|
text, len, // text string and lenght
|
|
|
|
text_x, text_y); // position
|
|
|
|
}
|
|
|
|
|
|
|
|
if (dosel && item->submenu()) {
|
2003-08-27 14:14:04 +00:00
|
|
|
if (m_theme.bulletPixmap().pixmap().drawable() != 0) {
|
|
|
|
// enable clip mask
|
|
|
|
XSetClipMask(FbTk::App::instance()->display(),
|
|
|
|
gc,
|
|
|
|
m_theme.bulletPixmap().mask().drawable());
|
|
|
|
XSetClipOrigin(FbTk::App::instance()->display(),
|
|
|
|
gc, sel_x, item_y);
|
|
|
|
// copy bullet pixmap to frame
|
|
|
|
m_frame_pm.copyArea(m_theme.bulletPixmap().pixmap().drawable(),
|
|
|
|
gc,
|
|
|
|
0, 0,
|
|
|
|
sel_x, item_y,
|
|
|
|
m_theme.bulletPixmap().width(),
|
|
|
|
m_theme.bulletPixmap().height());
|
|
|
|
// disable clip mask
|
|
|
|
XSetClipMask(FbTk::App::instance()->display(),
|
|
|
|
gc,
|
|
|
|
None);
|
|
|
|
} else {
|
|
|
|
switch (m_theme.bullet()) {
|
|
|
|
case MenuTheme::SQUARE:
|
|
|
|
m_frame_pm.drawRectangle(gc, sel_x, sel_y, half_w, half_w);
|
|
|
|
break;
|
|
|
|
|
|
|
|
case MenuTheme::TRIANGLE:
|
|
|
|
XPoint tri[3];
|
|
|
|
|
|
|
|
if (m_theme.bulletPos() == FbTk::RIGHT) {
|
|
|
|
tri[0].x = sel_x + quarter_w - 2;
|
|
|
|
tri[0].y = sel_y + quarter_w - 2;
|
|
|
|
tri[1].x = 4;
|
|
|
|
tri[1].y = 2;
|
|
|
|
tri[2].x = -4;
|
|
|
|
tri[2].y = 2;
|
|
|
|
} else {
|
|
|
|
tri[0].x = sel_x + quarter_w - 2;
|
|
|
|
tri[0].y = item_y + half_w;
|
|
|
|
tri[1].x = 4;
|
|
|
|
tri[1].y = 2;
|
|
|
|
tri[2].x = 0;
|
|
|
|
tri[2].y = -4;
|
|
|
|
}
|
2002-12-25 11:46:50 +00:00
|
|
|
|
2003-08-27 14:14:04 +00:00
|
|
|
m_frame_pm.fillPolygon(gc, tri, 3, Convex,
|
|
|
|
CoordModePrevious);
|
|
|
|
break;
|
2002-12-25 11:46:50 +00:00
|
|
|
|
2003-08-27 14:14:04 +00:00
|
|
|
case MenuTheme::DIAMOND:
|
|
|
|
XPoint dia[4];
|
|
|
|
|
|
|
|
dia[0].x = sel_x + quarter_w - 3;
|
|
|
|
dia[0].y = item_y + half_w;
|
|
|
|
dia[1].x = 3;
|
|
|
|
dia[1].y = -3;
|
|
|
|
dia[2].x = 3;
|
|
|
|
dia[2].y = 3;
|
|
|
|
dia[3].x = -3;
|
|
|
|
dia[3].y = 3;
|
|
|
|
|
|
|
|
m_frame_pm.fillPolygon(gc, dia, 4, Convex,
|
|
|
|
CoordModePrevious);
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
2002-12-25 11:46:50 +00:00
|
|
|
}
|
|
|
|
}
|
2003-04-20 13:49:26 +00:00
|
|
|
|
2003-08-30 01:03:48 +00:00
|
|
|
menu.frame.clearArea(item_x, item_y,
|
|
|
|
menu.item_w, menu.item_h, False);
|
2003-08-04 12:45:42 +00:00
|
|
|
|
2003-08-30 01:03:48 +00:00
|
|
|
|
2003-08-04 12:45:42 +00:00
|
|
|
menu.frame.updateTransparent(item_x, item_y,
|
|
|
|
menu.item_w, menu.item_h);
|
2003-08-30 01:03:48 +00:00
|
|
|
|
2002-12-25 11:46:50 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void Menu::setLabel(const char *labelstr) {
|
|
|
|
//make sure we don't send 0 to std::string
|
|
|
|
menu.label = (labelstr ? labelstr : "");
|
|
|
|
reconfigure();
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void Menu::setItemSelected(unsigned int index, bool sel) {
|
|
|
|
if (index >= menuitems.size()) return;
|
|
|
|
|
|
|
|
MenuItem *item = find(index);
|
|
|
|
if (! item) return;
|
|
|
|
|
|
|
|
item->setSelected(sel);
|
2003-08-30 01:03:48 +00:00
|
|
|
|
2002-12-25 11:46:50 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
bool Menu::isItemSelected(unsigned int index) const{
|
|
|
|
if (index >= menuitems.size()) return false;
|
|
|
|
|
|
|
|
const MenuItem *item = find(index);
|
|
|
|
if (!item)
|
|
|
|
return false;
|
|
|
|
|
|
|
|
return item->isSelected();
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void Menu::setItemEnabled(unsigned int index, bool enable) {
|
|
|
|
if (index >= menuitems.size()) return;
|
|
|
|
|
|
|
|
MenuItem *item = find(index);
|
|
|
|
if (! item) return;
|
|
|
|
|
|
|
|
item->setEnabled(enable);
|
2003-08-30 01:03:48 +00:00
|
|
|
|
2002-12-25 11:46:50 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
bool Menu::isItemEnabled(unsigned int index) const {
|
|
|
|
if (index >= menuitems.size()) return false;
|
|
|
|
|
2003-05-13 00:24:26 +00:00
|
|
|
const MenuItem *item = find(index);
|
2002-12-25 11:46:50 +00:00
|
|
|
if (!item)
|
|
|
|
return false;
|
|
|
|
|
|
|
|
return item->isEnabled();
|
|
|
|
}
|
|
|
|
|
2003-07-02 05:26:45 +00:00
|
|
|
void Menu::handleEvent(XEvent &event) {
|
|
|
|
if (event.type == FocusOut) {
|
|
|
|
if (s_focused == this)
|
|
|
|
s_focused = 0;
|
|
|
|
} else if (event.type == FocusIn) {
|
|
|
|
if (s_focused != this)
|
|
|
|
s_focused = this;
|
|
|
|
}
|
|
|
|
}
|
2002-12-25 11:46:50 +00:00
|
|
|
|
|
|
|
void Menu::buttonPressEvent(XButtonEvent &be) {
|
2003-08-18 11:49:50 +00:00
|
|
|
if (be.window == menu.title)
|
|
|
|
grabInputFocus();
|
|
|
|
|
2003-04-25 16:23:59 +00:00
|
|
|
if (be.window == menu.frame && menu.item_h != 0 && menu.item_w != 0) {
|
2003-07-02 05:26:45 +00:00
|
|
|
|
2002-12-25 11:46:50 +00:00
|
|
|
int sbl = (be.x / menu.item_w), i = (be.y / menu.item_h);
|
|
|
|
int w = (sbl * menu.persub) + i;
|
|
|
|
|
|
|
|
if (w < static_cast<int>(menuitems.size()) && w >= 0) {
|
|
|
|
which_press = i;
|
|
|
|
which_sbl = sbl;
|
|
|
|
|
|
|
|
MenuItem *item = menuitems[w];
|
|
|
|
|
2003-09-07 14:57:49 +00:00
|
|
|
if (item->submenu()) {
|
|
|
|
if (!item->submenu()->isVisible())
|
|
|
|
drawSubmenu(w);
|
|
|
|
} else
|
2003-05-04 10:34:09 +00:00
|
|
|
drawItem(w, item->isEnabled(), true, true);
|
2002-12-25 11:46:50 +00:00
|
|
|
}
|
|
|
|
} else {
|
|
|
|
menu.x_move = be.x_root - menu.x;
|
|
|
|
menu.y_move = be.y_root - menu.y;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void Menu::buttonReleaseEvent(XButtonEvent &re) {
|
|
|
|
if (re.window == menu.title) {
|
|
|
|
if (moving) {
|
|
|
|
moving = false;
|
|
|
|
|
|
|
|
if (which_sub >= 0)
|
|
|
|
drawSubmenu(which_sub);
|
2003-04-20 13:49:26 +00:00
|
|
|
update();
|
2002-12-25 11:46:50 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if (re.x >= 0 && re.x <= (signed) menu.width &&
|
|
|
|
re.y >= 0 && re.y <= (signed) menu.title_h &&
|
|
|
|
re.button == 3)
|
|
|
|
hide();
|
|
|
|
|
|
|
|
} else if (re.window == menu.frame &&
|
|
|
|
re.x >= 0 && re.x < (signed) menu.width &&
|
|
|
|
re.y >= 0 && re.y < (signed) menu.frame_h) {
|
|
|
|
|
2003-01-12 17:01:02 +00:00
|
|
|
int sbl = (re.x / menu.item_w), i = (re.y / menu.item_h),
|
|
|
|
ix = sbl * menu.item_w, iy = i * menu.item_h,
|
|
|
|
w = (sbl * menu.persub) + i,
|
|
|
|
p = (which_sbl * menu.persub) + which_press;
|
|
|
|
|
|
|
|
if (w < static_cast<int>(menuitems.size()) && w >= 0) {
|
|
|
|
if (p == w && isItemEnabled(w)) {
|
|
|
|
if (re.x > ix && re.x < (signed) (ix + menu.item_w) &&
|
|
|
|
re.y > iy && re.y < (signed) (iy + menu.item_h)) {
|
|
|
|
menuitems[w]->click(re.button, re.time);
|
|
|
|
itemSelected(re.button, w);
|
2003-09-07 14:57:49 +00:00
|
|
|
// redraw whole menu as enableds for any item
|
|
|
|
// may have changed
|
|
|
|
update(w);
|
2002-12-25 11:46:50 +00:00
|
|
|
}
|
2003-07-20 10:41:56 +00:00
|
|
|
} else {
|
|
|
|
drawItem(p, isItemEnabled(p) && (p == which_sub), true, true);
|
2003-01-12 17:01:02 +00:00
|
|
|
}
|
|
|
|
} else
|
2003-04-20 13:49:26 +00:00
|
|
|
drawItem(p, false, true, true);
|
2002-12-25 11:46:50 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void Menu::motionNotifyEvent(XMotionEvent &me) {
|
|
|
|
if (me.window == menu.title && (me.state & Button1Mask)) {
|
|
|
|
if (movable) {
|
|
|
|
if (! moving) {
|
|
|
|
if (m_parent && (! torn)) {
|
2003-04-20 13:49:26 +00:00
|
|
|
m_parent->drawItem(m_parent->which_sub, false, true, true);
|
2002-12-25 11:46:50 +00:00
|
|
|
m_parent->which_sub = -1;
|
|
|
|
}
|
|
|
|
|
2003-04-25 16:23:59 +00:00
|
|
|
moving = torn = true;
|
2002-12-25 11:46:50 +00:00
|
|
|
|
|
|
|
if (which_sub >= 0)
|
|
|
|
drawSubmenu(which_sub);
|
|
|
|
} else {
|
|
|
|
menu.x = me.x_root - menu.x_move,
|
|
|
|
menu.y = me.y_root - menu.y_move;
|
|
|
|
|
|
|
|
menu.window.move(menu.x, menu.y);
|
|
|
|
|
2003-08-30 01:03:48 +00:00
|
|
|
// if (which_sub >= 0)
|
|
|
|
// drawSubmenu(which_sub);
|
2002-12-25 11:46:50 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
} else if ((! (me.state & Button1Mask)) && me.window == menu.frame &&
|
|
|
|
me.x >= 0 && me.x < (signed) menu.width &&
|
|
|
|
me.y >= 0 && me.y < (signed) menu.frame_h) {
|
|
|
|
int sbl = (me.x / menu.item_w), i = (me.y / menu.item_h),
|
|
|
|
w = (sbl * menu.persub) + i;
|
|
|
|
|
|
|
|
if ((i != which_press || sbl != which_sbl) &&
|
|
|
|
(w < static_cast<int>(menuitems.size()) && w >= 0)) {
|
|
|
|
if (which_press != -1 && which_sbl != -1) {
|
2003-07-02 05:26:45 +00:00
|
|
|
int p = which_sbl * menu.persub + which_press;
|
2002-12-25 11:46:50 +00:00
|
|
|
MenuItem *item = menuitems[p];
|
|
|
|
|
2003-07-20 10:41:56 +00:00
|
|
|
// don't redraw disabled items on enter/leave
|
|
|
|
if (item->isEnabled()) {
|
|
|
|
drawItem(p, false, true, true);
|
|
|
|
if (item->submenu()) {
|
|
|
|
if (item->submenu()->isVisible() &&
|
|
|
|
(! item->submenu()->isTorn())) {
|
|
|
|
item->submenu()->internal_hide();
|
|
|
|
which_sub = -1;
|
|
|
|
}
|
2002-12-25 11:46:50 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
which_press = i;
|
|
|
|
which_sbl = sbl;
|
|
|
|
|
|
|
|
MenuItem *itmp = menuitems[w];
|
|
|
|
|
2003-09-07 14:57:49 +00:00
|
|
|
if (itmp->submenu()) {
|
|
|
|
if (!itmp->submenu()->isVisible())
|
|
|
|
drawSubmenu(w);
|
|
|
|
} else
|
2003-07-20 10:41:56 +00:00
|
|
|
if (itmp->isEnabled())
|
|
|
|
drawItem(w, true, true, true);
|
2002-12-25 11:46:50 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void Menu::exposeEvent(XExposeEvent &ee) {
|
|
|
|
if (ee.window == menu.title) {
|
|
|
|
redrawTitle();
|
|
|
|
} else if (ee.window == menu.frame) {
|
|
|
|
// this is a compilicated algorithm... lets do it step by step...
|
|
|
|
// first... we see in which sub level the expose starts... and how many
|
|
|
|
// items down in that sublevel
|
2003-02-15 01:48:16 +00:00
|
|
|
if (menu.item_w == 0)
|
|
|
|
menu.item_w = 1;
|
|
|
|
if (menu.item_h == 0)
|
|
|
|
menu.item_h = 1;
|
2003-01-12 17:01:02 +00:00
|
|
|
unsigned int sbl = (ee.x / menu.item_w), id = (ee.y / menu.item_h),
|
2002-12-25 11:46:50 +00:00
|
|
|
// next... figure out how many sublevels over the redraw spans
|
|
|
|
sbl_d = ((ee.x + ee.width) / menu.item_w),
|
|
|
|
// then we see how many items down to redraw
|
|
|
|
id_d = ((ee.y + ee.height) / menu.item_h);
|
|
|
|
if (id_d > menu.persub) id_d = menu.persub;
|
|
|
|
|
|
|
|
// draw the sublevels and the number of items the exposure spans
|
2003-01-12 17:01:02 +00:00
|
|
|
unsigned int i, ii;
|
2002-12-25 11:46:50 +00:00
|
|
|
for (i = sbl; i <= sbl_d; i++) {
|
|
|
|
// set the iterator to the first item in the sublevel needing redrawing
|
2003-01-12 17:01:02 +00:00
|
|
|
unsigned int index = id + i * menu.persub;
|
2002-12-25 11:46:50 +00:00
|
|
|
if (index < static_cast<int>(menuitems.size()) && index >= 0) {
|
|
|
|
Menuitems::iterator it = menuitems.begin() + index;
|
|
|
|
Menuitems::iterator it_end = menuitems.end();
|
|
|
|
for (ii = id; ii <= id_d && it != it_end; ++it, ii++) {
|
2003-01-12 17:01:02 +00:00
|
|
|
unsigned int index = ii + (i * menu.persub);
|
2003-04-20 13:49:26 +00:00
|
|
|
drawItem(index, (which_sub == index), true, true,
|
2002-12-25 11:46:50 +00:00
|
|
|
ee.x, ee.y, ee.width, ee.height);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void Menu::enterNotifyEvent(XCrossingEvent &ce) {
|
|
|
|
|
|
|
|
if (menu.frame != ce.window)
|
|
|
|
return;
|
|
|
|
|
|
|
|
menu.x_shift = menu.x, menu.y_shift = menu.y;
|
|
|
|
if (menu.x + menu.width > m_screen_width) {
|
2003-10-06 09:55:36 +00:00
|
|
|
menu.x_shift = m_screen_width - menu.width - 2*m_border_width;
|
2002-12-25 11:46:50 +00:00
|
|
|
shifted = true;
|
|
|
|
} else if (menu.x < 0) {
|
2003-10-06 09:55:36 +00:00
|
|
|
menu.x_shift = 0; //-m_border_width;
|
2002-12-25 11:46:50 +00:00
|
|
|
shifted = true;
|
|
|
|
}
|
|
|
|
|
2003-10-06 09:55:36 +00:00
|
|
|
if (menu.y + menu.height + 2*m_border_width > m_screen_height) {
|
|
|
|
menu.y_shift = m_screen_height - menu.height - 2*m_border_width;
|
2002-12-25 11:46:50 +00:00
|
|
|
shifted = true;
|
|
|
|
} else if (menu.y + (signed) menu.title_h < 0) {
|
2003-10-06 09:55:36 +00:00
|
|
|
menu.y_shift = 0; // -m_border_width;;
|
2002-12-25 11:46:50 +00:00
|
|
|
shifted = true;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
if (shifted)
|
|
|
|
menu.window.move(menu.x_shift, menu.y_shift);
|
|
|
|
|
|
|
|
if (which_sub >= 0 && static_cast<size_t>(which_sub) < menuitems.size()) {
|
|
|
|
MenuItem *tmp = menuitems[which_sub];
|
|
|
|
if (tmp->submenu()->isVisible()) {
|
|
|
|
int sbl = (ce.x / menu.item_w), i = (ce.y / menu.item_h),
|
|
|
|
w = (sbl * menu.persub) + i;
|
|
|
|
|
|
|
|
if (w != which_sub && (! tmp->submenu()->isTorn())) {
|
|
|
|
tmp->submenu()->internal_hide();
|
|
|
|
|
2003-04-20 13:49:26 +00:00
|
|
|
drawItem(which_sub, false, true, true);
|
2002-12-25 11:46:50 +00:00
|
|
|
which_sub = -1;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void Menu::leaveNotifyEvent(XCrossingEvent &ce) {
|
|
|
|
if (menu.frame != ce.window)
|
|
|
|
return;
|
|
|
|
|
|
|
|
if (which_press != -1 && which_sbl != -1 && menuitems.size() > 0) {
|
|
|
|
int p = (which_sbl * menu.persub) + which_press;
|
|
|
|
|
2003-04-20 13:49:26 +00:00
|
|
|
drawItem(p, (p == which_sub), true, true);
|
2002-12-25 11:46:50 +00:00
|
|
|
|
|
|
|
which_sbl = which_press = -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (shifted) {
|
|
|
|
menu.window.move(menu.x, menu.y);
|
|
|
|
shifted = false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2003-07-02 05:26:45 +00:00
|
|
|
void Menu::keyPressEvent(XKeyEvent &event) {
|
|
|
|
KeySym ks;
|
|
|
|
char keychar[1];
|
|
|
|
XLookupString(&event, keychar, 1, &ks, 0);
|
|
|
|
// a modifier key by itself doesn't do anything
|
|
|
|
if (IsModifierKey(ks))
|
|
|
|
return;
|
|
|
|
if (event.state) // dont handle modifier with normal key
|
|
|
|
return;
|
|
|
|
|
|
|
|
switch (ks) {
|
|
|
|
case XK_Up:
|
|
|
|
prevItem();
|
|
|
|
break;
|
|
|
|
case XK_Down:
|
|
|
|
nextItem();
|
|
|
|
break;
|
2003-07-03 12:47:22 +00:00
|
|
|
case XK_Left: // enter parent if we have one
|
|
|
|
enterParent();
|
2003-07-02 05:26:45 +00:00
|
|
|
break;
|
2003-07-03 12:47:22 +00:00
|
|
|
case XK_Right: // enter submenu if we have one
|
|
|
|
enterSubmenu();
|
2003-07-02 05:26:45 +00:00
|
|
|
break;
|
2003-07-03 12:23:28 +00:00
|
|
|
case XK_Escape: // close menu
|
2003-07-02 05:26:45 +00:00
|
|
|
hide();
|
|
|
|
break;
|
|
|
|
case XK_Return:
|
2003-07-03 12:23:28 +00:00
|
|
|
// send fake button 1 click
|
2003-07-02 05:26:45 +00:00
|
|
|
if (which_press >= 0 && which_press < menuitems.size()) {
|
|
|
|
menuitems[which_press]->click(1, event.time);
|
|
|
|
itemSelected(1, which_press);
|
2003-07-20 10:41:56 +00:00
|
|
|
m_need_update = true;
|
2003-07-02 05:26:45 +00:00
|
|
|
update();
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
2002-12-25 11:46:50 +00:00
|
|
|
|
|
|
|
void Menu::reconfigure() {
|
2003-04-25 12:32:57 +00:00
|
|
|
m_need_update = true; // redraw items
|
|
|
|
|
2003-01-24 12:19:15 +00:00
|
|
|
menu.bevel_w = m_theme.bevelWidth();
|
|
|
|
m_border_width = m_theme.borderWidth();
|
2003-04-25 12:32:57 +00:00
|
|
|
|
2003-01-24 12:19:15 +00:00
|
|
|
if (menu.bevel_w > 10) // clamp to "normal" size
|
|
|
|
menu.bevel_w = 10;
|
|
|
|
if (menu.bevel_w < 0)
|
|
|
|
menu.bevel_w = 1;
|
2003-04-25 12:32:57 +00:00
|
|
|
|
2003-01-24 12:19:15 +00:00
|
|
|
if (m_border_width > 20) // clamp to normal size
|
|
|
|
m_border_width = 20;
|
|
|
|
if (m_border_width < 0)
|
|
|
|
m_border_width = 0;
|
|
|
|
|
2003-01-09 16:45:21 +00:00
|
|
|
menu.window.setBackgroundColor(m_theme.borderColor());
|
2003-04-25 12:32:57 +00:00
|
|
|
menu.title.setBackgroundColor(m_theme.borderColor());
|
2003-01-24 12:19:15 +00:00
|
|
|
|
2003-01-09 16:45:21 +00:00
|
|
|
menu.window.setBorderColor(m_theme.borderColor());
|
2003-01-24 12:19:15 +00:00
|
|
|
menu.title.setBorderColor(m_theme.borderColor());
|
|
|
|
menu.frame.setBorderColor(m_theme.borderColor());
|
|
|
|
|
|
|
|
menu.window.setBorderWidth(m_border_width);
|
|
|
|
menu.title.setBorderWidth(m_border_width);
|
2003-08-04 12:45:42 +00:00
|
|
|
|
|
|
|
menu.frame.setAlpha(alpha());
|
|
|
|
menu.title.setAlpha(alpha());
|
|
|
|
menu.window.setAlpha(alpha());
|
2003-08-30 01:03:48 +00:00
|
|
|
|
2002-12-25 11:46:50 +00:00
|
|
|
update();
|
|
|
|
}
|
2003-05-01 14:33:36 +00:00
|
|
|
|
2003-04-25 16:23:59 +00:00
|
|
|
void Menu::renderTransFrame() {
|
2003-08-24 16:57:38 +00:00
|
|
|
menu.frame.clear();
|
2003-08-04 12:45:42 +00:00
|
|
|
menu.frame.updateTransparent();
|
2003-04-25 16:23:59 +00:00
|
|
|
}
|
|
|
|
|
2002-12-25 11:46:50 +00:00
|
|
|
}; // end namespace FbTk
|