VIZ++ Class: OpenGLMenuBar

 VIZ++ Class Library  VIZ++ Samples  VIZ++ ClassTree 

Source code

/*
 * OpenGLMenuBar.h 
 * Copyright (c) 2015 Antillia.com TOSHIYUKI ARAI. ALL RIGHTS RESERVED. 
 */



#pragma once

#include <viz++/opengl/OpenGLMenu.h>
#include <viz++/ListEntryT.h>

#include <viz++/LinkedListT.h>
#include <viz++/Item.h>
#include <viz++/opengl/MenuItem.h>

namespace VIZ {

class OpenGLMenuBar :public OpenGLMenu {

public:
  OpenGLMenuBar()
  :OpenGLMenu()
  {
  }

public:
  //2012/06/23
  OpenGLMenuBar(OpenGLIView* view, const TCHAR* name)
  :OpenGLMenu()
  {
    create(view, name);
  }


public:
  //2012/06/23
  Boolean create(OpenGLIView* view, const TCHAR* name)
  {
    Boolean rc = True;
    OpenGLMenu::setOwner(view);

    HWND   hwnd    = view -> getHwnd();
    HINSTANCE progIns = (HINSTANCE)::GetWindowLongPtr(hwnd, GWLP_HINSTANCE);
    HMENU  hmenu   = ::LoadMenu(progIns, name);
    if(hmenu == NULL) {
      hmenu = ::CreateMenu();
    }
    set(hmenu);
    ::SetMenu(hwnd, hmenu);
    ::DrawMenuBar(hwnd);
    return rc;
  }

public:
  void tearOff(int n)
  {
    HMENU hpopup = ::GetSubMenu(get(), n);
    if(hpopup) {
      POINT p;
      ::GetCursorPos(&p);
      OpenGLIView* owner = getOwner();
      int  h = ::GetSystemMetrics(SM_CYMENU);
      ::TrackPopupMenu(hpopup, 0, p.x-h, p.y-h/2, 0,
             owner->getHwnd(), NULL);
    }
  }

public:
  void append(const TCHAR* head, LinkedListT<Item>* list)
  {
    OpenGLIView* owner  = getOwner();
    HMENU hmenu  = get();
    HMENU hpopup= ::CreateMenu();
    ::AppendMenu(hmenu, MF_STRING | MF_POPUP, (UINT_PTR)hpopup, head);

    if(list) {
      ListEntryT<Item>* p = list -> getEntry();
      while(p) {
        Item* item = (Item *)(p->getObject());
        if(strcmp(item->getText(), _T("SEPARATOR")) == 0) {
          ::AppendMenu(hpopup, MF_SEPARATOR, 0, 0L);
        }
        else {
          ::AppendMenu(hpopup, MF_STRING, 
             item->getId(), item->getText());
        }
        p = p->getNext();
      }
    }
    ::DrawMenuBar(owner ->getHwnd());
  }

public:
  void addPopupMenu(HMENU hpopup, LinkedListT<Item>* list)
  {
    if(list) {
      ListEntryT<Item>* p = list -> getEntry();
      while(p) {
        Item* item = (Item *)(p->getObject());
        if(strcmp(item->getText(), _T("SEPARATOR")) == 0) {
          ::AppendMenu(hpopup, MF_SEPARATOR, 0, 0L);
        }
        else {
          ::AppendMenu(hpopup, MF_STRING, 
             item->getId(), item->getText());
        }
        p = p->getNext();
      }
    }
  }

public:
  void changePopupMenu(int n, TCHAR* menuItems[])
  {
    HMENU hmenu  = get();
    HMENU hpopup = ::GetSubMenu(hmenu, n);

    int count = ::GetMenuItemCount(hpopup);
    // For BC by Yamada of SOFT BANK.
    int i = 0;
    for(i = 0; i<count; i++) {
      ::DeleteMenu(hpopup, 0, MF_BYPOSITION);
    }
    for(i = 0; menuItems[i] != NULL; i++) {
      if(strcmp(menuItems[i], _T("SEPARATOR")) == 0) {
        ::AppendMenu(hpopup, MF_SEPARATOR,0, 0L);
      }
      else {
        ::AppendMenu(hpopup, MF_STRING,i, menuItems[i]);
      }
    }
  }

public:
  HMENU getPopupHandle(int n)
  {
    return ::GetSubMenu((HMENU)get(), n);
  }

public:
  void update(int n, const TCHAR* head, LinkedListT<Item>* items, HMENU hpopup) 
  {
    HMENU hmenu = get();
    OpenGLIView* owner = getOwner();

    ::ChangeMenu(hmenu,n, head, (UINT_PTR)hpopup,
      MF_POPUP|MF_CHANGE|MF_BYPOSITION);
    int count = ::GetMenuItemCount(hpopup);
    for(int i = 0; i<count; i++) {
      ::DeleteMenu(hpopup, 0, MF_BYPOSITION);
    }
    ListEntryT<Item>* p = items -> getEntry();
    while(p) {
      Item* item = (Item *)(p->getObject());
      if(strcmp(item->getText(), _T("SEPARATOR")) == 0) {
        ::AppendMenu(hpopup, MF_SEPARATOR, 0, 0L);
      }
      else {
        ::AppendMenu(hpopup, MF_STRING, item->getId(), 
             (TCHAR*)item->getText());
      }
      p = p -> getNext();
    }
    ::DrawMenuBar(owner->getHwnd());
  }

public:
  void append(const TCHAR* name, const MenuItem* items, int count)
  {
    OpenGLIView* owner = getOwner();
    HMENU hPopup = CreatePopupMenu();

    HMENU hMenu  = get();

    AppendMenu(hMenu, MF_ENABLED | MF_POPUP , (UINT)hPopup, name);
    for (int i = 0; i<count; i++) {
      AppendMenu(hPopup, 
        items[i].flags,  //MF_ENABLED | MF_STRING ,
        items[i].id, 
        items[i].name);
    }
    ::DrawMenuBar(owner ->getHwnd());
  }

};

}



Last modified: 10 Feb 2017

Copyright (c) 2009-2017 Antillia.com ALL RIGHTS RESERVED.