コード例 #1
0
ファイル: GWindow.cpp プロジェクト: FEI17N/Lgi
int GWindow::OnDrop(char *Format, GVariant *Data, GdcPt2 Pt, int KeyState)
{
	int Status = DROPEFFECT_NONE;

	if (Format && Data)
	{
		if (stricmp(Format, LGI_FileDropFormat) == 0)
		{
			GArray<char*> Files;
			if (Data->IsBinary())
			{
				GToken Uri(	(char*)Data->Value.Binary.Data,
							"\r\n,",
							true,
							Data->Value.Binary.Length);
				for (int n=0; n<Uri.Length(); n++)
				{
					char *File = Uri[n];
					if (strnicmp(File, "file:", 5) == 0)
						File += 5;
					
					char *i = File, *o = File;
					while (*i)
					{
						if (i[0] == '%' &&
							i[1] &&
							i[2])
						{
							char h[3] = { i[1], i[2], 0 };
							*o++ = htoi(h);
							i += 3;
						}
						else
						{
							*o++ = *i++;
						}
					}
					*o++ = 0;
					
					if (FileExists(File))
					{
						Files.Add(NewStr(File));
					}
				}
			}
			
			if (Files.Length())
			{
				Status = DROPEFFECT_COPY;
				OnReceiveFiles(Files);
				Files.DeleteArrays();
			}
		}
	}
	
	return Status;
}
コード例 #2
0
ファイル: GString.cpp プロジェクト: gedamial/GedamialLibrary
	GArray<GString> GString::Split(GString& str, char const token)
	{
		str.Trim(token);
		GArray<GString> arr;

		size_t lastPos = 0;
		size_t tokenPos = str.Find(token);

		while (tokenPos != -1)
		{
			arr.Add(str.SubString(lastPos, tokenPos - 1));

			lastPos = tokenPos + 1;

			tokenPos = str.Find(token, tokenPos + 1);
		}

		arr.Add(str.SubString(lastPos, str.Size() - 1));

		return arr;
	}	
