Example #1
0
static int richeditreplace(HWND hwnd, char *what, char *replacewith,
			   int matchcase, int wholeword, int down)
{
    /* If current selection is the find string, replace it and find next */
    long start, end;
    CHARRANGE sel;
    char *buf;
    textbox t = find_by_handle(hwnd);
    if (t) {
	sendmessage (hwnd, EM_EXGETSEL, 0, &sel) ;
	start = sel.cpMin;
	end = sel.cpMax;
	if (start < end) {
	    buf = (char *) malloc(end - start + 1);
	    sendmessage(hwnd, EM_GETSELTEXT, 0, buf);
	    if (!strcmp(buf, what)) {
		checklimittext(t, strlen(replacewith) - strlen(what) + 2);
		sendmessage (hwnd, EM_REPLACESEL, 1, replacewith);
	    }
	    free(buf);
	}
	/* else just find next */
	if (richeditfind(hwnd, what, matchcase, wholeword, down))
	    return 1;
    }
    return 0;
}
Example #2
0
/*
 *  The adjust_menu function is called just after the program
 *  receives a WM_INITMENU message.  This message is sent even if
 *  the user is attempting to use the system menu, which is nice.
 *  We use this function to keep menubars and menus up-to-date by
 *  calling their respective action functions.
 */
PROTECTED
void adjust_menu(WPARAM wParam)
{
    object obj;
    obj = find_by_handle((HANDLE)wParam);
    if (obj) {
	activatecontrol(obj);
	if (obj->kind == MenubarObject)
	    DrawMenuBar(obj->parent->handle);
    }
}
void QHiMDWinDetection::remove_himd(HANDLE devhandle)
{
    QMDDevice * dev = find_by_handle(devhandle);
    if (!dev)
        return;

    if(dev->isOpen())
        dev->close();

    dev->setMdInserted(false);

    return;
}
void QHiMDWinDetection::add_himd(HANDLE devhandle)
{
    QMDDevice * dev = find_by_handle(devhandle);
    if (!dev)
        return;

    if(!dev->mdInserted())
        dev->setMdInserted(true);

    if(!dev->isOpen())
        dev->open();

    return;
}
Example #5
0
PROTECTED
int handle_menu_key(WPARAM wParam)
{
    object win, obj;
    win = find_by_handle(GetFocus());
    if (win) {
	if (win->kind != WindowObject)
	    win = win->parent;
	obj = find_by_key(win, wParam);
	if (obj) {
	    adjust_menus_top_down(obj);
	    if (isenabled(obj)) /* Don't do menu actions which are greyed out. CJ */
		activatecontrol(obj);
	    return 1;
	}
    }
    return 0;
}
Example #6
0
/*
 *  Activate a control's action function. We do several things here.
 *  Checking to see what kind of control it is, we handle some
 *  events and discard others. We automatically toggle the state of
 *  checkboxes and radio buttons, and handle listbox changes and
 *  allow text box update events to call the control's action.
 */
