Qt 4.8
Classes | Macros | Typedefs | Functions | Variables
qmenu_wince.cpp File Reference
#include "qmenu.h"
#include "qt_windows.h"
#include "qapplication.h"
#include "qmainwindow.h"
#include "qtoolbar.h"
#include "qevent.h"
#include "qstyle.h"
#include "qdebug.h"
#include "qwidgetaction.h"
#include <private/qapplication_p.h>
#include <private/qmenu_p.h>
#include <private/qmenubar_p.h>
#include "qmenu_wince_resource_p.h"
#include <QtCore/qlibrary.h>
#include <commctrl.h>
#include "qguifunctions_wince.h"

Go to the source code of this file.

Classes

struct  qt_SHMENUBARINFO
 

Macros

#define SHCMBF_EMPTYBAR   0x0001
 
#define SHCMBM_GETSUBMENU   (WM_USER + 401)
 

Typedefs

typedef BOOL(WINAPI * AygCreateMenuBar) (qt_SHMENUBARINFO *)
 
typedef HRESULT(WINAPI * AygEnableSoftKey) (HWND, UINT, BOOL, BOOL)
 

Functions

static void qt_wce_change_command (HWND menuHandle, int item, int command)
 
static void qt_wce_clear_menu (HMENU hMenu)
 
static HWND qt_wce_create_menubar (HWND parentHandle, HINSTANCE resourceHandle, int toolbarID, int flags=0)
 
static void qt_wce_delete_action_list (QList< QWceMenuAction *> *list)
 
static void qt_wce_disable_soft_key (HWND handle, uint command)
 
static void qt_wce_enable_soft_key (HWND handle, uint command)
 
static HMODULE qt_wce_get_module_handle ()
 
static QActionqt_wce_get_quit_action (QList< QAction *> actionItems)
 
static QActionqt_wce_get_quit_action (QList< QWceMenuAction *> actionItems)
 
static void qt_wce_insert_action (HMENU menu, QWceMenuAction *action)
 
static void qt_wce_rename_menu_item (HWND menuHandle, int item, const QString &newText)
 
bool qt_wince_is_pocket_pc ()
 
bool qt_wince_is_smartphone ()
 
static void resolveAygLibs ()
 

Variables

static bool aygResolved = false
 
static QList< QMenuBar * > nativeMenuBars
 
static AygCreateMenuBar ptrCreateMenuBar = 0
 
static AygEnableSoftKey ptrEnableSoftKey = 0
 
static uint qt_wce_menu_static_cmd_id = 200
 

Macro Definition Documentation

◆ SHCMBF_EMPTYBAR

#define SHCMBF_EMPTYBAR   0x0001

Definition at line 70 of file qmenu_wince.cpp.

Referenced by QMenuBarPrivate::wceCreateMenuBar().

◆ SHCMBM_GETSUBMENU

#define SHCMBM_GETSUBMENU   (WM_USER + 401)

Definition at line 74 of file qmenu_wince.cpp.

Referenced by QMenuBarPrivate::QWceMenuBarPrivate::rebuild().

Typedef Documentation

◆ AygCreateMenuBar

typedef BOOL(WINAPI * AygCreateMenuBar) (qt_SHMENUBARINFO *)

Definition at line 104 of file qmenu_wince.cpp.

◆ AygEnableSoftKey

typedef HRESULT(WINAPI * AygEnableSoftKey) (HWND, UINT, BOOL, BOOL)

Definition at line 105 of file qmenu_wince.cpp.

Function Documentation

◆ qt_wce_change_command()

static void qt_wce_change_command ( HWND  menuHandle,
int  item,
int  command 
)
static

Definition at line 186 of file qmenu_wince.cpp.

Referenced by QMenuBarPrivate::QWceMenuBarPrivate::rebuild().

187 {
188 TBBUTTONINFOA tbbi;
189  memset(&tbbi,0,sizeof(tbbi));
190  tbbi.cbSize = sizeof(tbbi);
191  tbbi.dwMask = TBIF_COMMAND;
192  tbbi.idCommand = command;
193  SendMessage(menuHandle, TB_SETBUTTONINFO, item, (LPARAM)&tbbi);
194 }

◆ qt_wce_clear_menu()

static void qt_wce_clear_menu ( HMENU  hMenu)
static

Definition at line 263 of file qmenu_wince.cpp.

Referenced by QMenuBarPrivate::QWceMenuBarPrivate::rebuild(), and QMenuPrivate::QWceMenuPrivate::rebuild().

264 {
265  while (RemoveMenu(hMenu, 0, MF_BYPOSITION));
266 }

◆ qt_wce_create_menubar()

static HWND qt_wce_create_menubar ( HWND  parentHandle,
HINSTANCE  resourceHandle,
int  toolbarID,
int  flags = 0 
)
static