コード例 #3
0
ファイル: GWindow.cpp プロジェクト: FEI17N/Lgi
GMessage::Result GWindow::OnEvent(GMessage *Msg)
{
	switch (MsgCode(Msg))
	{
		case B_SIMPLE_DATA:
		{
			GArray<char*> Files;
			int32 Count = 0;
			type_code Type = 0;
			
			if (Msg->GetInfo("refs", &Type, &Count) == B_OK)
			{
				for (int i=0; i<Count; i++)
				{
					entry_ref Ref;
					if (Msg->FindRef("refs", i, &Ref) == B_OK)
					{
						BPath Path("");
						BEntry Entry(&Ref, true);
						Entry.GetPath(&Path);
						char *p = (char*) Path.Path();
						if (p)
						{
							Files.Add(NewStr(p));
						}
					}
				}
			}
			
			if (Files.Length() > 0)
			{
				OnReceiveFiles(Files);
			}
			
			Files.DeleteArrays();
			break;
		}
		case M_COMMAND:
		{
			int32 Cmd = 0;
			int32 Event = 0;
			Msg->FindInt32("Cmd", &Cmd);
			Msg->FindInt32("Event", &Event);
			OnCommand(Cmd, Event, 0);
			break;
		}
	}

	return GView::OnEvent(Msg);
}
コード例 #4
0
ファイル: GWindow.cpp プロジェクト: FEI17N/Lgi
GMessage::Result GWindow::OnEvent(GMessage *Msg)
{
	int Status = 0;

	switch (MsgCode(Msg))
	{
		case M_SET_WINDOW_PLACEMENT:
		{
			/*	
				Apparently if you use SetWindowPlacement inside the WM_CREATE handler,
				then the restored rect doesn't "stick", it gets stomped on by windows.
				So this code... RESETS it to be what we set earlier. Windows sucks.
			*/
			if (d->Wp)
			{
				if (_View)
				{
					GRect r = d->Wp->rcNormalPosition;

					if (!GView::Visible())
					{
						d->Wp->showCmd = SW_HIDE;
					}

					#if DEBUG_WINDOW_PLACEMENT
					LgiTrace("%s:%i - SetWindowPlacement, pos=%s, show=%i\n", __FILE__, __LINE__, r.GetStr(), d->Wp->showCmd);
					#endif

					SetWindowPlacement(_View, d->Wp);
				}
				DeleteObj(d->Wp);
			}
			break;
		}
		case WM_SYSCOLORCHANGE:
		{
			LgiInitColours();
			break;
		}
		case WM_WINDOWPOSCHANGING:
		{
			bool Icon = IsIconic(Handle());
			bool Zoom = IsZoomed(Handle());

			if (!Icon && (_Dialog || !Zoom))
			{
				WINDOWPOS *Info = (LPWINDOWPOS) Msg->b;
				if (!Info)
				    break;
				    
				if (Info->flags == (SWP_NOSIZE | SWP_NOMOVE) && _Dialog)
				{
				    // Info->flags |= SWP_NOZORDER;
				    Info->hwndInsertAfter = _Dialog->Handle();
				}

				if (GetMinimumSize().x &&
					GetMinimumSize().x > Info->cx)
				{
					Info->cx = GetMinimumSize().x;
				}

				if (GetMinimumSize().y &&
					GetMinimumSize().y > Info->cy)
				{
					Info->cy = GetMinimumSize().y;
				}

				RECT Rc;
				if (d->SnapToEdge &&
					SystemParametersInfo(SPI_GETWORKAREA, 0, &Rc, SPIF_SENDCHANGE))
				{
					GRect r = Rc;
					GRect p(Info->x,
					        Info->y,
					        Info->x + Info->cx - 1,
					        Info->y + Info->cy - 1);
					
					if (r.Valid() && p.Valid())
					{
						int Snap = 12;

						if (abs(p.x1 - r.x1) <= Snap)
						{
							// Snap left edge
							Info->x = r.x1;
						}
						else if (abs(p.x2 - r.x2) <= Snap)
						{
							// Snap right edge
							Info->x = r.x2 - Info->cx + 1;
						}

						if (abs(p.y1 - r.y1) <= Snap)
						{
							// Snap top edge
							Info->y = r.y1;
						}
						else if (abs(p.y2 - r.y2) <= Snap)
						{
							// Snap bottom edge
							Info->y = r.y2 - Info->cy + 1;
						}
					}
				}
			}
			break;
		}
		case WM_SIZE:
		{
			if (Visible())
			{
				GWindowZoom z = d->Show;
				switch (Msg->a)
				{
					case SIZE_MINIMIZED:
					{
						z = GZoomMin;
						break;
					}
					case SIZE_MAXIMIZED:
					{
						z = GZoomMax;
						break;
					}
					case SIZE_RESTORED:
					{
						z = GZoomNormal;
						break;
					}
				}
				if (z != d->Show)
				{
					OnZoom(d->Show = z);
				}
			}

			Status = GView::OnEvent(Msg);
			break;
		}
		case WM_ACTIVATE:
		{
			// This is a hack to make Windows set the focus of a child
			// control when you Alt-Tab in and out of a top level window
			if (LOWORD(Msg->a) != WA_INACTIVE)
			{
				/*
				// gaining focus
				if (LastFocus)
				{
					if (In_SetWindowPos)
					{
						assert(0);
						LgiTrace("%s:%i - %s->SetFocus()\n", __FILE__, __LINE__, GetClass());
					}
					SetFocus(LastFocus);
					LastFocus = 0;
				}
				
				if (d->Focus && d->Focus->Handle())
				{
					if (In_SetWindowPos)
					{
						assert(0);
						LgiTrace("%s:%i - %s->SetFocus()\n", __FILE__, __LINE__, GetClass());
					}
					else
					{					
						::SetFocus(d->Focus->Handle());
					}
				}
				*/
			}
			/*
			else
			{
				// losing focus
				LastFocus = 0;
				HWND f = GetFocus();
				for (HWND p = ::GetParent(f); p; p = ::GetParent(p))
				{
					if (p == Handle())
					{
						LastFocus = f;
					}
				}
			}
			*/
			break;
		}
		case WM_CREATE:
		{
			Pour();
			OnCreate();

			if (!_Default)
			{
				_Default = FindControl(IDOK);
				if (_Default)
				{
					_Default->Invalidate();
				}
			}

			d->InCreate = false;
			if (d->Wp)
			{
				PostEvent(M_SET_WINDOW_PLACEMENT);
			}
			break;
		}
		case WM_WINDOWPOSCHANGED:
		{
			DeleteObj(d->Wp);
			Status = GView::OnEvent(Msg);
			break;
		}
		case WM_QUERYENDSESSION:
	 	case WM_CLOSE:
		{
			bool QuitApp;
			if (QuitApp = OnRequestClose(MsgCode(Msg) == WM_QUERYENDSESSION))
			{
				Quit();
			}

			if (MsgCode(Msg) == WM_CLOSE)
			{
				return 0;
			}
			else
			{
				return QuitApp;
			}
			break;
		}
		case WM_SYSCOMMAND:
		{
		    if (Msg->a == SC_CLOSE)
		    {
    			if (OnRequestClose(false))
    		    {
    		        Quit();
    		    }

   		        return 0;
		    }
		    else
		    {
			    Status = GView::OnEvent(Msg);
			}
		    break;
		}
		case WM_DROPFILES:
		{
			HDROP hDrop = (HDROP) Msg->a;
			if (hDrop)
			{
				GArray<char*> FileNames;
				int Count = 0;
				
				Count = DragQueryFileW(hDrop, -1, NULL, 0);

				for (int i=0; i<Count; i++)
				{
					char16 FileName[256];
					if (DragQueryFileW(hDrop, i, FileName, sizeof(FileName)-1) > 0)
					{
						FileNames.Add(LgiNewUtf16To8(FileName));
					}
				}

				OnReceiveFiles(FileNames);
				FileNames.DeleteArrays();
			}
			break;
		}
		case M_HANDLEMOUSEMOVE:
		{
			// This receives events fired from the GMouseHookPrivate class so that
			// non-LGI windows create mouse hook events as well.
			GTempView v((OsView)MsgB(Msg));
			GMouse m;
			m.x = LOWORD(MsgA(Msg));
			m.y = HIWORD(MsgA(Msg));
			HandleViewMouse(&v, m);
			break;
		}
		case M_COMMAND:
		{
			HWND OurWnd = Handle(); // copy onto the stack, because
									// we might lose the 'this' object in the
									// OnCommand handler which would delete
									// the memory containing the handle.

			Status = OnCommand(Msg->a, 0, (HWND) Msg->b);
			if (!IsWindow(OurWnd))
			{
				// The window was deleted so break out now
				break;
			}
			// otherwise fall thru to the GView handler
		}
		default:
		{
			Status = GView::OnEvent(Msg);
			break;
		}
	}

	return Status;
}