PROTECTED
void handle_control(HWND hwnd, UINT message)
{
	object obj;
	int index;

	obj = find_by_handle(hwnd);

	if ((! obj) || (! (obj->state & Enabled)))
		return;

	/* Only let certain events cause activation. */
	switch (obj->kind)
	{
	  case CheckboxObject:
		if (obj->state & Checked)
			uncheck(obj);
		else
			check(obj);
		break;

	  case RadioObject:
		if (!(obj->state & Checked)) {
			uncheck_neighbours(obj);
			check(obj);
		}
		break;

	  case ListboxObject:
		/* Ignore all but selection-change events. */
		if (message != LBN_SELCHANGE)
			return;
		index = sendmessage(hwnd, LB_GETCURSEL, 0, 0L);
		obj->value = index;
		break;

	  case MultilistObject:
		/* Ignore all but selection-change events. */
		if (message != LBN_SELCHANGE)
			return;
		index = sendmessage(hwnd, LB_GETCARETINDEX, 0, 0L);
		/* We do want to see de-selection events too
		if (! sendmessage(hwnd, LB_GETSEL, index, 0L))
		  return;*/
		obj->value = index;
		break;

	  case DroplistObject:
	  case DropfieldObject:
		/* Ignore all but selection-change events. */
		if (message != CBN_SELCHANGE)
			return;
		index = sendmessage(hwnd, CB_GETCURSEL, 0, 0L);
		obj->value = index;
		break;

	  case FieldObject:
	  case TextboxObject:
	      if (message == EN_MAXTEXT) {
		  /* increase the character limit in the editor by 50%
		     if the limit is reached, but this should not
		     happen */
		  setlimittext(obj, 1.5 * getlimittext(obj));
	      }
	      /* Ignore everything else but killfocus. */
	      else if (message != EN_KILLFOCUS)
			return;
		break;

	  default:
		break;
	}
	/* activate the control's callback */
	activatecontrol(obj);
}
bool QHiMDWinDetection::winEvent(MSG * msg, long * result)
    {
        QString name, devID, path ;
        if(msg->message == WM_DEVICECHANGE)
        {
            PDEV_BROADCAST_HDR pHdr = (PDEV_BROADCAST_HDR )msg->lParam;
            switch(msg->wParam)
            {
                case DBT_DEVICEARRIVAL :
                {
                    if(pHdr->dbch_devicetype == DBT_DEVTYP_VOLUME)
                    {
                        PDEV_BROADCAST_VOLUME pHdrv = (PDEV_BROADCAST_VOLUME)pHdr;
                        path = FindPath(pHdrv->dbcv_unitmask);
                        devID = get_deviceID_from_driveletter(path.at(0).toLatin1());
                        if(!devID.isEmpty())
                        {
                            if(is_himddevice(devID, name))
                            {
                                qDebug() << "Message:DBT_DEVICEARRIVAL for drive " + path;
                                add_himddevice(path, name);
                            }
                        }
                    }
                    else if(pHdr->dbch_devicetype == DBT_DEVTYP_DEVICEINTERFACE)
                    {
                        PDEV_BROADCAST_DEVICEINTERFACE pDevInf = (PDEV_BROADCAST_DEVICEINTERFACE)pHdr;
                        devID = QString::fromWCharArray(pDevInf->dbcc_name).toUpper();
                        /* only handle netmd devices, himd devices will be handled by DBT_DEVTYP_VOLUME */
                        if(identified(devID, name) && name.contains("NetMD)"))
                        {
                            qDebug() << name << " detected, rescanning netmd devices" << endl;
                            rescan_netmd_devices();
                        }
                    }
                    break;
                }
                case DBT_DEVICEREMOVECOMPLETE :
                {
                    if(pHdr->dbch_devicetype == DBT_DEVTYP_VOLUME)
                    {
                        PDEV_BROADCAST_VOLUME pHdrv = (PDEV_BROADCAST_VOLUME)pHdr;
                        path = FindPath(pHdrv->dbcv_unitmask);
                        qDebug() << "Message:DBT_DEVICEREMOVECOMPLETE for drive " + path;
                        remove_himddevice(path);
                    }
                    else if(pHdr->dbch_devicetype == DBT_DEVTYP_DEVICEINTERFACE)
                    {
                        PDEV_BROADCAST_DEVICEINTERFACE pDevInf = (PDEV_BROADCAST_DEVICEINTERFACE)pHdr;
                        devID = QString::fromWCharArray(pDevInf->dbcc_name).toUpper();
                        if(identified(devID, name) && name.contains("NetMD)"))
                        {
                            qDebug() << name << " removed, rescanning netmd devices" << endl;
                            rescan_netmd_devices();
                        }
                    }
                    break;
                }
                case DBT_DEVICEQUERYREMOVE :
                {
                    if(pHdr->dbch_devicetype & DBT_DEVTYP_HANDLE)
                    {
                        PDEV_BROADCAST_HANDLE pHdrh = (PDEV_BROADCAST_HANDLE)pHdr;
                        QMDDevice *dev = find_by_handle(pHdrh->dbch_handle);
                        if(!dev)
                        {
                            qDebug() << "Message:DBT_DEVICEQUERYREMOVE for unknown device " << pHdrh->dbch_handle;
                            break;
                        }
                        if(dev->isBusy())
                        {
                            *result = BROADCAST_QUERY_DENY;
                            qDebug() << "Message:DBT_DEVICEQUERYREMOVE for drive " + path + " denied: transfer in progress";
                            return true;
                        }
                        else
                        {
                            qDebug() << "Message:DBT_DEVICEQUERYREMOVE requested";
                            remove_himddevice(dev->path());
                        }
                    }
                    else if(pHdr->dbch_devicetype == DBT_DEVTYP_DEVICEINTERFACE)
                    {
                        PDEV_BROADCAST_DEVICEINTERFACE pDevInf = (PDEV_BROADCAST_DEVICEINTERFACE)pHdr;
                        devID = QString::fromWCharArray(pDevInf->dbcc_name).toUpper();
                        if(identified(devID, name) && name.contains("NetMD)"))
                        {
                            QMDDevice * dev = find_by_name(name);
                            if(!dev)
                                break;
                            if(dev->isBusy())
                            {
                                *result = BROADCAST_QUERY_DENY;
                                return true;
                            }
                            dev->close();
                        }
                    }
                    break;
                }
                case my_DBT_CUSTOMEVENT :
                {
                    if(pHdr->dbch_devicetype & DBT_DEVTYP_HANDLE)
                    {
                        PDEV_BROADCAST_HANDLE pHdrh = (PDEV_BROADCAST_HANDLE)pHdr;
                        if (pHdrh->dbch_eventguid == my_GUID_IO_MEDIA_ARRIVAL)
                        {
                            qDebug() << "Message:DBT_CUSTOMEVENT - GUID_IO_MEDIA_ARRIVAL";
                            add_himd(pHdrh->dbch_handle);
                            break;
                        }
                        if (pHdrh->dbch_eventguid == my_GUID_IO_MEDIA_REMOVAL)
                        {
                            qDebug() << "Message:DBT_CUSTOMEVENT - GUID_IO_MEDIA_REMOVAL";
                            remove_himd(pHdrh->dbch_handle);
                            break;
                        }
                    }
                    break;
                }
                default: return false;  // skip unknown/unused messages
            }
            *result = TRUE;
            return true;
        }
        return false;
    }