Definition at line 208 of file qmenu_wince.cpp.

Referenced by QMenuBarPrivate::QWceMenuBarPrivate::rebuild(), and QMenuBarPrivate::wceCreateMenuBar().

209 {
210  resolveAygLibs();
211 
212  if (ptrCreateMenuBar) {
213  qt_SHMENUBARINFO mbi;
214  memset(&mbi, 0, sizeof(qt_SHMENUBARINFO));
215  mbi.cbSize = sizeof(qt_SHMENUBARINFO);
216  mbi.hwndParent = parentHandle;
217  mbi.hInstRes = resourceHandle;
218  mbi.dwFlags = flags;
219  mbi.nToolBarId = toolbarID;
220 
221  if (ptrCreateMenuBar(&mbi)) {
222 #ifdef Q_OS_WINCE_WM
223  // Tell the menu bar that we want to override hot key behaviour.
224  LPARAM lparam = MAKELPARAM(SHMBOF_NODEFAULT | SHMBOF_NOTIFY,
225  SHMBOF_NODEFAULT | SHMBOF_NOTIFY);
226  SendMessage(mbi.hwndMB, SHCMBM_OVERRIDEKEY, VK_TBACK, lparam);
227 #endif
228  return mbi.hwndMB;
229  }
230  }
231  return 0;
232 }
static void resolveAygLibs()
static AygCreateMenuBar ptrCreateMenuBar
HINSTANCE hInstRes
Definition: qmenu_wince.cpp:97

◆ qt_wce_delete_action_list()

static void qt_wce_delete_action_list ( QList< QWceMenuAction *> *  list)
static

Definition at line 135 of file qmenu_wince.cpp.

Referenced by QMenuBarPrivate::QWceMenuBarPrivate::rebuild(), QMenuBarPrivate::QWceMenuBarPrivate::~QWceMenuBarPrivate(), and QMenuPrivate::QWceMenuPrivate::~QWceMenuPrivate().

136 {
137  for(QList<QWceMenuAction*>::Iterator it = list->begin(); it != list->end(); ++it) {
138  QWceMenuAction *action = (*it);
139  delete action;
140  action = 0;
141  }
142  list->clear();
143 }
#define it(className, varName)
iterator begin()
Returns an STL-style iterator pointing to the first item in the list.
Definition: qlist.h:267
iterator end()
Returns an STL-style iterator pointing to the imaginary item after the last item in the list...
Definition: qlist.h:270
void clear()
Removes all items from the list.
Definition: qlist.h:764
The QList::iterator class provides an STL-style non-const iterator for QList and QQueue.
Definition: qlist.h:181

◆ qt_wce_disable_soft_key()

static void qt_wce_disable_soft_key ( HWND  handle,
uint  command 
)
static

Definition at line 128 of file qmenu_wince.cpp.

Referenced by QMenuBarPrivate::QWceMenuBarPrivate::rebuild().

129 {
130  resolveAygLibs();
131  if (ptrEnableSoftKey)
132  ptrEnableSoftKey(handle, command, false, false);
133 }
static AygEnableSoftKey ptrEnableSoftKey
static void resolveAygLibs()

◆ qt_wce_enable_soft_key()

static void qt_wce_enable_soft_key ( HWND  handle,
uint  command 
)
static

Definition at line 121 of file qmenu_wince.cpp.

Referenced by QMenuBarPrivate::QWceMenuBarPrivate::rebuild().

122 {
123  resolveAygLibs();
124  if (ptrEnableSoftKey)
125  ptrEnableSoftKey(handle, command, false, true);
126 }
static AygEnableSoftKey ptrEnableSoftKey
static void resolveAygLibs()

◆ qt_wce_get_module_handle()

static HMODULE qt_wce_get_module_handle ( )
static

Definition at line 176 of file qmenu_wince.cpp.

Referenced by QMenuBarPrivate::QWceMenuBarPrivate::rebuild().

177 {
178  HMODULE module = 0; //handle to resources
179  if (!(module = GetModuleHandle(L"QtGui4"))) //release dynamic
180  if (!(module = GetModuleHandle(L"QtGuid4"))) //debug dynamic
181  module = (HINSTANCE)qWinAppInst(); //static
182  Q_ASSERT_X(module, "qt_wce_get_module_handle()", "cannot get handle to module?");
183  return module;
184 }
#define Q_ASSERT_X(cond, where, what)
Definition: qglobal.h:1837
Q_CORE_EXPORT HINSTANCE qWinAppInst()

◆ qt_wce_get_quit_action() [1/2]

static QAction* qt_wce_get_quit_action ( QList< QAction *>  actionItems)
static

Definition at line 146 of file qmenu_wince.cpp.

Referenced by qt_wce_get_quit_action(), and QMenuBarPrivate::QWceMenuBarPrivate::rebuild().

147 {
148  QAction *returnAction = 0;
149  for (int i = 0; i < actionItems.size(); ++i) {
150  QAction *action = actionItems.at(i);
151  if (action->menuRole() == QAction::QuitRole)
152  returnAction = action;
153  else
154  if (action->menu())
155  returnAction = qt_wce_get_quit_action(action->menu()->actions());
156  if (returnAction)
157  return returnAction; //return first action found
158  }
159  return 0; //nothing found;
160 }
MenuRole menuRole
the action&#39;s menu role
Definition: qaction.h:88
const T & at(int i) const
Returns the item at index position i in the list.
Definition: qlist.h:468
QMenu * menu() const
Returns the menu contained by this action.
Definition: qaction.cpp:793
int size() const
Returns the number of items in the list.
Definition: qlist.h:137
QList< QAction * > actions() const
Returns the (possibly empty) list of this widget&#39;s actions.
Definition: qwidget.cpp:3407
static QAction * qt_wce_get_quit_action(QList< QAction *> actionItems)
The QAction class provides an abstract user interface action that can be inserted into widgets...
Definition: qaction.h:64

◆ qt_wce_get_quit_action() [2/2]

static QAction* qt_wce_get_quit_action ( QList< QWceMenuAction *>  actionItems)
static

Definition at line 162 of file qmenu_wince.cpp.

163 {
164  for (int i = 0; i < actionItems.size(); ++i) {
165  if (actionItems.at(i)->action->menuRole() == QAction::QuitRole)
166  return actionItems.at(i)->action;
167  else if (actionItems.at(i)->action->menu()) {
168  QAction *returnAction = qt_wce_get_quit_action(actionItems.at(i)->action->menu()->actions());
169  if (returnAction)
170  return returnAction;
171  }
172  }
173  return 0;
174 }
const T & at(int i) const
Returns the item at index position i in the list.
Definition: qlist.h:468
int size() const
Returns the number of items in the list.
Definition: qlist.h:137
static QAction * qt_wce_get_quit_action(QList< QAction *> actionItems)
The QAction class provides an abstract user interface action that can be inserted into widgets...
Definition: qaction.h:64

◆ qt_wce_insert_action()

static void qt_wce_insert_action ( HMENU  menu,
QWceMenuAction action 
)
static

Definition at line 234 of file qmenu_wince.cpp.

Referenced by QMenuBarPrivate::QWceMenuBarPrivate::rebuild(), and QMenuPrivate::QWceMenuPrivate::rebuild().

235 {
236  Q_ASSERT_X(menu, "AppendMenu", "menu is 0");
237  if (action->action->isVisible()) {
238  int flags;
239  action->action->isEnabled() ? flags = MF_ENABLED : flags = MF_GRAYED;
240 
241  QString text = action->action->iconText();
242  text.remove(QChar::fromLatin1('&'));
243  if (action->action->isSeparator()) {
244  AppendMenu (menu, MF_SEPARATOR , 0, 0);
245  }
246  else if (action->action->menu()) {
247  text.remove(QChar::fromLatin1('&'));
248  AppendMenu (menu, MF_STRING | flags | MF_POPUP,
249  (UINT) action->action->menu()->wceMenu(), reinterpret_cast<const wchar_t *> (text.utf16()));
250  }
251  else {
252  AppendMenu (menu, MF_STRING | flags, action->command, reinterpret_cast<const wchar_t *> (text.utf16()));
253  }
254  if (action->action->isCheckable())
255  if (action->action->isChecked())
256  CheckMenuItem(menu, action->command, MF_BYCOMMAND | MF_CHECKED);
257  else
258  CheckMenuItem(menu, action->command, MF_BYCOMMAND | MF_UNCHECKED);
259  }
260 }
bool isSeparator() const
Returns true if this action is a separator action; otherwise it returns false.
Definition: qaction.cpp:839
bool isEnabled() const
Definition: qaction.cpp:1208
The QString class provides a Unicode character string.
Definition: qstring.h:83
bool isVisible() const
Definition: qaction.cpp:1246
static QChar fromLatin1(char c)
Converts the Latin-1 character c to its equivalent QChar.
Definition: qchar.h:378
#define Q_ASSERT_X(cond, where, what)
Definition: qglobal.h:1837
QMenu * menu() const
Returns the menu contained by this action.
Definition: qaction.cpp:793
QPointer< QAction > action
Definition: qmenu_p.h:129
bool isCheckable() const
Definition: qaction.cpp:1105
HMENU wceMenu()
This function will return the HMENU used to create the native Windows CE menu bar bindings...
uint command
Definition: qmenu_p.h:128
QString iconText
the action&#39;s descriptive icon text
Definition: qaction.h:77
bool isChecked() const
Definition: qaction.cpp:1151
QString & remove(int i, int len)
Removes n characters from the string, starting at the given position index, and returns a reference t...
Definition: qstring.cpp:1867
#define text
Definition: qobjectdefs.h:80
const ushort * utf16() const
Returns the QString as a &#39;\0\&#39;-terminated array of unsigned shorts.
Definition: qstring.cpp:5290

◆ qt_wce_rename_menu_item()

static void qt_wce_rename_menu_item ( HWND  menuHandle,
int  item,
const QString newText 
)
static

Definition at line 196 of file qmenu_wince.cpp.

Referenced by QMenuBarPrivate::QWceMenuBarPrivate::rebuild().

197 {
198  TBBUTTONINFOA tbbi;
199  memset(&tbbi,0,sizeof(tbbi));
200  tbbi.cbSize = sizeof(tbbi);
201  tbbi.dwMask = TBIF_TEXT;
202  QString text = newText;
203  text.remove(QChar::fromLatin1('&'));
204  tbbi.pszText = (LPSTR) text.utf16();
205  SendMessage(menuHandle, TB_SETBUTTONINFO, item, (LPARAM)&tbbi);
206 }
The QString class provides a Unicode character string.
Definition: qstring.h:83
static QChar fromLatin1(char c)
Converts the Latin-1 character c to its equivalent QChar.
Definition: qchar.h:378
QString & remove(int i, int len)
Removes n characters from the string, starting at the given position index, and returns a reference t...
Definition: qstring.cpp:1867
#define text
Definition: qobjectdefs.h:80
const ushort * utf16() const
Returns the QString as a &#39;\0\&#39;-terminated array of unsigned shorts.
Definition: qstring.cpp:5290

◆ qt_wince_is_pocket_pc()

bool qt_wince_is_pocket_pc ( )

Definition at line 289 of file qguifunctions_wince.cpp.

Referenced by qt_wince_is_high_dpi(), qt_wince_is_mobile(), and QMenuBarPrivate::wceCreateMenuBar().

289  {
290  return qt_wince_is_platform(QString::fromLatin1("PocketPC"));
291 }
bool qt_wince_is_platform(const QString &platformString)
static QString fromLatin1(const char *, int size=-1)
Returns a QString initialized with the first size characters of the Latin-1 string str...
Definition: qstring.cpp:4188

◆ qt_wince_is_smartphone()

bool qt_wince_is_smartphone ( )

Definition at line 293 of file qguifunctions_wince.cpp.

Referenced by qt_wince_is_mobile(), and QMenuBarPrivate::wceCreateMenuBar().

293  {
294  return qt_wince_is_platform(QString::fromLatin1("Smartphone"));
295 }
bool qt_wince_is_platform(const QString &platformString)
static QString fromLatin1(const char *, int size=-1)
Returns a QString initialized with the first size characters of the Latin-1 string str...
Definition: qstring.cpp:4188

◆ resolveAygLibs()

static void resolveAygLibs ( )
static

Definition at line 111 of file qmenu_wince.cpp.

Referenced by qt_wce_create_menubar(), qt_wce_disable_soft_key(), and qt_wce_enable_soft_key().

112 {
113  if (!aygResolved) {
114  QLibrary aygLib(QLatin1String("aygshell"));
115  ptrCreateMenuBar = (AygCreateMenuBar) aygLib.resolve("SHCreateMenuBar");
116  ptrEnableSoftKey = (AygEnableSoftKey) aygLib.resolve("SHEnableSoftkey");
117  aygResolved = true;
118  }
119 }
static AygEnableSoftKey ptrEnableSoftKey
QLatin1String(DBUS_INTERFACE_DBUS))) Q_GLOBAL_STATIC_WITH_ARGS(QString
static bool aygResolved
BOOL(WINAPI * AygCreateMenuBar)(qt_SHMENUBARINFO *)
static AygCreateMenuBar ptrCreateMenuBar
HRESULT(WINAPI * AygEnableSoftKey)(HWND, UINT, BOOL, BOOL)
The QLibrary class loads shared libraries at runtime.
Definition: qlibrary.h:62

Variable Documentation

◆ aygResolved

bool aygResolved = false
static

Definition at line 107 of file qmenu_wince.cpp.

Referenced by resolveAygLibs().

◆ nativeMenuBars

QList<QMenuBar*> nativeMenuBars
static

Definition at line 89 of file qmenu_wince.cpp.

◆ ptrCreateMenuBar

AygCreateMenuBar ptrCreateMenuBar = 0
static

Definition at line 108 of file qmenu_wince.cpp.

Referenced by qt_wce_create_menubar(), and resolveAygLibs().

◆ ptrEnableSoftKey

AygEnableSoftKey ptrEnableSoftKey = 0
static

◆ qt_wce_menu_static_cmd_id

uint qt_wce_menu_static_cmd_id = 200
static